mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-27 00:35:18 +00:00
c63ecf908a
* Add 'InterestFactor' to CDP type (#734) * update cdp type to include interest factor * fix build * Add cdp accumulator methods (#735) * remame fees to interest * add accumulate interest method * add basic test * add note * address review comments * update tests * Add sync cdp interest method (#737) * remame fees to interest * add accumulate interest method * add basic test * add note * address review comments * update tests * remove old fee functions * add method to synchronize cdp interest * add multi-cdp tests * add test with many blocks * add test for interest getter * address review comments * calculate time difference then convert to seconds * fix: update collateral index when syncing interest * fix: differentiate between case when apy is zero and all fees are being rounded to zero * fix: round time difference properly * update cdp genesis state and migrations (#738) * remame fees to interest * add accumulate interest method * add basic test * add note * address review comments * update tests * remove old fee functions * add method to synchronize cdp interest * add multi-cdp tests * add test with many blocks * add test for interest getter * update cdp genesis state and migrations * address review comments * calculate time difference then convert to seconds * fix: update collateral index when syncing interest * fix: differentiate between case when apy is zero and all fees are being rounded to zero * fix: simplify add/remove/update collateral index * update genesis state to include total principal amounts * update migration * Delete kava-4-cdp-state-block-500000.json * Add cdp liquidations by external keeper (#750) * feat: split liquidations between external keepers and automated begin blocker * address review comments * USDX incentive accumulators (#752) * feat: split liquidations between external keepers and automated begin blocker * wip: refactor usdx minting incentives to use accumulators/hooks * wip: refactor usdx minting claim object * feat: use accumulators/hooks for usdx minting rewards * fix: get tests passing * fix: don't create claim objects unless that cdp type is eligable for rewards * add begin blocker * update client * cleanup comments/tests * update querier * address review comments * fix: check for division by zero * address review comments * run hook before interest is synced * Remove savings rate (#764) * remove savings rate * remove savings rate from debt param * update migrations * address review comments * Add usdx incentives calculation test (#765) * add usdx incentive calculation test * update reward calculation * add allowable error to test criteria * Update x/incentive/keeper/rewards_test.go Co-authored-by: Kevin Davis <karzak@users.noreply.github.com> * fix: remove old fields from test genesis state Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com> Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>
70 lines
2.8 KiB
Go
70 lines
2.8 KiB
Go
package v0_13
|
|
|
|
import (
|
|
"time"
|
|
|
|
v0_11cdp "github.com/kava-labs/kava/x/cdp/legacy/v0_11"
|
|
v0_13cdp "github.com/kava-labs/kava/x/cdp/legacy/v0_13"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
// MigrateCDP migrates from a v0.9 (or v0.10) cdp genesis state to a v0.11 cdp genesis state
|
|
func MigrateCDP(oldGenState v0_11cdp.GenesisState) v0_13cdp.GenesisState {
|
|
var newCDPs v0_13cdp.CDPs
|
|
var newDeposits v0_13cdp.Deposits
|
|
var newCollateralParams v0_13cdp.CollateralParams
|
|
var newGenesisAccumulationTimes v0_13cdp.GenesisAccumulationTimes
|
|
var previousAccumulationTime time.Time
|
|
var totalPrincipals v0_13cdp.GenesisTotalPrincipals
|
|
newStartingID := oldGenState.StartingCdpID
|
|
|
|
totalPrincipalMap := make(map[string]sdk.Int)
|
|
for _, cp := range oldGenState.Params.CollateralParams {
|
|
newCollateralParam := v0_13cdp.NewCollateralParam(cp.Denom, cp.Type, cp.LiquidationRatio, cp.DebtLimit, cp.StabilityFee, cp.AuctionSize, cp.LiquidationPenalty, cp.Prefix, cp.SpotMarketID, cp.LiquidationMarketID, sdk.MustNewDecFromStr("0.01"), sdk.NewInt(10), cp.ConversionFactor)
|
|
newCollateralParams = append(newCollateralParams, newCollateralParam)
|
|
newGenesisAccumulationTime := v0_13cdp.NewGenesisAccumulationTime(cp.Type, previousAccumulationTime, sdk.OneDec())
|
|
newGenesisAccumulationTimes = append(newGenesisAccumulationTimes, newGenesisAccumulationTime)
|
|
totalPrincipalMap[cp.Type] = sdk.ZeroInt()
|
|
}
|
|
|
|
for _, cdp := range oldGenState.CDPs {
|
|
newCDP := v0_13cdp.NewCDPWithFees(cdp.ID, cdp.Owner, cdp.Collateral, cdp.Type, cdp.Principal, cdp.AccumulatedFees, cdp.FeesUpdated, sdk.OneDec())
|
|
if previousAccumulationTime.Before(cdp.FeesUpdated) {
|
|
previousAccumulationTime = cdp.FeesUpdated
|
|
}
|
|
totalPrincipalMap[cdp.Type] = totalPrincipalMap[cdp.Type].Add(newCDP.GetTotalPrincipal().Amount)
|
|
|
|
newCDPs = append(newCDPs, newCDP)
|
|
}
|
|
|
|
for _, dep := range oldGenState.Deposits {
|
|
newDep := v0_13cdp.NewDeposit(dep.CdpID, dep.Depositor, dep.Amount)
|
|
newDeposits = append(newDeposits, newDep)
|
|
}
|
|
|
|
for ctype, tp := range totalPrincipalMap {
|
|
totalPrincipal := v0_13cdp.NewGenesisTotalPrincipal(ctype, tp)
|
|
totalPrincipals = append(totalPrincipals, totalPrincipal)
|
|
}
|
|
|
|
oldDebtParam := oldGenState.Params.DebtParam
|
|
|
|
newDebtParam := v0_13cdp.NewDebtParam(oldDebtParam.Denom, oldDebtParam.ReferenceAsset, oldDebtParam.ConversionFactor, oldDebtParam.DebtFloor)
|
|
|
|
newGlobalDebtLimit := oldGenState.Params.GlobalDebtLimit
|
|
|
|
newParams := v0_13cdp.NewParams(newGlobalDebtLimit, newCollateralParams, newDebtParam, oldGenState.Params.SurplusAuctionThreshold, oldGenState.Params.SurplusAuctionLot, oldGenState.Params.DebtAuctionThreshold, oldGenState.Params.DebtAuctionLot, false)
|
|
|
|
return v0_13cdp.NewGenesisState(
|
|
newParams,
|
|
newCDPs,
|
|
newDeposits,
|
|
newStartingID,
|
|
oldGenState.DebtDenom,
|
|
oldGenState.GovDenom,
|
|
newGenesisAccumulationTimes,
|
|
totalPrincipals,
|
|
)
|
|
}
|