mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
26 lines
811 B
Go
26 lines
811 B
Go
|
package cdp
|
||
|
|
||
|
import (
|
||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||
|
abci "github.com/tendermint/tendermint/abci/types"
|
||
|
)
|
||
|
|
||
|
// BeginBlock compounds the debt in outstanding cdps and liquidates cdps that are below the required collateralization ratio
|
||
|
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k Keeper) {
|
||
|
params := k.GetParams(ctx)
|
||
|
previousBlockTime, found := k.GetPreviousBlockTime(ctx)
|
||
|
if !found {
|
||
|
previousBlockTime = ctx.BlockTime()
|
||
|
}
|
||
|
timeElapsed := sdk.NewInt(ctx.BlockTime().Unix() - previousBlockTime.Unix())
|
||
|
for _, cp := range params.CollateralParams {
|
||
|
for _, dp := range params.DebtParams {
|
||
|
k.HandleNewDebt(ctx, cp.Denom, dp.Denom, timeElapsed)
|
||
|
}
|
||
|
|
||
|
k.LiquidateCdps(ctx, cp.MarketID, cp.Denom, cp.LiquidationRatio)
|
||
|
}
|
||
|
k.SetPreviousBlockTime(ctx, ctx.BlockTime())
|
||
|
return
|
||
|
}
|