mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-11-04 06:37:26 +00:00 
			
		
		
		
	[R4R] CDP module migrations from v0.11 -> v0.13 (#769)
* remove references to savings rate * removing savings rate module account in auth migration * use compact json * fix non-determinism is cdp migration
This commit is contained in:
		
							parent
							
								
									92afaf6ca0
								
							
						
					
					
						commit
						4eef80b47f
					
				@ -1,15 +1,19 @@
 | 
				
			|||||||
package v0_13
 | 
					package v0_13
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"sort"
 | 
				
			||||||
	"time"
 | 
						"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"
 | 
						sdk "github.com/cosmos/cosmos-sdk/types"
 | 
				
			||||||
 | 
						"github.com/cosmos/cosmos-sdk/x/auth"
 | 
				
			||||||
 | 
						authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
 | 
				
			||||||
 | 
						"github.com/cosmos/cosmos-sdk/x/supply"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						v0_13cdp "github.com/kava-labs/kava/x/cdp"
 | 
				
			||||||
 | 
						v0_11cdp "github.com/kava-labs/kava/x/cdp/legacy/v0_11"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// MigrateCDP migrates from a v0.9 (or v0.10) cdp genesis state to a v0.11 cdp genesis state
 | 
					// MigrateCDP migrates from a v0.11 cdp genesis state to a v0.13 cdp genesis state
 | 
				
			||||||
func MigrateCDP(oldGenState v0_11cdp.GenesisState) v0_13cdp.GenesisState {
 | 
					func MigrateCDP(oldGenState v0_11cdp.GenesisState) v0_13cdp.GenesisState {
 | 
				
			||||||
	var newCDPs v0_13cdp.CDPs
 | 
						var newCDPs v0_13cdp.CDPs
 | 
				
			||||||
	var newDeposits v0_13cdp.Deposits
 | 
						var newDeposits v0_13cdp.Deposits
 | 
				
			||||||
@ -20,24 +24,28 @@ func MigrateCDP(oldGenState v0_11cdp.GenesisState) v0_13cdp.GenesisState {
 | 
				
			|||||||
	newStartingID := oldGenState.StartingCdpID
 | 
						newStartingID := oldGenState.StartingCdpID
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	totalPrincipalMap := make(map[string]sdk.Int)
 | 
						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 {
 | 
						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())
 | 
							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) {
 | 
							if previousAccumulationTime.Before(cdp.FeesUpdated) {
 | 
				
			||||||
			previousAccumulationTime = cdp.FeesUpdated
 | 
								previousAccumulationTime = cdp.FeesUpdated
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							_, found := totalPrincipalMap[cdp.Type]
 | 
				
			||||||
 | 
							if !found {
 | 
				
			||||||
 | 
								totalPrincipalMap[cdp.Type] = sdk.ZeroInt()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		totalPrincipalMap[cdp.Type] = totalPrincipalMap[cdp.Type].Add(newCDP.GetTotalPrincipal().Amount)
 | 
							totalPrincipalMap[cdp.Type] = totalPrincipalMap[cdp.Type].Add(newCDP.GetTotalPrincipal().Amount)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		newCDPs = append(newCDPs, newCDP)
 | 
							newCDPs = append(newCDPs, newCDP)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, dep := range oldGenState.Deposits {
 | 
						for _, dep := range oldGenState.Deposits {
 | 
				
			||||||
		newDep := v0_13cdp.NewDeposit(dep.CdpID, dep.Depositor, dep.Amount)
 | 
							newDep := v0_13cdp.NewDeposit(dep.CdpID, dep.Depositor, dep.Amount)
 | 
				
			||||||
		newDeposits = append(newDeposits, newDep)
 | 
							newDeposits = append(newDeposits, newDep)
 | 
				
			||||||
@ -48,6 +56,8 @@ func MigrateCDP(oldGenState v0_11cdp.GenesisState) v0_13cdp.GenesisState {
 | 
				
			|||||||
		totalPrincipals = append(totalPrincipals, totalPrincipal)
 | 
							totalPrincipals = append(totalPrincipals, totalPrincipal)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sort.Slice(totalPrincipals, func(i, j int) bool { return totalPrincipals[i].CollateralType < totalPrincipals[j].CollateralType })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	oldDebtParam := oldGenState.Params.DebtParam
 | 
						oldDebtParam := oldGenState.Params.DebtParam
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	newDebtParam := v0_13cdp.NewDebtParam(oldDebtParam.Denom, oldDebtParam.ReferenceAsset, oldDebtParam.ConversionFactor, oldDebtParam.DebtFloor)
 | 
						newDebtParam := v0_13cdp.NewDebtParam(oldDebtParam.Denom, oldDebtParam.ReferenceAsset, oldDebtParam.ConversionFactor, oldDebtParam.DebtFloor)
 | 
				
			||||||
@ -67,3 +77,39 @@ func MigrateCDP(oldGenState v0_11cdp.GenesisState) v0_13cdp.GenesisState {
 | 
				
			|||||||
		totalPrincipals,
 | 
							totalPrincipals,
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// MigrateAuth migrates from a v0.11 auth genesis state to a v0.13
 | 
				
			||||||
 | 
					func MigrateAuth(genesisState auth.GenesisState) auth.GenesisState {
 | 
				
			||||||
 | 
						savingsRateMaccCoins := sdk.NewCoins()
 | 
				
			||||||
 | 
						savingsMaccAddr := supply.NewModuleAddress(v0_11cdp.SavingsRateMacc)
 | 
				
			||||||
 | 
						savingsRateMaccIndex := 0
 | 
				
			||||||
 | 
						liquidatorMaccIndex := 0
 | 
				
			||||||
 | 
						for idx, acc := range genesisState.Accounts {
 | 
				
			||||||
 | 
							if acc.GetAddress().Equals(savingsMaccAddr) {
 | 
				
			||||||
 | 
								savingsRateMaccCoins = acc.GetCoins()
 | 
				
			||||||
 | 
								savingsRateMaccIndex = idx
 | 
				
			||||||
 | 
								err := acc.SetCoins(acc.GetCoins().Sub(acc.GetCoins()))
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									panic(err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if acc.GetAddress().Equals(supply.NewModuleAddress(v0_13cdp.LiquidatorMacc)) {
 | 
				
			||||||
 | 
								liquidatorMaccIndex = idx
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						liquidatorAcc := genesisState.Accounts[liquidatorMaccIndex]
 | 
				
			||||||
 | 
						err := liquidatorAcc.SetCoins(liquidatorAcc.GetCoins().Add(savingsRateMaccCoins...))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						genesisState.Accounts[liquidatorMaccIndex] = liquidatorAcc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						genesisState.Accounts = removeIndex(genesisState.Accounts, savingsRateMaccIndex)
 | 
				
			||||||
 | 
						return genesisState
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func removeIndex(accs authexported.GenesisAccounts, index int) authexported.GenesisAccounts {
 | 
				
			||||||
 | 
						ret := make(authexported.GenesisAccounts, 0)
 | 
				
			||||||
 | 
						ret = append(ret, accs[:index]...)
 | 
				
			||||||
 | 
						return append(ret, accs[index+1:]...)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sdk "github.com/cosmos/cosmos-sdk/types"
 | 
						sdk "github.com/cosmos/cosmos-sdk/types"
 | 
				
			||||||
 | 
						"github.com/cosmos/cosmos-sdk/x/auth"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/kava-labs/kava/app"
 | 
						"github.com/kava-labs/kava/app"
 | 
				
			||||||
	v0_11cdp "github.com/kava-labs/kava/x/cdp/legacy/v0_11"
 | 
						v0_11cdp "github.com/kava-labs/kava/x/cdp/legacy/v0_11"
 | 
				
			||||||
@ -41,3 +42,18 @@ func TestMigrateCdp(t *testing.T) {
 | 
				
			|||||||
	require.Equal(t, sdk.OneDec(), cdp1.InterestFactor)
 | 
						require.Equal(t, sdk.OneDec(), cdp1.InterestFactor)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestMigrateAuth(t *testing.T) {
 | 
				
			||||||
 | 
						bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-4-auth-state-block-500000.json"))
 | 
				
			||||||
 | 
						require.NoError(t, err)
 | 
				
			||||||
 | 
						var oldGenState auth.GenesisState
 | 
				
			||||||
 | 
						cdc := app.MakeCodec()
 | 
				
			||||||
 | 
						require.NotPanics(t, func() {
 | 
				
			||||||
 | 
							cdc.MustUnmarshalJSON(bz, &oldGenState)
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						newGenState := MigrateAuth(oldGenState)
 | 
				
			||||||
 | 
						err = auth.ValidateGenesis(newGenState)
 | 
				
			||||||
 | 
						require.NoError(t, err)
 | 
				
			||||||
 | 
						require.Equal(t, len(oldGenState.Accounts), len(newGenState.Accounts)+1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								migrate/v0_13/testdata/kava-4-auth-state-block-500000.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								migrate/v0_13/testdata/kava-4-auth-state-block-500000.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										169
									
								
								x/cdp/alias.go
									
									
									
									
									
								
							
							
						
						
									
										169
									
								
								x/cdp/alias.go
									
									
									
									
									
								
							@ -8,36 +8,34 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	AttributeKeyCdpID                       = types.AttributeKeyCdpID
 | 
						AttributeKeyCdpID               = types.AttributeKeyCdpID
 | 
				
			||||||
	AttributeKeyDeposit                     = types.AttributeKeyDeposit
 | 
						AttributeKeyDeposit             = types.AttributeKeyDeposit
 | 
				
			||||||
	AttributeKeyError                       = types.AttributeKeyError
 | 
						AttributeKeyError               = types.AttributeKeyError
 | 
				
			||||||
	AttributeValueCategory                  = types.AttributeValueCategory
 | 
						AttributeValueCategory          = types.AttributeValueCategory
 | 
				
			||||||
	DefaultParamspace                       = types.DefaultParamspace
 | 
						DefaultParamspace               = types.DefaultParamspace
 | 
				
			||||||
	EventTypeBeginBlockerFatal              = types.EventTypeBeginBlockerFatal
 | 
						EventTypeBeginBlockerFatal      = types.EventTypeBeginBlockerFatal
 | 
				
			||||||
	EventTypeCdpClose                       = types.EventTypeCdpClose
 | 
						EventTypeCdpClose               = types.EventTypeCdpClose
 | 
				
			||||||
	EventTypeCdpDeposit                     = types.EventTypeCdpDeposit
 | 
						EventTypeCdpDeposit             = types.EventTypeCdpDeposit
 | 
				
			||||||
	EventTypeCdpDraw                        = types.EventTypeCdpDraw
 | 
						EventTypeCdpDraw                = types.EventTypeCdpDraw
 | 
				
			||||||
	EventTypeCdpLiquidation                 = types.EventTypeCdpLiquidation
 | 
						EventTypeCdpLiquidation         = types.EventTypeCdpLiquidation
 | 
				
			||||||
	EventTypeCdpRepay                       = types.EventTypeCdpRepay
 | 
						EventTypeCdpRepay               = types.EventTypeCdpRepay
 | 
				
			||||||
	EventTypeCdpWithdrawal                  = types.EventTypeCdpWithdrawal
 | 
						EventTypeCdpWithdrawal          = types.EventTypeCdpWithdrawal
 | 
				
			||||||
	EventTypeCreateCdp                      = types.EventTypeCreateCdp
 | 
						EventTypeCreateCdp              = types.EventTypeCreateCdp
 | 
				
			||||||
	LiquidatorMacc                          = types.LiquidatorMacc
 | 
						LiquidatorMacc                  = types.LiquidatorMacc
 | 
				
			||||||
	ModuleName                              = types.ModuleName
 | 
						ModuleName                      = types.ModuleName
 | 
				
			||||||
	QuerierRoute                            = types.QuerierRoute
 | 
						QuerierRoute                    = types.QuerierRoute
 | 
				
			||||||
	QueryGetAccounts                        = types.QueryGetAccounts
 | 
						QueryGetAccounts                = types.QueryGetAccounts
 | 
				
			||||||
	QueryGetCdp                             = types.QueryGetCdp
 | 
						QueryGetCdp                     = types.QueryGetCdp
 | 
				
			||||||
	QueryGetCdpDeposits                     = types.QueryGetCdpDeposits
 | 
						QueryGetCdpDeposits             = types.QueryGetCdpDeposits
 | 
				
			||||||
	QueryGetCdps                            = types.QueryGetCdps
 | 
						QueryGetCdps                    = types.QueryGetCdps
 | 
				
			||||||
	QueryGetCdpsByCollateralType            = types.QueryGetCdpsByCollateralType
 | 
						QueryGetCdpsByCollateralType    = types.QueryGetCdpsByCollateralType
 | 
				
			||||||
	QueryGetCdpsByCollateralization         = types.QueryGetCdpsByCollateralization
 | 
						QueryGetCdpsByCollateralization = types.QueryGetCdpsByCollateralization
 | 
				
			||||||
	QueryGetParams                          = types.QueryGetParams
 | 
						QueryGetParams                  = types.QueryGetParams
 | 
				
			||||||
	QueryGetPreviousSavingsDistributionTime = types.QueryGetPreviousSavingsDistributionTime
 | 
						RestCollateralType              = types.RestCollateralType
 | 
				
			||||||
	QueryGetSavingsRateDistributed          = types.QueryGetSavingsRateDistributed
 | 
						RestOwner                       = types.RestOwner
 | 
				
			||||||
	RestCollateralType                      = types.RestCollateralType
 | 
						RestRatio                       = types.RestRatio
 | 
				
			||||||
	RestOwner                               = types.RestOwner
 | 
						RouterKey                       = types.RouterKey
 | 
				
			||||||
	RestRatio                               = types.RestRatio
 | 
						StoreKey                        = types.StoreKey
 | 
				
			||||||
	RouterKey                               = types.RouterKey
 | 
					 | 
				
			||||||
	StoreKey                                = types.StoreKey
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
@ -94,62 +92,61 @@ var (
 | 
				
			|||||||
	ValidSortableDec                   = types.ValidSortableDec
 | 
						ValidSortableDec                   = types.ValidSortableDec
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// variable aliases
 | 
						// variable aliases
 | 
				
			||||||
	CdpIDKey                      = types.CdpIDKey
 | 
						CdpIDKey                   = types.CdpIDKey
 | 
				
			||||||
	CdpIDKeyPrefix                = types.CdpIDKeyPrefix
 | 
						CdpIDKeyPrefix             = types.CdpIDKeyPrefix
 | 
				
			||||||
	CdpKeyPrefix                  = types.CdpKeyPrefix
 | 
						CdpKeyPrefix               = types.CdpKeyPrefix
 | 
				
			||||||
	CollateralRatioIndexPrefix    = types.CollateralRatioIndexPrefix
 | 
						CollateralRatioIndexPrefix = types.CollateralRatioIndexPrefix
 | 
				
			||||||
	DebtDenomKey                  = types.DebtDenomKey
 | 
						DebtDenomKey               = types.DebtDenomKey
 | 
				
			||||||
	DefaultCdpStartingID          = types.DefaultCdpStartingID
 | 
						DefaultCdpStartingID       = types.DefaultCdpStartingID
 | 
				
			||||||
	DefaultCircuitBreaker         = types.DefaultCircuitBreaker
 | 
						DefaultCircuitBreaker      = types.DefaultCircuitBreaker
 | 
				
			||||||
	DefaultCollateralParams       = types.DefaultCollateralParams
 | 
						DefaultCollateralParams    = types.DefaultCollateralParams
 | 
				
			||||||
	DefaultDebtDenom              = types.DefaultDebtDenom
 | 
						DefaultDebtDenom           = types.DefaultDebtDenom
 | 
				
			||||||
	DefaultDebtLot                = types.DefaultDebtLot
 | 
						DefaultDebtLot             = types.DefaultDebtLot
 | 
				
			||||||
	DefaultDebtParam              = types.DefaultDebtParam
 | 
						DefaultDebtParam           = types.DefaultDebtParam
 | 
				
			||||||
	DefaultDebtThreshold          = types.DefaultDebtThreshold
 | 
						DefaultDebtThreshold       = types.DefaultDebtThreshold
 | 
				
			||||||
	DefaultGlobalDebt             = types.DefaultGlobalDebt
 | 
						DefaultGlobalDebt          = types.DefaultGlobalDebt
 | 
				
			||||||
	DefaultGovDenom               = types.DefaultGovDenom
 | 
						DefaultGovDenom            = types.DefaultGovDenom
 | 
				
			||||||
	DefaultSavingsRateDistributed = types.DefaultSavingsRateDistributed
 | 
						DefaultStableDenom         = types.DefaultStableDenom
 | 
				
			||||||
	DefaultStableDenom            = types.DefaultStableDenom
 | 
						DefaultSurplusLot          = types.DefaultSurplusLot
 | 
				
			||||||
	DefaultSurplusLot             = types.DefaultSurplusLot
 | 
						DefaultSurplusThreshold    = types.DefaultSurplusThreshold
 | 
				
			||||||
	DefaultSurplusThreshold       = types.DefaultSurplusThreshold
 | 
						DepositKeyPrefix           = types.DepositKeyPrefix
 | 
				
			||||||
	DepositKeyPrefix              = types.DepositKeyPrefix
 | 
						ErrAccountNotFound         = types.ErrAccountNotFound
 | 
				
			||||||
	ErrAccountNotFound            = types.ErrAccountNotFound
 | 
						ErrBelowDebtFloor          = types.ErrBelowDebtFloor
 | 
				
			||||||
	ErrBelowDebtFloor             = types.ErrBelowDebtFloor
 | 
						ErrCdpAlreadyExists        = types.ErrCdpAlreadyExists
 | 
				
			||||||
	ErrCdpAlreadyExists           = types.ErrCdpAlreadyExists
 | 
						ErrCdpNotAvailable         = types.ErrCdpNotAvailable
 | 
				
			||||||
	ErrCdpNotAvailable            = types.ErrCdpNotAvailable
 | 
						ErrCdpNotFound             = types.ErrCdpNotFound
 | 
				
			||||||
	ErrCdpNotFound                = types.ErrCdpNotFound
 | 
						ErrCollateralNotSupported  = types.ErrCollateralNotSupported
 | 
				
			||||||
	ErrCollateralNotSupported     = types.ErrCollateralNotSupported
 | 
						ErrDebtNotSupported        = types.ErrDebtNotSupported
 | 
				
			||||||
	ErrDebtNotSupported           = types.ErrDebtNotSupported
 | 
						ErrDenomPrefixNotFound     = types.ErrDenomPrefixNotFound
 | 
				
			||||||
	ErrDenomPrefixNotFound        = types.ErrDenomPrefixNotFound
 | 
						ErrDepositNotAvailable     = types.ErrDepositNotAvailable
 | 
				
			||||||
	ErrDepositNotAvailable        = types.ErrDepositNotAvailable
 | 
						ErrDepositNotFound         = types.ErrDepositNotFound
 | 
				
			||||||
	ErrDepositNotFound            = types.ErrDepositNotFound
 | 
						ErrExceedsDebtLimit        = types.ErrExceedsDebtLimit
 | 
				
			||||||
	ErrExceedsDebtLimit           = types.ErrExceedsDebtLimit
 | 
						ErrInsufficientBalance     = types.ErrInsufficientBalance
 | 
				
			||||||
	ErrInsufficientBalance        = types.ErrInsufficientBalance
 | 
						ErrInvalidCollateral       = types.ErrInvalidCollateral
 | 
				
			||||||
	ErrInvalidCollateral          = types.ErrInvalidCollateral
 | 
						ErrInvalidCollateralLength = types.ErrInvalidCollateralLength
 | 
				
			||||||
	ErrInvalidCollateralLength    = types.ErrInvalidCollateralLength
 | 
						ErrInvalidCollateralRatio  = types.ErrInvalidCollateralRatio
 | 
				
			||||||
	ErrInvalidCollateralRatio     = types.ErrInvalidCollateralRatio
 | 
						ErrInvalidDebtRequest      = types.ErrInvalidDebtRequest
 | 
				
			||||||
	ErrInvalidDebtRequest         = types.ErrInvalidDebtRequest
 | 
						ErrInvalidDeposit          = types.ErrInvalidDeposit
 | 
				
			||||||
	ErrInvalidDeposit             = types.ErrInvalidDeposit
 | 
						ErrInvalidPayment          = types.ErrInvalidPayment
 | 
				
			||||||
	ErrInvalidPayment             = types.ErrInvalidPayment
 | 
						ErrInvalidWithdrawAmount   = types.ErrInvalidWithdrawAmount
 | 
				
			||||||
	ErrInvalidWithdrawAmount      = types.ErrInvalidWithdrawAmount
 | 
						ErrLoadingAugmentedCDP     = types.ErrLoadingAugmentedCDP
 | 
				
			||||||
	ErrLoadingAugmentedCDP        = types.ErrLoadingAugmentedCDP
 | 
						ErrNotLiquidatable         = types.ErrNotLiquidatable
 | 
				
			||||||
	ErrNotLiquidatable            = types.ErrNotLiquidatable
 | 
						ErrPricefeedDown           = types.ErrPricefeedDown
 | 
				
			||||||
	ErrPricefeedDown              = types.ErrPricefeedDown
 | 
						GovDenomKey                = types.GovDenomKey
 | 
				
			||||||
	GovDenomKey                   = types.GovDenomKey
 | 
						InterestFactorPrefix       = types.InterestFactorPrefix
 | 
				
			||||||
	InterestFactorPrefix          = types.InterestFactorPrefix
 | 
						KeyCircuitBreaker          = types.KeyCircuitBreaker
 | 
				
			||||||
	KeyCircuitBreaker             = types.KeyCircuitBreaker
 | 
						KeyCollateralParams        = types.KeyCollateralParams
 | 
				
			||||||
	KeyCollateralParams           = types.KeyCollateralParams
 | 
						KeyDebtLot                 = types.KeyDebtLot
 | 
				
			||||||
	KeyDebtLot                    = types.KeyDebtLot
 | 
						KeyDebtParam               = types.KeyDebtParam
 | 
				
			||||||
	KeyDebtParam                  = types.KeyDebtParam
 | 
						KeyDebtThreshold           = types.KeyDebtThreshold
 | 
				
			||||||
	KeyDebtThreshold              = types.KeyDebtThreshold
 | 
						KeyGlobalDebtLimit         = types.KeyGlobalDebtLimit
 | 
				
			||||||
	KeyGlobalDebtLimit            = types.KeyGlobalDebtLimit
 | 
						KeySurplusLot              = types.KeySurplusLot
 | 
				
			||||||
	KeySurplusLot                 = types.KeySurplusLot
 | 
						KeySurplusThreshold        = types.KeySurplusThreshold
 | 
				
			||||||
	KeySurplusThreshold           = types.KeySurplusThreshold
 | 
						MaxSortableDec             = types.MaxSortableDec
 | 
				
			||||||
	MaxSortableDec                = types.MaxSortableDec
 | 
						ModuleCdc                  = types.ModuleCdc
 | 
				
			||||||
	ModuleCdc                     = types.ModuleCdc
 | 
						PreviousAccrualTimePrefix  = types.PreviousAccrualTimePrefix
 | 
				
			||||||
	PreviousAccrualTimePrefix     = types.PreviousAccrualTimePrefix
 | 
						PricefeedStatusKeyPrefix   = types.PricefeedStatusKeyPrefix
 | 
				
			||||||
	PricefeedStatusKeyPrefix      = types.PricefeedStatusKeyPrefix
 | 
						PrincipalKeyPrefix         = types.PrincipalKeyPrefix
 | 
				
			||||||
	PrincipalKeyPrefix            = types.PrincipalKeyPrefix
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type (
 | 
					type (
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,6 @@ func (suite *GenesisTestSuite) TestInvalidGenState() {
 | 
				
			|||||||
		startingID         uint64
 | 
							startingID         uint64
 | 
				
			||||||
		debtDenom          string
 | 
							debtDenom          string
 | 
				
			||||||
		govDenom           string
 | 
							govDenom           string
 | 
				
			||||||
		savingsRateDist    sdk.Int
 | 
					 | 
				
			||||||
		genAccumTimes      cdp.GenesisAccumulationTimes
 | 
							genAccumTimes      cdp.GenesisAccumulationTimes
 | 
				
			||||||
		genTotalPrincipals cdp.GenesisTotalPrincipals
 | 
							genTotalPrincipals cdp.GenesisTotalPrincipals
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -54,7 +53,6 @@ func (suite *GenesisTestSuite) TestInvalidGenState() {
 | 
				
			|||||||
				deposits:           cdp.Deposits{},
 | 
									deposits:           cdp.Deposits{},
 | 
				
			||||||
				debtDenom:          "",
 | 
									debtDenom:          "",
 | 
				
			||||||
				govDenom:           cdp.DefaultGovDenom,
 | 
									govDenom:           cdp.DefaultGovDenom,
 | 
				
			||||||
				savingsRateDist:    cdp.DefaultSavingsRateDistributed,
 | 
					 | 
				
			||||||
				genAccumTimes:      cdp.DefaultGenesisState().PreviousAccumulationTimes,
 | 
									genAccumTimes:      cdp.DefaultGenesisState().PreviousAccumulationTimes,
 | 
				
			||||||
				genTotalPrincipals: cdp.DefaultGenesisState().TotalPrincipals,
 | 
									genTotalPrincipals: cdp.DefaultGenesisState().TotalPrincipals,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
@ -71,7 +69,6 @@ func (suite *GenesisTestSuite) TestInvalidGenState() {
 | 
				
			|||||||
				deposits:           cdp.Deposits{},
 | 
									deposits:           cdp.Deposits{},
 | 
				
			||||||
				debtDenom:          cdp.DefaultDebtDenom,
 | 
									debtDenom:          cdp.DefaultDebtDenom,
 | 
				
			||||||
				govDenom:           "",
 | 
									govDenom:           "",
 | 
				
			||||||
				savingsRateDist:    cdp.DefaultSavingsRateDistributed,
 | 
					 | 
				
			||||||
				genAccumTimes:      cdp.DefaultGenesisState().PreviousAccumulationTimes,
 | 
									genAccumTimes:      cdp.DefaultGenesisState().PreviousAccumulationTimes,
 | 
				
			||||||
				genTotalPrincipals: cdp.DefaultGenesisState().TotalPrincipals,
 | 
									genTotalPrincipals: cdp.DefaultGenesisState().TotalPrincipals,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
@ -88,7 +85,6 @@ func (suite *GenesisTestSuite) TestInvalidGenState() {
 | 
				
			|||||||
				deposits:           cdp.Deposits{},
 | 
									deposits:           cdp.Deposits{},
 | 
				
			||||||
				debtDenom:          cdp.DefaultDebtDenom,
 | 
									debtDenom:          cdp.DefaultDebtDenom,
 | 
				
			||||||
				govDenom:           cdp.DefaultGovDenom,
 | 
									govDenom:           cdp.DefaultGovDenom,
 | 
				
			||||||
				savingsRateDist:    sdk.NewInt(100),
 | 
					 | 
				
			||||||
				genAccumTimes:      cdp.GenesisAccumulationTimes{cdp.NewGenesisAccumulationTime("bnb-a", time.Time{}, sdk.OneDec().Sub(sdk.SmallestDec()))},
 | 
									genAccumTimes:      cdp.GenesisAccumulationTimes{cdp.NewGenesisAccumulationTime("bnb-a", time.Time{}, sdk.OneDec().Sub(sdk.SmallestDec()))},
 | 
				
			||||||
				genTotalPrincipals: cdp.DefaultGenesisState().TotalPrincipals,
 | 
									genTotalPrincipals: cdp.DefaultGenesisState().TotalPrincipals,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
@ -105,7 +101,6 @@ func (suite *GenesisTestSuite) TestInvalidGenState() {
 | 
				
			|||||||
				deposits:           cdp.Deposits{},
 | 
									deposits:           cdp.Deposits{},
 | 
				
			||||||
				debtDenom:          cdp.DefaultDebtDenom,
 | 
									debtDenom:          cdp.DefaultDebtDenom,
 | 
				
			||||||
				govDenom:           cdp.DefaultGovDenom,
 | 
									govDenom:           cdp.DefaultGovDenom,
 | 
				
			||||||
				savingsRateDist:    sdk.NewInt(100),
 | 
					 | 
				
			||||||
				genAccumTimes:      cdp.DefaultGenesisState().PreviousAccumulationTimes,
 | 
									genAccumTimes:      cdp.DefaultGenesisState().PreviousAccumulationTimes,
 | 
				
			||||||
				genTotalPrincipals: cdp.GenesisTotalPrincipals{cdp.NewGenesisTotalPrincipal("bnb-a", sdk.NewInt(-1))},
 | 
									genTotalPrincipals: cdp.GenesisTotalPrincipals{cdp.NewGenesisTotalPrincipal("bnb-a", sdk.NewInt(-1))},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
@ -152,7 +147,6 @@ func (suite *GenesisTestSuite) TestValidGenState() {
 | 
				
			|||||||
			appGS,
 | 
								appGS,
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestGenesisTestSuite(t *testing.T) {
 | 
					func TestGenesisTestSuite(t *testing.T) {
 | 
				
			||||||
 | 
				
			|||||||
@ -28,18 +28,17 @@ var (
 | 
				
			|||||||
		ConversionFactor: sdk.NewInt(6),
 | 
							ConversionFactor: sdk.NewInt(6),
 | 
				
			||||||
		DebtFloor:        sdk.NewInt(10000000),
 | 
							DebtFloor:        sdk.NewInt(10000000),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	DefaultCdpStartingID          = uint64(1)
 | 
						DefaultCdpStartingID    = uint64(1)
 | 
				
			||||||
	DefaultDebtDenom              = "debt"
 | 
						DefaultDebtDenom        = "debt"
 | 
				
			||||||
	DefaultGovDenom               = "ukava"
 | 
						DefaultGovDenom         = "ukava"
 | 
				
			||||||
	DefaultStableDenom            = "usdx"
 | 
						DefaultStableDenom      = "usdx"
 | 
				
			||||||
	DefaultSurplusThreshold       = sdk.NewInt(500000000000)
 | 
						DefaultSurplusThreshold = sdk.NewInt(500000000000)
 | 
				
			||||||
	DefaultDebtThreshold          = sdk.NewInt(100000000000)
 | 
						DefaultDebtThreshold    = sdk.NewInt(100000000000)
 | 
				
			||||||
	DefaultSurplusLot             = sdk.NewInt(10000000000)
 | 
						DefaultSurplusLot       = sdk.NewInt(10000000000)
 | 
				
			||||||
	DefaultDebtLot                = sdk.NewInt(10000000000)
 | 
						DefaultDebtLot          = sdk.NewInt(10000000000)
 | 
				
			||||||
	DefaultSavingsRateDistributed = sdk.NewInt(0)
 | 
						minCollateralPrefix     = 0
 | 
				
			||||||
	minCollateralPrefix           = 0
 | 
						maxCollateralPrefix     = 255
 | 
				
			||||||
	maxCollateralPrefix           = 255
 | 
						stabilityFeeMax         = sdk.MustNewDecFromStr("1.000000051034942716") // 500% APR
 | 
				
			||||||
	stabilityFeeMax               = sdk.MustNewDecFromStr("1.000000051034942716") // 500% APR
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Params governance parameters for cdp module
 | 
					// Params governance parameters for cdp module
 | 
				
			||||||
 | 
				
			|||||||
@ -6,18 +6,16 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Querier routes for the cdp module
 | 
					// Querier routes for the cdp module
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	QueryGetCdp                             = "cdp"
 | 
						QueryGetCdp                     = "cdp"
 | 
				
			||||||
	QueryGetCdps                            = "cdps"
 | 
						QueryGetCdps                    = "cdps"
 | 
				
			||||||
	QueryGetCdpDeposits                     = "deposits"
 | 
						QueryGetCdpDeposits             = "deposits"
 | 
				
			||||||
	QueryGetCdpsByCollateralization         = "ratio"          // legacy query, maintained for REST API
 | 
						QueryGetCdpsByCollateralization = "ratio"          // legacy query, maintained for REST API
 | 
				
			||||||
	QueryGetCdpsByCollateralType            = "collateralType" // legacy query, maintained for REST API
 | 
						QueryGetCdpsByCollateralType    = "collateralType" // legacy query, maintained for REST API
 | 
				
			||||||
	QueryGetParams                          = "params"
 | 
						QueryGetParams                  = "params"
 | 
				
			||||||
	QueryGetAccounts                        = "accounts"
 | 
						QueryGetAccounts                = "accounts"
 | 
				
			||||||
	QueryGetSavingsRateDistributed          = "savings-rate-dist"
 | 
						RestOwner                       = "owner"
 | 
				
			||||||
	QueryGetPreviousSavingsDistributionTime = "savings-rate-dist-time"
 | 
						RestCollateralType              = "collateral-type"
 | 
				
			||||||
	RestOwner                               = "owner"
 | 
						RestRatio                       = "ratio"
 | 
				
			||||||
	RestCollateralType                      = "collateral-type"
 | 
					 | 
				
			||||||
	RestRatio                               = "ratio"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// QueryCdpParams params for query /cdp/cdp
 | 
					// QueryCdpParams params for query /cdp/cdp
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user