0g-chain/x/cdp/keeper/integration_test.go
Draco 614d4e40fe
Update cosmos-sdk to v0.47.7 (#1811)
* Update cometbft, cosmos, ethermint, and ibc-go

* Replace github.com/tendermint/tendermint by github.com/cometbft/cometbft

* Replace github.com/tendermint/tm-db by github.com/cometbft/cometbft-db

* Replace gogo/protobuf with cosmos/gogoproto & simapp replacement

* Replace cosmos-sdk/simapp/helpers with cosmos-sdk/testutil/sims

* Remove no longer used simulations

* Replace ibchost with ibcexported
See https://github.com/cosmos/ibc-go/blob/v7.2.2/docs/migrations/v6-to-v7.md#ibc-module-constants

* Add new consensus params keeper

* Add consensus keeper to blockers

* Fix keeper and module issues in app.go

* Add IsSendEnabledCoins and update SetParams interface changes

* Fix protobuf build for cosmos 47 (#1800)

* fix cp errors by using -f; fix lint by only linting our proto dir;
and use proofs.proto directly from ics23 for ibc-go v7

* run proto-all; commit updated third party deps and swagger changes

* regenerate proto files

* use correct gocosmos build plugin for buf

* re-gen all protobuf files to update paths for new gocosmos plugin

* update protoc and buf to latest versions

* fix staking keeper issues in app.go

* update tally handler for gov changes

* chain id fix and flag fixes

* update deps for cometbft 47.7 upgrade

* remove all module legacy queriers

* update stakingKeeper to pointer

* Replace ModuleCdc from govv1beta1 to govcodec

* remove simulations

* abci.LastCommitInfo → abci.CommitInfo

* Remove unused code in keys.go

* simapp.MakeTestEncodingConfig -> moduletestutil.MakeTestEncodingConfi

* Fix chain id issues in tests

* Fix remaining unit test issues

* Update changelog for upgrade

* Fix e2e tests using updated kvtool

* Update protonet to v47 compatible genesis

* Bump cometbft-db to v0.9.1-kava.1

* Update kvtool

* Remove extra changelog

* Fix merged rocksdb issues

* go mod cleanup

* Bump cometbft-db to v9 and go to 1.21

* Bump rocksdb version to v8.10.0

* Update kvtool to latest version

* Update gin to v1.9.0

* Use ibctm.ModuleName in app_test

* Fallback to genesis chain id instead of client toml

* Remove all simulations

* Fix cdp migrations issue with v47

* Update dependencies to correct tags

---------

Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
2024-02-06 17:54:10 -05:00

321 lines
14 KiB
Go

package keeper_test
import (
"time"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
tmtime "github.com/cometbft/cometbft/types/time"
"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/cdp/types"
pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types"
)
// Avoid cluttering test cases with long function names
func i(in int64) sdkmath.Int { return sdkmath.NewInt(in) }
func d(str string) sdk.Dec { return sdk.MustNewDecFromStr(str) }
func c(denom string, amount int64) sdk.Coin { return sdk.NewInt64Coin(denom, amount) }
func cs(coins ...sdk.Coin) sdk.Coins { return sdk.NewCoins(coins...) }
func NewPricefeedGenState(cdc codec.JSONCodec, asset string, price sdk.Dec) app.GenesisState {
pfGenesis := pricefeedtypes.GenesisState{
Params: pricefeedtypes.Params{
Markets: []pricefeedtypes.Market{
{MarketID: asset + ":usd", BaseAsset: asset, QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
},
},
PostedPrices: []pricefeedtypes.PostedPrice{
{
MarketID: asset + ":usd",
OracleAddress: sdk.AccAddress{},
Price: price,
Expiry: time.Now().Add(1 * time.Hour),
},
},
}
return app.GenesisState{pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pfGenesis)}
}
func NewCDPGenState(cdc codec.JSONCodec, asset string, liquidationRatio sdk.Dec) app.GenesisState {
cdpGenesis := types.GenesisState{
Params: types.Params{
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000),
SurplusAuctionThreshold: types.DefaultSurplusThreshold,
SurplusAuctionLot: types.DefaultSurplusLot,
DebtAuctionThreshold: types.DefaultDebtThreshold,
DebtAuctionLot: types.DefaultDebtLot,
LiquidationBlockInterval: types.DefaultBeginBlockerExecutionBlockInterval,
CollateralParams: types.CollateralParams{
{
Denom: asset,
Type: asset + "-a",
LiquidationRatio: liquidationRatio,
DebtLimit: sdk.NewInt64Coin("usdx", 1000000000000),
StabilityFee: sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
LiquidationPenalty: d("0.05"),
AuctionSize: i(100),
SpotMarketID: asset + ":usd",
LiquidationMarketID: asset + ":usd",
KeeperRewardPercentage: d("0.01"),
CheckCollateralizationIndexCount: i(10),
ConversionFactor: i(6),
},
},
DebtParam: types.DebtParam{
Denom: "usdx",
ReferenceAsset: "usd",
ConversionFactor: i(6),
DebtFloor: i(10000000),
},
},
StartingCdpID: types.DefaultCdpStartingID,
DebtDenom: types.DefaultDebtDenom,
GovDenom: types.DefaultGovDenom,
CDPs: types.CDPs{},
PreviousAccumulationTimes: types.GenesisAccumulationTimes{
types.NewGenesisAccumulationTime(asset+"-a", time.Time{}, sdk.OneDec()),
},
TotalPrincipals: types.GenesisTotalPrincipals{
types.NewGenesisTotalPrincipal(asset+"-a", sdk.ZeroInt()),
},
}
return app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(&cdpGenesis)}
}
func NewPricefeedGenStateMulti(cdc codec.JSONCodec) app.GenesisState {
pfGenesis := pricefeedtypes.GenesisState{
Params: pricefeedtypes.Params{
Markets: []pricefeedtypes.Market{
{MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
{MarketID: "btc:usd:30", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
{MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
{MarketID: "xrp:usd:30", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
{MarketID: "bnb:usd", BaseAsset: "bnb", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
{MarketID: "bnb:usd:30", BaseAsset: "bnb", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
{MarketID: "busd:usd", BaseAsset: "busd", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
{MarketID: "busd:usd:30", BaseAsset: "busd", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
},
},
PostedPrices: []pricefeedtypes.PostedPrice{
{
MarketID: "btc:usd",
OracleAddress: sdk.AccAddress{},
Price: sdk.MustNewDecFromStr("8000.00"),
Expiry: time.Now().Add(1 * time.Hour),
},
{
MarketID: "btc:usd:30",
OracleAddress: sdk.AccAddress{},
Price: sdk.MustNewDecFromStr("8000.00"),
Expiry: time.Now().Add(1 * time.Hour),
},
{
MarketID: "xrp:usd",
OracleAddress: sdk.AccAddress{},
Price: sdk.MustNewDecFromStr("0.25"),
Expiry: time.Now().Add(1 * time.Hour),
},
{
MarketID: "xrp:usd:30",
OracleAddress: sdk.AccAddress{},
Price: sdk.MustNewDecFromStr("0.25"),
Expiry: time.Now().Add(1 * time.Hour),
},
{
MarketID: "bnb:usd",
OracleAddress: sdk.AccAddress{},
Price: sdk.MustNewDecFromStr("17.25"),
Expiry: time.Now().Add(1 * time.Hour),
},
{
MarketID: "bnb:usd:30",
OracleAddress: sdk.AccAddress{},
Price: sdk.MustNewDecFromStr("17.25"),
Expiry: time.Now().Add(1 * time.Hour),
},
{
MarketID: "busd:usd",
OracleAddress: sdk.AccAddress{},
Price: sdk.OneDec(),
Expiry: time.Now().Add(1 * time.Hour),
},
{
MarketID: "busd:usd:30",
OracleAddress: sdk.AccAddress{},
Price: sdk.OneDec(),
Expiry: time.Now().Add(1 * time.Hour),
},
},
}
return app.GenesisState{pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pfGenesis)}
}
func NewCDPGenStateMulti(cdc codec.JSONCodec) app.GenesisState {
cdpGenesis := types.GenesisState{
Params: types.Params{
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000),
SurplusAuctionThreshold: types.DefaultSurplusThreshold,
SurplusAuctionLot: types.DefaultSurplusLot,
DebtAuctionThreshold: types.DefaultDebtThreshold,
DebtAuctionLot: types.DefaultDebtLot,
LiquidationBlockInterval: types.DefaultBeginBlockerExecutionBlockInterval,
CollateralParams: types.CollateralParams{
{
Denom: "xrp",
Type: "xrp-a",
LiquidationRatio: sdk.MustNewDecFromStr("2.0"),
DebtLimit: sdk.NewInt64Coin("usdx", 500000000000),
StabilityFee: sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
LiquidationPenalty: d("0.05"),
AuctionSize: i(7000000000),
SpotMarketID: "xrp:usd",
LiquidationMarketID: "xrp:usd:30",
KeeperRewardPercentage: d("0.01"),
CheckCollateralizationIndexCount: i(10),
ConversionFactor: i(6),
},
{
Denom: "btc",
Type: "btc-a",
LiquidationRatio: sdk.MustNewDecFromStr("1.5"),
DebtLimit: sdk.NewInt64Coin("usdx", 500000000000),
StabilityFee: sdk.MustNewDecFromStr("1.000000000782997609"), // %2.5 apr
LiquidationPenalty: d("0.025"),
AuctionSize: i(10000000),
SpotMarketID: "btc:usd",
LiquidationMarketID: "btc:usd:30",
KeeperRewardPercentage: d("0.01"),
CheckCollateralizationIndexCount: i(10),
ConversionFactor: i(8),
},
{
Denom: "bnb",
Type: "bnb-a",
LiquidationRatio: sdk.MustNewDecFromStr("1.5"),
DebtLimit: sdk.NewInt64Coin("usdx", 500000000000),
StabilityFee: sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
LiquidationPenalty: d("0.05"),
AuctionSize: i(50000000000),
SpotMarketID: "bnb:usd",
LiquidationMarketID: "bnb:usd:30",
KeeperRewardPercentage: d("0.01"),
CheckCollateralizationIndexCount: i(10),
ConversionFactor: i(8),
},
{
Denom: "busd",
Type: "busd-a",
LiquidationRatio: d("1.01"),
DebtLimit: sdk.NewInt64Coin("usdx", 500000000000),
StabilityFee: sdk.OneDec(), // %0 apr
LiquidationPenalty: d("0.05"),
AuctionSize: i(10000000000),
SpotMarketID: "busd:usd",
LiquidationMarketID: "busd:usd:30",
KeeperRewardPercentage: d("0.01"),
CheckCollateralizationIndexCount: i(10),
ConversionFactor: i(8),
},
},
DebtParam: types.DebtParam{
Denom: "usdx",
ReferenceAsset: "usd",
ConversionFactor: i(6),
DebtFloor: i(10000000),
},
},
StartingCdpID: types.DefaultCdpStartingID,
DebtDenom: types.DefaultDebtDenom,
GovDenom: types.DefaultGovDenom,
CDPs: types.CDPs{},
PreviousAccumulationTimes: types.GenesisAccumulationTimes{
types.NewGenesisAccumulationTime("btc-a", time.Time{}, sdk.OneDec()),
types.NewGenesisAccumulationTime("xrp-a", time.Time{}, sdk.OneDec()),
types.NewGenesisAccumulationTime("busd-a", time.Time{}, sdk.OneDec()),
types.NewGenesisAccumulationTime("bnb-a", time.Time{}, sdk.OneDec()),
},
TotalPrincipals: types.GenesisTotalPrincipals{
types.NewGenesisTotalPrincipal("btc-a", sdk.ZeroInt()),
types.NewGenesisTotalPrincipal("xrp-a", sdk.ZeroInt()),
types.NewGenesisTotalPrincipal("busd-a", sdk.ZeroInt()),
types.NewGenesisTotalPrincipal("bnb-a", sdk.ZeroInt()),
},
}
return app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(&cdpGenesis)}
}
func NewCDPGenStateHighDebtLimit(cdc codec.JSONCodec) app.GenesisState {
cdpGenesis := types.GenesisState{
Params: types.Params{
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 100000000000000),
SurplusAuctionThreshold: types.DefaultSurplusThreshold,
SurplusAuctionLot: types.DefaultSurplusLot,
DebtAuctionThreshold: types.DefaultDebtThreshold,
DebtAuctionLot: types.DefaultDebtLot,
LiquidationBlockInterval: types.DefaultBeginBlockerExecutionBlockInterval,
CollateralParams: types.CollateralParams{
{
Denom: "xrp",
Type: "xrp-a",
LiquidationRatio: sdk.MustNewDecFromStr("2.0"),
DebtLimit: sdk.NewInt64Coin("usdx", 50000000000000),
StabilityFee: sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
LiquidationPenalty: d("0.05"),
AuctionSize: i(7000000000),
SpotMarketID: "xrp:usd",
LiquidationMarketID: "xrp:usd",
KeeperRewardPercentage: d("0.01"),
CheckCollateralizationIndexCount: i(10),
ConversionFactor: i(6),
},
{
Denom: "btc",
Type: "btc-a",
LiquidationRatio: sdk.MustNewDecFromStr("1.5"),
DebtLimit: sdk.NewInt64Coin("usdx", 50000000000000),
StabilityFee: sdk.MustNewDecFromStr("1.000000000782997609"), // %2.5 apr
LiquidationPenalty: d("0.025"),
AuctionSize: i(10000000),
SpotMarketID: "btc:usd",
LiquidationMarketID: "btc:usd",
KeeperRewardPercentage: d("0.01"),
CheckCollateralizationIndexCount: i(10),
ConversionFactor: i(8),
},
},
DebtParam: types.DebtParam{
Denom: "usdx",
ReferenceAsset: "usd",
ConversionFactor: i(6),
DebtFloor: i(10000000),
},
},
StartingCdpID: types.DefaultCdpStartingID,
DebtDenom: types.DefaultDebtDenom,
GovDenom: types.DefaultGovDenom,
CDPs: types.CDPs{},
PreviousAccumulationTimes: types.GenesisAccumulationTimes{
types.NewGenesisAccumulationTime("btc-a", time.Time{}, sdk.OneDec()),
types.NewGenesisAccumulationTime("xrp-a", time.Time{}, sdk.OneDec()),
},
TotalPrincipals: types.GenesisTotalPrincipals{
types.NewGenesisTotalPrincipal("btc-a", sdk.ZeroInt()),
types.NewGenesisTotalPrincipal("xrp-a", sdk.ZeroInt()),
},
}
return app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(&cdpGenesis)}
}
func cdps() (cdps types.CDPs) {
_, addrs := app.GeneratePrivKeyAddressPairs(3)
c1 := types.NewCDP(uint64(1), addrs[0], sdk.NewCoin("xrp", sdkmath.NewInt(10000000)), "xrp-a", sdk.NewCoin("usdx", sdkmath.NewInt(8000000)), tmtime.Canonical(time.Now()), sdk.OneDec())
c2 := types.NewCDP(uint64(2), addrs[1], sdk.NewCoin("xrp", sdkmath.NewInt(100000000)), "xrp-a", sdk.NewCoin("usdx", sdkmath.NewInt(10000000)), tmtime.Canonical(time.Now()), sdk.OneDec())
c3 := types.NewCDP(uint64(3), addrs[1], sdk.NewCoin("btc", sdkmath.NewInt(1000000000)), "btc-a", sdk.NewCoin("usdx", sdkmath.NewInt(10000000)), tmtime.Canonical(time.Now()), sdk.OneDec())
c4 := types.NewCDP(uint64(4), addrs[2], sdk.NewCoin("xrp", sdkmath.NewInt(1000000000)), "xrp-a", sdk.NewCoin("usdx", sdkmath.NewInt(500000000)), tmtime.Canonical(time.Now()), sdk.OneDec())
cdps = append(cdps, c1, c2, c3, c4)
return
}