mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
d849d690e5
* wip: tpyes and keeper methods * wip: iterators * wip: types and keeper methods * wip: add msgs * wip: client methods * wip: rebase develop * wip: types tests * wip: keeper tests, small fixes * wip: add cdp tests * wip: deposit tests * wip: keeper tests * wip: tests and module methods * feat: error when fetching expired price * feat: conversion factor for external assets * feat: debt floor for new cdps * feat: save deposits on export genesis * feat: ensure messages implement msg * feat: index deposits by status * fix: stray comment * wip: address review comments * address review comments
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
|
|
}
|