2019-12-03 14:35:40 +00:00
|
|
|
package cdp_test
|
|
|
|
|
|
|
|
import (
|
2019-12-07 01:25:25 +00:00
|
|
|
"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"
|
2019-12-03 14:35:40 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-12-07 01:25:25 +00:00
|
|
|
|
2024-02-06 22:54:10 +00:00
|
|
|
tmtime "github.com/cometbft/cometbft/types/time"
|
2020-04-30 14:13:31 +00:00
|
|
|
|
2024-08-03 09:51:56 +00:00
|
|
|
"github.com/0glabs/0g-chain/app"
|
|
|
|
"github.com/0glabs/0g-chain/x/cdp/types"
|
|
|
|
pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
2019-12-03 14:35:40 +00:00
|
|
|
)
|
|
|
|
|
2020-01-12 15:35:34 +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) }
|
2019-12-03 14:35:40 +00:00
|
|
|
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...) }
|
2019-12-07 01:25:25 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewPricefeedGenState(cdc codec.JSONCodec, asset string, price sdk.Dec) app.GenesisState {
|
|
|
|
pfGenesis := pricefeedtypes.GenesisState{
|
|
|
|
Params: pricefeedtypes.Params{
|
|
|
|
Markets: []pricefeedtypes.Market{
|
2020-04-30 14:13:31 +00:00
|
|
|
{MarketID: asset + ":usd", BaseAsset: asset, QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
2020-01-12 15:35:34 +00:00
|
|
|
},
|
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
PostedPrices: []pricefeedtypes.PostedPrice{
|
2020-04-30 14:13:31 +00:00
|
|
|
{
|
2020-01-12 15:35:34 +00:00
|
|
|
MarketID: asset + ":usd",
|
2019-12-07 01:25:25 +00:00
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: price,
|
2019-12-07 15:08:07 +00:00
|
|
|
Expiry: time.Now().Add(1 * time.Hour),
|
2019-12-07 01:25:25 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return app.GenesisState{pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pfGenesis)}
|
2019-12-07 01:25:25 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewCDPGenState(cdc codec.JSONCodec, asset string, liquidationRatio sdk.Dec) app.GenesisState {
|
|
|
|
cdpGenesis := types.GenesisState{
|
|
|
|
Params: types.Params{
|
2021-01-18 19:12:37 +00:00
|
|
|
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000),
|
2022-01-08 00:39:27 +00:00
|
|
|
SurplusAuctionThreshold: types.DefaultSurplusThreshold,
|
|
|
|
SurplusAuctionLot: types.DefaultSurplusLot,
|
|
|
|
DebtAuctionThreshold: types.DefaultDebtThreshold,
|
|
|
|
DebtAuctionLot: types.DefaultDebtLot,
|
|
|
|
CollateralParams: types.CollateralParams{
|
2019-12-07 01:25:25 +00:00
|
|
|
{
|
2021-01-18 19:12:37 +00:00
|
|
|
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(1000000000),
|
|
|
|
ConversionFactor: i(6),
|
|
|
|
SpotMarketID: asset + ":usd",
|
|
|
|
LiquidationMarketID: asset + ":usd",
|
|
|
|
KeeperRewardPercentage: d("0.01"),
|
|
|
|
CheckCollateralizationIndexCount: i(10),
|
2020-01-12 15:35:34 +00:00
|
|
|
},
|
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
DebtParam: types.DebtParam{
|
2020-04-27 14:40:34 +00:00
|
|
|
Denom: "usdx",
|
|
|
|
ReferenceAsset: "usd",
|
|
|
|
ConversionFactor: i(6),
|
|
|
|
DebtFloor: i(10000000),
|
2020-01-12 15:35:34 +00:00
|
|
|
},
|
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
StartingCdpID: types.DefaultCdpStartingID,
|
|
|
|
DebtDenom: types.DefaultDebtDenom,
|
|
|
|
GovDenom: types.DefaultGovDenom,
|
|
|
|
CDPs: types.CDPs{},
|
|
|
|
PreviousAccumulationTimes: types.GenesisAccumulationTimes{
|
|
|
|
types.NewGenesisAccumulationTime(asset+"-a", time.Time{}, sdk.OneDec()),
|
2021-01-18 19:12:37 +00:00
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
TotalPrincipals: types.GenesisTotalPrincipals{
|
|
|
|
types.NewGenesisTotalPrincipal(asset+"-a", sdk.ZeroInt()),
|
2021-01-18 19:12:37 +00:00
|
|
|
},
|
2020-01-12 15:35:34 +00:00
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(&cdpGenesis)}
|
2020-01-12 15:35:34 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewPricefeedGenStateMulti(cdc codec.JSONCodec) app.GenesisState {
|
|
|
|
pfGenesis := pricefeedtypes.GenesisState{
|
|
|
|
Params: pricefeedtypes.Params{
|
|
|
|
Markets: []pricefeedtypes.Market{
|
2020-04-30 14:13:31 +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},
|
2020-01-12 15:35:34 +00:00
|
|
|
},
|
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
PostedPrices: []pricefeedtypes.PostedPrice{
|
2020-04-30 14:13:31 +00:00
|
|
|
{
|
2020-01-12 15:35:34 +00:00
|
|
|
MarketID: "btc:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("8000.00"),
|
|
|
|
Expiry: time.Now().Add(1 * time.Hour),
|
|
|
|
},
|
2020-04-30 14:13:31 +00:00
|
|
|
{
|
2020-01-12 15:35:34 +00:00
|
|
|
MarketID: "xrp:usd",
|
|
|
|
OracleAddress: sdk.AccAddress{},
|
|
|
|
Price: sdk.MustNewDecFromStr("0.25"),
|
|
|
|
Expiry: time.Now().Add(1 * time.Hour),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return app.GenesisState{pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pfGenesis)}
|
2020-01-12 15:35:34 +00:00
|
|
|
}
|
2022-05-09 18:37:36 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func NewCDPGenStateMulti(cdc codec.JSONCodec) app.GenesisState {
|
|
|
|
cdpGenesis := types.GenesisState{
|
|
|
|
Params: types.Params{
|
2024-02-02 18:21:11 +00:00
|
|
|
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000),
|
|
|
|
SurplusAuctionThreshold: types.DefaultSurplusThreshold,
|
|
|
|
SurplusAuctionLot: types.DefaultSurplusLot,
|
|
|
|
DebtAuctionThreshold: types.DefaultDebtThreshold,
|
|
|
|
DebtAuctionLot: types.DefaultDebtLot,
|
|
|
|
LiquidationBlockInterval: types.DefaultBeginBlockerExecutionBlockInterval,
|
2022-01-08 00:39:27 +00:00
|
|
|
CollateralParams: types.CollateralParams{
|
2020-01-12 15:35:34 +00:00
|
|
|
{
|
2021-01-18 19:12:37 +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",
|
|
|
|
KeeperRewardPercentage: d("0.01"),
|
|
|
|
CheckCollateralizationIndexCount: i(10),
|
|
|
|
ConversionFactor: i(6),
|
2020-01-12 15:35:34 +00:00
|
|
|
},
|
|
|
|
{
|
2021-01-18 19:12:37 +00:00
|
|
|
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",
|
|
|
|
KeeperRewardPercentage: d("0.01"),
|
|
|
|
CheckCollateralizationIndexCount: i(10),
|
|
|
|
ConversionFactor: i(8),
|
2020-01-12 15:35:34 +00:00
|
|
|
},
|
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
DebtParam: types.DebtParam{
|
2020-04-27 14:40:34 +00:00
|
|
|
Denom: "usdx",
|
|
|
|
ReferenceAsset: "usd",
|
|
|
|
ConversionFactor: i(6),
|
|
|
|
DebtFloor: i(10000000),
|
2019-12-07 01:25:25 +00:00
|
|
|
},
|
|
|
|
},
|
2022-01-08 00:39:27 +00:00
|
|
|
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()),
|
2021-01-18 19:12:37 +00:00
|
|
|
},
|
|
|
|
TotalPrincipals: types.GenesisTotalPrincipals{
|
2022-01-08 00:39:27 +00:00
|
|
|
types.NewGenesisTotalPrincipal("btc-a", sdk.ZeroInt()),
|
|
|
|
types.NewGenesisTotalPrincipal("xrp-a", sdk.ZeroInt()),
|
2021-01-18 19:12:37 +00:00
|
|
|
},
|
2019-12-07 01:25:25 +00:00
|
|
|
}
|
2022-01-08 00:39:27 +00:00
|
|
|
return app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(&cdpGenesis)}
|
2019-12-07 15:08:07 +00:00
|
|
|
}
|
2020-01-12 15:35:34 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func cdps() (cdps types.CDPs) {
|
2020-01-12 15:35:34 +00:00
|
|
|
_, addrs := app.GeneratePrivKeyAddressPairs(3)
|
2023-04-05 23:21:59 +00:00
|
|
|
c1 := types.NewCDP(uint64(1), addrs[0], sdk.NewCoin("xrp", sdkmath.NewInt(100000000)), "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(50000000)), tmtime.Canonical(time.Now()), sdk.OneDec())
|
2020-01-12 15:35:34 +00:00
|
|
|
cdps = append(cdps, c1, c2, c3, c4)
|
|
|
|
return
|
|
|
|
}
|