2021-01-20 05:42:50 +00:00
|
|
|
package incentive_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2023-04-05 23:21:59 +00:00
|
|
|
sdkmath "cosmossdk.io/math"
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2021-01-20 05:42:50 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2022-01-08 00:39:27 +00:00
|
|
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
2021-01-20 05:42:50 +00:00
|
|
|
|
2024-05-01 03:17:24 +00:00
|
|
|
"github.com/0glabs/0g-chain/app"
|
|
|
|
cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
|
|
|
|
"github.com/0glabs/0g-chain/x/incentive/testutil"
|
|
|
|
pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
2021-01-20 05:42:50 +00:00
|
|
|
)
|
|
|
|
|
2021-07-15 14:05:54 +00:00
|
|
|
// Avoid cluttering test cases with long function names
|
2023-04-05 23:21:59 +00:00
|
|
|
func i(in int64) sdkmath.Int { return sdkmath.NewInt(in) }
|
2021-07-15 14:05:54 +00:00
|
|
|
func d(str string) sdk.Dec { return sdk.MustNewDecFromStr(str) }
|
|
|
|
func cs(coins ...sdk.Coin) sdk.Coins { return sdk.NewCoins(coins...) }
|
|
|
|
func c(denom string, amount int64) sdk.Coin { return sdk.NewInt64Coin(denom, amount) }
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewCDPGenStateMulti(cdc codec.JSONCodec) app.GenesisState {
|
|
|
|
cdpGenesis := cdptypes.GenesisState{
|
|
|
|
Params: cdptypes.Params{
|
2024-02-02 18:21:11 +00:00
|
|
|
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000),
|
|
|
|
SurplusAuctionThreshold: cdptypes.DefaultSurplusThreshold,
|
|
|
|
SurplusAuctionLot: cdptypes.DefaultSurplusLot,
|
|
|
|
DebtAuctionThreshold: cdptypes.DefaultDebtThreshold,
|
|
|
|
DebtAuctionLot: cdptypes.DefaultDebtLot,
|
|
|
|
LiquidationBlockInterval: cdptypes.DefaultBeginBlockerExecutionBlockInterval,
|
2022-01-08 00:39:27 +00:00
|
|
|
CollateralParams: cdptypes.CollateralParams{
|
2021-01-20 05:42:50 +00:00
|
|
|
{
|
|
|
|
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",
|
|
|
|
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",
|
|
|
|
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",
|
|
|
|
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",
|
|
|
|
ConversionFactor: i(8),
|
|
|
|
},
|
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
DebtParam: cdptypes.DebtParam{
|
2021-01-20 05:42:50 +00:00
|
|
|
Denom: "usdx",
|
|
|
|
ReferenceAsset: "usd",
|
|
|
|
ConversionFactor: i(6),
|
|
|
|
DebtFloor: i(10000000),
|
|
|
|
},
|
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
StartingCdpID: cdptypes.DefaultCdpStartingID,
|
|
|
|
DebtDenom: cdptypes.DefaultDebtDenom,
|
|
|
|
GovDenom: cdptypes.DefaultGovDenom,
|
|
|
|
CDPs: cdptypes.CDPs{},
|
|
|
|
PreviousAccumulationTimes: cdptypes.GenesisAccumulationTimes{
|
|
|
|
cdptypes.NewGenesisAccumulationTime("btc-a", time.Time{}, sdk.OneDec()),
|
|
|
|
cdptypes.NewGenesisAccumulationTime("xrp-a", time.Time{}, sdk.OneDec()),
|
|
|
|
cdptypes.NewGenesisAccumulationTime("busd-a", time.Time{}, sdk.OneDec()),
|
|
|
|
cdptypes.NewGenesisAccumulationTime("bnb-a", time.Time{}, sdk.OneDec()),
|
2021-01-20 05:42:50 +00:00
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
TotalPrincipals: cdptypes.GenesisTotalPrincipals{
|
|
|
|
cdptypes.NewGenesisTotalPrincipal("btc-a", sdk.ZeroInt()),
|
|
|
|
cdptypes.NewGenesisTotalPrincipal("xrp-a", sdk.ZeroInt()),
|
|
|
|
cdptypes.NewGenesisTotalPrincipal("busd-a", sdk.ZeroInt()),
|
|
|
|
cdptypes.NewGenesisTotalPrincipal("bnb-a", sdk.ZeroInt()),
|
2021-01-20 05:42:50 +00:00
|
|
|
},
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return app.GenesisState{cdptypes.ModuleName: cdc.MustMarshalJSON(&cdpGenesis)}
|
2021-01-20 05:42:50 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewPricefeedGenStateMultiFromTime(cdc codec.JSONCodec, t time.Time) app.GenesisState {
|
|
|
|
pfGenesis := pricefeedtypes.GenesisState{
|
|
|
|
Params: pricefeedtypes.Params{
|
|
|
|
Markets: []pricefeedtypes.Market{
|
2021-07-15 14:05:54 +00:00
|
|
|
{MarketID: "kava:usd", BaseAsset: "kava", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
2021-01-20 05:42:50 +00:00
|
|
|
{MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
|
|
|
{MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
|
|
|
{MarketID: "bnb:usd", BaseAsset: "bnb", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
|
|
|
{MarketID: "busd:usd", BaseAsset: "busd", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
2021-07-15 14:05:54 +00:00
|
|
|
{MarketID: "zzz:usd", BaseAsset: "zzz", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
2021-01-20 05:42:50 +00:00
|
|
|
},
|
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
PostedPrices: []pricefeedtypes.PostedPrice{
|
2021-07-15 14:05:54 +00:00
|
|
|
{
|
|
|
|
MarketID: "kava:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("2.00"),
|
|
|
|
Expiry: t.Add(1 * time.Hour),
|
|
|
|
},
|
2021-01-20 05:42:50 +00:00
|
|
|
{
|
|
|
|
MarketID: "btc:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("8000.00"),
|
2021-07-15 14:05:54 +00:00
|
|
|
Expiry: t.Add(1 * time.Hour),
|
2021-01-20 05:42:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
MarketID: "xrp:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("0.25"),
|
2021-07-15 14:05:54 +00:00
|
|
|
Expiry: t.Add(1 * time.Hour),
|
2021-01-20 05:42:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
MarketID: "bnb:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("17.25"),
|
2021-07-15 14:05:54 +00:00
|
|
|
Expiry: t.Add(1 * time.Hour),
|
2021-01-20 05:42:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
MarketID: "busd:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.OneDec(),
|
2021-07-15 14:05:54 +00:00
|
|
|
Expiry: t.Add(1 * time.Hour),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
MarketID: "zzz:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("2.00"),
|
|
|
|
Expiry: t.Add(1 * time.Hour),
|
2021-01-20 05:42:50 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return app.GenesisState{pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pfGenesis)}
|
2021-01-20 05:42:50 +00:00
|
|
|
}
|
|
|
|
|
2021-07-15 14:05:54 +00:00
|
|
|
func NewHardGenStateMulti(genTime time.Time) testutil.HardGenesisBuilder {
|
|
|
|
kavaMM := testutil.NewStandardMoneyMarket("ukava")
|
|
|
|
kavaMM.SpotMarketID = "kava:usd"
|
|
|
|
btcMM := testutil.NewStandardMoneyMarket("btcb")
|
|
|
|
btcMM.SpotMarketID = "btc:usd"
|
2021-01-20 05:42:50 +00:00
|
|
|
|
2021-07-15 14:05:54 +00:00
|
|
|
builder := testutil.NewHardGenesisBuilder().WithGenesisTime(genTime).
|
|
|
|
WithInitializedMoneyMarket(testutil.NewStandardMoneyMarket("usdx")).
|
|
|
|
WithInitializedMoneyMarket(kavaMM).
|
|
|
|
WithInitializedMoneyMarket(testutil.NewStandardMoneyMarket("bnb")).
|
|
|
|
WithInitializedMoneyMarket(btcMM).
|
|
|
|
WithInitializedMoneyMarket(testutil.NewStandardMoneyMarket("xrp")).
|
|
|
|
WithInitializedMoneyMarket(testutil.NewStandardMoneyMarket("zzz"))
|
|
|
|
return builder
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewStakingGenesisState(cdc codec.JSONCodec) app.GenesisState {
|
|
|
|
genState := stakingtypes.DefaultGenesisState()
|
2021-07-15 14:05:54 +00:00
|
|
|
genState.Params.BondDenom = "ukava"
|
|
|
|
return app.GenesisState{
|
2022-01-08 00:39:27 +00:00
|
|
|
stakingtypes.ModuleName: cdc.MustMarshalJSON(genState),
|
2021-01-20 05:42:50 +00:00
|
|
|
}
|
|
|
|
}
|