mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-13 03:25:20 +00:00
cae7503f7b
* Committee types (#899) * committee types * refactor to committee interface * include tokencommitee stringer method * add members to BaseCommittee * address revisions * update querier * update querier * fix compilation errors, tests, etc. * Update MsgVote with vote type (#900) * add vote to msg * update querier/rest * update example cli vote msg * remove incorrect comments * address revisions * update handler, stub keeper method * add vote type to vote struct * Committee module keeper logic for token holder governance (#902) * fix keeper/test compilation errors * fix keeper/test compilation errors pt 2 * add setters to committee interface * fix sims compilation errors * fix incentive tests compilation errors * update types, expected keepers * core keeper logic * don't allow bond denom * implement vote tallying * query proposal polling status * update module keepers in app.go * register committee interface * fix failing incentive test * commitee types tests * refactor GetProposalResult by committee types * update invariants * implement most proposal keeper tests * add nulls to custom enums * remove abstain vote type * add test for close proposal * remove outdated TODOs * update ProcessProposals * switch on committee type directly * reintroduce Abstain votes and update vote tallying * don't allow divide by 0 panics * delete unused setters on committee interface * clean up tally methods return values for querier * update enum validation to catch negative ints * reintroduce setters for sims compilation * address revisions * remove commented out test * implement ProcessProposals test * additional revisions * Committee migrations (#909) * add committee v14 legacy types * update migration imports for compile * addRegisterCodec() to committee v14 legacy types * migrate committee genesis state from v14 to v15 * set stability committee permissions properly * fix committee allowed params * migration test, kava-7 sample data * add concrete types to committees (#911) * revisions: migrate + tests * register msgs on legacy codec * Prepare Committee module for migrations (#906) * remove invariants * edits * fix abci test * fix keeper querier tests * add committee interface registration * use codec.Codec * don't allow null vote types * don't allow null tally option * minor spelling fixes * update example cli proposal * fix cli tally query * enable vote abstain from cli * include vote options in cli help text * call CloseProposal from handler * custom enum marshaling * committee: fix failing tests (#921) * fix failing tests * fix: spelling Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com> Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
245 lines
9.9 KiB
Go
245 lines
9.9 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"time"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
tmtime "github.com/tendermint/tendermint/types/time"
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/x/cdp"
|
|
committeetypes "github.com/kava-labs/kava/x/committee/types"
|
|
"github.com/kava-labs/kava/x/hard"
|
|
"github.com/kava-labs/kava/x/pricefeed"
|
|
)
|
|
|
|
func NewCDPGenStateMulti() app.GenesisState {
|
|
cdpGenesis := cdp.GenesisState{
|
|
Params: cdp.Params{
|
|
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000),
|
|
SurplusAuctionThreshold: cdp.DefaultSurplusThreshold,
|
|
SurplusAuctionLot: cdp.DefaultSurplusLot,
|
|
DebtAuctionThreshold: cdp.DefaultDebtThreshold,
|
|
DebtAuctionLot: cdp.DefaultDebtLot,
|
|
CollateralParams: cdp.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),
|
|
Prefix: 0x20,
|
|
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),
|
|
Prefix: 0x21,
|
|
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),
|
|
Prefix: 0x22,
|
|
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),
|
|
Prefix: 0x23,
|
|
SpotMarketID: "busd:usd",
|
|
LiquidationMarketID: "busd:usd",
|
|
ConversionFactor: i(8),
|
|
},
|
|
},
|
|
DebtParam: cdp.DebtParam{
|
|
Denom: "usdx",
|
|
ReferenceAsset: "usd",
|
|
ConversionFactor: i(6),
|
|
DebtFloor: i(10000000),
|
|
},
|
|
},
|
|
StartingCdpID: cdp.DefaultCdpStartingID,
|
|
DebtDenom: cdp.DefaultDebtDenom,
|
|
GovDenom: cdp.DefaultGovDenom,
|
|
CDPs: cdp.CDPs{},
|
|
PreviousAccumulationTimes: cdp.GenesisAccumulationTimes{
|
|
cdp.NewGenesisAccumulationTime("btc-a", time.Time{}, sdk.OneDec()),
|
|
cdp.NewGenesisAccumulationTime("xrp-a", time.Time{}, sdk.OneDec()),
|
|
cdp.NewGenesisAccumulationTime("busd-a", time.Time{}, sdk.OneDec()),
|
|
cdp.NewGenesisAccumulationTime("bnb-a", time.Time{}, sdk.OneDec()),
|
|
},
|
|
TotalPrincipals: cdp.GenesisTotalPrincipals{
|
|
cdp.NewGenesisTotalPrincipal("btc-a", sdk.ZeroInt()),
|
|
cdp.NewGenesisTotalPrincipal("xrp-a", sdk.ZeroInt()),
|
|
cdp.NewGenesisTotalPrincipal("busd-a", sdk.ZeroInt()),
|
|
cdp.NewGenesisTotalPrincipal("bnb-a", sdk.ZeroInt()),
|
|
},
|
|
}
|
|
return app.GenesisState{cdp.ModuleName: cdp.ModuleCdc.MustMarshalJSON(cdpGenesis)}
|
|
}
|
|
|
|
func NewPricefeedGenStateMulti() app.GenesisState {
|
|
pfGenesis := pricefeed.GenesisState{
|
|
Params: pricefeed.Params{
|
|
Markets: []pricefeed.Market{
|
|
{MarketID: "kava:usd", BaseAsset: "kava", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
|
{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},
|
|
{MarketID: "zzz:usd", BaseAsset: "zzz", QuoteAsset: "usd", Oracles: []sdk.AccAddress{}, Active: true},
|
|
},
|
|
},
|
|
PostedPrices: []pricefeed.PostedPrice{
|
|
{
|
|
MarketID: "kava:usd",
|
|
OracleAddress: sdk.AccAddress{},
|
|
Price: sdk.MustNewDecFromStr("2.00"),
|
|
Expiry: time.Now().Add(1 * time.Hour),
|
|
},
|
|
{
|
|
MarketID: "btc:usd",
|
|
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: "bnb:usd",
|
|
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: "zzz:usd",
|
|
OracleAddress: sdk.AccAddress{},
|
|
Price: sdk.MustNewDecFromStr("2.00"),
|
|
Expiry: time.Now().Add(1 * time.Hour),
|
|
},
|
|
},
|
|
}
|
|
return app.GenesisState{pricefeed.ModuleName: pricefeed.ModuleCdc.MustMarshalJSON(pfGenesis)}
|
|
}
|
|
|
|
func NewHardGenStateMulti() app.GenesisState {
|
|
loanToValue, _ := sdk.NewDecFromStr("0.6")
|
|
borrowLimit := sdk.NewDec(1000000000000000)
|
|
|
|
hardGS := hard.NewGenesisState(hard.NewParams(
|
|
hard.MoneyMarkets{
|
|
hard.NewMoneyMarket("usdx", hard.NewBorrowLimit(false, borrowLimit, loanToValue), "usdx:usd", sdk.NewInt(1000000), hard.NewInterestRateModel(sdk.MustNewDecFromStr("0.05"), sdk.MustNewDecFromStr("2"), sdk.MustNewDecFromStr("0.8"), sdk.MustNewDecFromStr("10")), sdk.MustNewDecFromStr("0.05"), sdk.ZeroDec()),
|
|
hard.NewMoneyMarket("ukava", hard.NewBorrowLimit(false, borrowLimit, loanToValue), "kava:usd", sdk.NewInt(1000000), hard.NewInterestRateModel(sdk.MustNewDecFromStr("0.05"), sdk.MustNewDecFromStr("2"), sdk.MustNewDecFromStr("0.8"), sdk.MustNewDecFromStr("10")), sdk.MustNewDecFromStr("0.05"), sdk.ZeroDec()),
|
|
hard.NewMoneyMarket("bnb", hard.NewBorrowLimit(false, borrowLimit, loanToValue), "bnb:usd", sdk.NewInt(1000000), hard.NewInterestRateModel(sdk.MustNewDecFromStr("0.05"), sdk.MustNewDecFromStr("2"), sdk.MustNewDecFromStr("0.8"), sdk.MustNewDecFromStr("10")), sdk.MustNewDecFromStr("0.05"), sdk.ZeroDec()),
|
|
hard.NewMoneyMarket("btcb", hard.NewBorrowLimit(false, borrowLimit, loanToValue), "btc:usd", sdk.NewInt(1000000), hard.NewInterestRateModel(sdk.MustNewDecFromStr("0.05"), sdk.MustNewDecFromStr("2"), sdk.MustNewDecFromStr("0.8"), sdk.MustNewDecFromStr("10")), sdk.MustNewDecFromStr("0.05"), sdk.ZeroDec()),
|
|
hard.NewMoneyMarket("xrp", hard.NewBorrowLimit(false, borrowLimit, loanToValue), "xrp:usd", sdk.NewInt(1000000), hard.NewInterestRateModel(sdk.MustNewDecFromStr("0.05"), sdk.MustNewDecFromStr("2"), sdk.MustNewDecFromStr("0.8"), sdk.MustNewDecFromStr("10")), sdk.MustNewDecFromStr("0.05"), sdk.ZeroDec()),
|
|
hard.NewMoneyMarket("zzz", hard.NewBorrowLimit(false, borrowLimit, loanToValue), "zzz:usd", sdk.NewInt(1000000), hard.NewInterestRateModel(sdk.MustNewDecFromStr("0.05"), sdk.MustNewDecFromStr("2"), sdk.MustNewDecFromStr("0.8"), sdk.MustNewDecFromStr("10")), sdk.MustNewDecFromStr("0.05"), sdk.ZeroDec()),
|
|
},
|
|
sdk.NewDec(10),
|
|
), hard.DefaultAccumulationTimes, hard.DefaultDeposits, hard.DefaultBorrows,
|
|
hard.DefaultTotalSupplied, hard.DefaultTotalBorrowed, hard.DefaultTotalReserves,
|
|
)
|
|
|
|
return app.GenesisState{hard.ModuleName: hard.ModuleCdc.MustMarshalJSON(hardGS)}
|
|
}
|
|
|
|
func NewAuthGenState(addresses []sdk.AccAddress, coins sdk.Coins) app.GenesisState {
|
|
coinsList := []sdk.Coins{}
|
|
for range addresses {
|
|
coinsList = append(coinsList, coins)
|
|
}
|
|
|
|
// Load up our primary user address
|
|
if len(addresses) >= 4 {
|
|
coinsList[3] = sdk.NewCoins(
|
|
sdk.NewCoin("bnb", sdk.NewInt(1000000000000000)),
|
|
sdk.NewCoin("ukava", sdk.NewInt(1000000000000000)),
|
|
sdk.NewCoin("btcb", sdk.NewInt(1000000000000000)),
|
|
sdk.NewCoin("xrp", sdk.NewInt(1000000000000000)),
|
|
sdk.NewCoin("zzz", sdk.NewInt(1000000000000000)),
|
|
)
|
|
}
|
|
|
|
return app.NewAuthGenState(addresses, coinsList)
|
|
}
|
|
|
|
func NewStakingGenesisState() app.GenesisState {
|
|
genState := staking.DefaultGenesisState()
|
|
genState.Params.BondDenom = "ukava"
|
|
return app.GenesisState{
|
|
staking.ModuleName: staking.ModuleCdc.MustMarshalJSON(genState),
|
|
}
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) SetupWithGenState() {
|
|
tApp := app.NewTestApp()
|
|
ctx := tApp.NewContext(true, abci.Header{Height: 1, Time: tmtime.Now()})
|
|
|
|
tApp.InitializeFromGenesisStates(
|
|
NewAuthGenState(suite.getAllAddrs(), cs(c("ukava", 1_000_000_000))),
|
|
NewStakingGenesisState(),
|
|
NewPricefeedGenStateMulti(),
|
|
NewCDPGenStateMulti(),
|
|
NewHardGenStateMulti(),
|
|
)
|
|
|
|
// Set up a god committee
|
|
committeeModKeeper := tApp.GetCommitteeKeeper()
|
|
godCommittee := committeetypes.MemberCommittee{
|
|
BaseCommittee: committeetypes.BaseCommittee{
|
|
ID: 1,
|
|
Description: "This committee is for testing.",
|
|
Members: suite.addrs[:2],
|
|
Permissions: []committeetypes.Permission{committeetypes.GodPermission{}},
|
|
VoteThreshold: d("0.667"),
|
|
ProposalDuration: time.Hour * 24 * 7,
|
|
TallyOption: committeetypes.FirstPastThePost,
|
|
},
|
|
}
|
|
committeeModKeeper.SetCommittee(ctx, godCommittee)
|
|
|
|
suite.app = tApp
|
|
suite.ctx = ctx
|
|
suite.keeper = tApp.GetIncentiveKeeper()
|
|
suite.hardKeeper = tApp.GetHardKeeper()
|
|
suite.stakingKeeper = tApp.GetStakingKeeper()
|
|
suite.committeeKeeper = committeeModKeeper
|
|
}
|