From 974b6f98ae49dae0d610954c28ec2db3209e686c Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Wed, 25 Jan 2023 11:27:19 -0500 Subject: [PATCH 1/9] feat: create asset registry --- x/common/asset_registry.go | 76 +++++++++++++++++++++++++++++++ x/common/asset_registry_test.go | 79 +++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 x/common/asset_registry.go create mode 100644 x/common/asset_registry_test.go diff --git a/x/common/asset_registry.go b/x/common/asset_registry.go new file mode 100644 index 000000000..53ddb653f --- /dev/null +++ b/x/common/asset_registry.go @@ -0,0 +1,76 @@ +package common + +type assetRegistry map[string][]string + +var AssetRegistry assetRegistry + +func init() { + // map of base asset to supported quote assets + // quote assets are usually stables + AssetRegistry = map[string][]string{ + DenomBTC: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, + DenomETH: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, + DenomNIBI: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, + DenomATOM: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, + DenomOSMO: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, + DenomNUSD: {DenomUSD}, + DenomUSDC: {DenomUSD}, + DenomUSDT: {DenomUSD}, + } +} + +func (r assetRegistry) Pair(base string, quote string) AssetPair { + for _, q := range r[base] { + if q == quote { + return NewAssetPair(string(base), string(quote)) + } + } + + return "" +} + +// Returns all supported base denoms +func (r assetRegistry) BaseDenoms() []string { + var denoms []string + for d := range r { + denoms = append(denoms, d) + } + return denoms +} + +// Returns all supported quote denoms +func (r assetRegistry) QuoteDenoms() []string { + var denoms []string + for _, q := range r { + denoms = append(denoms, q...) + } + return denoms +} + +// Checks if the provided denom is a supportedd base denom +func (r assetRegistry) IsSupportedBaseDenom(denom string) bool { + _, ok := r[denom] + return ok +} + +// Checks if the provided denom is a supported quote denom +func (r assetRegistry) IsSupportedQuoteDenom(denom string) bool { + for _, q := range r { + for _, d := range q { + if d == denom { + return true + } + } + } + return false +} + +// Checks if the provided denom is a supported denom +func (r assetRegistry) IsSupportedDenom(denom string) bool { + return r.IsSupportedBaseDenom(string(denom)) || r.IsSupportedQuoteDenom(string(denom)) +} + +// Checks if the provided base and quote denoms are a supported pair +func (r assetRegistry) IsSupportedPair(base string, quote string) bool { + return r.IsSupportedBaseDenom(base) && r.IsSupportedQuoteDenom(quote) +} diff --git a/x/common/asset_registry_test.go b/x/common/asset_registry_test.go new file mode 100644 index 000000000..e539f838d --- /dev/null +++ b/x/common/asset_registry_test.go @@ -0,0 +1,79 @@ +package common + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestIsSupportedPair(t *testing.T) { + for base := range AssetRegistry { + for _, quote := range AssetRegistry[base] { + require.Truef(t, AssetRegistry.IsSupportedPair(base, quote), "%s:%s should be supported", base, quote) + } + } + + t.Log("test an unsupported pair") + require.False(t, AssetRegistry.IsSupportedPair(DenomATOM, DenomOSMO)) +} + +func TestPair(t *testing.T) { + for base := range AssetRegistry { + for _, quote := range AssetRegistry[base] { + require.Equal(t, NewAssetPair(base, quote), AssetRegistry.Pair(base, quote)) + } + } + + t.Log("test an unsupported pair") + require.Equal(t, AssetPair(""), AssetRegistry.Pair(DenomATOM, DenomOSMO)) + + t.Log("test an unsupported base asset") + require.Equal(t, AssetPair(""), AssetRegistry.Pair("unsuported_denom", DenomUSDC)) + + t.Log("test an unsupported quote asset") + require.Equal(t, AssetPair(""), AssetRegistry.Pair(DenomATOM, "unsupported_denom")) +} + +func TestBaseDenoms(t *testing.T) { + for base := range AssetRegistry { + require.Contains(t, AssetRegistry.BaseDenoms(), base) + } +} + +func TestIsSupportedBaseDenom(t *testing.T) { + for base := range AssetRegistry { + require.True(t, AssetRegistry.IsSupportedBaseDenom(base)) + } + require.False(t, AssetRegistry.IsSupportedBaseDenom("unsupported_denom")) +} + +func TestQuoteDenoms(t *testing.T) { + for base := range AssetRegistry { + for _, quote := range AssetRegistry[base] { + require.Contains(t, AssetRegistry.QuoteDenoms(), quote) + } + } +} + +func TestIsSupportedQuoteDenom(t *testing.T) { + for base := range AssetRegistry { + for _, quote := range AssetRegistry[base] { + require.True(t, AssetRegistry.IsSupportedQuoteDenom(quote)) + } + } + + require.False(t, AssetRegistry.IsSupportedQuoteDenom("unsupported_denom")) +} + +func TestIsSupportedDenom(t *testing.T) { + for _, base := range AssetRegistry.BaseDenoms() { + require.True(t, AssetRegistry.IsSupportedDenom(base)) + } + + for _, quote := range AssetRegistry.QuoteDenoms() { + require.True(t, AssetRegistry.IsSupportedDenom(quote)) + } + + t.Log("test an unsupported denom") + require.False(t, AssetRegistry.IsSupportedDenom("unsupported_denom")) +} From be0e82fa37f0e94f7bbc75a88e22eb9b836bfb38 Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Wed, 25 Jan 2023 11:33:47 -0500 Subject: [PATCH 2/9] refactor: move denoms to separate file --- x/common/common.go | 29 ++--------------------------- x/common/denoms.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 27 deletions(-) create mode 100644 x/common/denoms.go diff --git a/x/common/common.go b/x/common/common.go index de84233a6..fce93272f 100644 --- a/x/common/common.go +++ b/x/common/common.go @@ -15,40 +15,15 @@ import ( type AssetPair string const ( - // stablecoins - DenomUSDC = "uusdc" - DenomNUSD = "unusd" - DenomUSD = "uusd" - DenomUSDT = "uusdt" - - // crypto assets - DenomNIBI = "unibi" - DenomBTC = "ubtc" - DenomETH = "ueth" - - ModuleName = "common" - + ModuleName = "common" TreasuryPoolModuleAccount = "treasury_pool" - - PairSeparator = ":" + PairSeparator = ":" ) var ( // paired against USD - Pair_NIBI_USD = NewAssetPair(DenomNIBI, DenomUSD) - Pair_USDC_USD = NewAssetPair(DenomUSDC, DenomUSD) - Pair_BTC_USD = NewAssetPair(DenomBTC, DenomUSD) - Pair_ETH_USD = NewAssetPair(DenomETH, DenomUSD) - - // paired against NUSD - Pair_NIBI_NUSD = NewAssetPair(DenomNIBI, DenomNUSD) - Pair_USDC_NUSD = NewAssetPair(DenomUSDC, DenomNUSD) - Pair_BTC_NUSD = NewAssetPair(DenomBTC, DenomNUSD) - Pair_ETH_NUSD = NewAssetPair(DenomETH, DenomNUSD) - ErrInvalidTokenPair = sdkerrors.Register(ModuleName, 1, "invalid token pair") APrecision = uint256.NewInt().SetUint64(1) - // Precision for int representation in sdk.Int objects Precision = int64(1_000_000) ) diff --git a/x/common/denoms.go b/x/common/denoms.go new file mode 100644 index 000000000..5fe1f9448 --- /dev/null +++ b/x/common/denoms.go @@ -0,0 +1,22 @@ +package common + +const ( // stablecoins + DenomUSDC = "uusdc" + DenomNUSD = "unusd" + DenomUSD = "uusd" + DenomUSDT = "uusdt" +) + +var allStableDenoms = []string{DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT} + +const ( // volatile assets + DenomNIBI = "unibi" + DenomBTC = "ubtc" + DenomETH = "ueth" + DenomATOM = "uatom" + DenomOSMO = "uosmo" + DenomAVAX = "uavax" + DenomSOL = "usol" + DenomBNB = "ubnb" + DenomADA = "uada" +) From f946adb0cf0731bfde6e664176542c7b70378c37 Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Wed, 25 Jan 2023 11:46:35 -0500 Subject: [PATCH 3/9] refactor: use AssetRegistry instead of hard-coded constants --- simapp/testapp.go | 4 +- x/common/asset_registry.go | 10 +- x/common/common.go | 2 +- x/common/error_test.go | 4 +- x/oracle/keeper/ballot_test.go | 32 ++--- x/oracle/keeper/keeper_test.go | 4 +- x/oracle/keeper/msg_server_test.go | 18 +-- x/oracle/keeper/querier_test.go | 44 +++--- x/oracle/keeper/reward_test.go | 8 +- x/oracle/keeper/slash_test.go | 40 +++--- x/oracle/keeper/tally_fuzz_test.go | 8 +- x/oracle/keeper/update_exchange_rates_test.go | 110 +++++++------- x/oracle/simulation/decoder_test.go | 4 +- x/oracle/simulation/genesis.go | 10 +- x/oracle/simulation/operations.go | 2 +- x/oracle/types/ballot_test.go | 26 ++-- x/oracle/types/params.go | 8 +- x/perp/client/cli/cli_test.go | 76 +++++----- x/perp/genesis_test.go | 4 +- x/perp/keeper/calc_test.go | 2 +- x/perp/keeper/calc_unit_test.go | 24 ++-- .../keeper/clearing_house_integration_test.go | 34 ++--- x/perp/keeper/clearing_house_unit_test.go | 136 +++++++++--------- x/perp/keeper/grpc_query_test.go | 66 ++++----- x/perp/keeper/hooks_test.go | 16 +-- x/perp/keeper/liquidate_unit_test.go | 134 ++++++++--------- x/perp/keeper/margin_test.go | 12 +- x/perp/keeper/margin_unit_test.go | 82 +++++------ x/perp/keeper/msg_server_test.go | 48 +++---- x/perp/simulation/genesis.go | 2 +- x/perp/simulation/operations.go | 14 +- x/perp/types/msgs_test.go | 8 +- x/stablecoin/abci.go | 2 +- x/stablecoin/abci_test.go | 14 +- x/stablecoin/client/cli/cli_test.go | 4 +- x/stablecoin/keeper/collateral_ratio.go | 16 +-- x/stablecoin/keeper/collateral_ratio_test.go | 104 +++++++------- x/stablecoin/keeper/mint_burn_stable.go | 4 +- x/stablecoin/keeper/mint_burn_stable_test.go | 16 +-- x/vpool/abci_test.go | 12 +- x/vpool/client/cli/cli_test.go | 24 ++-- x/vpool/keeper/keeper_test.go | 100 ++++++------- x/vpool/keeper/pool_state_test.go | 22 +-- x/vpool/keeper/prices_test.go | 80 +++++------ x/vpool/keeper/query_server_test.go | 6 +- x/vpool/keeper/snapshot_test.go | 10 +- x/vpool/simulation/genesis.go | 2 +- x/vpool/types/gov_test.go | 2 +- x/vpool/types/pool_test.go | 32 ++--- x/vpool/types/snapshot_test.go | 8 +- x/wasm/cli/cli_test.go | 2 +- 51 files changed, 728 insertions(+), 724 deletions(-) diff --git a/simapp/testapp.go b/simapp/testapp.go index c633971b9..b9b22269c 100644 --- a/simapp/testapp.go +++ b/simapp/testapp.go @@ -36,8 +36,8 @@ func NewTestNibiruAppAndContext(shouldUseDefaultGenesis bool) (*NibiruTestApp, s newNibiruApp := NewTestNibiruApp(shouldUseDefaultGenesis) ctx := newNibiruApp.NewContext(false, tmproto.Header{}) - newNibiruApp.OracleKeeper.SetPrice(ctx, common.Pair_BTC_NUSD, sdk.NewDec(20000)) - // newNibiruApp.OracleKeeper.SetPrice(ctx, common.Pair_NIBI_NUSD, sdk.NewDec(10)) + newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(20000)) + // newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), sdk.NewDec(10)) newNibiruApp.OracleKeeper.SetPrice(ctx, "xxx:yyy", sdk.NewDec(20000)) return newNibiruApp, ctx diff --git a/x/common/asset_registry.go b/x/common/asset_registry.go index 53ddb653f..c426d4028 100644 --- a/x/common/asset_registry.go +++ b/x/common/asset_registry.go @@ -13,9 +13,13 @@ func init() { DenomNIBI: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, DenomATOM: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, DenomOSMO: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, - DenomNUSD: {DenomUSD}, - DenomUSDC: {DenomUSD}, - DenomUSDT: {DenomUSD}, + DenomAVAX: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, + DenomSOL: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, + DenomBNB: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, + DenomADA: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, + DenomNUSD: {DenomUSD, DenomUSDC}, + DenomUSDC: {DenomUSD, DenomNUSD}, + DenomUSDT: {DenomUSD, DenomNUSD, DenomUSDC}, } } diff --git a/x/common/common.go b/x/common/common.go index fce93272f..a540b6d83 100644 --- a/x/common/common.go +++ b/x/common/common.go @@ -101,7 +101,7 @@ func (pair AssetPair) QuoteDenom() string { func (pair AssetPair) Validate() error { split := strings.Split(pair.String(), PairSeparator) if len(split) != 2 { - return ErrInvalidTokenPair.Wrapf("invalid pair: %s", pair) + return ErrInvalidTokenPair.Wrap(pair.String()) } if err := sdk.ValidateDenom(split[0]); err != nil { diff --git a/x/common/error_test.go b/x/common/error_test.go index b65bbf8d0..5b274efc8 100644 --- a/x/common/error_test.go +++ b/x/common/error_test.go @@ -86,12 +86,12 @@ func TestCombineErrorsGeneric(t *testing.T) { {name: "type=[]string | mixed", in: []string{"", "abc", ""}, out: errors.New(": abc: ")}, // cases: fmt.Stringer - {name: "type=fmt.Stringer |", in: common.Pair_USDC_NUSD, out: errors.New("uusdc:unusd")}, + {name: "type=fmt.Stringer |", in: common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), out: errors.New("uusdc:unusd")}, // cases: []fmt.Stringer { name: "type=[]fmt.Stringer | happy", - in: []fmt.Stringer{common.Pair_BTC_NUSD, common.Pair_ETH_NUSD}, + in: []fmt.Stringer{common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)}, out: errors.New("ubtc:unusd: ueth:unusd")}, {name: "type=[]fmt.Stringer | empty", in: []fmt.Stringer{}, out: nil}, } diff --git a/x/oracle/keeper/ballot_test.go b/x/oracle/keeper/ballot_test.go index 6bf9d3bd6..14780ac2e 100644 --- a/x/oracle/keeper/ballot_test.go +++ b/x/oracle/keeper/ballot_test.go @@ -32,14 +32,14 @@ func TestOrganizeAggregate(t *testing.T) { staking.EndBlocker(ctx, input.StakingKeeper) btcBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(17), common.Pair_BTC_NUSD, ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(10), common.Pair_BTC_NUSD, ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(6), common.Pair_BTC_NUSD, ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[2], power), } ethBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(1000), common.Pair_ETH_NUSD, ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(1300), common.Pair_ETH_NUSD, ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(2000), common.Pair_ETH_NUSD, ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[2], power), } for i := range btcBallot { @@ -78,11 +78,11 @@ func TestOrganizeAggregate(t *testing.T) { // sort each ballot for comparison sort.Sort(btcBallot) sort.Sort(ethBallot) - sort.Sort(ballotMap[common.Pair_BTC_NUSD]) - sort.Sort(ballotMap[common.Pair_ETH_NUSD]) + sort.Sort(ballotMap[common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)]) + sort.Sort(ballotMap[common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)]) - require.Equal(t, btcBallot, ballotMap[common.Pair_BTC_NUSD]) - require.Equal(t, ethBallot, ballotMap[common.Pair_ETH_NUSD]) + require.Equal(t, btcBallot, ballotMap[common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)]) + require.Equal(t, ethBallot, ballotMap[common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)]) } func TestClearBallots(t *testing.T) { @@ -103,14 +103,14 @@ func TestClearBallots(t *testing.T) { staking.EndBlocker(ctx, input.StakingKeeper) btcBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(17), common.Pair_BTC_NUSD, ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(10), common.Pair_BTC_NUSD, ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(6), common.Pair_BTC_NUSD, ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[2], power), } ethBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(1000), common.Pair_ETH_NUSD, ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(1300), common.Pair_ETH_NUSD, ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(2000), common.Pair_ETH_NUSD, ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[2], power), } for i := range btcBallot { diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index fcdcb4cf4..440070e23 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -30,8 +30,8 @@ func TestParams(t *testing.T) { slashWindow := uint64(1000) minValidPerWindow := sdk.NewDecWithPrec(1, 4) whitelist := []common.AssetPair{ - common.Pair_BTC_NUSD, - common.Pair_ETH_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), } // Should really test validateParams, but skipping because obvious diff --git a/x/oracle/keeper/msg_server_test.go b/x/oracle/keeper/msg_server_test.go index 07f197d5d..e9a5a9df1 100644 --- a/x/oracle/keeper/msg_server_test.go +++ b/x/oracle/keeper/msg_server_test.go @@ -19,7 +19,7 @@ func TestMsgServer_FeederDelegation(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: randomExchangeRate, }, } @@ -86,43 +86,43 @@ func TestMsgServer_AggregatePrevoteVote(t *testing.T) { salt := "1" exchangeRates := types.ExchangeRateTuples{ { - Pair: common.Pair_NIBI_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } otherExchangeRate := types.ExchangeRateTuples{ { - Pair: common.Pair_NIBI_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } unintendedExchangeRateStr := types.ExchangeRateTuples{ { - Pair: common.Pair_NIBI_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { diff --git a/x/oracle/keeper/querier_test.go b/x/oracle/keeper/querier_test.go index 99c8c41bf..a1f4d1499 100644 --- a/x/oracle/keeper/querier_test.go +++ b/x/oracle/keeper/querier_test.go @@ -31,7 +31,7 @@ func TestQueryExchangeRate(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.Pair_ETH_NUSD, rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), rate) // empty request _, err := querier.ExchangeRate(ctx, nil) @@ -39,7 +39,7 @@ func TestQueryExchangeRate(t *testing.T) { // Query to grpc res, err := querier.ExchangeRate(ctx, &types.QueryExchangeRateRequest{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), }) require.NoError(t, err) require.Equal(t, rate, res.ExchangeRate) @@ -71,15 +71,15 @@ func TestQueryExchangeRates(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.Pair_BTC_NUSD, rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.Pair_ETH_NUSD, rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), rate) res, err := querier.ExchangeRates(ctx, &types.QueryExchangeRatesRequest{}) require.NoError(t, err) require.Equal(t, types.ExchangeRateTuples{ - {Pair: common.Pair_BTC_NUSD, ExchangeRate: rate}, - {Pair: common.Pair_ETH_NUSD, ExchangeRate: rate}, + {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: rate}, + {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: rate}, }, res.ExchangeRates) } @@ -89,12 +89,12 @@ func TestQueryExchangeRateTwap(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.SetPrice(input.Ctx, common.Pair_BTC_NUSD, rate) + input.OracleKeeper.SetPrice(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), rate) - _, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.Pair_ETH_NUSD}) + _, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)}) require.Error(t, err) - res, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.Pair_BTC_NUSD}) + res, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)}) require.NoError(t, err) require.Equal(t, sdk.MustNewDecFromStr("1700"), res.ExchangeRate) } @@ -114,25 +114,25 @@ func TestCalcTwap(t *testing.T) { // expected price: (9.5 * (35 - 30) + 8.5 * (30 - 20) + 9.0 * (20 - 5)) / 30 = 8.916666 { name: "spot price twap calc, t=(5,35]", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), priceSnapshots: []types.PriceSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Price: sdk.MustNewDecFromStr("90000.0"), TimestampMs: time.UnixMilli(1).UnixMilli(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Price: sdk.MustNewDecFromStr("9.0"), TimestampMs: time.UnixMilli(10).UnixMilli(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Price: sdk.MustNewDecFromStr("8.5"), TimestampMs: time.UnixMilli(20).UnixMilli(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Price: sdk.MustNewDecFromStr("9.5"), TimestampMs: time.UnixMilli(30).UnixMilli(), }, @@ -166,12 +166,12 @@ func TestCalcTwap(t *testing.T) { ctx = ctx.WithBlockTime(time.UnixMilli(0)) for _, reserve := range tc.priceSnapshots { ctx = ctx.WithBlockTime(time.UnixMilli(reserve.TimestampMs)) - input.OracleKeeper.SetPrice(ctx, common.Pair_BTC_NUSD, reserve.Price) + input.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserve.Price) } ctx = ctx.WithBlockTime(tc.currentBlockTime).WithBlockHeight(tc.currentBlockHeight) - price, err := querier.ExchangeRateTwap(sdk.WrapSDKContext(ctx), &types.QueryExchangeRateRequest{Pair: common.Pair_BTC_NUSD}) + price, err := querier.ExchangeRateTwap(sdk.WrapSDKContext(ctx), &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)}) require.NoError(t, err) require.EqualValuesf(t, tc.expectedPrice, price.ExchangeRate, @@ -186,17 +186,17 @@ func TestQueryActives(t *testing.T) { queryClient := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.Pair_BTC_NUSD, rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.Pair_NIBI_NUSD, rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.Pair_ETH_NUSD, rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), rate) res, err := queryClient.Actives(ctx, &types.QueryActivesRequest{}) require.NoError(t, err) targetPairs := []common.AssetPair{ - common.Pair_BTC_NUSD, - common.Pair_ETH_NUSD, - common.Pair_NIBI_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), } require.Equal(t, targetPairs, res.Actives) diff --git a/x/oracle/keeper/reward_test.go b/x/oracle/keeper/reward_test.go index c80419689..793a9b46e 100644 --- a/x/oracle/keeper/reward_test.go +++ b/x/oracle/keeper/reward_test.go @@ -57,7 +57,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { valPeriodicRewards := sdk.NewDecCoinsFromCoins(rewards). QuoDec(sdk.NewDec(int64(periods))). QuoDec(sdk.NewDec(int64(validators))) - keeper.AllocateRewards(t, input, common.Pair_NIBI_NUSD, sdk.NewCoins(rewards), periods) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), sdk.NewCoins(rewards), periods) for i := uint64(1); i <= periods; i++ { for valIndex := 0; valIndex < validators; valIndex++ { @@ -65,7 +65,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { // passes the current context block height for pre vote // then changes the height to current height + vote period for the vote makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{ - Pair: common.Pair_NIBI_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate, }}, valIndex) } @@ -82,8 +82,8 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { } // assert there are no rewards for pair - require.True(t, input.OracleKeeper.GatherRewardsForVotePeriod(input.Ctx, common.Pair_NIBI_NUSD).IsZero()) + require.True(t, input.OracleKeeper.GatherRewardsForVotePeriod(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)).IsZero()) // assert that there are no rewards instances - require.Empty(t, input.OracleKeeper.PairRewards.Indexes.RewardsByPair.ExactMatch(input.Ctx, common.Pair_NIBI_NUSD).PrimaryKeys()) + require.Empty(t, input.OracleKeeper.PairRewards.Indexes.RewardsByPair.ExactMatch(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)).PrimaryKeys()) } diff --git a/x/oracle/keeper/slash_test.go b/x/oracle/keeper/slash_test.go index 3bcb90163..068f72064 100644 --- a/x/oracle/keeper/slash_test.go +++ b/x/oracle/keeper/slash_test.go @@ -90,9 +90,9 @@ func TestSlashAndResetMissCounters(t *testing.T) { func TestInvalidVotesSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.Pair_NIBI_NUSD} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.Pair_NIBI_NUSD) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) votePeriodsPerWindow := types.NewDec(int64(input.OracleKeeper.SlashWindow(input.Ctx))).QuoInt64(int64(input.OracleKeeper.VotePeriod(input.Ctx))).TruncateInt64() slashFraction := input.OracleKeeper.SlashFraction(input.Ctx) @@ -102,13 +102,13 @@ func TestInvalidVotesSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, miss vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, i+1, input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[1], 0)) @@ -119,13 +119,13 @@ func TestInvalidVotesSlashing(t *testing.T) { // one more miss vote will inccur keeper.ValAddrs[1] slashing // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, miss vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) input.Ctx = input.Ctx.WithBlockHeight(votePeriodsPerWindow - 1) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -144,9 +144,9 @@ func TestWhitelistSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, i+1, input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[0], 0)) @@ -158,9 +158,9 @@ func TestWhitelistSlashing(t *testing.T) { // one more miss vote will inccur Account 1 slashing // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) input.Ctx = input.Ctx.WithBlockHeight(votePeriodsPerWindow - 1) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -171,19 +171,19 @@ func TestWhitelistSlashing(t *testing.T) { func TestNotPassedBallotSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.Pair_NIBI_NUSD} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.Pair_NIBI_NUSD) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[0], 0)) @@ -194,14 +194,14 @@ func TestNotPassedBallotSlashing(t *testing.T) { func TestAbstainSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.Pair_NIBI_NUSD} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.Pair_NIBI_NUSD) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) votePeriodsPerWindow := types.NewDec(int64(input.OracleKeeper.SlashWindow(input.Ctx))).QuoInt64(int64(input.OracleKeeper.VotePeriod(input.Ctx))).TruncateInt64() minValidPerWindow := input.OracleKeeper.MinValidPerWindow(input.Ctx) @@ -210,13 +210,13 @@ func TestAbstainSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, abstain vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: types.ZeroDec()}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: types.ZeroDec()}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[1], 0)) diff --git a/x/oracle/keeper/tally_fuzz_test.go b/x/oracle/keeper/tally_fuzz_test.go index 804512bbb..24e81e50d 100644 --- a/x/oracle/keeper/tally_fuzz_test.go +++ b/x/oracle/keeper/tally_fuzz_test.go @@ -131,11 +131,11 @@ func TestRemoveInvalidBallots(t *testing.T) { "x": types.ExchangeRateBallots{ {Pair: "x", ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, - common.Pair_BTC_NUSD: types.ExchangeRateBallots{ - {Pair: common.Pair_BTC_NUSD, ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD): types.ExchangeRateBallots{ + {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, - common.Pair_ETH_NUSD: types.ExchangeRateBallots{ - {Pair: common.Pair_BTC_NUSD, ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD): types.ExchangeRateBallots{ + {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, }, }, diff --git a/x/oracle/keeper/update_exchange_rates_test.go b/x/oracle/keeper/update_exchange_rates_test.go index b85d69d59..e41b8450a 100644 --- a/x/oracle/keeper/update_exchange_rates_test.go +++ b/x/oracle/keeper/update_exchange_rates_test.go @@ -23,7 +23,7 @@ import ( func TestOracleThreshold(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: randomExchangeRate, }, } @@ -120,15 +120,15 @@ func TestOracleThreshold(t *testing.T) { func TestOracleDrop(t *testing.T) { input, h := setup(t) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.Pair_NIBI_NUSD, randomExchangeRate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), randomExchangeRate) // Account 1, pair gov stable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) // Immediately swap halt after an illiquid oracle vote oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.Pair_NIBI_NUSD) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) require.Error(t, err) } @@ -142,7 +142,7 @@ func TestOracleTally(t *testing.T) { for i, rate := range rates { decExchangeRate := sdk.NewDecWithPrec(int64(rate*math.Pow10(keeper.OracleDecPrecision)), int64(keeper.OracleDecPrecision)) exchangeRateStr, err := types.ExchangeRateTuples{ - {ExchangeRate: decExchangeRate, Pair: common.Pair_BTC_NUSD}}.ToString() + {ExchangeRate: decExchangeRate, Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)}}.ToString() require.NoError(t, err) salt := fmt.Sprintf("%d", i) @@ -161,7 +161,7 @@ func TestOracleTally(t *testing.T) { } vote := types.NewExchangeRateBallot( - decExchangeRate, common.Pair_BTC_NUSD, valAddrs[i], power) + decExchangeRate, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), valAddrs[i], power) ballot = append(ballot, vote) // change power of every three validator @@ -221,7 +221,7 @@ func TestOracleTallyTiming(t *testing.T) { // all the keeper.Addrs vote for the block ... not last period block yet, so tally fails for i := range keeper.Addrs[:2] { - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_BTC_NUSD, ExchangeRate: randomExchangeRate}}, i) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, i) } params := input.OracleKeeper.GetParams(input.Ctx) @@ -230,13 +230,13 @@ func TestOracleTallyTiming(t *testing.T) { require.Equal(t, 0, int(input.Ctx.BlockHeight())) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.Pair_BTC_NUSD) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) require.Error(t, err) input.Ctx = input.Ctx.WithBlockHeight(int64(params.VotePeriod - 1)) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err = input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.Pair_BTC_NUSD) + _, err = input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) require.NoError(t, err) } @@ -246,13 +246,13 @@ func TestOracleRewardDistribution(t *testing.T) { input, h := setup(t) // Account 1, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_BTC_NUSD, ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_BTC_NUSD, ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) rewardAllocation := sdk.NewCoins(sdk.NewCoin("reward", sdk.NewInt(1*common.Precision))) - keeper.AllocateRewards(t, input, common.Pair_BTC_NUSD, rewardAllocation, 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), rewardAllocation, 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -266,26 +266,26 @@ func TestOracleRewardDistribution(t *testing.T) { func TestOracleRewardBand(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.Pair_NIBI_NUSD} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear pairs to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.Pair_NIBI_NUSD) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) rewardSpread := randomExchangeRate.Mul(input.OracleKeeper.RewardBand(input.Ctx).QuoInt64(2)) // no one will miss the vote // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate.Sub(rewardSpread)}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread)}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -295,13 +295,13 @@ func TestOracleRewardBand(t *testing.T) { // Account 1 will miss the vote due to raward band condition // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate.Sub(rewardSpread.Add(sdk.OneDec()))}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread.Add(sdk.OneDec()))}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -355,19 +355,19 @@ func TestOracleExchangeRate(t *testing.T) { // govstable has been chosen as referenceExchangeRate by highest voting power // Account 1, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_ETH_NUSD, ExchangeRate: ethStableExchangeRate}, {Pair: common.Pair_NIBI_NUSD, ExchangeRate: govStableExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableExchangeRate}}, 0) // Account 2, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_ETH_NUSD, ExchangeRate: ethStableExchangeRate}, {Pair: common.Pair_NIBI_NUSD, ExchangeRate: govStableExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableExchangeRate}}, 1) // Account 3, govstable, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: govStableExchangeRate}, {Pair: common.Pair_BTC_NUSD, ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableExchangeRate}, {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) - keeper.AllocateRewards(t, input, common.Pair_ETH_NUSD, sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, common.Pair_NIBI_NUSD, sdk.NewCoins(govStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), sdk.NewCoins(ethStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -403,13 +403,13 @@ func TestOracleEnsureSorted(t *testing.T) { ethStableRate3 := sdk.NewDec(int64(rand.Uint64() % 100000000)) // Account 1, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_ETH_NUSD, ExchangeRate: ethStableRate1}, {Pair: common.Pair_NIBI_NUSD, ExchangeRate: govStableRate1}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableRate1}, {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate1}}, 0) // Account 2, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_ETH_NUSD, ExchangeRate: ethStableRate2}, {Pair: common.Pair_NIBI_NUSD, ExchangeRate: govStableRate2}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableRate2}, {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate2}}, 1) // Account 3, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_ETH_NUSD, ExchangeRate: govStableRate3}, {Pair: common.Pair_NIBI_NUSD, ExchangeRate: ethStableRate3}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: govStableRate3}, {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: ethStableRate3}}, 2) require.NotPanics(t, func() { oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -427,31 +427,31 @@ func TestOracleExchangeRateVal5(t *testing.T) { // govstable has been chosen as reference pair by highest voting power // Account 1, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: govStableRate1}, {Pair: common.Pair_ETH_NUSD, ExchangeRate: ethStableRate1}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate1}, {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableRate1}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: govStableRate1}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate1}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: govStableRate1}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate1}}, 2) // Account 4, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: govStableRate2}, {Pair: common.Pair_ETH_NUSD, ExchangeRate: ethStableRate2}}, 3) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableRate2}}, 3) // Account 5, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: govStableRate2}, {Pair: common.Pair_ETH_NUSD, ExchangeRate: ethStableRate2}}, 4) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableRate2}}, 4) ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) - keeper.AllocateRewards(t, input, common.Pair_ETH_NUSD, sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, common.Pair_NIBI_NUSD, sdk.NewCoins(govStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), sdk.NewCoins(ethStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) - gotGovStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.Pair_NIBI_NUSD) + gotGovStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) require.NoError(t, err) - gotEthStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.Pair_ETH_NUSD) + gotEthStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)) require.NoError(t, err) require.Equal(t, govStableRate1, gotGovStableRate) @@ -485,15 +485,15 @@ func TestWhitelistedPairs(t *testing.T) { for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.Pair_NIBI_NUSD) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) // govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) // set btcstable for next vote period - params.Whitelist = []common.AssetPair{common.Pair_NIBI_NUSD, common.Pair_BTC_NUSD} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -503,15 +503,15 @@ func TestWhitelistedPairs(t *testing.T) { require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[2], 0)) // whitelisted pairs are {govstable, btcstable} - require.Equal(t, []common.AssetPair{common.Pair_BTC_NUSD, common.Pair_NIBI_NUSD}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) + require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) // govstable, missing btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) // delete btcstable for next vote period - params.Whitelist = []common.AssetPair{common.Pair_NIBI_NUSD} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -520,13 +520,13 @@ func TestWhitelistedPairs(t *testing.T) { require.Equal(t, uint64(1), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[2], 0)) // btcstable must be deleted - require.Equal(t, []common.AssetPair{common.Pair_NIBI_NUSD}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) - require.False(t, input.OracleKeeper.WhitelistedPairs.Has(input.Ctx, common.Pair_BTC_NUSD)) + require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) + require.False(t, input.OracleKeeper.WhitelistedPairs.Has(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD))) // govstable, no missing - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -542,11 +542,11 @@ func TestAbstainWithSmallStakingPower(t *testing.T) { for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.Pair_NIBI_NUSD) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD, ExchangeRate: sdk.ZeroDec()}}, 0) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: sdk.ZeroDec()}}, 0) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.Pair_NIBI_NUSD) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) require.Error(t, err) } diff --git a/x/oracle/simulation/decoder_test.go b/x/oracle/simulation/decoder_test.go index 6bf419996..78f613c89 100644 --- a/x/oracle/simulation/decoder_test.go +++ b/x/oracle/simulation/decoder_test.go @@ -34,8 +34,8 @@ func TestDecodeDistributionStore(t *testing.T) { aggregatePrevote := types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash([]byte("12345")), valAddr, 123) aggregateVote := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{ - {Pair: common.Pair_NIBI_NUSD, ExchangeRate: sdk.NewDecWithPrec(1234, 1)}, - {Pair: common.Pair_ETH_NUSD, ExchangeRate: sdk.NewDecWithPrec(4321, 1)}, + {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: sdk.NewDecWithPrec(1234, 1)}, + {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: sdk.NewDecWithPrec(4321, 1)}, }, valAddr) pair := "btc:usd" diff --git a/x/oracle/simulation/genesis.go b/x/oracle/simulation/genesis.go index 5d94b2fdb..99f4cfb9c 100644 --- a/x/oracle/simulation/genesis.go +++ b/x/oracle/simulation/genesis.go @@ -97,17 +97,17 @@ func RandomizedGenState(simState *module.SimulationState) { VoteThreshold: voteThreshold, RewardBand: rewardBand, Whitelist: []common.AssetPair{ - common.Pair_ETH_NUSD, - common.Pair_USDC_NUSD, - common.Pair_BTC_NUSD, - common.Pair_NIBI_NUSD, + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), }, SlashFraction: slashFraction, SlashWindow: slashWindow, MinValidPerWindow: minValidPerWindow, }, []types.ExchangeRateTuple{ - {Pair: common.Pair_BTC_NUSD, ExchangeRate: sdk.NewDec(20_000)}, + {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.NewDec(20_000)}, }, []types.FeederDelegation{}, []types.MissCounter{}, diff --git a/x/oracle/simulation/operations.go b/x/oracle/simulation/operations.go index c9c8e8a66..982aafb87 100644 --- a/x/oracle/simulation/operations.go +++ b/x/oracle/simulation/operations.go @@ -30,7 +30,7 @@ const ( ) var ( - whitelist = []common.AssetPair{common.Pair_BTC_NUSD, common.Pair_ETH_NUSD, common.Pair_NIBI_NUSD} + whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} voteHashMap map[string]string = make(map[string]string) ) diff --git a/x/oracle/types/ballot_test.go b/x/oracle/types/ballot_test.go index 9581ea1eb..8ad625f23 100644 --- a/x/oracle/types/ballot_test.go +++ b/x/oracle/types/ballot_test.go @@ -30,21 +30,21 @@ func TestToMap(t *testing.T) { { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.NewDec(1600), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.ZeroDec(), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.NewDec(1500), Power: 100, }, @@ -94,15 +94,15 @@ func TestToCrossRate(t *testing.T) { for _, data := range data { valAddr := sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()) if !data.base.IsZero() { - pbBase = append(pbBase, types.NewExchangeRateBallot(data.base, common.Pair_BTC_NUSD, valAddr, 100)) + pbBase = append(pbBase, types.NewExchangeRateBallot(data.base, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), valAddr, 100)) } - pbQuote = append(pbQuote, types.NewExchangeRateBallot(data.quote, common.Pair_BTC_NUSD, valAddr, 100)) + pbQuote = append(pbQuote, types.NewExchangeRateBallot(data.quote, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), valAddr, 100)) if !data.base.IsZero() && !data.quote.IsZero() { - cb = append(cb, types.NewExchangeRateBallot(data.base.Quo(data.quote), common.Pair_BTC_NUSD, valAddr, 100)) + cb = append(cb, types.NewExchangeRateBallot(data.base.Quo(data.quote), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), valAddr, 100)) } else { - cb = append(cb, types.NewExchangeRateBallot(sdk.ZeroDec(), common.Pair_BTC_NUSD, valAddr, 0)) + cb = append(cb, types.NewExchangeRateBallot(sdk.ZeroDec(), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), valAddr, 0)) } } @@ -134,7 +134,7 @@ func TestPBPower(t *testing.T) { power := sk.Validator(ctx, valAccAddrs[i]).GetConsensusPower(sdk.DefaultPowerReduction) vote := types.NewExchangeRateBallot( sdk.ZeroDec(), - common.Pair_ETH_NUSD, + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), valAccAddrs[i], power, ) @@ -153,7 +153,7 @@ func TestPBPower(t *testing.T) { faceValAddr := sdk.ValAddress(pubKey.Address()) fakeVote := types.NewExchangeRateBallot( sdk.OneDec(), - common.Pair_ETH_NUSD, + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), faceValAddr, 0, ) @@ -224,7 +224,7 @@ func TestPBWeightedMedian(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDec(int64(input)), - common.Pair_ETH_NUSD, + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), valAddr, power, ) @@ -291,7 +291,7 @@ func TestPBStandardDeviation(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDecWithPrec(int64(input*base), int64(types.OracleDecPrecision)), - common.Pair_ETH_NUSD, + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), valAddr, power, ) @@ -310,12 +310,12 @@ func TestPBStandardDeviationOverflow(t *testing.T) { pb := types.ExchangeRateBallots{types.NewExchangeRateBallot( sdk.ZeroDec(), - common.Pair_ETH_NUSD, + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), valAddr, 2, ), types.NewExchangeRateBallot( exchangeRate, - common.Pair_ETH_NUSD, + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), valAddr, 1, )} diff --git a/x/oracle/types/params.go b/x/oracle/types/params.go index ac08fe41f..11f2e22ea 100644 --- a/x/oracle/types/params.go +++ b/x/oracle/types/params.go @@ -38,10 +38,10 @@ var ( DefaultVoteThreshold = sdk.NewDecWithPrec(50, 2) // 50% DefaultRewardBand = sdk.NewDecWithPrec(2, 2) // 2% (-1, 1) DefaultWhitelist = []common.AssetPair{ - common.Pair_BTC_NUSD, - common.Pair_USDC_NUSD, - common.Pair_ETH_NUSD, - common.Pair_NIBI_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), } DefaultSlashFraction = sdk.NewDecWithPrec(1, 4) // 0.01% DefaultMinValidPerWindow = sdk.NewDecWithPrec(5, 2) // 5% diff --git a/x/perp/client/cli/cli_test.go b/x/perp/client/cli/cli_test.go index 4362a8724..8287f2033 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -51,7 +51,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -63,7 +63,7 @@ func (s *IntegrationTestSuite) SetupSuite() { }, }, { - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -81,11 +81,11 @@ func (s *IntegrationTestSuite) SetupSuite() { perpGenesis := perptypes.DefaultGenesis() perpGenesis.PairMetadata = []perptypes.PairMetadata{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), }, { - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, } @@ -94,12 +94,12 @@ func (s *IntegrationTestSuite) SetupSuite() { oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.Params.Whitelist = []common.AssetPair{ - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), } oracleGenesis.Params.VotePeriod = 1_000 oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.Pair_BTC_NUSD, ExchangeRate: sdk.NewDec(20_000)}, - {Pair: common.Pair_ETH_NUSD, ExchangeRate: sdk.NewDec(2_000)}, + {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.NewDec(20_000)}, + {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: sdk.NewDec(2_000)}, } genesisState[oracletypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(oracleGenesis) @@ -186,25 +186,25 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { val := s.network.Validators[0] user := s.users[0] - exchangeRate, err := testutilcli.QueryOracleExchangeRate(val.ClientCtx, common.Pair_BTC_NUSD) + exchangeRate, err := testutilcli.QueryOracleExchangeRate(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) s.T().Logf("0. current exchange rate is: %+v", exchangeRate) s.NoError(err) s.T().Log("A. check vpool balances") - reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.Pair_BTC_NUSD) + reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.NewDec(10*common.Precision), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_000*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("A. check trader has no existing positions") - _, err = testutilcli.QueryPosition(val.ClientCtx, common.Pair_BTC_NUSD, user) + _, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) s.Error(err) s.T().Log("B. open position") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "buy", - common.Pair_BTC_NUSD.String(), + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), /* leverage */ "1", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAssetLimit */ "1"}, @@ -213,18 +213,18 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("B. check vpool balance after open position") - reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.Pair_BTC_NUSD) + reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("9999833.336111064815586407"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_001*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("B. check trader position") - queryResp, err := testutilcli.QueryPosition(val.ClientCtx, common.Pair_BTC_NUSD, user) + queryResp, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.Pair_BTC_NUSD, queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("166.663888935184413593"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.OpenNotional) @@ -236,7 +236,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("C. open position with 2x leverage and zero baseAmtLimit") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "buy", - common.Pair_BTC_NUSD.String(), + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), /* leverage */ "2", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAmtLimit */ "0", @@ -245,11 +245,11 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("C. check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.Pair_BTC_NUSD, user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.Pair_BTC_NUSD, queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.975001249937503125"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(3*common.Precision), queryResp.Position.OpenNotional) @@ -260,7 +260,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("D. Open a reverse position smaller than the existing position") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "sell", - common.Pair_BTC_NUSD.String(), + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), /* leverage */ "1", /* quoteAmt */ "100", // 100 uNUSD /* baseAssetLimit */ "1", @@ -269,18 +269,18 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("D. Check vpool after opening reverse position") - reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.Pair_BTC_NUSD) + reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) s.NoError(err) s.T().Logf(" \n reserve assets: %+v \n", reserveAssets) s.EqualValues(sdk.MustNewDecFromStr("9999500.041663750215262154"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_002_999_900), reserveAssets.QuoteAssetReserve) s.T().Log("D. Check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.Pair_BTC_NUSD, user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.Pair_BTC_NUSD, queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.958336249784737846"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(2_999_900), queryResp.Position.OpenNotional) @@ -291,7 +291,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("E. Open a reverse position larger than the existing position") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "sell", - common.Pair_BTC_NUSD.String(), + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), /* leverage */ "1", /* quoteAmt */ "4000000", // 4*10^6 uNUSD /* baseAssetLimit */ "0", @@ -300,11 +300,11 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("E. Check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.Pair_BTC_NUSD, user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.Pair_BTC_NUSD, queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("-166.686111713005402945"), queryResp.Position.Size_) s.EqualValues(sdk.MustNewDecFromStr("1000100.000000000000000494"), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("1000100.000000000000000494"), queryResp.Position.Margin) @@ -315,13 +315,13 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("F. Close position") txResp, err = testutilcli.ExecTx(s.network, cli.ClosePositionCmd(), user, []string{ - common.Pair_BTC_NUSD.String(), + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), }) s.NoError(err) s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("F. check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.Pair_BTC_NUSD, user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) s.Error(err) s.T().Logf("query response: %+v", queryResp) @@ -335,12 +335,12 @@ func (s *IntegrationTestSuite) TestPositionEmptyAndClose() { user := s.users[0] // verify trader has no position (empty) - _, err := testutilcli.QueryPosition(val.ClientCtx, common.Pair_ETH_NUSD, user) + _, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), user) s.Error(err, "no position found") // close position should produce error _, err = testutilcli.ExecTx(s.network, cli.ClosePositionCmd(), user, []string{ - common.Pair_ETH_NUSD.String(), + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) } @@ -349,7 +349,7 @@ func (s *IntegrationTestSuite) TestQueryCumulativePremiumFractions() { val := s.network.Validators[0] s.T().Log("get cumulative funding payments") - queryResp, err := testutilcli.QueryCumulativePremiumFraction(val.ClientCtx, common.Pair_BTC_NUSD) + queryResp, err := testutilcli.QueryCumulativePremiumFraction(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) s.NoError(err) s.EqualValues(sdk.NewDec(2), queryResp.CumulativePremiumFraction) } @@ -359,7 +359,7 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { s.T().Log("opening a position with user 0") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[0], []string{ "buy", - common.Pair_BTC_NUSD.String(), + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), "10", // Leverage "1", // Quote asset amount "0.0000001", @@ -370,7 +370,7 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { // Remove margin to trigger bad debt on user 0 s.T().Log("removing margin on user 0....") _, err = testutilcli.ExecTx(s.network, cli.RemoveMarginCmd(), s.users[0], []string{ - common.Pair_BTC_NUSD.String(), + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), fmt.Sprintf("%s%s", "100", common.DenomNUSD), }) s.Contains(err.Error(), perptypes.ErrFailedRemoveMarginCanCauseBadDebt.Error()) @@ -378,7 +378,7 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { func (s *IntegrationTestSuite) TestX_AddMargin() { val := s.network.Validators[0] - pair := common.Pair_ETH_NUSD + pair := common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD) // Open a new position s.T().Log("opening a position with user 3....") @@ -410,7 +410,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { { name: "FAIL: position not found", args: []string{ - common.Pair_BTC_NUSD.String(), + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), fmt.Sprintf("%s%s", "10000", pair.QuoteDenom()), }, expectedCode: 1, @@ -437,7 +437,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidate a position that does not exist") _, err := testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.Pair_ETH_NUSD.String(), + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), s.users[1].String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) @@ -445,7 +445,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("opening a position with user 1....") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[1], []string{ "buy", - common.Pair_ETH_NUSD.String(), + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), "15", // Leverage "90000", // Quote asset amount "0", @@ -455,7 +455,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidate a position that is above maintenance margin mario") _, err = testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.Pair_ETH_NUSD.String(), + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), s.users[1].String(), }) s.Contains(err.Error(), "margin ratio is too healthy to liquidate") @@ -463,7 +463,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("opening a position with user 2...") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[2], []string{ "sell", - common.Pair_ETH_NUSD.String(), + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), "15", // Leverage "45000000", // Quote asset amount "0", @@ -479,7 +479,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidating user 1...") txResp, err = testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.Pair_ETH_NUSD.String(), + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), s.users[1].String(), }) s.NoError(err) diff --git a/x/perp/genesis_test.go b/x/perp/genesis_test.go index 81cc8526b..4d3b64e4e 100644 --- a/x/perp/genesis_test.go +++ b/x/perp/genesis_test.go @@ -39,9 +39,9 @@ func TestGenesis(t *testing.T) { // create some positions for i := int64(0); i < 100; i++ { addr := testutil.AccAddress() - app.PerpKeeper.Positions.Insert(ctx, collections.Join(common.Pair_NIBI_NUSD, addr), types.Position{ + app.PerpKeeper.Positions.Insert(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), addr), types.Position{ TraderAddress: addr.String(), - Pair: common.Pair_NIBI_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), Size_: sdk.NewDec(i + 1), Margin: sdk.NewDec(i * 2), OpenNotional: sdk.NewDec(i * 100), diff --git a/x/perp/keeper/calc_test.go b/x/perp/keeper/calc_test.go index 98ca599ba..fcb48129d 100644 --- a/x/perp/keeper/calc_test.go +++ b/x/perp/keeper/calc_test.go @@ -28,7 +28,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { marginDelta := sdk.OneDec() _, err := nibiruApp.PerpKeeper.CalcRemainMarginWithFundingPayment( ctx, types.Position{ - Pair: common.Pair_NIBI_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), }, marginDelta) require.ErrorIs(t, err, collections.ErrNotFound) }, diff --git a/x/perp/keeper/calc_unit_test.go b/x/perp/keeper/calc_unit_test.go index 425b2d3c0..2ebfb3f1e 100644 --- a/x/perp/keeper/calc_unit_test.go +++ b/x/perp/keeper/calc_unit_test.go @@ -37,9 +37,9 @@ func TestCalcFreeCollateralErrors(t *testing.T) { test: func() { k, mocks, ctx := getKeeper(t) - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.Pair_BTC_NUSD).Return(false) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(false) - pos := types.ZeroPosition(ctx, common.Pair_BTC_NUSD, testutil.AccAddress()) + pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), testutil.AccAddress()) _, err := k.calcFreeCollateral(ctx, pos) @@ -53,12 +53,12 @@ func TestCalcFreeCollateralErrors(t *testing.T) { k, mocks, ctx := getKeeper(t) mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.Pair_BTC_NUSD).Return(true) + ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.Pair_BTC_NUSD). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - pos := types.ZeroPosition(ctx, common.Pair_BTC_NUSD, testutil.AccAddress()) + pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), testutil.AccAddress()) freeCollateral, err := k.calcFreeCollateral(ctx, pos) @@ -150,7 +150,7 @@ func TestCalcFreeCollateralSuccess(t *testing.T) { pos := types.Position{ TraderAddress: testutil.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: tc.positionSize, Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(1000), @@ -159,19 +159,19 @@ func TestCalcFreeCollateralSuccess(t *testing.T) { } t.Log("mock vpool keeper") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.Pair_BTC_NUSD).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.Pair_BTC_NUSD). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.vpoolDirection, sdk.OneDec(), ).Return(tc.positionNotional, nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.vpoolDirection, sdk.OneDec(), 15*time.Minute, @@ -196,13 +196,13 @@ func TestGetLatestCumulativePremiumFraction(t *testing.T) { keeper, _, ctx := getKeeper(t) metadata := &types.PairMetadata{ - Pair: common.Pair_NIBI_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), } setPairMetadata(keeper, ctx, *metadata) latestCumulativePremiumFraction, err := keeper. - getLatestCumulativePremiumFraction(ctx, common.Pair_NIBI_NUSD) + getLatestCumulativePremiumFraction(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) require.NoError(t, err) assert.Equal(t, sdk.NewDec(2), latestCumulativePremiumFraction) diff --git a/x/perp/keeper/clearing_house_integration_test.go b/x/perp/keeper/clearing_house_integration_test.go index f4858a48b..51db37c57 100644 --- a/x/perp/keeper/clearing_house_integration_test.go +++ b/x/perp/keeper/clearing_house_integration_test.go @@ -63,7 +63,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing long position, go more long", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -87,7 +87,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing long position, decrease a bit", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -111,7 +111,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing long position, decrease a lot", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1060)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -169,7 +169,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing short position, go more short", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -193,7 +193,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing short position, decrease a bit", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -217,7 +217,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing short position, decrease a lot", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1060)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -267,7 +267,7 @@ func TestOpenPositionSuccess(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision*common.Precision), vpooltypes.VpoolConfig{ @@ -279,7 +279,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -294,11 +294,11 @@ func TestOpenPositionSuccess(t *testing.T) { } ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(time.Second * 5)) - resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.Pair_BTC_NUSD, tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) + resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) require.NoError(t, err) t.Log("assert position response") - assert.EqualValues(t, common.Pair_BTC_NUSD, resp.Position.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), resp.Position.Pair) assert.EqualValues(t, traderAddr.String(), resp.Position.TraderAddress) assert.EqualValues(t, tc.expectedMargin, resp.Position.Margin, "margin") assert.EqualValues(t, tc.expectedOpenNotional, resp.Position.OpenNotional, "open notional") @@ -315,9 +315,9 @@ func TestOpenPositionSuccess(t *testing.T) { assert.EqualValues(t, tc.expectedPositionNotional, resp.PositionNotional) t.Log("assert position in state") - position, err := nibiruApp.PerpKeeper.Positions.Get(ctx, collections.Join(common.Pair_BTC_NUSD, traderAddr)) + position, err := nibiruApp.PerpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr)) require.NoError(t, err) - assert.EqualValues(t, common.Pair_BTC_NUSD, position.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), position.Pair) assert.EqualValues(t, traderAddr.String(), position.TraderAddress) assert.EqualValues(t, tc.expectedMargin, position.Margin, "margin") assert.EqualValues(t, tc.expectedOpenNotional, position.OpenNotional, "open notional") @@ -330,7 +330,7 @@ func TestOpenPositionSuccess(t *testing.T) { ecosystemFundFee := nibiruApp.PerpKeeper.GetParams(ctx).EcosystemFundFeeRatio.Mul(exchangedNotional).RoundInt() testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionChangedEvent{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: traderAddr.String(), Margin: sdk.NewCoin(common.DenomNUSD, tc.expectedMargin.RoundInt()), PositionNotional: tc.expectedPositionNotional, @@ -384,7 +384,7 @@ func TestOpenPositionError(t *testing.T) { traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 999)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -519,7 +519,7 @@ func TestOpenPositionError(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /* tradeLimitRatio */ /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), @@ -533,7 +533,7 @@ func TestOpenPositionError(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -547,7 +547,7 @@ func TestOpenPositionError(t *testing.T) { } ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(time.Second * 5)) - resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.Pair_BTC_NUSD, tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) + resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) require.ErrorContains(t, err, tc.expectedErr.Error()) require.Nil(t, resp) }) diff --git a/x/perp/keeper/clearing_house_unit_test.go b/x/perp/keeper/clearing_house_unit_test.go index 1ae921475..cdb34bc13 100644 --- a/x/perp/keeper/clearing_house_unit_test.go +++ b/x/perp/keeper/clearing_house_unit_test.go @@ -116,7 +116,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -132,7 +132,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -153,7 +153,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { baseAmount, err := perpKeeper.swapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.side, sdk.NewDec(10), sdk.NewDec(1), @@ -181,7 +181,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -193,7 +193,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(50), @@ -203,7 +203,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -212,7 +212,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, ) @@ -255,7 +255,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -267,7 +267,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(101), @@ -277,7 +277,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -285,7 +285,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -330,7 +330,7 @@ func TestIncreasePosition(t *testing.T) { // funding payment causes negative margin aka bad debt initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(110), // 110 BTC Margin: sdk.NewDec(11), // 11 NUSD OpenNotional: sdk.NewDec(110), // 110 NUSD @@ -342,7 +342,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(110), @@ -352,7 +352,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(110), ). @@ -360,7 +360,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.2"), }) }, @@ -403,7 +403,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -415,7 +415,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(200), @@ -425,7 +425,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -433,7 +433,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -476,7 +476,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -488,7 +488,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(99), @@ -498,7 +498,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -506,7 +506,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -552,7 +552,7 @@ func TestIncreasePosition(t *testing.T) { // funding payment causes bad debt initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -564,7 +564,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(105), /*baseAssetLimit=*/ sdk.NewDec(100), @@ -574,7 +574,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -582,7 +582,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("-0.3"), }) }, @@ -656,7 +656,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 200 NUSD and unrealized PnL of +100 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -664,7 +664,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -683,7 +683,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of -5 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -691,7 +691,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -710,7 +710,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of -50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -718,7 +718,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -739,7 +739,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of +50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-150), // -150 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -747,7 +747,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -766,7 +766,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 105 NUSD and unrealized PnL of -5 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -774,7 +774,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -793,7 +793,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 150 NUSD and unrealized PnL of -50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -801,7 +801,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -826,7 +826,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -835,7 +835,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /*quoteAssetDirection=*/ tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ tc.quoteAssetLimit, @@ -910,7 +910,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 100 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -945,7 +945,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 95 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(105), // 105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -980,7 +980,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -1017,7 +1017,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 95 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-105), // -105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1052,7 +1052,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 99.75 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1087,7 +1087,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 75 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1122,7 +1122,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1131,7 +1131,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /*quoteAssetDirection=*/ tc.quoteAssetDir, /*quoteAssetAmount=*/ tc.quoteAmountToDecrease, /*baseAssetLimit=*/ tc.exchangedBaseAmount.Abs(), @@ -1140,7 +1140,7 @@ func TestDecreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1508,7 +1508,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -1521,7 +1521,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), ). @@ -1530,7 +1530,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1541,7 +1541,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /*quoteAssetDirection=*/ tc.mockQuoteDir, /*quoteAssetAmount=*/ tc.inputQuoteAmount.Mul(tc.inputLeverage).Sub(tc.mockQuoteAmount), /*baseAssetLimit=*/ sdk.MaxDec(tc.inputBaseAssetLimit.Sub(currentPosition.Size_.Abs()), sdk.ZeroDec()), @@ -1551,7 +1551,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1689,7 +1689,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1715,7 +1715,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(105), // 105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1743,7 +1743,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-105), // -105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1769,7 +1769,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1806,7 +1806,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1815,7 +1815,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1852,7 +1852,7 @@ func TestClosePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1891,7 +1891,7 @@ func TestClosePosition(t *testing.T) { PositionSize: sdk.ZeroDec(), RealizedPnl: tc.expectedRealizedPnl, UnrealizedPnlAfter: sdk.ZeroDec(), - BadDebt: sdk.NewCoin(common.Pair_BTC_NUSD.QuoteDenom(), sdk.ZeroInt()), + BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), sdk.ZeroInt()), MarkPrice: tc.newPositionNotional.Quo(tc.initialPosition.Size_.Abs()), FundingPayment: sdk.MustNewDecFromStr("0.02").Mul(tc.initialPosition.Size_), TransactionFee: sdk.NewInt64Coin(tc.initialPosition.Pair.QuoteDenom(), 0), @@ -1919,7 +1919,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { // user cannot close position due to bad debt initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -1940,7 +1940,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { // user cannot close position due to bad debt initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1969,7 +1969,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1979,7 +1979,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1988,7 +1988,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) diff --git a/x/perp/keeper/grpc_query_test.go b/x/perp/keeper/grpc_query_test.go index a8ba6de11..a7a006437 100644 --- a/x/perp/keeper/grpc_query_test.go +++ b/x/perp/keeper/grpc_query_test.go @@ -30,7 +30,7 @@ func initAppVpools( t.Log("initialize vpool and pair") assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), quoteAssetReserve, baseAssetReserve, vpooltypes.VpoolConfig{ @@ -42,12 +42,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_ETH_NUSD, + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -59,12 +59,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_NIBI_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -76,7 +76,7 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_NIBI_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) return ctx, nibiruApp, queryServer @@ -97,7 +97,7 @@ func TestQueryPosition(t *testing.T) { { name: "positive PnL", initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -114,7 +114,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, positive margin ratio", initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -131,7 +131,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, negative margin ratio", initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -166,7 +166,7 @@ func TestQueryPosition(t *testing.T) { sdk.WrapSDKContext(ctx), &types.QueryPositionRequest{ Trader: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), }, ) require.NoError(t, err) @@ -192,7 +192,7 @@ func TestQueryPositions(t *testing.T) { name: "positive PnL", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -200,7 +200,7 @@ func TestQueryPositions(t *testing.T) { LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -263,7 +263,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "empty string pair", initialPairMetadata: &types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -274,7 +274,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "pair metadata not found", initialPairMetadata: &types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -285,11 +285,11 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "returns single funding payment", initialPairMetadata: &types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), }, expectErr: false, expectedLatestCPF: sdk.ZeroDec(), @@ -304,7 +304,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { ctx, app, queryServer := initAppVpools(t, sdk.NewDec(481_000), sdk.NewDec(1_000)) t.Log("set index price") - app.OracleKeeper.SetPrice(ctx, common.Pair_BTC_NUSD, sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.OneDec()) t.Log("query cumulative premium fraction") resp, err := queryServer.CumulativePremiumFraction(sdk.WrapSDKContext(ctx), tc.query) @@ -339,7 +339,7 @@ func TestQueryMetrics(t *testing.T) { name: "two longs", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -347,7 +347,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -361,7 +361,7 @@ func TestQueryMetrics(t *testing.T) { name: "two shorts", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -369,7 +369,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -383,7 +383,7 @@ func TestQueryMetrics(t *testing.T) { name: "one long, one short", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -391,7 +391,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -405,14 +405,14 @@ func TestQueryMetrics(t *testing.T) { name: "decrease position", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -427,42 +427,42 @@ func TestQueryMetrics(t *testing.T) { name: "swap positions", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), @@ -488,7 +488,7 @@ func TestQueryMetrics(t *testing.T) { // Detect position decrease app.PerpKeeper.OnSwapEnd( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), position.OpenNotional, position.Size_, ) @@ -498,7 +498,7 @@ func TestQueryMetrics(t *testing.T) { resp, err := queryServer.Metrics( sdk.WrapSDKContext(ctx), &types.QueryMetricsRequest{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), }, ) require.NoError(t, err) diff --git a/x/perp/keeper/hooks_test.go b/x/perp/keeper/hooks_test.go index 803a54dce..74a53b005 100644 --- a/x/perp/keeper/hooks_test.go +++ b/x/perp/keeper/hooks_test.go @@ -50,7 +50,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { markPrice: sdk.NewDec(10), expectedLatestCumulativePremiumFraction: sdk.ZeroDec(), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), MarkPrice: sdk.NewDec(10), IndexPrice: sdk.NewDec(10), LatestFundingRate: sdk.ZeroDec(), @@ -66,7 +66,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { indexPrice: sdk.NewDec(462), expectedLatestCumulativePremiumFraction: sdk.MustNewDecFromStr("-9.229166666666666666"), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), MarkPrice: sdk.NewDec(19), IndexPrice: sdk.NewDec(462), LatestFundingRate: sdk.MustNewDecFromStr("-0.019976551226551227"), @@ -82,7 +82,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { indexPrice: sdk.NewDec(64), expectedLatestCumulativePremiumFraction: sdk.MustNewDecFromStr("14.1875"), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), MarkPrice: sdk.NewDec(745), IndexPrice: sdk.NewDec(64), LatestFundingRate: sdk.MustNewDecFromStr("0.2216796875"), @@ -107,7 +107,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { perpKeeper.AfterEpochEnd(ctx, "30 min", 1) t.Log("assert PairMetadataState") - pair, err := perpKeeper.PairsMetadata.Get(ctx, common.Pair_BTC_NUSD) + pair, err := perpKeeper.PairsMetadata.Get(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) require.NoError(t, err) assert.Equal(t, tc.expectedLatestCumulativePremiumFraction, pair.LatestCumulativePremiumFraction) @@ -130,23 +130,23 @@ func initParams(ctx sdk.Context, k Keeper) { TwapLookbackWindow: 15 * time.Minute, }) setPairMetadata(k, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), // start with one entry to ensure we append LatestCumulativePremiumFraction: sdk.ZeroDec(), }) } func setMocks(ctx sdk.Context, mocks mockedDependencies, indexPrice sdk.Dec, markPrice sdk.Dec) { - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.Pair_BTC_NUSD).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true) mocks.mockEpochKeeper.EXPECT().GetEpochInfo(ctx, "30 min").Return( epochtypes.EpochInfo{Duration: 30 * time.Minute}, ).MaxTimes(1) mocks.mockOracleKeeper.EXPECT(). - GetExchangeRateTwap(ctx, common.Pair_BTC_NUSD).Return(indexPrice, nil).MaxTimes(1) + GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(indexPrice, nil).MaxTimes(1) mocks.mockVpoolKeeper.EXPECT(). - GetMarkPriceTWAP(ctx, common.Pair_BTC_NUSD, 15*time.Minute). + GetMarkPriceTWAP(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), 15*time.Minute). Return(markPrice, nil).MaxTimes(1) } diff --git a/x/perp/keeper/liquidate_unit_test.go b/x/perp/keeper/liquidate_unit_test.go index 21a932c2d..f65f02f36 100644 --- a/x/perp/keeper/liquidate_unit_test.go +++ b/x/perp/keeper/liquidate_unit_test.go @@ -90,7 +90,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -103,25 +103,25 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.Pair_BTC_NUSD).Return(true).Times(2) + ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.Pair_BTC_NUSD). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.Pair_BTC_NUSD).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.Pair_BTC_NUSD).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.OneDec(), 15*time.Minute, @@ -130,7 +130,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.OneDec(), ). @@ -138,7 +138,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.exchangedSize, ). @@ -146,7 +146,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /* quoteAmt */ tc.exchangedNotional, /* baseLimit */ sdk.ZeroDec(), @@ -178,16 +178,16 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.Pair_BTC_NUSD, traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee, feeToFund) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.Pair_BTC_NUSD, traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr)) require.NoError(t, err) assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.Pair_BTC_NUSD, newPosition.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), newPosition.Pair) assert.EqualValues(t, tc.expectedPositionSize, newPosition.Size_) assert.EqualValues(t, tc.expectedPositionMargin, newPosition.Margin) assert.EqualValues(t, tc.expectedPositionOpenNotional, newPosition.OpenNotional) @@ -195,7 +195,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.exchangedNotional, ExchangedPositionSize: tc.exchangedSize.Neg(), @@ -265,7 +265,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -278,24 +278,24 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.Pair_BTC_NUSD).Return(true).Times(2) + ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.Pair_BTC_NUSD). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.Pair_BTC_NUSD).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.Pair_BTC_NUSD).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, 15*time.Minute, @@ -304,7 +304,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -312,7 +312,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /* baseAmt */ tc.initialPositionSize, /* quoteLimit */ sdk.ZeroDec(), @@ -346,18 +346,18 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.Pair_BTC_NUSD, traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee.String(), feeToFund.String()) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.Pair_BTC_NUSD, traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr)) require.ErrorIs(t, err, collections.ErrNotFound) assert.Empty(t, newPosition) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.newPositionNotional, ExchangedPositionSize: tc.initialPositionSize.Neg(), @@ -436,7 +436,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -449,24 +449,24 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.Pair_BTC_NUSD).Return(true).Times(2) + ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.Pair_BTC_NUSD). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.Pair_BTC_NUSD).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.Pair_BTC_NUSD).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, 15*time.Minute, @@ -475,7 +475,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -483,7 +483,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /* baseAmt */ tc.initialPositionSize, /* quoteLimit */ sdk.ZeroDec(), @@ -520,18 +520,18 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.Pair_BTC_NUSD, traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee.String(), feeToFund.String()) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.Pair_BTC_NUSD, traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr)) require.ErrorIs(t, err, collections.ErrNotFound) assert.Empty(t, newPosition) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.newPositionNotional, ExchangedPositionSize: tc.initialPositionSize.Neg(), @@ -587,7 +587,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { test: func() { perpKeeper, mocks, ctx := getKeeper(t) liquidator := testutilevents.AccAddress() - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.Pair_BTC_NUSD).Return(false) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(false) err := perpKeeper.distributeLiquidateRewards(ctx, types.LiquidateResp{ @@ -597,7 +597,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { Liquidator: liquidator.String(), PositionResp: &types.PositionResp{ Position: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), }, }, }, @@ -612,7 +612,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { perpKeeper, mocks, ctx := getKeeper(t) liquidator := testutilevents.AccAddress() - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.Pair_BTC_NUSD).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true) mocks.mockAccountKeeper. EXPECT().GetModuleAddress(types.VaultModuleAccount). @@ -638,7 +638,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { Liquidator: liquidator.String(), PositionResp: &types.PositionResp{ Position: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), }}, }, ) @@ -928,16 +928,16 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { newParams.LiquidationFeeRatio = tc.liquidationFee perpKeeper.SetParams(ctx, newParams) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.Pair_BTC_NUSD).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -945,20 +945,20 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), /* skipFluctuationLimitCheck */ true, ).Return( /*quoteAssetAmount=*/ tc.baseAssetPriceInQuote, nil) mocks.mockVpoolKeeper.EXPECT(). - GetMarkPrice(ctx, common.Pair_BTC_NUSD). + GetMarkPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). Return(sdk.OneDec(), nil) t.Log("create and set the initial position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialMargin, OpenNotional: tc.initialOpenNotional, @@ -996,7 +996,7 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { t.Log("assert new position fields") newPosition := positionResp.Position assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.Pair_BTC_NUSD, newPosition.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), newPosition.Pair) assert.True(t, newPosition.Size_.IsZero()) // always zero assert.True(t, newPosition.Margin.IsZero()) // always zero assert.True(t, newPosition.OpenNotional.IsZero()) // always zero @@ -1004,15 +1004,15 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: positionResp.ExchangedNotionalValue, ExchangedPositionSize: positionResp.ExchangedPositionSize, LiquidatorAddress: liquidatorAddr.String(), - FeeToLiquidator: sdk.NewCoin(common.Pair_BTC_NUSD.QuoteDenom(), tc.expectedFundsToLiquidator), - FeeToEcosystemFund: sdk.NewCoin(common.Pair_BTC_NUSD.QuoteDenom(), tc.expectedFundsToPerpEF), + FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), tc.expectedFundsToLiquidator), + FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), tc.expectedFundsToPerpEF), BadDebt: sdk.NewCoin(common.DenomNUSD, tc.expectedLiquidationBadDebt), - Margin: sdk.NewCoin(common.Pair_BTC_NUSD.QuoteDenom(), newPosition.Margin.RoundInt()), + Margin: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), newPosition.Margin.RoundInt()), PositionNotional: positionResp.PositionNotional, PositionSize: newPosition.Size_, UnrealizedPnl: positionResp.UnrealizedPnlAfter, @@ -1219,16 +1219,16 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { newParams.PartialLiquidationRatio = tc.partialLiquidationRatio perpKeeper.SetParams(ctx, newParams) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.Pair_BTC_NUSD).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Mul(tc.partialLiquidationRatio), ). @@ -1237,7 +1237,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -1247,7 +1247,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ tc.baseAssetPriceInQuote.Mul(tc.partialLiquidationRatio), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), @@ -1257,7 +1257,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ tc.baseAssetPriceInQuote.Mul(tc.partialLiquidationRatio), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), @@ -1266,13 +1266,13 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { } mocks.mockVpoolKeeper.EXPECT(). - GetMarkPrice(ctx, common.Pair_BTC_NUSD). + GetMarkPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). Return(sdk.OneDec(), nil) t.Log("create and set the initial position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialMargin, OpenNotional: tc.initialOpenNotional, @@ -1312,21 +1312,21 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { t.Log("assert new position fields") newPosition := positionResp.Position assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.Pair_BTC_NUSD, newPosition.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), newPosition.Pair) assert.True(t, newPosition.LatestCumulativePremiumFraction.IsZero()) assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) assert.EqualValues(t, tc.expectedPositionMargin, newPosition.Margin) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: positionResp.ExchangedNotionalValue, ExchangedPositionSize: positionResp.ExchangedPositionSize, LiquidatorAddress: liquidatorAddr.String(), - FeeToLiquidator: sdk.NewCoin(common.Pair_BTC_NUSD.QuoteDenom(), tc.expectedFundsToLiquidator), - FeeToEcosystemFund: sdk.NewCoin(common.Pair_BTC_NUSD.QuoteDenom(), tc.expectedFundsToPerpEF), - BadDebt: sdk.NewCoin(common.Pair_BTC_NUSD.QuoteDenom(), sdk.ZeroInt()), - Margin: sdk.NewCoin(common.Pair_BTC_NUSD.QuoteDenom(), newPosition.Margin.RoundInt()), + FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), tc.expectedFundsToLiquidator), + FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), tc.expectedFundsToPerpEF), + BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), sdk.ZeroInt()), + Margin: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), newPosition.Margin.RoundInt()), PositionNotional: positionResp.PositionNotional, PositionSize: newPosition.Size_, UnrealizedPnl: positionResp.UnrealizedPnlAfter, diff --git a/x/perp/keeper/margin_test.go b/x/perp/keeper/margin_test.go index d346918ac..c777267a8 100644 --- a/x/perp/keeper/margin_test.go +++ b/x/perp/keeper/margin_test.go @@ -36,7 +36,7 @@ func TestAddMarginSuccess(t *testing.T) { latestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.001"), initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(1_000), Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(500), @@ -67,7 +67,7 @@ func TestAddMarginSuccess(t *testing.T) { vpoolKeeper := &nibiruApp.VpoolKeeper assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens vpooltypes.VpoolConfig{ @@ -78,11 +78,11 @@ func TestAddMarginSuccess(t *testing.T) { MaxLeverage: sdk.MustNewDecFromStr("15"), }, )) - require.True(t, vpoolKeeper.ExistsPool(ctx, common.Pair_BTC_NUSD)) + require.True(t, vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD))) t.Log("set pair metadata") setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: tc.latestCumulativePremiumFraction, }, ) @@ -90,14 +90,14 @@ func TestAddMarginSuccess(t *testing.T) { t.Log("establish initial position") setPosition(nibiruApp.PerpKeeper, ctx, tc.initialPosition) - resp, err := nibiruApp.PerpKeeper.AddMargin(ctx, common.Pair_BTC_NUSD, traderAddr, tc.marginToAdd) + resp, err := nibiruApp.PerpKeeper.AddMargin(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr, tc.marginToAdd) require.NoError(t, err) assert.EqualValues(t, tc.expectedFundingPayment, resp.FundingPayment) assert.EqualValues(t, tc.expectedMargin, resp.Position.Margin) assert.EqualValues(t, tc.initialPosition.OpenNotional, resp.Position.OpenNotional) assert.EqualValues(t, tc.initialPosition.Size_, resp.Position.Size_) assert.EqualValues(t, traderAddr.String(), resp.Position.TraderAddress) - assert.EqualValues(t, common.Pair_BTC_NUSD, resp.Position.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), resp.Position.Pair) assert.EqualValues(t, tc.latestCumulativePremiumFraction, resp.Position.LatestCumulativePremiumFraction) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }) diff --git a/x/perp/keeper/margin_unit_test.go b/x/perp/keeper/margin_unit_test.go index 17e1d175d..7961d948e 100644 --- a/x/perp/keeper/margin_unit_test.go +++ b/x/perp/keeper/margin_unit_test.go @@ -112,7 +112,7 @@ func TestGetMarginRatio(t *testing.T) { name: "margin without price changes", position: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -125,7 +125,7 @@ func TestGetMarginRatio(t *testing.T) { name: "margin with price changes", position: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -145,7 +145,7 @@ func TestGetMarginRatio(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.position.Size_.Abs(), ). @@ -154,7 +154,7 @@ func TestGetMarginRatio(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.position.Size_.Abs(), 15*time.Minute, @@ -162,7 +162,7 @@ func TestGetMarginRatio(t *testing.T) { Return(tc.newPrice, nil) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.OneDec(), }) @@ -636,7 +636,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -645,7 +645,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -659,7 +659,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -668,7 +668,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -682,7 +682,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -691,7 +691,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -706,7 +706,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -715,7 +715,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -730,7 +730,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -739,7 +739,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ). Return(sdk.NewDec(2), nil) }, @@ -751,7 +751,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -760,7 +760,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ). Return(sdk.MustNewDecFromStr("0.5"), nil) }, @@ -772,7 +772,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -781,7 +781,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), ). @@ -795,7 +795,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; negative pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -804,7 +804,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), ). @@ -818,7 +818,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -827,7 +827,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), 15*time.Minute, @@ -842,7 +842,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; negative pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -851,7 +851,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), 15*time.Minute, @@ -866,7 +866,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -875,7 +875,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ). Return(sdk.MustNewDecFromStr("0.5"), nil) }, @@ -887,7 +887,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -896,7 +896,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ). Return(sdk.NewDec(2), nil) }, @@ -943,7 +943,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "max pnl, pick spot price", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -953,7 +953,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -962,7 +962,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -977,7 +977,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "max pnl, pick twap", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -987,7 +987,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -996,7 +996,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -1011,7 +1011,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "min pnl, pick spot price", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -1021,7 +1021,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -1030,7 +1030,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -1045,7 +1045,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "min pnl, pick twap", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -1055,7 +1055,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -1064,7 +1064,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, diff --git a/x/perp/keeper/msg_server_test.go b/x/perp/keeper/msg_server_test.go index d8f46a2ab..daa6d8e17 100644 --- a/x/perp/keeper/msg_server_test.go +++ b/x/perp/keeper/msg_server_test.go @@ -35,7 +35,7 @@ func TestMsgServerAddMargin(t *testing.T) { name: "trader not enough funds", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 999)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), @@ -56,7 +56,7 @@ func TestMsgServerAddMargin(t *testing.T) { name: "success", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1000)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), @@ -78,7 +78,7 @@ func TestMsgServerAddMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -90,7 +90,7 @@ func TestMsgServerAddMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -105,7 +105,7 @@ func TestMsgServerAddMargin(t *testing.T) { resp, err := msgServer.AddMargin(sdk.WrapSDKContext(ctx), &types.MsgAddMargin{ Sender: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Margin: tc.margin, }) @@ -142,7 +142,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { name: "position not enough margin", vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1000)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), @@ -163,7 +163,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { name: "vault insufficient funds", vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 999)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), @@ -177,7 +177,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { name: "success", vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1000)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), @@ -199,7 +199,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -211,7 +211,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -228,7 +228,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { resp, err := msgServer.RemoveMargin(sdk.WrapSDKContext(ctx), &types.MsgRemoveMargin{ Sender: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Margin: tc.marginToRemove, }) @@ -263,14 +263,14 @@ func TestMsgServerOpenPosition(t *testing.T) { { name: "trader not enough funds", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 999)), - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sender: testutil.AccAddress().String(), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "success", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sender: testutil.AccAddress().String(), expectedErr: nil, }, @@ -286,7 +286,7 @@ func TestMsgServerOpenPosition(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ common.Pair_BTC_NUSD, + /* pair */ common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -298,7 +298,7 @@ func TestMsgServerOpenPosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -357,7 +357,7 @@ func TestMsgServerClosePosition(t *testing.T) { }{ { name: "success", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr: testutil.AccAddress(), expectedErr: nil, }, @@ -373,7 +373,7 @@ func TestMsgServerClosePosition(t *testing.T) { assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -385,7 +385,7 @@ func TestMsgServerClosePosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -434,7 +434,7 @@ func TestMsgServerLiquidate(t *testing.T) { }{ { name: "success", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), liquidator: testutil.AccAddress().String(), trader: testutil.AccAddress().String(), expectedErr: nil, @@ -452,7 +452,7 @@ func TestMsgServerLiquidate(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ common.Pair_BTC_NUSD, + /* pair */ common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -464,7 +464,7 @@ func TestMsgServerLiquidate(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(time.Now().Add(time.Minute)) @@ -472,7 +472,7 @@ func TestMsgServerLiquidate(t *testing.T) { traderAddr, err := sdk.AccAddressFromBech32(tc.trader) if err == nil { t.Log("set oracle price") - app.OracleKeeper.SetPrice(ctx, common.Pair_BTC_NUSD, sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.OneDec()) t.Log("create position") setPosition(app.PerpKeeper, ctx, types.Position{ @@ -515,7 +515,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ctx = ctx.WithBlockTime(time.Now()) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) - pair := common.Pair_BTC_NUSD + pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) liquidator := testutil.AccAddress() atRiskTrader1 := testutil.AccAddress() @@ -543,7 +543,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(time.Now().Add(time.Minute)) t.Log("set oracle price") - app.OracleKeeper.SetPrice(ctx, common.Pair_BTC_NUSD, sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.OneDec()) t.Log("create positions") atRiskPosition1 := types.Position{ diff --git a/x/perp/simulation/genesis.go b/x/perp/simulation/genesis.go index b3277dfc6..47f858527 100644 --- a/x/perp/simulation/genesis.go +++ b/x/perp/simulation/genesis.go @@ -17,7 +17,7 @@ func RandomizedGenState(simState *module.SimulationState) { Params: types.DefaultParams(), PairMetadata: []types.PairMetadata{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, }, diff --git a/x/perp/simulation/operations.go b/x/perp/simulation/operations.go index b8524567e..8afdaf112 100644 --- a/x/perp/simulation/operations.go +++ b/x/perp/simulation/operations.go @@ -75,7 +75,7 @@ func SimulateMsgOpenPosition(ak types.AccountKeeper, bk types.BankKeeper, k keep msg := &types.MsgOpenPosition{ Sender: simAccount.Address.String(), - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Side: side, QuoteAssetAmount: quoteAmt, Leverage: leverage, @@ -170,14 +170,14 @@ func SimulateMsgClosePosition(ak types.AccountKeeper, bk types.BankKeeper, k kee ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.Pair_BTC_NUSD + pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) msg := &types.MsgClosePosition{ Sender: trader, Pair: pair, } - _, err := k.Positions.Get(ctx, collections.Join(common.Pair_BTC_NUSD, simAccount.Address)) + _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } @@ -208,10 +208,10 @@ func SimulateMsgAddMargin(ak types.AccountKeeper, bk types.BankKeeper, k keeper. ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.Pair_BTC_NUSD + pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) msg := &types.MsgAddMargin{} - _, err := k.Positions.Get(ctx, collections.Join(common.Pair_BTC_NUSD, simAccount.Address)) + _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } @@ -257,11 +257,11 @@ func SimulateMsgRemoveMargin(ak types.AccountKeeper, bk types.BankKeeper, k keep ) (opMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.Pair_BTC_NUSD + pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) msg := &types.MsgRemoveMargin{} - position, err := k.Positions.Get(ctx, collections.Join(common.Pair_BTC_NUSD, simAccount.Address)) + position, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } diff --git a/x/perp/types/msgs_test.go b/x/perp/types/msgs_test.go index b41689231..67bec561a 100644 --- a/x/perp/types/msgs_test.go +++ b/x/perp/types/msgs_test.go @@ -335,7 +335,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Trader: testutil.AccAddress().String(), }, }}, @@ -346,7 +346,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Trader: testutil.AccAddress().String(), }, { @@ -361,11 +361,11 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Trader: testutil.AccAddress().String(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), Trader: "invalid", }, }}, diff --git a/x/stablecoin/abci.go b/x/stablecoin/abci.go index 984d429d7..dbae9786f 100644 --- a/x/stablecoin/abci.go +++ b/x/stablecoin/abci.go @@ -19,7 +19,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { k.SetParams(ctx, params) } - _, err := k.OracleKeeper.GetExchangeRateTwap(ctx, common.Pair_USDC_NUSD) + _, err := k.OracleKeeper.GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) if err != nil { params := k.GetParams(ctx) diff --git a/x/stablecoin/abci_test.go b/x/stablecoin/abci_test.go index f9b927bf1..475895156 100644 --- a/x/stablecoin/abci_test.go +++ b/x/stablecoin/abci_test.go @@ -38,7 +38,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second * 60 * 16)) - app.OracleKeeper.SetPrice(ctx, common.Pair_USDC_NUSD, price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -52,7 +52,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second * 60 * 16)) - app.OracleKeeper.SetPrice(ctx, common.Pair_USDC_NUSD, price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -82,11 +82,11 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*15)) - app.OracleKeeper.SetPrice(ctx, common.Pair_USDC_NUSD, price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*30)) - app.OracleKeeper.SetPrice(ctx, common.Pair_USDC_NUSD, price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -100,11 +100,11 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*14)) - app.OracleKeeper.SetPrice(ctx, common.Pair_USDC_NUSD, price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*16)) - app.OracleKeeper.SetPrice(ctx, common.Pair_USDC_NUSD, price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -141,7 +141,7 @@ func TestEpochInfoChangesCollateralValidity(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) pairs := common.AssetPairs{ - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), } params := otypes.DefaultParams() params.TwapLookbackWindow = 1 * time.Hour diff --git a/x/stablecoin/client/cli/cli_test.go b/x/stablecoin/client/cli/cli_test.go index d913c377f..e124089bc 100644 --- a/x/stablecoin/client/cli/cli_test.go +++ b/x/stablecoin/client/cli/cli_test.go @@ -54,8 +54,8 @@ func (s *IntegrationTestSuite) SetupSuite() { oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.Pair_NIBI_NUSD, ExchangeRate: sdk.NewDec(10)}, - {Pair: common.Pair_USDC_NUSD, ExchangeRate: sdk.NewDec(1)}, + {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: sdk.NewDec(10)}, + {Pair: common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), ExchangeRate: sdk.NewDec(1)}, } oracleGenesis.Params.VotePeriod = 1_000 diff --git a/x/stablecoin/keeper/collateral_ratio.go b/x/stablecoin/keeper/collateral_ratio.go index a55ca90ad..8e6d416b4 100644 --- a/x/stablecoin/keeper/collateral_ratio.go +++ b/x/stablecoin/keeper/collateral_ratio.go @@ -86,7 +86,7 @@ func (k *Keeper) EvaluateCollRatio(ctx sdk.Context) (err error) { upperBound := params.GetPriceUpperBoundAsDec() stablePrice, err := k.OracleKeeper.GetExchangeRateTwap( - ctx, common.Pair_USDC_NUSD) + ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) if err != nil { return err } @@ -120,7 +120,7 @@ func (k *Keeper) StableRequiredForTargetCollRatio( for _, collDenom := range collDenoms { amtColl := moduleCoins.AmountOf(collDenom) priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_USDC_NUSD) + ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) if err != nil { return sdk.ZeroDec(), err } @@ -138,7 +138,7 @@ func (k *Keeper) RecollateralizeCollAmtForTargetCollRatio( ) (neededCollAmount sdk.Int, err error) { neededUSDForRecoll, _ := k.StableRequiredForTargetCollRatio(ctx) priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_USDC_NUSD) + ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) if err != nil { return sdk.Int{}, err } @@ -222,7 +222,7 @@ func (k Keeper) Recollateralize( // Compute GOV rewarded to user priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_USDC_NUSD) + ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) if err != nil { return response, err } @@ -293,7 +293,7 @@ func (k *Keeper) GovAmtFromRecollateralize( bonusRate := params.GetBonusRateRecollAsDec() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_NIBI_NUSD) + ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) if err != nil { return sdk.Int{}, err } @@ -336,7 +336,7 @@ func (k *Keeper) BuybackGovAmtForTargetCollRatio( neededUSDForRecoll, _ := k.StableRequiredForTargetCollRatio(ctx) neededUSDForBuyback := neededUSDForRecoll.Neg() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_NIBI_NUSD) + ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) if err != nil { return sdk.Int{}, err } @@ -413,7 +413,7 @@ func (k Keeper) Buyback( // Compute USD (stable) value of the GOV sent by the caller: 'inUSD' priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_NIBI_NUSD) + ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) if err != nil { return response, err } @@ -473,7 +473,7 @@ func (k *Keeper) CollAmtFromBuyback( ctx sdk.Context, valUSD sdk.Dec, ) (collAmt sdk.Int, err error) { priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_USDC_NUSD) + ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) if err != nil { return sdk.Int{}, err } diff --git a/x/stablecoin/keeper/collateral_ratio_test.go b/x/stablecoin/keeper/collateral_ratio_test.go index f3e497bc4..f415eff84 100644 --- a/x/stablecoin/keeper/collateral_ratio_test.go +++ b/x/stablecoin/keeper/collateral_ratio_test.go @@ -81,7 +81,7 @@ func TestSetCollRatioUpdate(t *testing.T) { stablecoinKeeper := &nibiruApp.StablecoinKeeper oracleKeeper := &nibiruApp.OracleKeeper - oracleKeeper.SetPrice(ctx, common.Pair_USDC_NUSD, tc.price) + oracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), tc.price) err := stablecoinKeeper.SetCollRatio(ctx, tc.inCollRatio) require.NoError(t, err) err = stablecoinKeeper.EvaluateCollRatio(ctx) @@ -178,7 +178,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(500), priceCollStable: sdk.OneDec(), // startCollUSD = 500 * 1 -> 500 postedAssetPairs: []common.AssetPair{ - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 @@ -189,7 +189,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(600), priceCollStable: sdk.OneDec(), // startCollUSD = 600 * 1 = 600 postedAssetPairs: []common.AssetPair{ - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.5"), // 0.5 * 1000 = 500 @@ -222,7 +222,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { // Post prices to each specified market with the oracle. prices := map[common.AssetPair]sdk.Dec{ - common.Pair_USDC_NUSD: tc.priceCollStable, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -295,7 +295,7 @@ func TestRecollateralizeCollAmtForTargetCollRatio(t *testing.T) { )) // Post the price - pair := common.Pair_USDC_NUSD + pair := common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD) nibiruApp.OracleKeeper.SetPrice(ctx, pair, tc.priceCollStable) neededCollAmount, err := stablecoinKeeper.RecollateralizeCollAmtForTargetCollRatio(ctx) @@ -334,7 +334,7 @@ func TestRecollateralizeCollAmtForTargetCollRatio(t *testing.T) { )) // Post the price - // pair := common.Pair_USDC_NUSD + // pair := common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD) // nibiruApp.OracleKeeper.SetPrice(ctx, pair, tc.priceCollStable) neededCollAmount, err := stablecoinKeeper.RecollateralizeCollAmtForTargetCollRatio(ctx) @@ -377,7 +377,7 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 priceCollStable: sdk.OneDec(), postedAssetPairs: []common.AssetPair{ - common.Pair_USDC_NUSD}, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -388,7 +388,7 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 priceGovStable: sdk.OneDec(), postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD}, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -398,8 +398,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(10_000), targetCollRatio: sdk.MustNewDecFromStr("0.7"), // 0.7 * 10_000 = 7_000 postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(2), @@ -414,8 +414,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(100_000), targetCollRatio: sdk.MustNewDecFromStr("0.7"), // 0.7 * 100_000 = 70_000 postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -430,8 +430,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(100_000), targetCollRatio: sdk.MustNewDecFromStr("0.5"), // 0.5 * 100_000 = 50_000 postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -456,8 +456,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { )) prices := map[common.AssetPair]sdk.Dec{ - common.Pair_NIBI_NUSD: tc.priceGovStable, - common.Pair_USDC_NUSD: tc.priceCollStable, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -465,8 +465,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { // Post prices to each specified market with the oracle. prices = map[common.AssetPair]sdk.Dec{ - common.Pair_USDC_NUSD: tc.priceCollStable, - common.Pair_NIBI_NUSD: tc.priceGovStable, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.priceCollStable, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, } for _, assetPair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, assetPair, prices[assetPair]) @@ -518,8 +518,8 @@ func TestRecollateralize(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -551,8 +551,8 @@ func TestRecollateralize(t *testing.T) { { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -586,8 +586,8 @@ func TestRecollateralize(t *testing.T) { { name: "protocol has sufficient collateral - error", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -613,8 +613,8 @@ func TestRecollateralize(t *testing.T) { { name: "caller is broke - error", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -640,8 +640,8 @@ func TestRecollateralize(t *testing.T) { { name: "negative msg.Coll.Amount - error", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -667,7 +667,7 @@ func TestRecollateralize(t *testing.T) { { name: "oracle prices are expired - error", postedAssetPairs: []common.AssetPair{ - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -716,8 +716,8 @@ func TestRecollateralize(t *testing.T) { } prices := map[common.AssetPair]sdk.Dec{ - common.Pair_NIBI_NUSD: tc.priceGovStable, - common.Pair_USDC_NUSD: tc.scenario.priceCollStable, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -725,8 +725,8 @@ func TestRecollateralize(t *testing.T) { // Post prices to each specified market with the oracle. prices = map[common.AssetPair]sdk.Dec{ - common.Pair_USDC_NUSD: tc.scenario.priceCollStable, - common.Pair_NIBI_NUSD: tc.priceGovStable, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.scenario.priceCollStable, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, } for _, assetPair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, assetPair, prices[assetPair]) @@ -849,8 +849,8 @@ func TestBuyback(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -885,8 +885,8 @@ func TestBuyback(t *testing.T) { { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(850_000), @@ -926,8 +926,8 @@ func TestBuyback(t *testing.T) { { name: "msg has more NIBI than the protocol needs, only needed sent", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -959,8 +959,8 @@ func TestBuyback(t *testing.T) { { name: "protocol under-collateralized, so buyback won't run", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -985,8 +985,8 @@ func TestBuyback(t *testing.T) { { name: "caller has insufficient funds", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1011,7 +1011,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing collateral price post", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1036,7 +1036,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing NIBI price post", postedAssetPairs: []common.AssetPair{ - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1089,8 +1089,8 @@ func TestBuyback(t *testing.T) { // Set up markets for the oracle keeper. prices := map[common.AssetPair]sdk.Dec{ - common.Pair_NIBI_NUSD: tc.priceGovStable, - common.Pair_USDC_NUSD: tc.scenario.priceCollStable, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -1131,8 +1131,8 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, correct amount out", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1162,7 +1162,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, only coll price posted", postedAssetPairs: []common.AssetPair{ - common.Pair_USDC_NUSD, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1191,8 +1191,8 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { )) prices := map[common.AssetPair]sdk.Dec{ - common.Pair_NIBI_NUSD: tc.priceGovStable, - common.Pair_USDC_NUSD: tc.scenario.priceCollStable, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) diff --git a/x/stablecoin/keeper/mint_burn_stable.go b/x/stablecoin/keeper/mint_burn_stable.go index cac9ea492..ecba22b26 100644 --- a/x/stablecoin/keeper/mint_burn_stable.go +++ b/x/stablecoin/keeper/mint_burn_stable.go @@ -93,7 +93,7 @@ func (k Keeper) calcNeededGovAndFees( ctx sdk.Context, stable sdk.Coin, govRatio sdk.Dec, feeRatio sdk.Dec, ) (sdk.Coin, sdk.Coin, error) { priceGov, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_NIBI_NUSD) + ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } @@ -115,7 +115,7 @@ func (k Keeper) calcNeededCollateralAndFees( feeRatio sdk.Dec, ) (sdk.Coin, sdk.Coin, error) { priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_USDC_NUSD) + ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } diff --git a/x/stablecoin/keeper/mint_burn_stable_test.go b/x/stablecoin/keeper/mint_burn_stable_test.go index 164e7c180..45eb1e17c 100644 --- a/x/stablecoin/keeper/mint_burn_stable_test.go +++ b/x/stablecoin/keeper/mint_burn_stable_test.go @@ -144,8 +144,8 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { ) // Post prices to each pair with the oracle. - nibiruApp.OracleKeeper.SetPrice(ctx, common.Pair_NIBI_NUSD, tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.Pair_USDC_NUSD, tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), tc.collPrice) // Fund account require.NoError(t, simapp.FundAccount(nibiruApp.BankKeeper, ctx, acc, tc.accFunds)) @@ -301,8 +301,8 @@ func TestMsgMintStableResponse_NotEnoughFunds(t *testing.T) { ) t.Log("Post prices to each pair with the oracle.") - nibiruApp.OracleKeeper.SetPrice(ctx, common.Pair_NIBI_NUSD, tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.Pair_USDC_NUSD, tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), tc.collPrice) // Fund account require.NoError(t, simapp.FundAccount(nibiruApp.BankKeeper, ctx, acc, tc.accFunds)) @@ -448,8 +448,8 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { nibiruApp.StablecoinKeeper.SetParams(ctx, defaultParams) t.Log("Post prices to each pair with the oracle.") - nibiruApp.OracleKeeper.SetPrice(ctx, common.Pair_NIBI_NUSD, tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.Pair_USDC_NUSD, tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), tc.collPrice) // Add collaterals to the module require.NoError(t, nibiruApp.BankKeeper.MintCoins(ctx, types.ModuleName, tc.moduleFunds)) @@ -569,8 +569,8 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { ), ) - nibiruApp.OracleKeeper.SetPrice(ctx, common.Pair_NIBI_NUSD, tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.Pair_USDC_NUSD, tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), tc.collPrice) // Add collaterals to the module require.NoError(t, nibiruApp.BankKeeper.MintCoins(ctx, types.ModuleName, tc.moduleFunds)) diff --git a/x/vpool/abci_test.go b/x/vpool/abci_test.go index 8454d86e9..6722920bc 100644 --- a/x/vpool/abci_test.go +++ b/x/vpool/abci_test.go @@ -31,7 +31,7 @@ func TestSnapshotUpdates(t *testing.T) { require.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(1_000), sdk.NewDec(1_000), types.DefaultVpoolConfig(). @@ -39,7 +39,7 @@ func TestSnapshotUpdates(t *testing.T) { WithFluctuationLimitRatio(sdk.OneDec()), )) expectedSnapshot := types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(1_000), sdk.NewDec(1_000), ctx.BlockTime(), @@ -47,14 +47,14 @@ func TestSnapshotUpdates(t *testing.T) { t.Log("run one block of 5 seconds") runBlock(5 * time.Second) - snapshot, err := vpoolKeeper.ReserveSnapshots.Get(ctx, collections.Join(common.Pair_BTC_NUSD, time.UnixMilli(expectedSnapshot.TimestampMs))) + snapshot, err := vpoolKeeper.ReserveSnapshots.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) require.NoError(t, err) assert.EqualValues(t, expectedSnapshot, snapshot) t.Log("affect mark price") baseAmtAbs, err := vpoolKeeper.SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), types.Direction_ADD_TO_POOL, sdk.NewDec(250), // ← dyAmm sdk.ZeroDec(), @@ -64,7 +64,7 @@ func TestSnapshotUpdates(t *testing.T) { assert.EqualValues(t, sdk.NewDec(200), baseAmtAbs) require.NoError(t, err) expectedSnapshot = types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(800), // ← x + dxAmm sdk.NewDec(1_250), // ← y + dyAMM ctx.BlockTime(), @@ -75,7 +75,7 @@ func TestSnapshotUpdates(t *testing.T) { timeSkipDuration := 5 * time.Second runBlock(timeSkipDuration) // increments ctx.blockHeight and ctx.BlockTime snapshot, err = vpoolKeeper.ReserveSnapshots.Get(ctx, - collections.Join(common.Pair_BTC_NUSD, time.UnixMilli(expectedSnapshot.TimestampMs))) + collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) require.NoError(t, err) assert.EqualValues(t, expectedSnapshot, snapshot) diff --git a/x/vpool/client/cli/cli_test.go b/x/vpool/client/cli/cli_test.go index cda955ea9..09403a1d7 100644 --- a/x/vpool/client/cli/cli_test.go +++ b/x/vpool/client/cli/cli_test.go @@ -34,8 +34,8 @@ func TestIntegrationTestSuite(t *testing.T) { } var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ - common.Pair_ETH_NUSD: { - Pair: common.Pair_ETH_NUSD, + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD): { + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -46,8 +46,8 @@ var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ MaxLeverage: sdk.MustNewDecFromStr("15"), }, }, - common.Pair_NIBI_NUSD: { - Pair: common.Pair_NIBI_NUSD, + common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): { + Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(500_000), QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -73,14 +73,14 @@ func (s *IntegrationTestSuite) SetupSuite() { genesisState := simapp.NewTestGenesisStateFromDefault() vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ - START_VPOOLS[common.Pair_ETH_NUSD], - START_VPOOLS[common.Pair_NIBI_NUSD], + START_VPOOLS[common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)], + START_VPOOLS[common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)], } oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.Pair_ETH_NUSD, ExchangeRate: sdk.NewDec(1_000)}, - {Pair: common.Pair_NIBI_NUSD, ExchangeRate: sdk.NewDec(10)}, + {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: sdk.NewDec(1_000)}, + {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: sdk.NewDec(10)}, } oracleGenesis.Params.VotePeriod = 1_000 @@ -168,13 +168,13 @@ func (s *IntegrationTestSuite) TestGetPrices() { val := s.network.Validators[0] s.T().Log("check vpool balances") - reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.Pair_ETH_NUSD) + reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("10000000"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.MustNewDecFromStr("60000000000"), reserveAssets.QuoteAssetReserve) s.T().Log("check prices") - priceInfo, err := testutilcli.QueryBaseAssetPrice(val.ClientCtx, common.Pair_ETH_NUSD, "add", "100") + priceInfo, err := testutilcli.QueryBaseAssetPrice(val.ClientCtx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), "add", "100") s.T().Logf("priceInfo: %+v", priceInfo) s.EqualValues(sdk.MustNewDecFromStr("599994.000059999400006000"), priceInfo.PriceInQuoteDenom) s.NoError(err) @@ -186,7 +186,7 @@ func (s *IntegrationTestSuite) TestCmdEditPoolConfigProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[common.Pair_ETH_NUSD] + startVpool := START_VPOOLS[common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)] proposal := &vpooltypes.EditPoolConfigProposal{ Title: "NIP-3: Edit config of the ueth:unusd vpool", Description: "enables higher max leverage on ueth:unusd", @@ -252,7 +252,7 @@ func (s *IntegrationTestSuite) TestCmdEditSwapInvariantsProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[common.Pair_NIBI_NUSD] + startVpool := START_VPOOLS[common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)] proposal := &vpooltypes.EditSwapInvariantsProposal{ Title: "NIP-4: Change the swap invariant for ATOM, OSMO, and BTC.", Description: "increase swap invariant for many virtual pools", diff --git a/x/vpool/keeper/keeper_test.go b/x/vpool/keeper/keeper_test.go index 98cfaf247..96f4be858 100644 --- a/x/vpool/keeper/keeper_test.go +++ b/x/vpool/keeper/keeper_test.go @@ -32,7 +32,7 @@ func TestSwapQuoteForBase(t *testing.T) { }{ { name: "quote amount == 0", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(0), baseLimit: sdk.NewDec(10), @@ -44,7 +44,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap add", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(49504), @@ -56,7 +56,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap remove", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(50506), @@ -78,7 +78,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount less than base limit in Long", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(500_000), baseLimit: sdk.NewDec(454_500), @@ -88,7 +88,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount more than base limit in Short", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_500), @@ -98,7 +98,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when removing quote", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -108,7 +108,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when adding quote", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -118,7 +118,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), @@ -128,7 +128,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), @@ -138,7 +138,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), @@ -150,7 +150,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), @@ -172,7 +172,7 @@ func TestSwapQuoteForBase(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ @@ -200,7 +200,7 @@ func TestSwapQuoteForBase(t *testing.T) { assert.EqualValuesf(t, tc.expectedBaseAmount, baseAmt, "base amount mismatch") t.Log("assert vpool") - pool, err := vpoolKeeper.Pools.Get(ctx, common.Pair_BTC_NUSD) + pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) require.NoError(t, err) assert.EqualValuesf(t, tc.expectedQuoteReserve, pool.QuoteAssetReserve, "pool quote asset reserve mismatch") assert.EqualValuesf(t, tc.expectedBaseReserve, pool.BaseAssetReserve, "pool base asset reserve mismatch") @@ -225,7 +225,7 @@ func TestSwapBaseForQuote(t *testing.T) { }{ { name: "zero base asset swap", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.ZeroDec(), quoteLimit: sdk.ZeroDec(), @@ -237,7 +237,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "add base asset swap", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196078), @@ -249,7 +249,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "remove base asset", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(204_082), @@ -271,7 +271,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount less than quote limit in Long", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196079), @@ -281,7 +281,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount more than quote limit in Short", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(204_081), @@ -291,7 +291,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when removing base", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -301,7 +301,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when adding base", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -311,7 +311,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), @@ -321,7 +321,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), @@ -331,7 +331,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), @@ -343,7 +343,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), @@ -365,7 +365,7 @@ func TestSwapBaseForQuote(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ @@ -394,7 +394,7 @@ func TestSwapBaseForQuote(t *testing.T) { "expected %s; got %s", tc.expectedQuoteAssetAmount.String(), quoteAssetAmount.String()) t.Log("assert pool") - pool, err := vpoolKeeper.Pools.Get(ctx, common.Pair_BTC_NUSD) + pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) require.NoError(t, err) assert.Equal(t, tc.expectedQuoteReserve, pool.QuoteAssetReserve) assert.Equal(t, tc.expectedBaseReserve, pool.BaseAssetReserve) @@ -410,7 +410,7 @@ func TestGetVpools(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10*common.Precision), sdk.NewDec(5*common.Precision), types.VpoolConfig{ @@ -423,7 +423,7 @@ func TestGetVpools(t *testing.T) { )) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_ETH_NUSD, + common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), sdk.NewDec(5*common.Precision), sdk.NewDec(10*common.Precision), types.VpoolConfig{ @@ -440,7 +440,7 @@ func TestGetVpools(t *testing.T) { require.EqualValues(t, 2, len(pools)) require.EqualValues(t, pools[0], types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(5 * common.Precision), QuoteAssetReserve: sdk.NewDec(10 * common.Precision), Config: types.VpoolConfig{ @@ -452,7 +452,7 @@ func TestGetVpools(t *testing.T) { }, }) require.EqualValues(t, pools[1], types.Vpool{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: types.VpoolConfig{ @@ -476,7 +476,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses latest snapshot - does not result in error", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -489,13 +489,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -506,7 +506,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses previous snapshot - results in error", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -519,7 +519,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -530,7 +530,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "only one snapshot - no error", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -543,7 +543,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -554,7 +554,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "zero fluctuation limit - no error", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -567,13 +567,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -584,7 +584,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "multiple pools - no overlap", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -597,25 +597,25 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.Pair_NIBI_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.Pair_USDC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -666,7 +666,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -677,7 +677,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -694,7 +694,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { mock.NewMockOracleKeeper(gomock.NewController(t)), ) vpoolKeeper.Pools.Insert(ctx, tc.pool.Pair, tc.pool) - mmr, err := vpoolKeeper.GetMaintenanceMarginRatio(ctx, common.Pair_BTC_NUSD) + mmr, err := vpoolKeeper.GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) assert.NoError(t, err) assert.EqualValues(t, tc.expectedMaintenanceMarginRatio, mmr) }) @@ -711,7 +711,7 @@ func TestGetMaxLeverage(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -734,7 +734,7 @@ func TestGetMaxLeverage(t *testing.T) { ) vpoolKeeper.Pools.Insert(ctx, tc.pool.Pair, tc.pool) - maxLeverage, err := vpoolKeeper.GetMaxLeverage(ctx, common.Pair_BTC_NUSD) + maxLeverage, err := vpoolKeeper.GetMaxLeverage(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) assert.EqualValues(t, tc.expectedMaxLeverage, maxLeverage) assert.NoError(t, err) }) diff --git a/x/vpool/keeper/pool_state_test.go b/x/vpool/keeper/pool_state_test.go index c0304a488..501dabe80 100644 --- a/x/vpool/keeper/pool_state_test.go +++ b/x/vpool/keeper/pool_state_test.go @@ -18,7 +18,7 @@ func TestCreatePool(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens @@ -31,7 +31,7 @@ func TestCreatePool(t *testing.T) { }, )) - exists := vpoolKeeper.ExistsPool(ctx, common.Pair_BTC_NUSD) + exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) require.True(t, exists) notExist := vpoolKeeper.ExistsPool(ctx, "BTC:OTHER") @@ -39,7 +39,7 @@ func TestCreatePool(t *testing.T) { } func TestEditPoolConfig(t *testing.T) { - pair := common.Pair_BTC_NUSD + pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) vpoolStart := types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(10 * common.Precision), @@ -57,12 +57,12 @@ func TestEditPoolConfig(t *testing.T) { vpoolKeeper, _, ctx := getKeeper(t) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), vpoolStart.QuoteAssetReserve, vpoolStart.BaseAssetReserve, vpoolStart.Config, )) - exists := vpoolKeeper.ExistsPool(ctx, common.Pair_BTC_NUSD) + exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) require.True(t, exists) return vpoolKeeper, ctx } @@ -188,7 +188,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool + pricefeed active", vpool: types.Vpool{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -202,7 +202,7 @@ func TestGetPoolPrices(t *testing.T) { shouldCreateVpool: true, mockIndexPrice: sdk.NewDec(99), expectedPoolPrices: types.PoolPrices{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.NewDec(99).String(), @@ -213,7 +213,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool active, but no index price", vpool: types.Vpool{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -228,7 +228,7 @@ func TestGetPoolPrices(t *testing.T) { mockIndexPrice: sdk.OneDec().Neg(), oracleKeeperErr: fmt.Errorf("No index price"), expectedPoolPrices: types.PoolPrices{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.OneDec().Neg().String(), @@ -239,7 +239,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "vpool doesn't exist", vpool: types.Vpool{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -292,7 +292,7 @@ func TestGetPoolPrices(t *testing.T) { } func TestEditSwapInvariant(t *testing.T) { - pair := common.Pair_NIBI_NUSD + pair := common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD) vpoolStart := types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(10 * common.Precision), diff --git a/x/vpool/keeper/prices_test.go b/x/vpool/keeper/prices_test.go index 82a167b2e..8069295e7 100644 --- a/x/vpool/keeper/prices_test.go +++ b/x/vpool/keeper/prices_test.go @@ -26,14 +26,14 @@ func TestGetMarkPrice(t *testing.T) { }{ { name: "correctly fetch underlying price", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(1), expectedPrice: sdk.NewDec(40000), }, { name: "complex price", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), quoteAssetReserve: sdk.NewDec(2_489_723_947), baseAssetReserve: sdk.NewDec(34_597_234), expectedPrice: sdk.MustNewDecFromStr("71.963092396345904415"), @@ -80,7 +80,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), baseAmount: sdk.ZeroDec(), @@ -89,7 +89,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -98,7 +98,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -107,7 +107,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("1000"), @@ -163,7 +163,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), quoteAmount: sdk.ZeroDec(), @@ -172,7 +172,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -181,7 +181,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -190,7 +190,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(1000), @@ -252,22 +252,22 @@ func TestCalcTwap(t *testing.T) { // expected price: ((95/10 * (35 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 10) + 100/1 * (10 - 5)) / (5 + 10 + 10 + 5) { name: "spot price twap calc, t=[5,35]", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -283,22 +283,22 @@ func TestCalcTwap(t *testing.T) { // expected price: (95/10 * (30 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 10)) / (10 + 10) { name: "spot price twap calc, t=[10,30]", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -314,22 +314,22 @@ func TestCalcTwap(t *testing.T) { // expected price: (95/10 * (35 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 11)) / (5 + 10 + 9) { name: "spot price twap calc, t=[11,35]", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -347,7 +347,7 @@ func TestCalcTwap(t *testing.T) { // expected price: 100/1 { name: "spot price twap calc, t=[0,0]", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{}, currentBlockTime: time.UnixMilli(0), currentBlockHeight: 1, @@ -361,16 +361,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((7.5 - 300/(40 + 10)) * (30 - 20) + (10 - 300/(30 + 10)) * (20 - 10)) / (10 + 10) { name: "quote asset swap twap calc, add to pool, t=[10,30]", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(30), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.MustNewDecFromStr("7.5"), sdk.NewDec(40), time.UnixMilli(20), @@ -390,16 +390,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((12 - 600/(50 - 10)) * (30 - 20) + (10 - 600/(60 - 10)) * (20 - 10)) / (10 + 10) { name: "quote asset swap twap calc, remove from pool, t=[10,30]", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(12), sdk.NewDec(50), time.UnixMilli(20), @@ -415,10 +415,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: quote asset reserve = asset amount", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(20), time.UnixMilli(20), @@ -438,16 +438,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((60 - 600/(10 + 10)) * (20 - 10) + (30 - 600/(20 + 10)) * (30 - 20)) / (10 + 10) { name: "base asset swap twap calc, add to pool, t=[10,30]", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(20), sdk.NewDec(30), time.UnixMilli(20), @@ -467,16 +467,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((60 - 600/(10 - 2)) * (20 - 10) + (75 - 600/(8 - 2)) * (30 - 20)) / (10 + 10) { name: "base asset swap twap calc, remove from pool, t=[10,30]", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(8), sdk.NewDec(75), time.UnixMilli(20), @@ -492,10 +492,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: base asset reserve = asset amount", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(20), @@ -539,7 +539,7 @@ func TestCalcTwap(t *testing.T) { for _, snapshot := range tc.reserveSnapshots { ctx = ctx.WithBlockTime(time.UnixMilli(snapshot.TimestampMs)) snapshot := types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), snapshot.BaseAssetReserve, snapshot.QuoteAssetReserve, ctx.BlockTime(), diff --git a/x/vpool/keeper/query_server_test.go b/x/vpool/keeper/query_server_test.go index f01a563fc..f6fe9cac5 100644 --- a/x/vpool/keeper/query_server_test.go +++ b/x/vpool/keeper/query_server_test.go @@ -23,7 +23,7 @@ func TestQueryReserveAssets(t *testing.T) { t.Log("initialize vpool") pool := types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1 * common.Precision), BaseAssetReserve: sdk.NewDec(1000), Config: types.VpoolConfig{ @@ -40,7 +40,7 @@ func TestQueryReserveAssets(t *testing.T) { resp, err := queryServer.ReserveAssets( sdk.WrapSDKContext(ctx), &types.QueryReserveAssetsRequest{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), }, ) @@ -57,7 +57,7 @@ func TestQueryAllPools(t *testing.T) { queryServer := NewQuerier(vpoolKeeper) t.Log("initialize vpool") - pair := common.Pair_BTC_NUSD + pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) pool := &types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(1 * common.Precision), diff --git a/x/vpool/keeper/snapshot_test.go b/x/vpool/keeper/snapshot_test.go index 44818b666..e10391a1e 100644 --- a/x/vpool/keeper/snapshot_test.go +++ b/x/vpool/keeper/snapshot_test.go @@ -24,7 +24,7 @@ func TestGetSnapshotPrice(t *testing.T) { }{ { name: "spot price calc", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(2), twapCalcOption: types.TwapCalcOption_SPOT, @@ -32,7 +32,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap add to pool calc", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_QUOTE_ASSET_SWAP, @@ -42,7 +42,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap remove from pool calc", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_QUOTE_ASSET_SWAP, @@ -52,7 +52,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap add to pool calc", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_BASE_ASSET_SWAP, @@ -62,7 +62,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap remove from pool calc", - pair: common.Pair_BTC_NUSD, + pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_BASE_ASSET_SWAP, diff --git a/x/vpool/simulation/genesis.go b/x/vpool/simulation/genesis.go index c2ba99785..628cd07ac 100644 --- a/x/vpool/simulation/genesis.go +++ b/x/vpool/simulation/genesis.go @@ -23,7 +23,7 @@ func RandomizedGenState(simState *module.SimulationState) { vpoolGenesis := types.GenesisState{ Vpools: []types.Vpool{ { - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(10e12).Add(simtypes.RandomDecAmount(simState.Rand, sdk.NewDec(10e12))), BaseAssetReserve: sdk.NewDec(10e12).Add(simtypes.RandomDecAmount(simState.Rand, sdk.NewDec(10e12))), Config: types.VpoolConfig{ diff --git a/x/vpool/types/gov_test.go b/x/vpool/types/gov_test.go index 29827dc0a..b42b0c1ca 100644 --- a/x/vpool/types/gov_test.go +++ b/x/vpool/types/gov_test.go @@ -144,7 +144,7 @@ func TestMarshalProposalEditPoolConfig(t *testing.T) { proposal := EditPoolConfigProposal{ Title: "Edit vpool config for NIBI:NUSD", Description: "I want to take 100x leverage on my NIBI", - Pair: common.Pair_NIBI_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), Config: VpoolConfig{ MaxLeverage: sdk.MustNewDecFromStr("100"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), diff --git a/x/vpool/types/pool_test.go b/x/vpool/types/pool_test.go index 9bfc7aa5c..3992081dd 100644 --- a/x/vpool/types/pool_test.go +++ b/x/vpool/types/pool_test.go @@ -504,7 +504,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "happy path", Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -513,7 +513,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil base", Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -522,7 +522,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero base", Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -531,7 +531,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil quote", Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.Dec{}, }, @@ -540,7 +540,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero quote", Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.ZeroDec(), }, @@ -566,7 +566,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "zero fluctuation limit ratio", pool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -582,7 +582,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "lower limit of fluctuation limit", pool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(999), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -598,7 +598,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "upper limit of fluctuation limit", pool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1001), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -614,7 +614,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "under fluctuation limit", pool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(998), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -630,7 +630,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "over fluctuation limit", pool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -649,7 +649,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { snapshot := NewReserveSnapshot( - common.Pair_BTC_NUSD, + common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.OneDec(), sdk.NewDec(1000), time.Now(), @@ -668,7 +668,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "happy path", vpool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(10), QuoteAssetReserve: sdk.NewDec(10_000), }, @@ -677,7 +677,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid base", vpool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.NewDec(500), }, @@ -686,7 +686,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid quote", vpool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.Dec{}, }, @@ -695,7 +695,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative quote", vpool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.NewDec(-500), }, @@ -704,7 +704,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative base", vpool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(-500), QuoteAssetReserve: sdk.NewDec(500), }, diff --git a/x/vpool/types/snapshot_test.go b/x/vpool/types/snapshot_test.go index 61b6ce4f9..f9c7c953c 100644 --- a/x/vpool/types/snapshot_test.go +++ b/x/vpool/types/snapshot_test.go @@ -19,7 +19,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "happy path", snapshot: ReserveSnapshot{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), BaseAssetReserve: sdk.OneDec(), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -39,7 +39,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "base asset negative", snapshot: ReserveSnapshot{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(-1), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -49,7 +49,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "quote asset negative", snapshot: ReserveSnapshot{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.NewDec(-1), TimestampMs: time.Now().UnixMilli(), @@ -60,7 +60,7 @@ func TestSnapshotValidate(t *testing.T) { name: "timestamp lower than smallest UTC ('0001-01-01 00:00:00 +0000 UTC')", // see time.UnixMilli(-62135596800000).UTC()) snapshot: ReserveSnapshot{ - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.ZeroDec(), TimestampMs: -62135596800000 - 1, diff --git a/x/wasm/cli/cli_test.go b/x/wasm/cli/cli_test.go index 9f16197a7..5354578d2 100644 --- a/x/wasm/cli/cli_test.go +++ b/x/wasm/cli/cli_test.go @@ -48,7 +48,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: common.Pair_ETH_NUSD, + Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ From 27aacd2b40acc562d611b9d5dc9674d077d6fa14 Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Wed, 25 Jan 2023 11:48:37 -0500 Subject: [PATCH 4/9] chore: update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d0cf0e28..7bef1b849 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### API Breaking +* [#1158](https://github.com/NibiruChain/nibiru/pull/1158) - feat(asset-registry)!: Add `AssetRegistry` + +### State Machine Breaking + * [#1154](https://github.com/NibiruChain/nibiru/pull/1154) - refactor(asset-pair)!: refactors `common.AssetPair` as an extension of string ### CI From ce813a4c1b45ebdf44bb55c0c1e799ae1b65bed6 Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Wed, 25 Jan 2023 12:00:09 -0500 Subject: [PATCH 5/9] refactor(denom): move denoms to separate package --- cmd/nibid/cmd/testnet.go | 10 +- simapp/testapp.go | 7 +- x/common/asset_registry.go | 26 +- x/common/asset_registry_test.go | 10 +- x/common/common_test.go | 11 +- x/common/{ => denoms}/denoms.go | 4 +- x/common/error_test.go | 5 +- x/dex/client/testutil/cli_test.go | 10 +- x/dex/client/testutil/test_helpers.go | 4 +- x/dex/keeper/balances_test.go | 9 +- x/dex/keeper/grpc_query_test.go | 76 +++--- x/dex/keeper/keeper_test.go | 13 +- x/dex/keeper/msg_server_test.go | 256 +++++++++--------- x/dex/keeper/swap_test.go | 32 +-- x/dex/simulation/operations.go | 7 +- x/dex/types/params.go | 9 +- x/oracle/keeper/ballot_test.go | 33 +-- x/oracle/keeper/keeper_test.go | 5 +- x/oracle/keeper/msg_server_test.go | 19 +- x/oracle/keeper/querier_test.go | 45 +-- x/oracle/keeper/reward_test.go | 9 +- x/oracle/keeper/slash_test.go | 41 +-- x/oracle/keeper/tally_fuzz_test.go | 9 +- x/oracle/keeper/test_utils.go | 11 +- x/oracle/keeper/update_exchange_rates_test.go | 121 +++++---- x/oracle/simulation/decoder_test.go | 5 +- x/oracle/simulation/genesis.go | 11 +- x/oracle/simulation/operations.go | 3 +- x/oracle/types/ballot_test.go | 27 +- x/oracle/types/msgs_test.go | 5 +- x/oracle/types/params.go | 9 +- x/perp/client/cli/cli_test.go | 115 ++++---- x/perp/genesis_test.go | 5 +- x/perp/keeper/calc_test.go | 3 +- x/perp/keeper/calc_unit_test.go | 25 +- .../keeper/clearing_house_integration_test.go | 85 +++--- x/perp/keeper/clearing_house_unit_test.go | 137 +++++----- x/perp/keeper/grpc_query_test.go | 67 ++--- x/perp/keeper/hooks_test.go | 17 +- x/perp/keeper/liquidate_unit_test.go | 187 ++++++------- x/perp/keeper/margin_test.go | 17 +- x/perp/keeper/margin_unit_test.go | 87 +++--- x/perp/keeper/msg_server_test.go | 89 +++--- x/perp/simulation/genesis.go | 3 +- x/perp/simulation/operations.go | 29 +- x/perp/types/msgs_test.go | 9 +- x/stablecoin/abci.go | 3 +- x/stablecoin/abci_test.go | 15 +- x/stablecoin/client/cli/cli_test.go | 29 +- x/stablecoin/genesis_test.go | 4 +- x/stablecoin/keeper/collateral_ratio.go | 23 +- x/stablecoin/keeper/collateral_ratio_test.go | 211 ++++++++------- x/stablecoin/keeper/keeper.go | 4 +- x/stablecoin/keeper/mint_burn_stable.go | 15 +- x/stablecoin/keeper/mint_burn_stable_test.go | 133 ++++----- x/stablecoin/keeper/supply.go | 10 +- x/stablecoin/keeper/supply_test.go | 17 +- x/stablecoin/simulation/msg.go | 4 +- x/stablecoin/types/genesis.go | 4 +- x/testutil/cli/network.go | 12 +- x/testutil/cli/tx.go | 3 +- x/testutil/testapp/config.go | 12 +- x/testutil/testapp/testapp.go | 5 +- x/vpool/abci_test.go | 13 +- x/vpool/client/cli/cli_test.go | 25 +- x/vpool/keeper/keeper_test.go | 101 +++---- x/vpool/keeper/pool_state_test.go | 23 +- x/vpool/keeper/prices_test.go | 81 +++--- x/vpool/keeper/query_server_test.go | 7 +- x/vpool/keeper/snapshot_test.go | 11 +- x/vpool/simulation/genesis.go | 3 +- x/vpool/types/gov_test.go | 3 +- x/vpool/types/pool_test.go | 33 +-- x/vpool/types/snapshot_test.go | 9 +- x/wasm/cli/cli_test.go | 5 +- 75 files changed, 1293 insertions(+), 1242 deletions(-) rename x/common/{ => denoms}/denoms.go (78%) diff --git a/cmd/nibid/cmd/testnet.go b/cmd/nibid/cmd/testnet.go index a1418b7a0..f2df056e2 100644 --- a/cmd/nibid/cmd/testnet.go +++ b/cmd/nibid/cmd/testnet.go @@ -33,7 +33,7 @@ import ( "github.com/tendermint/tendermint/types" tmtime "github.com/tendermint/tendermint/types/time" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" ) var ( @@ -89,7 +89,7 @@ Example: cmd.Flags().String(flagNodeDaemonHome, "nibid", "Home directory of the node's daemon configuration") cmd.Flags().String(flagStartingIPAddress, "192.168.0.1", "Starting IP address (192.168.0.1 results in persistent peers list ID0@192.168.0.1:46656, ID1@192.168.0.2:46656, ...)") cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") - cmd.Flags().String(server.FlagMinGasPrices, fmt.Sprintf("0.000006%s", common.DenomNIBI), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.001stake)") + cmd.Flags().String(server.FlagMinGasPrices, fmt.Sprintf("0.000006%s", denoms.DenomNIBI), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.001stake)") cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)") cmd.Flags().String(flags.FlagKeyAlgorithm, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for") @@ -200,8 +200,8 @@ func InitTestnet( accTokens := sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction) accStakingTokens := sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction) coins := sdk.Coins{ - sdk.NewCoin(common.DenomNUSD, accTokens), - sdk.NewCoin(common.DenomNIBI, accStakingTokens), + sdk.NewCoin(denoms.DenomNUSD, accTokens), + sdk.NewCoin(denoms.DenomNIBI, accStakingTokens), } genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()}) @@ -211,7 +211,7 @@ func InitTestnet( createValMsg, err := stakingtypes.NewMsgCreateValidator( sdk.ValAddress(addr), valPubKeys[i], - sdk.NewCoin(common.DenomNIBI, valTokens), + sdk.NewCoin(denoms.DenomNIBI, valTokens), stakingtypes.NewDescription(nodeDirName, "", "", "", ""), stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()), sdk.OneInt(), diff --git a/simapp/testapp.go b/simapp/testapp.go index b9b22269c..a149db584 100644 --- a/simapp/testapp.go +++ b/simapp/testapp.go @@ -16,6 +16,7 @@ import ( tmdb "github.com/tendermint/tm-db" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" ) // NewTestNibiruApp creates an application instance ('app.NibiruApp') with an in-memory @@ -36,8 +37,8 @@ func NewTestNibiruAppAndContext(shouldUseDefaultGenesis bool) (*NibiruTestApp, s newNibiruApp := NewTestNibiruApp(shouldUseDefaultGenesis) ctx := newNibiruApp.NewContext(false, tmproto.Header{}) - newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.NewDec(20000)) - // newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), sdk.NewDec(10)) + newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(20000)) + // newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), sdk.NewDec(10)) newNibiruApp.OracleKeeper.SetPrice(ctx, "xxx:yyy", sdk.NewDec(20000)) return newNibiruApp, ctx @@ -122,7 +123,7 @@ func NewTestGenesisState(codec codec.Codec, inGenState GenesisState, var govGenState govtypes.GenesisState codec.MustUnmarshalJSON(testGenState[govtypes.ModuleName], &govGenState) govGenState.VotingParams.VotingPeriod = time.Second * 20 - govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision)) // min deposit of 1 NIBI + govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision)) // min deposit of 1 NIBI testGenState[govtypes.ModuleName] = codec.MustMarshalJSON(&govGenState) return testGenState diff --git a/x/common/asset_registry.go b/x/common/asset_registry.go index c426d4028..31d6589c2 100644 --- a/x/common/asset_registry.go +++ b/x/common/asset_registry.go @@ -1,5 +1,7 @@ package common +import "github.com/NibiruChain/nibiru/x/common/denoms" + type assetRegistry map[string][]string var AssetRegistry assetRegistry @@ -8,18 +10,18 @@ func init() { // map of base asset to supported quote assets // quote assets are usually stables AssetRegistry = map[string][]string{ - DenomBTC: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, - DenomETH: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, - DenomNIBI: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, - DenomATOM: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, - DenomOSMO: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, - DenomAVAX: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, - DenomSOL: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, - DenomBNB: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, - DenomADA: {DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT}, - DenomNUSD: {DenomUSD, DenomUSDC}, - DenomUSDC: {DenomUSD, DenomNUSD}, - DenomUSDT: {DenomUSD, DenomNUSD, DenomUSDC}, + denoms.DenomBTC: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, + denoms.DenomETH: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, + denoms.DenomNIBI: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, + denoms.DenomATOM: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, + denoms.DenomOSMO: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, + denoms.DenomAVAX: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, + denoms.DenomSOL: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, + denoms.DenomBNB: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, + denoms.DenomADA: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, + denoms.DenomNUSD: {denoms.DenomUSD, denoms.DenomUSDC}, + denoms.DenomUSDC: {denoms.DenomUSD, denoms.DenomNUSD}, + denoms.DenomUSDT: {denoms.DenomUSD, denoms.DenomNUSD, denoms.DenomUSDC}, } } diff --git a/x/common/asset_registry_test.go b/x/common/asset_registry_test.go index e539f838d..df86371aa 100644 --- a/x/common/asset_registry_test.go +++ b/x/common/asset_registry_test.go @@ -4,6 +4,8 @@ import ( "testing" "github.com/stretchr/testify/require" + + "github.com/NibiruChain/nibiru/x/common/denoms" ) func TestIsSupportedPair(t *testing.T) { @@ -14,7 +16,7 @@ func TestIsSupportedPair(t *testing.T) { } t.Log("test an unsupported pair") - require.False(t, AssetRegistry.IsSupportedPair(DenomATOM, DenomOSMO)) + require.False(t, AssetRegistry.IsSupportedPair(denoms.DenomATOM, denoms.DenomOSMO)) } func TestPair(t *testing.T) { @@ -25,13 +27,13 @@ func TestPair(t *testing.T) { } t.Log("test an unsupported pair") - require.Equal(t, AssetPair(""), AssetRegistry.Pair(DenomATOM, DenomOSMO)) + require.Equal(t, AssetPair(""), AssetRegistry.Pair(denoms.DenomATOM, denoms.DenomOSMO)) t.Log("test an unsupported base asset") - require.Equal(t, AssetPair(""), AssetRegistry.Pair("unsuported_denom", DenomUSDC)) + require.Equal(t, AssetPair(""), AssetRegistry.Pair("unsuported_denom", denoms.DenomUSDC)) t.Log("test an unsupported quote asset") - require.Equal(t, AssetPair(""), AssetRegistry.Pair(DenomATOM, "unsupported_denom")) + require.Equal(t, AssetPair(""), AssetRegistry.Pair(denoms.DenomATOM, "unsupported_denom")) } func TestBaseDenoms(t *testing.T) { diff --git a/x/common/common_test.go b/x/common/common_test.go index f059322ec..5938b0967 100644 --- a/x/common/common_test.go +++ b/x/common/common_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" ) func TestTryNewAssetPair(t *testing.T) { @@ -19,23 +20,23 @@ func TestTryNewAssetPair(t *testing.T) { }{ { "only one token", - common.DenomNIBI, + denoms.DenomNIBI, common.ErrInvalidTokenPair, }, { "more than 2 tokens", - fmt.Sprintf("%s%s%s%s%s", common.DenomNIBI, common.PairSeparator, common.DenomNUSD, - common.PairSeparator, common.DenomUSDC), + fmt.Sprintf("%s%s%s%s%s", denoms.DenomNIBI, common.PairSeparator, denoms.DenomNUSD, + common.PairSeparator, denoms.DenomUSDC), common.ErrInvalidTokenPair, }, { "different separator", - fmt.Sprintf("%s%s%s", common.DenomNIBI, "%", common.DenomNUSD), + fmt.Sprintf("%s%s%s", denoms.DenomNIBI, "%", denoms.DenomNUSD), common.ErrInvalidTokenPair, }, { "correct pair", - fmt.Sprintf("%s%s%s", common.DenomNIBI, common.PairSeparator, common.DenomNUSD), + fmt.Sprintf("%s%s%s", denoms.DenomNIBI, common.PairSeparator, denoms.DenomNUSD), nil, }, { diff --git a/x/common/denoms.go b/x/common/denoms/denoms.go similarity index 78% rename from x/common/denoms.go rename to x/common/denoms/denoms.go index 5fe1f9448..d8c7d5bf7 100644 --- a/x/common/denoms.go +++ b/x/common/denoms/denoms.go @@ -1,4 +1,4 @@ -package common +package denoms const ( // stablecoins DenomUSDC = "uusdc" @@ -7,8 +7,6 @@ const ( // stablecoins DenomUSDT = "uusdt" ) -var allStableDenoms = []string{DenomUSDC, DenomNUSD, DenomUSD, DenomUSDT} - const ( // volatile assets DenomNIBI = "unibi" DenomBTC = "ubtc" diff --git a/x/common/error_test.go b/x/common/error_test.go index 5b274efc8..d4b57f3ef 100644 --- a/x/common/error_test.go +++ b/x/common/error_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" ) @@ -86,12 +87,12 @@ func TestCombineErrorsGeneric(t *testing.T) { {name: "type=[]string | mixed", in: []string{"", "abc", ""}, out: errors.New(": abc: ")}, // cases: fmt.Stringer - {name: "type=fmt.Stringer |", in: common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), out: errors.New("uusdc:unusd")}, + {name: "type=fmt.Stringer |", in: common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), out: errors.New("uusdc:unusd")}, // cases: []fmt.Stringer { name: "type=[]fmt.Stringer | happy", - in: []fmt.Stringer{common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)}, + in: []fmt.Stringer{common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)}, out: errors.New("ubtc:unusd: ueth:unusd")}, {name: "type=[]fmt.Stringer | empty", in: []fmt.Stringer{}, out: nil}, } diff --git a/x/dex/client/testutil/cli_test.go b/x/dex/client/testutil/cli_test.go index 2b678adfa..e0f37bff1 100644 --- a/x/dex/client/testutil/cli_test.go +++ b/x/dex/client/testutil/cli_test.go @@ -7,15 +7,15 @@ import ( "github.com/stretchr/testify/suite" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil/testapp" ) func TestIntegrationTestSuite(t *testing.T) { coinsFromGenesis := []string{ - common.DenomNIBI, - common.DenomNUSD, - common.DenomUSDC, + denoms.DenomNIBI, + denoms.DenomNUSD, + denoms.DenomUSDC, "coin-1", "coin-2", "coin-3", @@ -33,7 +33,7 @@ func TestIntegrationTestSuite(t *testing.T) { cfg := testapp.BuildNetworkConfig(genesisState) cfg.StartingTokens = sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 2e12), // for pool creation fee and more for tx fees + sdk.NewInt64Coin(denoms.DenomNIBI, 2e12), // for pool creation fee and more for tx fees ) for _, coin := range coinsFromGenesis { diff --git a/x/dex/client/testutil/test_helpers.go b/x/dex/client/testutil/test_helpers.go index c29456818..02ed577de 100644 --- a/x/dex/client/testutil/test_helpers.go +++ b/x/dex/client/testutil/test_helpers.go @@ -13,7 +13,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/dex/client/cli" "github.com/NibiruChain/nibiru/x/dex/types" "github.com/NibiruChain/nibiru/x/testutil/testapp" @@ -23,7 +23,7 @@ import ( var commonArgs = []string{ fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(common.DenomNIBI, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10))).String()), } // ExecMsgCreatePool broadcast a pool creation message. diff --git a/x/dex/keeper/balances_test.go b/x/dex/keeper/balances_test.go index ba8e9b838..791c8eb63 100644 --- a/x/dex/keeper/balances_test.go +++ b/x/dex/keeper/balances_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" "github.com/NibiruChain/nibiru/x/testutil/testapp" @@ -11,8 +12,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/stretchr/testify/require" - - "github.com/NibiruChain/nibiru/x/common" ) func TestCheckBalances(t *testing.T) { @@ -30,11 +29,11 @@ func TestCheckBalances(t *testing.T) { name: "has enough funds", userInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), coinsToSpend: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), expectedError: nil, }, @@ -45,7 +44,7 @@ func TestCheckBalances(t *testing.T) { ), coinsToSpend: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), expectedError: sdkerrors.ErrInsufficientFunds, }, diff --git a/x/dex/keeper/grpc_query_test.go b/x/dex/keeper/grpc_query_test.go index 11a0aeeec..43ede3844 100644 --- a/x/dex/keeper/grpc_query_test.go +++ b/x/dex/keeper/grpc_query_test.go @@ -3,19 +3,17 @@ package keeper_test import ( "testing" - "github.com/NibiruChain/nibiru/x/testutil" - - "github.com/NibiruChain/nibiru/x/testutil/testapp" - "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/dex/keeper" "github.com/NibiruChain/nibiru/x/dex/types" + "github.com/NibiruChain/nibiru/x/testutil" "github.com/NibiruChain/nibiru/x/testutil/mock" + "github.com/NibiruChain/nibiru/x/testutil/testapp" ) func TestParamsQuery(t *testing.T) { @@ -271,7 +269,7 @@ func TestQueryNumPools(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -285,22 +283,22 @@ func TestQueryNumPools(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomUSDC, 100), + sdk.NewInt64Coin(denoms.DenomUSDC, 100), ), /*shares=*/ 100, ), mock.DexPool( /*poolId=*/ 2, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomUSDC, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), mock.DexPool( /*poolId=*/ 3, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), sdk.NewInt64Coin("unibi", 100), ), /*shares=*/ 100, @@ -321,9 +319,9 @@ func TestQueryNumPools(t *testing.T) { ctx, sender, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1e18), - sdk.NewInt64Coin(common.DenomNUSD, 1e18), - sdk.NewInt64Coin(common.DenomUSDC, 1e18), + sdk.NewInt64Coin(denoms.DenomNIBI, 1e18), + sdk.NewInt64Coin(denoms.DenomNUSD, 1e18), + sdk.NewInt64Coin(denoms.DenomUSDC, 1e18), ), )) @@ -448,7 +446,7 @@ func TestQueryTotalShares(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -491,11 +489,11 @@ func TestQuerySpotPrice(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), - tokenInDenom: common.DenomNUSD, + tokenInDenom: denoms.DenomNUSD, tokenOutDenom: "unibi", expectedPrice: sdk.MustNewDecFromStr("1"), }, @@ -505,11 +503,11 @@ func TestQuerySpotPrice(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 200), + sdk.NewInt64Coin(denoms.DenomNUSD, 200), ), /*shares=*/ 100, ), - tokenInDenom: common.DenomNUSD, + tokenInDenom: denoms.DenomNUSD, tokenOutDenom: "unibi", expectedPrice: sdk.MustNewDecFromStr("2"), }, @@ -519,12 +517,12 @@ func TestQuerySpotPrice(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 200), + sdk.NewInt64Coin(denoms.DenomNUSD, 200), ), /*shares=*/ 100, ), tokenInDenom: "unibi", - tokenOutDenom: common.DenomNUSD, + tokenOutDenom: denoms.DenomNUSD, expectedPrice: sdk.MustNewDecFromStr("0.5"), }, } @@ -566,11 +564,11 @@ func TestQueryEstimateSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(common.DenomNUSD, 100), + tokenIn: sdk.NewInt64Coin(denoms.DenomNUSD, 100), tokenOutDenom: "unibi", expectedTokenOut: sdk.NewInt64Coin("unibi", 50), }, @@ -580,14 +578,14 @@ func TestQueryEstimateSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 34844867), - sdk.NewInt64Coin(common.DenomNUSD, 4684496849), + sdk.NewInt64Coin(denoms.DenomNUSD, 4684496849), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 586848), - tokenOutDenom: common.DenomNUSD, + tokenOutDenom: denoms.DenomNUSD, // https://www.wolframalpha.com/input?i=4684496849+-+%2834844867+*+4684496849+%2F+%2834844867%2B586848%29+%29 - expectedTokenOut: sdk.NewInt64Coin(common.DenomNUSD, 77588330), + expectedTokenOut: sdk.NewInt64Coin(denoms.DenomNUSD, 77588330), }, } @@ -627,14 +625,14 @@ func TestQueryEstimateSwapExactAmountOut(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokenOut: sdk.NewInt64Coin("unibi", 50), - tokenInDenom: common.DenomNUSD, + tokenInDenom: denoms.DenomNUSD, // there's a swap fee that we take the ceiling of to round int - expectedTokenIn: sdk.NewInt64Coin(common.DenomNUSD, 101), + expectedTokenIn: sdk.NewInt64Coin(denoms.DenomNUSD, 101), }, { name: "complex swap", @@ -642,11 +640,11 @@ func TestQueryEstimateSwapExactAmountOut(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 34844867), - sdk.NewInt64Coin(common.DenomNUSD, 4684496849), + sdk.NewInt64Coin(denoms.DenomNUSD, 4684496849), ), /*shares=*/ 100, ), - tokenOut: sdk.NewInt64Coin(common.DenomNUSD, 77588330), + tokenOut: sdk.NewInt64Coin(denoms.DenomNUSD, 77588330), tokenInDenom: "unibi", // https://www.wolframalpha.com/input?i=4684496849+-+%2834844867+*+4684496849+%2F+%2834844867%2B586848%29+%29 expectedTokenIn: sdk.NewInt64Coin("unibi", 586848), @@ -689,13 +687,13 @@ func TestQueryEstimateJoinExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), expectedPoolSharesOut: sdk.NewIntFromUint64(100), expectedRemCoins: sdk.NewCoins(), @@ -706,17 +704,17 @@ func TestQueryEstimateJoinExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 50), - sdk.NewInt64Coin(common.DenomNUSD, 75), + sdk.NewInt64Coin(denoms.DenomNUSD, 75), ), expectedPoolSharesOut: sdk.NewIntFromUint64(50), expectedRemCoins: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 25), + sdk.NewInt64Coin(denoms.DenomNUSD, 25), ), }, } @@ -756,7 +754,7 @@ func TestQueryEstimateExitExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -764,7 +762,7 @@ func TestQueryEstimateExitExactAmountIn(t *testing.T) { // exit fee leaves some tokens in pool expectedTokensOut: sdk.NewCoins( sdk.NewInt64Coin("unibi", 99), - sdk.NewInt64Coin(common.DenomNUSD, 99), + sdk.NewInt64Coin(denoms.DenomNUSD, 99), ), }, { @@ -773,7 +771,7 @@ func TestQueryEstimateExitExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -781,7 +779,7 @@ func TestQueryEstimateExitExactAmountIn(t *testing.T) { // exit fee leaves some tokens in pool expectedTokensOut: sdk.NewCoins( sdk.NewInt64Coin("unibi", 49), - sdk.NewInt64Coin(common.DenomNUSD, 49), + sdk.NewInt64Coin(denoms.DenomNUSD, 49), ), }, } diff --git a/x/dex/keeper/keeper_test.go b/x/dex/keeper/keeper_test.go index f630607d5..9d02da83f 100644 --- a/x/dex/keeper/keeper_test.go +++ b/x/dex/keeper/keeper_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" "github.com/NibiruChain/nibiru/x/testutil/testapp" @@ -60,11 +61,11 @@ func TestSetAndFetchPool(t *testing.T) { }, PoolAssets: []types.PoolAsset{ { - Token: sdk.NewCoin(common.DenomBTC, sdk.NewInt(1000)), + Token: sdk.NewCoin(denoms.DenomBTC, sdk.NewInt(1000)), Weight: sdk.NewInt(1), }, { - Token: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1000)), + Token: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1000)), Weight: sdk.NewInt(1), }, }, @@ -221,7 +222,7 @@ func TestFetchPoolFromPair(t *testing.T) { func TestNewPool(t *testing.T) { app, ctx := testapp.NewTestNibiruAppAndContext(true) - poolCreationFeeCoin := sdk.NewInt64Coin(common.DenomNIBI, 1000*common.Precision) + poolCreationFeeCoin := sdk.NewInt64Coin(denoms.DenomNIBI, 1000*common.Precision) app.DexKeeper.SetParams(ctx, types.NewParams( /*startingPoolNumber=*/ 1, /*poolCreationFee=*/ sdk.NewCoins(poolCreationFeeCoin), @@ -294,7 +295,7 @@ func TestNewPoolNotEnoughFunds(t *testing.T) { app.DexKeeper.SetParams(ctx, types.NewParams( /*startingPoolNumber=*/ 1, - /*poolCreationFee=*/ sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000*common.Precision)), + /*poolCreationFee=*/ sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1000*common.Precision)), /*whitelistedAssets*/ []string{}, )) @@ -426,9 +427,9 @@ func TestNewPoolDups(t *testing.T) { userAddr, err := sdk.AccAddressFromBech32(testutil.AccAddress().String()) require.NoError(t, err) - poolCreationFeeCoin := sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1)) + poolCreationFeeCoin := sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1)) err = simapp.FundAccount(app.BankKeeper, ctx, userAddr, sdk.NewCoins( - sdk.NewCoin(common.DenomNIBI, sdk.NewInt(1000)), + sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(1000)), sdk.NewCoin("bar", sdk.NewInt(1000)), sdk.NewCoin("foo", sdk.NewInt(1000)), )) diff --git a/x/dex/keeper/msg_server_test.go b/x/dex/keeper/msg_server_test.go index a504c908f..b421b79dc 100644 --- a/x/dex/keeper/msg_server_test.go +++ b/x/dex/keeper/msg_server_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" "github.com/NibiruChain/nibiru/x/testutil/testapp" @@ -14,7 +15,6 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" - "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/dex/keeper" "github.com/NibiruChain/nibiru/x/dex/types" "github.com/NibiruChain/nibiru/x/testutil/mock" @@ -66,7 +66,7 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), Weight: sdk.OneInt(), }, { @@ -85,7 +85,7 @@ func TestCreatePool(t *testing.T) { Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), Weight: sdk.OneInt(), }, }, @@ -96,11 +96,11 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1), + Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1), Weight: sdk.OneInt(), }, }, @@ -116,11 +116,11 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNIBI, 1), + Token: sdk.NewInt64Coin(denoms.DenomNIBI, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), Weight: sdk.OneInt(), }, }, @@ -134,18 +134,18 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1), + Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1e9), - sdk.NewInt64Coin(common.DenomNUSD, 1), - sdk.NewInt64Coin(common.DenomUSDC, 1), + sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), + sdk.NewInt64Coin(denoms.DenomNUSD, 1), + sdk.NewInt64Coin(denoms.DenomUSDC, 1), ), expectedErr: nil, }, @@ -186,7 +186,7 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), Weight: sdk.OneInt(), }, { @@ -205,7 +205,7 @@ func TestCreatePool(t *testing.T) { Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), Weight: sdk.OneInt(), }, }, @@ -216,11 +216,11 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1), + Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1), Weight: sdk.OneInt(), }, }, @@ -236,11 +236,11 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNIBI, 1), + Token: sdk.NewInt64Coin(denoms.DenomNIBI, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), Weight: sdk.OneInt(), }, }, @@ -254,18 +254,18 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1), + Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1e9), - sdk.NewInt64Coin(common.DenomNUSD, 1), - sdk.NewInt64Coin(common.DenomUSDC, 1), + sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), + sdk.NewInt64Coin(denoms.DenomNUSD, 1), + sdk.NewInt64Coin(denoms.DenomUSDC, 1), ), expectedErr: nil, }, @@ -323,18 +323,18 @@ func TestCreateExitJoinPool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1e9), - sdk.NewInt64Coin(common.DenomNUSD, 1_000), - sdk.NewInt64Coin(common.DenomUSDC, 1_000), + sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), + sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), + sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), ), expectedErr: nil, useAllCoins: true, @@ -344,18 +344,18 @@ func TestCreateExitJoinPool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1e9), - sdk.NewInt64Coin(common.DenomNUSD, 1_000), - sdk.NewInt64Coin(common.DenomUSDC, 1_000), + sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), + sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), + sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), ), expectedErr: nil, useAllCoins: true, @@ -365,18 +365,18 @@ func TestCreateExitJoinPool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1e9), - sdk.NewInt64Coin(common.DenomNUSD, 1_000), - sdk.NewInt64Coin(common.DenomUSDC, 1_000), + sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), + sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), + sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), ), expectedErr: nil, useAllCoins: false, @@ -386,18 +386,18 @@ func TestCreateExitJoinPool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1e9), - sdk.NewInt64Coin(common.DenomNUSD, 1_000), - sdk.NewInt64Coin(common.DenomUSDC, 1_000), + sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), + sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), + sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), ), expectedErr: nil, useAllCoins: false, @@ -441,14 +441,14 @@ func TestCreateExitJoinPool(t *testing.T) { require.Equal( t, - tc.senderInitialFunds.Sub(sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1e9))), + tc.senderInitialFunds.Sub(sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1e9))), app.BankKeeper.GetAllBalances(ctx, tc.creatorAddr), ) msgJoinPool := types.MsgJoinPool{ Sender: tc.creatorAddr.String(), PoolId: 1, - TokensIn: tc.senderInitialFunds.Sub(sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1e9))), + TokensIn: tc.senderInitialFunds.Sub(sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1e9))), UseAllCoins: tc.useAllCoins, } _, err = msgServer.JoinPool(sdk.WrapSDKContext(ctx), &msgJoinPool) @@ -479,18 +479,18 @@ func TestMsgServerJoinPool(t *testing.T) { name: "join with all assets", joinerInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 100), expectedRemCoins: sdk.NewCoins(), @@ -499,7 +499,7 @@ func TestMsgServerJoinPool(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 200), - sdk.NewInt64Coin(common.DenomNUSD, 200), + sdk.NewInt64Coin(denoms.DenomNUSD, 200), ), /*shares=*/ 200), }, @@ -507,31 +507,31 @@ func TestMsgServerJoinPool(t *testing.T) { name: "join with some assets, none remaining", joinerInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.DenomNUSD, 50), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 50), expectedRemCoins: sdk.NewCoins(), expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin(shareDenom, 50), sdk.NewInt64Coin("unibi", 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.DenomNUSD, 50), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 150), - sdk.NewInt64Coin(common.DenomNUSD, 150), + sdk.NewInt64Coin(denoms.DenomNUSD, 150), ), /*shares=*/ 150), }, @@ -539,33 +539,33 @@ func TestMsgServerJoinPool(t *testing.T) { name: "join with some assets, some remaining", joinerInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 50), - sdk.NewInt64Coin(common.DenomNUSD, 75), + sdk.NewInt64Coin(denoms.DenomNUSD, 75), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 50), expectedRemCoins: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 25), + sdk.NewInt64Coin(denoms.DenomNUSD, 25), ), expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin(shareDenom, 50), sdk.NewInt64Coin("unibi", 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.DenomNUSD, 50), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 150), - sdk.NewInt64Coin(common.DenomNUSD, 150), + sdk.NewInt64Coin(denoms.DenomNUSD, 150), ), /*shares=*/ 150), }, @@ -573,18 +573,18 @@ func TestMsgServerJoinPool(t *testing.T) { name: "join with all assets - Stablepool", joinerInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 100), expectedRemCoins: sdk.NewCoins(), @@ -593,7 +593,7 @@ func TestMsgServerJoinPool(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 200), - sdk.NewInt64Coin(common.DenomNUSD, 200), + sdk.NewInt64Coin(denoms.DenomNUSD, 200), ), /*shares=*/ 200), }, @@ -601,31 +601,31 @@ func TestMsgServerJoinPool(t *testing.T) { name: "join with some assets, none remaining - Stablepool", joinerInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.DenomNUSD, 50), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 50), expectedRemCoins: []sdk.Coin{}, expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin(shareDenom, 50), sdk.NewInt64Coin("unibi", 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.DenomNUSD, 50), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 150), - sdk.NewInt64Coin(common.DenomNUSD, 150), + sdk.NewInt64Coin(denoms.DenomNUSD, 150), ), /*shares=*/ 150), }, @@ -633,31 +633,31 @@ func TestMsgServerJoinPool(t *testing.T) { name: "join with some assets, some remaining - Stablepool", joinerInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 50), - sdk.NewInt64Coin(common.DenomNUSD, 75), + sdk.NewInt64Coin(denoms.DenomNUSD, 75), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 62), expectedRemCoins: []sdk.Coin{}, expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin(shareDenom, 62), sdk.NewInt64Coin("unibi", 50), - sdk.NewInt64Coin(common.DenomNUSD, 25), + sdk.NewInt64Coin(denoms.DenomNUSD, 25), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 150), - sdk.NewInt64Coin(common.DenomNUSD, 175), + sdk.NewInt64Coin(denoms.DenomNUSD, 175), ), /*shares=*/ 162), }, @@ -717,35 +717,35 @@ func TestMsgServerExitPool(t *testing.T) { name: "exit all pool shares", joinerInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), sdk.NewInt64Coin(shareDenom, 100), ), initialPoolFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), poolSharesIn: sdk.NewInt64Coin(shareDenom, 100), expectedTokensOut: sdk.NewCoins( sdk.NewInt64Coin("unibi", 99), - sdk.NewInt64Coin(common.DenomNUSD, 99), + sdk.NewInt64Coin(denoms.DenomNUSD, 99), ), expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 199), - sdk.NewInt64Coin(common.DenomNUSD, 199), + sdk.NewInt64Coin(denoms.DenomNUSD, 199), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 1), - sdk.NewInt64Coin(common.DenomNUSD, 1), + sdk.NewInt64Coin(denoms.DenomNUSD, 1), ), /*shares=*/ 0, ), @@ -754,36 +754,36 @@ func TestMsgServerExitPool(t *testing.T) { name: "exit half pool shares", joinerInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), sdk.NewInt64Coin(shareDenom, 100), ), initialPoolFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), poolSharesIn: sdk.NewInt64Coin(shareDenom, 50), expectedTokensOut: sdk.NewCoins( sdk.NewInt64Coin("unibi", 49), - sdk.NewInt64Coin(common.DenomNUSD, 49), + sdk.NewInt64Coin(denoms.DenomNUSD, 49), ), expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 149), - sdk.NewInt64Coin(common.DenomNUSD, 149), + sdk.NewInt64Coin(denoms.DenomNUSD, 149), sdk.NewInt64Coin(shareDenom, 50), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 51), - sdk.NewInt64Coin(common.DenomNUSD, 51), + sdk.NewInt64Coin(denoms.DenomNUSD, 51), ), /*shares=*/ 50, ), @@ -792,35 +792,35 @@ func TestMsgServerExitPool(t *testing.T) { name: "exit all pool shares - StablePool", joinerInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), sdk.NewInt64Coin(shareDenom, 100), ), initialPoolFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), poolSharesIn: sdk.NewInt64Coin(shareDenom, 100), expectedTokensOut: sdk.NewCoins( sdk.NewInt64Coin("unibi", 99), - sdk.NewInt64Coin(common.DenomNUSD, 99), + sdk.NewInt64Coin(denoms.DenomNUSD, 99), ), expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 199), - sdk.NewInt64Coin(common.DenomNUSD, 199), + sdk.NewInt64Coin(denoms.DenomNUSD, 199), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 1), - sdk.NewInt64Coin(common.DenomNUSD, 1), + sdk.NewInt64Coin(denoms.DenomNUSD, 1), ), /*shares=*/ 0, ), @@ -829,36 +829,36 @@ func TestMsgServerExitPool(t *testing.T) { name: "exit half pool shares - StablePool", joinerInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), sdk.NewInt64Coin(shareDenom, 100), ), initialPoolFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), poolSharesIn: sdk.NewInt64Coin(shareDenom, 50), expectedTokensOut: sdk.NewCoins( sdk.NewInt64Coin("unibi", 49), - sdk.NewInt64Coin(common.DenomNUSD, 49), + sdk.NewInt64Coin(denoms.DenomNUSD, 49), ), expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 149), - sdk.NewInt64Coin(common.DenomNUSD, 149), + sdk.NewInt64Coin(denoms.DenomNUSD, 149), sdk.NewInt64Coin(shareDenom, 50), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 51), - sdk.NewInt64Coin(common.DenomNUSD, 51), + sdk.NewInt64Coin(denoms.DenomNUSD, 51), ), /*shares=*/ 50, ), @@ -933,21 +933,21 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 100), - tokenOutDenom: common.DenomNUSD, - expectedTokenOut: sdk.NewInt64Coin(common.DenomNUSD, 50), + tokenOutDenom: denoms.DenomNUSD, + expectedTokenOut: sdk.NewInt64Coin(denoms.DenomNUSD, 50), expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.DenomNUSD, 50), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 200), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.DenomNUSD, 50), ), /*shares=*/ 100, ), @@ -962,12 +962,12 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 100), - tokenOutDenom: common.DenomNUSD, + tokenOutDenom: denoms.DenomNUSD, expectedUserFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 1), ), @@ -975,7 +975,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -990,12 +990,12 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("foo", 100), - tokenOutDenom: common.DenomNUSD, + tokenOutDenom: denoms.DenomNUSD, expectedUserFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("foo", 100), ), @@ -1003,7 +1003,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -1018,7 +1018,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -1031,7 +1031,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -1046,7 +1046,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -1059,7 +1059,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -1074,21 +1074,21 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 100), - tokenOutDenom: common.DenomNUSD, - expectedTokenOut: sdk.NewInt64Coin(common.DenomNUSD, 30), + tokenOutDenom: denoms.DenomNUSD, + expectedTokenOut: sdk.NewInt64Coin(denoms.DenomNUSD, 30), expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 30), + sdk.NewInt64Coin(denoms.DenomNUSD, 30), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 200), - sdk.NewInt64Coin(common.DenomNUSD, 70), + sdk.NewInt64Coin(denoms.DenomNUSD, 70), ), /*shares=*/ 100, ), @@ -1103,12 +1103,12 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 100), - tokenOutDenom: common.DenomNUSD, + tokenOutDenom: denoms.DenomNUSD, expectedUserFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 1), ), @@ -1116,7 +1116,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -1131,12 +1131,12 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("foo", 100), - tokenOutDenom: common.DenomNUSD, + tokenOutDenom: denoms.DenomNUSD, expectedUserFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("foo", 100), ), @@ -1144,7 +1144,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -1159,7 +1159,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -1172,7 +1172,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -1187,7 +1187,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -1200,7 +1200,7 @@ func TestMsgServerSwapAssets(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), diff --git a/x/dex/keeper/swap_test.go b/x/dex/keeper/swap_test.go index c91c7a799..9f1ca047f 100644 --- a/x/dex/keeper/swap_test.go +++ b/x/dex/keeper/swap_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" "github.com/NibiruChain/nibiru/x/testutil/testapp" @@ -12,7 +13,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/dex/types" "github.com/NibiruChain/nibiru/x/testutil/mock" ) @@ -93,21 +93,21 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 100), - tokenOutDenom: common.DenomNUSD, - expectedTokenOut: sdk.NewInt64Coin(common.DenomNUSD, 50), + tokenOutDenom: denoms.DenomNUSD, + expectedTokenOut: sdk.NewInt64Coin(denoms.DenomNUSD, 50), expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.DenomNUSD, 50), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 200), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.DenomNUSD, 50), ), /*shares=*/ 100, ), @@ -122,12 +122,12 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 100), - tokenOutDenom: common.DenomNUSD, + tokenOutDenom: denoms.DenomNUSD, expectedUserFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 1), ), @@ -135,7 +135,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -150,12 +150,12 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("foo", 100), - tokenOutDenom: common.DenomNUSD, + tokenOutDenom: denoms.DenomNUSD, expectedUserFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("foo", 100), ), @@ -163,7 +163,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -178,7 +178,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -191,7 +191,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -206,7 +206,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), @@ -219,7 +219,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.DenomNUSD, 100), ), /*shares=*/ 100, ), diff --git a/x/dex/simulation/operations.go b/x/dex/simulation/operations.go index 99c7add31..39b8f8108 100644 --- a/x/dex/simulation/operations.go +++ b/x/dex/simulation/operations.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/dex/keeper" "github.com/NibiruChain/nibiru/x/dex/types" ) @@ -359,9 +360,9 @@ func genPoolAssets( func fundAccountWithTokens(ctx sdk.Context, address sdk.AccAddress, bk types.BankKeeper) { million := 1 * common.Precision newTokens := sdk.NewCoins( - sdk.NewCoin(common.DenomNIBI, sdk.NewInt(int64(10*million))), - sdk.NewCoin(common.DenomUSDC, sdk.NewInt(int64(10*million))), - sdk.NewCoin(common.DenomNUSD, sdk.NewInt(int64(10*million))), + sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(int64(10*million))), + sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(int64(10*million))), + sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(int64(10*million))), ) err := bk.MintCoins(ctx, types.ModuleName, newTokens) diff --git a/x/dex/types/params.go b/x/dex/types/params.go index ba2668875..f42de0e6e 100644 --- a/x/dex/types/params.go +++ b/x/dex/types/params.go @@ -8,6 +8,7 @@ import ( "gopkg.in/yaml.v2" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" ) var _ paramtypes.ParamSet = (*Params)(nil) @@ -30,11 +31,11 @@ func NewParams(startingPoolNumber uint64, poolCreationFee sdk.Coins, whitelisted func DefaultParams() Params { return Params{ StartingPoolNumber: 1, - PoolCreationFee: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000*common.Precision)), // 1000 NIBI + PoolCreationFee: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1000*common.Precision)), // 1000 NIBI WhitelistedAsset: []string{ - common.DenomNIBI, - common.DenomUSDC, - common.DenomNUSD, + denoms.DenomNIBI, + denoms.DenomUSDC, + denoms.DenomNUSD, }, } } diff --git a/x/oracle/keeper/ballot_test.go b/x/oracle/keeper/ballot_test.go index 14780ac2e..1f35876b6 100644 --- a/x/oracle/keeper/ballot_test.go +++ b/x/oracle/keeper/ballot_test.go @@ -11,6 +11,7 @@ import ( "github.com/NibiruChain/collections" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle/types" ) @@ -32,14 +33,14 @@ func TestOrganizeAggregate(t *testing.T) { staking.EndBlocker(ctx, input.StakingKeeper) btcBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[2], power), } ethBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[2], power), } for i := range btcBallot { @@ -78,11 +79,11 @@ func TestOrganizeAggregate(t *testing.T) { // sort each ballot for comparison sort.Sort(btcBallot) sort.Sort(ethBallot) - sort.Sort(ballotMap[common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)]) - sort.Sort(ballotMap[common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)]) + sort.Sort(ballotMap[common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)]) + sort.Sort(ballotMap[common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)]) - require.Equal(t, btcBallot, ballotMap[common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)]) - require.Equal(t, ethBallot, ballotMap[common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)]) + require.Equal(t, btcBallot, ballotMap[common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)]) + require.Equal(t, ethBallot, ballotMap[common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)]) } func TestClearBallots(t *testing.T) { @@ -103,14 +104,14 @@ func TestClearBallots(t *testing.T) { staking.EndBlocker(ctx, input.StakingKeeper) btcBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[2], power), } ethBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[2], power), } for i := range btcBallot { diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index 440070e23..41e91c0db 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle/types" @@ -30,8 +31,8 @@ func TestParams(t *testing.T) { slashWindow := uint64(1000) minValidPerWindow := sdk.NewDecWithPrec(1, 4) whitelist := []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), } // Should really test validateParams, but skipping because obvious diff --git a/x/oracle/keeper/msg_server_test.go b/x/oracle/keeper/msg_server_test.go index e9a5a9df1..da9a44e7c 100644 --- a/x/oracle/keeper/msg_server_test.go +++ b/x/oracle/keeper/msg_server_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/stretchr/testify/require" @@ -19,7 +20,7 @@ func TestMsgServer_FeederDelegation(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: randomExchangeRate, }, } @@ -86,43 +87,43 @@ func TestMsgServer_AggregatePrevoteVote(t *testing.T) { salt := "1" exchangeRates := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } otherExchangeRate := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } unintendedExchangeRateStr := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { diff --git a/x/oracle/keeper/querier_test.go b/x/oracle/keeper/querier_test.go index a1f4d1499..8b4f2644f 100644 --- a/x/oracle/keeper/querier_test.go +++ b/x/oracle/keeper/querier_test.go @@ -11,6 +11,7 @@ import ( "github.com/NibiruChain/collections" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle/types" ) @@ -31,7 +32,7 @@ func TestQueryExchangeRate(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), rate) // empty request _, err := querier.ExchangeRate(ctx, nil) @@ -39,7 +40,7 @@ func TestQueryExchangeRate(t *testing.T) { // Query to grpc res, err := querier.ExchangeRate(ctx, &types.QueryExchangeRateRequest{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), }) require.NoError(t, err) require.Equal(t, rate, res.ExchangeRate) @@ -71,15 +72,15 @@ func TestQueryExchangeRates(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), rate) res, err := querier.ExchangeRates(ctx, &types.QueryExchangeRatesRequest{}) require.NoError(t, err) require.Equal(t, types.ExchangeRateTuples{ - {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: rate}, - {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: rate}, + {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: rate}, + {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: rate}, }, res.ExchangeRates) } @@ -89,12 +90,12 @@ func TestQueryExchangeRateTwap(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.SetPrice(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), rate) + input.OracleKeeper.SetPrice(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), rate) - _, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)}) + _, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)}) require.Error(t, err) - res, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)}) + res, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)}) require.NoError(t, err) require.Equal(t, sdk.MustNewDecFromStr("1700"), res.ExchangeRate) } @@ -114,25 +115,25 @@ func TestCalcTwap(t *testing.T) { // expected price: (9.5 * (35 - 30) + 8.5 * (30 - 20) + 9.0 * (20 - 5)) / 30 = 8.916666 { name: "spot price twap calc, t=(5,35]", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), priceSnapshots: []types.PriceSnapshot{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Price: sdk.MustNewDecFromStr("90000.0"), TimestampMs: time.UnixMilli(1).UnixMilli(), }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Price: sdk.MustNewDecFromStr("9.0"), TimestampMs: time.UnixMilli(10).UnixMilli(), }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Price: sdk.MustNewDecFromStr("8.5"), TimestampMs: time.UnixMilli(20).UnixMilli(), }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Price: sdk.MustNewDecFromStr("9.5"), TimestampMs: time.UnixMilli(30).UnixMilli(), }, @@ -166,12 +167,12 @@ func TestCalcTwap(t *testing.T) { ctx = ctx.WithBlockTime(time.UnixMilli(0)) for _, reserve := range tc.priceSnapshots { ctx = ctx.WithBlockTime(time.UnixMilli(reserve.TimestampMs)) - input.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), reserve.Price) + input.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserve.Price) } ctx = ctx.WithBlockTime(tc.currentBlockTime).WithBlockHeight(tc.currentBlockHeight) - price, err := querier.ExchangeRateTwap(sdk.WrapSDKContext(ctx), &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)}) + price, err := querier.ExchangeRateTwap(sdk.WrapSDKContext(ctx), &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)}) require.NoError(t, err) require.EqualValuesf(t, tc.expectedPrice, price.ExchangeRate, @@ -186,17 +187,17 @@ func TestQueryActives(t *testing.T) { queryClient := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), rate) res, err := queryClient.Actives(ctx, &types.QueryActivesRequest{}) require.NoError(t, err) targetPairs := []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), } require.Equal(t, targetPairs, res.Actives) diff --git a/x/oracle/keeper/reward_test.go b/x/oracle/keeper/reward_test.go index 793a9b46e..f0a12d352 100644 --- a/x/oracle/keeper/reward_test.go +++ b/x/oracle/keeper/reward_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle" "github.com/NibiruChain/nibiru/x/oracle/keeper" "github.com/NibiruChain/nibiru/x/oracle/types" @@ -57,7 +58,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { valPeriodicRewards := sdk.NewDecCoinsFromCoins(rewards). QuoDec(sdk.NewDec(int64(periods))). QuoDec(sdk.NewDec(int64(validators))) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), sdk.NewCoins(rewards), periods) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), sdk.NewCoins(rewards), periods) for i := uint64(1); i <= periods; i++ { for valIndex := 0; valIndex < validators; valIndex++ { @@ -65,7 +66,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { // passes the current context block height for pre vote // then changes the height to current height + vote period for the vote makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{ - Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate, }}, valIndex) } @@ -82,8 +83,8 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { } // assert there are no rewards for pair - require.True(t, input.OracleKeeper.GatherRewardsForVotePeriod(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)).IsZero()) + require.True(t, input.OracleKeeper.GatherRewardsForVotePeriod(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)).IsZero()) // assert that there are no rewards instances - require.Empty(t, input.OracleKeeper.PairRewards.Indexes.RewardsByPair.ExactMatch(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)).PrimaryKeys()) + require.Empty(t, input.OracleKeeper.PairRewards.Indexes.RewardsByPair.ExactMatch(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)).PrimaryKeys()) } diff --git a/x/oracle/keeper/slash_test.go b/x/oracle/keeper/slash_test.go index 068f72064..b3b1d43a9 100644 --- a/x/oracle/keeper/slash_test.go +++ b/x/oracle/keeper/slash_test.go @@ -11,6 +11,7 @@ import ( "github.com/NibiruChain/collections" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle" "github.com/NibiruChain/nibiru/x/oracle/keeper" types3 "github.com/NibiruChain/nibiru/x/oracle/types" @@ -90,9 +91,9 @@ func TestSlashAndResetMissCounters(t *testing.T) { func TestInvalidVotesSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) votePeriodsPerWindow := types.NewDec(int64(input.OracleKeeper.SlashWindow(input.Ctx))).QuoInt64(int64(input.OracleKeeper.VotePeriod(input.Ctx))).TruncateInt64() slashFraction := input.OracleKeeper.SlashFraction(input.Ctx) @@ -102,13 +103,13 @@ func TestInvalidVotesSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, miss vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, i+1, input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[1], 0)) @@ -119,13 +120,13 @@ func TestInvalidVotesSlashing(t *testing.T) { // one more miss vote will inccur keeper.ValAddrs[1] slashing // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, miss vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) input.Ctx = input.Ctx.WithBlockHeight(votePeriodsPerWindow - 1) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -144,9 +145,9 @@ func TestWhitelistSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, i+1, input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[0], 0)) @@ -158,9 +159,9 @@ func TestWhitelistSlashing(t *testing.T) { // one more miss vote will inccur Account 1 slashing // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) input.Ctx = input.Ctx.WithBlockHeight(votePeriodsPerWindow - 1) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -171,19 +172,19 @@ func TestWhitelistSlashing(t *testing.T) { func TestNotPassedBallotSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[0], 0)) @@ -194,14 +195,14 @@ func TestNotPassedBallotSlashing(t *testing.T) { func TestAbstainSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) votePeriodsPerWindow := types.NewDec(int64(input.OracleKeeper.SlashWindow(input.Ctx))).QuoInt64(int64(input.OracleKeeper.VotePeriod(input.Ctx))).TruncateInt64() minValidPerWindow := input.OracleKeeper.MinValidPerWindow(input.Ctx) @@ -210,13 +211,13 @@ func TestAbstainSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, abstain vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: types.ZeroDec()}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: types.ZeroDec()}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[1], 0)) diff --git a/x/oracle/keeper/tally_fuzz_test.go b/x/oracle/keeper/tally_fuzz_test.go index 24e81e50d..f693dd813 100644 --- a/x/oracle/keeper/tally_fuzz_test.go +++ b/x/oracle/keeper/tally_fuzz_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle/types" "github.com/NibiruChain/nibiru/x/testutil" ) @@ -131,11 +132,11 @@ func TestRemoveInvalidBallots(t *testing.T) { "x": types.ExchangeRateBallots{ {Pair: "x", ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD): types.ExchangeRateBallots{ - {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD): types.ExchangeRateBallots{ + {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD): types.ExchangeRateBallots{ - {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD): types.ExchangeRateBallots{ + {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, }, }, diff --git a/x/oracle/keeper/test_utils.go b/x/oracle/keeper/test_utils.go index 282c3d867..fbbd76c86 100644 --- a/x/oracle/keeper/test_utils.go +++ b/x/oracle/keeper/test_utils.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/bank" @@ -111,7 +112,7 @@ var ( } InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction) - InitCoins = sdk.NewCoins(sdk.NewCoin(common.DenomNIBI, InitTokens)) + InitCoins = sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, InitTokens)) OracleDecPrecision = 8 ) @@ -175,7 +176,7 @@ func CreateTestInput(t *testing.T) TestInput { accountKeeper := authkeeper.NewAccountKeeper(appCodec, keyAcc, paramsKeeper.Subspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms) bankKeeper := bankkeeper.NewBaseKeeper(appCodec, keyBank, accountKeeper, paramsKeeper.Subspace(banktypes.ModuleName), blackListAddrs) - totalSupply := sdk.NewCoins(sdk.NewCoin(common.DenomNIBI, InitTokens.MulRaw(int64(len(Addrs)*10)))) + totalSupply := sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, InitTokens.MulRaw(int64(len(Addrs)*10)))) bankKeeper.MintCoins(ctx, faucetAccountName, totalSupply) stakingKeeper := stakingkeeper.NewKeeper( @@ -187,7 +188,7 @@ func CreateTestInput(t *testing.T) TestInput { ) stakingParams := stakingtypes.DefaultParams() - stakingParams.BondDenom = common.DenomNIBI + stakingParams.BondDenom = denoms.DenomNIBI stakingKeeper.SetParams(ctx, stakingParams) distrKeeper := distrkeeper.NewKeeper( @@ -210,7 +211,7 @@ func CreateTestInput(t *testing.T) TestInput { distrAcc := authtypes.NewEmptyModuleAccount(distrtypes.ModuleName) oracleAcc := authtypes.NewEmptyModuleAccount(types.ModuleName, authtypes.Minter) - bankKeeper.SendCoinsFromModuleToModule(ctx, faucetAccountName, stakingtypes.NotBondedPoolName, sdk.NewCoins(sdk.NewCoin(common.DenomNIBI, InitTokens.MulRaw(int64(len(Addrs)))))) + bankKeeper.SendCoinsFromModuleToModule(ctx, faucetAccountName, stakingtypes.NotBondedPoolName, sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, InitTokens.MulRaw(int64(len(Addrs)))))) accountKeeper.SetModuleAccount(ctx, feeCollectorAcc) accountKeeper.SetModuleAccount(ctx, bondPool) @@ -249,7 +250,7 @@ func CreateTestInput(t *testing.T) TestInput { func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator { commission := stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) msg, _ := stakingtypes.NewMsgCreateValidator( - address, pubKey, sdk.NewCoin(common.DenomNIBI, amt), + address, pubKey, sdk.NewCoin(denoms.DenomNIBI, amt), stakingtypes.Description{}, commission, sdk.OneInt(), ) diff --git a/x/oracle/keeper/update_exchange_rates_test.go b/x/oracle/keeper/update_exchange_rates_test.go index e41b8450a..85053cc04 100644 --- a/x/oracle/keeper/update_exchange_rates_test.go +++ b/x/oracle/keeper/update_exchange_rates_test.go @@ -15,6 +15,7 @@ import ( "github.com/NibiruChain/collections" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle" "github.com/NibiruChain/nibiru/x/oracle/keeper" "github.com/NibiruChain/nibiru/x/oracle/types" @@ -23,7 +24,7 @@ import ( func TestOracleThreshold(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: randomExchangeRate, }, } @@ -120,15 +121,15 @@ func TestOracleThreshold(t *testing.T) { func TestOracleDrop(t *testing.T) { input, h := setup(t) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), randomExchangeRate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), randomExchangeRate) // Account 1, pair gov stable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) // Immediately swap halt after an illiquid oracle vote oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) require.Error(t, err) } @@ -142,7 +143,7 @@ func TestOracleTally(t *testing.T) { for i, rate := range rates { decExchangeRate := sdk.NewDecWithPrec(int64(rate*math.Pow10(keeper.OracleDecPrecision)), int64(keeper.OracleDecPrecision)) exchangeRateStr, err := types.ExchangeRateTuples{ - {ExchangeRate: decExchangeRate, Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)}}.ToString() + {ExchangeRate: decExchangeRate, Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)}}.ToString() require.NoError(t, err) salt := fmt.Sprintf("%d", i) @@ -161,7 +162,7 @@ func TestOracleTally(t *testing.T) { } vote := types.NewExchangeRateBallot( - decExchangeRate, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), valAddrs[i], power) + decExchangeRate, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), valAddrs[i], power) ballot = append(ballot, vote) // change power of every three validator @@ -221,7 +222,7 @@ func TestOracleTallyTiming(t *testing.T) { // all the keeper.Addrs vote for the block ... not last period block yet, so tally fails for i := range keeper.Addrs[:2] { - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, i) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, i) } params := input.OracleKeeper.GetParams(input.Ctx) @@ -230,13 +231,13 @@ func TestOracleTallyTiming(t *testing.T) { require.Equal(t, 0, int(input.Ctx.BlockHeight())) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) require.Error(t, err) input.Ctx = input.Ctx.WithBlockHeight(int64(params.VotePeriod - 1)) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err = input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + _, err = input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) require.NoError(t, err) } @@ -246,13 +247,13 @@ func TestOracleRewardDistribution(t *testing.T) { input, h := setup(t) // Account 1, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) rewardAllocation := sdk.NewCoins(sdk.NewCoin("reward", sdk.NewInt(1*common.Precision))) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), rewardAllocation, 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), rewardAllocation, 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -260,32 +261,32 @@ func TestOracleRewardDistribution(t *testing.T) { distributionRewards := input.DistrKeeper.GetValidatorOutstandingRewards(input.Ctx.WithBlockHeight(2), keeper.ValAddrs[0]) require.Equalf(t, expectedRewardOneVal, distributionRewards.Rewards, "%s<=>%s", expectedRewardOneVal.String(), distributionRewards.String()) distributionRewards = input.DistrKeeper.GetValidatorOutstandingRewards(input.Ctx.WithBlockHeight(2), keeper.ValAddrs[1]) - require.Equal(t, expectedRewardOneVal, distributionRewards.Rewards, "%s %s", expectedRewardOneVal.String(), distributionRewards.Rewards.AmountOf(common.DenomNIBI).TruncateInt().String()) + require.Equal(t, expectedRewardOneVal, distributionRewards.Rewards, "%s %s", expectedRewardOneVal.String(), distributionRewards.Rewards.AmountOf(denoms.DenomNIBI).TruncateInt().String()) } func TestOracleRewardBand(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear pairs to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) rewardSpread := randomExchangeRate.Mul(input.OracleKeeper.RewardBand(input.Ctx).QuoInt64(2)) // no one will miss the vote // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread)}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread)}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -295,13 +296,13 @@ func TestOracleRewardBand(t *testing.T) { // Account 1 will miss the vote due to raward band condition // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread.Add(sdk.OneDec()))}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread.Add(sdk.OneDec()))}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -325,7 +326,7 @@ func TestOracleMultiRewardDistribution(t *testing.T) { makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.PairBTCStable.String(), ExchangeRate: randomExchangeRate}}, 2) rewardAmt := sdk.NewInt(100000000) - err := input.BankKeeper.MintCoins(input.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(common.DenomGov, rewardAmt))) + err := input.BankKeeper.MintCoins(input.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(denoms.DenomGov, rewardAmt))) require.NoError(t, err) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -337,11 +338,11 @@ func TestOracleMultiRewardDistribution(t *testing.T) { expectedRewardAmt3 := sdk.NewDecFromInt(rewardAmt.QuoRaw(3)).QuoInt64(int64(rewardDistributedWindow)).TruncateInt() rewards := input.DistrKeeper.GetValidatorOutstandingRewards(input.Ctx.WithBlockHeight(2), keeper.ValAddrs[0]) - require.Equal(t, expectedRewardAmt, rewards.Rewards.AmountOf(common.DenomGov).TruncateInt()) + require.Equal(t, expectedRewardAmt, rewards.Rewards.AmountOf(denoms.DenomGov).TruncateInt()) rewards = input.DistrKeeper.GetValidatorOutstandingRewards(input.Ctx.WithBlockHeight(2), keeper.ValAddrs[1]) - require.Equal(t, expectedRewardAmt2, rewards.Rewards.AmountOf(common.DenomGov).TruncateInt()) + require.Equal(t, expectedRewardAmt2, rewards.Rewards.AmountOf(denoms.DenomGov).TruncateInt()) rewards = input.DistrKeeper.GetValidatorOutstandingRewards(input.Ctx.WithBlockHeight(2), keeper.ValAddrs[2]) - require.Equal(t, expectedRewardAmt3, rewards.Rewards.AmountOf(common.DenomGov).TruncateInt()) + require.Equal(t, expectedRewardAmt3, rewards.Rewards.AmountOf(denoms.DenomGov).TruncateInt()) } */ @@ -355,19 +356,19 @@ func TestOracleExchangeRate(t *testing.T) { // govstable has been chosen as referenceExchangeRate by highest voting power // Account 1, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableExchangeRate}}, 0) // Account 2, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableExchangeRate}}, 1) // Account 3, govstable, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableExchangeRate}, {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), sdk.NewCoins(govStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), sdk.NewCoins(ethStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -403,13 +404,13 @@ func TestOracleEnsureSorted(t *testing.T) { ethStableRate3 := sdk.NewDec(int64(rand.Uint64() % 100000000)) // Account 1, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableRate1}, {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate1}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableRate1}, {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate1}}, 0) // Account 2, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableRate2}, {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate2}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate2}}, 1) // Account 3, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: govStableRate3}, {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: ethStableRate3}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: govStableRate3}, {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: ethStableRate3}}, 2) require.NotPanics(t, func() { oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -427,31 +428,31 @@ func TestOracleExchangeRateVal5(t *testing.T) { // govstable has been chosen as reference pair by highest voting power // Account 1, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate1}, {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableRate1}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate1}, {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableRate1}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate1}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate1}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate1}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate1}}, 2) // Account 4, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableRate2}}, 3) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableRate2}}, 3) // Account 5, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: ethStableRate2}}, 4) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableRate2}}, 4) ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), sdk.NewCoins(govStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), sdk.NewCoins(ethStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) - gotGovStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + gotGovStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) require.NoError(t, err) - gotEthStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)) + gotEthStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)) require.NoError(t, err) require.Equal(t, govStableRate1, gotGovStableRate) @@ -485,15 +486,15 @@ func TestWhitelistedPairs(t *testing.T) { for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) // govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) // set btcstable for next vote period - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -503,15 +504,15 @@ func TestWhitelistedPairs(t *testing.T) { require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[2], 0)) // whitelisted pairs are {govstable, btcstable} - require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) + require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) // govstable, missing btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) // delete btcstable for next vote period - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} input.OracleKeeper.SetParams(input.Ctx, params) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -520,13 +521,13 @@ func TestWhitelistedPairs(t *testing.T) { require.Equal(t, uint64(1), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[2], 0)) // btcstable must be deleted - require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) - require.False(t, input.OracleKeeper.WhitelistedPairs.Has(input.Ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD))) + require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) + require.False(t, input.OracleKeeper.WhitelistedPairs.Has(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD))) // govstable, no missing - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -542,11 +543,11 @@ func TestAbstainWithSmallStakingPower(t *testing.T) { for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: sdk.ZeroDec()}}, 0) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: sdk.ZeroDec()}}, 0) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) require.Error(t, err) } diff --git a/x/oracle/simulation/decoder_test.go b/x/oracle/simulation/decoder_test.go index 78f613c89..b27b04644 100644 --- a/x/oracle/simulation/decoder_test.go +++ b/x/oracle/simulation/decoder_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" gogotypes "github.com/gogo/protobuf/types" "github.com/stretchr/testify/require" @@ -34,8 +35,8 @@ func TestDecodeDistributionStore(t *testing.T) { aggregatePrevote := types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash([]byte("12345")), valAddr, 123) aggregateVote := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{ - {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: sdk.NewDecWithPrec(1234, 1)}, - {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: sdk.NewDecWithPrec(4321, 1)}, + {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: sdk.NewDecWithPrec(1234, 1)}, + {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: sdk.NewDecWithPrec(4321, 1)}, }, valAddr) pair := "btc:usd" diff --git a/x/oracle/simulation/genesis.go b/x/oracle/simulation/genesis.go index 99f4cfb9c..5eebf0e1c 100644 --- a/x/oracle/simulation/genesis.go +++ b/x/oracle/simulation/genesis.go @@ -8,6 +8,7 @@ import ( "math/rand" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -97,17 +98,17 @@ func RandomizedGenState(simState *module.SimulationState) { VoteThreshold: voteThreshold, RewardBand: rewardBand, Whitelist: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), }, SlashFraction: slashFraction, SlashWindow: slashWindow, MinValidPerWindow: minValidPerWindow, }, []types.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.NewDec(20_000)}, + {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(20_000)}, }, []types.FeederDelegation{}, []types.MissCounter{}, diff --git a/x/oracle/simulation/operations.go b/x/oracle/simulation/operations.go index 982aafb87..a30e6a516 100644 --- a/x/oracle/simulation/operations.go +++ b/x/oracle/simulation/operations.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" @@ -30,7 +31,7 @@ const ( ) var ( - whitelist = []common.AssetPair{common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)} + whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} voteHashMap map[string]string = make(map[string]string) ) diff --git a/x/oracle/types/ballot_test.go b/x/oracle/types/ballot_test.go index 8ad625f23..7ad4b99a1 100644 --- a/x/oracle/types/ballot_test.go +++ b/x/oracle/types/ballot_test.go @@ -7,6 +7,7 @@ import ( "strconv" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "testing" @@ -30,21 +31,21 @@ func TestToMap(t *testing.T) { { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(1600), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.ZeroDec(), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(1500), Power: 100, }, @@ -94,15 +95,15 @@ func TestToCrossRate(t *testing.T) { for _, data := range data { valAddr := sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()) if !data.base.IsZero() { - pbBase = append(pbBase, types.NewExchangeRateBallot(data.base, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), valAddr, 100)) + pbBase = append(pbBase, types.NewExchangeRateBallot(data.base, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), valAddr, 100)) } - pbQuote = append(pbQuote, types.NewExchangeRateBallot(data.quote, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), valAddr, 100)) + pbQuote = append(pbQuote, types.NewExchangeRateBallot(data.quote, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), valAddr, 100)) if !data.base.IsZero() && !data.quote.IsZero() { - cb = append(cb, types.NewExchangeRateBallot(data.base.Quo(data.quote), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), valAddr, 100)) + cb = append(cb, types.NewExchangeRateBallot(data.base.Quo(data.quote), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), valAddr, 100)) } else { - cb = append(cb, types.NewExchangeRateBallot(sdk.ZeroDec(), common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), valAddr, 0)) + cb = append(cb, types.NewExchangeRateBallot(sdk.ZeroDec(), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), valAddr, 0)) } } @@ -134,7 +135,7 @@ func TestPBPower(t *testing.T) { power := sk.Validator(ctx, valAccAddrs[i]).GetConsensusPower(sdk.DefaultPowerReduction) vote := types.NewExchangeRateBallot( sdk.ZeroDec(), - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), valAccAddrs[i], power, ) @@ -153,7 +154,7 @@ func TestPBPower(t *testing.T) { faceValAddr := sdk.ValAddress(pubKey.Address()) fakeVote := types.NewExchangeRateBallot( sdk.OneDec(), - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), faceValAddr, 0, ) @@ -224,7 +225,7 @@ func TestPBWeightedMedian(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDec(int64(input)), - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), valAddr, power, ) @@ -291,7 +292,7 @@ func TestPBStandardDeviation(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDecWithPrec(int64(input*base), int64(types.OracleDecPrecision)), - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), valAddr, power, ) @@ -310,12 +311,12 @@ func TestPBStandardDeviationOverflow(t *testing.T) { pb := types.ExchangeRateBallots{types.NewExchangeRateBallot( sdk.ZeroDec(), - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), valAddr, 2, ), types.NewExchangeRateBallot( exchangeRate, - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), valAddr, 1, )} diff --git a/x/oracle/types/msgs_test.go b/x/oracle/types/msgs_test.go index d678ddee6..ab006bcbb 100644 --- a/x/oracle/types/msgs_test.go +++ b/x/oracle/types/msgs_test.go @@ -3,8 +3,7 @@ package types_test import ( "testing" - "github.com/NibiruChain/nibiru/x/common" - + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle/types" "github.com/stretchr/testify/require" @@ -44,7 +43,7 @@ func TestMsgAggregateExchangeRatePrevote(t *testing.T) { sdk.AccAddress([]byte("addr1_______________")), } - exchangeRates := sdk.DecCoins{sdk.NewDecCoinFromDec(common.DenomUSDC, sdk.OneDec()), sdk.NewDecCoinFromDec(common.DenomNUSD, sdk.NewDecWithPrec(32121, 1))} + exchangeRates := sdk.DecCoins{sdk.NewDecCoinFromDec(denoms.DenomUSDC, sdk.OneDec()), sdk.NewDecCoinFromDec(denoms.DenomNUSD, sdk.NewDecWithPrec(32121, 1))} bz := types.GetAggregateVoteHash("1", exchangeRates.String(), sdk.ValAddress(addrs[0])) tests := []struct { diff --git a/x/oracle/types/params.go b/x/oracle/types/params.go index 11f2e22ea..2c355cc87 100644 --- a/x/oracle/types/params.go +++ b/x/oracle/types/params.go @@ -7,6 +7,7 @@ import ( "gopkg.in/yaml.v2" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" sdk "github.com/cosmos/cosmos-sdk/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -38,10 +39,10 @@ var ( DefaultVoteThreshold = sdk.NewDecWithPrec(50, 2) // 50% DefaultRewardBand = sdk.NewDecWithPrec(2, 2) // 2% (-1, 1) DefaultWhitelist = []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), } DefaultSlashFraction = sdk.NewDecWithPrec(1, 4) // 0.01% DefaultMinValidPerWindow = sdk.NewDecWithPrec(5, 2) // 5% diff --git a/x/perp/client/cli/cli_test.go b/x/perp/client/cli/cli_test.go index 8287f2033..985333cdf 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -16,6 +16,7 @@ import ( "github.com/NibiruChain/nibiru/app" "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" "github.com/NibiruChain/nibiru/x/perp/client/cli" perptypes "github.com/NibiruChain/nibiru/x/perp/types" @@ -51,7 +52,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -63,7 +64,7 @@ func (s *IntegrationTestSuite) SetupSuite() { }, }, { - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -81,11 +82,11 @@ func (s *IntegrationTestSuite) SetupSuite() { perpGenesis := perptypes.DefaultGenesis() perpGenesis.PairMetadata = []perptypes.PairMetadata{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), }, { - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, } @@ -94,12 +95,12 @@ func (s *IntegrationTestSuite) SetupSuite() { oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.Params.Whitelist = []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), } oracleGenesis.Params.VotePeriod = 1_000 oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), ExchangeRate: sdk.NewDec(20_000)}, - {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: sdk.NewDec(2_000)}, + {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(20_000)}, + {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(2_000)}, } genesisState[oracletypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(oracleGenesis) @@ -123,56 +124,56 @@ func (s *IntegrationTestSuite) SetupSuite() { s.NoError( testutilcli.FillWalletFromValidator(user1, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 10*common.Precision), - sdk.NewInt64Coin(common.DenomUSDC, 10*common.Precision), - sdk.NewInt64Coin(common.DenomNUSD, 50*common.Precision), + sdk.NewInt64Coin(denoms.DenomNIBI, 10*common.Precision), + sdk.NewInt64Coin(denoms.DenomUSDC, 10*common.Precision), + sdk.NewInt64Coin(denoms.DenomNUSD, 50*common.Precision), ), val, - common.DenomNIBI, + denoms.DenomNIBI, ), ) s.NoError( testutilcli.FillWalletFromValidator(user2, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1000), - sdk.NewInt64Coin(common.DenomUSDC, 1000), - sdk.NewInt64Coin(common.DenomNUSD, 100000), + sdk.NewInt64Coin(denoms.DenomNIBI, 1000), + sdk.NewInt64Coin(denoms.DenomUSDC, 1000), + sdk.NewInt64Coin(denoms.DenomNUSD, 100000), ), val, - common.DenomNIBI, + denoms.DenomNIBI, ), ) s.NoError( testutilcli.FillWalletFromValidator(user3, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1000), - sdk.NewInt64Coin(common.DenomUSDC, 1000), - sdk.NewInt64Coin(common.DenomNUSD, 49*common.Precision), + sdk.NewInt64Coin(denoms.DenomNIBI, 1000), + sdk.NewInt64Coin(denoms.DenomUSDC, 1000), + sdk.NewInt64Coin(denoms.DenomNUSD, 49*common.Precision), ), val, - common.DenomNIBI, + denoms.DenomNIBI, ), ) s.NoError( testutilcli.FillWalletFromValidator(user4, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1000), - sdk.NewInt64Coin(common.DenomUSDC, 1000), - sdk.NewInt64Coin(common.DenomNUSD, 100000), + sdk.NewInt64Coin(denoms.DenomNIBI, 1000), + sdk.NewInt64Coin(denoms.DenomUSDC, 1000), + sdk.NewInt64Coin(denoms.DenomNUSD, 100000), ), val, - common.DenomNIBI, + denoms.DenomNIBI, ), ) s.NoError( testutilcli.FillWalletFromValidator(user5, - sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000)), + sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1000)), val, - common.DenomNIBI, + denoms.DenomNIBI, ), ) } @@ -186,25 +187,25 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { val := s.network.Validators[0] user := s.users[0] - exchangeRate, err := testutilcli.QueryOracleExchangeRate(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + exchangeRate, err := testutilcli.QueryOracleExchangeRate(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) s.T().Logf("0. current exchange rate is: %+v", exchangeRate) s.NoError(err) s.T().Log("A. check vpool balances") - reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.NewDec(10*common.Precision), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_000*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("A. check trader has no existing positions") - _, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) + _, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) s.Error(err) s.T().Log("B. open position") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "buy", - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), /* leverage */ "1", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAssetLimit */ "1"}, @@ -213,18 +214,18 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("B. check vpool balance after open position") - reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("9999833.336111064815586407"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_001*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("B. check trader position") - queryResp, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) + queryResp, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("166.663888935184413593"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.OpenNotional) @@ -236,7 +237,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("C. open position with 2x leverage and zero baseAmtLimit") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "buy", - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), /* leverage */ "2", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAmtLimit */ "0", @@ -245,11 +246,11 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("C. check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.975001249937503125"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(3*common.Precision), queryResp.Position.OpenNotional) @@ -260,7 +261,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("D. Open a reverse position smaller than the existing position") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "sell", - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), /* leverage */ "1", /* quoteAmt */ "100", // 100 uNUSD /* baseAssetLimit */ "1", @@ -269,18 +270,18 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("D. Check vpool after opening reverse position") - reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) s.NoError(err) s.T().Logf(" \n reserve assets: %+v \n", reserveAssets) s.EqualValues(sdk.MustNewDecFromStr("9999500.041663750215262154"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_002_999_900), reserveAssets.QuoteAssetReserve) s.T().Log("D. Check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.958336249784737846"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(2_999_900), queryResp.Position.OpenNotional) @@ -291,7 +292,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("E. Open a reverse position larger than the existing position") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "sell", - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), /* leverage */ "1", /* quoteAmt */ "4000000", // 4*10^6 uNUSD /* baseAssetLimit */ "0", @@ -300,11 +301,11 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("E. Check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("-166.686111713005402945"), queryResp.Position.Size_) s.EqualValues(sdk.MustNewDecFromStr("1000100.000000000000000494"), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("1000100.000000000000000494"), queryResp.Position.Margin) @@ -315,13 +316,13 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("F. Close position") txResp, err = testutilcli.ExecTx(s.network, cli.ClosePositionCmd(), user, []string{ - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), }) s.NoError(err) s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("F. check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) s.Error(err) s.T().Logf("query response: %+v", queryResp) @@ -335,12 +336,12 @@ func (s *IntegrationTestSuite) TestPositionEmptyAndClose() { user := s.users[0] // verify trader has no position (empty) - _, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), user) + _, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), user) s.Error(err, "no position found") // close position should produce error _, err = testutilcli.ExecTx(s.network, cli.ClosePositionCmd(), user, []string{ - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) } @@ -349,7 +350,7 @@ func (s *IntegrationTestSuite) TestQueryCumulativePremiumFractions() { val := s.network.Validators[0] s.T().Log("get cumulative funding payments") - queryResp, err := testutilcli.QueryCumulativePremiumFraction(val.ClientCtx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + queryResp, err := testutilcli.QueryCumulativePremiumFraction(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) s.NoError(err) s.EqualValues(sdk.NewDec(2), queryResp.CumulativePremiumFraction) } @@ -359,7 +360,7 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { s.T().Log("opening a position with user 0") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[0], []string{ "buy", - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), "10", // Leverage "1", // Quote asset amount "0.0000001", @@ -370,15 +371,15 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { // Remove margin to trigger bad debt on user 0 s.T().Log("removing margin on user 0....") _, err = testutilcli.ExecTx(s.network, cli.RemoveMarginCmd(), s.users[0], []string{ - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), - fmt.Sprintf("%s%s", "100", common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), + fmt.Sprintf("%s%s", "100", denoms.DenomNUSD), }) s.Contains(err.Error(), perptypes.ErrFailedRemoveMarginCanCauseBadDebt.Error()) } func (s *IntegrationTestSuite) TestX_AddMargin() { val := s.network.Validators[0] - pair := common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD) // Open a new position s.T().Log("opening a position with user 3....") @@ -410,7 +411,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { { name: "FAIL: position not found", args: []string{ - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), fmt.Sprintf("%s%s", "10000", pair.QuoteDenom()), }, expectedCode: 1, @@ -437,7 +438,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidate a position that does not exist") _, err := testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), s.users[1].String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) @@ -445,7 +446,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("opening a position with user 1....") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[1], []string{ "buy", - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), "15", // Leverage "90000", // Quote asset amount "0", @@ -455,7 +456,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidate a position that is above maintenance margin mario") _, err = testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), s.users[1].String(), }) s.Contains(err.Error(), "margin ratio is too healthy to liquidate") @@ -463,7 +464,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("opening a position with user 2...") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[2], []string{ "sell", - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), "15", // Leverage "45000000", // Quote asset amount "0", @@ -479,7 +480,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidating user 1...") txResp, err = testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), s.users[1].String(), }) s.NoError(err) diff --git a/x/perp/genesis_test.go b/x/perp/genesis_test.go index 4d3b64e4e..e367ad018 100644 --- a/x/perp/genesis_test.go +++ b/x/perp/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/NibiruChain/collections" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" simapp2 "github.com/NibiruChain/nibiru/simapp" @@ -39,9 +40,9 @@ func TestGenesis(t *testing.T) { // create some positions for i := int64(0); i < 100; i++ { addr := testutil.AccAddress() - app.PerpKeeper.Positions.Insert(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), addr), types.Position{ + app.PerpKeeper.Positions.Insert(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), addr), types.Position{ TraderAddress: addr.String(), - Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), Size_: sdk.NewDec(i + 1), Margin: sdk.NewDec(i * 2), OpenNotional: sdk.NewDec(i * 100), diff --git a/x/perp/keeper/calc_test.go b/x/perp/keeper/calc_test.go index fcb48129d..b35407826 100644 --- a/x/perp/keeper/calc_test.go +++ b/x/perp/keeper/calc_test.go @@ -10,6 +10,7 @@ import ( "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/perp/types" "github.com/NibiruChain/nibiru/x/testutil" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -28,7 +29,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { marginDelta := sdk.OneDec() _, err := nibiruApp.PerpKeeper.CalcRemainMarginWithFundingPayment( ctx, types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), }, marginDelta) require.ErrorIs(t, err, collections.ErrNotFound) }, diff --git a/x/perp/keeper/calc_unit_test.go b/x/perp/keeper/calc_unit_test.go index 2ebfb3f1e..e0ff458dc 100644 --- a/x/perp/keeper/calc_unit_test.go +++ b/x/perp/keeper/calc_unit_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -37,9 +38,9 @@ func TestCalcFreeCollateralErrors(t *testing.T) { test: func() { k, mocks, ctx := getKeeper(t) - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(false) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(false) - pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), testutil.AccAddress()) + pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), testutil.AccAddress()) _, err := k.calcFreeCollateral(ctx, pos) @@ -53,12 +54,12 @@ func TestCalcFreeCollateralErrors(t *testing.T) { k, mocks, ctx := getKeeper(t) mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true) + ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), testutil.AccAddress()) + pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), testutil.AccAddress()) freeCollateral, err := k.calcFreeCollateral(ctx, pos) @@ -150,7 +151,7 @@ func TestCalcFreeCollateralSuccess(t *testing.T) { pos := types.Position{ TraderAddress: testutil.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: tc.positionSize, Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(1000), @@ -159,19 +160,19 @@ func TestCalcFreeCollateralSuccess(t *testing.T) { } t.Log("mock vpool keeper") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.vpoolDirection, sdk.OneDec(), ).Return(tc.positionNotional, nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.vpoolDirection, sdk.OneDec(), 15*time.Minute, @@ -196,13 +197,13 @@ func TestGetLatestCumulativePremiumFraction(t *testing.T) { keeper, _, ctx := getKeeper(t) metadata := &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), } setPairMetadata(keeper, ctx, *metadata) latestCumulativePremiumFraction, err := keeper. - getLatestCumulativePremiumFraction(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + getLatestCumulativePremiumFraction(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) require.NoError(t, err) assert.Equal(t, sdk.NewDec(2), latestCumulativePremiumFraction) diff --git a/x/perp/keeper/clearing_house_integration_test.go b/x/perp/keeper/clearing_house_integration_test.go index 51db37c57..417ab87f9 100644 --- a/x/perp/keeper/clearing_house_integration_test.go +++ b/x/perp/keeper/clearing_house_integration_test.go @@ -6,6 +6,7 @@ import ( "github.com/NibiruChain/collections" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" testutilevents "github.com/NibiruChain/nibiru/x/testutil" @@ -44,7 +45,7 @@ func TestOpenPositionSuccess(t *testing.T) { }{ { name: "new long position", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), initialPosition: nil, side: types.Side_BUY, margin: sdk.NewInt(1000), @@ -61,9 +62,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing long position, go more long", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -85,9 +86,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing long position, decrease a bit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 10)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -109,9 +110,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing long position, decrease a lot", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1060)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1060)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -133,7 +134,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "new long position just under fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision*common.Precision)), initialPosition: nil, side: types.Side_BUY, margin: sdk.NewInt(47_619_047_619), @@ -150,7 +151,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "new short position", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), initialPosition: nil, side: types.Side_SELL, margin: sdk.NewInt(1000), @@ -167,9 +168,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing short position, go more short", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -191,9 +192,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing short position, decrease a bit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 10)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -215,9 +216,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing short position, decrease a lot", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1060)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1060)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -239,7 +240,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "new short position just under fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision*common.Precision)), initialPosition: nil, side: types.Side_SELL, margin: sdk.NewInt(47_619_047_619), @@ -267,7 +268,7 @@ func TestOpenPositionSuccess(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision*common.Precision), vpooltypes.VpoolConfig{ @@ -279,7 +280,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -294,11 +295,11 @@ func TestOpenPositionSuccess(t *testing.T) { } ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(time.Second * 5)) - resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) + resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) require.NoError(t, err) t.Log("assert position response") - assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), resp.Position.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), resp.Position.Pair) assert.EqualValues(t, traderAddr.String(), resp.Position.TraderAddress) assert.EqualValues(t, tc.expectedMargin, resp.Position.Margin, "margin") assert.EqualValues(t, tc.expectedOpenNotional, resp.Position.OpenNotional, "open notional") @@ -315,9 +316,9 @@ func TestOpenPositionSuccess(t *testing.T) { assert.EqualValues(t, tc.expectedPositionNotional, resp.PositionNotional) t.Log("assert position in state") - position, err := nibiruApp.PerpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr)) + position, err := nibiruApp.PerpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr)) require.NoError(t, err) - assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), position.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), position.Pair) assert.EqualValues(t, traderAddr.String(), position.TraderAddress) assert.EqualValues(t, tc.expectedMargin, position.Margin, "margin") assert.EqualValues(t, tc.expectedOpenNotional, position.OpenNotional, "open notional") @@ -330,19 +331,19 @@ func TestOpenPositionSuccess(t *testing.T) { ecosystemFundFee := nibiruApp.PerpKeeper.GetParams(ctx).EcosystemFundFeeRatio.Mul(exchangedNotional).RoundInt() testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionChangedEvent{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: traderAddr.String(), - Margin: sdk.NewCoin(common.DenomNUSD, tc.expectedMargin.RoundInt()), + Margin: sdk.NewCoin(denoms.DenomNUSD, tc.expectedMargin.RoundInt()), PositionNotional: tc.expectedPositionNotional, ExchangedNotional: exchangedNotional, ExchangedSize: exchangedSize, PositionSize: tc.expectedSize, RealizedPnl: tc.expectedRealizedPnl, UnrealizedPnlAfter: tc.expectedUnrealizedPnl, - BadDebt: sdk.NewCoin(common.DenomNUSD, sdk.ZeroInt()), + BadDebt: sdk.NewCoin(denoms.DenomNUSD, sdk.ZeroInt()), MarkPrice: tc.expectedMarkPrice, FundingPayment: sdk.ZeroDec(), - TransactionFee: sdk.NewCoin(common.DenomNUSD, feePoolFee.Add(ecosystemFundFee)), + TransactionFee: sdk.NewCoin(denoms.DenomNUSD, feePoolFee.Add(ecosystemFundFee)), BlockHeight: ctx.BlockHeight(), BlockTimeMs: ctx.BlockTime().UnixMilli(), }) @@ -370,7 +371,7 @@ func TestOpenPositionError(t *testing.T) { }{ { name: "not enough trader funds", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 999)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 999)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -381,10 +382,10 @@ func TestOpenPositionError(t *testing.T) { }, { name: "position has bad debt", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 999)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 999)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -399,7 +400,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new long position not over base limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -410,7 +411,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new short position not under base limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -421,7 +422,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "quote asset amount is zero", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -432,7 +433,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "leverage amount is zero", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -443,7 +444,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "leverage amount is too high - SELL", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -454,7 +455,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "leverage amount is too high - BUY", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -465,7 +466,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new long position over fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision*common.Precision)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -476,7 +477,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new short position over fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision*common.Precision)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -487,7 +488,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new long position over trade limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10_000*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 10_000*common.Precision)), poolTradeLimitRatio: sdk.MustNewDecFromStr("0.01"), initialPosition: nil, side: types.Side_BUY, @@ -498,7 +499,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new short position over trade limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10_000*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 10_000*common.Precision)), poolTradeLimitRatio: sdk.MustNewDecFromStr("0.01"), initialPosition: nil, side: types.Side_SELL, @@ -519,7 +520,7 @@ func TestOpenPositionError(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /* tradeLimitRatio */ /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), @@ -533,7 +534,7 @@ func TestOpenPositionError(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -547,7 +548,7 @@ func TestOpenPositionError(t *testing.T) { } ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(time.Second * 5)) - resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) + resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) require.ErrorContains(t, err, tc.expectedErr.Error()) require.Nil(t, resp) }) diff --git a/x/perp/keeper/clearing_house_unit_test.go b/x/perp/keeper/clearing_house_unit_test.go index cdb34bc13..e7da98ed0 100644 --- a/x/perp/keeper/clearing_house_unit_test.go +++ b/x/perp/keeper/clearing_house_unit_test.go @@ -6,6 +6,7 @@ import ( "github.com/NibiruChain/collections" + "github.com/NibiruChain/nibiru/x/common/denoms" testutilevents "github.com/NibiruChain/nibiru/x/testutil" "github.com/cosmos/cosmos-sdk/codec" @@ -116,7 +117,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -132,7 +133,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -153,7 +154,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { baseAmount, err := perpKeeper.swapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.side, sdk.NewDec(10), sdk.NewDec(1), @@ -181,7 +182,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -193,7 +194,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(50), @@ -203,7 +204,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -212,7 +213,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, ) @@ -255,7 +256,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -267,7 +268,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(101), @@ -277,7 +278,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -285,7 +286,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -330,7 +331,7 @@ func TestIncreasePosition(t *testing.T) { // funding payment causes negative margin aka bad debt initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(110), // 110 BTC Margin: sdk.NewDec(11), // 11 NUSD OpenNotional: sdk.NewDec(110), // 110 NUSD @@ -342,7 +343,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(110), @@ -352,7 +353,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(110), ). @@ -360,7 +361,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.2"), }) }, @@ -403,7 +404,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -415,7 +416,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(200), @@ -425,7 +426,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -433,7 +434,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -476,7 +477,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -488,7 +489,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(99), @@ -498,7 +499,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -506,7 +507,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -552,7 +553,7 @@ func TestIncreasePosition(t *testing.T) { // funding payment causes bad debt initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -564,7 +565,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(105), /*baseAssetLimit=*/ sdk.NewDec(100), @@ -574,7 +575,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -582,7 +583,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("-0.3"), }) }, @@ -656,7 +657,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 200 NUSD and unrealized PnL of +100 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -664,7 +665,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -683,7 +684,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of -5 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -691,7 +692,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -710,7 +711,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of -50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -718,7 +719,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -739,7 +740,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of +50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-150), // -150 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -747,7 +748,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -766,7 +767,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 105 NUSD and unrealized PnL of -5 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -774,7 +775,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -793,7 +794,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 150 NUSD and unrealized PnL of -50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -801,7 +802,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -826,7 +827,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -835,7 +836,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /*quoteAssetDirection=*/ tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ tc.quoteAssetLimit, @@ -910,7 +911,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 100 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -945,7 +946,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 95 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(105), // 105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -980,7 +981,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -1017,7 +1018,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 95 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-105), // -105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1052,7 +1053,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 99.75 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1087,7 +1088,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 75 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1122,7 +1123,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1131,7 +1132,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /*quoteAssetDirection=*/ tc.quoteAssetDir, /*quoteAssetAmount=*/ tc.quoteAmountToDecrease, /*baseAssetLimit=*/ tc.exchangedBaseAmount.Abs(), @@ -1140,7 +1141,7 @@ func TestDecreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1508,7 +1509,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -1521,7 +1522,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), ). @@ -1530,7 +1531,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1541,7 +1542,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /*quoteAssetDirection=*/ tc.mockQuoteDir, /*quoteAssetAmount=*/ tc.inputQuoteAmount.Mul(tc.inputLeverage).Sub(tc.mockQuoteAmount), /*baseAssetLimit=*/ sdk.MaxDec(tc.inputBaseAssetLimit.Sub(currentPosition.Size_.Abs()), sdk.ZeroDec()), @@ -1551,7 +1552,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1689,7 +1690,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1715,7 +1716,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(105), // 105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1743,7 +1744,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-105), // -105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1769,7 +1770,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1806,7 +1807,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1815,7 +1816,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1852,7 +1853,7 @@ func TestClosePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1891,7 +1892,7 @@ func TestClosePosition(t *testing.T) { PositionSize: sdk.ZeroDec(), RealizedPnl: tc.expectedRealizedPnl, UnrealizedPnlAfter: sdk.ZeroDec(), - BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), sdk.ZeroInt()), + BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), sdk.ZeroInt()), MarkPrice: tc.newPositionNotional.Quo(tc.initialPosition.Size_.Abs()), FundingPayment: sdk.MustNewDecFromStr("0.02").Mul(tc.initialPosition.Size_), TransactionFee: sdk.NewInt64Coin(tc.initialPosition.Pair.QuoteDenom(), 0), @@ -1919,7 +1920,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { // user cannot close position due to bad debt initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -1940,7 +1941,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { // user cannot close position due to bad debt initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1969,7 +1970,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1979,7 +1980,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1988,7 +1989,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) diff --git a/x/perp/keeper/grpc_query_test.go b/x/perp/keeper/grpc_query_test.go index a7a006437..1960deb6b 100644 --- a/x/perp/keeper/grpc_query_test.go +++ b/x/perp/keeper/grpc_query_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -30,7 +31,7 @@ func initAppVpools( t.Log("initialize vpool and pair") assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), quoteAssetReserve, baseAssetReserve, vpooltypes.VpoolConfig{ @@ -42,12 +43,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -59,12 +60,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -76,7 +77,7 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) return ctx, nibiruApp, queryServer @@ -97,7 +98,7 @@ func TestQueryPosition(t *testing.T) { { name: "positive PnL", initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -114,7 +115,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, positive margin ratio", initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -131,7 +132,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, negative margin ratio", initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -166,7 +167,7 @@ func TestQueryPosition(t *testing.T) { sdk.WrapSDKContext(ctx), &types.QueryPositionRequest{ Trader: traderAddr.String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), }, ) require.NoError(t, err) @@ -192,7 +193,7 @@ func TestQueryPositions(t *testing.T) { name: "positive PnL", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -200,7 +201,7 @@ func TestQueryPositions(t *testing.T) { LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -263,7 +264,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "empty string pair", initialPairMetadata: &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -274,7 +275,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "pair metadata not found", initialPairMetadata: &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -285,11 +286,11 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "returns single funding payment", initialPairMetadata: &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), }, expectErr: false, expectedLatestCPF: sdk.ZeroDec(), @@ -304,7 +305,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { ctx, app, queryServer := initAppVpools(t, sdk.NewDec(481_000), sdk.NewDec(1_000)) t.Log("set index price") - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.OneDec()) t.Log("query cumulative premium fraction") resp, err := queryServer.CumulativePremiumFraction(sdk.WrapSDKContext(ctx), tc.query) @@ -339,7 +340,7 @@ func TestQueryMetrics(t *testing.T) { name: "two longs", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -347,7 +348,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -361,7 +362,7 @@ func TestQueryMetrics(t *testing.T) { name: "two shorts", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -369,7 +370,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -383,7 +384,7 @@ func TestQueryMetrics(t *testing.T) { name: "one long, one short", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -391,7 +392,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -405,14 +406,14 @@ func TestQueryMetrics(t *testing.T) { name: "decrease position", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -427,42 +428,42 @@ func TestQueryMetrics(t *testing.T) { name: "swap positions", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), @@ -488,7 +489,7 @@ func TestQueryMetrics(t *testing.T) { // Detect position decrease app.PerpKeeper.OnSwapEnd( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), position.OpenNotional, position.Size_, ) @@ -498,7 +499,7 @@ func TestQueryMetrics(t *testing.T) { resp, err := queryServer.Metrics( sdk.WrapSDKContext(ctx), &types.QueryMetricsRequest{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), }, ) require.NoError(t, err) diff --git a/x/perp/keeper/hooks_test.go b/x/perp/keeper/hooks_test.go index 74a53b005..3a5252baa 100644 --- a/x/perp/keeper/hooks_test.go +++ b/x/perp/keeper/hooks_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/NibiruChain/nibiru/x/common/denoms" testutilevents "github.com/NibiruChain/nibiru/x/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -50,7 +51,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { markPrice: sdk.NewDec(10), expectedLatestCumulativePremiumFraction: sdk.ZeroDec(), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), MarkPrice: sdk.NewDec(10), IndexPrice: sdk.NewDec(10), LatestFundingRate: sdk.ZeroDec(), @@ -66,7 +67,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { indexPrice: sdk.NewDec(462), expectedLatestCumulativePremiumFraction: sdk.MustNewDecFromStr("-9.229166666666666666"), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), MarkPrice: sdk.NewDec(19), IndexPrice: sdk.NewDec(462), LatestFundingRate: sdk.MustNewDecFromStr("-0.019976551226551227"), @@ -82,7 +83,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { indexPrice: sdk.NewDec(64), expectedLatestCumulativePremiumFraction: sdk.MustNewDecFromStr("14.1875"), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), MarkPrice: sdk.NewDec(745), IndexPrice: sdk.NewDec(64), LatestFundingRate: sdk.MustNewDecFromStr("0.2216796875"), @@ -107,7 +108,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { perpKeeper.AfterEpochEnd(ctx, "30 min", 1) t.Log("assert PairMetadataState") - pair, err := perpKeeper.PairsMetadata.Get(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + pair, err := perpKeeper.PairsMetadata.Get(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) require.NoError(t, err) assert.Equal(t, tc.expectedLatestCumulativePremiumFraction, pair.LatestCumulativePremiumFraction) @@ -130,23 +131,23 @@ func initParams(ctx sdk.Context, k Keeper) { TwapLookbackWindow: 15 * time.Minute, }) setPairMetadata(k, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), // start with one entry to ensure we append LatestCumulativePremiumFraction: sdk.ZeroDec(), }) } func setMocks(ctx sdk.Context, mocks mockedDependencies, indexPrice sdk.Dec, markPrice sdk.Dec) { - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true) mocks.mockEpochKeeper.EXPECT().GetEpochInfo(ctx, "30 min").Return( epochtypes.EpochInfo{Duration: 30 * time.Minute}, ).MaxTimes(1) mocks.mockOracleKeeper.EXPECT(). - GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(indexPrice, nil).MaxTimes(1) + GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(indexPrice, nil).MaxTimes(1) mocks.mockVpoolKeeper.EXPECT(). - GetMarkPriceTWAP(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), 15*time.Minute). + GetMarkPriceTWAP(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), 15*time.Minute). Return(markPrice, nil).MaxTimes(1) } diff --git a/x/perp/keeper/liquidate_unit_test.go b/x/perp/keeper/liquidate_unit_test.go index f65f02f36..3f63a027e 100644 --- a/x/perp/keeper/liquidate_unit_test.go +++ b/x/perp/keeper/liquidate_unit_test.go @@ -7,6 +7,7 @@ import ( "github.com/NibiruChain/collections" + "github.com/NibiruChain/nibiru/x/common/denoms" testutilevents "github.com/NibiruChain/nibiru/x/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -50,8 +51,8 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { exchangedSize: sdk.MustNewDecFromStr("0.25"), // 1 * 0.25 exchangedNotional: sdk.MustNewDecFromStr("239.75"), // 959 * 0.25 - expectedLiquidatorFee: sdk.NewInt64Coin(common.DenomNUSD, 3), // 959 * 0.25 * 0.025 / 2 - expectedPerpEFFee: sdk.NewInt64Coin(common.DenomNUSD, 3), // 959 * 0.25 * 0.025 / 2 + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 3), // 959 * 0.25 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 3), // 959 * 0.25 * 0.025 / 2 expectedPositionSize: sdk.MustNewDecFromStr("0.75"), // 1 - 0.25 expectedUnrealizedPnl: sdk.MustNewDecFromStr("-30.75"), // -41 * 0.75 @@ -69,8 +70,8 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { exchangedSize: sdk.MustNewDecFromStr("0.25"), // 1 * 0.5 exchangedNotional: sdk.MustNewDecFromStr("230.76923078"), // 923.0769231 * 0.5 - expectedLiquidatorFee: sdk.NewInt64Coin(common.DenomNUSD, 3), // 923.0769231 * 0.25 * 0.025 / 2 - expectedPerpEFFee: sdk.NewInt64Coin(common.DenomNUSD, 3), // 923.0769231 * 0.25 * 0.025 / 2 + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 3), // 923.0769231 * 0.25 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 3), // 923.0769231 * 0.25 * 0.025 / 2 expectedPositionSize: sdk.MustNewDecFromStr("0.75"), // 1 - 0.25 expectedUnrealizedPnl: sdk.MustNewDecFromStr("-57.692307675"), // -76.92307692 * 0.75 @@ -90,7 +91,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -103,25 +104,25 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true).Times(2) + ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.OneDec(), 15*time.Minute, @@ -130,7 +131,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.OneDec(), ). @@ -138,7 +139,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.exchangedSize, ). @@ -146,7 +147,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /* quoteAmt */ tc.exchangedNotional, /* baseLimit */ sdk.ZeroDec(), @@ -161,8 +162,8 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("mock bank keeper") mocks.mockBankKeeper.EXPECT(). - GetBalance(ctx, vaultAddr, common.DenomNUSD). - Return(sdk.NewInt64Coin(common.DenomNUSD, 1_000)) + GetBalance(ctx, vaultAddr, denoms.DenomNUSD). + Return(sdk.NewInt64Coin(denoms.DenomNUSD, 1_000)) mocks.mockBankKeeper.EXPECT(). SendCoinsFromModuleToAccount( ctx, types.VaultModuleAccount, liquidatorAddr, @@ -178,16 +179,16 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee, feeToFund) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr)) require.NoError(t, err) assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), newPosition.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), newPosition.Pair) assert.EqualValues(t, tc.expectedPositionSize, newPosition.Size_) assert.EqualValues(t, tc.expectedPositionMargin, newPosition.Margin) assert.EqualValues(t, tc.expectedPositionOpenNotional, newPosition.OpenNotional) @@ -195,15 +196,15 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.exchangedNotional, ExchangedPositionSize: tc.exchangedSize.Neg(), LiquidatorAddress: liquidatorAddr.String(), FeeToLiquidator: tc.expectedLiquidatorFee, FeeToEcosystemFund: tc.expectedPerpEFFee, - BadDebt: sdk.NewCoin(common.DenomNUSD, sdk.ZeroInt()), - Margin: sdk.NewCoin(common.DenomNUSD, tc.expectedPositionMargin.RoundInt()), + BadDebt: sdk.NewCoin(denoms.DenomNUSD, sdk.ZeroInt()), + Margin: sdk.NewCoin(denoms.DenomNUSD, tc.expectedPositionMargin.RoundInt()), PositionNotional: tc.newPositionNotional.Sub(tc.exchangedNotional), PositionSize: tc.initialPositionSize.Sub(tc.exchangedSize), UnrealizedPnl: tc.expectedUnrealizedPnl, @@ -237,8 +238,8 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { newPositionNotional: sdk.NewDec(923), // just below 2.5% margin ratio - expectedLiquidatorFee: sdk.NewInt64Coin(common.DenomNUSD, 12), // 923 * 0.025 / 2 - expectedPerpEFFee: sdk.NewInt64Coin(common.DenomNUSD, 11), // 23 - 12 + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 12), // 923 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 11), // 23 - 12 }, { name: "Full Liquidation - at 1.25%", @@ -249,8 +250,8 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { newPositionNotional: sdk.MustNewDecFromStr("911.3924051"), // at 1.25% margin ratio - expectedLiquidatorFee: sdk.NewInt64Coin(common.DenomNUSD, 11), - expectedPerpEFFee: sdk.NewInt64Coin(common.DenomNUSD, 0), + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 11), + expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 0), }, } @@ -265,7 +266,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -278,24 +279,24 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true).Times(2) + ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, 15*time.Minute, @@ -304,7 +305,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -312,7 +313,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /* baseAmt */ tc.initialPositionSize, /* quoteLimit */ sdk.ZeroDec(), @@ -327,8 +328,8 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("mock bank keeper") mocks.mockBankKeeper.EXPECT(). - GetBalance(ctx, vaultAddr, common.DenomNUSD). - Return(sdk.NewInt64Coin(common.DenomNUSD, 1_000)) + GetBalance(ctx, vaultAddr, denoms.DenomNUSD). + Return(sdk.NewInt64Coin(denoms.DenomNUSD, 1_000)) mocks.mockBankKeeper.EXPECT(). SendCoinsFromModuleToAccount( ctx, types.VaultModuleAccount, liquidatorAddr, @@ -346,26 +347,26 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee.String(), feeToFund.String()) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr)) require.ErrorIs(t, err, collections.ErrNotFound) assert.Empty(t, newPosition) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.newPositionNotional, ExchangedPositionSize: tc.initialPositionSize.Neg(), LiquidatorAddress: liquidatorAddr.String(), FeeToLiquidator: tc.expectedLiquidatorFee, FeeToEcosystemFund: tc.expectedPerpEFFee, - BadDebt: sdk.NewCoin(common.DenomNUSD, sdk.ZeroInt()), - Margin: sdk.NewCoin(common.DenomNUSD, sdk.ZeroInt()), + BadDebt: sdk.NewCoin(denoms.DenomNUSD, sdk.ZeroInt()), + Margin: sdk.NewCoin(denoms.DenomNUSD, sdk.ZeroInt()), PositionNotional: sdk.ZeroDec(), // always zero PositionSize: sdk.ZeroDec(), // always zero UnrealizedPnl: sdk.ZeroDec(), // always zero @@ -402,8 +403,8 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { newPositionNotional: sdk.NewDec(900), // at 0% margin ratio - expectedLiquidatorFee: sdk.NewInt64Coin(common.DenomNUSD, 11), // 900 * 0.025 / 2 - expectedPerpEFFee: sdk.NewInt64Coin(common.DenomNUSD, 0), // no margin left for perp ef + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 11), // 900 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 0), // no margin left for perp ef expectedPositionBadDebt: sdk.ZeroDec(), expectedLiquidationBadDebt: sdk.MustNewDecFromStr("11.25"), @@ -417,8 +418,8 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { newPositionNotional: sdk.NewDec(899), - expectedLiquidatorFee: sdk.NewInt64Coin(common.DenomNUSD, 11), // 899 * 0.025 / 2 - expectedPerpEFFee: sdk.NewInt64Coin(common.DenomNUSD, 0), + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 11), // 899 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 0), expectedPositionBadDebt: sdk.NewDec(1), expectedLiquidationBadDebt: sdk.MustNewDecFromStr("11.2375"), @@ -436,7 +437,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -449,24 +450,24 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true).Times(2) + ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, 15*time.Minute, @@ -475,7 +476,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -483,7 +484,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /* baseAmt */ tc.initialPositionSize, /* quoteLimit */ sdk.ZeroDec(), @@ -498,8 +499,8 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("mock bank keeper") mocks.mockBankKeeper.EXPECT(). - GetBalance(ctx, vaultAddr, common.DenomNUSD). - Return(sdk.NewInt64Coin(common.DenomNUSD, 1_000)) + GetBalance(ctx, vaultAddr, denoms.DenomNUSD). + Return(sdk.NewInt64Coin(denoms.DenomNUSD, 1_000)) mocks.mockBankKeeper.EXPECT(). SendCoinsFromModuleToAccount( ctx, types.VaultModuleAccount, liquidatorAddr, @@ -511,7 +512,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { ctx, types.PerpEFModuleAccount, types.VaultModuleAccount, sdk.NewCoins( sdk.NewCoin( - common.DenomNUSD, + denoms.DenomNUSD, tc.expectedLiquidationBadDebt.Add(tc.expectedPositionBadDebt).RoundInt(), ), ), @@ -520,26 +521,26 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee.String(), feeToFund.String()) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr)) require.ErrorIs(t, err, collections.ErrNotFound) assert.Empty(t, newPosition) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.newPositionNotional, ExchangedPositionSize: tc.initialPositionSize.Neg(), LiquidatorAddress: liquidatorAddr.String(), FeeToLiquidator: tc.expectedLiquidatorFee, FeeToEcosystemFund: tc.expectedPerpEFFee, - BadDebt: sdk.NewCoin(common.DenomNUSD, tc.expectedLiquidationBadDebt.Add(tc.expectedPositionBadDebt).RoundInt()), - Margin: sdk.NewInt64Coin(common.DenomNUSD, 0), + BadDebt: sdk.NewCoin(denoms.DenomNUSD, tc.expectedLiquidationBadDebt.Add(tc.expectedPositionBadDebt).RoundInt()), + Margin: sdk.NewInt64Coin(denoms.DenomNUSD, 0), PositionNotional: sdk.ZeroDec(), // always zero PositionSize: sdk.ZeroDec(), // always zero UnrealizedPnl: sdk.ZeroDec(), // always zero @@ -587,7 +588,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { test: func() { perpKeeper, mocks, ctx := getKeeper(t) liquidator := testutilevents.AccAddress() - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(false) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(false) err := perpKeeper.distributeLiquidateRewards(ctx, types.LiquidateResp{ @@ -597,7 +598,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { Liquidator: liquidator.String(), PositionResp: &types.PositionResp{ Position: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), }, }, }, @@ -612,7 +613,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { perpKeeper, mocks, ctx := getKeeper(t) liquidator := testutilevents.AccAddress() - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true) mocks.mockAccountKeeper. EXPECT().GetModuleAddress(types.VaultModuleAccount). @@ -638,7 +639,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { Liquidator: liquidator.String(), PositionResp: &types.PositionResp{ Position: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), }}, }, ) @@ -928,16 +929,16 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { newParams.LiquidationFeeRatio = tc.liquidationFee perpKeeper.SetParams(ctx, newParams) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -945,20 +946,20 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), /* skipFluctuationLimitCheck */ true, ).Return( /*quoteAssetAmount=*/ tc.baseAssetPriceInQuote, nil) mocks.mockVpoolKeeper.EXPECT(). - GetMarkPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). + GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). Return(sdk.OneDec(), nil) t.Log("create and set the initial position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialMargin, OpenNotional: tc.initialOpenNotional, @@ -996,7 +997,7 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { t.Log("assert new position fields") newPosition := positionResp.Position assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), newPosition.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), newPosition.Pair) assert.True(t, newPosition.Size_.IsZero()) // always zero assert.True(t, newPosition.Margin.IsZero()) // always zero assert.True(t, newPosition.OpenNotional.IsZero()) // always zero @@ -1004,15 +1005,15 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: positionResp.ExchangedNotionalValue, ExchangedPositionSize: positionResp.ExchangedPositionSize, LiquidatorAddress: liquidatorAddr.String(), - FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), tc.expectedFundsToLiquidator), - FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), tc.expectedFundsToPerpEF), - BadDebt: sdk.NewCoin(common.DenomNUSD, tc.expectedLiquidationBadDebt), - Margin: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), newPosition.Margin.RoundInt()), + FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), tc.expectedFundsToLiquidator), + FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), tc.expectedFundsToPerpEF), + BadDebt: sdk.NewCoin(denoms.DenomNUSD, tc.expectedLiquidationBadDebt), + Margin: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), newPosition.Margin.RoundInt()), PositionNotional: positionResp.PositionNotional, PositionSize: newPosition.Size_, UnrealizedPnl: positionResp.UnrealizedPnlAfter, @@ -1219,16 +1220,16 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { newParams.PartialLiquidationRatio = tc.partialLiquidationRatio perpKeeper.SetParams(ctx, newParams) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Mul(tc.partialLiquidationRatio), ). @@ -1237,7 +1238,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -1247,7 +1248,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ tc.baseAssetPriceInQuote.Mul(tc.partialLiquidationRatio), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), @@ -1257,7 +1258,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ tc.baseAssetPriceInQuote.Mul(tc.partialLiquidationRatio), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), @@ -1266,13 +1267,13 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { } mocks.mockVpoolKeeper.EXPECT(). - GetMarkPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)). + GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). Return(sdk.OneDec(), nil) t.Log("create and set the initial position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: tc.initialPositionSize, Margin: tc.initialMargin, OpenNotional: tc.initialOpenNotional, @@ -1312,21 +1313,21 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { t.Log("assert new position fields") newPosition := positionResp.Position assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), newPosition.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), newPosition.Pair) assert.True(t, newPosition.LatestCumulativePremiumFraction.IsZero()) assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) assert.EqualValues(t, tc.expectedPositionMargin, newPosition.Margin) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: positionResp.ExchangedNotionalValue, ExchangedPositionSize: positionResp.ExchangedPositionSize, LiquidatorAddress: liquidatorAddr.String(), - FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), tc.expectedFundsToLiquidator), - FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), tc.expectedFundsToPerpEF), - BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), sdk.ZeroInt()), - Margin: sdk.NewCoin(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD).QuoteDenom(), newPosition.Margin.RoundInt()), + FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), tc.expectedFundsToLiquidator), + FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), tc.expectedFundsToPerpEF), + BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), sdk.ZeroInt()), + Margin: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), newPosition.Margin.RoundInt()), PositionNotional: positionResp.PositionNotional, PositionSize: newPosition.Size_, UnrealizedPnl: positionResp.UnrealizedPnlAfter, diff --git a/x/perp/keeper/margin_test.go b/x/perp/keeper/margin_test.go index c777267a8..6fca81dc4 100644 --- a/x/perp/keeper/margin_test.go +++ b/x/perp/keeper/margin_test.go @@ -6,6 +6,7 @@ import ( "github.com/NibiruChain/collections" + "github.com/NibiruChain/nibiru/x/common/denoms" testutilevents "github.com/NibiruChain/nibiru/x/testutil" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -32,11 +33,11 @@ func TestAddMarginSuccess(t *testing.T) { }{ { name: "add margin", - marginToAdd: sdk.NewInt64Coin(common.DenomNUSD, 100), + marginToAdd: sdk.NewInt64Coin(denoms.DenomNUSD, 100), latestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.001"), initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(1_000), Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(500), @@ -67,7 +68,7 @@ func TestAddMarginSuccess(t *testing.T) { vpoolKeeper := &nibiruApp.VpoolKeeper assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens vpooltypes.VpoolConfig{ @@ -78,11 +79,11 @@ func TestAddMarginSuccess(t *testing.T) { MaxLeverage: sdk.MustNewDecFromStr("15"), }, )) - require.True(t, vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD))) + require.True(t, vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD))) t.Log("set pair metadata") setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: tc.latestCumulativePremiumFraction, }, ) @@ -90,14 +91,14 @@ func TestAddMarginSuccess(t *testing.T) { t.Log("establish initial position") setPosition(nibiruApp.PerpKeeper, ctx, tc.initialPosition) - resp, err := nibiruApp.PerpKeeper.AddMargin(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), traderAddr, tc.marginToAdd) + resp, err := nibiruApp.PerpKeeper.AddMargin(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr, tc.marginToAdd) require.NoError(t, err) assert.EqualValues(t, tc.expectedFundingPayment, resp.FundingPayment) assert.EqualValues(t, tc.expectedMargin, resp.Position.Margin) assert.EqualValues(t, tc.initialPosition.OpenNotional, resp.Position.OpenNotional) assert.EqualValues(t, tc.initialPosition.Size_, resp.Position.Size_) assert.EqualValues(t, traderAddr.String(), resp.Position.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), resp.Position.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), resp.Position.Pair) assert.EqualValues(t, tc.latestCumulativePremiumFraction, resp.Position.LatestCumulativePremiumFraction) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }) @@ -119,7 +120,7 @@ func TestRemoveMargin(t *testing.T) { trader := testutilevents.AccAddress() pair := common.MustNewAssetPair("osmo:nusd") - _, _, _, err := nibiruApp.PerpKeeper.RemoveMargin(ctx, pair, trader, sdk.Coin{Denom: common.DenomNUSD, Amount: removeAmt}) + _, _, _, err := nibiruApp.PerpKeeper.RemoveMargin(ctx, pair, trader, sdk.Coin{Denom: denoms.DenomNUSD, Amount: removeAmt}) require.Error(t, err) require.ErrorContains(t, err, types.ErrPairNotFound.Error()) }, diff --git a/x/perp/keeper/margin_unit_test.go b/x/perp/keeper/margin_unit_test.go index 7961d948e..504711d39 100644 --- a/x/perp/keeper/margin_unit_test.go +++ b/x/perp/keeper/margin_unit_test.go @@ -7,16 +7,15 @@ import ( "time" "github.com/NibiruChain/collections" - - testutilevents "github.com/NibiruChain/nibiru/x/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/perp/types" + testutilevents "github.com/NibiruChain/nibiru/x/testutil" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -112,7 +111,7 @@ func TestGetMarginRatio(t *testing.T) { name: "margin without price changes", position: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -125,7 +124,7 @@ func TestGetMarginRatio(t *testing.T) { name: "margin with price changes", position: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -145,7 +144,7 @@ func TestGetMarginRatio(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.position.Size_.Abs(), ). @@ -154,7 +153,7 @@ func TestGetMarginRatio(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, tc.position.Size_.Abs(), 15*time.Minute, @@ -162,7 +161,7 @@ func TestGetMarginRatio(t *testing.T) { Return(tc.newPrice, nil) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.OneDec(), }) @@ -636,7 +635,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -645,7 +644,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -659,7 +658,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -668,7 +667,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -682,7 +681,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -691,7 +690,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -706,7 +705,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -715,7 +714,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -730,7 +729,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -739,7 +738,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ). Return(sdk.NewDec(2), nil) }, @@ -751,7 +750,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -760,7 +759,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ). Return(sdk.MustNewDecFromStr("0.5"), nil) }, @@ -772,7 +771,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -781,7 +780,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), ). @@ -795,7 +794,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; negative pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -804,7 +803,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), ). @@ -818,7 +817,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -827,7 +826,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), 15*time.Minute, @@ -842,7 +841,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; negative pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -851,7 +850,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), 15*time.Minute, @@ -866,7 +865,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -875,7 +874,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ). Return(sdk.MustNewDecFromStr("0.5"), nil) }, @@ -887,7 +886,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -896,7 +895,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ). Return(sdk.NewDec(2), nil) }, @@ -943,7 +942,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "max pnl, pick spot price", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -953,7 +952,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -962,7 +961,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -977,7 +976,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "max pnl, pick twap", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -987,7 +986,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -996,7 +995,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -1011,7 +1010,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "min pnl, pick spot price", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -1021,7 +1020,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -1030,7 +1029,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -1045,7 +1044,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "min pnl, pick twap", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -1055,7 +1054,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -1064,7 +1063,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, diff --git a/x/perp/keeper/msg_server_test.go b/x/perp/keeper/msg_server_test.go index daa6d8e17..c3b780c8f 100644 --- a/x/perp/keeper/msg_server_test.go +++ b/x/perp/keeper/msg_server_test.go @@ -15,6 +15,7 @@ import ( nibisimapp "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/perp/keeper" "github.com/NibiruChain/nibiru/x/perp/types" "github.com/NibiruChain/nibiru/x/testutil" @@ -33,37 +34,37 @@ func TestMsgServerAddMargin(t *testing.T) { }{ { name: "trader not enough funds", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 999)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 999)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - margin: sdk.NewInt64Coin(common.DenomNUSD, 1000), + margin: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "no initial position", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1000)), initialPosition: nil, - margin: sdk.NewInt64Coin(common.DenomNUSD, 1000), + margin: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), expectedErr: collections.ErrNotFound, }, { name: "success", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1000)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - margin: sdk.NewInt64Coin(common.DenomNUSD, 1000), + margin: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), expectedErr: nil, }, } @@ -78,7 +79,7 @@ func TestMsgServerAddMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -90,7 +91,7 @@ func TestMsgServerAddMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -105,7 +106,7 @@ func TestMsgServerAddMargin(t *testing.T) { resp, err := msgServer.AddMargin(sdk.WrapSDKContext(ctx), &types.MsgAddMargin{ Sender: traderAddr.String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Margin: tc.margin, }) @@ -140,51 +141,51 @@ func TestMsgServerRemoveMargin(t *testing.T) { }{ { name: "position not enough margin", - vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1000)), + vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1000)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - marginToRemove: sdk.NewInt64Coin(common.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), expectedErr: types.ErrFailedRemoveMarginCanCauseBadDebt, }, { name: "no initial position", - vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 0)), + vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 0)), initialPosition: nil, - marginToRemove: sdk.NewInt64Coin(common.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), expectedErr: collections.ErrNotFound, }, { name: "vault insufficient funds", - vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 999)), + vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 999)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - marginToRemove: sdk.NewInt64Coin(common.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "success", - vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1000)), + vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1000)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - marginToRemove: sdk.NewInt64Coin(common.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), expectedErr: nil, }, } @@ -199,7 +200,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -211,7 +212,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -228,7 +229,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { resp, err := msgServer.RemoveMargin(sdk.WrapSDKContext(ctx), &types.MsgRemoveMargin{ Sender: traderAddr.String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Margin: tc.marginToRemove, }) @@ -262,15 +263,15 @@ func TestMsgServerOpenPosition(t *testing.T) { }{ { name: "trader not enough funds", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 999)), - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 999)), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sender: testutil.AccAddress().String(), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "success", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sender: testutil.AccAddress().String(), expectedErr: nil, }, @@ -286,7 +287,7 @@ func TestMsgServerOpenPosition(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + /* pair */ common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -298,7 +299,7 @@ func TestMsgServerOpenPosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -357,7 +358,7 @@ func TestMsgServerClosePosition(t *testing.T) { }{ { name: "success", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr: testutil.AccAddress(), expectedErr: nil, }, @@ -373,7 +374,7 @@ func TestMsgServerClosePosition(t *testing.T) { assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -385,7 +386,7 @@ func TestMsgServerClosePosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -434,7 +435,7 @@ func TestMsgServerLiquidate(t *testing.T) { }{ { name: "success", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), liquidator: testutil.AccAddress().String(), trader: testutil.AccAddress().String(), expectedErr: nil, @@ -452,7 +453,7 @@ func TestMsgServerLiquidate(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + /* pair */ common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -464,7 +465,7 @@ func TestMsgServerLiquidate(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(time.Now().Add(time.Minute)) @@ -472,7 +473,7 @@ func TestMsgServerLiquidate(t *testing.T) { traderAddr, err := sdk.AccAddressFromBech32(tc.trader) if err == nil { t.Log("set oracle price") - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.OneDec()) t.Log("create position") setPosition(app.PerpKeeper, ctx, types.Position{ @@ -515,7 +516,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ctx = ctx.WithBlockTime(time.Now()) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) - pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) liquidator := testutil.AccAddress() atRiskTrader1 := testutil.AccAddress() @@ -543,7 +544,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(time.Now().Add(time.Minute)) t.Log("set oracle price") - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.OneDec()) t.Log("create positions") atRiskPosition1 := types.Position{ @@ -641,14 +642,14 @@ func TestMsgServerDonateToEcosystemFund(t *testing.T) { name: "not enough funds", sender: testutil.AccAddress(), initialFunds: sdk.NewCoins(), - donation: sdk.NewInt64Coin(common.DenomNUSD, 100), + donation: sdk.NewInt64Coin(denoms.DenomNUSD, 100), expectedErr: fmt.Errorf("insufficient funds"), }, { name: "success", sender: testutil.AccAddress(), - initialFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1e6)), - donation: sdk.NewInt64Coin(common.DenomNUSD, 100), + initialFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1e6)), + donation: sdk.NewInt64Coin(denoms.DenomNUSD, 100), expectedErr: nil, }, } @@ -676,7 +677,7 @@ func TestMsgServerDonateToEcosystemFund(t *testing.T) { app.BankKeeper.GetBalance( ctx, app.AccountKeeper.GetModuleAddress(types.PerpEFModuleAccount), - common.DenomNUSD, + denoms.DenomNUSD, ), ) } diff --git a/x/perp/simulation/genesis.go b/x/perp/simulation/genesis.go index 47f858527..f24d6a630 100644 --- a/x/perp/simulation/genesis.go +++ b/x/perp/simulation/genesis.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/perp/types" ) @@ -17,7 +18,7 @@ func RandomizedGenState(simState *module.SimulationState) { Params: types.DefaultParams(), PairMetadata: []types.PairMetadata{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, }, diff --git a/x/perp/simulation/operations.go b/x/perp/simulation/operations.go index 8afdaf112..c30a1de13 100644 --- a/x/perp/simulation/operations.go +++ b/x/perp/simulation/operations.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/perp/keeper" "github.com/NibiruChain/nibiru/x/perp/types" pooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -55,7 +56,7 @@ func SimulateMsgOpenPosition(ak types.AccountKeeper, bk types.BankKeeper, k keep pool := pools[rand.Intn(len(pools))] maxQuote := getMaxQuoteForPool(pool) - quoteAmt, _ := simtypes.RandPositiveInt(r, sdk.MinInt(sdk.Int(maxQuote), spendableCoins.AmountOf(common.DenomNUSD))) + quoteAmt, _ := simtypes.RandPositiveInt(r, sdk.MinInt(sdk.Int(maxQuote), spendableCoins.AmountOf(denoms.DenomNUSD))) leverage := simtypes.RandomDecAmount(r, pool.Config.MaxLeverage.Sub(sdk.OneDec())).Add(sdk.OneDec()) // between [1, MaxLeverage] openNotional := leverage.MulInt(quoteAmt) @@ -71,11 +72,11 @@ func SimulateMsgOpenPosition(ak types.AccountKeeper, bk types.BankKeeper, k keep } feesAmt := openNotional.Mul(sdk.MustNewDecFromStr("0.002")).Ceil().TruncateInt() - spentCoins := sdk.NewCoins(sdk.NewCoin(common.DenomNUSD, quoteAmt.Add(feesAmt))) + spentCoins := sdk.NewCoins(sdk.NewCoin(denoms.DenomNUSD, quoteAmt.Add(feesAmt))) msg := &types.MsgOpenPosition{ Sender: simAccount.Address.String(), - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Side: side, QuoteAssetAmount: quoteAmt, Leverage: leverage, @@ -170,14 +171,14 @@ func SimulateMsgClosePosition(ak types.AccountKeeper, bk types.BankKeeper, k kee ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) msg := &types.MsgClosePosition{ Sender: trader, Pair: pair, } - _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), simAccount.Address)) + _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } @@ -208,22 +209,22 @@ func SimulateMsgAddMargin(ak types.AccountKeeper, bk types.BankKeeper, k keeper. ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) msg := &types.MsgAddMargin{} - _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), simAccount.Address)) + _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } spendableCoins := bk.SpendableCoins(ctx, simAccount.Address) - if spendableCoins.AmountOf(common.DenomNUSD).IsZero() { + if spendableCoins.AmountOf(denoms.DenomNUSD).IsZero() { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no nusd left"), nil, nil } - quoteAmt, _ := simtypes.RandPositiveInt(r, spendableCoins.AmountOf(common.DenomNUSD)) + quoteAmt, _ := simtypes.RandPositiveInt(r, spendableCoins.AmountOf(denoms.DenomNUSD)) - spentCoin := sdk.NewCoin(common.DenomNUSD, quoteAmt) + spentCoin := sdk.NewCoin(denoms.DenomNUSD, quoteAmt) msg = &types.MsgAddMargin{ Sender: trader, @@ -257,11 +258,11 @@ func SimulateMsgRemoveMargin(ak types.AccountKeeper, bk types.BankKeeper, k keep ) (opMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) msg := &types.MsgRemoveMargin{} - position, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), simAccount.Address)) + position, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } @@ -280,7 +281,7 @@ func SimulateMsgRemoveMargin(ak types.AccountKeeper, bk types.BankKeeper, k keep marginToRemove, _ := simtypes.RandPositiveInt(r, maxMarginToRemove.TruncateInt()) - expectedCoin := sdk.NewCoin(common.DenomNUSD, marginToRemove) + expectedCoin := sdk.NewCoin(denoms.DenomNUSD, marginToRemove) msg = &types.MsgRemoveMargin{ Sender: trader, @@ -315,7 +316,7 @@ func SimulateMsgRemoveMargin(ak types.AccountKeeper, bk types.BankKeeper, k keep func fundAccountWithTokens(ctx sdk.Context, receiver sdk.AccAddress, bk types.BankKeeper) (err error) { newCoins := sdk.NewCoins( - sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1e6)), + sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1e6)), ) if err := bk.MintCoins(ctx, types.ModuleName, newCoins); err != nil { diff --git a/x/perp/types/msgs_test.go b/x/perp/types/msgs_test.go index 67bec561a..312926c83 100644 --- a/x/perp/types/msgs_test.go +++ b/x/perp/types/msgs_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -335,7 +336,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Trader: testutil.AccAddress().String(), }, }}, @@ -346,7 +347,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Trader: testutil.AccAddress().String(), }, { @@ -361,11 +362,11 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Trader: testutil.AccAddress().String(), }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), Trader: "invalid", }, }}, diff --git a/x/stablecoin/abci.go b/x/stablecoin/abci.go index dbae9786f..0006d9515 100644 --- a/x/stablecoin/abci.go +++ b/x/stablecoin/abci.go @@ -4,6 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/stablecoin/keeper" ) @@ -19,7 +20,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { k.SetParams(ctx, params) } - _, err := k.OracleKeeper.GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) + _, err := k.OracleKeeper.GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) if err != nil { params := k.GetParams(ctx) diff --git a/x/stablecoin/abci_test.go b/x/stablecoin/abci_test.go index 475895156..6b0f608c3 100644 --- a/x/stablecoin/abci_test.go +++ b/x/stablecoin/abci_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/epochs" otypes "github.com/NibiruChain/nibiru/x/oracle/types" ) @@ -38,7 +39,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second * 60 * 16)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -52,7 +53,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second * 60 * 16)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -82,11 +83,11 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*15)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*30)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -100,11 +101,11 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*14)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*16)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -141,7 +142,7 @@ func TestEpochInfoChangesCollateralValidity(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) pairs := common.AssetPairs{ - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), } params := otypes.DefaultParams() params.TwapLookbackWindow = 1 * time.Hour diff --git a/x/stablecoin/client/cli/cli_test.go b/x/stablecoin/client/cli/cli_test.go index e124089bc..6a60295b2 100644 --- a/x/stablecoin/client/cli/cli_test.go +++ b/x/stablecoin/client/cli/cli_test.go @@ -17,6 +17,7 @@ import ( "github.com/NibiruChain/nibiru/app" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" "github.com/NibiruChain/nibiru/x/stablecoin/client/cli" stabletypes "github.com/NibiruChain/nibiru/x/stablecoin/types" @@ -49,13 +50,13 @@ func (s *IntegrationTestSuite) SetupSuite() { // x/stablecoin genesis state stableGen := stabletypes.DefaultGenesis() stableGen.Params.IsCollateralRatioValid = true - stableGen.ModuleAccountBalance = sdk.NewCoin(common.DenomUSDC, sdk.NewInt(10000*common.Precision)) + stableGen.ModuleAccountBalance = sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(10000*common.Precision)) genesisState[stabletypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(stableGen) oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: sdk.NewDec(10)}, - {Pair: common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), ExchangeRate: sdk.NewDec(1)}, + {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(10)}, + {Pair: common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(1)}, } oracleGenesis.Params.VotePeriod = 1_000 @@ -80,8 +81,8 @@ func (s IntegrationTestSuite) TestMintStableCmd() { s.NoError(testutilcli.FillWalletFromValidator( minter, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100*common.Precision), - sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(denoms.DenomNIBI, 100*common.Precision), + sdk.NewInt64Coin(denoms.DenomUSDC, 100*common.Precision), ), val, s.cfg.BondDenom, @@ -90,7 +91,7 @@ func (s IntegrationTestSuite) TestMintStableCmd() { commonArgs := []string{ fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(common.DenomNIBI, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10))).String()), } testCases := []struct { @@ -142,7 +143,7 @@ func (s IntegrationTestSuite) TestMintStableCmd() { s.NoError(err) s.Require().Equal( - balRes.Balances.AmountOf(common.DenomNUSD), tc.expectedStable) + balRes.Balances.AmountOf(denoms.DenomNUSD), tc.expectedStable) } }) } @@ -155,7 +156,7 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { burner, sdk.NewCoins( sdk.NewInt64Coin(s.cfg.BondDenom, 20_000), - sdk.NewInt64Coin(common.DenomNUSD, 50*common.Precision), + sdk.NewInt64Coin(denoms.DenomNUSD, 50*common.Precision), ), val, s.cfg.BondDenom, @@ -163,7 +164,7 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { s.NoError(s.network.WaitForNextBlock()) - defaultBondCoinsString := sdk.NewCoins(sdk.NewCoin(common.DenomNIBI, sdk.NewInt(10))).String() + defaultBondCoinsString := sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10))).String() commonArgs := []string{ fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), @@ -191,8 +192,8 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { expectedStable: sdk.ZeroInt(), expectedColl: sdk.NewInt(50*common.Precision - 100_000), // Collateral minus 0,02% fees expectedGov: sdk.NewInt(19_990), - expectedTreasury: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 50_000)), - expectedEf: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 50_000)), + expectedTreasury: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 50_000)), + expectedEf: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 50_000)), expectErr: false, respType: &sdk.TxResponse{}, expectedCode: 0, @@ -241,11 +242,11 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { s.NoError(err) s.Require().Equal( - tc.expectedColl, balRes.Balances.AmountOf(common.DenomUSDC)) + tc.expectedColl, balRes.Balances.AmountOf(denoms.DenomUSDC)) s.Require().Equal( - tc.expectedGov, balRes.Balances.AmountOf(common.DenomNIBI)) + tc.expectedGov, balRes.Balances.AmountOf(denoms.DenomNIBI)) s.Require().Equal( - tc.expectedStable, balRes.Balances.AmountOf(common.DenomNUSD)) + tc.expectedStable, balRes.Balances.AmountOf(denoms.DenomNUSD)) // Query treasury pool balance resp, err = banktestutil.QueryBalancesExec( diff --git a/x/stablecoin/genesis_test.go b/x/stablecoin/genesis_test.go index e2d23efdd..a911e7be7 100644 --- a/x/stablecoin/genesis_test.go +++ b/x/stablecoin/genesis_test.go @@ -3,6 +3,7 @@ package stablecoin_test import ( "testing" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" "github.com/NibiruChain/nibiru/simapp" @@ -10,7 +11,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/stablecoin" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -18,7 +18,7 @@ import ( func TestGenesis(t *testing.T) { genesisState := types.GenesisState{ Params: types.DefaultParams(), - ModuleAccountBalance: sdk.NewCoin(common.DenomUSDC, sdk.ZeroInt()), + ModuleAccountBalance: sdk.NewCoin(denoms.DenomUSDC, sdk.ZeroInt()), } nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) diff --git a/x/stablecoin/keeper/collateral_ratio.go b/x/stablecoin/keeper/collateral_ratio.go index 8e6d416b4..ca5a1435c 100644 --- a/x/stablecoin/keeper/collateral_ratio.go +++ b/x/stablecoin/keeper/collateral_ratio.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -86,7 +87,7 @@ func (k *Keeper) EvaluateCollRatio(ctx sdk.Context) (err error) { upperBound := params.GetPriceUpperBoundAsDec() stablePrice, err := k.OracleKeeper.GetExchangeRateTwap( - ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) if err != nil { return err } @@ -113,14 +114,14 @@ func (k *Keeper) StableRequiredForTargetCollRatio( targetCollRatio := k.GetCollRatio(ctx) moduleAddr := k.AccountKeeper.GetModuleAddress(types.ModuleName) moduleCoins := k.BankKeeper.SpendableCoins(ctx, moduleAddr) - collDenoms := []string{common.DenomUSDC} + collDenoms := []string{denoms.DenomUSDC} currentTotalCollUSD := sdk.ZeroDec() for _, collDenom := range collDenoms { amtColl := moduleCoins.AmountOf(collDenom) priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) if err != nil { return sdk.ZeroDec(), err } @@ -138,7 +139,7 @@ func (k *Keeper) RecollateralizeCollAmtForTargetCollRatio( ) (neededCollAmount sdk.Int, err error) { neededUSDForRecoll, _ := k.StableRequiredForTargetCollRatio(ctx) priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) if err != nil { return sdk.Int{}, err } @@ -222,7 +223,7 @@ func (k Keeper) Recollateralize( // Compute GOV rewarded to user priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) if err != nil { return response, err } @@ -231,7 +232,7 @@ func (k Keeper) Recollateralize( if err != nil { return response, err } - outGov := sdk.NewCoin(common.DenomNIBI, outGovAmount) + outGov := sdk.NewCoin(denoms.DenomNIBI, outGovAmount) // Mint and send GOV reward from the module to the caller err = k.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(outGov)) @@ -293,7 +294,7 @@ func (k *Keeper) GovAmtFromRecollateralize( bonusRate := params.GetBonusRateRecollAsDec() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) if err != nil { return sdk.Int{}, err } @@ -336,7 +337,7 @@ func (k *Keeper) BuybackGovAmtForTargetCollRatio( neededUSDForRecoll, _ := k.StableRequiredForTargetCollRatio(ctx) neededUSDForBuyback := neededUSDForRecoll.Neg() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) if err != nil { return sdk.Int{}, err } @@ -413,7 +414,7 @@ func (k Keeper) Buyback( // Compute USD (stable) value of the GOV sent by the caller: 'inUSD' priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) if err != nil { return response, err } @@ -424,7 +425,7 @@ func (k Keeper) Buyback( if err != nil { return response, err } - outColl := sdk.NewCoin(common.DenomUSDC, outCollAmount) + outColl := sdk.NewCoin(denoms.DenomUSDC, outCollAmount) // Send COLL from the module to the caller err = k.BankKeeper.SendCoinsFromModuleToAccount( @@ -473,7 +474,7 @@ func (k *Keeper) CollAmtFromBuyback( ctx sdk.Context, valUSD sdk.Dec, ) (collAmt sdk.Int, err error) { priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) if err != nil { return sdk.Int{}, err } diff --git a/x/stablecoin/keeper/collateral_ratio_test.go b/x/stablecoin/keeper/collateral_ratio_test.go index f415eff84..ce99ce643 100644 --- a/x/stablecoin/keeper/collateral_ratio_test.go +++ b/x/stablecoin/keeper/collateral_ratio_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" simapp2 "github.com/NibiruChain/nibiru/simapp" @@ -81,7 +82,7 @@ func TestSetCollRatioUpdate(t *testing.T) { stablecoinKeeper := &nibiruApp.StablecoinKeeper oracleKeeper := &nibiruApp.OracleKeeper - oracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), tc.price) + oracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), tc.price) err := stablecoinKeeper.SetCollRatio(ctx, tc.inCollRatio) require.NoError(t, err) err = stablecoinKeeper.EvaluateCollRatio(ctx) @@ -178,7 +179,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(500), priceCollStable: sdk.OneDec(), // startCollUSD = 500 * 1 -> 500 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 @@ -189,7 +190,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(600), priceCollStable: sdk.OneDec(), // startCollUSD = 600 * 1 = 600 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.5"), // 0.5 * 1000 = 500 @@ -215,14 +216,14 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, tc.protocolColl), - sdk.NewCoin(common.DenomNUSD, tc.stableSupply), + sdk.NewCoin(denoms.DenomUSDC, tc.protocolColl), + sdk.NewCoin(denoms.DenomNUSD, tc.stableSupply), ), )) // Post prices to each specified market with the oracle. prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.priceCollStable, + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -289,13 +290,13 @@ func TestRecollateralizeCollAmtForTargetCollRatio(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, tc.protocolColl), - sdk.NewCoin(common.DenomNUSD, tc.stableSupply), + sdk.NewCoin(denoms.DenomUSDC, tc.protocolColl), + sdk.NewCoin(denoms.DenomNUSD, tc.stableSupply), ), )) // Post the price - pair := common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD) nibiruApp.OracleKeeper.SetPrice(ctx, pair, tc.priceCollStable) neededCollAmount, err := stablecoinKeeper.RecollateralizeCollAmtForTargetCollRatio(ctx) @@ -328,13 +329,13 @@ func TestRecollateralizeCollAmtForTargetCollRatio(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, tc.protocolColl), - sdk.NewCoin(common.DenomNUSD, tc.stableSupply), + sdk.NewCoin(denoms.DenomUSDC, tc.protocolColl), + sdk.NewCoin(denoms.DenomNUSD, tc.stableSupply), ), )) // Post the price - // pair := common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD) + // pair := common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD) // nibiruApp.OracleKeeper.SetPrice(ctx, pair, tc.priceCollStable) neededCollAmount, err := stablecoinKeeper.RecollateralizeCollAmtForTargetCollRatio(ctx) @@ -377,7 +378,7 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 priceCollStable: sdk.OneDec(), postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)}, + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -388,7 +389,7 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 priceGovStable: sdk.OneDec(), postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)}, + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -398,8 +399,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(10_000), targetCollRatio: sdk.MustNewDecFromStr("0.7"), // 0.7 * 10_000 = 7_000 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(2), @@ -414,8 +415,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(100_000), targetCollRatio: sdk.MustNewDecFromStr("0.7"), // 0.7 * 100_000 = 70_000 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -430,8 +431,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(100_000), targetCollRatio: sdk.MustNewDecFromStr("0.5"), // 0.5 * 100_000 = 50_000 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -450,14 +451,14 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, tc.protocolColl), - sdk.NewCoin(common.DenomNUSD, tc.stableSupply), + sdk.NewCoin(denoms.DenomUSDC, tc.protocolColl), + sdk.NewCoin(denoms.DenomNUSD, tc.stableSupply), ), )) prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.priceCollStable, + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -465,8 +466,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { // Post prices to each specified market with the oracle. prices = map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.priceCollStable, - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.priceCollStable, + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, } for _, assetPair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, assetPair, prices[assetPair]) @@ -518,8 +519,8 @@ func TestRecollateralize(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -530,13 +531,13 @@ func TestRecollateralize(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.DenomUSDC, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(100_000), msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewCoin(common.DenomUSDC, sdk.NewInt(100_000)), + Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(100_000)), }, response: &types.MsgRecollateralizeResponse{ /* @@ -544,15 +545,15 @@ func TestRecollateralize(t *testing.T) { = 100_000 * (1.002) / priceGovStable = 100_200 / priceGovStable */ - Gov: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(100_200)), + Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_200)), }, expectedPass: true, }, { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -563,13 +564,13 @@ func TestRecollateralize(t *testing.T) { }, priceGovStable: sdk.NewDec(5), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.DenomUSDC, 1_000*common.Precision), ), expectedNeededUSD: sdk.MustNewDecFromStr("150000.5"), msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewCoin(common.DenomUSDC, sdk.NewInt(50_000)), + Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(50_000)), }, response: &types.MsgRecollateralizeResponse{ /* @@ -579,15 +580,15 @@ func TestRecollateralize(t *testing.T) { = 55109.9499 / priceGovStable = 11021.98998 -> 11_021 */ - Gov: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(11_021)), + Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(11_021)), }, expectedPass: true, }, { name: "protocol has sufficient collateral - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -599,13 +600,13 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("-49.9995"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 1*common.Precision), + sdk.NewInt64Coin(denoms.DenomUSDC, 1*common.Precision), ), // Since 'neededUSD' is msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewCoin(common.DenomUSDC, sdk.NewInt(100)), + Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(100)), }, expectedPass: false, err: fmt.Errorf("protocol has sufficient COLL"), @@ -613,8 +614,8 @@ func TestRecollateralize(t *testing.T) { { name: "caller is broke - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -626,13 +627,13 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("150"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 99), + sdk.NewInt64Coin(denoms.DenomUSDC, 99), ), // Since 'neededUSD' is msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewCoin(common.DenomUSDC, sdk.NewInt(200)), + Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(200)), }, expectedPass: false, err: fmt.Errorf("Not enough balance"), @@ -640,8 +641,8 @@ func TestRecollateralize(t *testing.T) { { name: "negative msg.Coll.Amount - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -653,21 +654,21 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("400"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 400), + sdk.NewInt64Coin(denoms.DenomUSDC, 400), ), msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.Coin{Denom: common.DenomUSDC, Amount: sdk.NewInt(-200)}, + Coll: sdk.Coin{Denom: denoms.DenomUSDC, Amount: sdk.NewInt(-200)}, }, expectedPass: false, err: fmt.Errorf( - "collateral input, -200%v, must be positive", common.DenomUSDC), + "collateral input, -200%v, must be positive", denoms.DenomUSDC), }, { name: "oracle prices are expired - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -679,11 +680,11 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("400"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 400), + sdk.NewInt64Coin(denoms.DenomUSDC, 400), ), msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewInt64Coin(common.DenomUSDC, 400), + Coll: sdk.NewInt64Coin(denoms.DenomUSDC, 400), }, expectedPass: false, @@ -701,8 +702,8 @@ func TestRecollateralize(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.scenario.collRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, tc.scenario.protocolColl), - sdk.NewCoin(common.DenomNUSD, tc.scenario.stableSupply), + sdk.NewCoin(denoms.DenomUSDC, tc.scenario.protocolColl), + sdk.NewCoin(denoms.DenomNUSD, tc.scenario.stableSupply), ), )) // Fund account @@ -716,8 +717,8 @@ func TestRecollateralize(t *testing.T) { } prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.scenario.priceCollStable, + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -725,8 +726,8 @@ func TestRecollateralize(t *testing.T) { // Post prices to each specified market with the oracle. prices = map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.scenario.priceCollStable, - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.scenario.priceCollStable, + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, } for _, assetPair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, assetPair, prices[assetPair]) @@ -772,7 +773,7 @@ func TestRecollateralize_Short(t *testing.T) { sender := testutil.AccAddress() msg := &types.MsgRecollateralize{ Creator: sender.String(), - Coll: sdk.NewInt64Coin(common.DenomUSDC, 100), + Coll: sdk.NewInt64Coin(denoms.DenomUSDC, 100), } _, err := nibiruApp.StablecoinKeeper.Recollateralize(goCtx, msg) require.ErrorContains(t, err, "collections: not found") @@ -849,8 +850,8 @@ func TestBuyback(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -861,32 +862,32 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision), ), expectedAccFundsAfter: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 900_000), // accFunds - inGov.Amount - sdk.NewInt64Coin(common.DenomUSDC, 100_000), // response.Coll + sdk.NewInt64Coin(denoms.DenomNIBI, 900_000), // accFunds - inGov.Amount + sdk.NewInt64Coin(denoms.DenomUSDC, 100_000), // response.Coll ), expectedNeededUSD: sdk.NewDec(-100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{ /* Coll.Amount = inUSD * / priceCollStable = 100_000 / priceCollStable */ - Coll: sdk.NewCoin(common.DenomUSDC, sdk.NewInt(100_000)), + Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(100_000)), }, expectedPass: true, }, { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(850_000), @@ -897,17 +898,17 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.NewDec(5), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision), ), expectedAccFundsAfter: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 953_000), // accFunds - inGov.Amount - sdk.NewInt64Coin(common.DenomUSDC, 213_636), // response.Coll + sdk.NewInt64Coin(denoms.DenomNIBI, 953_000), // accFunds - inGov.Amount + sdk.NewInt64Coin(denoms.DenomUSDC, 213_636), // response.Coll ), expectedNeededUSD: sdk.MustNewDecFromStr("-234999.15"), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(50_000)), + Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(50_000)), }, response: &types.MsgBuybackResponse{ /* @@ -919,15 +920,15 @@ func TestBuyback(t *testing.T) { = 47000 * 5 / 1.099999 = 213636.55785141626 -> 213_636 */ - Coll: sdk.NewCoin(common.DenomUSDC, sdk.NewInt(213_636)), + Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(213_636)), }, expectedPass: true, }, { name: "msg has more NIBI than the protocol needs, only needed sent", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -938,29 +939,29 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision), ), expectedAccFundsAfter: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 900_000), // accFunds - inGov.Amount - sdk.NewInt64Coin(common.DenomUSDC, 100_000), // response.Coll + sdk.NewInt64Coin(denoms.DenomNIBI, 900_000), // accFunds - inGov.Amount + sdk.NewInt64Coin(denoms.DenomUSDC, 100_000), // response.Coll ), expectedNeededUSD: sdk.NewDec(-100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(200_000)), + Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(200_000)), }, response: &types.MsgBuybackResponse{ // Coll.Amount = inUSD * / priceCollStable - Coll: sdk.NewCoin(common.DenomUSDC, sdk.NewInt(100_000)), + Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(100_000)), }, expectedPass: true, }, { name: "protocol under-collateralized, so buyback won't run", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -971,13 +972,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.DenomNIBI, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -985,8 +986,8 @@ func TestBuyback(t *testing.T) { { name: "caller has insufficient funds", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -997,13 +998,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1), + sdk.NewInt64Coin(denoms.DenomNIBI, 1), ), expectedNeededUSD: sdk.NewDec(-100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -1011,7 +1012,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing collateral price post", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1022,13 +1023,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.DenomNIBI, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(-100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -1036,7 +1037,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing NIBI price post", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1047,13 +1048,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.DenomNIBI, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(-100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -1072,8 +1073,8 @@ func TestBuyback(t *testing.T) { // Fund module account based on scenario require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, tc.scenario.protocolColl), - sdk.NewCoin(common.DenomNUSD, tc.scenario.stableSupply), + sdk.NewCoin(denoms.DenomUSDC, tc.scenario.protocolColl), + sdk.NewCoin(denoms.DenomNUSD, tc.scenario.stableSupply), ), )) @@ -1089,8 +1090,8 @@ func TestBuyback(t *testing.T) { // Set up markets for the oracle keeper. prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.scenario.priceCollStable, + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -1131,8 +1132,8 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, correct amount out", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1162,7 +1163,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, only coll price posted", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1185,14 +1186,14 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.scenario.collRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, tc.scenario.protocolColl), - sdk.NewCoin(common.DenomNUSD, tc.scenario.stableSupply), + sdk.NewCoin(denoms.DenomUSDC, tc.scenario.protocolColl), + sdk.NewCoin(denoms.DenomNUSD, tc.scenario.stableSupply), ), )) prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): tc.priceGovStable, - common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD): tc.scenario.priceCollStable, + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) diff --git a/x/stablecoin/keeper/keeper.go b/x/stablecoin/keeper/keeper.go index 5222de886..391af97d5 100644 --- a/x/stablecoin/keeper/keeper.go +++ b/x/stablecoin/keeper/keeper.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -67,7 +67,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // GetModuleAccountBalance gets the airdrop coin balance of module account. func (k Keeper) GetModuleAccountBalance(ctx sdk.Context) sdk.Coin { moduleAccAddr := k.AccountKeeper.GetModuleAddress(types.ModuleName) - return k.BankKeeper.GetBalance(ctx, moduleAccAddr, common.DenomNIBI) + return k.BankKeeper.GetBalance(ctx, moduleAccAddr, denoms.DenomNIBI) } // GetParams get all parameters as types.Params diff --git a/x/stablecoin/keeper/mint_burn_stable.go b/x/stablecoin/keeper/mint_burn_stable.go index ecba22b26..590a4ca88 100644 --- a/x/stablecoin/keeper/mint_burn_stable.go +++ b/x/stablecoin/keeper/mint_burn_stable.go @@ -12,6 +12,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -93,16 +94,16 @@ func (k Keeper) calcNeededGovAndFees( ctx sdk.Context, stable sdk.Coin, govRatio sdk.Dec, feeRatio sdk.Dec, ) (sdk.Coin, sdk.Coin, error) { priceGov, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } neededGovUSD := stable.Amount.ToDec().Mul(govRatio) neededGovAmt := neededGovUSD.Quo(priceGov).TruncateInt() - neededGov := sdk.NewCoin(common.DenomNIBI, neededGovAmt) + neededGov := sdk.NewCoin(denoms.DenomNIBI, neededGovAmt) govFeeAmt := neededGovAmt.ToDec().Mul(feeRatio).RoundInt() - govFee := sdk.NewCoin(common.DenomNIBI, govFeeAmt) + govFee := sdk.NewCoin(denoms.DenomNIBI, govFeeAmt) return neededGov, govFee, nil } @@ -115,16 +116,16 @@ func (k Keeper) calcNeededCollateralAndFees( feeRatio sdk.Dec, ) (sdk.Coin, sdk.Coin, error) { priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } neededCollUSD := stable.Amount.ToDec().Mul(collRatio) neededCollAmt := neededCollUSD.Quo(priceColl).TruncateInt() - neededColl := sdk.NewCoin(common.DenomUSDC, neededCollAmt) + neededColl := sdk.NewCoin(denoms.DenomUSDC, neededCollAmt) collFeeAmt := neededCollAmt.ToDec().Mul(feeRatio).RoundInt() - collFee := sdk.NewCoin(common.DenomUSDC, collFeeAmt) + collFee := sdk.NewCoin(denoms.DenomUSDC, collFeeAmt) return neededColl, collFee, nil } @@ -252,7 +253,7 @@ func (k Keeper) splitAndSendFeesToEfAndTreasury( amountEf := c.Amount.ToDec().Mul(efFeeRatio).TruncateInt() amountTreasury := c.Amount.Sub(amountEf) - if c.Denom == common.DenomNIBI { + if c.Denom == denoms.DenomNIBI { stableCoins := sdk.NewCoins(sdk.NewCoin(c.Denom, amountEf)) err := k.BankKeeper.SendCoinsFromAccountToModule( ctx, account, types.StableEFModuleAccount, stableCoins) diff --git a/x/stablecoin/keeper/mint_burn_stable_test.go b/x/stablecoin/keeper/mint_burn_stable_test.go index 45eb1e17c..cc87ae087 100644 --- a/x/stablecoin/keeper/mint_burn_stable_test.go +++ b/x/stablecoin/keeper/mint_burn_stable_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" simapp2 "github.com/NibiruChain/nibiru/simapp" @@ -54,10 +55,10 @@ func TestMsgMint_ValidateBasic(t *testing.T) { } func TestMsgMintStableResponse_HappyPath(t *testing.T) { - accFundsGovAmount := sdk.NewCoin(common.DenomNIBI, sdk.NewInt(10_000)) - accFundsCollAmount := sdk.NewCoin(common.DenomUSDC, sdk.NewInt(900_000)) - neededGovFees := sdk.NewCoin(common.DenomNIBI, sdk.NewInt(20)) // 0.002 fee - neededCollFees := sdk.NewCoin(common.DenomUSDC, sdk.NewInt(1_800)) // 0.002 fee + accFundsGovAmount := sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10_000)) + accFundsCollAmount := sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(900_000)) + neededGovFees := sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(20)) // 0.002 fee + neededCollFees := sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(1_800)) // 0.002 fee accFundsAmt := sdk.NewCoins( accFundsGovAmount.Add(neededGovFees), @@ -81,7 +82,7 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { accFunds: accFundsAmt, msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1*common.Precision)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), @@ -93,18 +94,18 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { accFunds: accFundsAmt, msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1*common.Precision)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1*common.Precision)), UsedCoins: sdk.NewCoins(accFundsCollAmount, accFundsGovAmount), FeesPayed: sdk.NewCoins(neededCollFees, neededGovFees), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), - supplyNIBI: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(10)), + supplyNIBI: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10)), // 10_000 - 20 (neededAmt - fees) - 10 (0.5 of fees from EFund are burned) - supplyNUSD: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), + supplyNUSD: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1*common.Precision)), err: nil, isCollateralRatioValid: true, }, @@ -144,8 +145,8 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { ) // Post prices to each pair with the oracle. - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), tc.collPrice) // Fund account require.NoError(t, simapp.FundAccount(nibiruApp.BankKeeper, ctx, acc, tc.accFunds)) @@ -170,7 +171,7 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { ctx, nibiruApp.AccountKeeper.GetModuleAddress(types.StableEFModuleAccount), ) collFeesInEf := neededCollFees.Amount.ToDec().Mul(sdk.MustNewDecFromStr("0.5")).TruncateInt() - assert.Equal(t, sdk.NewCoins(sdk.NewCoin(common.DenomUSDC, collFeesInEf)), efModuleBalance) + assert.Equal(t, sdk.NewCoins(sdk.NewCoin(denoms.DenomUSDC, collFeesInEf)), efModuleBalance) // Check balances in Treasury treasuryModuleBalance := nibiruApp.BankKeeper. @@ -180,8 +181,8 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { assert.Equal( t, sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, collFeesInTreasury), - sdk.NewCoin(common.DenomNIBI, govFeesInTreasury), + sdk.NewCoin(denoms.DenomUSDC, collFeesInTreasury), + sdk.NewCoin(denoms.DenomNIBI, govFeesInTreasury), ), treasuryModuleBalance, ) @@ -202,70 +203,70 @@ func TestMsgMintStableResponse_NotEnoughFunds(t *testing.T) { { name: "User has no GOV", accFunds: sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, sdk.NewInt(9001)), - sdk.NewCoin(common.DenomNIBI, sdk.NewInt(0)), + sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(9001)), + sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(0)), ), msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(100)), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(100)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(0)), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(0)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), - err: types.NotEnoughBalance.Wrap(common.DenomNIBI), + err: types.NotEnoughBalance.Wrap(denoms.DenomNIBI), }, { name: "User has no COLL", accFunds: sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, sdk.NewInt(0)), - sdk.NewCoin(common.DenomNIBI, sdk.NewInt(9001)), + sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(0)), + sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(9001)), ), msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(100)), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(100)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(0)), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(0)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), - err: types.NotEnoughBalance.Wrap(common.DenomUSDC), + err: types.NotEnoughBalance.Wrap(denoms.DenomUSDC), }, { name: "Not enough GOV", accFunds: sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, sdk.NewInt(9001)), - sdk.NewCoin(common.DenomNIBI, sdk.NewInt(1)), + sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(9001)), + sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(1)), ), msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1000)), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1000)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(0)), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(0)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), err: types.NotEnoughBalance.Wrap( - sdk.NewCoin(common.DenomNIBI, sdk.NewInt(1)).String()), + sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(1)).String()), }, { name: "Not enough COLL", accFunds: sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, sdk.NewInt(1)), - sdk.NewCoin(common.DenomNIBI, sdk.NewInt(9001)), + sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(1)), + sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(9001)), ), msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(100)), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(100)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(0)), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(0)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), err: types.NotEnoughBalance.Wrap( - sdk.NewCoin(common.DenomUSDC, sdk.NewInt(1)).String()), + sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(1)).String()), }, } @@ -301,8 +302,8 @@ func TestMsgMintStableResponse_NotEnoughFunds(t *testing.T) { ) t.Log("Post prices to each pair with the oracle.") - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), tc.collPrice) // Fund account require.NoError(t, simapp.FundAccount(nibiruApp.BankKeeper, ctx, acc, tc.accFunds)) @@ -376,14 +377,14 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { }{ { name: "Not enough stable", - accFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10)), + accFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 10)), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(common.DenomNUSD, 9001), + Stable: sdk.NewInt64Coin(denoms.DenomNUSD, 9001), }, msgResponse: &types.MsgBurnStableResponse{ - Collateral: sdk.NewCoin(common.DenomNIBI, sdk.ZeroInt()), - Gov: sdk.NewCoin(common.DenomUSDC, sdk.ZeroInt()), + Collateral: sdk.NewCoin(denoms.DenomNIBI, sdk.ZeroInt()), + Gov: sdk.NewCoin(denoms.DenomUSDC, sdk.ZeroInt()), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), @@ -395,22 +396,22 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1000*common.Precision), + sdk.NewInt64Coin(denoms.DenomNUSD, 1000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(denoms.DenomUSDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.ZeroInt()), + Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.ZeroInt()), }, msgResponse: &types.MsgBurnStableResponse{ - Gov: sdk.NewCoin(common.DenomNIBI, sdk.ZeroInt()), - Collateral: sdk.NewCoin(common.DenomUSDC, sdk.ZeroInt()), + Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.ZeroInt()), + Collateral: sdk.NewCoin(denoms.DenomUSDC, sdk.ZeroInt()), FeesPayed: sdk.NewCoins(), }, expectedPass: true, - err: types.NoCoinFound.Wrap(common.DenomNUSD).Error(), + err: types.NoCoinFound.Wrap(denoms.DenomNUSD).Error(), }, } @@ -448,8 +449,8 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { nibiruApp.StablecoinKeeper.SetParams(ctx, defaultParams) t.Log("Post prices to each pair with the oracle.") - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), tc.collPrice) // Add collaterals to the module require.NoError(t, nibiruApp.BankKeeper.MintCoins(ctx, types.ModuleName, tc.moduleFunds)) @@ -494,17 +495,17 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.DenomNUSD, 1_000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(denoms.DenomUSDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(common.DenomNUSD, 10*common.Precision), + Stable: sdk.NewInt64Coin(denoms.DenomNUSD, 10*common.Precision), }, - ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000)), - treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000), sdk.NewInt64Coin(common.DenomNIBI, 100)), + ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 9000)), + treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 9000), sdk.NewInt64Coin(denoms.DenomNIBI, 100)), expectedPass: false, isCollateralRatioValid: false, err: types.NoValidCollateralRatio, @@ -514,27 +515,27 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.DenomNUSD, 1_000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(denoms.DenomUSDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(common.DenomNUSD, 10*common.Precision), + Stable: sdk.NewInt64Coin(denoms.DenomNUSD, 10*common.Precision), }, msgResponse: types.MsgBurnStableResponse{ - Gov: sdk.NewInt64Coin(common.DenomNIBI, 100_000-200), // amount - fees 0,02% - Collateral: sdk.NewInt64Coin(common.DenomUSDC, 9*common.Precision-18_000), // amount - fees 0,02% + Gov: sdk.NewInt64Coin(denoms.DenomNIBI, 100_000-200), // amount - fees 0,02% + Collateral: sdk.NewInt64Coin(denoms.DenomUSDC, 9*common.Precision-18_000), // amount - fees 0,02% FeesPayed: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 200), - sdk.NewInt64Coin(common.DenomUSDC, 18_000), + sdk.NewInt64Coin(denoms.DenomNIBI, 200), + sdk.NewInt64Coin(denoms.DenomUSDC, 18_000), ), }, - supplyNIBI: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(100_000-100)), // nibiru minus 0.5 of fees burned (the part that goes to EF) - supplyNUSD: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000*common.Precision-10*common.Precision)), - ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000)), - treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000), sdk.NewInt64Coin(common.DenomNIBI, 100)), + supplyNIBI: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000-100)), // nibiru minus 0.5 of fees burned (the part that goes to EF) + supplyNUSD: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1_000*common.Precision-10*common.Precision)), + ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 9000)), + treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 9000), sdk.NewInt64Coin(denoms.DenomNIBI, 100)), expectedPass: true, isCollateralRatioValid: true, }, @@ -569,8 +570,8 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { ), ) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), tc.collPrice) // Add collaterals to the module require.NoError(t, nibiruApp.BankKeeper.MintCoins(ctx, types.ModuleName, tc.moduleFunds)) diff --git a/x/stablecoin/keeper/supply.go b/x/stablecoin/keeper/supply.go index 706278058..b18d08a2a 100644 --- a/x/stablecoin/keeper/supply.go +++ b/x/stablecoin/keeper/supply.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" ) var LiquidityRatioBands = sdk.MustNewDecFromStr("0.001") @@ -13,13 +13,13 @@ var LiquidityRatioBands = sdk.MustNewDecFromStr("0.001") func (k Keeper) GetSupplyNUSD( ctx sdk.Context, ) sdk.Coin { - return k.BankKeeper.GetSupply(ctx, common.DenomNUSD) + return k.BankKeeper.GetSupply(ctx, denoms.DenomNUSD) } func (k Keeper) GetSupplyNIBI( ctx sdk.Context, ) sdk.Coin { - return k.BankKeeper.GetSupply(ctx, common.DenomNIBI) + return k.BankKeeper.GetSupply(ctx, denoms.DenomNIBI) } func (k Keeper) GetStableMarketCap(ctx sdk.Context) sdk.Int { @@ -27,12 +27,12 @@ func (k Keeper) GetStableMarketCap(ctx sdk.Context) sdk.Int { } func (k Keeper) GetGovMarketCap(ctx sdk.Context) (sdk.Int, error) { - pool, err := k.DexKeeper.FetchPoolFromPair(ctx, common.DenomNIBI, common.DenomNUSD) + pool, err := k.DexKeeper.FetchPoolFromPair(ctx, denoms.DenomNIBI, denoms.DenomNUSD) if err != nil { return sdk.Int{}, err } - price, err := pool.CalcSpotPrice(common.DenomNIBI, common.DenomNUSD) + price, err := pool.CalcSpotPrice(denoms.DenomNIBI, denoms.DenomNUSD) if err != nil { return sdk.Int{}, err } diff --git a/x/stablecoin/keeper/supply_test.go b/x/stablecoin/keeper/supply_test.go index 4a77bd87a..ef51cd76e 100644 --- a/x/stablecoin/keeper/supply_test.go +++ b/x/stablecoin/keeper/supply_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" "github.com/NibiruChain/nibiru/simapp" @@ -22,7 +23,7 @@ func TestKeeper_GetStableMarketCap(t *testing.T) { // We set some supply err := k.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), + sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision), )) require.NoError(t, err) @@ -44,11 +45,11 @@ func TestKeeper_GetGovMarketCap(t *testing.T) { } poolAssets := []dextypes.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNIBI, 2*common.Precision), + Token: sdk.NewInt64Coin(denoms.DenomNIBI, 2*common.Precision), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), + Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision), Weight: sdk.NewInt(100), }, } @@ -59,7 +60,7 @@ func TestKeeper_GetGovMarketCap(t *testing.T) { // We set some supply err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision), )) require.NoError(t, err) @@ -81,11 +82,11 @@ func TestKeeper_GetLiquidityRatio_AndBands(t *testing.T) { } poolAssets := []dextypes.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNIBI, 2*common.Precision), + Token: sdk.NewInt64Coin(denoms.DenomNIBI, 2*common.Precision), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), + Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision), Weight: sdk.NewInt(100), }, } @@ -96,12 +97,12 @@ func TestKeeper_GetLiquidityRatio_AndBands(t *testing.T) { // We set some supply err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision), )) require.NoError(t, err) err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), + sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision), )) require.NoError(t, err) diff --git a/x/stablecoin/simulation/msg.go b/x/stablecoin/simulation/msg.go index 37a8eda4a..db3f8953e 100644 --- a/x/stablecoin/simulation/msg.go +++ b/x/stablecoin/simulation/msg.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/stablecoin/keeper" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -23,7 +23,7 @@ func SimulateMsgMintStable( ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAcc, _ := simtypes.RandomAcc(r, accs) // How much stable should get minted? - simStable := sdk.NewCoin(common.DenomNUSD, sdk.NewInt(100)) + simStable := sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(100)) msg := &types.MsgMintStable{ Creator: simAcc.Address.String(), Stable: simStable, diff --git a/x/stablecoin/types/genesis.go b/x/stablecoin/types/genesis.go index ebed44b9d..8f933745a 100644 --- a/x/stablecoin/types/genesis.go +++ b/x/stablecoin/types/genesis.go @@ -3,7 +3,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" ) // DefaultIndex is the default capability global index @@ -13,7 +13,7 @@ const DefaultIndex uint64 = 1 func DefaultGenesis() *GenesisState { return &GenesisState{ Params: DefaultParams(), - ModuleAccountBalance: sdk.NewCoin(common.DenomUSDC, sdk.ZeroInt()), + ModuleAccountBalance: sdk.NewCoin(denoms.DenomUSDC, sdk.ZeroInt()), } } diff --git a/x/testutil/cli/network.go b/x/testutil/cli/network.go index 4ca70aa7c..b5bf5e94b 100644 --- a/x/testutil/cli/network.go +++ b/x/testutil/cli/network.go @@ -15,6 +15,7 @@ import ( "time" "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" @@ -44,7 +45,6 @@ import ( "google.golang.org/grpc" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/x/common" ) // package-wide network lock to only allow one test network at a time @@ -143,15 +143,15 @@ func BuildNetworkConfig(appGenesis simapp.GenesisState) Config { TimeoutCommit: time.Second / 2, ChainID: "chain-" + tmrand.NewRand().Str(6), NumValidators: 1, - BondDenom: common.DenomNIBI, - MinGasPrices: fmt.Sprintf("0.000006%s", common.DenomNIBI), + BondDenom: denoms.DenomNIBI, + MinGasPrices: fmt.Sprintf("0.000006%s", denoms.DenomNIBI), AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), StartingTokens: sdk.NewCoins( - sdk.NewCoin(common.DenomNUSD, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), - sdk.NewCoin(common.DenomNIBI, sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)), - sdk.NewCoin(common.DenomUSDC, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.DenomNUSD, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.DenomNIBI, sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.DenomUSDC, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), ), PruningStrategy: storetypes.PruningOptionNothing, CleanupDir: true, diff --git a/x/testutil/cli/tx.go b/x/testutil/cli/tx.go index c5a6b295c..964e5c10b 100644 --- a/x/testutil/cli/tx.go +++ b/x/testutil/cli/tx.go @@ -14,6 +14,7 @@ import ( "github.com/tendermint/tendermint/abci/types" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" ) type ExecTxOption func(*execTxOptions) @@ -67,7 +68,7 @@ func ExecTx(network *Network, cmd *cobra.Command, txSender sdk.AccAddress, args args = append(args, fmt.Sprintf("--%s=%s", flags.FlagFrom, txSender)) options := execTxOptions{ - fees: sdk.NewCoins(sdk.NewCoin(common.DenomNIBI, sdk.NewInt(10))), + fees: sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10))), gas: 2000000, skipConfirmation: true, broadcastMode: flags.BroadcastBlock, diff --git a/x/testutil/testapp/config.go b/x/testutil/testapp/config.go index 9a9e3baeb..e694f1236 100644 --- a/x/testutil/testapp/config.go +++ b/x/testutil/testapp/config.go @@ -13,7 +13,7 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil/cli" ) @@ -34,15 +34,15 @@ func BuildNetworkConfig(appGenesis GenesisState) cli.Config { TimeoutCommit: time.Second / 2, ChainID: "chain-" + tmrand.NewRand().Str(6), NumValidators: 1, - BondDenom: common.DenomNIBI, - MinGasPrices: fmt.Sprintf("0.000006%s", common.DenomNIBI), + BondDenom: denoms.DenomNIBI, + MinGasPrices: fmt.Sprintf("0.000006%s", denoms.DenomNIBI), AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), StartingTokens: sdk.NewCoins( - sdk.NewCoin(common.DenomNUSD, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), - sdk.NewCoin(common.DenomNIBI, sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)), - sdk.NewCoin(common.DenomUSDC, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.DenomNUSD, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.DenomNIBI, sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.DenomUSDC, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), ), PruningStrategy: storetypes.PruningOptionNothing, CleanupDir: true, diff --git a/x/testutil/testapp/testapp.go b/x/testutil/testapp/testapp.go index d25b57224..939249ddd 100644 --- a/x/testutil/testapp/testapp.go +++ b/x/testutil/testapp/testapp.go @@ -16,8 +16,7 @@ import ( tmdb "github.com/tendermint/tm-db" "github.com/NibiruChain/nibiru/app" - - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" ) // NewTestNibiruApp creates an application instance ('app.NibiruApp') with an in-memory @@ -120,7 +119,7 @@ func NewTestGenesisState(codec codec.Codec, inGenState GenesisState, var govGenState govtypes.GenesisState codec.MustUnmarshalJSON(testGenState[govtypes.ModuleName], &govGenState) govGenState.VotingParams.VotingPeriod = time.Second * 20 - govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1_000_000)) // min deposit of 1 NIBI + govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1_000_000)) // min deposit of 1 NIBI testGenState[govtypes.ModuleName] = codec.MustMarshalJSON(&govGenState) return testGenState diff --git a/x/vpool/abci_test.go b/x/vpool/abci_test.go index 6722920bc..c5358c65f 100644 --- a/x/vpool/abci_test.go +++ b/x/vpool/abci_test.go @@ -11,6 +11,7 @@ import ( "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" "github.com/NibiruChain/nibiru/x/vpool" "github.com/NibiruChain/nibiru/x/vpool/types" @@ -31,7 +32,7 @@ func TestSnapshotUpdates(t *testing.T) { require.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(1_000), sdk.NewDec(1_000), types.DefaultVpoolConfig(). @@ -39,7 +40,7 @@ func TestSnapshotUpdates(t *testing.T) { WithFluctuationLimitRatio(sdk.OneDec()), )) expectedSnapshot := types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(1_000), sdk.NewDec(1_000), ctx.BlockTime(), @@ -47,14 +48,14 @@ func TestSnapshotUpdates(t *testing.T) { t.Log("run one block of 5 seconds") runBlock(5 * time.Second) - snapshot, err := vpoolKeeper.ReserveSnapshots.Get(ctx, collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) + snapshot, err := vpoolKeeper.ReserveSnapshots.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) require.NoError(t, err) assert.EqualValues(t, expectedSnapshot, snapshot) t.Log("affect mark price") baseAmtAbs, err := vpoolKeeper.SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), types.Direction_ADD_TO_POOL, sdk.NewDec(250), // ← dyAmm sdk.ZeroDec(), @@ -64,7 +65,7 @@ func TestSnapshotUpdates(t *testing.T) { assert.EqualValues(t, sdk.NewDec(200), baseAmtAbs) require.NoError(t, err) expectedSnapshot = types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(800), // ← x + dxAmm sdk.NewDec(1_250), // ← y + dyAMM ctx.BlockTime(), @@ -75,7 +76,7 @@ func TestSnapshotUpdates(t *testing.T) { timeSkipDuration := 5 * time.Second runBlock(timeSkipDuration) // increments ctx.blockHeight and ctx.BlockTime snapshot, err = vpoolKeeper.ReserveSnapshots.Get(ctx, - collections.Join(common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) + collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) require.NoError(t, err) assert.EqualValues(t, expectedSnapshot, snapshot) diff --git a/x/vpool/client/cli/cli_test.go b/x/vpool/client/cli/cli_test.go index 09403a1d7..abf6161ff 100644 --- a/x/vpool/client/cli/cli_test.go +++ b/x/vpool/client/cli/cli_test.go @@ -16,6 +16,7 @@ import ( "github.com/NibiruChain/nibiru/app" "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" testutilcli "github.com/NibiruChain/nibiru/x/testutil/cli" "github.com/NibiruChain/nibiru/x/vpool/client/cli" @@ -34,8 +35,8 @@ func TestIntegrationTestSuite(t *testing.T) { } var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD): { - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD): { + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -46,8 +47,8 @@ var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ MaxLeverage: sdk.MustNewDecFromStr("15"), }, }, - common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD): { - Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): { + Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(500_000), QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -73,14 +74,14 @@ func (s *IntegrationTestSuite) SetupSuite() { genesisState := simapp.NewTestGenesisStateFromDefault() vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ - START_VPOOLS[common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)], - START_VPOOLS[common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)], + START_VPOOLS[common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)], + START_VPOOLS[common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)], } oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), ExchangeRate: sdk.NewDec(1_000)}, - {Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), ExchangeRate: sdk.NewDec(10)}, + {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(1_000)}, + {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(10)}, } oracleGenesis.Params.VotePeriod = 1_000 @@ -168,13 +169,13 @@ func (s *IntegrationTestSuite) TestGetPrices() { val := s.network.Validators[0] s.T().Log("check vpool balances") - reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)) + reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("10000000"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.MustNewDecFromStr("60000000000"), reserveAssets.QuoteAssetReserve) s.T().Log("check prices") - priceInfo, err := testutilcli.QueryBaseAssetPrice(val.ClientCtx, common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), "add", "100") + priceInfo, err := testutilcli.QueryBaseAssetPrice(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), "add", "100") s.T().Logf("priceInfo: %+v", priceInfo) s.EqualValues(sdk.MustNewDecFromStr("599994.000059999400006000"), priceInfo.PriceInQuoteDenom) s.NoError(err) @@ -186,7 +187,7 @@ func (s *IntegrationTestSuite) TestCmdEditPoolConfigProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD)] + startVpool := START_VPOOLS[common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)] proposal := &vpooltypes.EditPoolConfigProposal{ Title: "NIP-3: Edit config of the ueth:unusd vpool", Description: "enables higher max leverage on ueth:unusd", @@ -252,7 +253,7 @@ func (s *IntegrationTestSuite) TestCmdEditSwapInvariantsProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD)] + startVpool := START_VPOOLS[common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)] proposal := &vpooltypes.EditSwapInvariantsProposal{ Title: "NIP-4: Change the swap invariant for ATOM, OSMO, and BTC.", Description: "increase swap invariant for many virtual pools", diff --git a/x/vpool/keeper/keeper_test.go b/x/vpool/keeper/keeper_test.go index 96f4be858..af9a0749e 100644 --- a/x/vpool/keeper/keeper_test.go +++ b/x/vpool/keeper/keeper_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil/mock" "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -32,7 +33,7 @@ func TestSwapQuoteForBase(t *testing.T) { }{ { name: "quote amount == 0", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(0), baseLimit: sdk.NewDec(10), @@ -44,7 +45,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap add", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(49504), @@ -56,7 +57,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap remove", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(50506), @@ -78,7 +79,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount less than base limit in Long", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(500_000), baseLimit: sdk.NewDec(454_500), @@ -88,7 +89,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount more than base limit in Short", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_500), @@ -98,7 +99,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when removing quote", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -108,7 +109,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when adding quote", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -118,7 +119,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), @@ -128,7 +129,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), @@ -138,7 +139,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), @@ -150,7 +151,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), @@ -172,7 +173,7 @@ func TestSwapQuoteForBase(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ @@ -200,7 +201,7 @@ func TestSwapQuoteForBase(t *testing.T) { assert.EqualValuesf(t, tc.expectedBaseAmount, baseAmt, "base amount mismatch") t.Log("assert vpool") - pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) require.NoError(t, err) assert.EqualValuesf(t, tc.expectedQuoteReserve, pool.QuoteAssetReserve, "pool quote asset reserve mismatch") assert.EqualValuesf(t, tc.expectedBaseReserve, pool.BaseAssetReserve, "pool base asset reserve mismatch") @@ -225,7 +226,7 @@ func TestSwapBaseForQuote(t *testing.T) { }{ { name: "zero base asset swap", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.ZeroDec(), quoteLimit: sdk.ZeroDec(), @@ -237,7 +238,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "add base asset swap", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196078), @@ -249,7 +250,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "remove base asset", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(204_082), @@ -271,7 +272,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount less than quote limit in Long", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196079), @@ -281,7 +282,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount more than quote limit in Short", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(204_081), @@ -291,7 +292,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when removing base", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -301,7 +302,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when adding base", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -311,7 +312,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), @@ -321,7 +322,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), @@ -331,7 +332,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), @@ -343,7 +344,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), @@ -365,7 +366,7 @@ func TestSwapBaseForQuote(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ @@ -394,7 +395,7 @@ func TestSwapBaseForQuote(t *testing.T) { "expected %s; got %s", tc.expectedQuoteAssetAmount.String(), quoteAssetAmount.String()) t.Log("assert pool") - pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) require.NoError(t, err) assert.Equal(t, tc.expectedQuoteReserve, pool.QuoteAssetReserve) assert.Equal(t, tc.expectedBaseReserve, pool.BaseAssetReserve) @@ -410,7 +411,7 @@ func TestGetVpools(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10*common.Precision), sdk.NewDec(5*common.Precision), types.VpoolConfig{ @@ -423,7 +424,7 @@ func TestGetVpools(t *testing.T) { )) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), sdk.NewDec(5*common.Precision), sdk.NewDec(10*common.Precision), types.VpoolConfig{ @@ -440,7 +441,7 @@ func TestGetVpools(t *testing.T) { require.EqualValues(t, 2, len(pools)) require.EqualValues(t, pools[0], types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(5 * common.Precision), QuoteAssetReserve: sdk.NewDec(10 * common.Precision), Config: types.VpoolConfig{ @@ -452,7 +453,7 @@ func TestGetVpools(t *testing.T) { }, }) require.EqualValues(t, pools[1], types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: types.VpoolConfig{ @@ -476,7 +477,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses latest snapshot - does not result in error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -489,13 +490,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -506,7 +507,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses previous snapshot - results in error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -519,7 +520,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -530,7 +531,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "only one snapshot - no error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -543,7 +544,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -554,7 +555,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "zero fluctuation limit - no error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -567,13 +568,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -584,7 +585,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "multiple pools - no overlap", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -597,25 +598,25 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(common.DenomUSDC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -666,7 +667,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -677,7 +678,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -694,7 +695,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { mock.NewMockOracleKeeper(gomock.NewController(t)), ) vpoolKeeper.Pools.Insert(ctx, tc.pool.Pair, tc.pool) - mmr, err := vpoolKeeper.GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + mmr, err := vpoolKeeper.GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) assert.NoError(t, err) assert.EqualValues(t, tc.expectedMaintenanceMarginRatio, mmr) }) @@ -711,7 +712,7 @@ func TestGetMaxLeverage(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -734,7 +735,7 @@ func TestGetMaxLeverage(t *testing.T) { ) vpoolKeeper.Pools.Insert(ctx, tc.pool.Pair, tc.pool) - maxLeverage, err := vpoolKeeper.GetMaxLeverage(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + maxLeverage, err := vpoolKeeper.GetMaxLeverage(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) assert.EqualValues(t, tc.expectedMaxLeverage, maxLeverage) assert.NoError(t, err) }) diff --git a/x/vpool/keeper/pool_state_test.go b/x/vpool/keeper/pool_state_test.go index 501dabe80..1e36f8e58 100644 --- a/x/vpool/keeper/pool_state_test.go +++ b/x/vpool/keeper/pool_state_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -18,7 +19,7 @@ func TestCreatePool(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens @@ -31,7 +32,7 @@ func TestCreatePool(t *testing.T) { }, )) - exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) require.True(t, exists) notExist := vpoolKeeper.ExistsPool(ctx, "BTC:OTHER") @@ -39,7 +40,7 @@ func TestCreatePool(t *testing.T) { } func TestEditPoolConfig(t *testing.T) { - pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) vpoolStart := types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(10 * common.Precision), @@ -57,12 +58,12 @@ func TestEditPoolConfig(t *testing.T) { vpoolKeeper, _, ctx := getKeeper(t) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), vpoolStart.QuoteAssetReserve, vpoolStart.BaseAssetReserve, vpoolStart.Config, )) - exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD)) + exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) require.True(t, exists) return vpoolKeeper, ctx } @@ -188,7 +189,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool + pricefeed active", vpool: types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -202,7 +203,7 @@ func TestGetPoolPrices(t *testing.T) { shouldCreateVpool: true, mockIndexPrice: sdk.NewDec(99), expectedPoolPrices: types.PoolPrices{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.NewDec(99).String(), @@ -213,7 +214,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool active, but no index price", vpool: types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -228,7 +229,7 @@ func TestGetPoolPrices(t *testing.T) { mockIndexPrice: sdk.OneDec().Neg(), oracleKeeperErr: fmt.Errorf("No index price"), expectedPoolPrices: types.PoolPrices{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.OneDec().Neg().String(), @@ -239,7 +240,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "vpool doesn't exist", vpool: types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -292,7 +293,7 @@ func TestGetPoolPrices(t *testing.T) { } func TestEditSwapInvariant(t *testing.T) { - pair := common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD) vpoolStart := types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(10 * common.Precision), diff --git a/x/vpool/keeper/prices_test.go b/x/vpool/keeper/prices_test.go index 8069295e7..229d17661 100644 --- a/x/vpool/keeper/prices_test.go +++ b/x/vpool/keeper/prices_test.go @@ -12,6 +12,7 @@ import ( "github.com/NibiruChain/collections" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil/mock" "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -26,14 +27,14 @@ func TestGetMarkPrice(t *testing.T) { }{ { name: "correctly fetch underlying price", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(1), expectedPrice: sdk.NewDec(40000), }, { name: "complex price", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), quoteAssetReserve: sdk.NewDec(2_489_723_947), baseAssetReserve: sdk.NewDec(34_597_234), expectedPrice: sdk.MustNewDecFromStr("71.963092396345904415"), @@ -80,7 +81,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), baseAmount: sdk.ZeroDec(), @@ -89,7 +90,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -98,7 +99,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -107,7 +108,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("1000"), @@ -163,7 +164,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), quoteAmount: sdk.ZeroDec(), @@ -172,7 +173,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -181,7 +182,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -190,7 +191,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(1000), @@ -252,22 +253,22 @@ func TestCalcTwap(t *testing.T) { // expected price: ((95/10 * (35 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 10) + 100/1 * (10 - 5)) / (5 + 10 + 10 + 5) { name: "spot price twap calc, t=[5,35]", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -283,22 +284,22 @@ func TestCalcTwap(t *testing.T) { // expected price: (95/10 * (30 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 10)) / (10 + 10) { name: "spot price twap calc, t=[10,30]", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -314,22 +315,22 @@ func TestCalcTwap(t *testing.T) { // expected price: (95/10 * (35 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 11)) / (5 + 10 + 9) { name: "spot price twap calc, t=[11,35]", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -347,7 +348,7 @@ func TestCalcTwap(t *testing.T) { // expected price: 100/1 { name: "spot price twap calc, t=[0,0]", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{}, currentBlockTime: time.UnixMilli(0), currentBlockHeight: 1, @@ -361,16 +362,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((7.5 - 300/(40 + 10)) * (30 - 20) + (10 - 300/(30 + 10)) * (20 - 10)) / (10 + 10) { name: "quote asset swap twap calc, add to pool, t=[10,30]", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(30), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.MustNewDecFromStr("7.5"), sdk.NewDec(40), time.UnixMilli(20), @@ -390,16 +391,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((12 - 600/(50 - 10)) * (30 - 20) + (10 - 600/(60 - 10)) * (20 - 10)) / (10 + 10) { name: "quote asset swap twap calc, remove from pool, t=[10,30]", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(12), sdk.NewDec(50), time.UnixMilli(20), @@ -415,10 +416,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: quote asset reserve = asset amount", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(20), time.UnixMilli(20), @@ -438,16 +439,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((60 - 600/(10 + 10)) * (20 - 10) + (30 - 600/(20 + 10)) * (30 - 20)) / (10 + 10) { name: "base asset swap twap calc, add to pool, t=[10,30]", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(20), sdk.NewDec(30), time.UnixMilli(20), @@ -467,16 +468,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((60 - 600/(10 - 2)) * (20 - 10) + (75 - 600/(8 - 2)) * (30 - 20)) / (10 + 10) { name: "base asset swap twap calc, remove from pool, t=[10,30]", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(8), sdk.NewDec(75), time.UnixMilli(20), @@ -492,10 +493,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: base asset reserve = asset amount", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(20), @@ -539,7 +540,7 @@ func TestCalcTwap(t *testing.T) { for _, snapshot := range tc.reserveSnapshots { ctx = ctx.WithBlockTime(time.UnixMilli(snapshot.TimestampMs)) snapshot := types.NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), snapshot.BaseAssetReserve, snapshot.QuoteAssetReserve, ctx.BlockTime(), diff --git a/x/vpool/keeper/query_server_test.go b/x/vpool/keeper/query_server_test.go index f6fe9cac5..334c279a9 100644 --- a/x/vpool/keeper/query_server_test.go +++ b/x/vpool/keeper/query_server_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil/mock" "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -23,7 +24,7 @@ func TestQueryReserveAssets(t *testing.T) { t.Log("initialize vpool") pool := types.Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1 * common.Precision), BaseAssetReserve: sdk.NewDec(1000), Config: types.VpoolConfig{ @@ -40,7 +41,7 @@ func TestQueryReserveAssets(t *testing.T) { resp, err := queryServer.ReserveAssets( sdk.WrapSDKContext(ctx), &types.QueryReserveAssetsRequest{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), }, ) @@ -57,7 +58,7 @@ func TestQueryAllPools(t *testing.T) { queryServer := NewQuerier(vpoolKeeper) t.Log("initialize vpool") - pair := common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) pool := &types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(1 * common.Precision), diff --git a/x/vpool/keeper/snapshot_test.go b/x/vpool/keeper/snapshot_test.go index e10391a1e..f1d42b368 100644 --- a/x/vpool/keeper/snapshot_test.go +++ b/x/vpool/keeper/snapshot_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -24,7 +25,7 @@ func TestGetSnapshotPrice(t *testing.T) { }{ { name: "spot price calc", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(2), twapCalcOption: types.TwapCalcOption_SPOT, @@ -32,7 +33,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap add to pool calc", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_QUOTE_ASSET_SWAP, @@ -42,7 +43,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap remove from pool calc", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_QUOTE_ASSET_SWAP, @@ -52,7 +53,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap add to pool calc", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_BASE_ASSET_SWAP, @@ -62,7 +63,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap remove from pool calc", - pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_BASE_ASSET_SWAP, diff --git a/x/vpool/simulation/genesis.go b/x/vpool/simulation/genesis.go index 628cd07ac..429e8fe27 100644 --- a/x/vpool/simulation/genesis.go +++ b/x/vpool/simulation/genesis.go @@ -9,6 +9,7 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -23,7 +24,7 @@ func RandomizedGenState(simState *module.SimulationState) { vpoolGenesis := types.GenesisState{ Vpools: []types.Vpool{ { - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(10e12).Add(simtypes.RandomDecAmount(simState.Rand, sdk.NewDec(10e12))), BaseAssetReserve: sdk.NewDec(10e12).Add(simtypes.RandomDecAmount(simState.Rand, sdk.NewDec(10e12))), Config: types.VpoolConfig{ diff --git a/x/vpool/types/gov_test.go b/x/vpool/types/gov_test.go index b42b0c1ca..3b51b3739 100644 --- a/x/vpool/types/gov_test.go +++ b/x/vpool/types/gov_test.go @@ -11,6 +11,7 @@ import ( "github.com/gogo/protobuf/jsonpb" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -144,7 +145,7 @@ func TestMarshalProposalEditPoolConfig(t *testing.T) { proposal := EditPoolConfigProposal{ Title: "Edit vpool config for NIBI:NUSD", Description: "I want to take 100x leverage on my NIBI", - Pair: common.AssetRegistry.Pair(common.DenomNIBI, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), Config: VpoolConfig{ MaxLeverage: sdk.MustNewDecFromStr("100"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), diff --git a/x/vpool/types/pool_test.go b/x/vpool/types/pool_test.go index 3992081dd..37a70d7ff 100644 --- a/x/vpool/types/pool_test.go +++ b/x/vpool/types/pool_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" ) @@ -504,7 +505,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "happy path", Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -513,7 +514,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil base", Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -522,7 +523,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero base", Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -531,7 +532,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil quote", Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.Dec{}, }, @@ -540,7 +541,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero quote", Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.ZeroDec(), }, @@ -566,7 +567,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "zero fluctuation limit ratio", pool: Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -582,7 +583,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "lower limit of fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(999), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -598,7 +599,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "upper limit of fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1001), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -614,7 +615,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "under fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(998), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -630,7 +631,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "over fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -649,7 +650,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { snapshot := NewReserveSnapshot( - common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.OneDec(), sdk.NewDec(1000), time.Now(), @@ -668,7 +669,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "happy path", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(10), QuoteAssetReserve: sdk.NewDec(10_000), }, @@ -677,7 +678,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid base", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.NewDec(500), }, @@ -686,7 +687,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid quote", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.Dec{}, }, @@ -695,7 +696,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative quote", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.NewDec(-500), }, @@ -704,7 +705,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative base", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(common.DenomBTC, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(-500), QuoteAssetReserve: sdk.NewDec(500), }, diff --git a/x/vpool/types/snapshot_test.go b/x/vpool/types/snapshot_test.go index f9c7c953c..18d23a339 100644 --- a/x/vpool/types/snapshot_test.go +++ b/x/vpool/types/snapshot_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" ) func TestSnapshotValidate(t *testing.T) { @@ -19,7 +20,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "happy path", snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), BaseAssetReserve: sdk.OneDec(), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -39,7 +40,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "base asset negative", snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(-1), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -49,7 +50,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "quote asset negative", snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.NewDec(-1), TimestampMs: time.Now().UnixMilli(), @@ -60,7 +61,7 @@ func TestSnapshotValidate(t *testing.T) { name: "timestamp lower than smallest UTC ('0001-01-01 00:00:00 +0000 UTC')", // see time.UnixMilli(-62135596800000).UTC()) snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.ZeroDec(), TimestampMs: -62135596800000 - 1, diff --git a/x/wasm/cli/cli_test.go b/x/wasm/cli/cli_test.go index 5354578d2..1becdfc35 100644 --- a/x/wasm/cli/cli_test.go +++ b/x/wasm/cli/cli_test.go @@ -16,6 +16,7 @@ import ( "github.com/NibiruChain/nibiru/app" "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" testutilcli "github.com/NibiruChain/nibiru/x/testutil/cli" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -24,7 +25,7 @@ import ( var commonArgs = []string{ fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(common.DenomNIBI, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10))).String()), } type IntegrationTestSuite struct { @@ -48,7 +49,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: common.AssetRegistry.Pair(common.DenomETH, common.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ From bd0f7ea1734795f6ba5ca5771bb20a4484d112b1 Mon Sep 17 00:00:00 2001 From: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> Date: Wed, 25 Jan 2023 18:22:56 -0600 Subject: [PATCH 6/9] refactor(asset_registry): Use `set[string]` instead of slice `[]string`, since it covers both use cases (#1159) * refactor(asset_registry): Use StringSet instead of []slice, since it covers both use cases * feat: add generic sets (#1160) * feat(set): use a generic set instead of StringSet * chore: update changelog Co-authored-by: Kevin Yang <5478483+k-yang@users.noreply.github.com> --- CHANGELOG.md | 1 + x/common/asset_registry.go | 66 +++++++++++++++--------------- x/common/asset_registry_test.go | 14 +++---- x/common/set.go | 36 ---------------- x/common/set/set.go | 36 ++++++++++++++++ x/common/{ => set}/set_test.go | 17 ++++---- x/oracle/keeper/tally_fuzz_test.go | 4 +- 7 files changed, 89 insertions(+), 85 deletions(-) delete mode 100644 x/common/set.go create mode 100644 x/common/set/set.go rename x/common/{ => set}/set_test.go (80%) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2e35f36f..89cb450ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1141](https://github.com/NibiruChain/nibiru/pull/1141) - refactor(oracle): rename variables for readability * [#1146](https://github.com/NibiruChain/nibiru/pull/1146) - fix: local docker-compose network * [#1145](https://github.com/NibiruChain/nibiru/pull/1145) - chore: add USD quote asset +* [#1160](https://github.com/NibiruChain/nibiru/pull/1160) - feat: generic set ### Bug Fixes diff --git a/x/common/asset_registry.go b/x/common/asset_registry.go index 31d6589c2..bb9b6883a 100644 --- a/x/common/asset_registry.go +++ b/x/common/asset_registry.go @@ -1,32 +1,35 @@ package common -import "github.com/NibiruChain/nibiru/x/common/denoms" +import ( + "github.com/NibiruChain/nibiru/x/common/denoms" + "github.com/NibiruChain/nibiru/x/common/set" +) -type assetRegistry map[string][]string +type assetRegistry map[string]set.Set[string] var AssetRegistry assetRegistry func init() { // map of base asset to supported quote assets // quote assets are usually stables - AssetRegistry = map[string][]string{ - denoms.DenomBTC: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, - denoms.DenomETH: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, - denoms.DenomNIBI: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, - denoms.DenomATOM: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, - denoms.DenomOSMO: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, - denoms.DenomAVAX: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, - denoms.DenomSOL: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, - denoms.DenomBNB: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, - denoms.DenomADA: {denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT}, - denoms.DenomNUSD: {denoms.DenomUSD, denoms.DenomUSDC}, - denoms.DenomUSDC: {denoms.DenomUSD, denoms.DenomNUSD}, - denoms.DenomUSDT: {denoms.DenomUSD, denoms.DenomNUSD, denoms.DenomUSDC}, + AssetRegistry = map[string]set.Set[string]{ + denoms.DenomBTC: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), + denoms.DenomETH: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), + denoms.DenomNIBI: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), + denoms.DenomATOM: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), + denoms.DenomOSMO: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), + denoms.DenomAVAX: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), + denoms.DenomSOL: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), + denoms.DenomBNB: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), + denoms.DenomADA: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), + denoms.DenomNUSD: set.New(denoms.DenomUSD, denoms.DenomUSDC), + denoms.DenomUSDC: set.New(denoms.DenomUSD, denoms.DenomNUSD), + denoms.DenomUSDT: set.New(denoms.DenomUSD, denoms.DenomNUSD, denoms.DenomUSDC), } } func (r assetRegistry) Pair(base string, quote string) AssetPair { - for _, q := range r[base] { + for q := range r[base] { if q == quote { return NewAssetPair(string(base), string(quote)) } @@ -36,24 +39,26 @@ func (r assetRegistry) Pair(base string, quote string) AssetPair { } // Returns all supported base denoms -func (r assetRegistry) BaseDenoms() []string { - var denoms []string +func (r assetRegistry) BaseDenoms() set.Set[string] { + baseSet := make(set.Set[string]) for d := range r { - denoms = append(denoms, d) + baseSet.Add(d) } - return denoms + return baseSet } // Returns all supported quote denoms -func (r assetRegistry) QuoteDenoms() []string { - var denoms []string - for _, q := range r { - denoms = append(denoms, q...) +func (r assetRegistry) QuoteDenoms() set.Set[string] { + quoteSet := make(set.Set[string]) + for base := range r { + for q := range r[base] { + quoteSet.Add(q) + } } - return denoms + return quoteSet } -// Checks if the provided denom is a supportedd base denom +// Checks if the provided denom is a supported base denom func (r assetRegistry) IsSupportedBaseDenom(denom string) bool { _, ok := r[denom] return ok @@ -61,14 +66,7 @@ func (r assetRegistry) IsSupportedBaseDenom(denom string) bool { // Checks if the provided denom is a supported quote denom func (r assetRegistry) IsSupportedQuoteDenom(denom string) bool { - for _, q := range r { - for _, d := range q { - if d == denom { - return true - } - } - } - return false + return r.QuoteDenoms().Has(denom) } // Checks if the provided denom is a supported denom diff --git a/x/common/asset_registry_test.go b/x/common/asset_registry_test.go index df86371aa..8ee1fd7b4 100644 --- a/x/common/asset_registry_test.go +++ b/x/common/asset_registry_test.go @@ -10,7 +10,7 @@ import ( func TestIsSupportedPair(t *testing.T) { for base := range AssetRegistry { - for _, quote := range AssetRegistry[base] { + for quote := range AssetRegistry[base] { require.Truef(t, AssetRegistry.IsSupportedPair(base, quote), "%s:%s should be supported", base, quote) } } @@ -21,7 +21,7 @@ func TestIsSupportedPair(t *testing.T) { func TestPair(t *testing.T) { for base := range AssetRegistry { - for _, quote := range AssetRegistry[base] { + for quote := range AssetRegistry[base] { require.Equal(t, NewAssetPair(base, quote), AssetRegistry.Pair(base, quote)) } } @@ -51,15 +51,15 @@ func TestIsSupportedBaseDenom(t *testing.T) { func TestQuoteDenoms(t *testing.T) { for base := range AssetRegistry { - for _, quote := range AssetRegistry[base] { - require.Contains(t, AssetRegistry.QuoteDenoms(), quote) + for quote := range AssetRegistry[base] { + require.True(t, AssetRegistry.QuoteDenoms().Has(quote)) } } } func TestIsSupportedQuoteDenom(t *testing.T) { for base := range AssetRegistry { - for _, quote := range AssetRegistry[base] { + for quote := range AssetRegistry[base] { require.True(t, AssetRegistry.IsSupportedQuoteDenom(quote)) } } @@ -68,11 +68,11 @@ func TestIsSupportedQuoteDenom(t *testing.T) { } func TestIsSupportedDenom(t *testing.T) { - for _, base := range AssetRegistry.BaseDenoms() { + for base := range AssetRegistry.BaseDenoms() { require.True(t, AssetRegistry.IsSupportedDenom(base)) } - for _, quote := range AssetRegistry.QuoteDenoms() { + for quote := range AssetRegistry.QuoteDenoms() { require.True(t, AssetRegistry.IsSupportedDenom(quote)) } diff --git a/x/common/set.go b/x/common/set.go deleted file mode 100644 index c371897d1..000000000 --- a/x/common/set.go +++ /dev/null @@ -1,36 +0,0 @@ -package common - -type StringSet map[string]struct{} - -func (set StringSet) Add(s string) { - set[s] = struct{}{} -} - -func (set StringSet) Remove(s string) { - delete(set, s) -} - -func (set StringSet) Has(s string) bool { - _, ok := set[s] - return ok -} - -func (set StringSet) Len() int { - return len(set.ToSlice()) -} - -func (set StringSet) ToSlice() []string { - var slice []string - for s := range set { - slice = append(slice, s) - } - return slice -} - -func NewStringSet(strs ...string) StringSet { - set := StringSet{} - for _, s := range strs { - set.Add(s) - } - return set -} diff --git a/x/common/set/set.go b/x/common/set/set.go new file mode 100644 index 000000000..6b05a9055 --- /dev/null +++ b/x/common/set/set.go @@ -0,0 +1,36 @@ +package set + +type Set[T comparable] map[T]struct{} + +func (set Set[T]) Add(s T) { + set[s] = struct{}{} +} + +func (set Set[T]) Remove(s T) { + delete(set, s) +} + +func (set Set[T]) Has(s T) bool { + _, ok := set[s] + return ok +} + +func (set Set[T]) Len() int { + return len(set.ToSlice()) +} + +func (set Set[T]) ToSlice() []T { + var slice []T + for s := range set { + slice = append(slice, s) + } + return slice +} + +func New[T comparable](strs ...T) Set[T] { + set := Set[T]{} + for _, s := range strs { + set.Add(s) + } + return set +} diff --git a/x/common/set_test.go b/x/common/set/set_test.go similarity index 80% rename from x/common/set_test.go rename to x/common/set/set_test.go index cfcb0745f..f2665b98a 100644 --- a/x/common/set_test.go +++ b/x/common/set/set_test.go @@ -1,23 +1,24 @@ -package common_test +package set import ( "testing" "github.com/stretchr/testify/assert" - - "github.com/NibiruChain/nibiru/x/common" ) var elementSlice = []string{"fire", "earth", "water", "air"} func TestAdd(t *testing.T) { - elements := common.NewStringSet(elementSlice...) + elements := New(elementSlice...) + assert.False(t, elements.Has("lava")) assert.False(t, elements.Has("mud")) + elements.Add("lava") elements.Add("mud") assert.True(t, elements.Has("lava")) assert.True(t, elements.Has("mud")) + assert.Equal(t, 6, elements.Len()) // Add blank string @@ -27,15 +28,17 @@ func TestAdd(t *testing.T) { } func TestRemove(t *testing.T) { - elements := common.NewStringSet(elementSlice...) + elements := New(elementSlice...) elem := "water" assert.True(t, elements.Has(elem)) + elements.Remove(elem) assert.False(t, elements.Has(elem)) } func TestHas(t *testing.T) { - elements := common.NewStringSet(elementSlice...) + elements := New(elementSlice...) + assert.True(t, elements.Has("fire")) assert.True(t, elements.Has("water")) assert.True(t, elements.Has("air")) @@ -46,7 +49,7 @@ func TestHas(t *testing.T) { } func TestLen(t *testing.T) { - elements := common.NewStringSet(elementSlice...) + elements := New(elementSlice...) assert.Equal(t, elements.Len(), 4) elements.Remove("fire") diff --git a/x/oracle/keeper/tally_fuzz_test.go b/x/oracle/keeper/tally_fuzz_test.go index f693dd813..2ddf7893f 100644 --- a/x/oracle/keeper/tally_fuzz_test.go +++ b/x/oracle/keeper/tally_fuzz_test.go @@ -12,6 +12,7 @@ import ( "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/denoms" + "github.com/NibiruChain/nibiru/x/common/set" "github.com/NibiruChain/nibiru/x/oracle/types" "github.com/NibiruChain/nibiru/x/testutil" ) @@ -221,7 +222,8 @@ func TestFuzz_PickReferencePair(t *testing.T) { // test OracleKeeper.Pairs.Insert voteTargets := map[common.AssetPair]struct{}{} f.Fuzz(&voteTargets) - whitelistedPairs := make(common.StringSet) + whitelistedPairs := make(set.Set[string]) + for key := range voteTargets { assert.NotPanics(t, func() { input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, key) From aa49f266bc9dd7e0be35a457e35919d5d9bdb1ca Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Wed, 25 Jan 2023 19:36:35 -0500 Subject: [PATCH 7/9] refactor: remove redundant Denom name --- cmd/nibid/cmd/testnet.go | 8 +- simapp/testapp.go | 6 +- x/common/asset_registry.go | 24 +- x/common/asset_registry_test.go | 8 +- x/common/common_test.go | 10 +- x/common/denoms/denoms.go | 26 +- x/common/error_test.go | 4 +- x/dex/client/testutil/cli_test.go | 8 +- x/dex/client/testutil/test_helpers.go | 2 +- x/dex/keeper/balances_test.go | 6 +- x/dex/keeper/grpc_query_test.go | 68 +-- x/dex/keeper/keeper_test.go | 12 +- x/dex/keeper/msg_server_test.go | 454 +++++++++--------- x/dex/keeper/swap_test.go | 66 +-- x/dex/simulation/operations.go | 6 +- x/dex/types/params.go | 8 +- x/oracle/keeper/ballot_test.go | 32 +- x/oracle/keeper/keeper_test.go | 4 +- x/oracle/keeper/msg_server_test.go | 18 +- x/oracle/keeper/querier_test.go | 44 +- x/oracle/keeper/reward_test.go | 8 +- x/oracle/keeper/slash_test.go | 40 +- x/oracle/keeper/tally_fuzz_test.go | 8 +- x/oracle/keeper/test_utils.go | 10 +- x/oracle/keeper/update_exchange_rates_test.go | 120 ++--- x/oracle/simulation/decoder_test.go | 4 +- x/oracle/simulation/genesis.go | 10 +- x/oracle/simulation/operations.go | 2 +- x/oracle/types/ballot_test.go | 26 +- x/oracle/types/msgs_test.go | 2 +- x/oracle/types/params.go | 8 +- x/perp/client/cli/cli_test.go | 114 ++--- x/perp/genesis_test.go | 4 +- x/perp/keeper/calc_test.go | 2 +- x/perp/keeper/calc_unit_test.go | 24 +- .../keeper/clearing_house_integration_test.go | 84 ++-- x/perp/keeper/clearing_house_unit_test.go | 136 +++--- x/perp/keeper/grpc_query_test.go | 66 +-- x/perp/keeper/hooks_test.go | 16 +- x/perp/keeper/liquidate_unit_test.go | 186 +++---- x/perp/keeper/margin_test.go | 16 +- x/perp/keeper/margin_unit_test.go | 82 ++-- x/perp/keeper/msg_server_test.go | 88 ++-- x/perp/simulation/genesis.go | 2 +- x/perp/simulation/operations.go | 28 +- x/perp/types/msgs_test.go | 8 +- x/stablecoin/abci.go | 2 +- x/stablecoin/abci_test.go | 14 +- x/stablecoin/client/cli/cli_test.go | 28 +- x/stablecoin/genesis_test.go | 2 +- x/stablecoin/keeper/collateral_ratio.go | 22 +- x/stablecoin/keeper/collateral_ratio_test.go | 210 ++++---- x/stablecoin/keeper/keeper.go | 2 +- x/stablecoin/keeper/mint_burn_stable.go | 14 +- x/stablecoin/keeper/mint_burn_stable_test.go | 132 ++--- x/stablecoin/keeper/supply.go | 8 +- x/stablecoin/keeper/supply_test.go | 16 +- x/stablecoin/simulation/msg.go | 2 +- x/stablecoin/types/genesis.go | 2 +- x/testutil/cli/network.go | 10 +- x/testutil/cli/tx.go | 2 +- x/testutil/testapp/config.go | 10 +- x/testutil/testapp/testapp.go | 2 +- x/vpool/abci_test.go | 12 +- x/vpool/client/cli/cli_test.go | 24 +- x/vpool/keeper/keeper_test.go | 100 ++-- x/vpool/keeper/pool_state_test.go | 22 +- x/vpool/keeper/prices_test.go | 80 +-- x/vpool/keeper/query_server_test.go | 6 +- x/vpool/keeper/snapshot_test.go | 10 +- x/vpool/simulation/genesis.go | 2 +- x/vpool/types/gov_test.go | 2 +- x/vpool/types/pool_test.go | 32 +- x/vpool/types/snapshot_test.go | 8 +- x/wasm/cli/cli_test.go | 4 +- 75 files changed, 1344 insertions(+), 1344 deletions(-) diff --git a/cmd/nibid/cmd/testnet.go b/cmd/nibid/cmd/testnet.go index f2df056e2..f1d4cb036 100644 --- a/cmd/nibid/cmd/testnet.go +++ b/cmd/nibid/cmd/testnet.go @@ -89,7 +89,7 @@ Example: cmd.Flags().String(flagNodeDaemonHome, "nibid", "Home directory of the node's daemon configuration") cmd.Flags().String(flagStartingIPAddress, "192.168.0.1", "Starting IP address (192.168.0.1 results in persistent peers list ID0@192.168.0.1:46656, ID1@192.168.0.2:46656, ...)") cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") - cmd.Flags().String(server.FlagMinGasPrices, fmt.Sprintf("0.000006%s", denoms.DenomNIBI), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.001stake)") + cmd.Flags().String(server.FlagMinGasPrices, fmt.Sprintf("0.000006%s", denoms.NIBI), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.001stake)") cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)") cmd.Flags().String(flags.FlagKeyAlgorithm, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for") @@ -200,8 +200,8 @@ func InitTestnet( accTokens := sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction) accStakingTokens := sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction) coins := sdk.Coins{ - sdk.NewCoin(denoms.DenomNUSD, accTokens), - sdk.NewCoin(denoms.DenomNIBI, accStakingTokens), + sdk.NewCoin(denoms.NUSD, accTokens), + sdk.NewCoin(denoms.NIBI, accStakingTokens), } genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()}) @@ -211,7 +211,7 @@ func InitTestnet( createValMsg, err := stakingtypes.NewMsgCreateValidator( sdk.ValAddress(addr), valPubKeys[i], - sdk.NewCoin(denoms.DenomNIBI, valTokens), + sdk.NewCoin(denoms.NIBI, valTokens), stakingtypes.NewDescription(nodeDirName, "", "", "", ""), stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()), sdk.OneInt(), diff --git a/simapp/testapp.go b/simapp/testapp.go index a149db584..07cc23697 100644 --- a/simapp/testapp.go +++ b/simapp/testapp.go @@ -37,8 +37,8 @@ func NewTestNibiruAppAndContext(shouldUseDefaultGenesis bool) (*NibiruTestApp, s newNibiruApp := NewTestNibiruApp(shouldUseDefaultGenesis) ctx := newNibiruApp.NewContext(false, tmproto.Header{}) - newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.NewDec(20000)) - // newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), sdk.NewDec(10)) + newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(20000)) + // newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewDec(10)) newNibiruApp.OracleKeeper.SetPrice(ctx, "xxx:yyy", sdk.NewDec(20000)) return newNibiruApp, ctx @@ -123,7 +123,7 @@ func NewTestGenesisState(codec codec.Codec, inGenState GenesisState, var govGenState govtypes.GenesisState codec.MustUnmarshalJSON(testGenState[govtypes.ModuleName], &govGenState) govGenState.VotingParams.VotingPeriod = time.Second * 20 - govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision)) // min deposit of 1 NIBI + govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1*common.Precision)) // min deposit of 1 NIBI testGenState[govtypes.ModuleName] = codec.MustMarshalJSON(&govGenState) return testGenState diff --git a/x/common/asset_registry.go b/x/common/asset_registry.go index bb9b6883a..c64b5c91b 100644 --- a/x/common/asset_registry.go +++ b/x/common/asset_registry.go @@ -13,18 +13,18 @@ func init() { // map of base asset to supported quote assets // quote assets are usually stables AssetRegistry = map[string]set.Set[string]{ - denoms.DenomBTC: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), - denoms.DenomETH: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), - denoms.DenomNIBI: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), - denoms.DenomATOM: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), - denoms.DenomOSMO: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), - denoms.DenomAVAX: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), - denoms.DenomSOL: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), - denoms.DenomBNB: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), - denoms.DenomADA: set.New(denoms.DenomUSDC, denoms.DenomNUSD, denoms.DenomUSD, denoms.DenomUSDT), - denoms.DenomNUSD: set.New(denoms.DenomUSD, denoms.DenomUSDC), - denoms.DenomUSDC: set.New(denoms.DenomUSD, denoms.DenomNUSD), - denoms.DenomUSDT: set.New(denoms.DenomUSD, denoms.DenomNUSD, denoms.DenomUSDC), + denoms.BTC: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), + denoms.ETH: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), + denoms.NIBI: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), + denoms.ATOM: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), + denoms.OSMO: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), + denoms.AVAX: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), + denoms.SOL: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), + denoms.BNB: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), + denoms.ADA: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), + denoms.NUSD: set.New(denoms.USD, denoms.USDC), + denoms.USDC: set.New(denoms.USD, denoms.NUSD), + denoms.USDT: set.New(denoms.USD, denoms.NUSD, denoms.USDC), } } diff --git a/x/common/asset_registry_test.go b/x/common/asset_registry_test.go index 8ee1fd7b4..463ece9d3 100644 --- a/x/common/asset_registry_test.go +++ b/x/common/asset_registry_test.go @@ -16,7 +16,7 @@ func TestIsSupportedPair(t *testing.T) { } t.Log("test an unsupported pair") - require.False(t, AssetRegistry.IsSupportedPair(denoms.DenomATOM, denoms.DenomOSMO)) + require.False(t, AssetRegistry.IsSupportedPair(denoms.ATOM, denoms.OSMO)) } func TestPair(t *testing.T) { @@ -27,13 +27,13 @@ func TestPair(t *testing.T) { } t.Log("test an unsupported pair") - require.Equal(t, AssetPair(""), AssetRegistry.Pair(denoms.DenomATOM, denoms.DenomOSMO)) + require.Equal(t, AssetPair(""), AssetRegistry.Pair(denoms.ATOM, denoms.OSMO)) t.Log("test an unsupported base asset") - require.Equal(t, AssetPair(""), AssetRegistry.Pair("unsuported_denom", denoms.DenomUSDC)) + require.Equal(t, AssetPair(""), AssetRegistry.Pair("unsuported_denom", denoms.USDC)) t.Log("test an unsupported quote asset") - require.Equal(t, AssetPair(""), AssetRegistry.Pair(denoms.DenomATOM, "unsupported_denom")) + require.Equal(t, AssetPair(""), AssetRegistry.Pair(denoms.ATOM, "unsupported_denom")) } func TestBaseDenoms(t *testing.T) { diff --git a/x/common/common_test.go b/x/common/common_test.go index 5938b0967..920c28863 100644 --- a/x/common/common_test.go +++ b/x/common/common_test.go @@ -20,23 +20,23 @@ func TestTryNewAssetPair(t *testing.T) { }{ { "only one token", - denoms.DenomNIBI, + denoms.NIBI, common.ErrInvalidTokenPair, }, { "more than 2 tokens", - fmt.Sprintf("%s%s%s%s%s", denoms.DenomNIBI, common.PairSeparator, denoms.DenomNUSD, - common.PairSeparator, denoms.DenomUSDC), + fmt.Sprintf("%s%s%s%s%s", denoms.NIBI, common.PairSeparator, denoms.NUSD, + common.PairSeparator, denoms.USDC), common.ErrInvalidTokenPair, }, { "different separator", - fmt.Sprintf("%s%s%s", denoms.DenomNIBI, "%", denoms.DenomNUSD), + fmt.Sprintf("%s%s%s", denoms.NIBI, "%", denoms.NUSD), common.ErrInvalidTokenPair, }, { "correct pair", - fmt.Sprintf("%s%s%s", denoms.DenomNIBI, common.PairSeparator, denoms.DenomNUSD), + fmt.Sprintf("%s%s%s", denoms.NIBI, common.PairSeparator, denoms.NUSD), nil, }, { diff --git a/x/common/denoms/denoms.go b/x/common/denoms/denoms.go index d8c7d5bf7..5256f86c0 100644 --- a/x/common/denoms/denoms.go +++ b/x/common/denoms/denoms.go @@ -1,20 +1,20 @@ package denoms const ( // stablecoins - DenomUSDC = "uusdc" - DenomNUSD = "unusd" - DenomUSD = "uusd" - DenomUSDT = "uusdt" + USDC = "uusdc" + NUSD = "unusd" + USD = "uusd" + USDT = "uusdt" ) const ( // volatile assets - DenomNIBI = "unibi" - DenomBTC = "ubtc" - DenomETH = "ueth" - DenomATOM = "uatom" - DenomOSMO = "uosmo" - DenomAVAX = "uavax" - DenomSOL = "usol" - DenomBNB = "ubnb" - DenomADA = "uada" + NIBI = "unibi" + BTC = "ubtc" + ETH = "ueth" + ATOM = "uatom" + OSMO = "uosmo" + AVAX = "uavax" + SOL = "usol" + BNB = "ubnb" + ADA = "uada" ) diff --git a/x/common/error_test.go b/x/common/error_test.go index d4b57f3ef..671fe289b 100644 --- a/x/common/error_test.go +++ b/x/common/error_test.go @@ -87,12 +87,12 @@ func TestCombineErrorsGeneric(t *testing.T) { {name: "type=[]string | mixed", in: []string{"", "abc", ""}, out: errors.New(": abc: ")}, // cases: fmt.Stringer - {name: "type=fmt.Stringer |", in: common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), out: errors.New("uusdc:unusd")}, + {name: "type=fmt.Stringer |", in: common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), out: errors.New("uusdc:unusd")}, // cases: []fmt.Stringer { name: "type=[]fmt.Stringer | happy", - in: []fmt.Stringer{common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)}, + in: []fmt.Stringer{common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)}, out: errors.New("ubtc:unusd: ueth:unusd")}, {name: "type=[]fmt.Stringer | empty", in: []fmt.Stringer{}, out: nil}, } diff --git a/x/dex/client/testutil/cli_test.go b/x/dex/client/testutil/cli_test.go index e0f37bff1..31841009d 100644 --- a/x/dex/client/testutil/cli_test.go +++ b/x/dex/client/testutil/cli_test.go @@ -13,9 +13,9 @@ import ( func TestIntegrationTestSuite(t *testing.T) { coinsFromGenesis := []string{ - denoms.DenomNIBI, - denoms.DenomNUSD, - denoms.DenomUSDC, + denoms.NIBI, + denoms.NUSD, + denoms.USDC, "coin-1", "coin-2", "coin-3", @@ -33,7 +33,7 @@ func TestIntegrationTestSuite(t *testing.T) { cfg := testapp.BuildNetworkConfig(genesisState) cfg.StartingTokens = sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 2e12), // for pool creation fee and more for tx fees + sdk.NewInt64Coin(denoms.NIBI, 2e12), // for pool creation fee and more for tx fees ) for _, coin := range coinsFromGenesis { diff --git a/x/dex/client/testutil/test_helpers.go b/x/dex/client/testutil/test_helpers.go index 02ed577de..19d401208 100644 --- a/x/dex/client/testutil/test_helpers.go +++ b/x/dex/client/testutil/test_helpers.go @@ -23,7 +23,7 @@ import ( var commonArgs = []string{ fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(denoms.NIBI, sdk.NewInt(10))).String()), } // ExecMsgCreatePool broadcast a pool creation message. diff --git a/x/dex/keeper/balances_test.go b/x/dex/keeper/balances_test.go index 791c8eb63..70b1cbf87 100644 --- a/x/dex/keeper/balances_test.go +++ b/x/dex/keeper/balances_test.go @@ -29,11 +29,11 @@ func TestCheckBalances(t *testing.T) { name: "has enough funds", userInitialFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), coinsToSpend: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), expectedError: nil, }, @@ -44,7 +44,7 @@ func TestCheckBalances(t *testing.T) { ), coinsToSpend: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), expectedError: sdkerrors.ErrInsufficientFunds, }, diff --git a/x/dex/keeper/grpc_query_test.go b/x/dex/keeper/grpc_query_test.go index 43ede3844..bd30e7c85 100644 --- a/x/dex/keeper/grpc_query_test.go +++ b/x/dex/keeper/grpc_query_test.go @@ -269,7 +269,7 @@ func TestQueryNumPools(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -283,22 +283,22 @@ func TestQueryNumPools(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomUSDC, 100), + sdk.NewInt64Coin(denoms.USDC, 100), ), /*shares=*/ 100, ), mock.DexPool( /*poolId=*/ 2, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomUSDC, 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.USDC, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), mock.DexPool( /*poolId=*/ 3, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), sdk.NewInt64Coin("unibi", 100), ), /*shares=*/ 100, @@ -319,9 +319,9 @@ func TestQueryNumPools(t *testing.T) { ctx, sender, sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1e18), - sdk.NewInt64Coin(denoms.DenomNUSD, 1e18), - sdk.NewInt64Coin(denoms.DenomUSDC, 1e18), + sdk.NewInt64Coin(denoms.NIBI, 1e18), + sdk.NewInt64Coin(denoms.NUSD, 1e18), + sdk.NewInt64Coin(denoms.USDC, 1e18), ), )) @@ -446,7 +446,7 @@ func TestQueryTotalShares(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -489,11 +489,11 @@ func TestQuerySpotPrice(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), - tokenInDenom: denoms.DenomNUSD, + tokenInDenom: denoms.NUSD, tokenOutDenom: "unibi", expectedPrice: sdk.MustNewDecFromStr("1"), }, @@ -503,11 +503,11 @@ func TestQuerySpotPrice(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 200), + sdk.NewInt64Coin(denoms.NUSD, 200), ), /*shares=*/ 100, ), - tokenInDenom: denoms.DenomNUSD, + tokenInDenom: denoms.NUSD, tokenOutDenom: "unibi", expectedPrice: sdk.MustNewDecFromStr("2"), }, @@ -517,12 +517,12 @@ func TestQuerySpotPrice(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 200), + sdk.NewInt64Coin(denoms.NUSD, 200), ), /*shares=*/ 100, ), tokenInDenom: "unibi", - tokenOutDenom: denoms.DenomNUSD, + tokenOutDenom: denoms.NUSD, expectedPrice: sdk.MustNewDecFromStr("0.5"), }, } @@ -564,11 +564,11 @@ func TestQueryEstimateSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(denoms.DenomNUSD, 100), + tokenIn: sdk.NewInt64Coin(denoms.NUSD, 100), tokenOutDenom: "unibi", expectedTokenOut: sdk.NewInt64Coin("unibi", 50), }, @@ -578,14 +578,14 @@ func TestQueryEstimateSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 34844867), - sdk.NewInt64Coin(denoms.DenomNUSD, 4684496849), + sdk.NewInt64Coin(denoms.NUSD, 4684496849), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 586848), - tokenOutDenom: denoms.DenomNUSD, + tokenOutDenom: denoms.NUSD, // https://www.wolframalpha.com/input?i=4684496849+-+%2834844867+*+4684496849+%2F+%2834844867%2B586848%29+%29 - expectedTokenOut: sdk.NewInt64Coin(denoms.DenomNUSD, 77588330), + expectedTokenOut: sdk.NewInt64Coin(denoms.NUSD, 77588330), }, } @@ -625,14 +625,14 @@ func TestQueryEstimateSwapExactAmountOut(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), tokenOut: sdk.NewInt64Coin("unibi", 50), - tokenInDenom: denoms.DenomNUSD, + tokenInDenom: denoms.NUSD, // there's a swap fee that we take the ceiling of to round int - expectedTokenIn: sdk.NewInt64Coin(denoms.DenomNUSD, 101), + expectedTokenIn: sdk.NewInt64Coin(denoms.NUSD, 101), }, { name: "complex swap", @@ -640,11 +640,11 @@ func TestQueryEstimateSwapExactAmountOut(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 34844867), - sdk.NewInt64Coin(denoms.DenomNUSD, 4684496849), + sdk.NewInt64Coin(denoms.NUSD, 4684496849), ), /*shares=*/ 100, ), - tokenOut: sdk.NewInt64Coin(denoms.DenomNUSD, 77588330), + tokenOut: sdk.NewInt64Coin(denoms.NUSD, 77588330), tokenInDenom: "unibi", // https://www.wolframalpha.com/input?i=4684496849+-+%2834844867+*+4684496849+%2F+%2834844867%2B586848%29+%29 expectedTokenIn: sdk.NewInt64Coin("unibi", 586848), @@ -687,13 +687,13 @@ func TestQueryEstimateJoinExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), expectedPoolSharesOut: sdk.NewIntFromUint64(100), expectedRemCoins: sdk.NewCoins(), @@ -704,17 +704,17 @@ func TestQueryEstimateJoinExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 50), - sdk.NewInt64Coin(denoms.DenomNUSD, 75), + sdk.NewInt64Coin(denoms.NUSD, 75), ), expectedPoolSharesOut: sdk.NewIntFromUint64(50), expectedRemCoins: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNUSD, 25), + sdk.NewInt64Coin(denoms.NUSD, 25), ), }, } @@ -754,7 +754,7 @@ func TestQueryEstimateExitExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -762,7 +762,7 @@ func TestQueryEstimateExitExactAmountIn(t *testing.T) { // exit fee leaves some tokens in pool expectedTokensOut: sdk.NewCoins( sdk.NewInt64Coin("unibi", 99), - sdk.NewInt64Coin(denoms.DenomNUSD, 99), + sdk.NewInt64Coin(denoms.NUSD, 99), ), }, { @@ -771,7 +771,7 @@ func TestQueryEstimateExitExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -779,7 +779,7 @@ func TestQueryEstimateExitExactAmountIn(t *testing.T) { // exit fee leaves some tokens in pool expectedTokensOut: sdk.NewCoins( sdk.NewInt64Coin("unibi", 49), - sdk.NewInt64Coin(denoms.DenomNUSD, 49), + sdk.NewInt64Coin(denoms.NUSD, 49), ), }, } diff --git a/x/dex/keeper/keeper_test.go b/x/dex/keeper/keeper_test.go index 9d02da83f..fd004b3e5 100644 --- a/x/dex/keeper/keeper_test.go +++ b/x/dex/keeper/keeper_test.go @@ -61,11 +61,11 @@ func TestSetAndFetchPool(t *testing.T) { }, PoolAssets: []types.PoolAsset{ { - Token: sdk.NewCoin(denoms.DenomBTC, sdk.NewInt(1000)), + Token: sdk.NewCoin(denoms.BTC, sdk.NewInt(1000)), Weight: sdk.NewInt(1), }, { - Token: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1000)), + Token: sdk.NewCoin(denoms.NUSD, sdk.NewInt(1000)), Weight: sdk.NewInt(1), }, }, @@ -222,7 +222,7 @@ func TestFetchPoolFromPair(t *testing.T) { func TestNewPool(t *testing.T) { app, ctx := testapp.NewTestNibiruAppAndContext(true) - poolCreationFeeCoin := sdk.NewInt64Coin(denoms.DenomNIBI, 1000*common.Precision) + poolCreationFeeCoin := sdk.NewInt64Coin(denoms.NIBI, 1000*common.Precision) app.DexKeeper.SetParams(ctx, types.NewParams( /*startingPoolNumber=*/ 1, /*poolCreationFee=*/ sdk.NewCoins(poolCreationFeeCoin), @@ -295,7 +295,7 @@ func TestNewPoolNotEnoughFunds(t *testing.T) { app.DexKeeper.SetParams(ctx, types.NewParams( /*startingPoolNumber=*/ 1, - /*poolCreationFee=*/ sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1000*common.Precision)), + /*poolCreationFee=*/ sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1000*common.Precision)), /*whitelistedAssets*/ []string{}, )) @@ -427,9 +427,9 @@ func TestNewPoolDups(t *testing.T) { userAddr, err := sdk.AccAddressFromBech32(testutil.AccAddress().String()) require.NoError(t, err) - poolCreationFeeCoin := sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1)) + poolCreationFeeCoin := sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1)) err = simapp.FundAccount(app.BankKeeper, ctx, userAddr, sdk.NewCoins( - sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(1000)), + sdk.NewCoin(denoms.NIBI, sdk.NewInt(1000)), sdk.NewCoin("bar", sdk.NewInt(1000)), sdk.NewCoin("foo", sdk.NewInt(1000)), )) diff --git a/x/dex/keeper/msg_server_test.go b/x/dex/keeper/msg_server_test.go index 924845b70..46c04018c 100644 --- a/x/dex/keeper/msg_server_test.go +++ b/x/dex/keeper/msg_server_test.go @@ -66,7 +66,7 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, { @@ -85,7 +85,7 @@ func TestCreatePool(t *testing.T) { Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, }, @@ -96,16 +96,16 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1), + Token: sdk.NewInt64Coin(denoms.NUSD, 1), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1e9-1), + sdk.NewInt64Coin(denoms.NIBI, 1e9-1), sdk.NewInt64Coin("aaa", 1), sdk.NewInt64Coin("bbb", 1), ), @@ -116,16 +116,16 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomNIBI, 1), + Token: sdk.NewInt64Coin(denoms.NIBI, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1e9), + sdk.NewInt64Coin(denoms.NIBI, 1e9), ), expectedErr: fmt.Errorf("0unibi is smaller than 1unibi: insufficient funds"), }, @@ -134,18 +134,18 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1), + Token: sdk.NewInt64Coin(denoms.NUSD, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), - sdk.NewInt64Coin(denoms.DenomNUSD, 1), - sdk.NewInt64Coin(denoms.DenomUSDC, 1), + sdk.NewInt64Coin(denoms.NIBI, 1e9), + sdk.NewInt64Coin(denoms.NUSD, 1), + sdk.NewInt64Coin(denoms.USDC, 1), ), expectedErr: nil, }, @@ -186,7 +186,7 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, { @@ -205,7 +205,7 @@ func TestCreatePool(t *testing.T) { Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, }, @@ -216,16 +216,16 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1), + Token: sdk.NewInt64Coin(denoms.NUSD, 1), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1e9-1), + sdk.NewInt64Coin(denoms.NIBI, 1e9-1), sdk.NewInt64Coin("aaa", 1), sdk.NewInt64Coin("bbb", 1), ), @@ -236,16 +236,16 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomNIBI, 1), + Token: sdk.NewInt64Coin(denoms.NIBI, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1e9), + sdk.NewInt64Coin(denoms.NIBI, 1e9), ), expectedErr: fmt.Errorf("0unibi is smaller than 1unibi: insufficient funds"), }, @@ -254,18 +254,18 @@ func TestCreatePool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1), + Token: sdk.NewInt64Coin(denoms.NUSD, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), - sdk.NewInt64Coin(denoms.DenomNUSD, 1), - sdk.NewInt64Coin(denoms.DenomUSDC, 1), + sdk.NewInt64Coin(denoms.NIBI, 1e9), + sdk.NewInt64Coin(denoms.NUSD, 1), + sdk.NewInt64Coin(denoms.USDC, 1), ), expectedErr: nil, }, @@ -323,18 +323,18 @@ func TestCreateExitJoinPool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.NUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.USDC, 1_000), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), - sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), - sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), + sdk.NewInt64Coin(denoms.NIBI, 1e9), + sdk.NewInt64Coin(denoms.NUSD, 1_000), + sdk.NewInt64Coin(denoms.USDC, 1_000), ), expectedErr: nil, useAllCoins: true, @@ -344,18 +344,18 @@ func TestCreateExitJoinPool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.NUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.USDC, 1_000), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), - sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), - sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), + sdk.NewInt64Coin(denoms.NIBI, 1e9), + sdk.NewInt64Coin(denoms.NUSD, 1_000), + sdk.NewInt64Coin(denoms.USDC, 1_000), ), expectedErr: nil, useAllCoins: true, @@ -365,18 +365,18 @@ func TestCreateExitJoinPool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_BALANCER, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.NUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.USDC, 1_000), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), - sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), - sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), + sdk.NewInt64Coin(denoms.NIBI, 1e9), + sdk.NewInt64Coin(denoms.NUSD, 1_000), + sdk.NewInt64Coin(denoms.USDC, 1_000), ), expectedErr: nil, useAllCoins: false, @@ -386,18 +386,18 @@ func TestCreateExitJoinPool(t *testing.T) { poolParams: types.PoolParams{PoolType: types.PoolType_STABLESWAP, A: sdk.OneInt()}, poolAssets: []types.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.NUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.USDC, 1_000), Weight: sdk.OneInt(), }, }, senderInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1e9), - sdk.NewInt64Coin(denoms.DenomNUSD, 1_000), - sdk.NewInt64Coin(denoms.DenomUSDC, 1_000), + sdk.NewInt64Coin(denoms.NIBI, 1e9), + sdk.NewInt64Coin(denoms.NUSD, 1_000), + sdk.NewInt64Coin(denoms.USDC, 1_000), ), expectedErr: nil, useAllCoins: false, @@ -441,14 +441,14 @@ func TestCreateExitJoinPool(t *testing.T) { require.Equal( t, - tc.senderInitialFunds.Sub(sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1e9))), + tc.senderInitialFunds.Sub(sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1e9))), app.BankKeeper.GetAllBalances(ctx, tc.creatorAddr), ) msgJoinPool := types.MsgJoinPool{ Sender: tc.creatorAddr.String(), PoolId: 1, - TokensIn: tc.senderInitialFunds.Sub(sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1e9))), + TokensIn: tc.senderInitialFunds.Sub(sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1e9))), UseAllCoins: tc.useAllCoins, } _, err = msgServer.JoinPool(sdk.WrapSDKContext(ctx), &msgJoinPool) @@ -478,19 +478,19 @@ func TestMsgServerJoinPool(t *testing.T) { { name: "join with all assets", joinerInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 100), expectedRemCoins: sdk.NewCoins(), @@ -498,93 +498,93 @@ func TestMsgServerJoinPool(t *testing.T) { expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 200), - sdk.NewInt64Coin(common.DenomNUSD, 200), + sdk.NewInt64Coin(denoms.NIBI, 200), + sdk.NewInt64Coin(denoms.NUSD, 200), ), /*shares=*/ 200), }, { name: "join with some assets, none remaining", joinerInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NIBI, 50), + sdk.NewInt64Coin(denoms.NUSD, 50), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 50), expectedRemCoins: sdk.NewCoins(), expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin(shareDenom, 50), - sdk.NewInt64Coin(common.DenomNIBI, 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NIBI, 50), + sdk.NewInt64Coin(denoms.NUSD, 50), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 150), - sdk.NewInt64Coin(common.DenomNUSD, 150), + sdk.NewInt64Coin(denoms.NIBI, 150), + sdk.NewInt64Coin(denoms.NUSD, 150), ), /*shares=*/ 150), }, { name: "join with some assets, some remaining", joinerInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 50), - sdk.NewInt64Coin(common.DenomNUSD, 75), + sdk.NewInt64Coin(denoms.NIBI, 50), + sdk.NewInt64Coin(denoms.NUSD, 75), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 50), expectedRemCoins: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNUSD, 25), + sdk.NewInt64Coin(denoms.NUSD, 25), ), expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin(shareDenom, 50), - sdk.NewInt64Coin(common.DenomNIBI, 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NIBI, 50), + sdk.NewInt64Coin(denoms.NUSD, 50), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 150), - sdk.NewInt64Coin(common.DenomNUSD, 150), + sdk.NewInt64Coin(denoms.NIBI, 150), + sdk.NewInt64Coin(denoms.NUSD, 150), ), /*shares=*/ 150), }, { name: "join with all assets - Stablepool", joinerInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 100), expectedRemCoins: sdk.NewCoins(), @@ -592,72 +592,72 @@ func TestMsgServerJoinPool(t *testing.T) { expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 200), - sdk.NewInt64Coin(common.DenomNUSD, 200), + sdk.NewInt64Coin(denoms.NIBI, 200), + sdk.NewInt64Coin(denoms.NUSD, 200), ), /*shares=*/ 200), }, { name: "join with some assets, none remaining - Stablepool", joinerInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NIBI, 50), + sdk.NewInt64Coin(denoms.NUSD, 50), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 50), expectedRemCoins: []sdk.Coin{}, expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin(shareDenom, 50), - sdk.NewInt64Coin(common.DenomNIBI, 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NIBI, 50), + sdk.NewInt64Coin(denoms.NUSD, 50), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 150), - sdk.NewInt64Coin(common.DenomNUSD, 150), + sdk.NewInt64Coin(denoms.NIBI, 150), + sdk.NewInt64Coin(denoms.NUSD, 150), ), /*shares=*/ 150), }, { name: "join with some assets, some remaining - Stablepool", joinerInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100), tokensIn: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 50), - sdk.NewInt64Coin(common.DenomNUSD, 75), + sdk.NewInt64Coin(denoms.NIBI, 50), + sdk.NewInt64Coin(denoms.NUSD, 75), ), expectedNumSharesOut: sdk.NewInt64Coin(shareDenom, 62), expectedRemCoins: []sdk.Coin{}, expectedJoinerFinalFunds: sdk.NewCoins( sdk.NewInt64Coin(shareDenom, 62), - sdk.NewInt64Coin(common.DenomNIBI, 50), - sdk.NewInt64Coin(common.DenomNUSD, 25), + sdk.NewInt64Coin(denoms.NIBI, 50), + sdk.NewInt64Coin(denoms.NUSD, 25), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 150), - sdk.NewInt64Coin(common.DenomNUSD, 175), + sdk.NewInt64Coin(denoms.NIBI, 150), + sdk.NewInt64Coin(denoms.NUSD, 175), ), /*shares=*/ 162), }, @@ -716,36 +716,36 @@ func TestMsgServerExitPool(t *testing.T) { { name: "exit all pool shares", joinerInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), sdk.NewInt64Coin(shareDenom, 100), ), poolFundsToAdd: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), poolSharesIn: sdk.NewInt64Coin(shareDenom, 100), expectedTokensOut: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 99), - sdk.NewInt64Coin(common.DenomNUSD, 99), + sdk.NewInt64Coin(denoms.NIBI, 99), + sdk.NewInt64Coin(denoms.NUSD, 99), ), expectedJoinerFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 199), - sdk.NewInt64Coin(common.DenomNUSD, 199), + sdk.NewInt64Coin(denoms.NIBI, 199), + sdk.NewInt64Coin(denoms.NUSD, 199), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1), - sdk.NewInt64Coin(common.DenomNUSD, 1), + sdk.NewInt64Coin(denoms.NIBI, 1), + sdk.NewInt64Coin(denoms.NUSD, 1), ), /*shares=*/ 0, ), @@ -753,37 +753,37 @@ func TestMsgServerExitPool(t *testing.T) { { name: "exit half pool shares", joinerInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), sdk.NewInt64Coin(shareDenom, 100), ), poolFundsToAdd: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), poolSharesIn: sdk.NewInt64Coin(shareDenom, 50), expectedTokensOut: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 49), - sdk.NewInt64Coin(common.DenomNUSD, 49), + sdk.NewInt64Coin(denoms.NIBI, 49), + sdk.NewInt64Coin(denoms.NUSD, 49), ), expectedJoinerFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 149), - sdk.NewInt64Coin(common.DenomNUSD, 149), + sdk.NewInt64Coin(denoms.NIBI, 149), + sdk.NewInt64Coin(denoms.NUSD, 149), sdk.NewInt64Coin(shareDenom, 50), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 51), - sdk.NewInt64Coin(common.DenomNUSD, 51), + sdk.NewInt64Coin(denoms.NIBI, 51), + sdk.NewInt64Coin(denoms.NUSD, 51), ), /*shares=*/ 50, ), @@ -791,36 +791,36 @@ func TestMsgServerExitPool(t *testing.T) { { name: "exit all pool shares - StablePool", joinerInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), sdk.NewInt64Coin(shareDenom, 100), ), poolFundsToAdd: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), poolSharesIn: sdk.NewInt64Coin(shareDenom, 100), expectedTokensOut: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), expectedJoinerFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 200), - sdk.NewInt64Coin(common.DenomNUSD, 200), + sdk.NewInt64Coin(denoms.NIBI, 200), + sdk.NewInt64Coin(denoms.NUSD, 200), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1), - sdk.NewInt64Coin(common.DenomNUSD, 1), + sdk.NewInt64Coin(denoms.NIBI, 1), + sdk.NewInt64Coin(denoms.NUSD, 1), ), /*shares=*/ 0, ), @@ -828,37 +828,37 @@ func TestMsgServerExitPool(t *testing.T) { { name: "exit half pool shares - StablePool", joinerInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), sdk.NewInt64Coin(shareDenom, 100), ), poolFundsToAdd: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), poolSharesIn: sdk.NewInt64Coin(shareDenom, 50), expectedTokensOut: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NIBI, 50), + sdk.NewInt64Coin(denoms.NUSD, 50), ), expectedJoinerFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 150), - sdk.NewInt64Coin(common.DenomNUSD, 150), + sdk.NewInt64Coin(denoms.NIBI, 150), + sdk.NewInt64Coin(denoms.NUSD, 150), sdk.NewInt64Coin(shareDenom, 50), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 50), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NIBI, 50), + sdk.NewInt64Coin(denoms.NUSD, 50), ), /*shares=*/ 50, ), @@ -929,27 +929,27 @@ func TestMsgServerSwapAssets(t *testing.T) { { name: "regular swap", userInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(common.DenomNIBI, 100), - tokenOutDenom: common.DenomNUSD, - expectedTokenOut: sdk.NewInt64Coin(common.DenomNUSD, 50), + tokenIn: sdk.NewInt64Coin(denoms.NIBI, 100), + tokenOutDenom: denoms.NUSD, + expectedTokenOut: sdk.NewInt64Coin(denoms.NUSD, 50), expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NUSD, 50), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 200), - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NIBI, 200), + sdk.NewInt64Coin(denoms.NUSD, 50), ), /*shares=*/ 100, ), @@ -958,26 +958,26 @@ func TestMsgServerSwapAssets(t *testing.T) { { name: "not enough user funds", userInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1), + sdk.NewInt64Coin(denoms.NIBI, 1), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(common.DenomNIBI, 100), - tokenOutDenom: common.DenomNUSD, + tokenIn: sdk.NewInt64Coin(denoms.NIBI, 100), + tokenOutDenom: denoms.NUSD, expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1), + sdk.NewInt64Coin(denoms.NIBI, 1), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -991,21 +991,21 @@ func TestMsgServerSwapAssets(t *testing.T) { initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("foo", 100), - tokenOutDenom: denoms.DenomNUSD, + tokenOutDenom: denoms.NUSD, expectedUserFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("foo", 100), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -1014,26 +1014,26 @@ func TestMsgServerSwapAssets(t *testing.T) { { name: "invalid token out denom", userInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(common.DenomNIBI, 100), + tokenIn: sdk.NewInt64Coin(denoms.NIBI, 100), tokenOutDenom: "foo", expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -1042,26 +1042,26 @@ func TestMsgServerSwapAssets(t *testing.T) { { name: "same token in and token out denom", userInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), ), initialPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(common.DenomNIBI, 100), - tokenOutDenom: common.DenomNIBI, + tokenIn: sdk.NewInt64Coin(denoms.NIBI, 100), + tokenOutDenom: denoms.NIBI, expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -1070,27 +1070,27 @@ func TestMsgServerSwapAssets(t *testing.T) { { name: "regular swap - StableSwap", userInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(common.DenomNIBI, 100), - tokenOutDenom: common.DenomNUSD, - expectedTokenOut: sdk.NewInt64Coin(common.DenomNUSD, 95), + tokenIn: sdk.NewInt64Coin(denoms.NIBI, 100), + tokenOutDenom: denoms.NUSD, + expectedTokenOut: sdk.NewInt64Coin(denoms.NUSD, 95), expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 95), + sdk.NewInt64Coin(denoms.NUSD, 95), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 200), - sdk.NewInt64Coin(common.DenomNUSD, 5), + sdk.NewInt64Coin(denoms.NIBI, 200), + sdk.NewInt64Coin(denoms.NUSD, 5), ), /*shares=*/ 100, ), @@ -1099,26 +1099,26 @@ func TestMsgServerSwapAssets(t *testing.T) { { name: "not enough user funds - StableSwap", userInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1), + sdk.NewInt64Coin(denoms.NIBI, 1), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(common.DenomNIBI, 100), - tokenOutDenom: common.DenomNUSD, + tokenIn: sdk.NewInt64Coin(denoms.NIBI, 100), + tokenOutDenom: denoms.NUSD, expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1), + sdk.NewInt64Coin(denoms.NIBI, 1), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -1132,21 +1132,21 @@ func TestMsgServerSwapAssets(t *testing.T) { initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("foo", 100), - tokenOutDenom: denoms.DenomNUSD, + tokenOutDenom: denoms.NUSD, expectedUserFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("foo", 100), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -1155,26 +1155,26 @@ func TestMsgServerSwapAssets(t *testing.T) { { name: "invalid token out denom - StableSwap", userInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(common.DenomNIBI, 100), + tokenIn: sdk.NewInt64Coin(denoms.NIBI, 100), tokenOutDenom: "foo", expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -1183,26 +1183,26 @@ func TestMsgServerSwapAssets(t *testing.T) { { name: "same token in and token out denom - StableSwap", userInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(common.DenomNIBI, 100), - tokenOutDenom: common.DenomNIBI, + tokenIn: sdk.NewInt64Coin(denoms.NIBI, 100), + tokenOutDenom: denoms.NIBI, expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NIBI, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), diff --git a/x/dex/keeper/swap_test.go b/x/dex/keeper/swap_test.go index 4286bd58a..61cc57dc7 100644 --- a/x/dex/keeper/swap_test.go +++ b/x/dex/keeper/swap_test.go @@ -88,27 +88,27 @@ func TestSwapExactAmountIn(t *testing.T) { { name: "regular stableswap", userInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 10), + sdk.NewInt64Coin(denoms.USDC, 10), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.USDC, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(common.DenomUSDC, 10), - tokenOutDenom: common.DenomNUSD, - expectedTokenOut: sdk.NewInt64Coin(common.DenomNUSD, 10), + tokenIn: sdk.NewInt64Coin(denoms.USDC, 10), + tokenOutDenom: denoms.NUSD, + expectedTokenOut: sdk.NewInt64Coin(denoms.NUSD, 10), expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 10), + sdk.NewInt64Coin(denoms.NUSD, 10), ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 110), - sdk.NewInt64Coin(common.DenomNUSD, 90), + sdk.NewInt64Coin(denoms.USDC, 110), + sdk.NewInt64Coin(denoms.NUSD, 90), ), /*shares=*/ 100, ), @@ -123,21 +123,21 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 100), - tokenOutDenom: denoms.DenomNUSD, - expectedTokenOut: sdk.NewInt64Coin(denoms.DenomNUSD, 50), + tokenOutDenom: denoms.NUSD, + expectedTokenOut: sdk.NewInt64Coin(denoms.NUSD, 50), expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NUSD, 50), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 200), - sdk.NewInt64Coin(denoms.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NUSD, 50), ), /*shares=*/ 100, ), @@ -152,12 +152,12 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 100), - tokenOutDenom: denoms.DenomNUSD, + tokenOutDenom: denoms.NUSD, expectedUserFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("unibi", 1), ), @@ -165,7 +165,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -180,12 +180,12 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("foo", 100), - tokenOutDenom: denoms.DenomNUSD, + tokenOutDenom: denoms.NUSD, expectedUserFinalFunds: sdk.NewCoins( sdk.NewInt64Coin("foo", 100), ), @@ -193,7 +193,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -208,7 +208,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -221,7 +221,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -236,7 +236,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -249,7 +249,7 @@ func TestSwapExactAmountIn(t *testing.T) { /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(denoms.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), @@ -322,27 +322,27 @@ func TestDoubleSwapExactAmountIn(t *testing.T) { { name: "double stableswap", userInitialFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 10_000), + sdk.NewInt64Coin(denoms.USDC, 10_000), ), initialPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100_000_000), - sdk.NewInt64Coin(common.DenomNUSD, 100_000_000), + sdk.NewInt64Coin(denoms.USDC, 100_000_000), + sdk.NewInt64Coin(denoms.NUSD, 100_000_000), ), /*shares=*/ 100, ), - tokenIns: []sdk.Coin{sdk.NewInt64Coin(common.DenomUSDC, 10_000), sdk.NewInt64Coin("unusd", 10_000)}, - tokenOutDenoms: []string{common.DenomNUSD, common.DenomUSDC}, - expectedTokenOuts: []sdk.Coin{sdk.NewInt64Coin(common.DenomNUSD, 10_000), sdk.NewInt64Coin(common.DenomUSDC, 10_001)}, + tokenIns: []sdk.Coin{sdk.NewInt64Coin(denoms.USDC, 10_000), sdk.NewInt64Coin("unusd", 10_000)}, + tokenOutDenoms: []string{denoms.NUSD, denoms.USDC}, + expectedTokenOuts: []sdk.Coin{sdk.NewInt64Coin(denoms.NUSD, 10_000), sdk.NewInt64Coin(denoms.USDC, 10_001)}, expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 10_001), // TODO: fix https://github.com/NibiruChain/nibiru/issues/1152 + sdk.NewInt64Coin(denoms.USDC, 10_001), // TODO: fix https://github.com/NibiruChain/nibiru/issues/1152 ), expectedFinalPool: mock.DexStablePool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 99_999_999), - sdk.NewInt64Coin(common.DenomNUSD, 100_000_000), + sdk.NewInt64Coin(denoms.USDC, 99_999_999), + sdk.NewInt64Coin(denoms.NUSD, 100_000_000), ), /*shares=*/ 100, ), diff --git a/x/dex/simulation/operations.go b/x/dex/simulation/operations.go index 9585e35d1..f93ff6260 100644 --- a/x/dex/simulation/operations.go +++ b/x/dex/simulation/operations.go @@ -365,9 +365,9 @@ func genPoolAssets( func fundAccountWithTokens(ctx sdk.Context, address sdk.AccAddress, bk types.BankKeeper) { million := 1 * common.Precision newTokens := sdk.NewCoins( - sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(int64(10*million))), - sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(int64(10*million))), - sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(int64(10*million))), + sdk.NewCoin(denoms.NIBI, sdk.NewInt(int64(10*million))), + sdk.NewCoin(denoms.USDC, sdk.NewInt(int64(10*million))), + sdk.NewCoin(denoms.NUSD, sdk.NewInt(int64(10*million))), ) err := bk.MintCoins(ctx, types.ModuleName, newTokens) diff --git a/x/dex/types/params.go b/x/dex/types/params.go index f42de0e6e..6e0495e9f 100644 --- a/x/dex/types/params.go +++ b/x/dex/types/params.go @@ -31,11 +31,11 @@ func NewParams(startingPoolNumber uint64, poolCreationFee sdk.Coins, whitelisted func DefaultParams() Params { return Params{ StartingPoolNumber: 1, - PoolCreationFee: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1000*common.Precision)), // 1000 NIBI + PoolCreationFee: sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1000*common.Precision)), // 1000 NIBI WhitelistedAsset: []string{ - denoms.DenomNIBI, - denoms.DenomUSDC, - denoms.DenomNUSD, + denoms.NIBI, + denoms.USDC, + denoms.NUSD, }, } } diff --git a/x/oracle/keeper/ballot_test.go b/x/oracle/keeper/ballot_test.go index 1f35876b6..f897b5d6a 100644 --- a/x/oracle/keeper/ballot_test.go +++ b/x/oracle/keeper/ballot_test.go @@ -33,14 +33,14 @@ func TestOrganizeAggregate(t *testing.T) { staking.EndBlocker(ctx, input.StakingKeeper) btcBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[2], power), } ethBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[2], power), } for i := range btcBallot { @@ -79,11 +79,11 @@ func TestOrganizeAggregate(t *testing.T) { // sort each ballot for comparison sort.Sort(btcBallot) sort.Sort(ethBallot) - sort.Sort(ballotMap[common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)]) - sort.Sort(ballotMap[common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)]) + sort.Sort(ballotMap[common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)]) + sort.Sort(ballotMap[common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)]) - require.Equal(t, btcBallot, ballotMap[common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)]) - require.Equal(t, ethBallot, ballotMap[common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)]) + require.Equal(t, btcBallot, ballotMap[common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)]) + require.Equal(t, ethBallot, ballotMap[common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)]) } func TestClearBallots(t *testing.T) { @@ -104,14 +104,14 @@ func TestClearBallots(t *testing.T) { staking.EndBlocker(ctx, input.StakingKeeper) btcBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[2], power), } ethBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[2], power), } for i := range btcBallot { diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index 41e91c0db..61d550bbf 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -31,8 +31,8 @@ func TestParams(t *testing.T) { slashWindow := uint64(1000) minValidPerWindow := sdk.NewDecWithPrec(1, 4) whitelist := []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), } // Should really test validateParams, but skipping because obvious diff --git a/x/oracle/keeper/msg_server_test.go b/x/oracle/keeper/msg_server_test.go index da9a44e7c..59462b72d 100644 --- a/x/oracle/keeper/msg_server_test.go +++ b/x/oracle/keeper/msg_server_test.go @@ -20,7 +20,7 @@ func TestMsgServer_FeederDelegation(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate, }, } @@ -87,43 +87,43 @@ func TestMsgServer_AggregatePrevoteVote(t *testing.T) { salt := "1" exchangeRates := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } otherExchangeRate := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } unintendedExchangeRateStr := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { diff --git a/x/oracle/keeper/querier_test.go b/x/oracle/keeper/querier_test.go index 8b4f2644f..64ca94fd1 100644 --- a/x/oracle/keeper/querier_test.go +++ b/x/oracle/keeper/querier_test.go @@ -32,7 +32,7 @@ func TestQueryExchangeRate(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) // empty request _, err := querier.ExchangeRate(ctx, nil) @@ -40,7 +40,7 @@ func TestQueryExchangeRate(t *testing.T) { // Query to grpc res, err := querier.ExchangeRate(ctx, &types.QueryExchangeRateRequest{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), }) require.NoError(t, err) require.Equal(t, rate, res.ExchangeRate) @@ -72,15 +72,15 @@ func TestQueryExchangeRates(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) res, err := querier.ExchangeRates(ctx, &types.QueryExchangeRatesRequest{}) require.NoError(t, err) require.Equal(t, types.ExchangeRateTuples{ - {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: rate}, - {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: rate}, + {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: rate}, + {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: rate}, }, res.ExchangeRates) } @@ -90,12 +90,12 @@ func TestQueryExchangeRateTwap(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.SetPrice(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), rate) + input.OracleKeeper.SetPrice(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) - _, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)}) + _, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)}) require.Error(t, err) - res, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)}) + res, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}) require.NoError(t, err) require.Equal(t, sdk.MustNewDecFromStr("1700"), res.ExchangeRate) } @@ -115,25 +115,25 @@ func TestCalcTwap(t *testing.T) { // expected price: (9.5 * (35 - 30) + 8.5 * (30 - 20) + 9.0 * (20 - 5)) / 30 = 8.916666 { name: "spot price twap calc, t=(5,35]", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), priceSnapshots: []types.PriceSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("90000.0"), TimestampMs: time.UnixMilli(1).UnixMilli(), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("9.0"), TimestampMs: time.UnixMilli(10).UnixMilli(), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("8.5"), TimestampMs: time.UnixMilli(20).UnixMilli(), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("9.5"), TimestampMs: time.UnixMilli(30).UnixMilli(), }, @@ -167,12 +167,12 @@ func TestCalcTwap(t *testing.T) { ctx = ctx.WithBlockTime(time.UnixMilli(0)) for _, reserve := range tc.priceSnapshots { ctx = ctx.WithBlockTime(time.UnixMilli(reserve.TimestampMs)) - input.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), reserve.Price) + input.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserve.Price) } ctx = ctx.WithBlockTime(tc.currentBlockTime).WithBlockHeight(tc.currentBlockHeight) - price, err := querier.ExchangeRateTwap(sdk.WrapSDKContext(ctx), &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)}) + price, err := querier.ExchangeRateTwap(sdk.WrapSDKContext(ctx), &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}) require.NoError(t, err) require.EqualValuesf(t, tc.expectedPrice, price.ExchangeRate, @@ -187,17 +187,17 @@ func TestQueryActives(t *testing.T) { queryClient := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) res, err := queryClient.Actives(ctx, &types.QueryActivesRequest{}) require.NoError(t, err) targetPairs := []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), } require.Equal(t, targetPairs, res.Actives) diff --git a/x/oracle/keeper/reward_test.go b/x/oracle/keeper/reward_test.go index f0a12d352..eb6ae3fbe 100644 --- a/x/oracle/keeper/reward_test.go +++ b/x/oracle/keeper/reward_test.go @@ -58,7 +58,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { valPeriodicRewards := sdk.NewDecCoinsFromCoins(rewards). QuoDec(sdk.NewDec(int64(periods))). QuoDec(sdk.NewDec(int64(validators))) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), sdk.NewCoins(rewards), periods) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(rewards), periods) for i := uint64(1); i <= periods; i++ { for valIndex := 0; valIndex < validators; valIndex++ { @@ -66,7 +66,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { // passes the current context block height for pre vote // then changes the height to current height + vote period for the vote makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{ - Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate, }}, valIndex) } @@ -83,8 +83,8 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { } // assert there are no rewards for pair - require.True(t, input.OracleKeeper.GatherRewardsForVotePeriod(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)).IsZero()) + require.True(t, input.OracleKeeper.GatherRewardsForVotePeriod(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)).IsZero()) // assert that there are no rewards instances - require.Empty(t, input.OracleKeeper.PairRewards.Indexes.RewardsByPair.ExactMatch(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)).PrimaryKeys()) + require.Empty(t, input.OracleKeeper.PairRewards.Indexes.RewardsByPair.ExactMatch(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)).PrimaryKeys()) } diff --git a/x/oracle/keeper/slash_test.go b/x/oracle/keeper/slash_test.go index b3b1d43a9..fb977abb2 100644 --- a/x/oracle/keeper/slash_test.go +++ b/x/oracle/keeper/slash_test.go @@ -91,9 +91,9 @@ func TestSlashAndResetMissCounters(t *testing.T) { func TestInvalidVotesSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) votePeriodsPerWindow := types.NewDec(int64(input.OracleKeeper.SlashWindow(input.Ctx))).QuoInt64(int64(input.OracleKeeper.VotePeriod(input.Ctx))).TruncateInt64() slashFraction := input.OracleKeeper.SlashFraction(input.Ctx) @@ -103,13 +103,13 @@ func TestInvalidVotesSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, miss vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, i+1, input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[1], 0)) @@ -120,13 +120,13 @@ func TestInvalidVotesSlashing(t *testing.T) { // one more miss vote will inccur keeper.ValAddrs[1] slashing // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, miss vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) input.Ctx = input.Ctx.WithBlockHeight(votePeriodsPerWindow - 1) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -145,9 +145,9 @@ func TestWhitelistSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, i+1, input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[0], 0)) @@ -159,9 +159,9 @@ func TestWhitelistSlashing(t *testing.T) { // one more miss vote will inccur Account 1 slashing // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) input.Ctx = input.Ctx.WithBlockHeight(votePeriodsPerWindow - 1) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -172,19 +172,19 @@ func TestWhitelistSlashing(t *testing.T) { func TestNotPassedBallotSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[0], 0)) @@ -195,14 +195,14 @@ func TestNotPassedBallotSlashing(t *testing.T) { func TestAbstainSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) votePeriodsPerWindow := types.NewDec(int64(input.OracleKeeper.SlashWindow(input.Ctx))).QuoInt64(int64(input.OracleKeeper.VotePeriod(input.Ctx))).TruncateInt64() minValidPerWindow := input.OracleKeeper.MinValidPerWindow(input.Ctx) @@ -211,13 +211,13 @@ func TestAbstainSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, abstain vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: types.ZeroDec()}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: types.ZeroDec()}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[1], 0)) diff --git a/x/oracle/keeper/tally_fuzz_test.go b/x/oracle/keeper/tally_fuzz_test.go index 2ddf7893f..75bc5fec2 100644 --- a/x/oracle/keeper/tally_fuzz_test.go +++ b/x/oracle/keeper/tally_fuzz_test.go @@ -133,11 +133,11 @@ func TestRemoveInvalidBallots(t *testing.T) { "x": types.ExchangeRateBallots{ {Pair: "x", ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD): types.ExchangeRateBallots{ - {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD): types.ExchangeRateBallots{ + {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD): types.ExchangeRateBallots{ - {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD): types.ExchangeRateBallots{ + {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, }, }, diff --git a/x/oracle/keeper/test_utils.go b/x/oracle/keeper/test_utils.go index fbbd76c86..ba5ec30cf 100644 --- a/x/oracle/keeper/test_utils.go +++ b/x/oracle/keeper/test_utils.go @@ -112,7 +112,7 @@ var ( } InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction) - InitCoins = sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, InitTokens)) + InitCoins = sdk.NewCoins(sdk.NewCoin(denoms.NIBI, InitTokens)) OracleDecPrecision = 8 ) @@ -176,7 +176,7 @@ func CreateTestInput(t *testing.T) TestInput { accountKeeper := authkeeper.NewAccountKeeper(appCodec, keyAcc, paramsKeeper.Subspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms) bankKeeper := bankkeeper.NewBaseKeeper(appCodec, keyBank, accountKeeper, paramsKeeper.Subspace(banktypes.ModuleName), blackListAddrs) - totalSupply := sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, InitTokens.MulRaw(int64(len(Addrs)*10)))) + totalSupply := sdk.NewCoins(sdk.NewCoin(denoms.NIBI, InitTokens.MulRaw(int64(len(Addrs)*10)))) bankKeeper.MintCoins(ctx, faucetAccountName, totalSupply) stakingKeeper := stakingkeeper.NewKeeper( @@ -188,7 +188,7 @@ func CreateTestInput(t *testing.T) TestInput { ) stakingParams := stakingtypes.DefaultParams() - stakingParams.BondDenom = denoms.DenomNIBI + stakingParams.BondDenom = denoms.NIBI stakingKeeper.SetParams(ctx, stakingParams) distrKeeper := distrkeeper.NewKeeper( @@ -211,7 +211,7 @@ func CreateTestInput(t *testing.T) TestInput { distrAcc := authtypes.NewEmptyModuleAccount(distrtypes.ModuleName) oracleAcc := authtypes.NewEmptyModuleAccount(types.ModuleName, authtypes.Minter) - bankKeeper.SendCoinsFromModuleToModule(ctx, faucetAccountName, stakingtypes.NotBondedPoolName, sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, InitTokens.MulRaw(int64(len(Addrs)))))) + bankKeeper.SendCoinsFromModuleToModule(ctx, faucetAccountName, stakingtypes.NotBondedPoolName, sdk.NewCoins(sdk.NewCoin(denoms.NIBI, InitTokens.MulRaw(int64(len(Addrs)))))) accountKeeper.SetModuleAccount(ctx, feeCollectorAcc) accountKeeper.SetModuleAccount(ctx, bondPool) @@ -250,7 +250,7 @@ func CreateTestInput(t *testing.T) TestInput { func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator { commission := stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) msg, _ := stakingtypes.NewMsgCreateValidator( - address, pubKey, sdk.NewCoin(denoms.DenomNIBI, amt), + address, pubKey, sdk.NewCoin(denoms.NIBI, amt), stakingtypes.Description{}, commission, sdk.OneInt(), ) diff --git a/x/oracle/keeper/update_exchange_rates_test.go b/x/oracle/keeper/update_exchange_rates_test.go index 85053cc04..f8e9744da 100644 --- a/x/oracle/keeper/update_exchange_rates_test.go +++ b/x/oracle/keeper/update_exchange_rates_test.go @@ -24,7 +24,7 @@ import ( func TestOracleThreshold(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate, }, } @@ -121,15 +121,15 @@ func TestOracleThreshold(t *testing.T) { func TestOracleDrop(t *testing.T) { input, h := setup(t) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), randomExchangeRate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), randomExchangeRate) // Account 1, pair gov stable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Immediately swap halt after an illiquid oracle vote oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) require.Error(t, err) } @@ -143,7 +143,7 @@ func TestOracleTally(t *testing.T) { for i, rate := range rates { decExchangeRate := sdk.NewDecWithPrec(int64(rate*math.Pow10(keeper.OracleDecPrecision)), int64(keeper.OracleDecPrecision)) exchangeRateStr, err := types.ExchangeRateTuples{ - {ExchangeRate: decExchangeRate, Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)}}.ToString() + {ExchangeRate: decExchangeRate, Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}}.ToString() require.NoError(t, err) salt := fmt.Sprintf("%d", i) @@ -162,7 +162,7 @@ func TestOracleTally(t *testing.T) { } vote := types.NewExchangeRateBallot( - decExchangeRate, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), valAddrs[i], power) + decExchangeRate, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddrs[i], power) ballot = append(ballot, vote) // change power of every three validator @@ -222,7 +222,7 @@ func TestOracleTallyTiming(t *testing.T) { // all the keeper.Addrs vote for the block ... not last period block yet, so tally fails for i := range keeper.Addrs[:2] { - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, i) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, i) } params := input.OracleKeeper.GetParams(input.Ctx) @@ -231,13 +231,13 @@ func TestOracleTallyTiming(t *testing.T) { require.Equal(t, 0, int(input.Ctx.BlockHeight())) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.Error(t, err) input.Ctx = input.Ctx.WithBlockHeight(int64(params.VotePeriod - 1)) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err = input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + _, err = input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) } @@ -247,13 +247,13 @@ func TestOracleRewardDistribution(t *testing.T) { input, h := setup(t) // Account 1, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) rewardAllocation := sdk.NewCoins(sdk.NewCoin("reward", sdk.NewInt(1*common.Precision))) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), rewardAllocation, 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rewardAllocation, 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -261,32 +261,32 @@ func TestOracleRewardDistribution(t *testing.T) { distributionRewards := input.DistrKeeper.GetValidatorOutstandingRewards(input.Ctx.WithBlockHeight(2), keeper.ValAddrs[0]) require.Equalf(t, expectedRewardOneVal, distributionRewards.Rewards, "%s<=>%s", expectedRewardOneVal.String(), distributionRewards.String()) distributionRewards = input.DistrKeeper.GetValidatorOutstandingRewards(input.Ctx.WithBlockHeight(2), keeper.ValAddrs[1]) - require.Equal(t, expectedRewardOneVal, distributionRewards.Rewards, "%s %s", expectedRewardOneVal.String(), distributionRewards.Rewards.AmountOf(denoms.DenomNIBI).TruncateInt().String()) + require.Equal(t, expectedRewardOneVal, distributionRewards.Rewards, "%s %s", expectedRewardOneVal.String(), distributionRewards.Rewards.AmountOf(denoms.NIBI).TruncateInt().String()) } func TestOracleRewardBand(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear pairs to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) rewardSpread := randomExchangeRate.Mul(input.OracleKeeper.RewardBand(input.Ctx).QuoInt64(2)) // no one will miss the vote // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread)}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread)}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -296,13 +296,13 @@ func TestOracleRewardBand(t *testing.T) { // Account 1 will miss the vote due to raward band condition // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread.Add(sdk.OneDec()))}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread.Add(sdk.OneDec()))}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -326,7 +326,7 @@ func TestOracleMultiRewardDistribution(t *testing.T) { makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.PairBTCStable.String(), ExchangeRate: randomExchangeRate}}, 2) rewardAmt := sdk.NewInt(100000000) - err := input.BankKeeper.MintCoins(input.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(denoms.DenomGov, rewardAmt))) + err := input.BankKeeper.MintCoins(input.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(denoms.Gov, rewardAmt))) require.NoError(t, err) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -338,11 +338,11 @@ func TestOracleMultiRewardDistribution(t *testing.T) { expectedRewardAmt3 := sdk.NewDecFromInt(rewardAmt.QuoRaw(3)).QuoInt64(int64(rewardDistributedWindow)).TruncateInt() rewards := input.DistrKeeper.GetValidatorOutstandingRewards(input.Ctx.WithBlockHeight(2), keeper.ValAddrs[0]) - require.Equal(t, expectedRewardAmt, rewards.Rewards.AmountOf(denoms.DenomGov).TruncateInt()) + require.Equal(t, expectedRewardAmt, rewards.Rewards.AmountOf(denoms.Gov).TruncateInt()) rewards = input.DistrKeeper.GetValidatorOutstandingRewards(input.Ctx.WithBlockHeight(2), keeper.ValAddrs[1]) - require.Equal(t, expectedRewardAmt2, rewards.Rewards.AmountOf(denoms.DenomGov).TruncateInt()) + require.Equal(t, expectedRewardAmt2, rewards.Rewards.AmountOf(denoms.Gov).TruncateInt()) rewards = input.DistrKeeper.GetValidatorOutstandingRewards(input.Ctx.WithBlockHeight(2), keeper.ValAddrs[2]) - require.Equal(t, expectedRewardAmt3, rewards.Rewards.AmountOf(denoms.DenomGov).TruncateInt()) + require.Equal(t, expectedRewardAmt3, rewards.Rewards.AmountOf(denoms.Gov).TruncateInt()) } */ @@ -356,19 +356,19 @@ func TestOracleExchangeRate(t *testing.T) { // govstable has been chosen as referenceExchangeRate by highest voting power // Account 1, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}}, 0) // Account 2, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}}, 1) // Account 3, govstable, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), sdk.NewCoins(govStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), sdk.NewCoins(ethStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -404,13 +404,13 @@ func TestOracleEnsureSorted(t *testing.T) { ethStableRate3 := sdk.NewDec(int64(rand.Uint64() % 100000000)) // Account 1, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableRate1}, {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate1}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate1}, {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 0) // Account 2, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate2}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}}, 1) // Account 3, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: govStableRate3}, {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: ethStableRate3}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: govStableRate3}, {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: ethStableRate3}}, 2) require.NotPanics(t, func() { oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -428,31 +428,31 @@ func TestOracleExchangeRateVal5(t *testing.T) { // govstable has been chosen as reference pair by highest voting power // Account 1, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate1}, {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableRate1}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}, {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate1}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate1}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate1}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 2) // Account 4, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableRate2}}, 3) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}}, 3) // Account 5, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: ethStableRate2}}, 4) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}}, 4) ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), sdk.NewCoins(govStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), sdk.NewCoins(ethStableRewards), 1) + keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) - gotGovStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + gotGovStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) require.NoError(t, err) - gotEthStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)) + gotEthStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)) require.NoError(t, err) require.Equal(t, govStableRate1, gotGovStableRate) @@ -486,15 +486,15 @@ func TestWhitelistedPairs(t *testing.T) { for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) // govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) // set btcstable for next vote period - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -504,15 +504,15 @@ func TestWhitelistedPairs(t *testing.T) { require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[2], 0)) // whitelisted pairs are {govstable, btcstable} - require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) + require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) // govstable, missing btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) // delete btcstable for next vote period - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} + params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -521,13 +521,13 @@ func TestWhitelistedPairs(t *testing.T) { require.Equal(t, uint64(1), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[2], 0)) // btcstable must be deleted - require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) - require.False(t, input.OracleKeeper.WhitelistedPairs.Has(input.Ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD))) + require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) + require.False(t, input.OracleKeeper.WhitelistedPairs.Has(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD))) // govstable, no missing - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -543,11 +543,11 @@ func TestAbstainWithSmallStakingPower(t *testing.T) { for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: sdk.ZeroDec()}}, 0) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.ZeroDec()}}, 0) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) require.Error(t, err) } diff --git a/x/oracle/simulation/decoder_test.go b/x/oracle/simulation/decoder_test.go index b27b04644..acbf05837 100644 --- a/x/oracle/simulation/decoder_test.go +++ b/x/oracle/simulation/decoder_test.go @@ -35,8 +35,8 @@ func TestDecodeDistributionStore(t *testing.T) { aggregatePrevote := types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash([]byte("12345")), valAddr, 123) aggregateVote := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{ - {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: sdk.NewDecWithPrec(1234, 1)}, - {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: sdk.NewDecWithPrec(4321, 1)}, + {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDecWithPrec(1234, 1)}, + {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDecWithPrec(4321, 1)}, }, valAddr) pair := "btc:usd" diff --git a/x/oracle/simulation/genesis.go b/x/oracle/simulation/genesis.go index 5eebf0e1c..78e90b50b 100644 --- a/x/oracle/simulation/genesis.go +++ b/x/oracle/simulation/genesis.go @@ -98,17 +98,17 @@ func RandomizedGenState(simState *module.SimulationState) { VoteThreshold: voteThreshold, RewardBand: rewardBand, Whitelist: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), }, SlashFraction: slashFraction, SlashWindow: slashWindow, MinValidPerWindow: minValidPerWindow, }, []types.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(20_000)}, + {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(20_000)}, }, []types.FeederDelegation{}, []types.MissCounter{}, diff --git a/x/oracle/simulation/operations.go b/x/oracle/simulation/operations.go index a30e6a516..1da44e250 100644 --- a/x/oracle/simulation/operations.go +++ b/x/oracle/simulation/operations.go @@ -31,7 +31,7 @@ const ( ) var ( - whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)} + whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} voteHashMap map[string]string = make(map[string]string) ) diff --git a/x/oracle/types/ballot_test.go b/x/oracle/types/ballot_test.go index 7ad4b99a1..27c2aa1c0 100644 --- a/x/oracle/types/ballot_test.go +++ b/x/oracle/types/ballot_test.go @@ -31,21 +31,21 @@ func TestToMap(t *testing.T) { { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(1600), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.ZeroDec(), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(1500), Power: 100, }, @@ -95,15 +95,15 @@ func TestToCrossRate(t *testing.T) { for _, data := range data { valAddr := sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()) if !data.base.IsZero() { - pbBase = append(pbBase, types.NewExchangeRateBallot(data.base, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), valAddr, 100)) + pbBase = append(pbBase, types.NewExchangeRateBallot(data.base, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) } - pbQuote = append(pbQuote, types.NewExchangeRateBallot(data.quote, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), valAddr, 100)) + pbQuote = append(pbQuote, types.NewExchangeRateBallot(data.quote, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) if !data.base.IsZero() && !data.quote.IsZero() { - cb = append(cb, types.NewExchangeRateBallot(data.base.Quo(data.quote), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), valAddr, 100)) + cb = append(cb, types.NewExchangeRateBallot(data.base.Quo(data.quote), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) } else { - cb = append(cb, types.NewExchangeRateBallot(sdk.ZeroDec(), common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), valAddr, 0)) + cb = append(cb, types.NewExchangeRateBallot(sdk.ZeroDec(), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 0)) } } @@ -135,7 +135,7 @@ func TestPBPower(t *testing.T) { power := sk.Validator(ctx, valAccAddrs[i]).GetConsensusPower(sdk.DefaultPowerReduction) vote := types.NewExchangeRateBallot( sdk.ZeroDec(), - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), valAccAddrs[i], power, ) @@ -154,7 +154,7 @@ func TestPBPower(t *testing.T) { faceValAddr := sdk.ValAddress(pubKey.Address()) fakeVote := types.NewExchangeRateBallot( sdk.OneDec(), - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), faceValAddr, 0, ) @@ -225,7 +225,7 @@ func TestPBWeightedMedian(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDec(int64(input)), - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), valAddr, power, ) @@ -292,7 +292,7 @@ func TestPBStandardDeviation(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDecWithPrec(int64(input*base), int64(types.OracleDecPrecision)), - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), valAddr, power, ) @@ -311,12 +311,12 @@ func TestPBStandardDeviationOverflow(t *testing.T) { pb := types.ExchangeRateBallots{types.NewExchangeRateBallot( sdk.ZeroDec(), - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), valAddr, 2, ), types.NewExchangeRateBallot( exchangeRate, - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), valAddr, 1, )} diff --git a/x/oracle/types/msgs_test.go b/x/oracle/types/msgs_test.go index ab006bcbb..f85ebfd85 100644 --- a/x/oracle/types/msgs_test.go +++ b/x/oracle/types/msgs_test.go @@ -43,7 +43,7 @@ func TestMsgAggregateExchangeRatePrevote(t *testing.T) { sdk.AccAddress([]byte("addr1_______________")), } - exchangeRates := sdk.DecCoins{sdk.NewDecCoinFromDec(denoms.DenomUSDC, sdk.OneDec()), sdk.NewDecCoinFromDec(denoms.DenomNUSD, sdk.NewDecWithPrec(32121, 1))} + exchangeRates := sdk.DecCoins{sdk.NewDecCoinFromDec(denoms.USDC, sdk.OneDec()), sdk.NewDecCoinFromDec(denoms.NUSD, sdk.NewDecWithPrec(32121, 1))} bz := types.GetAggregateVoteHash("1", exchangeRates.String(), sdk.ValAddress(addrs[0])) tests := []struct { diff --git a/x/oracle/types/params.go b/x/oracle/types/params.go index 2c355cc87..65061fe1b 100644 --- a/x/oracle/types/params.go +++ b/x/oracle/types/params.go @@ -39,10 +39,10 @@ var ( DefaultVoteThreshold = sdk.NewDecWithPrec(50, 2) // 50% DefaultRewardBand = sdk.NewDecWithPrec(2, 2) // 2% (-1, 1) DefaultWhitelist = []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), } DefaultSlashFraction = sdk.NewDecWithPrec(1, 4) // 0.01% DefaultMinValidPerWindow = sdk.NewDecWithPrec(5, 2) // 5% diff --git a/x/perp/client/cli/cli_test.go b/x/perp/client/cli/cli_test.go index 985333cdf..6181d6d54 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -52,7 +52,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -64,7 +64,7 @@ func (s *IntegrationTestSuite) SetupSuite() { }, }, { - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -82,11 +82,11 @@ func (s *IntegrationTestSuite) SetupSuite() { perpGenesis := perptypes.DefaultGenesis() perpGenesis.PairMetadata = []perptypes.PairMetadata{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, } @@ -95,12 +95,12 @@ func (s *IntegrationTestSuite) SetupSuite() { oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.Params.Whitelist = []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), } oracleGenesis.Params.VotePeriod = 1_000 oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(20_000)}, - {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(2_000)}, + {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(20_000)}, + {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDec(2_000)}, } genesisState[oracletypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(oracleGenesis) @@ -124,56 +124,56 @@ func (s *IntegrationTestSuite) SetupSuite() { s.NoError( testutilcli.FillWalletFromValidator(user1, sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 10*common.Precision), - sdk.NewInt64Coin(denoms.DenomUSDC, 10*common.Precision), - sdk.NewInt64Coin(denoms.DenomNUSD, 50*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 10*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 10*common.Precision), + sdk.NewInt64Coin(denoms.NUSD, 50*common.Precision), ), val, - denoms.DenomNIBI, + denoms.NIBI, ), ) s.NoError( testutilcli.FillWalletFromValidator(user2, sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1000), - sdk.NewInt64Coin(denoms.DenomUSDC, 1000), - sdk.NewInt64Coin(denoms.DenomNUSD, 100000), + sdk.NewInt64Coin(denoms.NIBI, 1000), + sdk.NewInt64Coin(denoms.USDC, 1000), + sdk.NewInt64Coin(denoms.NUSD, 100000), ), val, - denoms.DenomNIBI, + denoms.NIBI, ), ) s.NoError( testutilcli.FillWalletFromValidator(user3, sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1000), - sdk.NewInt64Coin(denoms.DenomUSDC, 1000), - sdk.NewInt64Coin(denoms.DenomNUSD, 49*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 1000), + sdk.NewInt64Coin(denoms.USDC, 1000), + sdk.NewInt64Coin(denoms.NUSD, 49*common.Precision), ), val, - denoms.DenomNIBI, + denoms.NIBI, ), ) s.NoError( testutilcli.FillWalletFromValidator(user4, sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1000), - sdk.NewInt64Coin(denoms.DenomUSDC, 1000), - sdk.NewInt64Coin(denoms.DenomNUSD, 100000), + sdk.NewInt64Coin(denoms.NIBI, 1000), + sdk.NewInt64Coin(denoms.USDC, 1000), + sdk.NewInt64Coin(denoms.NUSD, 100000), ), val, - denoms.DenomNIBI, + denoms.NIBI, ), ) s.NoError( testutilcli.FillWalletFromValidator(user5, - sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1000)), + sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1000)), val, - denoms.DenomNIBI, + denoms.NIBI, ), ) } @@ -187,25 +187,25 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { val := s.network.Validators[0] user := s.users[0] - exchangeRate, err := testutilcli.QueryOracleExchangeRate(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + exchangeRate, err := testutilcli.QueryOracleExchangeRate(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) s.T().Logf("0. current exchange rate is: %+v", exchangeRate) s.NoError(err) s.T().Log("A. check vpool balances") - reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.NewDec(10*common.Precision), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_000*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("A. check trader has no existing positions") - _, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) + _, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.Error(err) s.T().Log("B. open position") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "buy", - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAssetLimit */ "1"}, @@ -214,18 +214,18 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("B. check vpool balance after open position") - reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("9999833.336111064815586407"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_001*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("B. check trader position") - queryResp, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) + queryResp, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("166.663888935184413593"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.OpenNotional) @@ -237,7 +237,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("C. open position with 2x leverage and zero baseAmtLimit") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "buy", - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "2", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAmtLimit */ "0", @@ -246,11 +246,11 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("C. check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.975001249937503125"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(3*common.Precision), queryResp.Position.OpenNotional) @@ -261,7 +261,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("D. Open a reverse position smaller than the existing position") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "sell", - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "100", // 100 uNUSD /* baseAssetLimit */ "1", @@ -270,18 +270,18 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("D. Check vpool after opening reverse position") - reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) s.NoError(err) s.T().Logf(" \n reserve assets: %+v \n", reserveAssets) s.EqualValues(sdk.MustNewDecFromStr("9999500.041663750215262154"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_002_999_900), reserveAssets.QuoteAssetReserve) s.T().Log("D. Check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.958336249784737846"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(2_999_900), queryResp.Position.OpenNotional) @@ -292,7 +292,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("E. Open a reverse position larger than the existing position") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "sell", - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "4000000", // 4*10^6 uNUSD /* baseAssetLimit */ "0", @@ -301,11 +301,11 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("E. Check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), queryResp.Position.Pair) + s.EqualValues(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("-166.686111713005402945"), queryResp.Position.Size_) s.EqualValues(sdk.MustNewDecFromStr("1000100.000000000000000494"), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("1000100.000000000000000494"), queryResp.Position.Margin) @@ -316,13 +316,13 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("F. Close position") txResp, err = testutilcli.ExecTx(s.network, cli.ClosePositionCmd(), user, []string{ - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), }) s.NoError(err) s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("F. check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.Error(err) s.T().Logf("query response: %+v", queryResp) @@ -336,12 +336,12 @@ func (s *IntegrationTestSuite) TestPositionEmptyAndClose() { user := s.users[0] // verify trader has no position (empty) - _, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), user) + _, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), user) s.Error(err, "no position found") // close position should produce error _, err = testutilcli.ExecTx(s.network, cli.ClosePositionCmd(), user, []string{ - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) } @@ -350,7 +350,7 @@ func (s *IntegrationTestSuite) TestQueryCumulativePremiumFractions() { val := s.network.Validators[0] s.T().Log("get cumulative funding payments") - queryResp, err := testutilcli.QueryCumulativePremiumFraction(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + queryResp, err := testutilcli.QueryCumulativePremiumFraction(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) s.NoError(err) s.EqualValues(sdk.NewDec(2), queryResp.CumulativePremiumFraction) } @@ -360,7 +360,7 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { s.T().Log("opening a position with user 0") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[0], []string{ "buy", - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), "10", // Leverage "1", // Quote asset amount "0.0000001", @@ -371,15 +371,15 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { // Remove margin to trigger bad debt on user 0 s.T().Log("removing margin on user 0....") _, err = testutilcli.ExecTx(s.network, cli.RemoveMarginCmd(), s.users[0], []string{ - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), - fmt.Sprintf("%s%s", "100", denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + fmt.Sprintf("%s%s", "100", denoms.NUSD), }) s.Contains(err.Error(), perptypes.ErrFailedRemoveMarginCanCauseBadDebt.Error()) } func (s *IntegrationTestSuite) TestX_AddMargin() { val := s.network.Validators[0] - pair := common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD) // Open a new position s.T().Log("opening a position with user 3....") @@ -411,7 +411,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { { name: "FAIL: position not found", args: []string{ - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), fmt.Sprintf("%s%s", "10000", pair.QuoteDenom()), }, expectedCode: 1, @@ -438,7 +438,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidate a position that does not exist") _, err := testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), s.users[1].String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) @@ -446,7 +446,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("opening a position with user 1....") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[1], []string{ "buy", - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), "15", // Leverage "90000", // Quote asset amount "0", @@ -456,7 +456,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidate a position that is above maintenance margin mario") _, err = testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), s.users[1].String(), }) s.Contains(err.Error(), "margin ratio is too healthy to liquidate") @@ -464,7 +464,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("opening a position with user 2...") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[2], []string{ "sell", - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), "15", // Leverage "45000000", // Quote asset amount "0", @@ -480,7 +480,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidating user 1...") txResp, err = testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD).String(), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), s.users[1].String(), }) s.NoError(err) diff --git a/x/perp/genesis_test.go b/x/perp/genesis_test.go index e367ad018..7ca77b10a 100644 --- a/x/perp/genesis_test.go +++ b/x/perp/genesis_test.go @@ -40,9 +40,9 @@ func TestGenesis(t *testing.T) { // create some positions for i := int64(0); i < 100; i++ { addr := testutil.AccAddress() - app.PerpKeeper.Positions.Insert(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), addr), types.Position{ + app.PerpKeeper.Positions.Insert(ctx, collections.Join(common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), addr), types.Position{ TraderAddress: addr.String(), - Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), Size_: sdk.NewDec(i + 1), Margin: sdk.NewDec(i * 2), OpenNotional: sdk.NewDec(i * 100), diff --git a/x/perp/keeper/calc_test.go b/x/perp/keeper/calc_test.go index b35407826..73236a643 100644 --- a/x/perp/keeper/calc_test.go +++ b/x/perp/keeper/calc_test.go @@ -29,7 +29,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { marginDelta := sdk.OneDec() _, err := nibiruApp.PerpKeeper.CalcRemainMarginWithFundingPayment( ctx, types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), }, marginDelta) require.ErrorIs(t, err, collections.ErrNotFound) }, diff --git a/x/perp/keeper/calc_unit_test.go b/x/perp/keeper/calc_unit_test.go index e0ff458dc..b7f9c1785 100644 --- a/x/perp/keeper/calc_unit_test.go +++ b/x/perp/keeper/calc_unit_test.go @@ -38,9 +38,9 @@ func TestCalcFreeCollateralErrors(t *testing.T) { test: func() { k, mocks, ctx := getKeeper(t) - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(false) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false) - pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), testutil.AccAddress()) + pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) _, err := k.calcFreeCollateral(ctx, pos) @@ -54,12 +54,12 @@ func TestCalcFreeCollateralErrors(t *testing.T) { k, mocks, ctx := getKeeper(t) mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true) + ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), testutil.AccAddress()) + pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) freeCollateral, err := k.calcFreeCollateral(ctx, pos) @@ -151,7 +151,7 @@ func TestCalcFreeCollateralSuccess(t *testing.T) { pos := types.Position{ TraderAddress: testutil.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.positionSize, Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(1000), @@ -160,19 +160,19 @@ func TestCalcFreeCollateralSuccess(t *testing.T) { } t.Log("mock vpool keeper") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.vpoolDirection, sdk.OneDec(), ).Return(tc.positionNotional, nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.vpoolDirection, sdk.OneDec(), 15*time.Minute, @@ -197,13 +197,13 @@ func TestGetLatestCumulativePremiumFraction(t *testing.T) { keeper, _, ctx := getKeeper(t) metadata := &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), } setPairMetadata(keeper, ctx, *metadata) latestCumulativePremiumFraction, err := keeper. - getLatestCumulativePremiumFraction(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + getLatestCumulativePremiumFraction(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) require.NoError(t, err) assert.Equal(t, sdk.NewDec(2), latestCumulativePremiumFraction) diff --git a/x/perp/keeper/clearing_house_integration_test.go b/x/perp/keeper/clearing_house_integration_test.go index 417ab87f9..3d7d9dbb9 100644 --- a/x/perp/keeper/clearing_house_integration_test.go +++ b/x/perp/keeper/clearing_house_integration_test.go @@ -45,7 +45,7 @@ func TestOpenPositionSuccess(t *testing.T) { }{ { name: "new long position", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), initialPosition: nil, side: types.Side_BUY, margin: sdk.NewInt(1000), @@ -62,9 +62,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing long position, go more long", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -86,9 +86,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing long position, decrease a bit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 10)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 10)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -110,9 +110,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing long position, decrease a lot", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1060)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1060)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -134,7 +134,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "new long position just under fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1*common.Precision*common.Precision)), initialPosition: nil, side: types.Side_BUY, margin: sdk.NewInt(47_619_047_619), @@ -151,7 +151,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "new short position", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), initialPosition: nil, side: types.Side_SELL, margin: sdk.NewInt(1000), @@ -168,9 +168,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing short position, go more short", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -192,9 +192,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing short position, decrease a bit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 10)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 10)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -216,9 +216,9 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "existing short position, decrease a lot", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1060)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1060)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -240,7 +240,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "new short position just under fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1*common.Precision*common.Precision)), initialPosition: nil, side: types.Side_SELL, margin: sdk.NewInt(47_619_047_619), @@ -268,7 +268,7 @@ func TestOpenPositionSuccess(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision*common.Precision), vpooltypes.VpoolConfig{ @@ -280,7 +280,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -295,11 +295,11 @@ func TestOpenPositionSuccess(t *testing.T) { } ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(time.Second * 5)) - resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) + resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) require.NoError(t, err) t.Log("assert position response") - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), resp.Position.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), resp.Position.Pair) assert.EqualValues(t, traderAddr.String(), resp.Position.TraderAddress) assert.EqualValues(t, tc.expectedMargin, resp.Position.Margin, "margin") assert.EqualValues(t, tc.expectedOpenNotional, resp.Position.OpenNotional, "open notional") @@ -316,9 +316,9 @@ func TestOpenPositionSuccess(t *testing.T) { assert.EqualValues(t, tc.expectedPositionNotional, resp.PositionNotional) t.Log("assert position in state") - position, err := nibiruApp.PerpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr)) + position, err := nibiruApp.PerpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.NoError(t, err) - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), position.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), position.Pair) assert.EqualValues(t, traderAddr.String(), position.TraderAddress) assert.EqualValues(t, tc.expectedMargin, position.Margin, "margin") assert.EqualValues(t, tc.expectedOpenNotional, position.OpenNotional, "open notional") @@ -331,19 +331,19 @@ func TestOpenPositionSuccess(t *testing.T) { ecosystemFundFee := nibiruApp.PerpKeeper.GetParams(ctx).EcosystemFundFeeRatio.Mul(exchangedNotional).RoundInt() testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionChangedEvent{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), - Margin: sdk.NewCoin(denoms.DenomNUSD, tc.expectedMargin.RoundInt()), + Margin: sdk.NewCoin(denoms.NUSD, tc.expectedMargin.RoundInt()), PositionNotional: tc.expectedPositionNotional, ExchangedNotional: exchangedNotional, ExchangedSize: exchangedSize, PositionSize: tc.expectedSize, RealizedPnl: tc.expectedRealizedPnl, UnrealizedPnlAfter: tc.expectedUnrealizedPnl, - BadDebt: sdk.NewCoin(denoms.DenomNUSD, sdk.ZeroInt()), + BadDebt: sdk.NewCoin(denoms.NUSD, sdk.ZeroInt()), MarkPrice: tc.expectedMarkPrice, FundingPayment: sdk.ZeroDec(), - TransactionFee: sdk.NewCoin(denoms.DenomNUSD, feePoolFee.Add(ecosystemFundFee)), + TransactionFee: sdk.NewCoin(denoms.NUSD, feePoolFee.Add(ecosystemFundFee)), BlockHeight: ctx.BlockHeight(), BlockTimeMs: ctx.BlockTime().UnixMilli(), }) @@ -371,7 +371,7 @@ func TestOpenPositionError(t *testing.T) { }{ { name: "not enough trader funds", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 999)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -382,10 +382,10 @@ func TestOpenPositionError(t *testing.T) { }, { name: "position has bad debt", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 999)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -400,7 +400,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new long position not over base limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -411,7 +411,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new short position not under base limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -422,7 +422,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "quote asset amount is zero", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -433,7 +433,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "leverage amount is zero", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -444,7 +444,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "leverage amount is too high - SELL", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -455,7 +455,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "leverage amount is too high - BUY", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -466,7 +466,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new long position over fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1*common.Precision*common.Precision)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -477,7 +477,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new short position over fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1*common.Precision*common.Precision)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -488,7 +488,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new long position over trade limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 10_000*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 10_000*common.Precision)), poolTradeLimitRatio: sdk.MustNewDecFromStr("0.01"), initialPosition: nil, side: types.Side_BUY, @@ -499,7 +499,7 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new short position over trade limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 10_000*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 10_000*common.Precision)), poolTradeLimitRatio: sdk.MustNewDecFromStr("0.01"), initialPosition: nil, side: types.Side_SELL, @@ -520,7 +520,7 @@ func TestOpenPositionError(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* tradeLimitRatio */ /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), @@ -534,7 +534,7 @@ func TestOpenPositionError(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -548,7 +548,7 @@ func TestOpenPositionError(t *testing.T) { } ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(time.Second * 5)) - resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) + resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) require.ErrorContains(t, err, tc.expectedErr.Error()) require.Nil(t, resp) }) diff --git a/x/perp/keeper/clearing_house_unit_test.go b/x/perp/keeper/clearing_house_unit_test.go index e7da98ed0..23f3552f1 100644 --- a/x/perp/keeper/clearing_house_unit_test.go +++ b/x/perp/keeper/clearing_house_unit_test.go @@ -117,7 +117,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -133,7 +133,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -154,7 +154,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { baseAmount, err := perpKeeper.swapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.side, sdk.NewDec(10), sdk.NewDec(1), @@ -182,7 +182,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -194,7 +194,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(50), @@ -204,7 +204,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -213,7 +213,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, ) @@ -256,7 +256,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -268,7 +268,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(101), @@ -278,7 +278,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -286,7 +286,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -331,7 +331,7 @@ func TestIncreasePosition(t *testing.T) { // funding payment causes negative margin aka bad debt initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(110), // 110 BTC Margin: sdk.NewDec(11), // 11 NUSD OpenNotional: sdk.NewDec(110), // 110 NUSD @@ -343,7 +343,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(110), @@ -353,7 +353,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(110), ). @@ -361,7 +361,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.2"), }) }, @@ -404,7 +404,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -416,7 +416,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(200), @@ -426,7 +426,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -434,7 +434,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -477,7 +477,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -489,7 +489,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(99), @@ -499,7 +499,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -507,7 +507,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -553,7 +553,7 @@ func TestIncreasePosition(t *testing.T) { // funding payment causes bad debt initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -565,7 +565,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(105), /*baseAssetLimit=*/ sdk.NewDec(100), @@ -575,7 +575,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -583,7 +583,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("-0.3"), }) }, @@ -657,7 +657,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 200 NUSD and unrealized PnL of +100 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -665,7 +665,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -684,7 +684,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of -5 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -692,7 +692,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -711,7 +711,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of -50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -719,7 +719,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -740,7 +740,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of +50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-150), // -150 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -748,7 +748,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -767,7 +767,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 105 NUSD and unrealized PnL of -5 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -775,7 +775,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -794,7 +794,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 150 NUSD and unrealized PnL of -50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -802,7 +802,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -827,7 +827,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -836,7 +836,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ tc.quoteAssetLimit, @@ -911,7 +911,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 100 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -946,7 +946,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 95 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(105), // 105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -981,7 +981,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -1018,7 +1018,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 95 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-105), // -105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1053,7 +1053,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 99.75 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1088,7 +1088,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 75 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1123,7 +1123,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1132,7 +1132,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ tc.quoteAssetDir, /*quoteAssetAmount=*/ tc.quoteAmountToDecrease, /*baseAssetLimit=*/ tc.exchangedBaseAmount.Abs(), @@ -1141,7 +1141,7 @@ func TestDecreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1509,7 +1509,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -1522,7 +1522,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), ). @@ -1531,7 +1531,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1542,7 +1542,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ tc.mockQuoteDir, /*quoteAssetAmount=*/ tc.inputQuoteAmount.Mul(tc.inputLeverage).Sub(tc.mockQuoteAmount), /*baseAssetLimit=*/ sdk.MaxDec(tc.inputBaseAssetLimit.Sub(currentPosition.Size_.Abs()), sdk.ZeroDec()), @@ -1552,7 +1552,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1690,7 +1690,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1716,7 +1716,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(105), // 105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1744,7 +1744,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-105), // -105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1770,7 +1770,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1807,7 +1807,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1816,7 +1816,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1853,7 +1853,7 @@ func TestClosePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1892,7 +1892,7 @@ func TestClosePosition(t *testing.T) { PositionSize: sdk.ZeroDec(), RealizedPnl: tc.expectedRealizedPnl, UnrealizedPnlAfter: sdk.ZeroDec(), - BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), sdk.ZeroInt()), + BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), sdk.ZeroInt()), MarkPrice: tc.newPositionNotional.Quo(tc.initialPosition.Size_.Abs()), FundingPayment: sdk.MustNewDecFromStr("0.02").Mul(tc.initialPosition.Size_), TransactionFee: sdk.NewInt64Coin(tc.initialPosition.Pair.QuoteDenom(), 0), @@ -1920,7 +1920,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { // user cannot close position due to bad debt initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -1941,7 +1941,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { // user cannot close position due to bad debt initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1970,7 +1970,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1980,7 +1980,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1989,7 +1989,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) diff --git a/x/perp/keeper/grpc_query_test.go b/x/perp/keeper/grpc_query_test.go index 1960deb6b..37c2b7329 100644 --- a/x/perp/keeper/grpc_query_test.go +++ b/x/perp/keeper/grpc_query_test.go @@ -31,7 +31,7 @@ func initAppVpools( t.Log("initialize vpool and pair") assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve, baseAssetReserve, vpooltypes.VpoolConfig{ @@ -43,12 +43,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -60,12 +60,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -77,7 +77,7 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) return ctx, nibiruApp, queryServer @@ -98,7 +98,7 @@ func TestQueryPosition(t *testing.T) { { name: "positive PnL", initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -115,7 +115,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, positive margin ratio", initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -132,7 +132,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, negative margin ratio", initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -167,7 +167,7 @@ func TestQueryPosition(t *testing.T) { sdk.WrapSDKContext(ctx), &types.QueryPositionRequest{ Trader: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }, ) require.NoError(t, err) @@ -193,7 +193,7 @@ func TestQueryPositions(t *testing.T) { name: "positive PnL", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -201,7 +201,7 @@ func TestQueryPositions(t *testing.T) { LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -264,7 +264,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "empty string pair", initialPairMetadata: &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -275,7 +275,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "pair metadata not found", initialPairMetadata: &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -286,11 +286,11 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "returns single funding payment", initialPairMetadata: &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }, expectErr: false, expectedLatestCPF: sdk.ZeroDec(), @@ -305,7 +305,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { ctx, app, queryServer := initAppVpools(t, sdk.NewDec(481_000), sdk.NewDec(1_000)) t.Log("set index price") - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) t.Log("query cumulative premium fraction") resp, err := queryServer.CumulativePremiumFraction(sdk.WrapSDKContext(ctx), tc.query) @@ -340,7 +340,7 @@ func TestQueryMetrics(t *testing.T) { name: "two longs", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -348,7 +348,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -362,7 +362,7 @@ func TestQueryMetrics(t *testing.T) { name: "two shorts", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -370,7 +370,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -384,7 +384,7 @@ func TestQueryMetrics(t *testing.T) { name: "one long, one short", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -392,7 +392,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -406,14 +406,14 @@ func TestQueryMetrics(t *testing.T) { name: "decrease position", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -428,42 +428,42 @@ func TestQueryMetrics(t *testing.T) { name: "swap positions", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), @@ -489,7 +489,7 @@ func TestQueryMetrics(t *testing.T) { // Detect position decrease app.PerpKeeper.OnSwapEnd( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), position.OpenNotional, position.Size_, ) @@ -499,7 +499,7 @@ func TestQueryMetrics(t *testing.T) { resp, err := queryServer.Metrics( sdk.WrapSDKContext(ctx), &types.QueryMetricsRequest{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }, ) require.NoError(t, err) diff --git a/x/perp/keeper/hooks_test.go b/x/perp/keeper/hooks_test.go index 3a5252baa..5f92abfb3 100644 --- a/x/perp/keeper/hooks_test.go +++ b/x/perp/keeper/hooks_test.go @@ -51,7 +51,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { markPrice: sdk.NewDec(10), expectedLatestCumulativePremiumFraction: sdk.ZeroDec(), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), MarkPrice: sdk.NewDec(10), IndexPrice: sdk.NewDec(10), LatestFundingRate: sdk.ZeroDec(), @@ -67,7 +67,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { indexPrice: sdk.NewDec(462), expectedLatestCumulativePremiumFraction: sdk.MustNewDecFromStr("-9.229166666666666666"), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), MarkPrice: sdk.NewDec(19), IndexPrice: sdk.NewDec(462), LatestFundingRate: sdk.MustNewDecFromStr("-0.019976551226551227"), @@ -83,7 +83,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { indexPrice: sdk.NewDec(64), expectedLatestCumulativePremiumFraction: sdk.MustNewDecFromStr("14.1875"), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), MarkPrice: sdk.NewDec(745), IndexPrice: sdk.NewDec(64), LatestFundingRate: sdk.MustNewDecFromStr("0.2216796875"), @@ -108,7 +108,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { perpKeeper.AfterEpochEnd(ctx, "30 min", 1) t.Log("assert PairMetadataState") - pair, err := perpKeeper.PairsMetadata.Get(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + pair, err := perpKeeper.PairsMetadata.Get(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) assert.Equal(t, tc.expectedLatestCumulativePremiumFraction, pair.LatestCumulativePremiumFraction) @@ -131,23 +131,23 @@ func initParams(ctx sdk.Context, k Keeper) { TwapLookbackWindow: 15 * time.Minute, }) setPairMetadata(k, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), // start with one entry to ensure we append LatestCumulativePremiumFraction: sdk.ZeroDec(), }) } func setMocks(ctx sdk.Context, mocks mockedDependencies, indexPrice sdk.Dec, markPrice sdk.Dec) { - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockEpochKeeper.EXPECT().GetEpochInfo(ctx, "30 min").Return( epochtypes.EpochInfo{Duration: 30 * time.Minute}, ).MaxTimes(1) mocks.mockOracleKeeper.EXPECT(). - GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(indexPrice, nil).MaxTimes(1) + GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(indexPrice, nil).MaxTimes(1) mocks.mockVpoolKeeper.EXPECT(). - GetMarkPriceTWAP(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), 15*time.Minute). + GetMarkPriceTWAP(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), 15*time.Minute). Return(markPrice, nil).MaxTimes(1) } diff --git a/x/perp/keeper/liquidate_unit_test.go b/x/perp/keeper/liquidate_unit_test.go index 3f63a027e..60cb7a43c 100644 --- a/x/perp/keeper/liquidate_unit_test.go +++ b/x/perp/keeper/liquidate_unit_test.go @@ -51,8 +51,8 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { exchangedSize: sdk.MustNewDecFromStr("0.25"), // 1 * 0.25 exchangedNotional: sdk.MustNewDecFromStr("239.75"), // 959 * 0.25 - expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 3), // 959 * 0.25 * 0.025 / 2 - expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 3), // 959 * 0.25 * 0.025 / 2 + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.NUSD, 3), // 959 * 0.25 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.NUSD, 3), // 959 * 0.25 * 0.025 / 2 expectedPositionSize: sdk.MustNewDecFromStr("0.75"), // 1 - 0.25 expectedUnrealizedPnl: sdk.MustNewDecFromStr("-30.75"), // -41 * 0.75 @@ -70,8 +70,8 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { exchangedSize: sdk.MustNewDecFromStr("0.25"), // 1 * 0.5 exchangedNotional: sdk.MustNewDecFromStr("230.76923078"), // 923.0769231 * 0.5 - expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 3), // 923.0769231 * 0.25 * 0.025 / 2 - expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 3), // 923.0769231 * 0.25 * 0.025 / 2 + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.NUSD, 3), // 923.0769231 * 0.25 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.NUSD, 3), // 923.0769231 * 0.25 * 0.025 / 2 expectedPositionSize: sdk.MustNewDecFromStr("0.75"), // 1 - 0.25 expectedUnrealizedPnl: sdk.MustNewDecFromStr("-57.692307675"), // -76.92307692 * 0.75 @@ -91,7 +91,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -104,25 +104,25 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true).Times(2) + ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.OneDec(), 15*time.Minute, @@ -131,7 +131,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.OneDec(), ). @@ -139,7 +139,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.exchangedSize, ). @@ -147,7 +147,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /* quoteAmt */ tc.exchangedNotional, /* baseLimit */ sdk.ZeroDec(), @@ -162,8 +162,8 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("mock bank keeper") mocks.mockBankKeeper.EXPECT(). - GetBalance(ctx, vaultAddr, denoms.DenomNUSD). - Return(sdk.NewInt64Coin(denoms.DenomNUSD, 1_000)) + GetBalance(ctx, vaultAddr, denoms.NUSD). + Return(sdk.NewInt64Coin(denoms.NUSD, 1_000)) mocks.mockBankKeeper.EXPECT(). SendCoinsFromModuleToAccount( ctx, types.VaultModuleAccount, liquidatorAddr, @@ -179,16 +179,16 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee, feeToFund) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.NoError(t, err) assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), newPosition.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) assert.EqualValues(t, tc.expectedPositionSize, newPosition.Size_) assert.EqualValues(t, tc.expectedPositionMargin, newPosition.Margin) assert.EqualValues(t, tc.expectedPositionOpenNotional, newPosition.OpenNotional) @@ -196,15 +196,15 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.exchangedNotional, ExchangedPositionSize: tc.exchangedSize.Neg(), LiquidatorAddress: liquidatorAddr.String(), FeeToLiquidator: tc.expectedLiquidatorFee, FeeToEcosystemFund: tc.expectedPerpEFFee, - BadDebt: sdk.NewCoin(denoms.DenomNUSD, sdk.ZeroInt()), - Margin: sdk.NewCoin(denoms.DenomNUSD, tc.expectedPositionMargin.RoundInt()), + BadDebt: sdk.NewCoin(denoms.NUSD, sdk.ZeroInt()), + Margin: sdk.NewCoin(denoms.NUSD, tc.expectedPositionMargin.RoundInt()), PositionNotional: tc.newPositionNotional.Sub(tc.exchangedNotional), PositionSize: tc.initialPositionSize.Sub(tc.exchangedSize), UnrealizedPnl: tc.expectedUnrealizedPnl, @@ -238,8 +238,8 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { newPositionNotional: sdk.NewDec(923), // just below 2.5% margin ratio - expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 12), // 923 * 0.025 / 2 - expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 11), // 23 - 12 + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.NUSD, 12), // 923 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.NUSD, 11), // 23 - 12 }, { name: "Full Liquidation - at 1.25%", @@ -250,8 +250,8 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { newPositionNotional: sdk.MustNewDecFromStr("911.3924051"), // at 1.25% margin ratio - expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 11), - expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 0), + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.NUSD, 11), + expectedPerpEFFee: sdk.NewInt64Coin(denoms.NUSD, 0), }, } @@ -266,7 +266,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -279,24 +279,24 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true).Times(2) + ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, 15*time.Minute, @@ -305,7 +305,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -313,7 +313,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /* baseAmt */ tc.initialPositionSize, /* quoteLimit */ sdk.ZeroDec(), @@ -328,8 +328,8 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("mock bank keeper") mocks.mockBankKeeper.EXPECT(). - GetBalance(ctx, vaultAddr, denoms.DenomNUSD). - Return(sdk.NewInt64Coin(denoms.DenomNUSD, 1_000)) + GetBalance(ctx, vaultAddr, denoms.NUSD). + Return(sdk.NewInt64Coin(denoms.NUSD, 1_000)) mocks.mockBankKeeper.EXPECT(). SendCoinsFromModuleToAccount( ctx, types.VaultModuleAccount, liquidatorAddr, @@ -347,26 +347,26 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee.String(), feeToFund.String()) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.ErrorIs(t, err, collections.ErrNotFound) assert.Empty(t, newPosition) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.newPositionNotional, ExchangedPositionSize: tc.initialPositionSize.Neg(), LiquidatorAddress: liquidatorAddr.String(), FeeToLiquidator: tc.expectedLiquidatorFee, FeeToEcosystemFund: tc.expectedPerpEFFee, - BadDebt: sdk.NewCoin(denoms.DenomNUSD, sdk.ZeroInt()), - Margin: sdk.NewCoin(denoms.DenomNUSD, sdk.ZeroInt()), + BadDebt: sdk.NewCoin(denoms.NUSD, sdk.ZeroInt()), + Margin: sdk.NewCoin(denoms.NUSD, sdk.ZeroInt()), PositionNotional: sdk.ZeroDec(), // always zero PositionSize: sdk.ZeroDec(), // always zero UnrealizedPnl: sdk.ZeroDec(), // always zero @@ -403,8 +403,8 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { newPositionNotional: sdk.NewDec(900), // at 0% margin ratio - expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 11), // 900 * 0.025 / 2 - expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 0), // no margin left for perp ef + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.NUSD, 11), // 900 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.NUSD, 0), // no margin left for perp ef expectedPositionBadDebt: sdk.ZeroDec(), expectedLiquidationBadDebt: sdk.MustNewDecFromStr("11.25"), @@ -418,8 +418,8 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { newPositionNotional: sdk.NewDec(899), - expectedLiquidatorFee: sdk.NewInt64Coin(denoms.DenomNUSD, 11), // 899 * 0.025 / 2 - expectedPerpEFFee: sdk.NewInt64Coin(denoms.DenomNUSD, 0), + expectedLiquidatorFee: sdk.NewInt64Coin(denoms.NUSD, 11), // 899 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.NUSD, 0), expectedPositionBadDebt: sdk.NewDec(1), expectedLiquidationBadDebt: sdk.MustNewDecFromStr("11.2375"), @@ -437,7 +437,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -450,24 +450,24 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true).Times(2) + ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). + GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, 15*time.Minute, @@ -476,7 +476,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -484,7 +484,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /* baseAmt */ tc.initialPositionSize, /* quoteLimit */ sdk.ZeroDec(), @@ -499,8 +499,8 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("mock bank keeper") mocks.mockBankKeeper.EXPECT(). - GetBalance(ctx, vaultAddr, denoms.DenomNUSD). - Return(sdk.NewInt64Coin(denoms.DenomNUSD, 1_000)) + GetBalance(ctx, vaultAddr, denoms.NUSD). + Return(sdk.NewInt64Coin(denoms.NUSD, 1_000)) mocks.mockBankKeeper.EXPECT(). SendCoinsFromModuleToAccount( ctx, types.VaultModuleAccount, liquidatorAddr, @@ -512,7 +512,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { ctx, types.PerpEFModuleAccount, types.VaultModuleAccount, sdk.NewCoins( sdk.NewCoin( - denoms.DenomNUSD, + denoms.NUSD, tc.expectedLiquidationBadDebt.Add(tc.expectedPositionBadDebt).RoundInt(), ), ), @@ -521,26 +521,26 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee.String(), feeToFund.String()) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.ErrorIs(t, err, collections.ErrNotFound) assert.Empty(t, newPosition) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.newPositionNotional, ExchangedPositionSize: tc.initialPositionSize.Neg(), LiquidatorAddress: liquidatorAddr.String(), FeeToLiquidator: tc.expectedLiquidatorFee, FeeToEcosystemFund: tc.expectedPerpEFFee, - BadDebt: sdk.NewCoin(denoms.DenomNUSD, tc.expectedLiquidationBadDebt.Add(tc.expectedPositionBadDebt).RoundInt()), - Margin: sdk.NewInt64Coin(denoms.DenomNUSD, 0), + BadDebt: sdk.NewCoin(denoms.NUSD, tc.expectedLiquidationBadDebt.Add(tc.expectedPositionBadDebt).RoundInt()), + Margin: sdk.NewInt64Coin(denoms.NUSD, 0), PositionNotional: sdk.ZeroDec(), // always zero PositionSize: sdk.ZeroDec(), // always zero UnrealizedPnl: sdk.ZeroDec(), // always zero @@ -588,7 +588,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { test: func() { perpKeeper, mocks, ctx := getKeeper(t) liquidator := testutilevents.AccAddress() - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(false) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false) err := perpKeeper.distributeLiquidateRewards(ctx, types.LiquidateResp{ @@ -598,7 +598,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { Liquidator: liquidator.String(), PositionResp: &types.PositionResp{ Position: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }, }, }, @@ -613,7 +613,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { perpKeeper, mocks, ctx := getKeeper(t) liquidator := testutilevents.AccAddress() - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockAccountKeeper. EXPECT().GetModuleAddress(types.VaultModuleAccount). @@ -639,7 +639,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { Liquidator: liquidator.String(), PositionResp: &types.PositionResp{ Position: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }}, }, ) @@ -929,16 +929,16 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { newParams.LiquidationFeeRatio = tc.liquidationFee perpKeeper.SetParams(ctx, newParams) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -946,20 +946,20 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), /* skipFluctuationLimitCheck */ true, ).Return( /*quoteAssetAmount=*/ tc.baseAssetPriceInQuote, nil) mocks.mockVpoolKeeper.EXPECT(). - GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). + GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.OneDec(), nil) t.Log("create and set the initial position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialMargin, OpenNotional: tc.initialOpenNotional, @@ -997,7 +997,7 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { t.Log("assert new position fields") newPosition := positionResp.Position assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), newPosition.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) assert.True(t, newPosition.Size_.IsZero()) // always zero assert.True(t, newPosition.Margin.IsZero()) // always zero assert.True(t, newPosition.OpenNotional.IsZero()) // always zero @@ -1005,15 +1005,15 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: positionResp.ExchangedNotionalValue, ExchangedPositionSize: positionResp.ExchangedPositionSize, LiquidatorAddress: liquidatorAddr.String(), - FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), tc.expectedFundsToLiquidator), - FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), tc.expectedFundsToPerpEF), - BadDebt: sdk.NewCoin(denoms.DenomNUSD, tc.expectedLiquidationBadDebt), - Margin: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), newPosition.Margin.RoundInt()), + FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToLiquidator), + FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToPerpEF), + BadDebt: sdk.NewCoin(denoms.NUSD, tc.expectedLiquidationBadDebt), + Margin: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), newPosition.Margin.RoundInt()), PositionNotional: positionResp.PositionNotional, PositionSize: newPosition.Size_, UnrealizedPnl: positionResp.UnrealizedPnlAfter, @@ -1220,16 +1220,16 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { newParams.PartialLiquidationRatio = tc.partialLiquidationRatio perpKeeper.SetParams(ctx, newParams) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Mul(tc.partialLiquidationRatio), ). @@ -1238,7 +1238,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -1248,7 +1248,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ tc.baseAssetPriceInQuote.Mul(tc.partialLiquidationRatio), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), @@ -1258,7 +1258,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ tc.baseAssetPriceInQuote.Mul(tc.partialLiquidationRatio), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), @@ -1267,13 +1267,13 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { } mocks.mockVpoolKeeper.EXPECT(). - GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)). + GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.OneDec(), nil) t.Log("create and set the initial position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialMargin, OpenNotional: tc.initialOpenNotional, @@ -1313,21 +1313,21 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { t.Log("assert new position fields") newPosition := positionResp.Position assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), newPosition.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) assert.True(t, newPosition.LatestCumulativePremiumFraction.IsZero()) assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) assert.EqualValues(t, tc.expectedPositionMargin, newPosition.Margin) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: positionResp.ExchangedNotionalValue, ExchangedPositionSize: positionResp.ExchangedPositionSize, LiquidatorAddress: liquidatorAddr.String(), - FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), tc.expectedFundsToLiquidator), - FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), tc.expectedFundsToPerpEF), - BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), sdk.ZeroInt()), - Margin: sdk.NewCoin(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD).QuoteDenom(), newPosition.Margin.RoundInt()), + FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToLiquidator), + FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToPerpEF), + BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), sdk.ZeroInt()), + Margin: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), newPosition.Margin.RoundInt()), PositionNotional: positionResp.PositionNotional, PositionSize: newPosition.Size_, UnrealizedPnl: positionResp.UnrealizedPnlAfter, diff --git a/x/perp/keeper/margin_test.go b/x/perp/keeper/margin_test.go index 6fca81dc4..bd6c103bb 100644 --- a/x/perp/keeper/margin_test.go +++ b/x/perp/keeper/margin_test.go @@ -33,11 +33,11 @@ func TestAddMarginSuccess(t *testing.T) { }{ { name: "add margin", - marginToAdd: sdk.NewInt64Coin(denoms.DenomNUSD, 100), + marginToAdd: sdk.NewInt64Coin(denoms.NUSD, 100), latestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.001"), initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(1_000), Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(500), @@ -68,7 +68,7 @@ func TestAddMarginSuccess(t *testing.T) { vpoolKeeper := &nibiruApp.VpoolKeeper assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens vpooltypes.VpoolConfig{ @@ -79,11 +79,11 @@ func TestAddMarginSuccess(t *testing.T) { MaxLeverage: sdk.MustNewDecFromStr("15"), }, )) - require.True(t, vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD))) + require.True(t, vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD))) t.Log("set pair metadata") setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: tc.latestCumulativePremiumFraction, }, ) @@ -91,14 +91,14 @@ func TestAddMarginSuccess(t *testing.T) { t.Log("establish initial position") setPosition(nibiruApp.PerpKeeper, ctx, tc.initialPosition) - resp, err := nibiruApp.PerpKeeper.AddMargin(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), traderAddr, tc.marginToAdd) + resp, err := nibiruApp.PerpKeeper.AddMargin(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr, tc.marginToAdd) require.NoError(t, err) assert.EqualValues(t, tc.expectedFundingPayment, resp.FundingPayment) assert.EqualValues(t, tc.expectedMargin, resp.Position.Margin) assert.EqualValues(t, tc.initialPosition.OpenNotional, resp.Position.OpenNotional) assert.EqualValues(t, tc.initialPosition.Size_, resp.Position.Size_) assert.EqualValues(t, traderAddr.String(), resp.Position.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), resp.Position.Pair) + assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), resp.Position.Pair) assert.EqualValues(t, tc.latestCumulativePremiumFraction, resp.Position.LatestCumulativePremiumFraction) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }) @@ -120,7 +120,7 @@ func TestRemoveMargin(t *testing.T) { trader := testutilevents.AccAddress() pair := common.MustNewAssetPair("osmo:nusd") - _, _, _, err := nibiruApp.PerpKeeper.RemoveMargin(ctx, pair, trader, sdk.Coin{Denom: denoms.DenomNUSD, Amount: removeAmt}) + _, _, _, err := nibiruApp.PerpKeeper.RemoveMargin(ctx, pair, trader, sdk.Coin{Denom: denoms.NUSD, Amount: removeAmt}) require.Error(t, err) require.ErrorContains(t, err, types.ErrPairNotFound.Error()) }, diff --git a/x/perp/keeper/margin_unit_test.go b/x/perp/keeper/margin_unit_test.go index 504711d39..4e7f0f9a7 100644 --- a/x/perp/keeper/margin_unit_test.go +++ b/x/perp/keeper/margin_unit_test.go @@ -111,7 +111,7 @@ func TestGetMarginRatio(t *testing.T) { name: "margin without price changes", position: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -124,7 +124,7 @@ func TestGetMarginRatio(t *testing.T) { name: "margin with price changes", position: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -144,7 +144,7 @@ func TestGetMarginRatio(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.position.Size_.Abs(), ). @@ -153,7 +153,7 @@ func TestGetMarginRatio(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.position.Size_.Abs(), 15*time.Minute, @@ -161,7 +161,7 @@ func TestGetMarginRatio(t *testing.T) { Return(tc.newPrice, nil) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.OneDec(), }) @@ -635,7 +635,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -644,7 +644,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -658,7 +658,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -667,7 +667,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -681,7 +681,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -690,7 +690,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -705,7 +705,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -714,7 +714,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -729,7 +729,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -738,7 +738,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.NewDec(2), nil) }, @@ -750,7 +750,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -759,7 +759,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.MustNewDecFromStr("0.5"), nil) }, @@ -771,7 +771,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -780,7 +780,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), ). @@ -794,7 +794,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; negative pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -803,7 +803,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), ). @@ -817,7 +817,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -826,7 +826,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), 15*time.Minute, @@ -841,7 +841,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; negative pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -850,7 +850,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), 15*time.Minute, @@ -865,7 +865,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -874,7 +874,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.MustNewDecFromStr("0.5"), nil) }, @@ -886,7 +886,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -895,7 +895,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.NewDec(2), nil) }, @@ -942,7 +942,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "max pnl, pick spot price", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -952,7 +952,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -961,7 +961,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -976,7 +976,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "max pnl, pick twap", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -986,7 +986,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -995,7 +995,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -1010,7 +1010,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "min pnl, pick spot price", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -1020,7 +1020,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -1029,7 +1029,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -1044,7 +1044,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "min pnl, pick twap", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -1054,7 +1054,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -1063,7 +1063,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, diff --git a/x/perp/keeper/msg_server_test.go b/x/perp/keeper/msg_server_test.go index c3b780c8f..a2e42997a 100644 --- a/x/perp/keeper/msg_server_test.go +++ b/x/perp/keeper/msg_server_test.go @@ -34,37 +34,37 @@ func TestMsgServerAddMargin(t *testing.T) { }{ { name: "trader not enough funds", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 999)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - margin: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), + margin: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "no initial position", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: nil, - margin: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), + margin: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: collections.ErrNotFound, }, { name: "success", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - margin: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), + margin: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: nil, }, } @@ -79,7 +79,7 @@ func TestMsgServerAddMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -91,7 +91,7 @@ func TestMsgServerAddMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -106,7 +106,7 @@ func TestMsgServerAddMargin(t *testing.T) { resp, err := msgServer.AddMargin(sdk.WrapSDKContext(ctx), &types.MsgAddMargin{ Sender: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Margin: tc.margin, }) @@ -141,51 +141,51 @@ func TestMsgServerRemoveMargin(t *testing.T) { }{ { name: "position not enough margin", - vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1000)), + vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - marginToRemove: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: types.ErrFailedRemoveMarginCanCauseBadDebt, }, { name: "no initial position", - vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 0)), + vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 0)), initialPosition: nil, - marginToRemove: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: collections.ErrNotFound, }, { name: "vault insufficient funds", - vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 999)), + vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - marginToRemove: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "success", - vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1000)), + vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - marginToRemove: sdk.NewInt64Coin(denoms.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: nil, }, } @@ -200,7 +200,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -212,7 +212,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -229,7 +229,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { resp, err := msgServer.RemoveMargin(sdk.WrapSDKContext(ctx), &types.MsgRemoveMargin{ Sender: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Margin: tc.marginToRemove, }) @@ -263,15 +263,15 @@ func TestMsgServerOpenPosition(t *testing.T) { }{ { name: "trader not enough funds", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 999)), - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sender: testutil.AccAddress().String(), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "success", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1020)), - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sender: testutil.AccAddress().String(), expectedErr: nil, }, @@ -287,7 +287,7 @@ func TestMsgServerOpenPosition(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + /* pair */ common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -299,7 +299,7 @@ func TestMsgServerOpenPosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -358,7 +358,7 @@ func TestMsgServerClosePosition(t *testing.T) { }{ { name: "success", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr: testutil.AccAddress(), expectedErr: nil, }, @@ -374,7 +374,7 @@ func TestMsgServerClosePosition(t *testing.T) { assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -386,7 +386,7 @@ func TestMsgServerClosePosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -435,7 +435,7 @@ func TestMsgServerLiquidate(t *testing.T) { }{ { name: "success", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), liquidator: testutil.AccAddress().String(), trader: testutil.AccAddress().String(), expectedErr: nil, @@ -453,7 +453,7 @@ func TestMsgServerLiquidate(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + /* pair */ common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -465,7 +465,7 @@ func TestMsgServerLiquidate(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(time.Now().Add(time.Minute)) @@ -473,7 +473,7 @@ func TestMsgServerLiquidate(t *testing.T) { traderAddr, err := sdk.AccAddressFromBech32(tc.trader) if err == nil { t.Log("set oracle price") - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) t.Log("create position") setPosition(app.PerpKeeper, ctx, types.Position{ @@ -516,7 +516,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ctx = ctx.WithBlockTime(time.Now()) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) - pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) liquidator := testutil.AccAddress() atRiskTrader1 := testutil.AccAddress() @@ -544,7 +544,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(time.Now().Add(time.Minute)) t.Log("set oracle price") - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) t.Log("create positions") atRiskPosition1 := types.Position{ @@ -642,14 +642,14 @@ func TestMsgServerDonateToEcosystemFund(t *testing.T) { name: "not enough funds", sender: testutil.AccAddress(), initialFunds: sdk.NewCoins(), - donation: sdk.NewInt64Coin(denoms.DenomNUSD, 100), + donation: sdk.NewInt64Coin(denoms.NUSD, 100), expectedErr: fmt.Errorf("insufficient funds"), }, { name: "success", sender: testutil.AccAddress(), - initialFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 1e6)), - donation: sdk.NewInt64Coin(denoms.DenomNUSD, 100), + initialFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1e6)), + donation: sdk.NewInt64Coin(denoms.NUSD, 100), expectedErr: nil, }, } @@ -677,7 +677,7 @@ func TestMsgServerDonateToEcosystemFund(t *testing.T) { app.BankKeeper.GetBalance( ctx, app.AccountKeeper.GetModuleAddress(types.PerpEFModuleAccount), - denoms.DenomNUSD, + denoms.NUSD, ), ) } diff --git a/x/perp/simulation/genesis.go b/x/perp/simulation/genesis.go index f24d6a630..0de722770 100644 --- a/x/perp/simulation/genesis.go +++ b/x/perp/simulation/genesis.go @@ -18,7 +18,7 @@ func RandomizedGenState(simState *module.SimulationState) { Params: types.DefaultParams(), PairMetadata: []types.PairMetadata{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, }, diff --git a/x/perp/simulation/operations.go b/x/perp/simulation/operations.go index c30a1de13..2639ac6f5 100644 --- a/x/perp/simulation/operations.go +++ b/x/perp/simulation/operations.go @@ -56,7 +56,7 @@ func SimulateMsgOpenPosition(ak types.AccountKeeper, bk types.BankKeeper, k keep pool := pools[rand.Intn(len(pools))] maxQuote := getMaxQuoteForPool(pool) - quoteAmt, _ := simtypes.RandPositiveInt(r, sdk.MinInt(sdk.Int(maxQuote), spendableCoins.AmountOf(denoms.DenomNUSD))) + quoteAmt, _ := simtypes.RandPositiveInt(r, sdk.MinInt(sdk.Int(maxQuote), spendableCoins.AmountOf(denoms.NUSD))) leverage := simtypes.RandomDecAmount(r, pool.Config.MaxLeverage.Sub(sdk.OneDec())).Add(sdk.OneDec()) // between [1, MaxLeverage] openNotional := leverage.MulInt(quoteAmt) @@ -72,11 +72,11 @@ func SimulateMsgOpenPosition(ak types.AccountKeeper, bk types.BankKeeper, k keep } feesAmt := openNotional.Mul(sdk.MustNewDecFromStr("0.002")).Ceil().TruncateInt() - spentCoins := sdk.NewCoins(sdk.NewCoin(denoms.DenomNUSD, quoteAmt.Add(feesAmt))) + spentCoins := sdk.NewCoins(sdk.NewCoin(denoms.NUSD, quoteAmt.Add(feesAmt))) msg := &types.MsgOpenPosition{ Sender: simAccount.Address.String(), - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Side: side, QuoteAssetAmount: quoteAmt, Leverage: leverage, @@ -171,14 +171,14 @@ func SimulateMsgClosePosition(ak types.AccountKeeper, bk types.BankKeeper, k kee ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) msg := &types.MsgClosePosition{ Sender: trader, Pair: pair, } - _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), simAccount.Address)) + _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } @@ -209,22 +209,22 @@ func SimulateMsgAddMargin(ak types.AccountKeeper, bk types.BankKeeper, k keeper. ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) msg := &types.MsgAddMargin{} - _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), simAccount.Address)) + _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } spendableCoins := bk.SpendableCoins(ctx, simAccount.Address) - if spendableCoins.AmountOf(denoms.DenomNUSD).IsZero() { + if spendableCoins.AmountOf(denoms.NUSD).IsZero() { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no nusd left"), nil, nil } - quoteAmt, _ := simtypes.RandPositiveInt(r, spendableCoins.AmountOf(denoms.DenomNUSD)) + quoteAmt, _ := simtypes.RandPositiveInt(r, spendableCoins.AmountOf(denoms.NUSD)) - spentCoin := sdk.NewCoin(denoms.DenomNUSD, quoteAmt) + spentCoin := sdk.NewCoin(denoms.NUSD, quoteAmt) msg = &types.MsgAddMargin{ Sender: trader, @@ -258,11 +258,11 @@ func SimulateMsgRemoveMargin(ak types.AccountKeeper, bk types.BankKeeper, k keep ) (opMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) msg := &types.MsgRemoveMargin{} - position, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), simAccount.Address)) + position, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } @@ -281,7 +281,7 @@ func SimulateMsgRemoveMargin(ak types.AccountKeeper, bk types.BankKeeper, k keep marginToRemove, _ := simtypes.RandPositiveInt(r, maxMarginToRemove.TruncateInt()) - expectedCoin := sdk.NewCoin(denoms.DenomNUSD, marginToRemove) + expectedCoin := sdk.NewCoin(denoms.NUSD, marginToRemove) msg = &types.MsgRemoveMargin{ Sender: trader, @@ -316,7 +316,7 @@ func SimulateMsgRemoveMargin(ak types.AccountKeeper, bk types.BankKeeper, k keep func fundAccountWithTokens(ctx sdk.Context, receiver sdk.AccAddress, bk types.BankKeeper) (err error) { newCoins := sdk.NewCoins( - sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1e6)), + sdk.NewCoin(denoms.NUSD, sdk.NewInt(1e6)), ) if err := bk.MintCoins(ctx, types.ModuleName, newCoins); err != nil { diff --git a/x/perp/types/msgs_test.go b/x/perp/types/msgs_test.go index 312926c83..c7cdde13b 100644 --- a/x/perp/types/msgs_test.go +++ b/x/perp/types/msgs_test.go @@ -336,7 +336,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, }}, @@ -347,7 +347,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, { @@ -362,11 +362,11 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Trader: "invalid", }, }}, diff --git a/x/stablecoin/abci.go b/x/stablecoin/abci.go index 0006d9515..2a89d6da0 100644 --- a/x/stablecoin/abci.go +++ b/x/stablecoin/abci.go @@ -20,7 +20,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { k.SetParams(ctx, params) } - _, err := k.OracleKeeper.GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) + _, err := k.OracleKeeper.GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { params := k.GetParams(ctx) diff --git a/x/stablecoin/abci_test.go b/x/stablecoin/abci_test.go index 6b0f608c3..30e1ce592 100644 --- a/x/stablecoin/abci_test.go +++ b/x/stablecoin/abci_test.go @@ -39,7 +39,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second * 60 * 16)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -53,7 +53,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second * 60 * 16)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -83,11 +83,11 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*15)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*30)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -101,11 +101,11 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*14)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*16)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), price) + app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -142,7 +142,7 @@ func TestEpochInfoChangesCollateralValidity(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) pairs := common.AssetPairs{ - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), } params := otypes.DefaultParams() params.TwapLookbackWindow = 1 * time.Hour diff --git a/x/stablecoin/client/cli/cli_test.go b/x/stablecoin/client/cli/cli_test.go index 6a60295b2..f7903cb68 100644 --- a/x/stablecoin/client/cli/cli_test.go +++ b/x/stablecoin/client/cli/cli_test.go @@ -50,13 +50,13 @@ func (s *IntegrationTestSuite) SetupSuite() { // x/stablecoin genesis state stableGen := stabletypes.DefaultGenesis() stableGen.Params.IsCollateralRatioValid = true - stableGen.ModuleAccountBalance = sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(10000*common.Precision)) + stableGen.ModuleAccountBalance = sdk.NewCoin(denoms.USDC, sdk.NewInt(10000*common.Precision)) genesisState[stabletypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(stableGen) oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(10)}, - {Pair: common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(1)}, + {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDec(10)}, + {Pair: common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), ExchangeRate: sdk.NewDec(1)}, } oracleGenesis.Params.VotePeriod = 1_000 @@ -81,8 +81,8 @@ func (s IntegrationTestSuite) TestMintStableCmd() { s.NoError(testutilcli.FillWalletFromValidator( minter, sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 100*common.Precision), - sdk.NewInt64Coin(denoms.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 100*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 100*common.Precision), ), val, s.cfg.BondDenom, @@ -91,7 +91,7 @@ func (s IntegrationTestSuite) TestMintStableCmd() { commonArgs := []string{ fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(denoms.NIBI, sdk.NewInt(10))).String()), } testCases := []struct { @@ -143,7 +143,7 @@ func (s IntegrationTestSuite) TestMintStableCmd() { s.NoError(err) s.Require().Equal( - balRes.Balances.AmountOf(denoms.DenomNUSD), tc.expectedStable) + balRes.Balances.AmountOf(denoms.NUSD), tc.expectedStable) } }) } @@ -156,7 +156,7 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { burner, sdk.NewCoins( sdk.NewInt64Coin(s.cfg.BondDenom, 20_000), - sdk.NewInt64Coin(denoms.DenomNUSD, 50*common.Precision), + sdk.NewInt64Coin(denoms.NUSD, 50*common.Precision), ), val, s.cfg.BondDenom, @@ -164,7 +164,7 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { s.NoError(s.network.WaitForNextBlock()) - defaultBondCoinsString := sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10))).String() + defaultBondCoinsString := sdk.NewCoins(sdk.NewCoin(denoms.NIBI, sdk.NewInt(10))).String() commonArgs := []string{ fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), @@ -192,8 +192,8 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { expectedStable: sdk.ZeroInt(), expectedColl: sdk.NewInt(50*common.Precision - 100_000), // Collateral minus 0,02% fees expectedGov: sdk.NewInt(19_990), - expectedTreasury: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 50_000)), - expectedEf: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 50_000)), + expectedTreasury: sdk.NewCoins(sdk.NewInt64Coin(denoms.USDC, 50_000)), + expectedEf: sdk.NewCoins(sdk.NewInt64Coin(denoms.USDC, 50_000)), expectErr: false, respType: &sdk.TxResponse{}, expectedCode: 0, @@ -242,11 +242,11 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { s.NoError(err) s.Require().Equal( - tc.expectedColl, balRes.Balances.AmountOf(denoms.DenomUSDC)) + tc.expectedColl, balRes.Balances.AmountOf(denoms.USDC)) s.Require().Equal( - tc.expectedGov, balRes.Balances.AmountOf(denoms.DenomNIBI)) + tc.expectedGov, balRes.Balances.AmountOf(denoms.NIBI)) s.Require().Equal( - tc.expectedStable, balRes.Balances.AmountOf(denoms.DenomNUSD)) + tc.expectedStable, balRes.Balances.AmountOf(denoms.NUSD)) // Query treasury pool balance resp, err = banktestutil.QueryBalancesExec( diff --git a/x/stablecoin/genesis_test.go b/x/stablecoin/genesis_test.go index a911e7be7..4f9e8e4c0 100644 --- a/x/stablecoin/genesis_test.go +++ b/x/stablecoin/genesis_test.go @@ -18,7 +18,7 @@ import ( func TestGenesis(t *testing.T) { genesisState := types.GenesisState{ Params: types.DefaultParams(), - ModuleAccountBalance: sdk.NewCoin(denoms.DenomUSDC, sdk.ZeroInt()), + ModuleAccountBalance: sdk.NewCoin(denoms.USDC, sdk.ZeroInt()), } nibiruApp, ctx := simapp.NewTestNibiruAppAndContext(true) diff --git a/x/stablecoin/keeper/collateral_ratio.go b/x/stablecoin/keeper/collateral_ratio.go index ca5a1435c..ad786c250 100644 --- a/x/stablecoin/keeper/collateral_ratio.go +++ b/x/stablecoin/keeper/collateral_ratio.go @@ -87,7 +87,7 @@ func (k *Keeper) EvaluateCollRatio(ctx sdk.Context) (err error) { upperBound := params.GetPriceUpperBoundAsDec() stablePrice, err := k.OracleKeeper.GetExchangeRateTwap( - ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return err } @@ -114,14 +114,14 @@ func (k *Keeper) StableRequiredForTargetCollRatio( targetCollRatio := k.GetCollRatio(ctx) moduleAddr := k.AccountKeeper.GetModuleAddress(types.ModuleName) moduleCoins := k.BankKeeper.SpendableCoins(ctx, moduleAddr) - collDenoms := []string{denoms.DenomUSDC} + collDenoms := []string{denoms.USDC} currentTotalCollUSD := sdk.ZeroDec() for _, collDenom := range collDenoms { amtColl := moduleCoins.AmountOf(collDenom) priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.ZeroDec(), err } @@ -139,7 +139,7 @@ func (k *Keeper) RecollateralizeCollAmtForTargetCollRatio( ) (neededCollAmount sdk.Int, err error) { neededUSDForRecoll, _ := k.StableRequiredForTargetCollRatio(ctx) priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -223,7 +223,7 @@ func (k Keeper) Recollateralize( // Compute GOV rewarded to user priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return response, err } @@ -232,7 +232,7 @@ func (k Keeper) Recollateralize( if err != nil { return response, err } - outGov := sdk.NewCoin(denoms.DenomNIBI, outGovAmount) + outGov := sdk.NewCoin(denoms.NIBI, outGovAmount) // Mint and send GOV reward from the module to the caller err = k.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(outGov)) @@ -294,7 +294,7 @@ func (k *Keeper) GovAmtFromRecollateralize( bonusRate := params.GetBonusRateRecollAsDec() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -337,7 +337,7 @@ func (k *Keeper) BuybackGovAmtForTargetCollRatio( neededUSDForRecoll, _ := k.StableRequiredForTargetCollRatio(ctx) neededUSDForBuyback := neededUSDForRecoll.Neg() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -414,7 +414,7 @@ func (k Keeper) Buyback( // Compute USD (stable) value of the GOV sent by the caller: 'inUSD' priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return response, err } @@ -425,7 +425,7 @@ func (k Keeper) Buyback( if err != nil { return response, err } - outColl := sdk.NewCoin(denoms.DenomUSDC, outCollAmount) + outColl := sdk.NewCoin(denoms.USDC, outCollAmount) // Send COLL from the module to the caller err = k.BankKeeper.SendCoinsFromModuleToAccount( @@ -474,7 +474,7 @@ func (k *Keeper) CollAmtFromBuyback( ctx sdk.Context, valUSD sdk.Dec, ) (collAmt sdk.Int, err error) { priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.Int{}, err } diff --git a/x/stablecoin/keeper/collateral_ratio_test.go b/x/stablecoin/keeper/collateral_ratio_test.go index ce99ce643..3c54d75cb 100644 --- a/x/stablecoin/keeper/collateral_ratio_test.go +++ b/x/stablecoin/keeper/collateral_ratio_test.go @@ -82,7 +82,7 @@ func TestSetCollRatioUpdate(t *testing.T) { stablecoinKeeper := &nibiruApp.StablecoinKeeper oracleKeeper := &nibiruApp.OracleKeeper - oracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), tc.price) + oracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.price) err := stablecoinKeeper.SetCollRatio(ctx, tc.inCollRatio) require.NoError(t, err) err = stablecoinKeeper.EvaluateCollRatio(ctx) @@ -179,7 +179,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(500), priceCollStable: sdk.OneDec(), // startCollUSD = 500 * 1 -> 500 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 @@ -190,7 +190,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(600), priceCollStable: sdk.OneDec(), // startCollUSD = 600 * 1 = 600 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.5"), // 0.5 * 1000 = 500 @@ -216,14 +216,14 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, tc.protocolColl), - sdk.NewCoin(denoms.DenomNUSD, tc.stableSupply), + sdk.NewCoin(denoms.USDC, tc.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.stableSupply), ), )) // Post prices to each specified market with the oracle. prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.priceCollStable, + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -290,13 +290,13 @@ func TestRecollateralizeCollAmtForTargetCollRatio(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, tc.protocolColl), - sdk.NewCoin(denoms.DenomNUSD, tc.stableSupply), + sdk.NewCoin(denoms.USDC, tc.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.stableSupply), ), )) // Post the price - pair := common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD) nibiruApp.OracleKeeper.SetPrice(ctx, pair, tc.priceCollStable) neededCollAmount, err := stablecoinKeeper.RecollateralizeCollAmtForTargetCollRatio(ctx) @@ -329,13 +329,13 @@ func TestRecollateralizeCollAmtForTargetCollRatio(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, tc.protocolColl), - sdk.NewCoin(denoms.DenomNUSD, tc.stableSupply), + sdk.NewCoin(denoms.USDC, tc.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.stableSupply), ), )) // Post the price - // pair := common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD) + // pair := common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD) // nibiruApp.OracleKeeper.SetPrice(ctx, pair, tc.priceCollStable) neededCollAmount, err := stablecoinKeeper.RecollateralizeCollAmtForTargetCollRatio(ctx) @@ -378,7 +378,7 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 priceCollStable: sdk.OneDec(), postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)}, + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -389,7 +389,7 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 priceGovStable: sdk.OneDec(), postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)}, + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -399,8 +399,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(10_000), targetCollRatio: sdk.MustNewDecFromStr("0.7"), // 0.7 * 10_000 = 7_000 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(2), @@ -415,8 +415,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(100_000), targetCollRatio: sdk.MustNewDecFromStr("0.7"), // 0.7 * 100_000 = 70_000 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -431,8 +431,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(100_000), targetCollRatio: sdk.MustNewDecFromStr("0.5"), // 0.5 * 100_000 = 50_000 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -451,14 +451,14 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.targetCollRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, tc.protocolColl), - sdk.NewCoin(denoms.DenomNUSD, tc.stableSupply), + sdk.NewCoin(denoms.USDC, tc.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.stableSupply), ), )) prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.priceCollStable, + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -466,8 +466,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { // Post prices to each specified market with the oracle. prices = map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.priceCollStable, - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, } for _, assetPair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, assetPair, prices[assetPair]) @@ -519,8 +519,8 @@ func TestRecollateralize(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -531,13 +531,13 @@ func TestRecollateralize(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomUSDC, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(100_000), msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(100_000)), + Coll: sdk.NewCoin(denoms.USDC, sdk.NewInt(100_000)), }, response: &types.MsgRecollateralizeResponse{ /* @@ -545,15 +545,15 @@ func TestRecollateralize(t *testing.T) { = 100_000 * (1.002) / priceGovStable = 100_200 / priceGovStable */ - Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_200)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(100_200)), }, expectedPass: true, }, { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -564,13 +564,13 @@ func TestRecollateralize(t *testing.T) { }, priceGovStable: sdk.NewDec(5), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomUSDC, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 1_000*common.Precision), ), expectedNeededUSD: sdk.MustNewDecFromStr("150000.5"), msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(50_000)), + Coll: sdk.NewCoin(denoms.USDC, sdk.NewInt(50_000)), }, response: &types.MsgRecollateralizeResponse{ /* @@ -580,15 +580,15 @@ func TestRecollateralize(t *testing.T) { = 55109.9499 / priceGovStable = 11021.98998 -> 11_021 */ - Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(11_021)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(11_021)), }, expectedPass: true, }, { name: "protocol has sufficient collateral - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -600,13 +600,13 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("-49.9995"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomUSDC, 1*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 1*common.Precision), ), // Since 'neededUSD' is msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(100)), + Coll: sdk.NewCoin(denoms.USDC, sdk.NewInt(100)), }, expectedPass: false, err: fmt.Errorf("protocol has sufficient COLL"), @@ -614,8 +614,8 @@ func TestRecollateralize(t *testing.T) { { name: "caller is broke - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -627,13 +627,13 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("150"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomUSDC, 99), + sdk.NewInt64Coin(denoms.USDC, 99), ), // Since 'neededUSD' is msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(200)), + Coll: sdk.NewCoin(denoms.USDC, sdk.NewInt(200)), }, expectedPass: false, err: fmt.Errorf("Not enough balance"), @@ -641,8 +641,8 @@ func TestRecollateralize(t *testing.T) { { name: "negative msg.Coll.Amount - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -654,21 +654,21 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("400"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomUSDC, 400), + sdk.NewInt64Coin(denoms.USDC, 400), ), msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.Coin{Denom: denoms.DenomUSDC, Amount: sdk.NewInt(-200)}, + Coll: sdk.Coin{Denom: denoms.USDC, Amount: sdk.NewInt(-200)}, }, expectedPass: false, err: fmt.Errorf( - "collateral input, -200%v, must be positive", denoms.DenomUSDC), + "collateral input, -200%v, must be positive", denoms.USDC), }, { name: "oracle prices are expired - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -680,11 +680,11 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("400"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomUSDC, 400), + sdk.NewInt64Coin(denoms.USDC, 400), ), msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewInt64Coin(denoms.DenomUSDC, 400), + Coll: sdk.NewInt64Coin(denoms.USDC, 400), }, expectedPass: false, @@ -702,8 +702,8 @@ func TestRecollateralize(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.scenario.collRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, tc.scenario.protocolColl), - sdk.NewCoin(denoms.DenomNUSD, tc.scenario.stableSupply), + sdk.NewCoin(denoms.USDC, tc.scenario.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.scenario.stableSupply), ), )) // Fund account @@ -717,8 +717,8 @@ func TestRecollateralize(t *testing.T) { } prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.scenario.priceCollStable, + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -726,8 +726,8 @@ func TestRecollateralize(t *testing.T) { // Post prices to each specified market with the oracle. prices = map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.scenario.priceCollStable, - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, } for _, assetPair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, assetPair, prices[assetPair]) @@ -773,7 +773,7 @@ func TestRecollateralize_Short(t *testing.T) { sender := testutil.AccAddress() msg := &types.MsgRecollateralize{ Creator: sender.String(), - Coll: sdk.NewInt64Coin(denoms.DenomUSDC, 100), + Coll: sdk.NewInt64Coin(denoms.USDC, 100), } _, err := nibiruApp.StablecoinKeeper.Recollateralize(goCtx, msg) require.ErrorContains(t, err, "collections: not found") @@ -850,8 +850,8 @@ func TestBuyback(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -862,32 +862,32 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 1*common.Precision), ), expectedAccFundsAfter: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 900_000), // accFunds - inGov.Amount - sdk.NewInt64Coin(denoms.DenomUSDC, 100_000), // response.Coll + sdk.NewInt64Coin(denoms.NIBI, 900_000), // accFunds - inGov.Amount + sdk.NewInt64Coin(denoms.USDC, 100_000), // response.Coll ), expectedNeededUSD: sdk.NewDec(-100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{ /* Coll.Amount = inUSD * / priceCollStable = 100_000 / priceCollStable */ - Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(100_000)), + Coll: sdk.NewCoin(denoms.USDC, sdk.NewInt(100_000)), }, expectedPass: true, }, { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(850_000), @@ -898,17 +898,17 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.NewDec(5), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 1*common.Precision), ), expectedAccFundsAfter: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 953_000), // accFunds - inGov.Amount - sdk.NewInt64Coin(denoms.DenomUSDC, 213_636), // response.Coll + sdk.NewInt64Coin(denoms.NIBI, 953_000), // accFunds - inGov.Amount + sdk.NewInt64Coin(denoms.USDC, 213_636), // response.Coll ), expectedNeededUSD: sdk.MustNewDecFromStr("-234999.15"), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(50_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(50_000)), }, response: &types.MsgBuybackResponse{ /* @@ -920,15 +920,15 @@ func TestBuyback(t *testing.T) { = 47000 * 5 / 1.099999 = 213636.55785141626 -> 213_636 */ - Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(213_636)), + Coll: sdk.NewCoin(denoms.USDC, sdk.NewInt(213_636)), }, expectedPass: true, }, { name: "msg has more NIBI than the protocol needs, only needed sent", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -939,29 +939,29 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 1*common.Precision), ), expectedAccFundsAfter: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 900_000), // accFunds - inGov.Amount - sdk.NewInt64Coin(denoms.DenomUSDC, 100_000), // response.Coll + sdk.NewInt64Coin(denoms.NIBI, 900_000), // accFunds - inGov.Amount + sdk.NewInt64Coin(denoms.USDC, 100_000), // response.Coll ), expectedNeededUSD: sdk.NewDec(-100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(200_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(200_000)), }, response: &types.MsgBuybackResponse{ // Coll.Amount = inUSD * / priceCollStable - Coll: sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(100_000)), + Coll: sdk.NewCoin(denoms.USDC, sdk.NewInt(100_000)), }, expectedPass: true, }, { name: "protocol under-collateralized, so buyback won't run", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -972,13 +972,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -986,8 +986,8 @@ func TestBuyback(t *testing.T) { { name: "caller has insufficient funds", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -998,13 +998,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1), + sdk.NewInt64Coin(denoms.NIBI, 1), ), expectedNeededUSD: sdk.NewDec(-100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -1012,7 +1012,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing collateral price post", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1023,13 +1023,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(-100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -1037,7 +1037,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing NIBI price post", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1048,13 +1048,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(-100_000), msg: types.MsgBuyback{ Creator: testutil.AccAddress().String(), - Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -1073,8 +1073,8 @@ func TestBuyback(t *testing.T) { // Fund module account based on scenario require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, tc.scenario.protocolColl), - sdk.NewCoin(denoms.DenomNUSD, tc.scenario.stableSupply), + sdk.NewCoin(denoms.USDC, tc.scenario.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.scenario.stableSupply), ), )) @@ -1090,8 +1090,8 @@ func TestBuyback(t *testing.T) { // Set up markets for the oracle keeper. prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.scenario.priceCollStable, + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -1132,8 +1132,8 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, correct amount out", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1163,7 +1163,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, only coll price posted", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1186,14 +1186,14 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { require.NoError(t, stablecoinKeeper.SetCollRatio(ctx, tc.scenario.collRatio)) require.NoError(t, nibiruApp.BankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, tc.scenario.protocolColl), - sdk.NewCoin(denoms.DenomNUSD, tc.scenario.stableSupply), + sdk.NewCoin(denoms.USDC, tc.scenario.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.scenario.stableSupply), ), )) prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): tc.priceGovStable, - common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD): tc.scenario.priceCollStable, + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) diff --git a/x/stablecoin/keeper/keeper.go b/x/stablecoin/keeper/keeper.go index 391af97d5..591e553df 100644 --- a/x/stablecoin/keeper/keeper.go +++ b/x/stablecoin/keeper/keeper.go @@ -67,7 +67,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { // GetModuleAccountBalance gets the airdrop coin balance of module account. func (k Keeper) GetModuleAccountBalance(ctx sdk.Context) sdk.Coin { moduleAccAddr := k.AccountKeeper.GetModuleAddress(types.ModuleName) - return k.BankKeeper.GetBalance(ctx, moduleAccAddr, denoms.DenomNIBI) + return k.BankKeeper.GetBalance(ctx, moduleAccAddr, denoms.NIBI) } // GetParams get all parameters as types.Params diff --git a/x/stablecoin/keeper/mint_burn_stable.go b/x/stablecoin/keeper/mint_burn_stable.go index 590a4ca88..14fe14400 100644 --- a/x/stablecoin/keeper/mint_burn_stable.go +++ b/x/stablecoin/keeper/mint_burn_stable.go @@ -94,16 +94,16 @@ func (k Keeper) calcNeededGovAndFees( ctx sdk.Context, stable sdk.Coin, govRatio sdk.Dec, feeRatio sdk.Dec, ) (sdk.Coin, sdk.Coin, error) { priceGov, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } neededGovUSD := stable.Amount.ToDec().Mul(govRatio) neededGovAmt := neededGovUSD.Quo(priceGov).TruncateInt() - neededGov := sdk.NewCoin(denoms.DenomNIBI, neededGovAmt) + neededGov := sdk.NewCoin(denoms.NIBI, neededGovAmt) govFeeAmt := neededGovAmt.ToDec().Mul(feeRatio).RoundInt() - govFee := sdk.NewCoin(denoms.DenomNIBI, govFeeAmt) + govFee := sdk.NewCoin(denoms.NIBI, govFeeAmt) return neededGov, govFee, nil } @@ -116,16 +116,16 @@ func (k Keeper) calcNeededCollateralAndFees( feeRatio sdk.Dec, ) (sdk.Coin, sdk.Coin, error) { priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD)) + ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } neededCollUSD := stable.Amount.ToDec().Mul(collRatio) neededCollAmt := neededCollUSD.Quo(priceColl).TruncateInt() - neededColl := sdk.NewCoin(denoms.DenomUSDC, neededCollAmt) + neededColl := sdk.NewCoin(denoms.USDC, neededCollAmt) collFeeAmt := neededCollAmt.ToDec().Mul(feeRatio).RoundInt() - collFee := sdk.NewCoin(denoms.DenomUSDC, collFeeAmt) + collFee := sdk.NewCoin(denoms.USDC, collFeeAmt) return neededColl, collFee, nil } @@ -253,7 +253,7 @@ func (k Keeper) splitAndSendFeesToEfAndTreasury( amountEf := c.Amount.ToDec().Mul(efFeeRatio).TruncateInt() amountTreasury := c.Amount.Sub(amountEf) - if c.Denom == denoms.DenomNIBI { + if c.Denom == denoms.NIBI { stableCoins := sdk.NewCoins(sdk.NewCoin(c.Denom, amountEf)) err := k.BankKeeper.SendCoinsFromAccountToModule( ctx, account, types.StableEFModuleAccount, stableCoins) diff --git a/x/stablecoin/keeper/mint_burn_stable_test.go b/x/stablecoin/keeper/mint_burn_stable_test.go index cc87ae087..18cb72763 100644 --- a/x/stablecoin/keeper/mint_burn_stable_test.go +++ b/x/stablecoin/keeper/mint_burn_stable_test.go @@ -55,10 +55,10 @@ func TestMsgMint_ValidateBasic(t *testing.T) { } func TestMsgMintStableResponse_HappyPath(t *testing.T) { - accFundsGovAmount := sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10_000)) - accFundsCollAmount := sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(900_000)) - neededGovFees := sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(20)) // 0.002 fee - neededCollFees := sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(1_800)) // 0.002 fee + accFundsGovAmount := sdk.NewCoin(denoms.NIBI, sdk.NewInt(10_000)) + accFundsCollAmount := sdk.NewCoin(denoms.USDC, sdk.NewInt(900_000)) + neededGovFees := sdk.NewCoin(denoms.NIBI, sdk.NewInt(20)) // 0.002 fee + neededCollFees := sdk.NewCoin(denoms.USDC, sdk.NewInt(1_800)) // 0.002 fee accFundsAmt := sdk.NewCoins( accFundsGovAmount.Add(neededGovFees), @@ -82,7 +82,7 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { accFunds: accFundsAmt, msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1*common.Precision)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(1*common.Precision)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), @@ -94,18 +94,18 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { accFunds: accFundsAmt, msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1*common.Precision)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(1*common.Precision)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1*common.Precision)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(1*common.Precision)), UsedCoins: sdk.NewCoins(accFundsCollAmount, accFundsGovAmount), FeesPayed: sdk.NewCoins(neededCollFees, neededGovFees), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), - supplyNIBI: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10)), + supplyNIBI: sdk.NewCoin(denoms.NIBI, sdk.NewInt(10)), // 10_000 - 20 (neededAmt - fees) - 10 (0.5 of fees from EFund are burned) - supplyNUSD: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1*common.Precision)), + supplyNUSD: sdk.NewCoin(denoms.NUSD, sdk.NewInt(1*common.Precision)), err: nil, isCollateralRatioValid: true, }, @@ -145,8 +145,8 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { ) // Post prices to each pair with the oracle. - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Fund account require.NoError(t, simapp.FundAccount(nibiruApp.BankKeeper, ctx, acc, tc.accFunds)) @@ -171,7 +171,7 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { ctx, nibiruApp.AccountKeeper.GetModuleAddress(types.StableEFModuleAccount), ) collFeesInEf := neededCollFees.Amount.ToDec().Mul(sdk.MustNewDecFromStr("0.5")).TruncateInt() - assert.Equal(t, sdk.NewCoins(sdk.NewCoin(denoms.DenomUSDC, collFeesInEf)), efModuleBalance) + assert.Equal(t, sdk.NewCoins(sdk.NewCoin(denoms.USDC, collFeesInEf)), efModuleBalance) // Check balances in Treasury treasuryModuleBalance := nibiruApp.BankKeeper. @@ -181,8 +181,8 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { assert.Equal( t, sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, collFeesInTreasury), - sdk.NewCoin(denoms.DenomNIBI, govFeesInTreasury), + sdk.NewCoin(denoms.USDC, collFeesInTreasury), + sdk.NewCoin(denoms.NIBI, govFeesInTreasury), ), treasuryModuleBalance, ) @@ -203,70 +203,70 @@ func TestMsgMintStableResponse_NotEnoughFunds(t *testing.T) { { name: "User has no GOV", accFunds: sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(9001)), - sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(0)), + sdk.NewCoin(denoms.USDC, sdk.NewInt(9001)), + sdk.NewCoin(denoms.NIBI, sdk.NewInt(0)), ), msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(100)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(100)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(0)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(0)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), - err: types.NotEnoughBalance.Wrap(denoms.DenomNIBI), + err: types.NotEnoughBalance.Wrap(denoms.NIBI), }, { name: "User has no COLL", accFunds: sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(0)), - sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(9001)), + sdk.NewCoin(denoms.USDC, sdk.NewInt(0)), + sdk.NewCoin(denoms.NIBI, sdk.NewInt(9001)), ), msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(100)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(100)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(0)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(0)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), - err: types.NotEnoughBalance.Wrap(denoms.DenomUSDC), + err: types.NotEnoughBalance.Wrap(denoms.USDC), }, { name: "Not enough GOV", accFunds: sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(9001)), - sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(1)), + sdk.NewCoin(denoms.USDC, sdk.NewInt(9001)), + sdk.NewCoin(denoms.NIBI, sdk.NewInt(1)), ), msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1000)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(1000)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(0)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(0)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), err: types.NotEnoughBalance.Wrap( - sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(1)).String()), + sdk.NewCoin(denoms.NIBI, sdk.NewInt(1)).String()), }, { name: "Not enough COLL", accFunds: sdk.NewCoins( - sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(1)), - sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(9001)), + sdk.NewCoin(denoms.USDC, sdk.NewInt(1)), + sdk.NewCoin(denoms.NIBI, sdk.NewInt(9001)), ), msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(100)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(100)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(0)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(0)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), err: types.NotEnoughBalance.Wrap( - sdk.NewCoin(denoms.DenomUSDC, sdk.NewInt(1)).String()), + sdk.NewCoin(denoms.USDC, sdk.NewInt(1)).String()), }, } @@ -302,8 +302,8 @@ func TestMsgMintStableResponse_NotEnoughFunds(t *testing.T) { ) t.Log("Post prices to each pair with the oracle.") - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Fund account require.NoError(t, simapp.FundAccount(nibiruApp.BankKeeper, ctx, acc, tc.accFunds)) @@ -377,14 +377,14 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { }{ { name: "Not enough stable", - accFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNUSD, 10)), + accFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 10)), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(denoms.DenomNUSD, 9001), + Stable: sdk.NewInt64Coin(denoms.NUSD, 9001), }, msgResponse: &types.MsgBurnStableResponse{ - Collateral: sdk.NewCoin(denoms.DenomNIBI, sdk.ZeroInt()), - Gov: sdk.NewCoin(denoms.DenomUSDC, sdk.ZeroInt()), + Collateral: sdk.NewCoin(denoms.NIBI, sdk.ZeroInt()), + Gov: sdk.NewCoin(denoms.USDC, sdk.ZeroInt()), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), @@ -396,22 +396,22 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNUSD, 1000*common.Precision), + sdk.NewInt64Coin(denoms.NUSD, 1000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(denoms.DenomNUSD, sdk.ZeroInt()), + Stable: sdk.NewCoin(denoms.NUSD, sdk.ZeroInt()), }, msgResponse: &types.MsgBurnStableResponse{ - Gov: sdk.NewCoin(denoms.DenomNIBI, sdk.ZeroInt()), - Collateral: sdk.NewCoin(denoms.DenomUSDC, sdk.ZeroInt()), + Gov: sdk.NewCoin(denoms.NIBI, sdk.ZeroInt()), + Collateral: sdk.NewCoin(denoms.USDC, sdk.ZeroInt()), FeesPayed: sdk.NewCoins(), }, expectedPass: true, - err: types.NoCoinFound.Wrap(denoms.DenomNUSD).Error(), + err: types.NoCoinFound.Wrap(denoms.NUSD).Error(), }, } @@ -449,8 +449,8 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { nibiruApp.StablecoinKeeper.SetParams(ctx, defaultParams) t.Log("Post prices to each pair with the oracle.") - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Add collaterals to the module require.NoError(t, nibiruApp.BankKeeper.MintCoins(ctx, types.ModuleName, tc.moduleFunds)) @@ -495,17 +495,17 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNUSD, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.NUSD, 1_000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(denoms.DenomNUSD, 10*common.Precision), + Stable: sdk.NewInt64Coin(denoms.NUSD, 10*common.Precision), }, - ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 9000)), - treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 9000), sdk.NewInt64Coin(denoms.DenomNIBI, 100)), + ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.USDC, 9000)), + treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.USDC, 9000), sdk.NewInt64Coin(denoms.NIBI, 100)), expectedPass: false, isCollateralRatioValid: false, err: types.NoValidCollateralRatio, @@ -515,27 +515,27 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNUSD, 1_000*common.Precision), + sdk.NewInt64Coin(denoms.NUSD, 1_000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(denoms.DenomNUSD, 10*common.Precision), + Stable: sdk.NewInt64Coin(denoms.NUSD, 10*common.Precision), }, msgResponse: types.MsgBurnStableResponse{ - Gov: sdk.NewInt64Coin(denoms.DenomNIBI, 100_000-200), // amount - fees 0,02% - Collateral: sdk.NewInt64Coin(denoms.DenomUSDC, 9*common.Precision-18_000), // amount - fees 0,02% + Gov: sdk.NewInt64Coin(denoms.NIBI, 100_000-200), // amount - fees 0,02% + Collateral: sdk.NewInt64Coin(denoms.USDC, 9*common.Precision-18_000), // amount - fees 0,02% FeesPayed: sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 200), - sdk.NewInt64Coin(denoms.DenomUSDC, 18_000), + sdk.NewInt64Coin(denoms.NIBI, 200), + sdk.NewInt64Coin(denoms.USDC, 18_000), ), }, - supplyNIBI: sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(100_000-100)), // nibiru minus 0.5 of fees burned (the part that goes to EF) - supplyNUSD: sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(1_000*common.Precision-10*common.Precision)), - ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 9000)), - treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomUSDC, 9000), sdk.NewInt64Coin(denoms.DenomNIBI, 100)), + supplyNIBI: sdk.NewCoin(denoms.NIBI, sdk.NewInt(100_000-100)), // nibiru minus 0.5 of fees burned (the part that goes to EF) + supplyNUSD: sdk.NewCoin(denoms.NUSD, sdk.NewInt(1_000*common.Precision-10*common.Precision)), + ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.USDC, 9000)), + treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.USDC, 9000), sdk.NewInt64Coin(denoms.NIBI, 100)), expectedPass: true, isCollateralRatioValid: true, }, @@ -570,8 +570,8 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { ), ) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Add collaterals to the module require.NoError(t, nibiruApp.BankKeeper.MintCoins(ctx, types.ModuleName, tc.moduleFunds)) diff --git a/x/stablecoin/keeper/supply.go b/x/stablecoin/keeper/supply.go index b18d08a2a..5c55a8767 100644 --- a/x/stablecoin/keeper/supply.go +++ b/x/stablecoin/keeper/supply.go @@ -13,13 +13,13 @@ var LiquidityRatioBands = sdk.MustNewDecFromStr("0.001") func (k Keeper) GetSupplyNUSD( ctx sdk.Context, ) sdk.Coin { - return k.BankKeeper.GetSupply(ctx, denoms.DenomNUSD) + return k.BankKeeper.GetSupply(ctx, denoms.NUSD) } func (k Keeper) GetSupplyNIBI( ctx sdk.Context, ) sdk.Coin { - return k.BankKeeper.GetSupply(ctx, denoms.DenomNIBI) + return k.BankKeeper.GetSupply(ctx, denoms.NIBI) } func (k Keeper) GetStableMarketCap(ctx sdk.Context) sdk.Int { @@ -27,12 +27,12 @@ func (k Keeper) GetStableMarketCap(ctx sdk.Context) sdk.Int { } func (k Keeper) GetGovMarketCap(ctx sdk.Context) (sdk.Int, error) { - pool, err := k.DexKeeper.FetchPoolFromPair(ctx, denoms.DenomNIBI, denoms.DenomNUSD) + pool, err := k.DexKeeper.FetchPoolFromPair(ctx, denoms.NIBI, denoms.NUSD) if err != nil { return sdk.Int{}, err } - price, err := pool.CalcSpotPrice(denoms.DenomNIBI, denoms.DenomNUSD) + price, err := pool.CalcSpotPrice(denoms.NIBI, denoms.NUSD) if err != nil { return sdk.Int{}, err } diff --git a/x/stablecoin/keeper/supply_test.go b/x/stablecoin/keeper/supply_test.go index ef51cd76e..a61ee6660 100644 --- a/x/stablecoin/keeper/supply_test.go +++ b/x/stablecoin/keeper/supply_test.go @@ -23,7 +23,7 @@ func TestKeeper_GetStableMarketCap(t *testing.T) { // We set some supply err := k.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision), + sdk.NewInt64Coin(denoms.NUSD, 1*common.Precision), )) require.NoError(t, err) @@ -45,11 +45,11 @@ func TestKeeper_GetGovMarketCap(t *testing.T) { } poolAssets := []dextypes.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomNIBI, 2*common.Precision), + Token: sdk.NewInt64Coin(denoms.NIBI, 2*common.Precision), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision), + Token: sdk.NewInt64Coin(denoms.NUSD, 1*common.Precision), Weight: sdk.NewInt(100), }, } @@ -60,7 +60,7 @@ func TestKeeper_GetGovMarketCap(t *testing.T) { // We set some supply err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 1*common.Precision), )) require.NoError(t, err) @@ -82,11 +82,11 @@ func TestKeeper_GetLiquidityRatio_AndBands(t *testing.T) { } poolAssets := []dextypes.PoolAsset{ { - Token: sdk.NewInt64Coin(denoms.DenomNIBI, 2*common.Precision), + Token: sdk.NewInt64Coin(denoms.NIBI, 2*common.Precision), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision), + Token: sdk.NewInt64Coin(denoms.NUSD, 1*common.Precision), Weight: sdk.NewInt(100), }, } @@ -97,12 +97,12 @@ func TestKeeper_GetLiquidityRatio_AndBands(t *testing.T) { // We set some supply err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 1*common.Precision), )) require.NoError(t, err) err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(denoms.DenomNUSD, 1*common.Precision), + sdk.NewInt64Coin(denoms.NUSD, 1*common.Precision), )) require.NoError(t, err) diff --git a/x/stablecoin/simulation/msg.go b/x/stablecoin/simulation/msg.go index db3f8953e..e7509d7b5 100644 --- a/x/stablecoin/simulation/msg.go +++ b/x/stablecoin/simulation/msg.go @@ -23,7 +23,7 @@ func SimulateMsgMintStable( ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAcc, _ := simtypes.RandomAcc(r, accs) // How much stable should get minted? - simStable := sdk.NewCoin(denoms.DenomNUSD, sdk.NewInt(100)) + simStable := sdk.NewCoin(denoms.NUSD, sdk.NewInt(100)) msg := &types.MsgMintStable{ Creator: simAcc.Address.String(), Stable: simStable, diff --git a/x/stablecoin/types/genesis.go b/x/stablecoin/types/genesis.go index 8f933745a..bb41c9ceb 100644 --- a/x/stablecoin/types/genesis.go +++ b/x/stablecoin/types/genesis.go @@ -13,7 +13,7 @@ const DefaultIndex uint64 = 1 func DefaultGenesis() *GenesisState { return &GenesisState{ Params: DefaultParams(), - ModuleAccountBalance: sdk.NewCoin(denoms.DenomUSDC, sdk.ZeroInt()), + ModuleAccountBalance: sdk.NewCoin(denoms.USDC, sdk.ZeroInt()), } } diff --git a/x/testutil/cli/network.go b/x/testutil/cli/network.go index b5bf5e94b..b8a9483d0 100644 --- a/x/testutil/cli/network.go +++ b/x/testutil/cli/network.go @@ -143,15 +143,15 @@ func BuildNetworkConfig(appGenesis simapp.GenesisState) Config { TimeoutCommit: time.Second / 2, ChainID: "chain-" + tmrand.NewRand().Str(6), NumValidators: 1, - BondDenom: denoms.DenomNIBI, - MinGasPrices: fmt.Sprintf("0.000006%s", denoms.DenomNIBI), + BondDenom: denoms.NIBI, + MinGasPrices: fmt.Sprintf("0.000006%s", denoms.NIBI), AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), StartingTokens: sdk.NewCoins( - sdk.NewCoin(denoms.DenomNUSD, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), - sdk.NewCoin(denoms.DenomNIBI, sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)), - sdk.NewCoin(denoms.DenomUSDC, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.NUSD, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.NIBI, sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.USDC, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), ), PruningStrategy: storetypes.PruningOptionNothing, CleanupDir: true, diff --git a/x/testutil/cli/tx.go b/x/testutil/cli/tx.go index 964e5c10b..3a6b1ecdc 100644 --- a/x/testutil/cli/tx.go +++ b/x/testutil/cli/tx.go @@ -68,7 +68,7 @@ func ExecTx(network *Network, cmd *cobra.Command, txSender sdk.AccAddress, args args = append(args, fmt.Sprintf("--%s=%s", flags.FlagFrom, txSender)) options := execTxOptions{ - fees: sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10))), + fees: sdk.NewCoins(sdk.NewCoin(denoms.NIBI, sdk.NewInt(10))), gas: 2000000, skipConfirmation: true, broadcastMode: flags.BroadcastBlock, diff --git a/x/testutil/testapp/config.go b/x/testutil/testapp/config.go index e694f1236..a7595bf4c 100644 --- a/x/testutil/testapp/config.go +++ b/x/testutil/testapp/config.go @@ -34,15 +34,15 @@ func BuildNetworkConfig(appGenesis GenesisState) cli.Config { TimeoutCommit: time.Second / 2, ChainID: "chain-" + tmrand.NewRand().Str(6), NumValidators: 1, - BondDenom: denoms.DenomNIBI, - MinGasPrices: fmt.Sprintf("0.000006%s", denoms.DenomNIBI), + BondDenom: denoms.NIBI, + MinGasPrices: fmt.Sprintf("0.000006%s", denoms.NIBI), AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), StartingTokens: sdk.NewCoins( - sdk.NewCoin(denoms.DenomNUSD, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), - sdk.NewCoin(denoms.DenomNIBI, sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)), - sdk.NewCoin(denoms.DenomUSDC, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.NUSD, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.NIBI, sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)), + sdk.NewCoin(denoms.USDC, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), ), PruningStrategy: storetypes.PruningOptionNothing, CleanupDir: true, diff --git a/x/testutil/testapp/testapp.go b/x/testutil/testapp/testapp.go index 939249ddd..8ac6cf01c 100644 --- a/x/testutil/testapp/testapp.go +++ b/x/testutil/testapp/testapp.go @@ -119,7 +119,7 @@ func NewTestGenesisState(codec codec.Codec, inGenState GenesisState, var govGenState govtypes.GenesisState codec.MustUnmarshalJSON(testGenState[govtypes.ModuleName], &govGenState) govGenState.VotingParams.VotingPeriod = time.Second * 20 - govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(denoms.DenomNIBI, 1_000_000)) // min deposit of 1 NIBI + govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1_000_000)) // min deposit of 1 NIBI testGenState[govtypes.ModuleName] = codec.MustMarshalJSON(&govGenState) return testGenState diff --git a/x/vpool/abci_test.go b/x/vpool/abci_test.go index c5358c65f..efabc73ab 100644 --- a/x/vpool/abci_test.go +++ b/x/vpool/abci_test.go @@ -32,7 +32,7 @@ func TestSnapshotUpdates(t *testing.T) { require.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(1_000), sdk.NewDec(1_000), types.DefaultVpoolConfig(). @@ -40,7 +40,7 @@ func TestSnapshotUpdates(t *testing.T) { WithFluctuationLimitRatio(sdk.OneDec()), )) expectedSnapshot := types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(1_000), sdk.NewDec(1_000), ctx.BlockTime(), @@ -48,14 +48,14 @@ func TestSnapshotUpdates(t *testing.T) { t.Log("run one block of 5 seconds") runBlock(5 * time.Second) - snapshot, err := vpoolKeeper.ReserveSnapshots.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) + snapshot, err := vpoolKeeper.ReserveSnapshots.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) require.NoError(t, err) assert.EqualValues(t, expectedSnapshot, snapshot) t.Log("affect mark price") baseAmtAbs, err := vpoolKeeper.SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), types.Direction_ADD_TO_POOL, sdk.NewDec(250), // ← dyAmm sdk.ZeroDec(), @@ -65,7 +65,7 @@ func TestSnapshotUpdates(t *testing.T) { assert.EqualValues(t, sdk.NewDec(200), baseAmtAbs) require.NoError(t, err) expectedSnapshot = types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(800), // ← x + dxAmm sdk.NewDec(1_250), // ← y + dyAMM ctx.BlockTime(), @@ -76,7 +76,7 @@ func TestSnapshotUpdates(t *testing.T) { timeSkipDuration := 5 * time.Second runBlock(timeSkipDuration) // increments ctx.blockHeight and ctx.BlockTime snapshot, err = vpoolKeeper.ReserveSnapshots.Get(ctx, - collections.Join(common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) + collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) require.NoError(t, err) assert.EqualValues(t, expectedSnapshot, snapshot) diff --git a/x/vpool/client/cli/cli_test.go b/x/vpool/client/cli/cli_test.go index abf6161ff..a3d1e2987 100644 --- a/x/vpool/client/cli/cli_test.go +++ b/x/vpool/client/cli/cli_test.go @@ -35,8 +35,8 @@ func TestIntegrationTestSuite(t *testing.T) { } var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD): { - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD): { + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -47,8 +47,8 @@ var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ MaxLeverage: sdk.MustNewDecFromStr("15"), }, }, - common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD): { - Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): { + Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), BaseAssetReserve: sdk.NewDec(500_000), QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -74,14 +74,14 @@ func (s *IntegrationTestSuite) SetupSuite() { genesisState := simapp.NewTestGenesisStateFromDefault() vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ - START_VPOOLS[common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)], - START_VPOOLS[common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)], + START_VPOOLS[common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)], + START_VPOOLS[common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)], } oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(1_000)}, - {Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), ExchangeRate: sdk.NewDec(10)}, + {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDec(1_000)}, + {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDec(10)}, } oracleGenesis.Params.VotePeriod = 1_000 @@ -169,13 +169,13 @@ func (s *IntegrationTestSuite) TestGetPrices() { val := s.network.Validators[0] s.T().Log("check vpool balances") - reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)) + reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("10000000"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.MustNewDecFromStr("60000000000"), reserveAssets.QuoteAssetReserve) s.T().Log("check prices") - priceInfo, err := testutilcli.QueryBaseAssetPrice(val.ClientCtx, common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), "add", "100") + priceInfo, err := testutilcli.QueryBaseAssetPrice(val.ClientCtx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), "add", "100") s.T().Logf("priceInfo: %+v", priceInfo) s.EqualValues(sdk.MustNewDecFromStr("599994.000059999400006000"), priceInfo.PriceInQuoteDenom) s.NoError(err) @@ -187,7 +187,7 @@ func (s *IntegrationTestSuite) TestCmdEditPoolConfigProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD)] + startVpool := START_VPOOLS[common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)] proposal := &vpooltypes.EditPoolConfigProposal{ Title: "NIP-3: Edit config of the ueth:unusd vpool", Description: "enables higher max leverage on ueth:unusd", @@ -253,7 +253,7 @@ func (s *IntegrationTestSuite) TestCmdEditSwapInvariantsProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD)] + startVpool := START_VPOOLS[common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)] proposal := &vpooltypes.EditSwapInvariantsProposal{ Title: "NIP-4: Change the swap invariant for ATOM, OSMO, and BTC.", Description: "increase swap invariant for many virtual pools", diff --git a/x/vpool/keeper/keeper_test.go b/x/vpool/keeper/keeper_test.go index af9a0749e..f6a83a714 100644 --- a/x/vpool/keeper/keeper_test.go +++ b/x/vpool/keeper/keeper_test.go @@ -33,7 +33,7 @@ func TestSwapQuoteForBase(t *testing.T) { }{ { name: "quote amount == 0", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(0), baseLimit: sdk.NewDec(10), @@ -45,7 +45,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap add", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(49504), @@ -57,7 +57,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap remove", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(50506), @@ -79,7 +79,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount less than base limit in Long", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(500_000), baseLimit: sdk.NewDec(454_500), @@ -89,7 +89,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount more than base limit in Short", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_500), @@ -99,7 +99,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when removing quote", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -109,7 +109,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when adding quote", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -119,7 +119,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), @@ -129,7 +129,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), @@ -139,7 +139,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), @@ -151,7 +151,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), @@ -173,7 +173,7 @@ func TestSwapQuoteForBase(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ @@ -201,7 +201,7 @@ func TestSwapQuoteForBase(t *testing.T) { assert.EqualValuesf(t, tc.expectedBaseAmount, baseAmt, "base amount mismatch") t.Log("assert vpool") - pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) assert.EqualValuesf(t, tc.expectedQuoteReserve, pool.QuoteAssetReserve, "pool quote asset reserve mismatch") assert.EqualValuesf(t, tc.expectedBaseReserve, pool.BaseAssetReserve, "pool base asset reserve mismatch") @@ -226,7 +226,7 @@ func TestSwapBaseForQuote(t *testing.T) { }{ { name: "zero base asset swap", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.ZeroDec(), quoteLimit: sdk.ZeroDec(), @@ -238,7 +238,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "add base asset swap", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196078), @@ -250,7 +250,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "remove base asset", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(204_082), @@ -272,7 +272,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount less than quote limit in Long", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196079), @@ -282,7 +282,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount more than quote limit in Short", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(204_081), @@ -292,7 +292,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when removing base", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -302,7 +302,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when adding base", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -312,7 +312,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), @@ -322,7 +322,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), @@ -332,7 +332,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), @@ -344,7 +344,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), @@ -366,7 +366,7 @@ func TestSwapBaseForQuote(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ @@ -395,7 +395,7 @@ func TestSwapBaseForQuote(t *testing.T) { "expected %s; got %s", tc.expectedQuoteAssetAmount.String(), quoteAssetAmount.String()) t.Log("assert pool") - pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) assert.Equal(t, tc.expectedQuoteReserve, pool.QuoteAssetReserve) assert.Equal(t, tc.expectedBaseReserve, pool.BaseAssetReserve) @@ -411,7 +411,7 @@ func TestGetVpools(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), sdk.NewDec(5*common.Precision), types.VpoolConfig{ @@ -424,7 +424,7 @@ func TestGetVpools(t *testing.T) { )) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), sdk.NewDec(5*common.Precision), sdk.NewDec(10*common.Precision), types.VpoolConfig{ @@ -441,7 +441,7 @@ func TestGetVpools(t *testing.T) { require.EqualValues(t, 2, len(pools)) require.EqualValues(t, pools[0], types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(5 * common.Precision), QuoteAssetReserve: sdk.NewDec(10 * common.Precision), Config: types.VpoolConfig{ @@ -453,7 +453,7 @@ func TestGetVpools(t *testing.T) { }, }) require.EqualValues(t, pools[1], types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: types.VpoolConfig{ @@ -477,7 +477,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses latest snapshot - does not result in error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -490,13 +490,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -507,7 +507,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses previous snapshot - results in error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -520,7 +520,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -531,7 +531,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "only one snapshot - no error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -544,7 +544,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -555,7 +555,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "zero fluctuation limit - no error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -568,13 +568,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -585,7 +585,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "multiple pools - no overlap", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -598,25 +598,25 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(denoms.DenomUSDC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -667,7 +667,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -678,7 +678,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -695,7 +695,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { mock.NewMockOracleKeeper(gomock.NewController(t)), ) vpoolKeeper.Pools.Insert(ctx, tc.pool.Pair, tc.pool) - mmr, err := vpoolKeeper.GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + mmr, err := vpoolKeeper.GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) assert.NoError(t, err) assert.EqualValues(t, tc.expectedMaintenanceMarginRatio, mmr) }) @@ -712,7 +712,7 @@ func TestGetMaxLeverage(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -735,7 +735,7 @@ func TestGetMaxLeverage(t *testing.T) { ) vpoolKeeper.Pools.Insert(ctx, tc.pool.Pair, tc.pool) - maxLeverage, err := vpoolKeeper.GetMaxLeverage(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + maxLeverage, err := vpoolKeeper.GetMaxLeverage(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) assert.EqualValues(t, tc.expectedMaxLeverage, maxLeverage) assert.NoError(t, err) }) diff --git a/x/vpool/keeper/pool_state_test.go b/x/vpool/keeper/pool_state_test.go index 1e36f8e58..58b7aeec8 100644 --- a/x/vpool/keeper/pool_state_test.go +++ b/x/vpool/keeper/pool_state_test.go @@ -19,7 +19,7 @@ func TestCreatePool(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens @@ -32,7 +32,7 @@ func TestCreatePool(t *testing.T) { }, )) - exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.True(t, exists) notExist := vpoolKeeper.ExistsPool(ctx, "BTC:OTHER") @@ -40,7 +40,7 @@ func TestCreatePool(t *testing.T) { } func TestEditPoolConfig(t *testing.T) { - pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) vpoolStart := types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(10 * common.Precision), @@ -58,12 +58,12 @@ func TestEditPoolConfig(t *testing.T) { vpoolKeeper, _, ctx := getKeeper(t) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpoolStart.QuoteAssetReserve, vpoolStart.BaseAssetReserve, vpoolStart.Config, )) - exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD)) + exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.True(t, exists) return vpoolKeeper, ctx } @@ -189,7 +189,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool + pricefeed active", vpool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -203,7 +203,7 @@ func TestGetPoolPrices(t *testing.T) { shouldCreateVpool: true, mockIndexPrice: sdk.NewDec(99), expectedPoolPrices: types.PoolPrices{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.NewDec(99).String(), @@ -214,7 +214,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool active, but no index price", vpool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -229,7 +229,7 @@ func TestGetPoolPrices(t *testing.T) { mockIndexPrice: sdk.OneDec().Neg(), oracleKeeperErr: fmt.Errorf("No index price"), expectedPoolPrices: types.PoolPrices{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.OneDec().Neg().String(), @@ -240,7 +240,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "vpool doesn't exist", vpool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -293,7 +293,7 @@ func TestGetPoolPrices(t *testing.T) { } func TestEditSwapInvariant(t *testing.T) { - pair := common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD) vpoolStart := types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(10 * common.Precision), diff --git a/x/vpool/keeper/prices_test.go b/x/vpool/keeper/prices_test.go index 229d17661..df38197bc 100644 --- a/x/vpool/keeper/prices_test.go +++ b/x/vpool/keeper/prices_test.go @@ -27,14 +27,14 @@ func TestGetMarkPrice(t *testing.T) { }{ { name: "correctly fetch underlying price", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(1), expectedPrice: sdk.NewDec(40000), }, { name: "complex price", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(2_489_723_947), baseAssetReserve: sdk.NewDec(34_597_234), expectedPrice: sdk.MustNewDecFromStr("71.963092396345904415"), @@ -81,7 +81,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), baseAmount: sdk.ZeroDec(), @@ -90,7 +90,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -99,7 +99,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -108,7 +108,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("1000"), @@ -164,7 +164,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), quoteAmount: sdk.ZeroDec(), @@ -173,7 +173,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -182,7 +182,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -191,7 +191,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(1000), @@ -253,22 +253,22 @@ func TestCalcTwap(t *testing.T) { // expected price: ((95/10 * (35 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 10) + 100/1 * (10 - 5)) / (5 + 10 + 10 + 5) { name: "spot price twap calc, t=[5,35]", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -284,22 +284,22 @@ func TestCalcTwap(t *testing.T) { // expected price: (95/10 * (30 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 10)) / (10 + 10) { name: "spot price twap calc, t=[10,30]", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -315,22 +315,22 @@ func TestCalcTwap(t *testing.T) { // expected price: (95/10 * (35 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 11)) / (5 + 10 + 9) { name: "spot price twap calc, t=[11,35]", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -348,7 +348,7 @@ func TestCalcTwap(t *testing.T) { // expected price: 100/1 { name: "spot price twap calc, t=[0,0]", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{}, currentBlockTime: time.UnixMilli(0), currentBlockHeight: 1, @@ -362,16 +362,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((7.5 - 300/(40 + 10)) * (30 - 20) + (10 - 300/(30 + 10)) * (20 - 10)) / (10 + 10) { name: "quote asset swap twap calc, add to pool, t=[10,30]", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(30), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.MustNewDecFromStr("7.5"), sdk.NewDec(40), time.UnixMilli(20), @@ -391,16 +391,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((12 - 600/(50 - 10)) * (30 - 20) + (10 - 600/(60 - 10)) * (20 - 10)) / (10 + 10) { name: "quote asset swap twap calc, remove from pool, t=[10,30]", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(12), sdk.NewDec(50), time.UnixMilli(20), @@ -416,10 +416,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: quote asset reserve = asset amount", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(20), time.UnixMilli(20), @@ -439,16 +439,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((60 - 600/(10 + 10)) * (20 - 10) + (30 - 600/(20 + 10)) * (30 - 20)) / (10 + 10) { name: "base asset swap twap calc, add to pool, t=[10,30]", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(20), sdk.NewDec(30), time.UnixMilli(20), @@ -468,16 +468,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((60 - 600/(10 - 2)) * (20 - 10) + (75 - 600/(8 - 2)) * (30 - 20)) / (10 + 10) { name: "base asset swap twap calc, remove from pool, t=[10,30]", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(8), sdk.NewDec(75), time.UnixMilli(20), @@ -493,10 +493,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: base asset reserve = asset amount", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(20), @@ -540,7 +540,7 @@ func TestCalcTwap(t *testing.T) { for _, snapshot := range tc.reserveSnapshots { ctx = ctx.WithBlockTime(time.UnixMilli(snapshot.TimestampMs)) snapshot := types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), snapshot.BaseAssetReserve, snapshot.QuoteAssetReserve, ctx.BlockTime(), diff --git a/x/vpool/keeper/query_server_test.go b/x/vpool/keeper/query_server_test.go index 334c279a9..9cbb2b7d0 100644 --- a/x/vpool/keeper/query_server_test.go +++ b/x/vpool/keeper/query_server_test.go @@ -24,7 +24,7 @@ func TestQueryReserveAssets(t *testing.T) { t.Log("initialize vpool") pool := types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1 * common.Precision), BaseAssetReserve: sdk.NewDec(1000), Config: types.VpoolConfig{ @@ -41,7 +41,7 @@ func TestQueryReserveAssets(t *testing.T) { resp, err := queryServer.ReserveAssets( sdk.WrapSDKContext(ctx), &types.QueryReserveAssetsRequest{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }, ) @@ -58,7 +58,7 @@ func TestQueryAllPools(t *testing.T) { queryServer := NewQuerier(vpoolKeeper) t.Log("initialize vpool") - pair := common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD) + pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) pool := &types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(1 * common.Precision), diff --git a/x/vpool/keeper/snapshot_test.go b/x/vpool/keeper/snapshot_test.go index f1d42b368..0f0126406 100644 --- a/x/vpool/keeper/snapshot_test.go +++ b/x/vpool/keeper/snapshot_test.go @@ -25,7 +25,7 @@ func TestGetSnapshotPrice(t *testing.T) { }{ { name: "spot price calc", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(2), twapCalcOption: types.TwapCalcOption_SPOT, @@ -33,7 +33,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap add to pool calc", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_QUOTE_ASSET_SWAP, @@ -43,7 +43,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap remove from pool calc", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_QUOTE_ASSET_SWAP, @@ -53,7 +53,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap add to pool calc", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_BASE_ASSET_SWAP, @@ -63,7 +63,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap remove from pool calc", - pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_BASE_ASSET_SWAP, diff --git a/x/vpool/simulation/genesis.go b/x/vpool/simulation/genesis.go index 429e8fe27..1f86f33f9 100644 --- a/x/vpool/simulation/genesis.go +++ b/x/vpool/simulation/genesis.go @@ -24,7 +24,7 @@ func RandomizedGenState(simState *module.SimulationState) { vpoolGenesis := types.GenesisState{ Vpools: []types.Vpool{ { - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(10e12).Add(simtypes.RandomDecAmount(simState.Rand, sdk.NewDec(10e12))), BaseAssetReserve: sdk.NewDec(10e12).Add(simtypes.RandomDecAmount(simState.Rand, sdk.NewDec(10e12))), Config: types.VpoolConfig{ diff --git a/x/vpool/types/gov_test.go b/x/vpool/types/gov_test.go index 3b51b3739..a6443b40b 100644 --- a/x/vpool/types/gov_test.go +++ b/x/vpool/types/gov_test.go @@ -145,7 +145,7 @@ func TestMarshalProposalEditPoolConfig(t *testing.T) { proposal := EditPoolConfigProposal{ Title: "Edit vpool config for NIBI:NUSD", Description: "I want to take 100x leverage on my NIBI", - Pair: common.AssetRegistry.Pair(denoms.DenomNIBI, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), Config: VpoolConfig{ MaxLeverage: sdk.MustNewDecFromStr("100"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), diff --git a/x/vpool/types/pool_test.go b/x/vpool/types/pool_test.go index 37a70d7ff..8f468049b 100644 --- a/x/vpool/types/pool_test.go +++ b/x/vpool/types/pool_test.go @@ -505,7 +505,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "happy path", Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -514,7 +514,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil base", Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -523,7 +523,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero base", Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -532,7 +532,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil quote", Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.Dec{}, }, @@ -541,7 +541,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero quote", Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.ZeroDec(), }, @@ -567,7 +567,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "zero fluctuation limit ratio", pool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -583,7 +583,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "lower limit of fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(999), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -599,7 +599,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "upper limit of fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1001), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -615,7 +615,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "under fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(998), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -631,7 +631,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "over fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -650,7 +650,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { snapshot := NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec(), sdk.NewDec(1000), time.Now(), @@ -669,7 +669,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "happy path", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10), QuoteAssetReserve: sdk.NewDec(10_000), }, @@ -678,7 +678,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid base", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.NewDec(500), }, @@ -687,7 +687,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid quote", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.Dec{}, }, @@ -696,7 +696,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative quote", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.NewDec(-500), }, @@ -705,7 +705,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative base", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.DenomBTC, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(-500), QuoteAssetReserve: sdk.NewDec(500), }, diff --git a/x/vpool/types/snapshot_test.go b/x/vpool/types/snapshot_test.go index 18d23a339..25dca6447 100644 --- a/x/vpool/types/snapshot_test.go +++ b/x/vpool/types/snapshot_test.go @@ -20,7 +20,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "happy path", snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.OneDec(), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -40,7 +40,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "base asset negative", snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(-1), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -50,7 +50,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "quote asset negative", snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.NewDec(-1), TimestampMs: time.Now().UnixMilli(), @@ -61,7 +61,7 @@ func TestSnapshotValidate(t *testing.T) { name: "timestamp lower than smallest UTC ('0001-01-01 00:00:00 +0000 UTC')", // see time.UnixMilli(-62135596800000).UTC()) snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.ZeroDec(), TimestampMs: -62135596800000 - 1, diff --git a/x/wasm/cli/cli_test.go b/x/wasm/cli/cli_test.go index 1becdfc35..9e3f6b5e9 100644 --- a/x/wasm/cli/cli_test.go +++ b/x/wasm/cli/cli_test.go @@ -25,7 +25,7 @@ import ( var commonArgs = []string{ fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(denoms.DenomNIBI, sdk.NewInt(10))).String()), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(denoms.NIBI, sdk.NewInt(10))).String()), } type IntegrationTestSuite struct { @@ -49,7 +49,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: common.AssetRegistry.Pair(denoms.DenomETH, denoms.DenomNUSD), + Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ From 77e863140a1189a3f2cb9a96691ecb9daf95538b Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Wed, 25 Jan 2023 19:39:27 -0500 Subject: [PATCH 8/9] refactor: AssetRegistry in asset package --- simapp/testapp.go | 5 +- x/common/{ => asset}/asset_registry.go | 7 +- x/common/{ => asset}/asset_registry_test.go | 11 +- x/common/error_test.go | 5 +- x/oracle/keeper/ballot_test.go | 33 +++-- x/oracle/keeper/keeper_test.go | 5 +- x/oracle/keeper/msg_server_test.go | 20 +-- x/oracle/keeper/querier_test.go | 45 +++--- x/oracle/keeper/reward_test.go | 9 +- x/oracle/keeper/slash_test.go | 41 +++--- x/oracle/keeper/tally_fuzz_test.go | 9 +- x/oracle/keeper/update_exchange_rates_test.go | 111 +++++++------- x/oracle/simulation/decoder_test.go | 6 +- x/oracle/simulation/genesis.go | 11 +- x/oracle/simulation/operations.go | 3 +- x/oracle/types/ballot_test.go | 28 ++-- x/oracle/types/params.go | 9 +- x/perp/client/cli/cli_test.go | 77 +++++----- x/perp/genesis_test.go | 6 +- x/perp/keeper/calc_test.go | 3 +- x/perp/keeper/calc_unit_test.go | 25 ++-- .../keeper/clearing_house_integration_test.go | 35 ++--- x/perp/keeper/clearing_house_unit_test.go | 137 +++++++++--------- x/perp/keeper/grpc_query_test.go | 67 ++++----- x/perp/keeper/hooks_test.go | 18 +-- x/perp/keeper/liquidate_unit_test.go | 136 ++++++++--------- x/perp/keeper/margin_test.go | 13 +- x/perp/keeper/margin_unit_test.go | 83 +++++------ x/perp/keeper/msg_server_test.go | 49 ++++--- x/perp/simulation/genesis.go | 4 +- x/perp/simulation/operations.go | 15 +- x/perp/types/msgs_test.go | 9 +- x/stablecoin/abci.go | 4 +- x/stablecoin/abci_test.go | 15 +- x/stablecoin/client/cli/cli_test.go | 5 +- x/stablecoin/keeper/collateral_ratio.go | 17 ++- x/stablecoin/keeper/collateral_ratio_test.go | 105 +++++++------- x/stablecoin/keeper/mint_burn_stable.go | 5 +- x/stablecoin/keeper/mint_burn_stable_test.go | 17 ++- x/vpool/abci_test.go | 14 +- x/vpool/client/cli/cli_test.go | 25 ++-- x/vpool/keeper/keeper_test.go | 103 ++++++------- x/vpool/keeper/pool_state_test.go | 23 +-- x/vpool/keeper/prices_test.go | 81 ++++++----- x/vpool/keeper/query_server_test.go | 7 +- x/vpool/keeper/snapshot_test.go | 11 +- x/vpool/simulation/genesis.go | 4 +- x/vpool/types/gov_test.go | 3 +- x/vpool/types/pool_test.go | 33 +++-- x/vpool/types/snapshot_test.go | 9 +- x/wasm/cli/cli_test.go | 3 +- 51 files changed, 780 insertions(+), 739 deletions(-) rename x/common/{ => asset}/asset_registry.go (92%) rename x/common/{ => asset}/asset_registry_test.go (81%) diff --git a/simapp/testapp.go b/simapp/testapp.go index 07cc23697..ad67750cd 100644 --- a/simapp/testapp.go +++ b/simapp/testapp.go @@ -16,6 +16,7 @@ import ( tmdb "github.com/tendermint/tm-db" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" ) @@ -37,8 +38,8 @@ func NewTestNibiruAppAndContext(shouldUseDefaultGenesis bool) (*NibiruTestApp, s newNibiruApp := NewTestNibiruApp(shouldUseDefaultGenesis) ctx := newNibiruApp.NewContext(false, tmproto.Header{}) - newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(20000)) - // newNibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewDec(10)) + newNibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(20000)) + // newNibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewDec(10)) newNibiruApp.OracleKeeper.SetPrice(ctx, "xxx:yyy", sdk.NewDec(20000)) return newNibiruApp, ctx diff --git a/x/common/asset_registry.go b/x/common/asset/asset_registry.go similarity index 92% rename from x/common/asset_registry.go rename to x/common/asset/asset_registry.go index c64b5c91b..369778eaa 100644 --- a/x/common/asset_registry.go +++ b/x/common/asset/asset_registry.go @@ -1,6 +1,7 @@ -package common +package asset import ( + "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/set" ) @@ -28,10 +29,10 @@ func init() { } } -func (r assetRegistry) Pair(base string, quote string) AssetPair { +func (r assetRegistry) Pair(base string, quote string) common.AssetPair { for q := range r[base] { if q == quote { - return NewAssetPair(string(base), string(quote)) + return common.NewAssetPair(string(base), string(quote)) } } diff --git a/x/common/asset_registry_test.go b/x/common/asset/asset_registry_test.go similarity index 81% rename from x/common/asset_registry_test.go rename to x/common/asset/asset_registry_test.go index 463ece9d3..de9b20caa 100644 --- a/x/common/asset_registry_test.go +++ b/x/common/asset/asset_registry_test.go @@ -1,10 +1,11 @@ -package common +package asset import ( "testing" "github.com/stretchr/testify/require" + "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/common/denoms" ) @@ -22,18 +23,18 @@ func TestIsSupportedPair(t *testing.T) { func TestPair(t *testing.T) { for base := range AssetRegistry { for quote := range AssetRegistry[base] { - require.Equal(t, NewAssetPair(base, quote), AssetRegistry.Pair(base, quote)) + require.Equal(t, common.NewAssetPair(base, quote), AssetRegistry.Pair(base, quote)) } } t.Log("test an unsupported pair") - require.Equal(t, AssetPair(""), AssetRegistry.Pair(denoms.ATOM, denoms.OSMO)) + require.Equal(t, common.AssetPair(""), AssetRegistry.Pair(denoms.ATOM, denoms.OSMO)) t.Log("test an unsupported base asset") - require.Equal(t, AssetPair(""), AssetRegistry.Pair("unsuported_denom", denoms.USDC)) + require.Equal(t, common.AssetPair(""), AssetRegistry.Pair("unsuported_denom", denoms.USDC)) t.Log("test an unsupported quote asset") - require.Equal(t, AssetPair(""), AssetRegistry.Pair(denoms.ATOM, "unsupported_denom")) + require.Equal(t, common.AssetPair(""), AssetRegistry.Pair(denoms.ATOM, "unsupported_denom")) } func TestBaseDenoms(t *testing.T) { diff --git a/x/common/error_test.go b/x/common/error_test.go index 671fe289b..ea4ea7bc1 100644 --- a/x/common/error_test.go +++ b/x/common/error_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" ) @@ -87,12 +88,12 @@ func TestCombineErrorsGeneric(t *testing.T) { {name: "type=[]string | mixed", in: []string{"", "abc", ""}, out: errors.New(": abc: ")}, // cases: fmt.Stringer - {name: "type=fmt.Stringer |", in: common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), out: errors.New("uusdc:unusd")}, + {name: "type=fmt.Stringer |", in: asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), out: errors.New("uusdc:unusd")}, // cases: []fmt.Stringer { name: "type=[]fmt.Stringer | happy", - in: []fmt.Stringer{common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)}, + in: []fmt.Stringer{asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)}, out: errors.New("ubtc:unusd: ueth:unusd")}, {name: "type=[]fmt.Stringer | empty", in: []fmt.Stringer{}, out: nil}, } diff --git a/x/oracle/keeper/ballot_test.go b/x/oracle/keeper/ballot_test.go index f897b5d6a..c5ce00b38 100644 --- a/x/oracle/keeper/ballot_test.go +++ b/x/oracle/keeper/ballot_test.go @@ -11,6 +11,7 @@ import ( "github.com/NibiruChain/collections" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle/types" ) @@ -33,14 +34,14 @@ func TestOrganizeAggregate(t *testing.T) { staking.EndBlocker(ctx, input.StakingKeeper) btcBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(17), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(10), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(6), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[2], power), } ethBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(1000), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(1300), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(2000), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[2], power), } for i := range btcBallot { @@ -79,11 +80,11 @@ func TestOrganizeAggregate(t *testing.T) { // sort each ballot for comparison sort.Sort(btcBallot) sort.Sort(ethBallot) - sort.Sort(ballotMap[common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)]) - sort.Sort(ballotMap[common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)]) + sort.Sort(ballotMap[asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)]) + sort.Sort(ballotMap[asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)]) - require.Equal(t, btcBallot, ballotMap[common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)]) - require.Equal(t, ethBallot, ballotMap[common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)]) + require.Equal(t, btcBallot, ballotMap[asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)]) + require.Equal(t, ethBallot, ballotMap[asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)]) } func TestClearBallots(t *testing.T) { @@ -104,14 +105,14 @@ func TestClearBallots(t *testing.T) { staking.EndBlocker(ctx, input.StakingKeeper) btcBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(17), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(10), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(6), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(17), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(10), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(6), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[2], power), } ethBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(1000), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(1300), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(2000), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(1000), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(1300), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(2000), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[2], power), } for i := range btcBallot { diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index 61d550bbf..9604decdd 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle/types" @@ -31,8 +32,8 @@ func TestParams(t *testing.T) { slashWindow := uint64(1000) minValidPerWindow := sdk.NewDecWithPrec(1, 4) whitelist := []common.AssetPair{ - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), } // Should really test validateParams, but skipping because obvious diff --git a/x/oracle/keeper/msg_server_test.go b/x/oracle/keeper/msg_server_test.go index 59462b72d..4bb5f65fc 100644 --- a/x/oracle/keeper/msg_server_test.go +++ b/x/oracle/keeper/msg_server_test.go @@ -3,7 +3,7 @@ package keeper import ( "testing" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/stretchr/testify/require" @@ -20,7 +20,7 @@ func TestMsgServer_FeederDelegation(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate, }, } @@ -87,43 +87,43 @@ func TestMsgServer_AggregatePrevoteVote(t *testing.T) { salt := "1" exchangeRates := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } otherExchangeRate := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } unintendedExchangeRateStr := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { diff --git a/x/oracle/keeper/querier_test.go b/x/oracle/keeper/querier_test.go index 64ca94fd1..9d2f9baaa 100644 --- a/x/oracle/keeper/querier_test.go +++ b/x/oracle/keeper/querier_test.go @@ -11,6 +11,7 @@ import ( "github.com/NibiruChain/collections" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle/types" ) @@ -32,7 +33,7 @@ func TestQueryExchangeRate(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) // empty request _, err := querier.ExchangeRate(ctx, nil) @@ -40,7 +41,7 @@ func TestQueryExchangeRate(t *testing.T) { // Query to grpc res, err := querier.ExchangeRate(ctx, &types.QueryExchangeRateRequest{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), }) require.NoError(t, err) require.Equal(t, rate, res.ExchangeRate) @@ -72,15 +73,15 @@ func TestQueryExchangeRates(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) res, err := querier.ExchangeRates(ctx, &types.QueryExchangeRatesRequest{}) require.NoError(t, err) require.Equal(t, types.ExchangeRateTuples{ - {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: rate}, - {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: rate}, + {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: rate}, + {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: rate}, }, res.ExchangeRates) } @@ -90,12 +91,12 @@ func TestQueryExchangeRateTwap(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.SetPrice(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) + input.OracleKeeper.SetPrice(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) - _, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)}) + _, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)}) require.Error(t, err) - res, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}) + res, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}) require.NoError(t, err) require.Equal(t, sdk.MustNewDecFromStr("1700"), res.ExchangeRate) } @@ -115,25 +116,25 @@ func TestCalcTwap(t *testing.T) { // expected price: (9.5 * (35 - 30) + 8.5 * (30 - 20) + 9.0 * (20 - 5)) / 30 = 8.916666 { name: "spot price twap calc, t=(5,35]", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), priceSnapshots: []types.PriceSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("90000.0"), TimestampMs: time.UnixMilli(1).UnixMilli(), }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("9.0"), TimestampMs: time.UnixMilli(10).UnixMilli(), }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("8.5"), TimestampMs: time.UnixMilli(20).UnixMilli(), }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("9.5"), TimestampMs: time.UnixMilli(30).UnixMilli(), }, @@ -167,12 +168,12 @@ func TestCalcTwap(t *testing.T) { ctx = ctx.WithBlockTime(time.UnixMilli(0)) for _, reserve := range tc.priceSnapshots { ctx = ctx.WithBlockTime(time.UnixMilli(reserve.TimestampMs)) - input.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserve.Price) + input.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserve.Price) } ctx = ctx.WithBlockTime(tc.currentBlockTime).WithBlockHeight(tc.currentBlockHeight) - price, err := querier.ExchangeRateTwap(sdk.WrapSDKContext(ctx), &types.QueryExchangeRateRequest{Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}) + price, err := querier.ExchangeRateTwap(sdk.WrapSDKContext(ctx), &types.QueryExchangeRateRequest{Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}) require.NoError(t, err) require.EqualValuesf(t, tc.expectedPrice, price.ExchangeRate, @@ -187,17 +188,17 @@ func TestQueryActives(t *testing.T) { queryClient := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) res, err := queryClient.Actives(ctx, &types.QueryActivesRequest{}) require.NoError(t, err) targetPairs := []common.AssetPair{ - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), } require.Equal(t, targetPairs, res.Actives) diff --git a/x/oracle/keeper/reward_test.go b/x/oracle/keeper/reward_test.go index eb6ae3fbe..dc643e116 100644 --- a/x/oracle/keeper/reward_test.go +++ b/x/oracle/keeper/reward_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle" "github.com/NibiruChain/nibiru/x/oracle/keeper" @@ -58,7 +59,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { valPeriodicRewards := sdk.NewDecCoinsFromCoins(rewards). QuoDec(sdk.NewDec(int64(periods))). QuoDec(sdk.NewDec(int64(validators))) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(rewards), periods) + keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(rewards), periods) for i := uint64(1); i <= periods; i++ { for valIndex := 0; valIndex < validators; valIndex++ { @@ -66,7 +67,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { // passes the current context block height for pre vote // then changes the height to current height + vote period for the vote makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{ - Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate, }}, valIndex) } @@ -83,8 +84,8 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { } // assert there are no rewards for pair - require.True(t, input.OracleKeeper.GatherRewardsForVotePeriod(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)).IsZero()) + require.True(t, input.OracleKeeper.GatherRewardsForVotePeriod(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)).IsZero()) // assert that there are no rewards instances - require.Empty(t, input.OracleKeeper.PairRewards.Indexes.RewardsByPair.ExactMatch(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)).PrimaryKeys()) + require.Empty(t, input.OracleKeeper.PairRewards.Indexes.RewardsByPair.ExactMatch(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)).PrimaryKeys()) } diff --git a/x/oracle/keeper/slash_test.go b/x/oracle/keeper/slash_test.go index fb977abb2..55455c923 100644 --- a/x/oracle/keeper/slash_test.go +++ b/x/oracle/keeper/slash_test.go @@ -11,6 +11,7 @@ import ( "github.com/NibiruChain/collections" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle" "github.com/NibiruChain/nibiru/x/oracle/keeper" @@ -91,9 +92,9 @@ func TestSlashAndResetMissCounters(t *testing.T) { func TestInvalidVotesSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) votePeriodsPerWindow := types.NewDec(int64(input.OracleKeeper.SlashWindow(input.Ctx))).QuoInt64(int64(input.OracleKeeper.VotePeriod(input.Ctx))).TruncateInt64() slashFraction := input.OracleKeeper.SlashFraction(input.Ctx) @@ -103,13 +104,13 @@ func TestInvalidVotesSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, miss vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, i+1, input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[1], 0)) @@ -120,13 +121,13 @@ func TestInvalidVotesSlashing(t *testing.T) { // one more miss vote will inccur keeper.ValAddrs[1] slashing // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, miss vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) input.Ctx = input.Ctx.WithBlockHeight(votePeriodsPerWindow - 1) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -145,9 +146,9 @@ func TestWhitelistSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, i+1, input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[0], 0)) @@ -159,9 +160,9 @@ func TestWhitelistSlashing(t *testing.T) { // one more miss vote will inccur Account 1 slashing // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) input.Ctx = input.Ctx.WithBlockHeight(votePeriodsPerWindow - 1) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -172,19 +173,19 @@ func TestWhitelistSlashing(t *testing.T) { func TestNotPassedBallotSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[0], 0)) @@ -195,14 +196,14 @@ func TestNotPassedBallotSlashing(t *testing.T) { func TestAbstainSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) votePeriodsPerWindow := types.NewDec(int64(input.OracleKeeper.SlashWindow(input.Ctx))).QuoInt64(int64(input.OracleKeeper.VotePeriod(input.Ctx))).TruncateInt64() minValidPerWindow := input.OracleKeeper.MinValidPerWindow(input.Ctx) @@ -211,13 +212,13 @@ func TestAbstainSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, abstain vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: types.ZeroDec()}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: types.ZeroDec()}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[1], 0)) diff --git a/x/oracle/keeper/tally_fuzz_test.go b/x/oracle/keeper/tally_fuzz_test.go index 75bc5fec2..f55c704c5 100644 --- a/x/oracle/keeper/tally_fuzz_test.go +++ b/x/oracle/keeper/tally_fuzz_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/common/set" "github.com/NibiruChain/nibiru/x/oracle/types" @@ -133,11 +134,11 @@ func TestRemoveInvalidBallots(t *testing.T) { "x": types.ExchangeRateBallots{ {Pair: "x", ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD): types.ExchangeRateBallots{ - {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD): types.ExchangeRateBallots{ + {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD): types.ExchangeRateBallots{ - {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD): types.ExchangeRateBallots{ + {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, }, }, diff --git a/x/oracle/keeper/update_exchange_rates_test.go b/x/oracle/keeper/update_exchange_rates_test.go index f8e9744da..0e739f2a4 100644 --- a/x/oracle/keeper/update_exchange_rates_test.go +++ b/x/oracle/keeper/update_exchange_rates_test.go @@ -15,6 +15,7 @@ import ( "github.com/NibiruChain/collections" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/oracle" "github.com/NibiruChain/nibiru/x/oracle/keeper" @@ -24,7 +25,7 @@ import ( func TestOracleThreshold(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate, }, } @@ -121,15 +122,15 @@ func TestOracleThreshold(t *testing.T) { func TestOracleDrop(t *testing.T) { input, h := setup(t) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), randomExchangeRate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), randomExchangeRate) // Account 1, pair gov stable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Immediately swap halt after an illiquid oracle vote oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) require.Error(t, err) } @@ -143,7 +144,7 @@ func TestOracleTally(t *testing.T) { for i, rate := range rates { decExchangeRate := sdk.NewDecWithPrec(int64(rate*math.Pow10(keeper.OracleDecPrecision)), int64(keeper.OracleDecPrecision)) exchangeRateStr, err := types.ExchangeRateTuples{ - {ExchangeRate: decExchangeRate, Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}}.ToString() + {ExchangeRate: decExchangeRate, Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}}.ToString() require.NoError(t, err) salt := fmt.Sprintf("%d", i) @@ -162,7 +163,7 @@ func TestOracleTally(t *testing.T) { } vote := types.NewExchangeRateBallot( - decExchangeRate, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddrs[i], power) + decExchangeRate, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddrs[i], power) ballot = append(ballot, vote) // change power of every three validator @@ -222,7 +223,7 @@ func TestOracleTallyTiming(t *testing.T) { // all the keeper.Addrs vote for the block ... not last period block yet, so tally fails for i := range keeper.Addrs[:2] { - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, i) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, i) } params := input.OracleKeeper.GetParams(input.Ctx) @@ -231,13 +232,13 @@ func TestOracleTallyTiming(t *testing.T) { require.Equal(t, 0, int(input.Ctx.BlockHeight())) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.Error(t, err) input.Ctx = input.Ctx.WithBlockHeight(int64(params.VotePeriod - 1)) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err = input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + _, err = input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) } @@ -247,13 +248,13 @@ func TestOracleRewardDistribution(t *testing.T) { input, h := setup(t) // Account 1, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) rewardAllocation := sdk.NewCoins(sdk.NewCoin("reward", sdk.NewInt(1*common.Precision))) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rewardAllocation, 1) + keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rewardAllocation, 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -267,26 +268,26 @@ func TestOracleRewardDistribution(t *testing.T) { func TestOracleRewardBand(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear pairs to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) rewardSpread := randomExchangeRate.Mul(input.OracleKeeper.RewardBand(input.Ctx).QuoInt64(2)) // no one will miss the vote // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread)}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread)}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -296,13 +297,13 @@ func TestOracleRewardBand(t *testing.T) { // Account 1 will miss the vote due to raward band condition // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread.Add(sdk.OneDec()))}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread.Add(sdk.OneDec()))}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -356,19 +357,19 @@ func TestOracleExchangeRate(t *testing.T) { // govstable has been chosen as referenceExchangeRate by highest voting power // Account 1, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableExchangeRate}, {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}}, 0) // Account 2, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableExchangeRate}, {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}}, 1) // Account 3, govstable, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}, {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}, {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(govStableRewards), 1) + keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), sdk.NewCoins(ethStableRewards), 1) + keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -404,13 +405,13 @@ func TestOracleEnsureSorted(t *testing.T) { ethStableRate3 := sdk.NewDec(int64(rand.Uint64() % 100000000)) // Account 1, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate1}, {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate1}, {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 0) // Account 2, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}, {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}}, 1) // Account 3, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: govStableRate3}, {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: ethStableRate3}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: govStableRate3}, {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: ethStableRate3}}, 2) require.NotPanics(t, func() { oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -428,31 +429,31 @@ func TestOracleExchangeRateVal5(t *testing.T) { // govstable has been chosen as reference pair by highest voting power // Account 1, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}, {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate1}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}, {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate1}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 2) // Account 4, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}}, 3) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}, {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}}, 3) // Account 5, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}, {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}}, 4) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}, {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}}, 4) ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(govStableRewards), 1) + keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), sdk.NewCoins(ethStableRewards), 1) + keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) - gotGovStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + gotGovStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) require.NoError(t, err) - gotEthStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)) + gotEthStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)) require.NoError(t, err) require.Equal(t, govStableRate1, gotGovStableRate) @@ -486,15 +487,15 @@ func TestWhitelistedPairs(t *testing.T) { for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) // govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) // set btcstable for next vote period - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -504,15 +505,15 @@ func TestWhitelistedPairs(t *testing.T) { require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[2], 0)) // whitelisted pairs are {govstable, btcstable} - require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) + require.Equal(t, []common.AssetPair{asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) // govstable, missing btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) // delete btcstable for next vote period - params.Whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -521,13 +522,13 @@ func TestWhitelistedPairs(t *testing.T) { require.Equal(t, uint64(1), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[2], 0)) // btcstable must be deleted - require.Equal(t, []common.AssetPair{common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) - require.False(t, input.OracleKeeper.WhitelistedPairs.Has(input.Ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD))) + require.Equal(t, []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) + require.False(t, input.OracleKeeper.WhitelistedPairs.Has(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD))) // govstable, no missing - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -543,11 +544,11 @@ func TestAbstainWithSmallStakingPower(t *testing.T) { for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.ZeroDec()}}, 0) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.ZeroDec()}}, 0) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) require.Error(t, err) } diff --git a/x/oracle/simulation/decoder_test.go b/x/oracle/simulation/decoder_test.go index acbf05837..67d733443 100644 --- a/x/oracle/simulation/decoder_test.go +++ b/x/oracle/simulation/decoder_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" gogotypes "github.com/gogo/protobuf/types" @@ -35,8 +35,8 @@ func TestDecodeDistributionStore(t *testing.T) { aggregatePrevote := types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash([]byte("12345")), valAddr, 123) aggregateVote := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{ - {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDecWithPrec(1234, 1)}, - {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDecWithPrec(4321, 1)}, + {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDecWithPrec(1234, 1)}, + {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDecWithPrec(4321, 1)}, }, valAddr) pair := "btc:usd" diff --git a/x/oracle/simulation/genesis.go b/x/oracle/simulation/genesis.go index 78e90b50b..63d875950 100644 --- a/x/oracle/simulation/genesis.go +++ b/x/oracle/simulation/genesis.go @@ -8,6 +8,7 @@ import ( "math/rand" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" sdk "github.com/cosmos/cosmos-sdk/types" @@ -98,17 +99,17 @@ func RandomizedGenState(simState *module.SimulationState) { VoteThreshold: voteThreshold, RewardBand: rewardBand, Whitelist: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), }, SlashFraction: slashFraction, SlashWindow: slashWindow, MinValidPerWindow: minValidPerWindow, }, []types.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(20_000)}, + {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(20_000)}, }, []types.FeederDelegation{}, []types.MissCounter{}, diff --git a/x/oracle/simulation/operations.go b/x/oracle/simulation/operations.go index 1da44e250..c1670dfc3 100644 --- a/x/oracle/simulation/operations.go +++ b/x/oracle/simulation/operations.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/cosmos/cosmos-sdk/baseapp" @@ -31,7 +32,7 @@ const ( ) var ( - whitelist = []common.AssetPair{common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} voteHashMap map[string]string = make(map[string]string) ) diff --git a/x/oracle/types/ballot_test.go b/x/oracle/types/ballot_test.go index 27c2aa1c0..2ac0c3e6b 100644 --- a/x/oracle/types/ballot_test.go +++ b/x/oracle/types/ballot_test.go @@ -6,7 +6,7 @@ import ( "sort" "strconv" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "testing" @@ -31,21 +31,21 @@ func TestToMap(t *testing.T) { { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(1600), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.ZeroDec(), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(1500), Power: 100, }, @@ -95,15 +95,15 @@ func TestToCrossRate(t *testing.T) { for _, data := range data { valAddr := sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()) if !data.base.IsZero() { - pbBase = append(pbBase, types.NewExchangeRateBallot(data.base, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) + pbBase = append(pbBase, types.NewExchangeRateBallot(data.base, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) } - pbQuote = append(pbQuote, types.NewExchangeRateBallot(data.quote, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) + pbQuote = append(pbQuote, types.NewExchangeRateBallot(data.quote, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) if !data.base.IsZero() && !data.quote.IsZero() { - cb = append(cb, types.NewExchangeRateBallot(data.base.Quo(data.quote), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) + cb = append(cb, types.NewExchangeRateBallot(data.base.Quo(data.quote), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) } else { - cb = append(cb, types.NewExchangeRateBallot(sdk.ZeroDec(), common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 0)) + cb = append(cb, types.NewExchangeRateBallot(sdk.ZeroDec(), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 0)) } } @@ -135,7 +135,7 @@ func TestPBPower(t *testing.T) { power := sk.Validator(ctx, valAccAddrs[i]).GetConsensusPower(sdk.DefaultPowerReduction) vote := types.NewExchangeRateBallot( sdk.ZeroDec(), - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), valAccAddrs[i], power, ) @@ -154,7 +154,7 @@ func TestPBPower(t *testing.T) { faceValAddr := sdk.ValAddress(pubKey.Address()) fakeVote := types.NewExchangeRateBallot( sdk.OneDec(), - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), faceValAddr, 0, ) @@ -225,7 +225,7 @@ func TestPBWeightedMedian(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDec(int64(input)), - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), valAddr, power, ) @@ -292,7 +292,7 @@ func TestPBStandardDeviation(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDecWithPrec(int64(input*base), int64(types.OracleDecPrecision)), - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), valAddr, power, ) @@ -311,12 +311,12 @@ func TestPBStandardDeviationOverflow(t *testing.T) { pb := types.ExchangeRateBallots{types.NewExchangeRateBallot( sdk.ZeroDec(), - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), valAddr, 2, ), types.NewExchangeRateBallot( exchangeRate, - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), valAddr, 1, )} diff --git a/x/oracle/types/params.go b/x/oracle/types/params.go index 65061fe1b..bcba54d42 100644 --- a/x/oracle/types/params.go +++ b/x/oracle/types/params.go @@ -7,6 +7,7 @@ import ( "gopkg.in/yaml.v2" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" sdk "github.com/cosmos/cosmos-sdk/types" @@ -39,10 +40,10 @@ var ( DefaultVoteThreshold = sdk.NewDecWithPrec(50, 2) // 50% DefaultRewardBand = sdk.NewDecWithPrec(2, 2) // 2% (-1, 1) DefaultWhitelist = []common.AssetPair{ - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), } DefaultSlashFraction = sdk.NewDecWithPrec(1, 4) // 0.01% DefaultMinValidPerWindow = sdk.NewDecWithPrec(5, 2) // 5% diff --git a/x/perp/client/cli/cli_test.go b/x/perp/client/cli/cli_test.go index 6181d6d54..c91bdfb42 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -16,6 +16,7 @@ import ( "github.com/NibiruChain/nibiru/app" "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" "github.com/NibiruChain/nibiru/x/perp/client/cli" @@ -52,7 +53,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -64,7 +65,7 @@ func (s *IntegrationTestSuite) SetupSuite() { }, }, { - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -82,11 +83,11 @@ func (s *IntegrationTestSuite) SetupSuite() { perpGenesis := perptypes.DefaultGenesis() perpGenesis.PairMetadata = []perptypes.PairMetadata{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), }, { - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, } @@ -95,12 +96,12 @@ func (s *IntegrationTestSuite) SetupSuite() { oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.Params.Whitelist = []common.AssetPair{ - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), } oracleGenesis.Params.VotePeriod = 1_000 oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(20_000)}, - {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDec(2_000)}, + {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(20_000)}, + {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDec(2_000)}, } genesisState[oracletypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(oracleGenesis) @@ -187,25 +188,25 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { val := s.network.Validators[0] user := s.users[0] - exchangeRate, err := testutilcli.QueryOracleExchangeRate(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + exchangeRate, err := testutilcli.QueryOracleExchangeRate(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) s.T().Logf("0. current exchange rate is: %+v", exchangeRate) s.NoError(err) s.T().Log("A. check vpool balances") - reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.NewDec(10*common.Precision), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_000*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("A. check trader has no existing positions") - _, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + _, err = testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.Error(err) s.T().Log("B. open position") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "buy", - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAssetLimit */ "1"}, @@ -214,18 +215,18 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("B. check vpool balance after open position") - reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("9999833.336111064815586407"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_001*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("B. check trader position") - queryResp, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + queryResp, err := testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) + s.EqualValues(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("166.663888935184413593"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.OpenNotional) @@ -237,7 +238,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("C. open position with 2x leverage and zero baseAmtLimit") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "buy", - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "2", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAmtLimit */ "0", @@ -246,11 +247,11 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("C. check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) + s.EqualValues(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.975001249937503125"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(3*common.Precision), queryResp.Position.OpenNotional) @@ -261,7 +262,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("D. Open a reverse position smaller than the existing position") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "sell", - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "100", // 100 uNUSD /* baseAssetLimit */ "1", @@ -270,18 +271,18 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("D. Check vpool after opening reverse position") - reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) s.NoError(err) s.T().Logf(" \n reserve assets: %+v \n", reserveAssets) s.EqualValues(sdk.MustNewDecFromStr("9999500.041663750215262154"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_002_999_900), reserveAssets.QuoteAssetReserve) s.T().Log("D. Check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) + s.EqualValues(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.958336249784737846"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(2_999_900), queryResp.Position.OpenNotional) @@ -292,7 +293,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("E. Open a reverse position larger than the existing position") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "sell", - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "4000000", // 4*10^6 uNUSD /* baseAssetLimit */ "0", @@ -301,11 +302,11 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("E. Check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) + s.EqualValues(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("-166.686111713005402945"), queryResp.Position.Size_) s.EqualValues(sdk.MustNewDecFromStr("1000100.000000000000000494"), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("1000100.000000000000000494"), queryResp.Position.Margin) @@ -316,13 +317,13 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("F. Close position") txResp, err = testutilcli.ExecTx(s.network, cli.ClosePositionCmd(), user, []string{ - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), }) s.NoError(err) s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("F. check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) s.Error(err) s.T().Logf("query response: %+v", queryResp) @@ -336,12 +337,12 @@ func (s *IntegrationTestSuite) TestPositionEmptyAndClose() { user := s.users[0] // verify trader has no position (empty) - _, err := testutilcli.QueryPosition(val.ClientCtx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), user) + _, err := testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), user) s.Error(err, "no position found") // close position should produce error _, err = testutilcli.ExecTx(s.network, cli.ClosePositionCmd(), user, []string{ - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) } @@ -350,7 +351,7 @@ func (s *IntegrationTestSuite) TestQueryCumulativePremiumFractions() { val := s.network.Validators[0] s.T().Log("get cumulative funding payments") - queryResp, err := testutilcli.QueryCumulativePremiumFraction(val.ClientCtx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + queryResp, err := testutilcli.QueryCumulativePremiumFraction(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) s.NoError(err) s.EqualValues(sdk.NewDec(2), queryResp.CumulativePremiumFraction) } @@ -360,7 +361,7 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { s.T().Log("opening a position with user 0") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[0], []string{ "buy", - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), "10", // Leverage "1", // Quote asset amount "0.0000001", @@ -371,7 +372,7 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { // Remove margin to trigger bad debt on user 0 s.T().Log("removing margin on user 0....") _, err = testutilcli.ExecTx(s.network, cli.RemoveMarginCmd(), s.users[0], []string{ - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), fmt.Sprintf("%s%s", "100", denoms.NUSD), }) s.Contains(err.Error(), perptypes.ErrFailedRemoveMarginCanCauseBadDebt.Error()) @@ -379,7 +380,7 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { func (s *IntegrationTestSuite) TestX_AddMargin() { val := s.network.Validators[0] - pair := common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD) + pair := asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD) // Open a new position s.T().Log("opening a position with user 3....") @@ -411,7 +412,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { { name: "FAIL: position not found", args: []string{ - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), fmt.Sprintf("%s%s", "10000", pair.QuoteDenom()), }, expectedCode: 1, @@ -438,7 +439,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidate a position that does not exist") _, err := testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), s.users[1].String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) @@ -446,7 +447,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("opening a position with user 1....") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[1], []string{ "buy", - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), "15", // Leverage "90000", // Quote asset amount "0", @@ -456,7 +457,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidate a position that is above maintenance margin mario") _, err = testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), s.users[1].String(), }) s.Contains(err.Error(), "margin ratio is too healthy to liquidate") @@ -464,7 +465,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("opening a position with user 2...") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[2], []string{ "sell", - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), "15", // Leverage "45000000", // Quote asset amount "0", @@ -480,7 +481,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidating user 1...") txResp, err = testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), s.users[1].String(), }) s.NoError(err) diff --git a/x/perp/genesis_test.go b/x/perp/genesis_test.go index 7ca77b10a..049bc1e68 100644 --- a/x/perp/genesis_test.go +++ b/x/perp/genesis_test.go @@ -7,6 +7,7 @@ import ( "github.com/NibiruChain/collections" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" @@ -16,7 +17,6 @@ import ( "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/perp" "github.com/NibiruChain/nibiru/x/perp/types" ) @@ -40,9 +40,9 @@ func TestGenesis(t *testing.T) { // create some positions for i := int64(0); i < 100; i++ { addr := testutil.AccAddress() - app.PerpKeeper.Positions.Insert(ctx, collections.Join(common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), addr), types.Position{ + app.PerpKeeper.Positions.Insert(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), addr), types.Position{ TraderAddress: addr.String(), - Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), Size_: sdk.NewDec(i + 1), Margin: sdk.NewDec(i * 2), OpenNotional: sdk.NewDec(i * 100), diff --git a/x/perp/keeper/calc_test.go b/x/perp/keeper/calc_test.go index 73236a643..63a2cae42 100644 --- a/x/perp/keeper/calc_test.go +++ b/x/perp/keeper/calc_test.go @@ -10,6 +10,7 @@ import ( "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/perp/types" "github.com/NibiruChain/nibiru/x/testutil" @@ -29,7 +30,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { marginDelta := sdk.OneDec() _, err := nibiruApp.PerpKeeper.CalcRemainMarginWithFundingPayment( ctx, types.Position{ - Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), }, marginDelta) require.ErrorIs(t, err, collections.ErrNotFound) }, diff --git a/x/perp/keeper/calc_unit_test.go b/x/perp/keeper/calc_unit_test.go index b7f9c1785..c01969d2f 100644 --- a/x/perp/keeper/calc_unit_test.go +++ b/x/perp/keeper/calc_unit_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" @@ -38,9 +39,9 @@ func TestCalcFreeCollateralErrors(t *testing.T) { test: func() { k, mocks, ctx := getKeeper(t) - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false) - pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) + pos := types.ZeroPosition(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) _, err := k.calcFreeCollateral(ctx, pos) @@ -54,12 +55,12 @@ func TestCalcFreeCollateralErrors(t *testing.T) { k, mocks, ctx := getKeeper(t) mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) + ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - pos := types.ZeroPosition(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) + pos := types.ZeroPosition(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) freeCollateral, err := k.calcFreeCollateral(ctx, pos) @@ -151,7 +152,7 @@ func TestCalcFreeCollateralSuccess(t *testing.T) { pos := types.Position{ TraderAddress: testutil.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.positionSize, Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(1000), @@ -160,19 +161,19 @@ func TestCalcFreeCollateralSuccess(t *testing.T) { } t.Log("mock vpool keeper") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.vpoolDirection, sdk.OneDec(), ).Return(tc.positionNotional, nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.vpoolDirection, sdk.OneDec(), 15*time.Minute, @@ -197,13 +198,13 @@ func TestGetLatestCumulativePremiumFraction(t *testing.T) { keeper, _, ctx := getKeeper(t) metadata := &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), } setPairMetadata(keeper, ctx, *metadata) latestCumulativePremiumFraction, err := keeper. - getLatestCumulativePremiumFraction(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + getLatestCumulativePremiumFraction(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) require.NoError(t, err) assert.Equal(t, sdk.NewDec(2), latestCumulativePremiumFraction) diff --git a/x/perp/keeper/clearing_house_integration_test.go b/x/perp/keeper/clearing_house_integration_test.go index 3d7d9dbb9..bf3ddd8b8 100644 --- a/x/perp/keeper/clearing_house_integration_test.go +++ b/x/perp/keeper/clearing_house_integration_test.go @@ -6,6 +6,7 @@ import ( "github.com/NibiruChain/collections" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" testutilevents "github.com/NibiruChain/nibiru/x/testutil" @@ -64,7 +65,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing long position, go more long", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -88,7 +89,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing long position, decrease a bit", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 10)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -112,7 +113,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing long position, decrease a lot", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1060)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -170,7 +171,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing short position, go more short", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -194,7 +195,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing short position, decrease a bit", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 10)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -218,7 +219,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing short position, decrease a lot", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1060)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -268,7 +269,7 @@ func TestOpenPositionSuccess(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision*common.Precision), vpooltypes.VpoolConfig{ @@ -280,7 +281,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -295,11 +296,11 @@ func TestOpenPositionSuccess(t *testing.T) { } ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(time.Second * 5)) - resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) + resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) require.NoError(t, err) t.Log("assert position response") - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), resp.Position.Pair) + assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), resp.Position.Pair) assert.EqualValues(t, traderAddr.String(), resp.Position.TraderAddress) assert.EqualValues(t, tc.expectedMargin, resp.Position.Margin, "margin") assert.EqualValues(t, tc.expectedOpenNotional, resp.Position.OpenNotional, "open notional") @@ -316,9 +317,9 @@ func TestOpenPositionSuccess(t *testing.T) { assert.EqualValues(t, tc.expectedPositionNotional, resp.PositionNotional) t.Log("assert position in state") - position, err := nibiruApp.PerpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) + position, err := nibiruApp.PerpKeeper.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.NoError(t, err) - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), position.Pair) + assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), position.Pair) assert.EqualValues(t, traderAddr.String(), position.TraderAddress) assert.EqualValues(t, tc.expectedMargin, position.Margin, "margin") assert.EqualValues(t, tc.expectedOpenNotional, position.OpenNotional, "open notional") @@ -331,7 +332,7 @@ func TestOpenPositionSuccess(t *testing.T) { ecosystemFundFee := nibiruApp.PerpKeeper.GetParams(ctx).EcosystemFundFeeRatio.Mul(exchangedNotional).RoundInt() testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionChangedEvent{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), Margin: sdk.NewCoin(denoms.NUSD, tc.expectedMargin.RoundInt()), PositionNotional: tc.expectedPositionNotional, @@ -385,7 +386,7 @@ func TestOpenPositionError(t *testing.T) { traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -520,7 +521,7 @@ func TestOpenPositionError(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* tradeLimitRatio */ /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), @@ -534,7 +535,7 @@ func TestOpenPositionError(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -548,7 +549,7 @@ func TestOpenPositionError(t *testing.T) { } ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(time.Second * 5)) - resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) + resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) require.ErrorContains(t, err, tc.expectedErr.Error()) require.Nil(t, resp) }) diff --git a/x/perp/keeper/clearing_house_unit_test.go b/x/perp/keeper/clearing_house_unit_test.go index 23f3552f1..8ee039ef8 100644 --- a/x/perp/keeper/clearing_house_unit_test.go +++ b/x/perp/keeper/clearing_house_unit_test.go @@ -6,6 +6,7 @@ import ( "github.com/NibiruChain/collections" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" testutilevents "github.com/NibiruChain/nibiru/x/testutil" @@ -117,7 +118,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -133,7 +134,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -154,7 +155,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { baseAmount, err := perpKeeper.swapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.side, sdk.NewDec(10), sdk.NewDec(1), @@ -182,7 +183,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -194,7 +195,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(50), @@ -204,7 +205,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -213,7 +214,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, ) @@ -256,7 +257,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -268,7 +269,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(101), @@ -278,7 +279,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -286,7 +287,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -331,7 +332,7 @@ func TestIncreasePosition(t *testing.T) { // funding payment causes negative margin aka bad debt initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(110), // 110 BTC Margin: sdk.NewDec(11), // 11 NUSD OpenNotional: sdk.NewDec(110), // 110 NUSD @@ -343,7 +344,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(110), @@ -353,7 +354,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(110), ). @@ -361,7 +362,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.2"), }) }, @@ -404,7 +405,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -416,7 +417,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(200), @@ -426,7 +427,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -434,7 +435,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -477,7 +478,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -489,7 +490,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(99), @@ -499,7 +500,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -507,7 +508,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -553,7 +554,7 @@ func TestIncreasePosition(t *testing.T) { // funding payment causes bad debt initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -565,7 +566,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(105), /*baseAssetLimit=*/ sdk.NewDec(100), @@ -575,7 +576,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -583,7 +584,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("-0.3"), }) }, @@ -657,7 +658,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 200 NUSD and unrealized PnL of +100 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -665,7 +666,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -684,7 +685,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of -5 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -692,7 +693,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -711,7 +712,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of -50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -719,7 +720,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -740,7 +741,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of +50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-150), // -150 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -748,7 +749,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -767,7 +768,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 105 NUSD and unrealized PnL of -5 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -775,7 +776,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -794,7 +795,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 150 NUSD and unrealized PnL of -50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -802,7 +803,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -827,7 +828,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -836,7 +837,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ tc.quoteAssetLimit, @@ -911,7 +912,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 100 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -946,7 +947,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 95 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(105), // 105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -981,7 +982,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -1018,7 +1019,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 95 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-105), // -105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1053,7 +1054,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 99.75 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1088,7 +1089,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 75 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1123,7 +1124,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1132,7 +1133,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ tc.quoteAssetDir, /*quoteAssetAmount=*/ tc.quoteAmountToDecrease, /*baseAssetLimit=*/ tc.exchangedBaseAmount.Abs(), @@ -1141,7 +1142,7 @@ func TestDecreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1509,7 +1510,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -1522,7 +1523,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), ). @@ -1531,7 +1532,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1542,7 +1543,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ tc.mockQuoteDir, /*quoteAssetAmount=*/ tc.inputQuoteAmount.Mul(tc.inputLeverage).Sub(tc.mockQuoteAmount), /*baseAssetLimit=*/ sdk.MaxDec(tc.inputBaseAssetLimit.Sub(currentPosition.Size_.Abs()), sdk.ZeroDec()), @@ -1552,7 +1553,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1690,7 +1691,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1716,7 +1717,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(105), // 105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1744,7 +1745,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-105), // -105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1770,7 +1771,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1807,7 +1808,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1816,7 +1817,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1853,7 +1854,7 @@ func TestClosePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1892,7 +1893,7 @@ func TestClosePosition(t *testing.T) { PositionSize: sdk.ZeroDec(), RealizedPnl: tc.expectedRealizedPnl, UnrealizedPnlAfter: sdk.ZeroDec(), - BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), sdk.ZeroInt()), + BadDebt: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), sdk.ZeroInt()), MarkPrice: tc.newPositionNotional.Quo(tc.initialPosition.Size_.Abs()), FundingPayment: sdk.MustNewDecFromStr("0.02").Mul(tc.initialPosition.Size_), TransactionFee: sdk.NewInt64Coin(tc.initialPosition.Pair.QuoteDenom(), 0), @@ -1920,7 +1921,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { // user cannot close position due to bad debt initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -1941,7 +1942,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { // user cannot close position due to bad debt initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1970,7 +1971,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1980,7 +1981,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1989,7 +1990,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) diff --git a/x/perp/keeper/grpc_query_test.go b/x/perp/keeper/grpc_query_test.go index 37c2b7329..57043058d 100644 --- a/x/perp/keeper/grpc_query_test.go +++ b/x/perp/keeper/grpc_query_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -31,7 +32,7 @@ func initAppVpools( t.Log("initialize vpool and pair") assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve, baseAssetReserve, vpooltypes.VpoolConfig{ @@ -43,12 +44,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -60,12 +61,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -77,7 +78,7 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) return ctx, nibiruApp, queryServer @@ -98,7 +99,7 @@ func TestQueryPosition(t *testing.T) { { name: "positive PnL", initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -115,7 +116,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, positive margin ratio", initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -132,7 +133,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, negative margin ratio", initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -167,7 +168,7 @@ func TestQueryPosition(t *testing.T) { sdk.WrapSDKContext(ctx), &types.QueryPositionRequest{ Trader: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }, ) require.NoError(t, err) @@ -193,7 +194,7 @@ func TestQueryPositions(t *testing.T) { name: "positive PnL", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -201,7 +202,7 @@ func TestQueryPositions(t *testing.T) { LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -264,7 +265,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "empty string pair", initialPairMetadata: &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -275,7 +276,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "pair metadata not found", initialPairMetadata: &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -286,11 +287,11 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "returns single funding payment", initialPairMetadata: &types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }, expectErr: false, expectedLatestCPF: sdk.ZeroDec(), @@ -305,7 +306,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { ctx, app, queryServer := initAppVpools(t, sdk.NewDec(481_000), sdk.NewDec(1_000)) t.Log("set index price") - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) t.Log("query cumulative premium fraction") resp, err := queryServer.CumulativePremiumFraction(sdk.WrapSDKContext(ctx), tc.query) @@ -340,7 +341,7 @@ func TestQueryMetrics(t *testing.T) { name: "two longs", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -348,7 +349,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -362,7 +363,7 @@ func TestQueryMetrics(t *testing.T) { name: "two shorts", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -370,7 +371,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -384,7 +385,7 @@ func TestQueryMetrics(t *testing.T) { name: "one long, one short", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -392,7 +393,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -406,14 +407,14 @@ func TestQueryMetrics(t *testing.T) { name: "decrease position", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -428,42 +429,42 @@ func TestQueryMetrics(t *testing.T) { name: "swap positions", Positions: []*types.Position{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), @@ -489,7 +490,7 @@ func TestQueryMetrics(t *testing.T) { // Detect position decrease app.PerpKeeper.OnSwapEnd( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), position.OpenNotional, position.Size_, ) @@ -499,7 +500,7 @@ func TestQueryMetrics(t *testing.T) { resp, err := queryServer.Metrics( sdk.WrapSDKContext(ctx), &types.QueryMetricsRequest{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }, ) require.NoError(t, err) diff --git a/x/perp/keeper/hooks_test.go b/x/perp/keeper/hooks_test.go index 5f92abfb3..e4ea8ee5b 100644 --- a/x/perp/keeper/hooks_test.go +++ b/x/perp/keeper/hooks_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" testutilevents "github.com/NibiruChain/nibiru/x/testutil" @@ -11,7 +12,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/x/common" epochtypes "github.com/NibiruChain/nibiru/x/epochs/types" "github.com/NibiruChain/nibiru/x/perp/types" ) @@ -51,7 +51,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { markPrice: sdk.NewDec(10), expectedLatestCumulativePremiumFraction: sdk.ZeroDec(), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), MarkPrice: sdk.NewDec(10), IndexPrice: sdk.NewDec(10), LatestFundingRate: sdk.ZeroDec(), @@ -67,7 +67,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { indexPrice: sdk.NewDec(462), expectedLatestCumulativePremiumFraction: sdk.MustNewDecFromStr("-9.229166666666666666"), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), MarkPrice: sdk.NewDec(19), IndexPrice: sdk.NewDec(462), LatestFundingRate: sdk.MustNewDecFromStr("-0.019976551226551227"), @@ -83,7 +83,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { indexPrice: sdk.NewDec(64), expectedLatestCumulativePremiumFraction: sdk.MustNewDecFromStr("14.1875"), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), MarkPrice: sdk.NewDec(745), IndexPrice: sdk.NewDec(64), LatestFundingRate: sdk.MustNewDecFromStr("0.2216796875"), @@ -108,7 +108,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { perpKeeper.AfterEpochEnd(ctx, "30 min", 1) t.Log("assert PairMetadataState") - pair, err := perpKeeper.PairsMetadata.Get(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + pair, err := perpKeeper.PairsMetadata.Get(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) assert.Equal(t, tc.expectedLatestCumulativePremiumFraction, pair.LatestCumulativePremiumFraction) @@ -131,23 +131,23 @@ func initParams(ctx sdk.Context, k Keeper) { TwapLookbackWindow: 15 * time.Minute, }) setPairMetadata(k, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), // start with one entry to ensure we append LatestCumulativePremiumFraction: sdk.ZeroDec(), }) } func setMocks(ctx sdk.Context, mocks mockedDependencies, indexPrice sdk.Dec, markPrice sdk.Dec) { - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockEpochKeeper.EXPECT().GetEpochInfo(ctx, "30 min").Return( epochtypes.EpochInfo{Duration: 30 * time.Minute}, ).MaxTimes(1) mocks.mockOracleKeeper.EXPECT(). - GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(indexPrice, nil).MaxTimes(1) + GetExchangeRateTwap(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(indexPrice, nil).MaxTimes(1) mocks.mockVpoolKeeper.EXPECT(). - GetMarkPriceTWAP(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), 15*time.Minute). + GetMarkPriceTWAP(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), 15*time.Minute). Return(markPrice, nil).MaxTimes(1) } diff --git a/x/perp/keeper/liquidate_unit_test.go b/x/perp/keeper/liquidate_unit_test.go index 60cb7a43c..567247848 100644 --- a/x/perp/keeper/liquidate_unit_test.go +++ b/x/perp/keeper/liquidate_unit_test.go @@ -7,6 +7,7 @@ import ( "github.com/NibiruChain/collections" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" testutilevents "github.com/NibiruChain/nibiru/x/testutil" @@ -15,7 +16,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/perp/types" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -91,7 +91,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -104,25 +104,25 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) + ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.OneDec(), 15*time.Minute, @@ -131,7 +131,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.OneDec(), ). @@ -139,7 +139,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.exchangedSize, ). @@ -147,7 +147,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /* quoteAmt */ tc.exchangedNotional, /* baseLimit */ sdk.ZeroDec(), @@ -179,16 +179,16 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee, feeToFund) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.NoError(t, err) assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) + assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) assert.EqualValues(t, tc.expectedPositionSize, newPosition.Size_) assert.EqualValues(t, tc.expectedPositionMargin, newPosition.Margin) assert.EqualValues(t, tc.expectedPositionOpenNotional, newPosition.OpenNotional) @@ -196,7 +196,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.exchangedNotional, ExchangedPositionSize: tc.exchangedSize.Neg(), @@ -266,7 +266,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -279,24 +279,24 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) + ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, 15*time.Minute, @@ -305,7 +305,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -313,7 +313,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /* baseAmt */ tc.initialPositionSize, /* quoteLimit */ sdk.ZeroDec(), @@ -347,18 +347,18 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee.String(), feeToFund.String()) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.ErrorIs(t, err, collections.ErrNotFound) assert.Empty(t, newPosition) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.newPositionNotional, ExchangedPositionSize: tc.initialPositionSize.Neg(), @@ -437,7 +437,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -450,24 +450,24 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) + ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, 15*time.Minute, @@ -476,7 +476,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -484,7 +484,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /* baseAmt */ tc.initialPositionSize, /* quoteLimit */ sdk.ZeroDec(), @@ -521,18 +521,18 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee.String(), feeToFund.String()) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.ErrorIs(t, err, collections.ErrNotFound) assert.Empty(t, newPosition) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.newPositionNotional, ExchangedPositionSize: tc.initialPositionSize.Neg(), @@ -588,7 +588,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { test: func() { perpKeeper, mocks, ctx := getKeeper(t) liquidator := testutilevents.AccAddress() - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false) err := perpKeeper.distributeLiquidateRewards(ctx, types.LiquidateResp{ @@ -598,7 +598,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { Liquidator: liquidator.String(), PositionResp: &types.PositionResp{ Position: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }, }, }, @@ -613,7 +613,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { perpKeeper, mocks, ctx := getKeeper(t) liquidator := testutilevents.AccAddress() - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockAccountKeeper. EXPECT().GetModuleAddress(types.VaultModuleAccount). @@ -639,7 +639,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { Liquidator: liquidator.String(), PositionResp: &types.PositionResp{ Position: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }}, }, ) @@ -929,16 +929,16 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { newParams.LiquidationFeeRatio = tc.liquidationFee perpKeeper.SetParams(ctx, newParams) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -946,20 +946,20 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), /* skipFluctuationLimitCheck */ true, ).Return( /*quoteAssetAmount=*/ tc.baseAssetPriceInQuote, nil) mocks.mockVpoolKeeper.EXPECT(). - GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMarkPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.OneDec(), nil) t.Log("create and set the initial position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialMargin, OpenNotional: tc.initialOpenNotional, @@ -997,7 +997,7 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { t.Log("assert new position fields") newPosition := positionResp.Position assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) + assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) assert.True(t, newPosition.Size_.IsZero()) // always zero assert.True(t, newPosition.Margin.IsZero()) // always zero assert.True(t, newPosition.OpenNotional.IsZero()) // always zero @@ -1005,15 +1005,15 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: positionResp.ExchangedNotionalValue, ExchangedPositionSize: positionResp.ExchangedPositionSize, LiquidatorAddress: liquidatorAddr.String(), - FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToLiquidator), - FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToPerpEF), + FeeToLiquidator: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToLiquidator), + FeeToEcosystemFund: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToPerpEF), BadDebt: sdk.NewCoin(denoms.NUSD, tc.expectedLiquidationBadDebt), - Margin: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), newPosition.Margin.RoundInt()), + Margin: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), newPosition.Margin.RoundInt()), PositionNotional: positionResp.PositionNotional, PositionSize: newPosition.Size_, UnrealizedPnl: positionResp.UnrealizedPnlAfter, @@ -1220,16 +1220,16 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { newParams.PartialLiquidationRatio = tc.partialLiquidationRatio perpKeeper.SetParams(ctx, newParams) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Mul(tc.partialLiquidationRatio), ). @@ -1238,7 +1238,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -1248,7 +1248,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ tc.baseAssetPriceInQuote.Mul(tc.partialLiquidationRatio), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), @@ -1258,7 +1258,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ tc.baseAssetPriceInQuote.Mul(tc.partialLiquidationRatio), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), @@ -1267,13 +1267,13 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { } mocks.mockVpoolKeeper.EXPECT(). - GetMarkPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMarkPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.OneDec(), nil) t.Log("create and set the initial position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialMargin, OpenNotional: tc.initialOpenNotional, @@ -1313,21 +1313,21 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { t.Log("assert new position fields") newPosition := positionResp.Position assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) + assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) assert.True(t, newPosition.LatestCumulativePremiumFraction.IsZero()) assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) assert.EqualValues(t, tc.expectedPositionMargin, newPosition.Margin) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: positionResp.ExchangedNotionalValue, ExchangedPositionSize: positionResp.ExchangedPositionSize, LiquidatorAddress: liquidatorAddr.String(), - FeeToLiquidator: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToLiquidator), - FeeToEcosystemFund: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToPerpEF), - BadDebt: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), sdk.ZeroInt()), - Margin: sdk.NewCoin(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), newPosition.Margin.RoundInt()), + FeeToLiquidator: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToLiquidator), + FeeToEcosystemFund: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToPerpEF), + BadDebt: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), sdk.ZeroInt()), + Margin: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), newPosition.Margin.RoundInt()), PositionNotional: positionResp.PositionNotional, PositionSize: newPosition.Size_, UnrealizedPnl: positionResp.UnrealizedPnlAfter, diff --git a/x/perp/keeper/margin_test.go b/x/perp/keeper/margin_test.go index bd6c103bb..e73b143d2 100644 --- a/x/perp/keeper/margin_test.go +++ b/x/perp/keeper/margin_test.go @@ -6,6 +6,7 @@ import ( "github.com/NibiruChain/collections" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" testutilevents "github.com/NibiruChain/nibiru/x/testutil" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -37,7 +38,7 @@ func TestAddMarginSuccess(t *testing.T) { latestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.001"), initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(1_000), Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(500), @@ -68,7 +69,7 @@ func TestAddMarginSuccess(t *testing.T) { vpoolKeeper := &nibiruApp.VpoolKeeper assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens vpooltypes.VpoolConfig{ @@ -79,11 +80,11 @@ func TestAddMarginSuccess(t *testing.T) { MaxLeverage: sdk.MustNewDecFromStr("15"), }, )) - require.True(t, vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD))) + require.True(t, vpoolKeeper.ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD))) t.Log("set pair metadata") setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: tc.latestCumulativePremiumFraction, }, ) @@ -91,14 +92,14 @@ func TestAddMarginSuccess(t *testing.T) { t.Log("establish initial position") setPosition(nibiruApp.PerpKeeper, ctx, tc.initialPosition) - resp, err := nibiruApp.PerpKeeper.AddMargin(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr, tc.marginToAdd) + resp, err := nibiruApp.PerpKeeper.AddMargin(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr, tc.marginToAdd) require.NoError(t, err) assert.EqualValues(t, tc.expectedFundingPayment, resp.FundingPayment) assert.EqualValues(t, tc.expectedMargin, resp.Position.Margin) assert.EqualValues(t, tc.initialPosition.OpenNotional, resp.Position.OpenNotional) assert.EqualValues(t, tc.initialPosition.Size_, resp.Position.Size_) assert.EqualValues(t, traderAddr.String(), resp.Position.TraderAddress) - assert.EqualValues(t, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), resp.Position.Pair) + assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), resp.Position.Pair) assert.EqualValues(t, tc.latestCumulativePremiumFraction, resp.Position.LatestCumulativePremiumFraction) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }) diff --git a/x/perp/keeper/margin_unit_test.go b/x/perp/keeper/margin_unit_test.go index 4e7f0f9a7..bc5983643 100644 --- a/x/perp/keeper/margin_unit_test.go +++ b/x/perp/keeper/margin_unit_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/perp/types" testutilevents "github.com/NibiruChain/nibiru/x/testutil" @@ -111,7 +112,7 @@ func TestGetMarginRatio(t *testing.T) { name: "margin without price changes", position: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -124,7 +125,7 @@ func TestGetMarginRatio(t *testing.T) { name: "margin with price changes", position: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -144,7 +145,7 @@ func TestGetMarginRatio(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.position.Size_.Abs(), ). @@ -153,7 +154,7 @@ func TestGetMarginRatio(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.position.Size_.Abs(), 15*time.Minute, @@ -161,7 +162,7 @@ func TestGetMarginRatio(t *testing.T) { Return(tc.newPrice, nil) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.OneDec(), }) @@ -635,7 +636,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -644,7 +645,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -658,7 +659,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -667,7 +668,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -681,7 +682,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -690,7 +691,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -705,7 +706,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -714,7 +715,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -729,7 +730,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -738,7 +739,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.NewDec(2), nil) }, @@ -750,7 +751,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -759,7 +760,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.MustNewDecFromStr("0.5"), nil) }, @@ -771,7 +772,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -780,7 +781,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), ). @@ -794,7 +795,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; negative pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -803,7 +804,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), ). @@ -817,7 +818,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -826,7 +827,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), 15*time.Minute, @@ -841,7 +842,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; negative pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -850,7 +851,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), 15*time.Minute, @@ -865,7 +866,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -874,7 +875,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.MustNewDecFromStr("0.5"), nil) }, @@ -886,7 +887,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -895,7 +896,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.NewDec(2), nil) }, @@ -942,7 +943,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "max pnl, pick spot price", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -952,7 +953,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -961,7 +962,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -976,7 +977,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "max pnl, pick twap", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -986,7 +987,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -995,7 +996,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -1010,7 +1011,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "min pnl, pick spot price", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -1020,7 +1021,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -1029,7 +1030,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -1044,7 +1045,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "min pnl, pick twap", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -1054,7 +1055,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -1063,7 +1064,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, diff --git a/x/perp/keeper/msg_server_test.go b/x/perp/keeper/msg_server_test.go index a2e42997a..118308027 100644 --- a/x/perp/keeper/msg_server_test.go +++ b/x/perp/keeper/msg_server_test.go @@ -15,6 +15,7 @@ import ( nibisimapp "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/perp/keeper" "github.com/NibiruChain/nibiru/x/perp/types" @@ -36,7 +37,7 @@ func TestMsgServerAddMargin(t *testing.T) { name: "trader not enough funds", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), @@ -57,7 +58,7 @@ func TestMsgServerAddMargin(t *testing.T) { name: "success", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), @@ -79,7 +80,7 @@ func TestMsgServerAddMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -91,7 +92,7 @@ func TestMsgServerAddMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -106,7 +107,7 @@ func TestMsgServerAddMargin(t *testing.T) { resp, err := msgServer.AddMargin(sdk.WrapSDKContext(ctx), &types.MsgAddMargin{ Sender: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Margin: tc.margin, }) @@ -143,7 +144,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { name: "position not enough margin", vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), @@ -164,7 +165,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { name: "vault insufficient funds", vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), @@ -178,7 +179,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { name: "success", vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: &types.Position{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), @@ -200,7 +201,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -212,7 +213,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -229,7 +230,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { resp, err := msgServer.RemoveMargin(sdk.WrapSDKContext(ctx), &types.MsgRemoveMargin{ Sender: traderAddr.String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Margin: tc.marginToRemove, }) @@ -264,14 +265,14 @@ func TestMsgServerOpenPosition(t *testing.T) { { name: "trader not enough funds", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sender: testutil.AccAddress().String(), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "success", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sender: testutil.AccAddress().String(), expectedErr: nil, }, @@ -287,7 +288,7 @@ func TestMsgServerOpenPosition(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + /* pair */ asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -299,7 +300,7 @@ func TestMsgServerOpenPosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -358,7 +359,7 @@ func TestMsgServerClosePosition(t *testing.T) { }{ { name: "success", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr: testutil.AccAddress(), expectedErr: nil, }, @@ -374,7 +375,7 @@ func TestMsgServerClosePosition(t *testing.T) { assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -386,7 +387,7 @@ func TestMsgServerClosePosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -435,7 +436,7 @@ func TestMsgServerLiquidate(t *testing.T) { }{ { name: "success", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), liquidator: testutil.AccAddress().String(), trader: testutil.AccAddress().String(), expectedErr: nil, @@ -453,7 +454,7 @@ func TestMsgServerLiquidate(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + /* pair */ asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -465,7 +466,7 @@ func TestMsgServerLiquidate(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(time.Now().Add(time.Minute)) @@ -473,7 +474,7 @@ func TestMsgServerLiquidate(t *testing.T) { traderAddr, err := sdk.AccAddressFromBech32(tc.trader) if err == nil { t.Log("set oracle price") - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) t.Log("create position") setPosition(app.PerpKeeper, ctx, types.Position{ @@ -516,7 +517,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ctx = ctx.WithBlockTime(time.Now()) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) - pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) liquidator := testutil.AccAddress() atRiskTrader1 := testutil.AccAddress() @@ -544,7 +545,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(time.Now().Add(time.Minute)) t.Log("set oracle price") - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) t.Log("create positions") atRiskPosition1 := types.Position{ diff --git a/x/perp/simulation/genesis.go b/x/perp/simulation/genesis.go index 0de722770..01ee88fe0 100644 --- a/x/perp/simulation/genesis.go +++ b/x/perp/simulation/genesis.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/perp/types" ) @@ -18,7 +18,7 @@ func RandomizedGenState(simState *module.SimulationState) { Params: types.DefaultParams(), PairMetadata: []types.PairMetadata{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, }, diff --git a/x/perp/simulation/operations.go b/x/perp/simulation/operations.go index 2639ac6f5..05fa6e37b 100644 --- a/x/perp/simulation/operations.go +++ b/x/perp/simulation/operations.go @@ -13,6 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/simulation" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/perp/keeper" "github.com/NibiruChain/nibiru/x/perp/types" @@ -76,7 +77,7 @@ func SimulateMsgOpenPosition(ak types.AccountKeeper, bk types.BankKeeper, k keep msg := &types.MsgOpenPosition{ Sender: simAccount.Address.String(), - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Side: side, QuoteAssetAmount: quoteAmt, Leverage: leverage, @@ -171,14 +172,14 @@ func SimulateMsgClosePosition(ak types.AccountKeeper, bk types.BankKeeper, k kee ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) msg := &types.MsgClosePosition{ Sender: trader, Pair: pair, } - _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) + _, err := k.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } @@ -209,10 +210,10 @@ func SimulateMsgAddMargin(ak types.AccountKeeper, bk types.BankKeeper, k keeper. ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) msg := &types.MsgAddMargin{} - _, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) + _, err := k.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } @@ -258,11 +259,11 @@ func SimulateMsgRemoveMargin(ak types.AccountKeeper, bk types.BankKeeper, k keep ) (opMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) msg := &types.MsgRemoveMargin{} - position, err := k.Positions.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) + position, err := k.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } diff --git a/x/perp/types/msgs_test.go b/x/perp/types/msgs_test.go index c7cdde13b..14853875a 100644 --- a/x/perp/types/msgs_test.go +++ b/x/perp/types/msgs_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" @@ -336,7 +337,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, }}, @@ -347,7 +348,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, { @@ -362,11 +363,11 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), Trader: "invalid", }, }}, diff --git a/x/stablecoin/abci.go b/x/stablecoin/abci.go index 2a89d6da0..412d04a7f 100644 --- a/x/stablecoin/abci.go +++ b/x/stablecoin/abci.go @@ -3,7 +3,7 @@ package stablecoin import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/stablecoin/keeper" ) @@ -20,7 +20,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { k.SetParams(ctx, params) } - _, err := k.OracleKeeper.GetExchangeRateTwap(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + _, err := k.OracleKeeper.GetExchangeRateTwap(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { params := k.GetParams(ctx) diff --git a/x/stablecoin/abci_test.go b/x/stablecoin/abci_test.go index 30e1ce592..a7d842dd9 100644 --- a/x/stablecoin/abci_test.go +++ b/x/stablecoin/abci_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/epochs" otypes "github.com/NibiruChain/nibiru/x/oracle/types" @@ -39,7 +40,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second * 60 * 16)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -53,7 +54,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second * 60 * 16)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -83,11 +84,11 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*15)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*30)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -101,11 +102,11 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*14)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*16)) - app.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -142,7 +143,7 @@ func TestEpochInfoChangesCollateralValidity(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) pairs := common.AssetPairs{ - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), } params := otypes.DefaultParams() params.TwapLookbackWindow = 1 * time.Hour diff --git a/x/stablecoin/client/cli/cli_test.go b/x/stablecoin/client/cli/cli_test.go index f7903cb68..d6391ce71 100644 --- a/x/stablecoin/client/cli/cli_test.go +++ b/x/stablecoin/client/cli/cli_test.go @@ -17,6 +17,7 @@ import ( "github.com/NibiruChain/nibiru/app" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" "github.com/NibiruChain/nibiru/x/stablecoin/client/cli" @@ -55,8 +56,8 @@ func (s *IntegrationTestSuite) SetupSuite() { oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDec(10)}, - {Pair: common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), ExchangeRate: sdk.NewDec(1)}, + {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDec(10)}, + {Pair: asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), ExchangeRate: sdk.NewDec(1)}, } oracleGenesis.Params.VotePeriod = 1_000 diff --git a/x/stablecoin/keeper/collateral_ratio.go b/x/stablecoin/keeper/collateral_ratio.go index ad786c250..aba113348 100644 --- a/x/stablecoin/keeper/collateral_ratio.go +++ b/x/stablecoin/keeper/collateral_ratio.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -87,7 +88,7 @@ func (k *Keeper) EvaluateCollRatio(ctx sdk.Context) (err error) { upperBound := params.GetPriceUpperBoundAsDec() stablePrice, err := k.OracleKeeper.GetExchangeRateTwap( - ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return err } @@ -121,7 +122,7 @@ func (k *Keeper) StableRequiredForTargetCollRatio( for _, collDenom := range collDenoms { amtColl := moduleCoins.AmountOf(collDenom) priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.ZeroDec(), err } @@ -139,7 +140,7 @@ func (k *Keeper) RecollateralizeCollAmtForTargetCollRatio( ) (neededCollAmount sdk.Int, err error) { neededUSDForRecoll, _ := k.StableRequiredForTargetCollRatio(ctx) priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -223,7 +224,7 @@ func (k Keeper) Recollateralize( // Compute GOV rewarded to user priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return response, err } @@ -294,7 +295,7 @@ func (k *Keeper) GovAmtFromRecollateralize( bonusRate := params.GetBonusRateRecollAsDec() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -337,7 +338,7 @@ func (k *Keeper) BuybackGovAmtForTargetCollRatio( neededUSDForRecoll, _ := k.StableRequiredForTargetCollRatio(ctx) neededUSDForBuyback := neededUSDForRecoll.Neg() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -414,7 +415,7 @@ func (k Keeper) Buyback( // Compute USD (stable) value of the GOV sent by the caller: 'inUSD' priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return response, err } @@ -474,7 +475,7 @@ func (k *Keeper) CollAmtFromBuyback( ctx sdk.Context, valUSD sdk.Dec, ) (collAmt sdk.Int, err error) { priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.Int{}, err } diff --git a/x/stablecoin/keeper/collateral_ratio_test.go b/x/stablecoin/keeper/collateral_ratio_test.go index 3c54d75cb..a46b449f8 100644 --- a/x/stablecoin/keeper/collateral_ratio_test.go +++ b/x/stablecoin/keeper/collateral_ratio_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" @@ -82,7 +83,7 @@ func TestSetCollRatioUpdate(t *testing.T) { stablecoinKeeper := &nibiruApp.StablecoinKeeper oracleKeeper := &nibiruApp.OracleKeeper - oracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.price) + oracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.price) err := stablecoinKeeper.SetCollRatio(ctx, tc.inCollRatio) require.NoError(t, err) err = stablecoinKeeper.EvaluateCollRatio(ctx) @@ -179,7 +180,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(500), priceCollStable: sdk.OneDec(), // startCollUSD = 500 * 1 -> 500 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 @@ -190,7 +191,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(600), priceCollStable: sdk.OneDec(), // startCollUSD = 600 * 1 = 600 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.5"), // 0.5 * 1000 = 500 @@ -223,7 +224,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { // Post prices to each specified market with the oracle. prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -296,7 +297,7 @@ func TestRecollateralizeCollAmtForTargetCollRatio(t *testing.T) { )) // Post the price - pair := common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD) + pair := asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD) nibiruApp.OracleKeeper.SetPrice(ctx, pair, tc.priceCollStable) neededCollAmount, err := stablecoinKeeper.RecollateralizeCollAmtForTargetCollRatio(ctx) @@ -335,7 +336,7 @@ func TestRecollateralizeCollAmtForTargetCollRatio(t *testing.T) { )) // Post the price - // pair := common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD) + // pair := asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD) // nibiruApp.OracleKeeper.SetPrice(ctx, pair, tc.priceCollStable) neededCollAmount, err := stablecoinKeeper.RecollateralizeCollAmtForTargetCollRatio(ctx) @@ -378,7 +379,7 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 priceCollStable: sdk.OneDec(), postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)}, + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -389,7 +390,7 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 priceGovStable: sdk.OneDec(), postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -399,8 +400,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(10_000), targetCollRatio: sdk.MustNewDecFromStr("0.7"), // 0.7 * 10_000 = 7_000 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(2), @@ -415,8 +416,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(100_000), targetCollRatio: sdk.MustNewDecFromStr("0.7"), // 0.7 * 100_000 = 70_000 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -431,8 +432,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(100_000), targetCollRatio: sdk.MustNewDecFromStr("0.5"), // 0.5 * 100_000 = 50_000 postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -457,8 +458,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { )) prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -466,8 +467,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { // Post prices to each specified market with the oracle. prices = map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, } for _, assetPair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, assetPair, prices[assetPair]) @@ -519,8 +520,8 @@ func TestRecollateralize(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -552,8 +553,8 @@ func TestRecollateralize(t *testing.T) { { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -587,8 +588,8 @@ func TestRecollateralize(t *testing.T) { { name: "protocol has sufficient collateral - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -614,8 +615,8 @@ func TestRecollateralize(t *testing.T) { { name: "caller is broke - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -641,8 +642,8 @@ func TestRecollateralize(t *testing.T) { { name: "negative msg.Coll.Amount - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -668,7 +669,7 @@ func TestRecollateralize(t *testing.T) { { name: "oracle prices are expired - error", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -717,8 +718,8 @@ func TestRecollateralize(t *testing.T) { } prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -726,8 +727,8 @@ func TestRecollateralize(t *testing.T) { // Post prices to each specified market with the oracle. prices = map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, } for _, assetPair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, assetPair, prices[assetPair]) @@ -850,8 +851,8 @@ func TestBuyback(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -886,8 +887,8 @@ func TestBuyback(t *testing.T) { { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(850_000), @@ -927,8 +928,8 @@ func TestBuyback(t *testing.T) { { name: "msg has more NIBI than the protocol needs, only needed sent", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -960,8 +961,8 @@ func TestBuyback(t *testing.T) { { name: "protocol under-collateralized, so buyback won't run", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -986,8 +987,8 @@ func TestBuyback(t *testing.T) { { name: "caller has insufficient funds", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1012,7 +1013,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing collateral price post", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1037,7 +1038,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing NIBI price post", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1090,8 +1091,8 @@ func TestBuyback(t *testing.T) { // Set up markets for the oracle keeper. prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -1132,8 +1133,8 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, correct amount out", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1163,7 +1164,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, only coll price posted", postedAssetPairs: []common.AssetPair{ - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1192,8 +1193,8 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { )) prices := map[common.AssetPair]sdk.Dec{ - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, - common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) diff --git a/x/stablecoin/keeper/mint_burn_stable.go b/x/stablecoin/keeper/mint_burn_stable.go index 14fe14400..e233f849c 100644 --- a/x/stablecoin/keeper/mint_burn_stable.go +++ b/x/stablecoin/keeper/mint_burn_stable.go @@ -12,6 +12,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -94,7 +95,7 @@ func (k Keeper) calcNeededGovAndFees( ctx sdk.Context, stable sdk.Coin, govRatio sdk.Dec, feeRatio sdk.Dec, ) (sdk.Coin, sdk.Coin, error) { priceGov, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } @@ -116,7 +117,7 @@ func (k Keeper) calcNeededCollateralAndFees( feeRatio sdk.Dec, ) (sdk.Coin, sdk.Coin, error) { priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } diff --git a/x/stablecoin/keeper/mint_burn_stable_test.go b/x/stablecoin/keeper/mint_burn_stable_test.go index 18cb72763..446ef4d70 100644 --- a/x/stablecoin/keeper/mint_burn_stable_test.go +++ b/x/stablecoin/keeper/mint_burn_stable_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" @@ -145,8 +146,8 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { ) // Post prices to each pair with the oracle. - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Fund account require.NoError(t, simapp.FundAccount(nibiruApp.BankKeeper, ctx, acc, tc.accFunds)) @@ -302,8 +303,8 @@ func TestMsgMintStableResponse_NotEnoughFunds(t *testing.T) { ) t.Log("Post prices to each pair with the oracle.") - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Fund account require.NoError(t, simapp.FundAccount(nibiruApp.BankKeeper, ctx, acc, tc.accFunds)) @@ -449,8 +450,8 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { nibiruApp.StablecoinKeeper.SetParams(ctx, defaultParams) t.Log("Post prices to each pair with the oracle.") - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Add collaterals to the module require.NoError(t, nibiruApp.BankKeeper.MintCoins(ctx, types.ModuleName, tc.moduleFunds)) @@ -570,8 +571,8 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { ), ) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Add collaterals to the module require.NoError(t, nibiruApp.BankKeeper.MintCoins(ctx, types.ModuleName, tc.moduleFunds)) diff --git a/x/vpool/abci_test.go b/x/vpool/abci_test.go index efabc73ab..5e9b4cc3f 100644 --- a/x/vpool/abci_test.go +++ b/x/vpool/abci_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/simapp" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" "github.com/NibiruChain/nibiru/x/vpool" @@ -32,7 +32,7 @@ func TestSnapshotUpdates(t *testing.T) { require.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(1_000), sdk.NewDec(1_000), types.DefaultVpoolConfig(). @@ -40,7 +40,7 @@ func TestSnapshotUpdates(t *testing.T) { WithFluctuationLimitRatio(sdk.OneDec()), )) expectedSnapshot := types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(1_000), sdk.NewDec(1_000), ctx.BlockTime(), @@ -48,14 +48,14 @@ func TestSnapshotUpdates(t *testing.T) { t.Log("run one block of 5 seconds") runBlock(5 * time.Second) - snapshot, err := vpoolKeeper.ReserveSnapshots.Get(ctx, collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) + snapshot, err := vpoolKeeper.ReserveSnapshots.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) require.NoError(t, err) assert.EqualValues(t, expectedSnapshot, snapshot) t.Log("affect mark price") baseAmtAbs, err := vpoolKeeper.SwapQuoteForBase( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), types.Direction_ADD_TO_POOL, sdk.NewDec(250), // ← dyAmm sdk.ZeroDec(), @@ -65,7 +65,7 @@ func TestSnapshotUpdates(t *testing.T) { assert.EqualValues(t, sdk.NewDec(200), baseAmtAbs) require.NoError(t, err) expectedSnapshot = types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(800), // ← x + dxAmm sdk.NewDec(1_250), // ← y + dyAMM ctx.BlockTime(), @@ -76,7 +76,7 @@ func TestSnapshotUpdates(t *testing.T) { timeSkipDuration := 5 * time.Second runBlock(timeSkipDuration) // increments ctx.blockHeight and ctx.BlockTime snapshot, err = vpoolKeeper.ReserveSnapshots.Get(ctx, - collections.Join(common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) + collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) require.NoError(t, err) assert.EqualValues(t, expectedSnapshot, snapshot) diff --git a/x/vpool/client/cli/cli_test.go b/x/vpool/client/cli/cli_test.go index a3d1e2987..e3580d73d 100644 --- a/x/vpool/client/cli/cli_test.go +++ b/x/vpool/client/cli/cli_test.go @@ -16,6 +16,7 @@ import ( "github.com/NibiruChain/nibiru/app" "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" oracletypes "github.com/NibiruChain/nibiru/x/oracle/types" testutilcli "github.com/NibiruChain/nibiru/x/testutil/cli" @@ -35,8 +36,8 @@ func TestIntegrationTestSuite(t *testing.T) { } var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD): { - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD): { + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -47,8 +48,8 @@ var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ MaxLeverage: sdk.MustNewDecFromStr("15"), }, }, - common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): { - Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): { + Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), BaseAssetReserve: sdk.NewDec(500_000), QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -74,14 +75,14 @@ func (s *IntegrationTestSuite) SetupSuite() { genesisState := simapp.NewTestGenesisStateFromDefault() vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ - START_VPOOLS[common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)], - START_VPOOLS[common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)], + START_VPOOLS[asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)], + START_VPOOLS[asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)], } oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDec(1_000)}, - {Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDec(10)}, + {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDec(1_000)}, + {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDec(10)}, } oracleGenesis.Params.VotePeriod = 1_000 @@ -169,13 +170,13 @@ func (s *IntegrationTestSuite) TestGetPrices() { val := s.network.Validators[0] s.T().Log("check vpool balances") - reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)) + reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("10000000"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.MustNewDecFromStr("60000000000"), reserveAssets.QuoteAssetReserve) s.T().Log("check prices") - priceInfo, err := testutilcli.QueryBaseAssetPrice(val.ClientCtx, common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), "add", "100") + priceInfo, err := testutilcli.QueryBaseAssetPrice(val.ClientCtx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), "add", "100") s.T().Logf("priceInfo: %+v", priceInfo) s.EqualValues(sdk.MustNewDecFromStr("599994.000059999400006000"), priceInfo.PriceInQuoteDenom) s.NoError(err) @@ -187,7 +188,7 @@ func (s *IntegrationTestSuite) TestCmdEditPoolConfigProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)] + startVpool := START_VPOOLS[asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)] proposal := &vpooltypes.EditPoolConfigProposal{ Title: "NIP-3: Edit config of the ueth:unusd vpool", Description: "enables higher max leverage on ueth:unusd", @@ -253,7 +254,7 @@ func (s *IntegrationTestSuite) TestCmdEditSwapInvariantsProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)] + startVpool := START_VPOOLS[asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)] proposal := &vpooltypes.EditSwapInvariantsProposal{ Title: "NIP-4: Change the swap invariant for ATOM, OSMO, and BTC.", Description: "increase swap invariant for many virtual pools", diff --git a/x/vpool/keeper/keeper_test.go b/x/vpool/keeper/keeper_test.go index f6a83a714..dead502a3 100644 --- a/x/vpool/keeper/keeper_test.go +++ b/x/vpool/keeper/keeper_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil/mock" "github.com/NibiruChain/nibiru/x/vpool/types" @@ -33,7 +34,7 @@ func TestSwapQuoteForBase(t *testing.T) { }{ { name: "quote amount == 0", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(0), baseLimit: sdk.NewDec(10), @@ -45,7 +46,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap add", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(49504), @@ -57,7 +58,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap remove", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(50506), @@ -79,7 +80,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount less than base limit in Long", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(500_000), baseLimit: sdk.NewDec(454_500), @@ -89,7 +90,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount more than base limit in Short", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_500), @@ -99,7 +100,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when removing quote", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -109,7 +110,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when adding quote", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -119,7 +120,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), @@ -129,7 +130,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), @@ -139,7 +140,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), @@ -151,7 +152,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), @@ -173,7 +174,7 @@ func TestSwapQuoteForBase(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ @@ -201,7 +202,7 @@ func TestSwapQuoteForBase(t *testing.T) { assert.EqualValuesf(t, tc.expectedBaseAmount, baseAmt, "base amount mismatch") t.Log("assert vpool") - pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + pool, err := vpoolKeeper.Pools.Get(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) assert.EqualValuesf(t, tc.expectedQuoteReserve, pool.QuoteAssetReserve, "pool quote asset reserve mismatch") assert.EqualValuesf(t, tc.expectedBaseReserve, pool.BaseAssetReserve, "pool base asset reserve mismatch") @@ -226,7 +227,7 @@ func TestSwapBaseForQuote(t *testing.T) { }{ { name: "zero base asset swap", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.ZeroDec(), quoteLimit: sdk.ZeroDec(), @@ -238,7 +239,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "add base asset swap", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196078), @@ -250,7 +251,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "remove base asset", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(204_082), @@ -272,7 +273,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount less than quote limit in Long", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196079), @@ -282,7 +283,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount more than quote limit in Short", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(204_081), @@ -292,7 +293,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when removing base", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -302,7 +303,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when adding base", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -312,7 +313,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), @@ -322,7 +323,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), @@ -332,7 +333,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), @@ -344,7 +345,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), @@ -366,7 +367,7 @@ func TestSwapBaseForQuote(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ @@ -395,7 +396,7 @@ func TestSwapBaseForQuote(t *testing.T) { "expected %s; got %s", tc.expectedQuoteAssetAmount.String(), quoteAssetAmount.String()) t.Log("assert pool") - pool, err := vpoolKeeper.Pools.Get(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + pool, err := vpoolKeeper.Pools.Get(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) assert.Equal(t, tc.expectedQuoteReserve, pool.QuoteAssetReserve) assert.Equal(t, tc.expectedBaseReserve, pool.BaseAssetReserve) @@ -411,7 +412,7 @@ func TestGetVpools(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), sdk.NewDec(5*common.Precision), types.VpoolConfig{ @@ -424,7 +425,7 @@ func TestGetVpools(t *testing.T) { )) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), sdk.NewDec(5*common.Precision), sdk.NewDec(10*common.Precision), types.VpoolConfig{ @@ -441,7 +442,7 @@ func TestGetVpools(t *testing.T) { require.EqualValues(t, 2, len(pools)) require.EqualValues(t, pools[0], types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(5 * common.Precision), QuoteAssetReserve: sdk.NewDec(10 * common.Precision), Config: types.VpoolConfig{ @@ -453,7 +454,7 @@ func TestGetVpools(t *testing.T) { }, }) require.EqualValues(t, pools[1], types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: types.VpoolConfig{ @@ -477,7 +478,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses latest snapshot - does not result in error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -490,13 +491,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -507,7 +508,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses previous snapshot - results in error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -520,7 +521,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -531,7 +532,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "only one snapshot - no error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -544,7 +545,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -555,7 +556,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "zero fluctuation limit - no error", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -568,13 +569,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -585,7 +586,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "multiple pools - no overlap", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -598,25 +599,25 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -638,7 +639,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { for _, snapshot := range tc.existingSnapshots { vpoolKeeper.ReserveSnapshots.Insert( ctx, - collections.Join[common.AssetPair, time.Time]( + collections.Join( snapshot.Pair, time.UnixMilli(snapshot.TimestampMs)), snapshot) @@ -667,7 +668,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -678,7 +679,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -695,7 +696,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { mock.NewMockOracleKeeper(gomock.NewController(t)), ) vpoolKeeper.Pools.Insert(ctx, tc.pool.Pair, tc.pool) - mmr, err := vpoolKeeper.GetMaintenanceMarginRatio(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + mmr, err := vpoolKeeper.GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) assert.NoError(t, err) assert.EqualValues(t, tc.expectedMaintenanceMarginRatio, mmr) }) @@ -712,7 +713,7 @@ func TestGetMaxLeverage(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -735,7 +736,7 @@ func TestGetMaxLeverage(t *testing.T) { ) vpoolKeeper.Pools.Insert(ctx, tc.pool.Pair, tc.pool) - maxLeverage, err := vpoolKeeper.GetMaxLeverage(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + maxLeverage, err := vpoolKeeper.GetMaxLeverage(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) assert.EqualValues(t, tc.expectedMaxLeverage, maxLeverage) assert.NoError(t, err) }) diff --git a/x/vpool/keeper/pool_state_test.go b/x/vpool/keeper/pool_state_test.go index 58b7aeec8..d8b5706b7 100644 --- a/x/vpool/keeper/pool_state_test.go +++ b/x/vpool/keeper/pool_state_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -19,7 +20,7 @@ func TestCreatePool(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens @@ -32,7 +33,7 @@ func TestCreatePool(t *testing.T) { }, )) - exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + exists := vpoolKeeper.ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.True(t, exists) notExist := vpoolKeeper.ExistsPool(ctx, "BTC:OTHER") @@ -40,7 +41,7 @@ func TestCreatePool(t *testing.T) { } func TestEditPoolConfig(t *testing.T) { - pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) vpoolStart := types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(10 * common.Precision), @@ -58,12 +59,12 @@ func TestEditPoolConfig(t *testing.T) { vpoolKeeper, _, ctx := getKeeper(t) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), vpoolStart.QuoteAssetReserve, vpoolStart.BaseAssetReserve, vpoolStart.Config, )) - exists := vpoolKeeper.ExistsPool(ctx, common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + exists := vpoolKeeper.ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) require.True(t, exists) return vpoolKeeper, ctx } @@ -189,7 +190,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool + pricefeed active", vpool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -203,7 +204,7 @@ func TestGetPoolPrices(t *testing.T) { shouldCreateVpool: true, mockIndexPrice: sdk.NewDec(99), expectedPoolPrices: types.PoolPrices{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.NewDec(99).String(), @@ -214,7 +215,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool active, but no index price", vpool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -229,7 +230,7 @@ func TestGetPoolPrices(t *testing.T) { mockIndexPrice: sdk.OneDec().Neg(), oracleKeeperErr: fmt.Errorf("No index price"), expectedPoolPrices: types.PoolPrices{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.OneDec().Neg().String(), @@ -240,7 +241,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "vpool doesn't exist", vpool: types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -293,7 +294,7 @@ func TestGetPoolPrices(t *testing.T) { } func TestEditSwapInvariant(t *testing.T) { - pair := common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD) + pair := asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD) vpoolStart := types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(10 * common.Precision), diff --git a/x/vpool/keeper/prices_test.go b/x/vpool/keeper/prices_test.go index df38197bc..02c6d4d9f 100644 --- a/x/vpool/keeper/prices_test.go +++ b/x/vpool/keeper/prices_test.go @@ -12,6 +12,7 @@ import ( "github.com/NibiruChain/collections" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil/mock" "github.com/NibiruChain/nibiru/x/vpool/types" @@ -27,14 +28,14 @@ func TestGetMarkPrice(t *testing.T) { }{ { name: "correctly fetch underlying price", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(1), expectedPrice: sdk.NewDec(40000), }, { name: "complex price", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(2_489_723_947), baseAssetReserve: sdk.NewDec(34_597_234), expectedPrice: sdk.MustNewDecFromStr("71.963092396345904415"), @@ -81,7 +82,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), baseAmount: sdk.ZeroDec(), @@ -90,7 +91,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -99,7 +100,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -108,7 +109,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("1000"), @@ -164,7 +165,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), quoteAmount: sdk.ZeroDec(), @@ -173,7 +174,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -182,7 +183,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -191,7 +192,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(1000), @@ -253,22 +254,22 @@ func TestCalcTwap(t *testing.T) { // expected price: ((95/10 * (35 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 10) + 100/1 * (10 - 5)) / (5 + 10 + 10 + 5) { name: "spot price twap calc, t=[5,35]", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -284,22 +285,22 @@ func TestCalcTwap(t *testing.T) { // expected price: (95/10 * (30 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 10)) / (10 + 10) { name: "spot price twap calc, t=[10,30]", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -315,22 +316,22 @@ func TestCalcTwap(t *testing.T) { // expected price: (95/10 * (35 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 11)) / (5 + 10 + 9) { name: "spot price twap calc, t=[11,35]", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -348,7 +349,7 @@ func TestCalcTwap(t *testing.T) { // expected price: 100/1 { name: "spot price twap calc, t=[0,0]", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{}, currentBlockTime: time.UnixMilli(0), currentBlockHeight: 1, @@ -362,16 +363,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((7.5 - 300/(40 + 10)) * (30 - 20) + (10 - 300/(30 + 10)) * (20 - 10)) / (10 + 10) { name: "quote asset swap twap calc, add to pool, t=[10,30]", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(30), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.MustNewDecFromStr("7.5"), sdk.NewDec(40), time.UnixMilli(20), @@ -391,16 +392,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((12 - 600/(50 - 10)) * (30 - 20) + (10 - 600/(60 - 10)) * (20 - 10)) / (10 + 10) { name: "quote asset swap twap calc, remove from pool, t=[10,30]", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(12), sdk.NewDec(50), time.UnixMilli(20), @@ -416,10 +417,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: quote asset reserve = asset amount", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(20), time.UnixMilli(20), @@ -439,16 +440,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((60 - 600/(10 + 10)) * (20 - 10) + (30 - 600/(20 + 10)) * (30 - 20)) / (10 + 10) { name: "base asset swap twap calc, add to pool, t=[10,30]", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(20), sdk.NewDec(30), time.UnixMilli(20), @@ -468,16 +469,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((60 - 600/(10 - 2)) * (20 - 10) + (75 - 600/(8 - 2)) * (30 - 20)) / (10 + 10) { name: "base asset swap twap calc, remove from pool, t=[10,30]", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(8), sdk.NewDec(75), time.UnixMilli(20), @@ -493,10 +494,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: base asset reserve = asset amount", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(20), @@ -540,7 +541,7 @@ func TestCalcTwap(t *testing.T) { for _, snapshot := range tc.reserveSnapshots { ctx = ctx.WithBlockTime(time.UnixMilli(snapshot.TimestampMs)) snapshot := types.NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), snapshot.BaseAssetReserve, snapshot.QuoteAssetReserve, ctx.BlockTime(), diff --git a/x/vpool/keeper/query_server_test.go b/x/vpool/keeper/query_server_test.go index 9cbb2b7d0..d80c4ba7a 100644 --- a/x/vpool/keeper/query_server_test.go +++ b/x/vpool/keeper/query_server_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil/mock" "github.com/NibiruChain/nibiru/x/vpool/types" @@ -24,7 +25,7 @@ func TestQueryReserveAssets(t *testing.T) { t.Log("initialize vpool") pool := types.Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1 * common.Precision), BaseAssetReserve: sdk.NewDec(1000), Config: types.VpoolConfig{ @@ -41,7 +42,7 @@ func TestQueryReserveAssets(t *testing.T) { resp, err := queryServer.ReserveAssets( sdk.WrapSDKContext(ctx), &types.QueryReserveAssetsRequest{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), }, ) @@ -58,7 +59,7 @@ func TestQueryAllPools(t *testing.T) { queryServer := NewQuerier(vpoolKeeper) t.Log("initialize vpool") - pair := common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) pool := &types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(1 * common.Precision), diff --git a/x/vpool/keeper/snapshot_test.go b/x/vpool/keeper/snapshot_test.go index 0f0126406..cbd69aa52 100644 --- a/x/vpool/keeper/snapshot_test.go +++ b/x/vpool/keeper/snapshot_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -25,7 +26,7 @@ func TestGetSnapshotPrice(t *testing.T) { }{ { name: "spot price calc", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(2), twapCalcOption: types.TwapCalcOption_SPOT, @@ -33,7 +34,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap add to pool calc", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_QUOTE_ASSET_SWAP, @@ -43,7 +44,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap remove from pool calc", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_QUOTE_ASSET_SWAP, @@ -53,7 +54,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap add to pool calc", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_BASE_ASSET_SWAP, @@ -63,7 +64,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap remove from pool calc", - pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_BASE_ASSET_SWAP, diff --git a/x/vpool/simulation/genesis.go b/x/vpool/simulation/genesis.go index 1f86f33f9..163cc8ef4 100644 --- a/x/vpool/simulation/genesis.go +++ b/x/vpool/simulation/genesis.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/vpool/types" ) @@ -24,7 +24,7 @@ func RandomizedGenState(simState *module.SimulationState) { vpoolGenesis := types.GenesisState{ Vpools: []types.Vpool{ { - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(10e12).Add(simtypes.RandomDecAmount(simState.Rand, sdk.NewDec(10e12))), BaseAssetReserve: sdk.NewDec(10e12).Add(simtypes.RandomDecAmount(simState.Rand, sdk.NewDec(10e12))), Config: types.VpoolConfig{ diff --git a/x/vpool/types/gov_test.go b/x/vpool/types/gov_test.go index a6443b40b..fcd616255 100644 --- a/x/vpool/types/gov_test.go +++ b/x/vpool/types/gov_test.go @@ -11,6 +11,7 @@ import ( "github.com/gogo/protobuf/jsonpb" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/stretchr/testify/assert" @@ -145,7 +146,7 @@ func TestMarshalProposalEditPoolConfig(t *testing.T) { proposal := EditPoolConfigProposal{ Title: "Edit vpool config for NIBI:NUSD", Description: "I want to take 100x leverage on my NIBI", - Pair: common.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), Config: VpoolConfig{ MaxLeverage: sdk.MustNewDecFromStr("100"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), diff --git a/x/vpool/types/pool_test.go b/x/vpool/types/pool_test.go index 8f468049b..a66ce1423 100644 --- a/x/vpool/types/pool_test.go +++ b/x/vpool/types/pool_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" ) @@ -505,7 +506,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "happy path", Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -514,7 +515,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil base", Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -523,7 +524,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero base", Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -532,7 +533,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil quote", Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.Dec{}, }, @@ -541,7 +542,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero quote", Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.ZeroDec(), }, @@ -567,7 +568,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "zero fluctuation limit ratio", pool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -583,7 +584,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "lower limit of fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(999), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -599,7 +600,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "upper limit of fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1001), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -615,7 +616,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "under fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(998), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -631,7 +632,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "over fluctuation limit", pool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -650,7 +651,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { snapshot := NewReserveSnapshot( - common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec(), sdk.NewDec(1000), time.Now(), @@ -669,7 +670,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "happy path", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10), QuoteAssetReserve: sdk.NewDec(10_000), }, @@ -678,7 +679,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid base", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.NewDec(500), }, @@ -687,7 +688,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid quote", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.Dec{}, }, @@ -696,7 +697,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative quote", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.NewDec(-500), }, @@ -705,7 +706,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative base", vpool: Vpool{ - Pair: common.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(-500), QuoteAssetReserve: sdk.NewDec(500), }, diff --git a/x/vpool/types/snapshot_test.go b/x/vpool/types/snapshot_test.go index 25dca6447..e78ce4486 100644 --- a/x/vpool/types/snapshot_test.go +++ b/x/vpool/types/snapshot_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" ) @@ -20,7 +21,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "happy path", snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.OneDec(), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -40,7 +41,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "base asset negative", snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(-1), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -50,7 +51,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "quote asset negative", snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.NewDec(-1), TimestampMs: time.Now().UnixMilli(), @@ -61,7 +62,7 @@ func TestSnapshotValidate(t *testing.T) { name: "timestamp lower than smallest UTC ('0001-01-01 00:00:00 +0000 UTC')", // see time.UnixMilli(-62135596800000).UTC()) snapshot: ReserveSnapshot{ - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.ZeroDec(), TimestampMs: -62135596800000 - 1, diff --git a/x/wasm/cli/cli_test.go b/x/wasm/cli/cli_test.go index 9e3f6b5e9..9f9faf542 100644 --- a/x/wasm/cli/cli_test.go +++ b/x/wasm/cli/cli_test.go @@ -16,6 +16,7 @@ import ( "github.com/NibiruChain/nibiru/app" "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" "github.com/NibiruChain/nibiru/x/common/denoms" testutilcli "github.com/NibiruChain/nibiru/x/testutil/cli" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -49,7 +50,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: common.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ From bf139c9caca3ad48cf92f173f4260f66775aef75 Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Wed, 25 Jan 2023 19:40:12 -0500 Subject: [PATCH 9/9] refactor: rename AssetRegistry to Registry --- simapp/testapp.go | 2 +- x/common/asset/asset_registry_test.go | 82 ----------- .../asset/{asset_registry.go => registry.go} | 20 +-- x/common/asset/registry_test.go | 82 +++++++++++ x/common/error_test.go | 4 +- x/oracle/keeper/ballot_test.go | 32 ++--- x/oracle/keeper/keeper_test.go | 4 +- x/oracle/keeper/msg_server_test.go | 18 +-- x/oracle/keeper/querier_test.go | 44 +++--- x/oracle/keeper/reward_test.go | 8 +- x/oracle/keeper/slash_test.go | 40 +++--- x/oracle/keeper/tally_fuzz_test.go | 8 +- x/oracle/keeper/update_exchange_rates_test.go | 110 +++++++------- x/oracle/simulation/decoder_test.go | 4 +- x/oracle/simulation/genesis.go | 10 +- x/oracle/simulation/operations.go | 2 +- x/oracle/types/ballot_test.go | 26 ++-- x/oracle/types/params.go | 8 +- x/perp/client/cli/cli_test.go | 76 +++++----- x/perp/genesis_test.go | 4 +- x/perp/keeper/calc_test.go | 2 +- x/perp/keeper/calc_unit_test.go | 24 ++-- .../keeper/clearing_house_integration_test.go | 34 ++--- x/perp/keeper/clearing_house_unit_test.go | 136 +++++++++--------- x/perp/keeper/grpc_query_test.go | 66 ++++----- x/perp/keeper/hooks_test.go | 16 +-- x/perp/keeper/liquidate_unit_test.go | 134 ++++++++--------- x/perp/keeper/margin_test.go | 12 +- x/perp/keeper/margin_unit_test.go | 82 +++++------ x/perp/keeper/msg_server_test.go | 48 +++---- x/perp/simulation/genesis.go | 2 +- x/perp/simulation/operations.go | 14 +- x/perp/types/msgs_test.go | 8 +- x/stablecoin/abci.go | 2 +- x/stablecoin/abci_test.go | 14 +- x/stablecoin/client/cli/cli_test.go | 4 +- x/stablecoin/keeper/collateral_ratio.go | 16 +-- x/stablecoin/keeper/collateral_ratio_test.go | 102 ++++++------- x/stablecoin/keeper/mint_burn_stable.go | 4 +- x/stablecoin/keeper/mint_burn_stable_test.go | 16 +-- x/vpool/abci_test.go | 12 +- x/vpool/client/cli/cli_test.go | 24 ++-- x/vpool/keeper/keeper_test.go | 100 ++++++------- x/vpool/keeper/pool_state_test.go | 22 +-- x/vpool/keeper/prices_test.go | 80 +++++------ x/vpool/keeper/query_server_test.go | 6 +- x/vpool/keeper/snapshot_test.go | 10 +- x/vpool/simulation/genesis.go | 2 +- x/vpool/types/gov_test.go | 2 +- x/vpool/types/pool_test.go | 32 ++--- x/vpool/types/snapshot_test.go | 8 +- x/wasm/cli/cli_test.go | 2 +- 52 files changed, 810 insertions(+), 810 deletions(-) delete mode 100644 x/common/asset/asset_registry_test.go rename x/common/asset/{asset_registry.go => registry.go} (77%) create mode 100644 x/common/asset/registry_test.go diff --git a/simapp/testapp.go b/simapp/testapp.go index ad67750cd..0056e7fc4 100644 --- a/simapp/testapp.go +++ b/simapp/testapp.go @@ -38,7 +38,7 @@ func NewTestNibiruAppAndContext(shouldUseDefaultGenesis bool) (*NibiruTestApp, s newNibiruApp := NewTestNibiruApp(shouldUseDefaultGenesis) ctx := newNibiruApp.NewContext(false, tmproto.Header{}) - newNibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(20000)) + newNibiruApp.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(20000)) // newNibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewDec(10)) newNibiruApp.OracleKeeper.SetPrice(ctx, "xxx:yyy", sdk.NewDec(20000)) diff --git a/x/common/asset/asset_registry_test.go b/x/common/asset/asset_registry_test.go deleted file mode 100644 index de9b20caa..000000000 --- a/x/common/asset/asset_registry_test.go +++ /dev/null @@ -1,82 +0,0 @@ -package asset - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/NibiruChain/nibiru/x/common" - "github.com/NibiruChain/nibiru/x/common/denoms" -) - -func TestIsSupportedPair(t *testing.T) { - for base := range AssetRegistry { - for quote := range AssetRegistry[base] { - require.Truef(t, AssetRegistry.IsSupportedPair(base, quote), "%s:%s should be supported", base, quote) - } - } - - t.Log("test an unsupported pair") - require.False(t, AssetRegistry.IsSupportedPair(denoms.ATOM, denoms.OSMO)) -} - -func TestPair(t *testing.T) { - for base := range AssetRegistry { - for quote := range AssetRegistry[base] { - require.Equal(t, common.NewAssetPair(base, quote), AssetRegistry.Pair(base, quote)) - } - } - - t.Log("test an unsupported pair") - require.Equal(t, common.AssetPair(""), AssetRegistry.Pair(denoms.ATOM, denoms.OSMO)) - - t.Log("test an unsupported base asset") - require.Equal(t, common.AssetPair(""), AssetRegistry.Pair("unsuported_denom", denoms.USDC)) - - t.Log("test an unsupported quote asset") - require.Equal(t, common.AssetPair(""), AssetRegistry.Pair(denoms.ATOM, "unsupported_denom")) -} - -func TestBaseDenoms(t *testing.T) { - for base := range AssetRegistry { - require.Contains(t, AssetRegistry.BaseDenoms(), base) - } -} - -func TestIsSupportedBaseDenom(t *testing.T) { - for base := range AssetRegistry { - require.True(t, AssetRegistry.IsSupportedBaseDenom(base)) - } - require.False(t, AssetRegistry.IsSupportedBaseDenom("unsupported_denom")) -} - -func TestQuoteDenoms(t *testing.T) { - for base := range AssetRegistry { - for quote := range AssetRegistry[base] { - require.True(t, AssetRegistry.QuoteDenoms().Has(quote)) - } - } -} - -func TestIsSupportedQuoteDenom(t *testing.T) { - for base := range AssetRegistry { - for quote := range AssetRegistry[base] { - require.True(t, AssetRegistry.IsSupportedQuoteDenom(quote)) - } - } - - require.False(t, AssetRegistry.IsSupportedQuoteDenom("unsupported_denom")) -} - -func TestIsSupportedDenom(t *testing.T) { - for base := range AssetRegistry.BaseDenoms() { - require.True(t, AssetRegistry.IsSupportedDenom(base)) - } - - for quote := range AssetRegistry.QuoteDenoms() { - require.True(t, AssetRegistry.IsSupportedDenom(quote)) - } - - t.Log("test an unsupported denom") - require.False(t, AssetRegistry.IsSupportedDenom("unsupported_denom")) -} diff --git a/x/common/asset/asset_registry.go b/x/common/asset/registry.go similarity index 77% rename from x/common/asset/asset_registry.go rename to x/common/asset/registry.go index 369778eaa..0efb23afb 100644 --- a/x/common/asset/asset_registry.go +++ b/x/common/asset/registry.go @@ -6,14 +6,14 @@ import ( "github.com/NibiruChain/nibiru/x/common/set" ) -type assetRegistry map[string]set.Set[string] +type registry map[string]set.Set[string] -var AssetRegistry assetRegistry +var Registry registry func init() { // map of base asset to supported quote assets // quote assets are usually stables - AssetRegistry = map[string]set.Set[string]{ + Registry = map[string]set.Set[string]{ denoms.BTC: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), denoms.ETH: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), denoms.NIBI: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT), @@ -29,7 +29,7 @@ func init() { } } -func (r assetRegistry) Pair(base string, quote string) common.AssetPair { +func (r registry) Pair(base string, quote string) common.AssetPair { for q := range r[base] { if q == quote { return common.NewAssetPair(string(base), string(quote)) @@ -40,7 +40,7 @@ func (r assetRegistry) Pair(base string, quote string) common.AssetPair { } // Returns all supported base denoms -func (r assetRegistry) BaseDenoms() set.Set[string] { +func (r registry) BaseDenoms() set.Set[string] { baseSet := make(set.Set[string]) for d := range r { baseSet.Add(d) @@ -49,7 +49,7 @@ func (r assetRegistry) BaseDenoms() set.Set[string] { } // Returns all supported quote denoms -func (r assetRegistry) QuoteDenoms() set.Set[string] { +func (r registry) QuoteDenoms() set.Set[string] { quoteSet := make(set.Set[string]) for base := range r { for q := range r[base] { @@ -60,22 +60,22 @@ func (r assetRegistry) QuoteDenoms() set.Set[string] { } // Checks if the provided denom is a supported base denom -func (r assetRegistry) IsSupportedBaseDenom(denom string) bool { +func (r registry) IsSupportedBaseDenom(denom string) bool { _, ok := r[denom] return ok } // Checks if the provided denom is a supported quote denom -func (r assetRegistry) IsSupportedQuoteDenom(denom string) bool { +func (r registry) IsSupportedQuoteDenom(denom string) bool { return r.QuoteDenoms().Has(denom) } // Checks if the provided denom is a supported denom -func (r assetRegistry) IsSupportedDenom(denom string) bool { +func (r registry) IsSupportedDenom(denom string) bool { return r.IsSupportedBaseDenom(string(denom)) || r.IsSupportedQuoteDenom(string(denom)) } // Checks if the provided base and quote denoms are a supported pair -func (r assetRegistry) IsSupportedPair(base string, quote string) bool { +func (r registry) IsSupportedPair(base string, quote string) bool { return r.IsSupportedBaseDenom(base) && r.IsSupportedQuoteDenom(quote) } diff --git a/x/common/asset/registry_test.go b/x/common/asset/registry_test.go new file mode 100644 index 000000000..ff08b2c8b --- /dev/null +++ b/x/common/asset/registry_test.go @@ -0,0 +1,82 @@ +package asset + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" +) + +func TestIsSupportedPair(t *testing.T) { + for base := range Registry { + for quote := range Registry[base] { + require.Truef(t, Registry.IsSupportedPair(base, quote), "%s:%s should be supported", base, quote) + } + } + + t.Log("test an unsupported pair") + require.False(t, Registry.IsSupportedPair(denoms.ATOM, denoms.OSMO)) +} + +func TestPair(t *testing.T) { + for base := range Registry { + for quote := range Registry[base] { + require.Equal(t, common.NewAssetPair(base, quote), Registry.Pair(base, quote)) + } + } + + t.Log("test an unsupported pair") + require.Equal(t, common.AssetPair(""), Registry.Pair(denoms.ATOM, denoms.OSMO)) + + t.Log("test an unsupported base asset") + require.Equal(t, common.AssetPair(""), Registry.Pair("unsuported_denom", denoms.USDC)) + + t.Log("test an unsupported quote asset") + require.Equal(t, common.AssetPair(""), Registry.Pair(denoms.ATOM, "unsupported_denom")) +} + +func TestBaseDenoms(t *testing.T) { + for base := range Registry { + require.Contains(t, Registry.BaseDenoms(), base) + } +} + +func TestIsSupportedBaseDenom(t *testing.T) { + for base := range Registry { + require.True(t, Registry.IsSupportedBaseDenom(base)) + } + require.False(t, Registry.IsSupportedBaseDenom("unsupported_denom")) +} + +func TestQuoteDenoms(t *testing.T) { + for base := range Registry { + for quote := range Registry[base] { + require.True(t, Registry.QuoteDenoms().Has(quote)) + } + } +} + +func TestIsSupportedQuoteDenom(t *testing.T) { + for base := range Registry { + for quote := range Registry[base] { + require.True(t, Registry.IsSupportedQuoteDenom(quote)) + } + } + + require.False(t, Registry.IsSupportedQuoteDenom("unsupported_denom")) +} + +func TestIsSupportedDenom(t *testing.T) { + for base := range Registry.BaseDenoms() { + require.True(t, Registry.IsSupportedDenom(base)) + } + + for quote := range Registry.QuoteDenoms() { + require.True(t, Registry.IsSupportedDenom(quote)) + } + + t.Log("test an unsupported denom") + require.False(t, Registry.IsSupportedDenom("unsupported_denom")) +} diff --git a/x/common/error_test.go b/x/common/error_test.go index ea4ea7bc1..39ed99cd7 100644 --- a/x/common/error_test.go +++ b/x/common/error_test.go @@ -88,12 +88,12 @@ func TestCombineErrorsGeneric(t *testing.T) { {name: "type=[]string | mixed", in: []string{"", "abc", ""}, out: errors.New(": abc: ")}, // cases: fmt.Stringer - {name: "type=fmt.Stringer |", in: asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), out: errors.New("uusdc:unusd")}, + {name: "type=fmt.Stringer |", in: asset.Registry.Pair(denoms.USDC, denoms.NUSD), out: errors.New("uusdc:unusd")}, // cases: []fmt.Stringer { name: "type=[]fmt.Stringer | happy", - in: []fmt.Stringer{asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)}, + in: []fmt.Stringer{asset.Registry.Pair(denoms.BTC, denoms.NUSD), asset.Registry.Pair(denoms.ETH, denoms.NUSD)}, out: errors.New("ubtc:unusd: ueth:unusd")}, {name: "type=[]fmt.Stringer | empty", in: []fmt.Stringer{}, out: nil}, } diff --git a/x/oracle/keeper/ballot_test.go b/x/oracle/keeper/ballot_test.go index c5ce00b38..1d5f8bf63 100644 --- a/x/oracle/keeper/ballot_test.go +++ b/x/oracle/keeper/ballot_test.go @@ -34,14 +34,14 @@ func TestOrganizeAggregate(t *testing.T) { staking.EndBlocker(ctx, input.StakingKeeper) btcBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(17), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(10), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(6), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(17), asset.Registry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(10), asset.Registry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(6), asset.Registry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[2], power), } ethBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(1000), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(1300), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(2000), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(1000), asset.Registry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(1300), asset.Registry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(2000), asset.Registry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[2], power), } for i := range btcBallot { @@ -80,11 +80,11 @@ func TestOrganizeAggregate(t *testing.T) { // sort each ballot for comparison sort.Sort(btcBallot) sort.Sort(ethBallot) - sort.Sort(ballotMap[asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)]) - sort.Sort(ballotMap[asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)]) + sort.Sort(ballotMap[asset.Registry.Pair(denoms.BTC, denoms.NUSD)]) + sort.Sort(ballotMap[asset.Registry.Pair(denoms.ETH, denoms.NUSD)]) - require.Equal(t, btcBallot, ballotMap[asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)]) - require.Equal(t, ethBallot, ballotMap[asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)]) + require.Equal(t, btcBallot, ballotMap[asset.Registry.Pair(denoms.BTC, denoms.NUSD)]) + require.Equal(t, ethBallot, ballotMap[asset.Registry.Pair(denoms.ETH, denoms.NUSD)]) } func TestClearBallots(t *testing.T) { @@ -105,14 +105,14 @@ func TestClearBallots(t *testing.T) { staking.EndBlocker(ctx, input.StakingKeeper) btcBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(17), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(10), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(6), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(17), asset.Registry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(10), asset.Registry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(6), asset.Registry.Pair(denoms.BTC, denoms.NUSD), ValAddrs[2], power), } ethBallot := types.ExchangeRateBallots{ - types.NewExchangeRateBallot(sdk.NewDec(1000), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[0], power), - types.NewExchangeRateBallot(sdk.NewDec(1300), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[1], power), - types.NewExchangeRateBallot(sdk.NewDec(2000), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[2], power), + types.NewExchangeRateBallot(sdk.NewDec(1000), asset.Registry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[0], power), + types.NewExchangeRateBallot(sdk.NewDec(1300), asset.Registry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[1], power), + types.NewExchangeRateBallot(sdk.NewDec(2000), asset.Registry.Pair(denoms.ETH, denoms.NUSD), ValAddrs[2], power), } for i := range btcBallot { diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index 9604decdd..a758fa896 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -32,8 +32,8 @@ func TestParams(t *testing.T) { slashWindow := uint64(1000) minValidPerWindow := sdk.NewDecWithPrec(1, 4) whitelist := []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), } // Should really test validateParams, but skipping because obvious diff --git a/x/oracle/keeper/msg_server_test.go b/x/oracle/keeper/msg_server_test.go index 4bb5f65fc..d14b67c64 100644 --- a/x/oracle/keeper/msg_server_test.go +++ b/x/oracle/keeper/msg_server_test.go @@ -20,7 +20,7 @@ func TestMsgServer_FeederDelegation(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate, }, } @@ -87,43 +87,43 @@ func TestMsgServer_AggregatePrevoteVote(t *testing.T) { salt := "1" exchangeRates := types.ExchangeRateTuples{ { - Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } otherExchangeRate := types.ExchangeRateTuples{ { - Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } unintendedExchangeRateStr := types.ExchangeRateTuples{ { - Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { diff --git a/x/oracle/keeper/querier_test.go b/x/oracle/keeper/querier_test.go index 9d2f9baaa..0daf1e47e 100644 --- a/x/oracle/keeper/querier_test.go +++ b/x/oracle/keeper/querier_test.go @@ -33,7 +33,7 @@ func TestQueryExchangeRate(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.Registry.Pair(denoms.ETH, denoms.NUSD), rate) // empty request _, err := querier.ExchangeRate(ctx, nil) @@ -41,7 +41,7 @@ func TestQueryExchangeRate(t *testing.T) { // Query to grpc res, err := querier.ExchangeRate(ctx, &types.QueryExchangeRateRequest{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), }) require.NoError(t, err) require.Equal(t, rate, res.ExchangeRate) @@ -73,15 +73,15 @@ func TestQueryExchangeRates(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.Registry.Pair(denoms.ETH, denoms.NUSD), rate) res, err := querier.ExchangeRates(ctx, &types.QueryExchangeRatesRequest{}) require.NoError(t, err) require.Equal(t, types.ExchangeRateTuples{ - {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: rate}, - {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: rate}, + {Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: rate}, + {Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: rate}, }, res.ExchangeRates) } @@ -91,12 +91,12 @@ func TestQueryExchangeRateTwap(t *testing.T) { querier := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.SetPrice(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) + input.OracleKeeper.SetPrice(input.Ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), rate) - _, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)}) + _, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD)}) require.Error(t, err) - res, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}) + res, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD)}) require.NoError(t, err) require.Equal(t, sdk.MustNewDecFromStr("1700"), res.ExchangeRate) } @@ -116,25 +116,25 @@ func TestCalcTwap(t *testing.T) { // expected price: (9.5 * (35 - 30) + 8.5 * (30 - 20) + 9.0 * (20 - 5)) / 30 = 8.916666 { name: "spot price twap calc, t=(5,35]", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), priceSnapshots: []types.PriceSnapshot{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("90000.0"), TimestampMs: time.UnixMilli(1).UnixMilli(), }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("9.0"), TimestampMs: time.UnixMilli(10).UnixMilli(), }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("8.5"), TimestampMs: time.UnixMilli(20).UnixMilli(), }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("9.5"), TimestampMs: time.UnixMilli(30).UnixMilli(), }, @@ -168,12 +168,12 @@ func TestCalcTwap(t *testing.T) { ctx = ctx.WithBlockTime(time.UnixMilli(0)) for _, reserve := range tc.priceSnapshots { ctx = ctx.WithBlockTime(time.UnixMilli(reserve.TimestampMs)) - input.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), reserve.Price) + input.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserve.Price) } ctx = ctx.WithBlockTime(tc.currentBlockTime).WithBlockHeight(tc.currentBlockHeight) - price, err := querier.ExchangeRateTwap(sdk.WrapSDKContext(ctx), &types.QueryExchangeRateRequest{Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}) + price, err := querier.ExchangeRateTwap(sdk.WrapSDKContext(ctx), &types.QueryExchangeRateRequest{Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD)}) require.NoError(t, err) require.EqualValuesf(t, tc.expectedPrice, price.ExchangeRate, @@ -188,17 +188,17 @@ func TestQueryActives(t *testing.T) { queryClient := NewQuerier(input.OracleKeeper) rate := sdk.NewDec(1700) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), rate) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD), rate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.Registry.Pair(denoms.ETH, denoms.NUSD), rate) res, err := queryClient.Actives(ctx, &types.QueryActivesRequest{}) require.NoError(t, err) targetPairs := []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), } require.Equal(t, targetPairs, res.Actives) diff --git a/x/oracle/keeper/reward_test.go b/x/oracle/keeper/reward_test.go index dc643e116..a22d345c4 100644 --- a/x/oracle/keeper/reward_test.go +++ b/x/oracle/keeper/reward_test.go @@ -59,7 +59,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { valPeriodicRewards := sdk.NewDecCoinsFromCoins(rewards). QuoDec(sdk.NewDec(int64(periods))). QuoDec(sdk.NewDec(int64(validators))) - keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(rewards), periods) + keeper.AllocateRewards(t, input, asset.Registry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(rewards), periods) for i := uint64(1); i <= periods; i++ { for valIndex := 0; valIndex < validators; valIndex++ { @@ -67,7 +67,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { // passes the current context block height for pre vote // then changes the height to current height + vote period for the vote makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{ - Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate, }}, valIndex) } @@ -84,8 +84,8 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { } // assert there are no rewards for pair - require.True(t, input.OracleKeeper.GatherRewardsForVotePeriod(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)).IsZero()) + require.True(t, input.OracleKeeper.GatherRewardsForVotePeriod(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)).IsZero()) // assert that there are no rewards instances - require.Empty(t, input.OracleKeeper.PairRewards.Indexes.RewardsByPair.ExactMatch(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)).PrimaryKeys()) + require.Empty(t, input.OracleKeeper.PairRewards.Indexes.RewardsByPair.ExactMatch(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)).PrimaryKeys()) } diff --git a/x/oracle/keeper/slash_test.go b/x/oracle/keeper/slash_test.go index 55455c923..7c053b399 100644 --- a/x/oracle/keeper/slash_test.go +++ b/x/oracle/keeper/slash_test.go @@ -92,9 +92,9 @@ func TestSlashAndResetMissCounters(t *testing.T) { func TestInvalidVotesSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.Registry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) votePeriodsPerWindow := types.NewDec(int64(input.OracleKeeper.SlashWindow(input.Ctx))).QuoInt64(int64(input.OracleKeeper.VotePeriod(input.Ctx))).TruncateInt64() slashFraction := input.OracleKeeper.SlashFraction(input.Ctx) @@ -104,13 +104,13 @@ func TestInvalidVotesSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, miss vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, i+1, input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[1], 0)) @@ -121,13 +121,13 @@ func TestInvalidVotesSlashing(t *testing.T) { // one more miss vote will inccur keeper.ValAddrs[1] slashing // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, miss vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(types.NewDec(100000000000000))}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) input.Ctx = input.Ctx.WithBlockHeight(votePeriodsPerWindow - 1) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -146,9 +146,9 @@ func TestWhitelistSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, i+1, input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[0], 0)) @@ -160,9 +160,9 @@ func TestWhitelistSlashing(t *testing.T) { // one more miss vote will inccur Account 1 slashing // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) input.Ctx = input.Ctx.WithBlockHeight(votePeriodsPerWindow - 1) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -173,19 +173,19 @@ func TestWhitelistSlashing(t *testing.T) { func TestNotPassedBallotSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.Registry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[0], 0)) @@ -196,14 +196,14 @@ func TestNotPassedBallotSlashing(t *testing.T) { func TestAbstainSlashing(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.Registry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear tobin tax to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) votePeriodsPerWindow := types.NewDec(int64(input.OracleKeeper.SlashWindow(input.Ctx))).QuoInt64(int64(input.OracleKeeper.VotePeriod(input.Ctx))).TruncateInt64() minValidPerWindow := input.OracleKeeper.MinValidPerWindow(input.Ctx) @@ -212,13 +212,13 @@ func TestAbstainSlashing(t *testing.T) { input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 1) // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, govstable, abstain vote - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: types.ZeroDec()}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: types.ZeroDec()}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types3.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[1], 0)) diff --git a/x/oracle/keeper/tally_fuzz_test.go b/x/oracle/keeper/tally_fuzz_test.go index f55c704c5..d6ac2d2ee 100644 --- a/x/oracle/keeper/tally_fuzz_test.go +++ b/x/oracle/keeper/tally_fuzz_test.go @@ -134,11 +134,11 @@ func TestRemoveInvalidBallots(t *testing.T) { "x": types.ExchangeRateBallots{ {Pair: "x", ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD): types.ExchangeRateBallots{ - {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, + asset.Registry.Pair(denoms.BTC, denoms.NUSD): types.ExchangeRateBallots{ + {Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD): types.ExchangeRateBallots{ - {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, + asset.Registry.Pair(denoms.ETH, denoms.NUSD): types.ExchangeRateBallots{ + {Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.Dec{}, Voter: sdk.ValAddress{123}, Power: 5}, }, }, }, diff --git a/x/oracle/keeper/update_exchange_rates_test.go b/x/oracle/keeper/update_exchange_rates_test.go index 0e739f2a4..7c5541ed7 100644 --- a/x/oracle/keeper/update_exchange_rates_test.go +++ b/x/oracle/keeper/update_exchange_rates_test.go @@ -25,7 +25,7 @@ import ( func TestOracleThreshold(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate, }, } @@ -122,15 +122,15 @@ func TestOracleThreshold(t *testing.T) { func TestOracleDrop(t *testing.T) { input, h := setup(t) - input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), randomExchangeRate) + input.OracleKeeper.ExchangeRates.Insert(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD), randomExchangeRate) // Account 1, pair gov stable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Immediately swap halt after an illiquid oracle vote oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) require.Error(t, err) } @@ -144,7 +144,7 @@ func TestOracleTally(t *testing.T) { for i, rate := range rates { decExchangeRate := sdk.NewDecWithPrec(int64(rate*math.Pow10(keeper.OracleDecPrecision)), int64(keeper.OracleDecPrecision)) exchangeRateStr, err := types.ExchangeRateTuples{ - {ExchangeRate: decExchangeRate, Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)}}.ToString() + {ExchangeRate: decExchangeRate, Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD)}}.ToString() require.NoError(t, err) salt := fmt.Sprintf("%d", i) @@ -163,7 +163,7 @@ func TestOracleTally(t *testing.T) { } vote := types.NewExchangeRateBallot( - decExchangeRate, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddrs[i], power) + decExchangeRate, asset.Registry.Pair(denoms.BTC, denoms.NUSD), valAddrs[i], power) ballot = append(ballot, vote) // change power of every three validator @@ -223,7 +223,7 @@ func TestOracleTallyTiming(t *testing.T) { // all the keeper.Addrs vote for the block ... not last period block yet, so tally fails for i := range keeper.Addrs[:2] { - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, i) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, i) } params := input.OracleKeeper.GetParams(input.Ctx) @@ -232,13 +232,13 @@ func TestOracleTallyTiming(t *testing.T) { require.Equal(t, 0, int(input.Ctx.BlockHeight())) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) require.Error(t, err) input.Ctx = input.Ctx.WithBlockHeight(int64(params.VotePeriod - 1)) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err = input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + _, err = input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) } @@ -248,13 +248,13 @@ func TestOracleRewardDistribution(t *testing.T) { input, h := setup(t) // Account 1, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) // Account 2, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) rewardAllocation := sdk.NewCoins(sdk.NewCoin("reward", sdk.NewInt(1*common.Precision))) - keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), rewardAllocation, 1) + keeper.AllocateRewards(t, input, asset.Registry.Pair(denoms.BTC, denoms.NUSD), rewardAllocation, 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -268,26 +268,26 @@ func TestOracleRewardDistribution(t *testing.T) { func TestOracleRewardBand(t *testing.T) { input, h := setup(t) params := input.OracleKeeper.GetParams(input.Ctx) - params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.Registry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) // clear pairs to reset vote targets for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) rewardSpread := randomExchangeRate.Mul(input.OracleKeeper.RewardBand(input.Ctx).QuoInt64(2)) // no one will miss the vote // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread)}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread)}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -297,13 +297,13 @@ func TestOracleRewardBand(t *testing.T) { // Account 1 will miss the vote due to raward band condition // Account 1, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread.Add(sdk.OneDec()))}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Sub(rewardSpread.Add(sdk.OneDec()))}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate.Add(rewardSpread)}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -357,19 +357,19 @@ func TestOracleExchangeRate(t *testing.T) { // govstable has been chosen as referenceExchangeRate by highest voting power // Account 1, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableExchangeRate}, {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableExchangeRate}, {Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}}, 0) // Account 2, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableExchangeRate}, {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableExchangeRate}, {Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}}, 1) // Account 3, govstable, btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}, {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableExchangeRate}, {Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) - keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(govStableRewards), 1) + keeper.AllocateRewards(t, input, asset.Registry.Pair(denoms.ETH, denoms.NUSD), sdk.NewCoins(ethStableRewards), 1) + keeper.AllocateRewards(t, input, asset.Registry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -405,13 +405,13 @@ func TestOracleEnsureSorted(t *testing.T) { ethStableRate3 := sdk.NewDec(int64(rand.Uint64() % 100000000)) // Account 1, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate1}, {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate1}, {Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 0) // Account 2, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}, {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}, {Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}}, 1) // Account 3, ethstable, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: govStableRate3}, {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: ethStableRate3}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: govStableRate3}, {Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: ethStableRate3}}, 2) require.NotPanics(t, func() { oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -429,31 +429,31 @@ func TestOracleExchangeRateVal5(t *testing.T) { // govstable has been chosen as reference pair by highest voting power // Account 1, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}, {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate1}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}, {Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate1}}, 0) // Account 2, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 1) // Account 3, govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate1}}, 2) // Account 4, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}, {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}}, 3) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}, {Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}}, 3) // Account 5, govstable, ethstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}, {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}}, 4) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: govStableRate2}, {Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: ethStableRate2}}, 4) ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) - keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(govStableRewards), 1) + keeper.AllocateRewards(t, input, asset.Registry.Pair(denoms.ETH, denoms.NUSD), sdk.NewCoins(ethStableRewards), 1) + keeper.AllocateRewards(t, input, asset.Registry.Pair(denoms.NIBI, denoms.NUSD), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) - gotGovStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + gotGovStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) require.NoError(t, err) - gotEthStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)) + gotEthStableRate, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.Registry.Pair(denoms.ETH, denoms.NUSD)) require.NoError(t, err) require.Equal(t, govStableRate1, gotGovStableRate) @@ -487,15 +487,15 @@ func TestWhitelistedPairs(t *testing.T) { for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) // govstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) // set btcstable for next vote period - params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.Registry.Pair(denoms.NIBI, denoms.NUSD), asset.Registry.Pair(denoms.BTC, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -505,15 +505,15 @@ func TestWhitelistedPairs(t *testing.T) { require.Equal(t, uint64(0), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[2], 0)) // whitelisted pairs are {govstable, btcstable} - require.Equal(t, []common.AssetPair{asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) + require.Equal(t, []common.AssetPair{asset.Registry.Pair(denoms.BTC, denoms.NUSD), asset.Registry.Pair(denoms.NIBI, denoms.NUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) // govstable, missing btcstable - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) // delete btcstable for next vote period - params.Whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + params.Whitelist = []common.AssetPair{asset.Registry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -522,13 +522,13 @@ func TestWhitelistedPairs(t *testing.T) { require.Equal(t, uint64(1), input.OracleKeeper.MissCounters.GetOr(input.Ctx, keeper.ValAddrs[2], 0)) // btcstable must be deleted - require.Equal(t, []common.AssetPair{asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) - require.False(t, input.OracleKeeper.WhitelistedPairs.Has(input.Ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD))) + require.Equal(t, []common.AssetPair{asset.Registry.Pair(denoms.NIBI, denoms.NUSD)}, input.OracleKeeper.GetWhitelistedPairs(input.Ctx)) + require.False(t, input.OracleKeeper.WhitelistedPairs.Has(input.Ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD))) // govstable, no missing - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 0) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 1) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate}}, 2) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -544,11 +544,11 @@ func TestAbstainWithSmallStakingPower(t *testing.T) { for _, p := range input.OracleKeeper.WhitelistedPairs.Iterate(input.Ctx, collections.Range[common.AssetPair]{}).Keys() { input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p) } - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) - makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.ZeroDec()}}, 0) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) + makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.ZeroDec()}}, 0) oracle.EndBlocker(input.Ctx, input.OracleKeeper) - _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) require.Error(t, err) } diff --git a/x/oracle/simulation/decoder_test.go b/x/oracle/simulation/decoder_test.go index 67d733443..9c8d06212 100644 --- a/x/oracle/simulation/decoder_test.go +++ b/x/oracle/simulation/decoder_test.go @@ -35,8 +35,8 @@ func TestDecodeDistributionStore(t *testing.T) { aggregatePrevote := types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash([]byte("12345")), valAddr, 123) aggregateVote := types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{ - {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDecWithPrec(1234, 1)}, - {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDecWithPrec(4321, 1)}, + {Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDecWithPrec(1234, 1)}, + {Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDecWithPrec(4321, 1)}, }, valAddr) pair := "btc:usd" diff --git a/x/oracle/simulation/genesis.go b/x/oracle/simulation/genesis.go index 63d875950..d36f6e92a 100644 --- a/x/oracle/simulation/genesis.go +++ b/x/oracle/simulation/genesis.go @@ -99,17 +99,17 @@ func RandomizedGenState(simState *module.SimulationState) { VoteThreshold: voteThreshold, RewardBand: rewardBand, Whitelist: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), }, SlashFraction: slashFraction, SlashWindow: slashWindow, MinValidPerWindow: minValidPerWindow, }, []types.ExchangeRateTuple{ - {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(20_000)}, + {Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(20_000)}, }, []types.FeederDelegation{}, []types.MissCounter{}, diff --git a/x/oracle/simulation/operations.go b/x/oracle/simulation/operations.go index c1670dfc3..6cf11ed98 100644 --- a/x/oracle/simulation/operations.go +++ b/x/oracle/simulation/operations.go @@ -32,7 +32,7 @@ const ( ) var ( - whitelist = []common.AssetPair{asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)} + whitelist = []common.AssetPair{asset.Registry.Pair(denoms.BTC, denoms.NUSD), asset.Registry.Pair(denoms.ETH, denoms.NUSD), asset.Registry.Pair(denoms.NIBI, denoms.NUSD)} voteHashMap map[string]string = make(map[string]string) ) diff --git a/x/oracle/types/ballot_test.go b/x/oracle/types/ballot_test.go index 2ac0c3e6b..1c8ce12fa 100644 --- a/x/oracle/types/ballot_test.go +++ b/x/oracle/types/ballot_test.go @@ -31,21 +31,21 @@ func TestToMap(t *testing.T) { { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(1600), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.ZeroDec(), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(1500), Power: 100, }, @@ -95,15 +95,15 @@ func TestToCrossRate(t *testing.T) { for _, data := range data { valAddr := sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()) if !data.base.IsZero() { - pbBase = append(pbBase, types.NewExchangeRateBallot(data.base, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) + pbBase = append(pbBase, types.NewExchangeRateBallot(data.base, asset.Registry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) } - pbQuote = append(pbQuote, types.NewExchangeRateBallot(data.quote, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) + pbQuote = append(pbQuote, types.NewExchangeRateBallot(data.quote, asset.Registry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) if !data.base.IsZero() && !data.quote.IsZero() { - cb = append(cb, types.NewExchangeRateBallot(data.base.Quo(data.quote), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) + cb = append(cb, types.NewExchangeRateBallot(data.base.Quo(data.quote), asset.Registry.Pair(denoms.BTC, denoms.NUSD), valAddr, 100)) } else { - cb = append(cb, types.NewExchangeRateBallot(sdk.ZeroDec(), asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), valAddr, 0)) + cb = append(cb, types.NewExchangeRateBallot(sdk.ZeroDec(), asset.Registry.Pair(denoms.BTC, denoms.NUSD), valAddr, 0)) } } @@ -135,7 +135,7 @@ func TestPBPower(t *testing.T) { power := sk.Validator(ctx, valAccAddrs[i]).GetConsensusPower(sdk.DefaultPowerReduction) vote := types.NewExchangeRateBallot( sdk.ZeroDec(), - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), valAccAddrs[i], power, ) @@ -154,7 +154,7 @@ func TestPBPower(t *testing.T) { faceValAddr := sdk.ValAddress(pubKey.Address()) fakeVote := types.NewExchangeRateBallot( sdk.OneDec(), - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), faceValAddr, 0, ) @@ -225,7 +225,7 @@ func TestPBWeightedMedian(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDec(int64(input)), - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), valAddr, power, ) @@ -292,7 +292,7 @@ func TestPBStandardDeviation(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDecWithPrec(int64(input*base), int64(types.OracleDecPrecision)), - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), valAddr, power, ) @@ -311,12 +311,12 @@ func TestPBStandardDeviationOverflow(t *testing.T) { pb := types.ExchangeRateBallots{types.NewExchangeRateBallot( sdk.ZeroDec(), - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), valAddr, 2, ), types.NewExchangeRateBallot( exchangeRate, - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), valAddr, 1, )} diff --git a/x/oracle/types/params.go b/x/oracle/types/params.go index bcba54d42..e40f463db 100644 --- a/x/oracle/types/params.go +++ b/x/oracle/types/params.go @@ -40,10 +40,10 @@ var ( DefaultVoteThreshold = sdk.NewDecWithPrec(50, 2) // 50% DefaultRewardBand = sdk.NewDecWithPrec(2, 2) // 2% (-1, 1) DefaultWhitelist = []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), } DefaultSlashFraction = sdk.NewDecWithPrec(1, 4) // 0.01% DefaultMinValidPerWindow = sdk.NewDecWithPrec(5, 2) // 5% diff --git a/x/perp/client/cli/cli_test.go b/x/perp/client/cli/cli_test.go index c91bdfb42..201a83aa0 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -53,7 +53,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -65,7 +65,7 @@ func (s *IntegrationTestSuite) SetupSuite() { }, }, { - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -83,11 +83,11 @@ func (s *IntegrationTestSuite) SetupSuite() { perpGenesis := perptypes.DefaultGenesis() perpGenesis.PairMetadata = []perptypes.PairMetadata{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), }, { - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, } @@ -96,12 +96,12 @@ func (s *IntegrationTestSuite) SetupSuite() { oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.Params.Whitelist = []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), } oracleGenesis.Params.VotePeriod = 1_000 oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(20_000)}, - {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDec(2_000)}, + {Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(20_000)}, + {Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDec(2_000)}, } genesisState[oracletypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(oracleGenesis) @@ -188,25 +188,25 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { val := s.network.Validators[0] user := s.users[0] - exchangeRate, err := testutilcli.QueryOracleExchangeRate(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + exchangeRate, err := testutilcli.QueryOracleExchangeRate(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) s.T().Logf("0. current exchange rate is: %+v", exchangeRate) s.NoError(err) s.T().Log("A. check vpool balances") - reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.NewDec(10*common.Precision), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_000*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("A. check trader has no existing positions") - _, err = testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + _, err = testutilcli.QueryPosition(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), user) s.Error(err) s.T().Log("B. open position") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "buy", - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAssetLimit */ "1"}, @@ -215,18 +215,18 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("B. check vpool balance after open position") - reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("9999833.336111064815586407"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_001*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("B. check trader position") - queryResp, err := testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + queryResp, err := testutilcli.QueryPosition(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) + s.EqualValues(asset.Registry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("166.663888935184413593"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.OpenNotional) @@ -238,7 +238,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("C. open position with 2x leverage and zero baseAmtLimit") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "buy", - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "2", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAmtLimit */ "0", @@ -247,11 +247,11 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("C. check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) + s.EqualValues(asset.Registry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.975001249937503125"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(3*common.Precision), queryResp.Position.OpenNotional) @@ -262,7 +262,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("D. Open a reverse position smaller than the existing position") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "sell", - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "100", // 100 uNUSD /* baseAssetLimit */ "1", @@ -271,18 +271,18 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("D. Check vpool after opening reverse position") - reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + reserveAssets, err = testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) s.NoError(err) s.T().Logf(" \n reserve assets: %+v \n", reserveAssets) s.EqualValues(sdk.MustNewDecFromStr("9999500.041663750215262154"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.NewDec(60_002_999_900), reserveAssets.QuoteAssetReserve) s.T().Log("D. Check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) + s.EqualValues(asset.Registry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.958336249784737846"), queryResp.Position.Size_) s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(2_999_900), queryResp.Position.OpenNotional) @@ -293,7 +293,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("E. Open a reverse position larger than the existing position") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), user, []string{ "sell", - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "4000000", // 4*10^6 uNUSD /* baseAssetLimit */ "0", @@ -302,11 +302,11 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("E. Check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), user) s.NoError(err) s.T().Logf("query response: %+v", queryResp) s.EqualValues(user.String(), queryResp.Position.TraderAddress) - s.EqualValues(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) + s.EqualValues(asset.Registry.Pair(denoms.BTC, denoms.NUSD), queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("-166.686111713005402945"), queryResp.Position.Size_) s.EqualValues(sdk.MustNewDecFromStr("1000100.000000000000000494"), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("1000100.000000000000000494"), queryResp.Position.Margin) @@ -317,13 +317,13 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Log("F. Close position") txResp, err = testutilcli.ExecTx(s.network, cli.ClosePositionCmd(), user, []string{ - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), }) s.NoError(err) s.EqualValues(abcitypes.CodeTypeOK, txResp.Code) s.T().Log("F. check trader position") - queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), user) + queryResp, err = testutilcli.QueryPosition(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), user) s.Error(err) s.T().Logf("query response: %+v", queryResp) @@ -337,12 +337,12 @@ func (s *IntegrationTestSuite) TestPositionEmptyAndClose() { user := s.users[0] // verify trader has no position (empty) - _, err := testutilcli.QueryPosition(val.ClientCtx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), user) + _, err := testutilcli.QueryPosition(val.ClientCtx, asset.Registry.Pair(denoms.ETH, denoms.NUSD), user) s.Error(err, "no position found") // close position should produce error _, err = testutilcli.ExecTx(s.network, cli.ClosePositionCmd(), user, []string{ - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) } @@ -351,7 +351,7 @@ func (s *IntegrationTestSuite) TestQueryCumulativePremiumFractions() { val := s.network.Validators[0] s.T().Log("get cumulative funding payments") - queryResp, err := testutilcli.QueryCumulativePremiumFraction(val.ClientCtx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + queryResp, err := testutilcli.QueryCumulativePremiumFraction(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) s.NoError(err) s.EqualValues(sdk.NewDec(2), queryResp.CumulativePremiumFraction) } @@ -361,7 +361,7 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { s.T().Log("opening a position with user 0") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[0], []string{ "buy", - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), "10", // Leverage "1", // Quote asset amount "0.0000001", @@ -372,7 +372,7 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { // Remove margin to trigger bad debt on user 0 s.T().Log("removing margin on user 0....") _, err = testutilcli.ExecTx(s.network, cli.RemoveMarginCmd(), s.users[0], []string{ - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), fmt.Sprintf("%s%s", "100", denoms.NUSD), }) s.Contains(err.Error(), perptypes.ErrFailedRemoveMarginCanCauseBadDebt.Error()) @@ -380,7 +380,7 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { func (s *IntegrationTestSuite) TestX_AddMargin() { val := s.network.Validators[0] - pair := asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD) + pair := asset.Registry.Pair(denoms.ETH, denoms.NUSD) // Open a new position s.T().Log("opening a position with user 3....") @@ -412,7 +412,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { { name: "FAIL: position not found", args: []string{ - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), fmt.Sprintf("%s%s", "10000", pair.QuoteDenom()), }, expectedCode: 1, @@ -439,7 +439,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidate a position that does not exist") _, err := testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), s.users[1].String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) @@ -447,7 +447,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("opening a position with user 1....") txResp, err := testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[1], []string{ "buy", - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), "15", // Leverage "90000", // Quote asset amount "0", @@ -457,7 +457,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidate a position that is above maintenance margin mario") _, err = testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), s.users[1].String(), }) s.Contains(err.Error(), "margin ratio is too healthy to liquidate") @@ -465,7 +465,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("opening a position with user 2...") txResp, err = testutilcli.ExecTx(s.network, cli.OpenPositionCmd(), s.users[2], []string{ "sell", - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), "15", // Leverage "45000000", // Quote asset amount "0", @@ -481,7 +481,7 @@ func (s *IntegrationTestSuite) TestLiquidate() { s.T().Log("liquidating user 1...") txResp, err = testutilcli.ExecTx(s.network, cli.LiquidateCmd(), s.users[4], []string{ - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD).String(), + asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), s.users[1].String(), }) s.NoError(err) diff --git a/x/perp/genesis_test.go b/x/perp/genesis_test.go index 049bc1e68..e80e87b6d 100644 --- a/x/perp/genesis_test.go +++ b/x/perp/genesis_test.go @@ -40,9 +40,9 @@ func TestGenesis(t *testing.T) { // create some positions for i := int64(0); i < 100; i++ { addr := testutil.AccAddress() - app.PerpKeeper.Positions.Insert(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), addr), types.Position{ + app.PerpKeeper.Positions.Insert(ctx, collections.Join(asset.Registry.Pair(denoms.NIBI, denoms.NUSD), addr), types.Position{ TraderAddress: addr.String(), - Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), Size_: sdk.NewDec(i + 1), Margin: sdk.NewDec(i * 2), OpenNotional: sdk.NewDec(i * 100), diff --git a/x/perp/keeper/calc_test.go b/x/perp/keeper/calc_test.go index 63a2cae42..93d12c476 100644 --- a/x/perp/keeper/calc_test.go +++ b/x/perp/keeper/calc_test.go @@ -30,7 +30,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { marginDelta := sdk.OneDec() _, err := nibiruApp.PerpKeeper.CalcRemainMarginWithFundingPayment( ctx, types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), }, marginDelta) require.ErrorIs(t, err, collections.ErrNotFound) }, diff --git a/x/perp/keeper/calc_unit_test.go b/x/perp/keeper/calc_unit_test.go index c01969d2f..37a869749 100644 --- a/x/perp/keeper/calc_unit_test.go +++ b/x/perp/keeper/calc_unit_test.go @@ -39,9 +39,9 @@ func TestCalcFreeCollateralErrors(t *testing.T) { test: func() { k, mocks, ctx := getKeeper(t) - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(false) - pos := types.ZeroPosition(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) + pos := types.ZeroPosition(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) _, err := k.calcFreeCollateral(ctx, pos) @@ -55,12 +55,12 @@ func TestCalcFreeCollateralErrors(t *testing.T) { k, mocks, ctx := getKeeper(t) mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) + ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - pos := types.ZeroPosition(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) + pos := types.ZeroPosition(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) freeCollateral, err := k.calcFreeCollateral(ctx, pos) @@ -152,7 +152,7 @@ func TestCalcFreeCollateralSuccess(t *testing.T) { pos := types.Position{ TraderAddress: testutil.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.positionSize, Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(1000), @@ -161,19 +161,19 @@ func TestCalcFreeCollateralSuccess(t *testing.T) { } t.Log("mock vpool keeper") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.vpoolDirection, sdk.OneDec(), ).Return(tc.positionNotional, nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.vpoolDirection, sdk.OneDec(), 15*time.Minute, @@ -198,13 +198,13 @@ func TestGetLatestCumulativePremiumFraction(t *testing.T) { keeper, _, ctx := getKeeper(t) metadata := &types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), } setPairMetadata(keeper, ctx, *metadata) latestCumulativePremiumFraction, err := keeper. - getLatestCumulativePremiumFraction(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + getLatestCumulativePremiumFraction(ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) require.NoError(t, err) assert.Equal(t, sdk.NewDec(2), latestCumulativePremiumFraction) diff --git a/x/perp/keeper/clearing_house_integration_test.go b/x/perp/keeper/clearing_house_integration_test.go index bf3ddd8b8..fe94695aa 100644 --- a/x/perp/keeper/clearing_house_integration_test.go +++ b/x/perp/keeper/clearing_house_integration_test.go @@ -65,7 +65,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing long position, go more long", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -89,7 +89,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing long position, decrease a bit", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 10)), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -113,7 +113,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing long position, decrease a lot", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1060)), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -171,7 +171,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing short position, go more short", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -195,7 +195,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing short position, decrease a bit", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 10)), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -219,7 +219,7 @@ func TestOpenPositionSuccess(t *testing.T) { name: "existing short position, decrease a lot", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1060)), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -269,7 +269,7 @@ func TestOpenPositionSuccess(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision*common.Precision), vpooltypes.VpoolConfig{ @@ -281,7 +281,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -296,11 +296,11 @@ func TestOpenPositionSuccess(t *testing.T) { } ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(time.Second * 5)) - resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) + resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) require.NoError(t, err) t.Log("assert position response") - assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), resp.Position.Pair) + assert.EqualValues(t, asset.Registry.Pair(denoms.BTC, denoms.NUSD), resp.Position.Pair) assert.EqualValues(t, traderAddr.String(), resp.Position.TraderAddress) assert.EqualValues(t, tc.expectedMargin, resp.Position.Margin, "margin") assert.EqualValues(t, tc.expectedOpenNotional, resp.Position.OpenNotional, "open notional") @@ -317,9 +317,9 @@ func TestOpenPositionSuccess(t *testing.T) { assert.EqualValues(t, tc.expectedPositionNotional, resp.PositionNotional) t.Log("assert position in state") - position, err := nibiruApp.PerpKeeper.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) + position, err := nibiruApp.PerpKeeper.Positions.Get(ctx, collections.Join(asset.Registry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.NoError(t, err) - assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), position.Pair) + assert.EqualValues(t, asset.Registry.Pair(denoms.BTC, denoms.NUSD), position.Pair) assert.EqualValues(t, traderAddr.String(), position.TraderAddress) assert.EqualValues(t, tc.expectedMargin, position.Margin, "margin") assert.EqualValues(t, tc.expectedOpenNotional, position.OpenNotional, "open notional") @@ -332,7 +332,7 @@ func TestOpenPositionSuccess(t *testing.T) { ecosystemFundFee := nibiruApp.PerpKeeper.GetParams(ctx).EcosystemFundFeeRatio.Mul(exchangedNotional).RoundInt() testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionChangedEvent{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), Margin: sdk.NewCoin(denoms.NUSD, tc.expectedMargin.RoundInt()), PositionNotional: tc.expectedPositionNotional, @@ -386,7 +386,7 @@ func TestOpenPositionError(t *testing.T) { traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -521,7 +521,7 @@ func TestOpenPositionError(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* tradeLimitRatio */ /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), @@ -535,7 +535,7 @@ func TestOpenPositionError(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -549,7 +549,7 @@ func TestOpenPositionError(t *testing.T) { } ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(ctx.BlockTime().Add(time.Second * 5)) - resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) + resp, err := nibiruApp.PerpKeeper.OpenPosition(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.side, traderAddr, tc.margin, tc.leverage, tc.baseLimit) require.ErrorContains(t, err, tc.expectedErr.Error()) require.Nil(t, resp) }) diff --git a/x/perp/keeper/clearing_house_unit_test.go b/x/perp/keeper/clearing_house_unit_test.go index 8ee039ef8..195f889c9 100644 --- a/x/perp/keeper/clearing_house_unit_test.go +++ b/x/perp/keeper/clearing_house_unit_test.go @@ -118,7 +118,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -134,7 +134,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -155,7 +155,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { baseAmount, err := perpKeeper.swapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.side, sdk.NewDec(10), sdk.NewDec(1), @@ -183,7 +183,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -195,7 +195,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(50), @@ -205,7 +205,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -214,7 +214,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, ) @@ -257,7 +257,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -269,7 +269,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(101), @@ -279,7 +279,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -287,7 +287,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -332,7 +332,7 @@ func TestIncreasePosition(t *testing.T) { // funding payment causes negative margin aka bad debt initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(110), // 110 BTC Margin: sdk.NewDec(11), // 11 NUSD OpenNotional: sdk.NewDec(110), // 110 NUSD @@ -344,7 +344,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(110), @@ -354,7 +354,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(110), ). @@ -362,7 +362,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.2"), }) }, @@ -405,7 +405,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -417,7 +417,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(200), @@ -427,7 +427,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -435,7 +435,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -478,7 +478,7 @@ func TestIncreasePosition(t *testing.T) { // user increases position by another 10 NUSD at 10x leverage initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -490,7 +490,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(99), @@ -500,7 +500,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -508,7 +508,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -554,7 +554,7 @@ func TestIncreasePosition(t *testing.T) { // funding payment causes bad debt initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -566,7 +566,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(105), /*baseAssetLimit=*/ sdk.NewDec(100), @@ -576,7 +576,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -584,7 +584,7 @@ func TestIncreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("-0.3"), }) }, @@ -658,7 +658,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 200 NUSD and unrealized PnL of +100 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -666,7 +666,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -685,7 +685,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of -5 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -693,7 +693,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -712,7 +712,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of -50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -720,7 +720,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -741,7 +741,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 100 NUSD and unrealized PnL of +50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-150), // -150 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -749,7 +749,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -768,7 +768,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 105 NUSD and unrealized PnL of -5 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -776,7 +776,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -795,7 +795,7 @@ func TestClosePositionEntirely(t *testing.T) { // user has position notional value of 150 NUSD and unrealized PnL of -50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -803,7 +803,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -828,7 +828,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -837,7 +837,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ tc.quoteAssetLimit, @@ -912,7 +912,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 100 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -947,7 +947,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 95 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(105), // 105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -982,7 +982,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 50 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -1019,7 +1019,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 95 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-105), // -105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1054,7 +1054,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 99.75 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1089,7 +1089,7 @@ func TestDecreasePosition(t *testing.T) { // position notional value of 75 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1124,7 +1124,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1133,7 +1133,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ tc.quoteAssetDir, /*quoteAssetAmount=*/ tc.quoteAmountToDecrease, /*baseAssetLimit=*/ tc.exchangedBaseAmount.Abs(), @@ -1142,7 +1142,7 @@ func TestDecreasePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1510,7 +1510,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ TraderAddress: traderAddr.String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -1523,7 +1523,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), ). @@ -1532,7 +1532,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1543,7 +1543,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ tc.mockQuoteDir, /*quoteAssetAmount=*/ tc.inputQuoteAmount.Mul(tc.inputLeverage).Sub(tc.mockQuoteAmount), /*baseAssetLimit=*/ sdk.MaxDec(tc.inputBaseAssetLimit.Sub(currentPosition.Size_.Abs()), sdk.ZeroDec()), @@ -1553,7 +1553,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1691,7 +1691,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1717,7 +1717,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(105), // 105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1745,7 +1745,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-105), // -105 BTC Margin: sdk.MustNewDecFromStr("10.5"), // 10.5 NUSD OpenNotional: sdk.NewDec(105), // 105 NUSD @@ -1771,7 +1771,7 @@ func TestClosePosition(t *testing.T) { // position notional value of 0 NUSD initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1808,7 +1808,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1817,7 +1817,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1854,7 +1854,7 @@ func TestClosePosition(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1893,7 +1893,7 @@ func TestClosePosition(t *testing.T) { PositionSize: sdk.ZeroDec(), RealizedPnl: tc.expectedRealizedPnl, UnrealizedPnlAfter: sdk.ZeroDec(), - BadDebt: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), sdk.ZeroInt()), + BadDebt: sdk.NewCoin(asset.Registry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), sdk.ZeroInt()), MarkPrice: tc.newPositionNotional.Quo(tc.initialPosition.Size_.Abs()), FundingPayment: sdk.MustNewDecFromStr("0.02").Mul(tc.initialPosition.Size_), TransactionFee: sdk.NewInt64Coin(tc.initialPosition.Pair.QuoteDenom(), 0), @@ -1921,7 +1921,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { // user cannot close position due to bad debt initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(100), // 100 BTC Margin: sdk.NewDec(15), // 15 NUSD OpenNotional: sdk.NewDec(150), // 150 NUSD @@ -1942,7 +1942,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { // user cannot close position due to bad debt initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-100), // -100 BTC Margin: sdk.NewDec(10), // 10 NUSD OpenNotional: sdk.NewDec(100), // 100 NUSD @@ -1971,7 +1971,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1981,7 +1981,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1990,7 +1990,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { t.Log("set up pair metadata and last cumulative funding rate") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) diff --git a/x/perp/keeper/grpc_query_test.go b/x/perp/keeper/grpc_query_test.go index 57043058d..ea6cae39c 100644 --- a/x/perp/keeper/grpc_query_test.go +++ b/x/perp/keeper/grpc_query_test.go @@ -32,7 +32,7 @@ func initAppVpools( t.Log("initialize vpool and pair") assert.NoError(t, vpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve, baseAssetReserve, vpooltypes.VpoolConfig{ @@ -44,12 +44,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -61,12 +61,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -78,7 +78,7 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) return ctx, nibiruApp, queryServer @@ -99,7 +99,7 @@ func TestQueryPosition(t *testing.T) { { name: "positive PnL", initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -116,7 +116,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, positive margin ratio", initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -133,7 +133,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, negative margin ratio", initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -168,7 +168,7 @@ func TestQueryPosition(t *testing.T) { sdk.WrapSDKContext(ctx), &types.QueryPositionRequest{ Trader: traderAddr.String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), }, ) require.NoError(t, err) @@ -194,7 +194,7 @@ func TestQueryPositions(t *testing.T) { name: "positive PnL", Positions: []*types.Position{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -202,7 +202,7 @@ func TestQueryPositions(t *testing.T) { LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -265,7 +265,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "empty string pair", initialPairMetadata: &types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -276,7 +276,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "pair metadata not found", initialPairMetadata: &types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -287,11 +287,11 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "returns single funding payment", initialPairMetadata: &types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), }, expectErr: false, expectedLatestCPF: sdk.ZeroDec(), @@ -306,7 +306,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { ctx, app, queryServer := initAppVpools(t, sdk.NewDec(481_000), sdk.NewDec(1_000)) t.Log("set index price") - app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) t.Log("query cumulative premium fraction") resp, err := queryServer.CumulativePremiumFraction(sdk.WrapSDKContext(ctx), tc.query) @@ -341,7 +341,7 @@ func TestQueryMetrics(t *testing.T) { name: "two longs", Positions: []*types.Position{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -349,7 +349,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -363,7 +363,7 @@ func TestQueryMetrics(t *testing.T) { name: "two shorts", Positions: []*types.Position{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -371,7 +371,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -385,7 +385,7 @@ func TestQueryMetrics(t *testing.T) { name: "one long, one short", Positions: []*types.Position{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -393,7 +393,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -407,14 +407,14 @@ func TestQueryMetrics(t *testing.T) { name: "decrease position", Positions: []*types.Position{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -429,42 +429,42 @@ func TestQueryMetrics(t *testing.T) { name: "swap positions", Positions: []*types.Position{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), @@ -490,7 +490,7 @@ func TestQueryMetrics(t *testing.T) { // Detect position decrease app.PerpKeeper.OnSwapEnd( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), position.OpenNotional, position.Size_, ) @@ -500,7 +500,7 @@ func TestQueryMetrics(t *testing.T) { resp, err := queryServer.Metrics( sdk.WrapSDKContext(ctx), &types.QueryMetricsRequest{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), }, ) require.NoError(t, err) diff --git a/x/perp/keeper/hooks_test.go b/x/perp/keeper/hooks_test.go index e4ea8ee5b..72f692ccc 100644 --- a/x/perp/keeper/hooks_test.go +++ b/x/perp/keeper/hooks_test.go @@ -51,7 +51,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { markPrice: sdk.NewDec(10), expectedLatestCumulativePremiumFraction: sdk.ZeroDec(), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), MarkPrice: sdk.NewDec(10), IndexPrice: sdk.NewDec(10), LatestFundingRate: sdk.ZeroDec(), @@ -67,7 +67,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { indexPrice: sdk.NewDec(462), expectedLatestCumulativePremiumFraction: sdk.MustNewDecFromStr("-9.229166666666666666"), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), MarkPrice: sdk.NewDec(19), IndexPrice: sdk.NewDec(462), LatestFundingRate: sdk.MustNewDecFromStr("-0.019976551226551227"), @@ -83,7 +83,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { indexPrice: sdk.NewDec(64), expectedLatestCumulativePremiumFraction: sdk.MustNewDecFromStr("14.1875"), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), MarkPrice: sdk.NewDec(745), IndexPrice: sdk.NewDec(64), LatestFundingRate: sdk.MustNewDecFromStr("0.2216796875"), @@ -108,7 +108,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { perpKeeper.AfterEpochEnd(ctx, "30 min", 1) t.Log("assert PairMetadataState") - pair, err := perpKeeper.PairsMetadata.Get(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + pair, err := perpKeeper.PairsMetadata.Get(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) assert.Equal(t, tc.expectedLatestCumulativePremiumFraction, pair.LatestCumulativePremiumFraction) @@ -131,23 +131,23 @@ func initParams(ctx sdk.Context, k Keeper) { TwapLookbackWindow: 15 * time.Minute, }) setPairMetadata(k, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), // start with one entry to ensure we append LatestCumulativePremiumFraction: sdk.ZeroDec(), }) } func setMocks(ctx sdk.Context, mocks mockedDependencies, indexPrice sdk.Dec, markPrice sdk.Dec) { - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockEpochKeeper.EXPECT().GetEpochInfo(ctx, "30 min").Return( epochtypes.EpochInfo{Duration: 30 * time.Minute}, ).MaxTimes(1) mocks.mockOracleKeeper.EXPECT(). - GetExchangeRateTwap(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(indexPrice, nil).MaxTimes(1) + GetExchangeRateTwap(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(indexPrice, nil).MaxTimes(1) mocks.mockVpoolKeeper.EXPECT(). - GetMarkPriceTWAP(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), 15*time.Minute). + GetMarkPriceTWAP(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), 15*time.Minute). Return(markPrice, nil).MaxTimes(1) } diff --git a/x/perp/keeper/liquidate_unit_test.go b/x/perp/keeper/liquidate_unit_test.go index 567247848..24c447813 100644 --- a/x/perp/keeper/liquidate_unit_test.go +++ b/x/perp/keeper/liquidate_unit_test.go @@ -91,7 +91,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -104,25 +104,25 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) + ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.OneDec(), 15*time.Minute, @@ -131,7 +131,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.OneDec(), ). @@ -139,7 +139,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.exchangedSize, ). @@ -147,7 +147,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /* quoteAmt */ tc.exchangedNotional, /* baseLimit */ sdk.ZeroDec(), @@ -179,16 +179,16 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, asset.Registry.Pair(denoms.BTC, denoms.NUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee, feeToFund) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(asset.Registry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.NoError(t, err) assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) + assert.EqualValues(t, asset.Registry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) assert.EqualValues(t, tc.expectedPositionSize, newPosition.Size_) assert.EqualValues(t, tc.expectedPositionMargin, newPosition.Margin) assert.EqualValues(t, tc.expectedPositionOpenNotional, newPosition.OpenNotional) @@ -196,7 +196,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.exchangedNotional, ExchangedPositionSize: tc.exchangedSize.Neg(), @@ -266,7 +266,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -279,24 +279,24 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) + ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, 15*time.Minute, @@ -305,7 +305,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -313,7 +313,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /* baseAmt */ tc.initialPositionSize, /* quoteLimit */ sdk.ZeroDec(), @@ -347,18 +347,18 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, asset.Registry.Pair(denoms.BTC, denoms.NUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee.String(), feeToFund.String()) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(asset.Registry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.ErrorIs(t, err, collections.ErrNotFound) assert.Empty(t, newPosition) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.newPositionNotional, ExchangedPositionSize: tc.initialPositionSize.Neg(), @@ -437,7 +437,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -450,24 +450,24 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("set pair metadata") setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) + ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) + mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(false, nil) markPrice := tc.newPositionNotional.Quo(tc.initialPositionSize) - mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, 15*time.Minute, @@ -476,7 +476,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -484,7 +484,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /* baseAmt */ tc.initialPositionSize, /* quoteLimit */ sdk.ZeroDec(), @@ -521,18 +521,18 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { t.Log("execute liquidation") setLiquidator(ctx, perpKeeper, liquidatorAddr) - feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr) + feeToLiquidator, feeToFund, err := perpKeeper.Liquidate(ctx, liquidatorAddr, asset.Registry.Pair(denoms.BTC, denoms.NUSD), traderAddr) require.NoError(t, err) assert.EqualValues(t, tc.expectedLiquidatorFee, feeToLiquidator) assert.EqualValues(t, tc.expectedPerpEFFee.String(), feeToFund.String()) t.Log("assert new position and event") - newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) + newPosition, err := perpKeeper.Positions.Get(ctx, collections.Join(asset.Registry.Pair(denoms.BTC, denoms.NUSD), traderAddr)) require.ErrorIs(t, err, collections.ErrNotFound) assert.Empty(t, newPosition) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: tc.newPositionNotional, ExchangedPositionSize: tc.initialPositionSize.Neg(), @@ -588,7 +588,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { test: func() { perpKeeper, mocks, ctx := getKeeper(t) liquidator := testutilevents.AccAddress() - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(false) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(false) err := perpKeeper.distributeLiquidateRewards(ctx, types.LiquidateResp{ @@ -598,7 +598,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { Liquidator: liquidator.String(), PositionResp: &types.PositionResp{ Position: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), }, }, }, @@ -613,7 +613,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { perpKeeper, mocks, ctx := getKeeper(t) liquidator := testutilevents.AccAddress() - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockAccountKeeper. EXPECT().GetModuleAddress(types.VaultModuleAccount). @@ -639,7 +639,7 @@ func TestDistributeLiquidateRewards(t *testing.T) { Liquidator: liquidator.String(), PositionResp: &types.PositionResp{ Position: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), }}, }, ) @@ -929,16 +929,16 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { newParams.LiquidationFeeRatio = tc.liquidationFee perpKeeper.SetParams(ctx, newParams) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -946,20 +946,20 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), /* skipFluctuationLimitCheck */ true, ).Return( /*quoteAssetAmount=*/ tc.baseAssetPriceInQuote, nil) mocks.mockVpoolKeeper.EXPECT(). - GetMarkPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMarkPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.OneDec(), nil) t.Log("create and set the initial position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialMargin, OpenNotional: tc.initialOpenNotional, @@ -997,7 +997,7 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { t.Log("assert new position fields") newPosition := positionResp.Position assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) + assert.EqualValues(t, asset.Registry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) assert.True(t, newPosition.Size_.IsZero()) // always zero assert.True(t, newPosition.Margin.IsZero()) // always zero assert.True(t, newPosition.OpenNotional.IsZero()) // always zero @@ -1005,15 +1005,15 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: positionResp.ExchangedNotionalValue, ExchangedPositionSize: positionResp.ExchangedPositionSize, LiquidatorAddress: liquidatorAddr.String(), - FeeToLiquidator: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToLiquidator), - FeeToEcosystemFund: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToPerpEF), + FeeToLiquidator: sdk.NewCoin(asset.Registry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToLiquidator), + FeeToEcosystemFund: sdk.NewCoin(asset.Registry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToPerpEF), BadDebt: sdk.NewCoin(denoms.NUSD, tc.expectedLiquidationBadDebt), - Margin: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), newPosition.Margin.RoundInt()), + Margin: sdk.NewCoin(asset.Registry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), newPosition.Margin.RoundInt()), PositionNotional: positionResp.PositionNotional, PositionSize: newPosition.Size_, UnrealizedPnl: positionResp.UnrealizedPnlAfter, @@ -1220,16 +1220,16 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { newParams.PartialLiquidationRatio = tc.partialLiquidationRatio perpKeeper.SetParams(ctx, newParams) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Mul(tc.partialLiquidationRatio), ). @@ -1238,7 +1238,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -1248,7 +1248,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ tc.baseAssetPriceInQuote.Mul(tc.partialLiquidationRatio), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), @@ -1258,7 +1258,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ tc.baseAssetPriceInQuote.Mul(tc.partialLiquidationRatio), /*quoteAssetAssetLimit=*/ sdk.ZeroDec(), @@ -1267,13 +1267,13 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { } mocks.mockVpoolKeeper.EXPECT(). - GetMarkPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)). + GetMarkPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.OneDec(), nil) t.Log("create and set the initial position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialMargin, OpenNotional: tc.initialOpenNotional, @@ -1313,21 +1313,21 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { t.Log("assert new position fields") newPosition := positionResp.Position assert.EqualValues(t, traderAddr.String(), newPosition.TraderAddress) - assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) + assert.EqualValues(t, asset.Registry.Pair(denoms.BTC, denoms.NUSD), newPosition.Pair) assert.True(t, newPosition.LatestCumulativePremiumFraction.IsZero()) assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) assert.EqualValues(t, tc.expectedPositionMargin, newPosition.Margin) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), ExchangedQuoteAmount: positionResp.ExchangedNotionalValue, ExchangedPositionSize: positionResp.ExchangedPositionSize, LiquidatorAddress: liquidatorAddr.String(), - FeeToLiquidator: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToLiquidator), - FeeToEcosystemFund: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToPerpEF), - BadDebt: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), sdk.ZeroInt()), - Margin: sdk.NewCoin(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), newPosition.Margin.RoundInt()), + FeeToLiquidator: sdk.NewCoin(asset.Registry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToLiquidator), + FeeToEcosystemFund: sdk.NewCoin(asset.Registry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), tc.expectedFundsToPerpEF), + BadDebt: sdk.NewCoin(asset.Registry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), sdk.ZeroInt()), + Margin: sdk.NewCoin(asset.Registry.Pair(denoms.BTC, denoms.NUSD).QuoteDenom(), newPosition.Margin.RoundInt()), PositionNotional: positionResp.PositionNotional, PositionSize: newPosition.Size_, UnrealizedPnl: positionResp.UnrealizedPnlAfter, diff --git a/x/perp/keeper/margin_test.go b/x/perp/keeper/margin_test.go index e73b143d2..0d689c7df 100644 --- a/x/perp/keeper/margin_test.go +++ b/x/perp/keeper/margin_test.go @@ -38,7 +38,7 @@ func TestAddMarginSuccess(t *testing.T) { latestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.001"), initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(1_000), Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(500), @@ -69,7 +69,7 @@ func TestAddMarginSuccess(t *testing.T) { vpoolKeeper := &nibiruApp.VpoolKeeper assert.NoError(t, vpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens vpooltypes.VpoolConfig{ @@ -80,11 +80,11 @@ func TestAddMarginSuccess(t *testing.T) { MaxLeverage: sdk.MustNewDecFromStr("15"), }, )) - require.True(t, vpoolKeeper.ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD))) + require.True(t, vpoolKeeper.ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD))) t.Log("set pair metadata") setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: tc.latestCumulativePremiumFraction, }, ) @@ -92,14 +92,14 @@ func TestAddMarginSuccess(t *testing.T) { t.Log("establish initial position") setPosition(nibiruApp.PerpKeeper, ctx, tc.initialPosition) - resp, err := nibiruApp.PerpKeeper.AddMargin(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), traderAddr, tc.marginToAdd) + resp, err := nibiruApp.PerpKeeper.AddMargin(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), traderAddr, tc.marginToAdd) require.NoError(t, err) assert.EqualValues(t, tc.expectedFundingPayment, resp.FundingPayment) assert.EqualValues(t, tc.expectedMargin, resp.Position.Margin) assert.EqualValues(t, tc.initialPosition.OpenNotional, resp.Position.OpenNotional) assert.EqualValues(t, tc.initialPosition.Size_, resp.Position.Size_) assert.EqualValues(t, traderAddr.String(), resp.Position.TraderAddress) - assert.EqualValues(t, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), resp.Position.Pair) + assert.EqualValues(t, asset.Registry.Pair(denoms.BTC, denoms.NUSD), resp.Position.Pair) assert.EqualValues(t, tc.latestCumulativePremiumFraction, resp.Position.LatestCumulativePremiumFraction) assert.EqualValues(t, ctx.BlockHeight(), resp.Position.BlockNumber) }) diff --git a/x/perp/keeper/margin_unit_test.go b/x/perp/keeper/margin_unit_test.go index bc5983643..85e965a8b 100644 --- a/x/perp/keeper/margin_unit_test.go +++ b/x/perp/keeper/margin_unit_test.go @@ -112,7 +112,7 @@ func TestGetMarginRatio(t *testing.T) { name: "margin without price changes", position: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -125,7 +125,7 @@ func TestGetMarginRatio(t *testing.T) { name: "margin with price changes", position: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -145,7 +145,7 @@ func TestGetMarginRatio(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.position.Size_.Abs(), ). @@ -154,7 +154,7 @@ func TestGetMarginRatio(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.position.Size_.Abs(), 15*time.Minute, @@ -162,7 +162,7 @@ func TestGetMarginRatio(t *testing.T) { Return(tc.newPrice, nil) setPairMetadata(perpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.OneDec(), }) @@ -636,7 +636,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -645,7 +645,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -659,7 +659,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -668,7 +668,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -682,7 +682,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -691,7 +691,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -706,7 +706,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -715,7 +715,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -730,7 +730,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; positive pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -739,7 +739,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.NewDec(2), nil) }, @@ -751,7 +751,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -760,7 +760,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.MustNewDecFromStr("0.5"), nil) }, @@ -772,7 +772,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -781,7 +781,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), ). @@ -795,7 +795,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; negative pnl; spot price calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -804,7 +804,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), ). @@ -818,7 +818,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -827,7 +827,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), 15*time.Minute, @@ -842,7 +842,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; negative pnl; twap calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -851,7 +851,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, sdk.NewDec(10), 15*time.Minute, @@ -866,7 +866,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "short position; positive pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -875,7 +875,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.MustNewDecFromStr("0.5"), nil) }, @@ -887,7 +887,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { name: "long position; negative pnl; oracle calc", initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -896,7 +896,7 @@ func TestGetPositionNotionalAndUnrealizedPnl(t *testing.T) { mocks.mockOracleKeeper.EXPECT(). GetExchangeRate( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), ). Return(sdk.NewDec(2), nil) }, @@ -943,7 +943,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "max pnl, pick spot price", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -953,7 +953,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -962,7 +962,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -977,7 +977,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "max pnl, pick twap", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -987,7 +987,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -996,7 +996,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -1011,7 +1011,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "min pnl, pick spot price", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -1021,7 +1021,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -1030,7 +1030,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, @@ -1045,7 +1045,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { name: "min pnl, pick twap", initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -1055,7 +1055,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), ). @@ -1064,7 +1064,7 @@ func TestGetPreferencePositionNotionalAndUnrealizedPnL(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.NewDec(10), 15*time.Minute, diff --git a/x/perp/keeper/msg_server_test.go b/x/perp/keeper/msg_server_test.go index 118308027..8887df872 100644 --- a/x/perp/keeper/msg_server_test.go +++ b/x/perp/keeper/msg_server_test.go @@ -37,7 +37,7 @@ func TestMsgServerAddMargin(t *testing.T) { name: "trader not enough funds", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), @@ -58,7 +58,7 @@ func TestMsgServerAddMargin(t *testing.T) { name: "success", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), @@ -80,7 +80,7 @@ func TestMsgServerAddMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -92,7 +92,7 @@ func TestMsgServerAddMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -107,7 +107,7 @@ func TestMsgServerAddMargin(t *testing.T) { resp, err := msgServer.AddMargin(sdk.WrapSDKContext(ctx), &types.MsgAddMargin{ Sender: traderAddr.String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Margin: tc.margin, }) @@ -144,7 +144,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { name: "position not enough margin", vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), @@ -165,7 +165,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { name: "vault insufficient funds", vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), @@ -179,7 +179,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { name: "success", vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: &types.Position{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), @@ -201,7 +201,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -213,7 +213,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -230,7 +230,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { resp, err := msgServer.RemoveMargin(sdk.WrapSDKContext(ctx), &types.MsgRemoveMargin{ Sender: traderAddr.String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Margin: tc.marginToRemove, }) @@ -265,14 +265,14 @@ func TestMsgServerOpenPosition(t *testing.T) { { name: "trader not enough funds", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), sender: testutil.AccAddress().String(), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "success", traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), sender: testutil.AccAddress().String(), expectedErr: nil, }, @@ -288,7 +288,7 @@ func TestMsgServerOpenPosition(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + /* pair */ asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -300,7 +300,7 @@ func TestMsgServerOpenPosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -359,7 +359,7 @@ func TestMsgServerClosePosition(t *testing.T) { }{ { name: "success", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), traderAddr: testutil.AccAddress(), expectedErr: nil, }, @@ -375,7 +375,7 @@ func TestMsgServerClosePosition(t *testing.T) { assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -387,7 +387,7 @@ func TestMsgServerClosePosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -436,7 +436,7 @@ func TestMsgServerLiquidate(t *testing.T) { }{ { name: "success", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), liquidator: testutil.AccAddress().String(), trader: testutil.AccAddress().String(), expectedErr: nil, @@ -454,7 +454,7 @@ func TestMsgServerLiquidate(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + /* pair */ asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -466,7 +466,7 @@ func TestMsgServerLiquidate(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(time.Now().Add(time.Minute)) @@ -474,7 +474,7 @@ func TestMsgServerLiquidate(t *testing.T) { traderAddr, err := sdk.AccAddressFromBech32(tc.trader) if err == nil { t.Log("set oracle price") - app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) t.Log("create position") setPosition(app.PerpKeeper, ctx, types.Position{ @@ -517,7 +517,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ctx = ctx.WithBlockTime(time.Now()) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) - pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) liquidator := testutil.AccAddress() atRiskTrader1 := testutil.AccAddress() @@ -545,7 +545,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(time.Now().Add(time.Minute)) t.Log("set oracle price") - app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) t.Log("create positions") atRiskPosition1 := types.Position{ diff --git a/x/perp/simulation/genesis.go b/x/perp/simulation/genesis.go index 01ee88fe0..f73611f6e 100644 --- a/x/perp/simulation/genesis.go +++ b/x/perp/simulation/genesis.go @@ -18,7 +18,7 @@ func RandomizedGenState(simState *module.SimulationState) { Params: types.DefaultParams(), PairMetadata: []types.PairMetadata{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, }, diff --git a/x/perp/simulation/operations.go b/x/perp/simulation/operations.go index 05fa6e37b..745e33d0e 100644 --- a/x/perp/simulation/operations.go +++ b/x/perp/simulation/operations.go @@ -77,7 +77,7 @@ func SimulateMsgOpenPosition(ak types.AccountKeeper, bk types.BankKeeper, k keep msg := &types.MsgOpenPosition{ Sender: simAccount.Address.String(), - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Side: side, QuoteAssetAmount: quoteAmt, Leverage: leverage, @@ -172,14 +172,14 @@ func SimulateMsgClosePosition(ak types.AccountKeeper, bk types.BankKeeper, k kee ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) msg := &types.MsgClosePosition{ Sender: trader, Pair: pair, } - _, err := k.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) + _, err := k.Positions.Get(ctx, collections.Join(asset.Registry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } @@ -210,10 +210,10 @@ func SimulateMsgAddMargin(ak types.AccountKeeper, bk types.BankKeeper, k keeper. ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) msg := &types.MsgAddMargin{} - _, err := k.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) + _, err := k.Positions.Get(ctx, collections.Join(asset.Registry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } @@ -259,11 +259,11 @@ func SimulateMsgRemoveMargin(ak types.AccountKeeper, bk types.BankKeeper, k keep ) (opMsg simtypes.OperationMsg, futureOps []simtypes.FutureOperation, err error) { simAccount, _ := simtypes.RandomAcc(r, accs) trader := simAccount.Address.String() - pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) msg := &types.MsgRemoveMargin{} - position, err := k.Positions.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) + position, err := k.Positions.Get(ctx, collections.Join(asset.Registry.Pair(denoms.BTC, denoms.NUSD), simAccount.Address)) if err != nil { return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "no position opened yet"), nil, nil } diff --git a/x/perp/types/msgs_test.go b/x/perp/types/msgs_test.go index 14853875a..b76ffeafb 100644 --- a/x/perp/types/msgs_test.go +++ b/x/perp/types/msgs_test.go @@ -337,7 +337,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, }}, @@ -348,7 +348,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, { @@ -363,11 +363,11 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Trader: "invalid", }, }}, diff --git a/x/stablecoin/abci.go b/x/stablecoin/abci.go index 412d04a7f..467acaf11 100644 --- a/x/stablecoin/abci.go +++ b/x/stablecoin/abci.go @@ -20,7 +20,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) { k.SetParams(ctx, params) } - _, err := k.OracleKeeper.GetExchangeRateTwap(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + _, err := k.OracleKeeper.GetExchangeRateTwap(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { params := k.GetParams(ctx) diff --git a/x/stablecoin/abci_test.go b/x/stablecoin/abci_test.go index a7d842dd9..f48686152 100644 --- a/x/stablecoin/abci_test.go +++ b/x/stablecoin/abci_test.go @@ -40,7 +40,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second * 60 * 16)) - app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -54,7 +54,7 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second * 60 * 16)) - app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -84,11 +84,11 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*15)) - app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*30)) - app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -102,11 +102,11 @@ func TestEpochInfoChangesBeginBlockerAndInitGenesis(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*14)) - app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) ctx = ctx.WithBlockHeight(3).WithBlockTime(ctx.BlockTime().Add(time.Second + time.Minute*16)) - app.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), price) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -143,7 +143,7 @@ func TestEpochInfoChangesCollateralValidity(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) pairs := common.AssetPairs{ - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), } params := otypes.DefaultParams() params.TwapLookbackWindow = 1 * time.Hour diff --git a/x/stablecoin/client/cli/cli_test.go b/x/stablecoin/client/cli/cli_test.go index d6391ce71..1e74c783d 100644 --- a/x/stablecoin/client/cli/cli_test.go +++ b/x/stablecoin/client/cli/cli_test.go @@ -56,8 +56,8 @@ func (s *IntegrationTestSuite) SetupSuite() { oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDec(10)}, - {Pair: asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), ExchangeRate: sdk.NewDec(1)}, + {Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDec(10)}, + {Pair: asset.Registry.Pair(denoms.USDC, denoms.NUSD), ExchangeRate: sdk.NewDec(1)}, } oracleGenesis.Params.VotePeriod = 1_000 diff --git a/x/stablecoin/keeper/collateral_ratio.go b/x/stablecoin/keeper/collateral_ratio.go index aba113348..d19b1e85b 100644 --- a/x/stablecoin/keeper/collateral_ratio.go +++ b/x/stablecoin/keeper/collateral_ratio.go @@ -88,7 +88,7 @@ func (k *Keeper) EvaluateCollRatio(ctx sdk.Context) (err error) { upperBound := params.GetPriceUpperBoundAsDec() stablePrice, err := k.OracleKeeper.GetExchangeRateTwap( - ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return err } @@ -122,7 +122,7 @@ func (k *Keeper) StableRequiredForTargetCollRatio( for _, collDenom := range collDenoms { amtColl := moduleCoins.AmountOf(collDenom) priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.ZeroDec(), err } @@ -140,7 +140,7 @@ func (k *Keeper) RecollateralizeCollAmtForTargetCollRatio( ) (neededCollAmount sdk.Int, err error) { neededUSDForRecoll, _ := k.StableRequiredForTargetCollRatio(ctx) priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -224,7 +224,7 @@ func (k Keeper) Recollateralize( // Compute GOV rewarded to user priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return response, err } @@ -295,7 +295,7 @@ func (k *Keeper) GovAmtFromRecollateralize( bonusRate := params.GetBonusRateRecollAsDec() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -338,7 +338,7 @@ func (k *Keeper) BuybackGovAmtForTargetCollRatio( neededUSDForRecoll, _ := k.StableRequiredForTargetCollRatio(ctx) neededUSDForBuyback := neededUSDForRecoll.Neg() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -415,7 +415,7 @@ func (k Keeper) Buyback( // Compute USD (stable) value of the GOV sent by the caller: 'inUSD' priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return response, err } @@ -475,7 +475,7 @@ func (k *Keeper) CollAmtFromBuyback( ctx sdk.Context, valUSD sdk.Dec, ) (collAmt sdk.Int, err error) { priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.Int{}, err } diff --git a/x/stablecoin/keeper/collateral_ratio_test.go b/x/stablecoin/keeper/collateral_ratio_test.go index a46b449f8..d3148cbb2 100644 --- a/x/stablecoin/keeper/collateral_ratio_test.go +++ b/x/stablecoin/keeper/collateral_ratio_test.go @@ -83,7 +83,7 @@ func TestSetCollRatioUpdate(t *testing.T) { stablecoinKeeper := &nibiruApp.StablecoinKeeper oracleKeeper := &nibiruApp.OracleKeeper - oracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.price) + oracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), tc.price) err := stablecoinKeeper.SetCollRatio(ctx, tc.inCollRatio) require.NoError(t, err) err = stablecoinKeeper.EvaluateCollRatio(ctx) @@ -180,7 +180,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(500), priceCollStable: sdk.OneDec(), // startCollUSD = 500 * 1 -> 500 postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 @@ -191,7 +191,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(600), priceCollStable: sdk.OneDec(), // startCollUSD = 600 * 1 = 600 postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.5"), // 0.5 * 1000 = 500 @@ -224,7 +224,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { // Post prices to each specified market with the oracle. prices := map[common.AssetPair]sdk.Dec{ - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, + asset.Registry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -297,7 +297,7 @@ func TestRecollateralizeCollAmtForTargetCollRatio(t *testing.T) { )) // Post the price - pair := asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD) + pair := asset.Registry.Pair(denoms.USDC, denoms.NUSD) nibiruApp.OracleKeeper.SetPrice(ctx, pair, tc.priceCollStable) neededCollAmount, err := stablecoinKeeper.RecollateralizeCollAmtForTargetCollRatio(ctx) @@ -379,7 +379,7 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 priceCollStable: sdk.OneDec(), postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)}, + asset.Registry.Pair(denoms.USDC, denoms.NUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -390,7 +390,7 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 priceGovStable: sdk.OneDec(), postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)}, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -400,8 +400,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(10_000), targetCollRatio: sdk.MustNewDecFromStr("0.7"), // 0.7 * 10_000 = 7_000 postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(2), @@ -416,8 +416,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(100_000), targetCollRatio: sdk.MustNewDecFromStr("0.7"), // 0.7 * 100_000 = 70_000 postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -432,8 +432,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { stableSupply: sdk.NewInt(100_000), targetCollRatio: sdk.MustNewDecFromStr("0.5"), // 0.5 * 100_000 = 50_000 postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -458,8 +458,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { )) prices := map[common.AssetPair]sdk.Dec{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.Registry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -467,8 +467,8 @@ func TestGovAmtFromFullRecollateralize(t *testing.T) { // Post prices to each specified market with the oracle. prices = map[common.AssetPair]sdk.Dec{ - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.Registry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, } for _, assetPair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, assetPair, prices[assetPair]) @@ -520,8 +520,8 @@ func TestRecollateralize(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -553,8 +553,8 @@ func TestRecollateralize(t *testing.T) { { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -588,8 +588,8 @@ func TestRecollateralize(t *testing.T) { { name: "protocol has sufficient collateral - error", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -615,8 +615,8 @@ func TestRecollateralize(t *testing.T) { { name: "caller is broke - error", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -642,8 +642,8 @@ func TestRecollateralize(t *testing.T) { { name: "negative msg.Coll.Amount - error", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -669,7 +669,7 @@ func TestRecollateralize(t *testing.T) { { name: "oracle prices are expired - error", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -718,8 +718,8 @@ func TestRecollateralize(t *testing.T) { } prices := map[common.AssetPair]sdk.Dec{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.Registry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -727,8 +727,8 @@ func TestRecollateralize(t *testing.T) { // Post prices to each specified market with the oracle. prices = map[common.AssetPair]sdk.Dec{ - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.Registry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, } for _, assetPair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, assetPair, prices[assetPair]) @@ -851,8 +851,8 @@ func TestBuyback(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -887,8 +887,8 @@ func TestBuyback(t *testing.T) { { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(850_000), @@ -928,8 +928,8 @@ func TestBuyback(t *testing.T) { { name: "msg has more NIBI than the protocol needs, only needed sent", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -961,8 +961,8 @@ func TestBuyback(t *testing.T) { { name: "protocol under-collateralized, so buyback won't run", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -987,8 +987,8 @@ func TestBuyback(t *testing.T) { { name: "caller has insufficient funds", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1013,7 +1013,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing collateral price post", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1038,7 +1038,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing NIBI price post", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1091,8 +1091,8 @@ func TestBuyback(t *testing.T) { // Set up markets for the oracle keeper. prices := map[common.AssetPair]sdk.Dec{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.Registry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -1133,8 +1133,8 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, correct amount out", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1164,7 +1164,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, only coll price posted", postedAssetPairs: []common.AssetPair{ - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1193,8 +1193,8 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { )) prices := map[common.AssetPair]sdk.Dec{ - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, - asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD): tc.priceGovStable, + asset.Registry.Pair(denoms.USDC, denoms.NUSD): tc.scenario.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) diff --git a/x/stablecoin/keeper/mint_burn_stable.go b/x/stablecoin/keeper/mint_burn_stable.go index e233f849c..9a9490c61 100644 --- a/x/stablecoin/keeper/mint_burn_stable.go +++ b/x/stablecoin/keeper/mint_burn_stable.go @@ -95,7 +95,7 @@ func (k Keeper) calcNeededGovAndFees( ctx sdk.Context, stable sdk.Coin, govRatio sdk.Dec, feeRatio sdk.Dec, ) (sdk.Coin, sdk.Coin, error) { priceGov, err := k.OracleKeeper.GetExchangeRate( - ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)) + ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } @@ -117,7 +117,7 @@ func (k Keeper) calcNeededCollateralAndFees( feeRatio sdk.Dec, ) (sdk.Coin, sdk.Coin, error) { priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD)) + ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.Coin{}, sdk.Coin{}, err } diff --git a/x/stablecoin/keeper/mint_burn_stable_test.go b/x/stablecoin/keeper/mint_burn_stable_test.go index 446ef4d70..bf66ba1be 100644 --- a/x/stablecoin/keeper/mint_burn_stable_test.go +++ b/x/stablecoin/keeper/mint_burn_stable_test.go @@ -146,8 +146,8 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { ) // Post prices to each pair with the oracle. - nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Fund account require.NoError(t, simapp.FundAccount(nibiruApp.BankKeeper, ctx, acc, tc.accFunds)) @@ -303,8 +303,8 @@ func TestMsgMintStableResponse_NotEnoughFunds(t *testing.T) { ) t.Log("Post prices to each pair with the oracle.") - nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Fund account require.NoError(t, simapp.FundAccount(nibiruApp.BankKeeper, ctx, acc, tc.accFunds)) @@ -450,8 +450,8 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { nibiruApp.StablecoinKeeper.SetParams(ctx, defaultParams) t.Log("Post prices to each pair with the oracle.") - nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Add collaterals to the module require.NoError(t, nibiruApp.BankKeeper.MintCoins(ctx, types.ModuleName, tc.moduleFunds)) @@ -571,8 +571,8 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { ), ) - nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD), tc.govPrice) + nibiruApp.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), tc.collPrice) // Add collaterals to the module require.NoError(t, nibiruApp.BankKeeper.MintCoins(ctx, types.ModuleName, tc.moduleFunds)) diff --git a/x/vpool/abci_test.go b/x/vpool/abci_test.go index 5e9b4cc3f..8ab57fa14 100644 --- a/x/vpool/abci_test.go +++ b/x/vpool/abci_test.go @@ -32,7 +32,7 @@ func TestSnapshotUpdates(t *testing.T) { require.NoError(t, vpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(1_000), sdk.NewDec(1_000), types.DefaultVpoolConfig(). @@ -40,7 +40,7 @@ func TestSnapshotUpdates(t *testing.T) { WithFluctuationLimitRatio(sdk.OneDec()), )) expectedSnapshot := types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(1_000), sdk.NewDec(1_000), ctx.BlockTime(), @@ -48,14 +48,14 @@ func TestSnapshotUpdates(t *testing.T) { t.Log("run one block of 5 seconds") runBlock(5 * time.Second) - snapshot, err := vpoolKeeper.ReserveSnapshots.Get(ctx, collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) + snapshot, err := vpoolKeeper.ReserveSnapshots.Get(ctx, collections.Join(asset.Registry.Pair(denoms.BTC, denoms.NUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) require.NoError(t, err) assert.EqualValues(t, expectedSnapshot, snapshot) t.Log("affect mark price") baseAmtAbs, err := vpoolKeeper.SwapQuoteForBase( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), types.Direction_ADD_TO_POOL, sdk.NewDec(250), // ← dyAmm sdk.ZeroDec(), @@ -65,7 +65,7 @@ func TestSnapshotUpdates(t *testing.T) { assert.EqualValues(t, sdk.NewDec(200), baseAmtAbs) require.NoError(t, err) expectedSnapshot = types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(800), // ← x + dxAmm sdk.NewDec(1_250), // ← y + dyAMM ctx.BlockTime(), @@ -76,7 +76,7 @@ func TestSnapshotUpdates(t *testing.T) { timeSkipDuration := 5 * time.Second runBlock(timeSkipDuration) // increments ctx.blockHeight and ctx.BlockTime snapshot, err = vpoolKeeper.ReserveSnapshots.Get(ctx, - collections.Join(asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) + collections.Join(asset.Registry.Pair(denoms.BTC, denoms.NUSD), time.UnixMilli(expectedSnapshot.TimestampMs))) require.NoError(t, err) assert.EqualValues(t, expectedSnapshot, snapshot) diff --git a/x/vpool/client/cli/cli_test.go b/x/vpool/client/cli/cli_test.go index e3580d73d..f03edf4ec 100644 --- a/x/vpool/client/cli/cli_test.go +++ b/x/vpool/client/cli/cli_test.go @@ -36,8 +36,8 @@ func TestIntegrationTestSuite(t *testing.T) { } var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD): { - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD): { + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -48,8 +48,8 @@ var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ MaxLeverage: sdk.MustNewDecFromStr("15"), }, }, - asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD): { - Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.NIBI, denoms.NUSD): { + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), BaseAssetReserve: sdk.NewDec(500_000), QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: vpooltypes.VpoolConfig{ @@ -75,14 +75,14 @@ func (s *IntegrationTestSuite) SetupSuite() { genesisState := simapp.NewTestGenesisStateFromDefault() vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ - START_VPOOLS[asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)], - START_VPOOLS[asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)], + START_VPOOLS[asset.Registry.Pair(denoms.ETH, denoms.NUSD)], + START_VPOOLS[asset.Registry.Pair(denoms.NIBI, denoms.NUSD)], } oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.ExchangeRates = []oracletypes.ExchangeRateTuple{ - {Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDec(1_000)}, - {Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDec(10)}, + {Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.NewDec(1_000)}, + {Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.NewDec(10)}, } oracleGenesis.Params.VotePeriod = 1_000 @@ -170,13 +170,13 @@ func (s *IntegrationTestSuite) TestGetPrices() { val := s.network.Validators[0] s.T().Log("check vpool balances") - reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)) + reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, asset.Registry.Pair(denoms.ETH, denoms.NUSD)) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("10000000"), reserveAssets.BaseAssetReserve) s.EqualValues(sdk.MustNewDecFromStr("60000000000"), reserveAssets.QuoteAssetReserve) s.T().Log("check prices") - priceInfo, err := testutilcli.QueryBaseAssetPrice(val.ClientCtx, asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), "add", "100") + priceInfo, err := testutilcli.QueryBaseAssetPrice(val.ClientCtx, asset.Registry.Pair(denoms.ETH, denoms.NUSD), "add", "100") s.T().Logf("priceInfo: %+v", priceInfo) s.EqualValues(sdk.MustNewDecFromStr("599994.000059999400006000"), priceInfo.PriceInQuoteDenom) s.NoError(err) @@ -188,7 +188,7 @@ func (s *IntegrationTestSuite) TestCmdEditPoolConfigProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD)] + startVpool := START_VPOOLS[asset.Registry.Pair(denoms.ETH, denoms.NUSD)] proposal := &vpooltypes.EditPoolConfigProposal{ Title: "NIP-3: Edit config of the ueth:unusd vpool", Description: "enables higher max leverage on ueth:unusd", @@ -254,7 +254,7 @@ func (s *IntegrationTestSuite) TestCmdEditSwapInvariantsProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD)] + startVpool := START_VPOOLS[asset.Registry.Pair(denoms.NIBI, denoms.NUSD)] proposal := &vpooltypes.EditSwapInvariantsProposal{ Title: "NIP-4: Change the swap invariant for ATOM, OSMO, and BTC.", Description: "increase swap invariant for many virtual pools", diff --git a/x/vpool/keeper/keeper_test.go b/x/vpool/keeper/keeper_test.go index dead502a3..767746031 100644 --- a/x/vpool/keeper/keeper_test.go +++ b/x/vpool/keeper/keeper_test.go @@ -34,7 +34,7 @@ func TestSwapQuoteForBase(t *testing.T) { }{ { name: "quote amount == 0", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(0), baseLimit: sdk.NewDec(10), @@ -46,7 +46,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap add", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(49504), @@ -58,7 +58,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap remove", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(50506), @@ -80,7 +80,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount less than base limit in Long", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(500_000), baseLimit: sdk.NewDec(454_500), @@ -90,7 +90,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount more than base limit in Short", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_500), @@ -100,7 +100,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when removing quote", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -110,7 +110,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when adding quote", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -120,7 +120,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), @@ -130,7 +130,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), @@ -140,7 +140,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), @@ -152,7 +152,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), @@ -174,7 +174,7 @@ func TestSwapQuoteForBase(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ @@ -202,7 +202,7 @@ func TestSwapQuoteForBase(t *testing.T) { assert.EqualValuesf(t, tc.expectedBaseAmount, baseAmt, "base amount mismatch") t.Log("assert vpool") - pool, err := vpoolKeeper.Pools.Get(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + pool, err := vpoolKeeper.Pools.Get(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) assert.EqualValuesf(t, tc.expectedQuoteReserve, pool.QuoteAssetReserve, "pool quote asset reserve mismatch") assert.EqualValuesf(t, tc.expectedBaseReserve, pool.BaseAssetReserve, "pool base asset reserve mismatch") @@ -227,7 +227,7 @@ func TestSwapBaseForQuote(t *testing.T) { }{ { name: "zero base asset swap", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.ZeroDec(), quoteLimit: sdk.ZeroDec(), @@ -239,7 +239,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "add base asset swap", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196078), @@ -251,7 +251,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "remove base asset", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(204_082), @@ -273,7 +273,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount less than quote limit in Long", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196079), @@ -283,7 +283,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount more than quote limit in Short", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(204_081), @@ -293,7 +293,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when removing base", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -303,7 +303,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when adding base", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -313,7 +313,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), @@ -323,7 +323,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), @@ -333,7 +333,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), @@ -345,7 +345,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), @@ -367,7 +367,7 @@ func TestSwapBaseForQuote(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ @@ -396,7 +396,7 @@ func TestSwapBaseForQuote(t *testing.T) { "expected %s; got %s", tc.expectedQuoteAssetAmount.String(), quoteAssetAmount.String()) t.Log("assert pool") - pool, err := vpoolKeeper.Pools.Get(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + pool, err := vpoolKeeper.Pools.Get(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) assert.Equal(t, tc.expectedQuoteReserve, pool.QuoteAssetReserve) assert.Equal(t, tc.expectedBaseReserve, pool.BaseAssetReserve) @@ -412,7 +412,7 @@ func TestGetVpools(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), sdk.NewDec(5*common.Precision), types.VpoolConfig{ @@ -425,7 +425,7 @@ func TestGetVpools(t *testing.T) { )) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + asset.Registry.Pair(denoms.ETH, denoms.NUSD), sdk.NewDec(5*common.Precision), sdk.NewDec(10*common.Precision), types.VpoolConfig{ @@ -442,7 +442,7 @@ func TestGetVpools(t *testing.T) { require.EqualValues(t, 2, len(pools)) require.EqualValues(t, pools[0], types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(5 * common.Precision), QuoteAssetReserve: sdk.NewDec(10 * common.Precision), Config: types.VpoolConfig{ @@ -454,7 +454,7 @@ func TestGetVpools(t *testing.T) { }, }) require.EqualValues(t, pools[1], types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: types.VpoolConfig{ @@ -478,7 +478,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses latest snapshot - does not result in error", pool: types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -491,13 +491,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -508,7 +508,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses previous snapshot - results in error", pool: types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -521,7 +521,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -532,7 +532,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "only one snapshot - no error", pool: types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -545,7 +545,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -556,7 +556,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "zero fluctuation limit - no error", pool: types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -569,13 +569,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -586,7 +586,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "multiple pools - no overlap", pool: types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -599,25 +599,25 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.USDC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -668,7 +668,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -679,7 +679,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -696,7 +696,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { mock.NewMockOracleKeeper(gomock.NewController(t)), ) vpoolKeeper.Pools.Insert(ctx, tc.pool.Pair, tc.pool) - mmr, err := vpoolKeeper.GetMaintenanceMarginRatio(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + mmr, err := vpoolKeeper.GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) assert.NoError(t, err) assert.EqualValues(t, tc.expectedMaintenanceMarginRatio, mmr) }) @@ -713,7 +713,7 @@ func TestGetMaxLeverage(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -736,7 +736,7 @@ func TestGetMaxLeverage(t *testing.T) { ) vpoolKeeper.Pools.Insert(ctx, tc.pool.Pair, tc.pool) - maxLeverage, err := vpoolKeeper.GetMaxLeverage(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + maxLeverage, err := vpoolKeeper.GetMaxLeverage(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) assert.EqualValues(t, tc.expectedMaxLeverage, maxLeverage) assert.NoError(t, err) }) diff --git a/x/vpool/keeper/pool_state_test.go b/x/vpool/keeper/pool_state_test.go index d8b5706b7..f931ed2d1 100644 --- a/x/vpool/keeper/pool_state_test.go +++ b/x/vpool/keeper/pool_state_test.go @@ -20,7 +20,7 @@ func TestCreatePool(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens @@ -33,7 +33,7 @@ func TestCreatePool(t *testing.T) { }, )) - exists := vpoolKeeper.ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + exists := vpoolKeeper.ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) require.True(t, exists) notExist := vpoolKeeper.ExistsPool(ctx, "BTC:OTHER") @@ -41,7 +41,7 @@ func TestCreatePool(t *testing.T) { } func TestEditPoolConfig(t *testing.T) { - pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) vpoolStart := types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(10 * common.Precision), @@ -59,12 +59,12 @@ func TestEditPoolConfig(t *testing.T) { vpoolKeeper, _, ctx := getKeeper(t) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpoolStart.QuoteAssetReserve, vpoolStart.BaseAssetReserve, vpoolStart.Config, )) - exists := vpoolKeeper.ExistsPool(ctx, asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD)) + exists := vpoolKeeper.ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) require.True(t, exists) return vpoolKeeper, ctx } @@ -190,7 +190,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool + pricefeed active", vpool: types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -204,7 +204,7 @@ func TestGetPoolPrices(t *testing.T) { shouldCreateVpool: true, mockIndexPrice: sdk.NewDec(99), expectedPoolPrices: types.PoolPrices{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.NewDec(99).String(), @@ -215,7 +215,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool active, but no index price", vpool: types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -230,7 +230,7 @@ func TestGetPoolPrices(t *testing.T) { mockIndexPrice: sdk.OneDec().Neg(), oracleKeeperErr: fmt.Errorf("No index price"), expectedPoolPrices: types.PoolPrices{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.OneDec().Neg().String(), @@ -241,7 +241,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "vpool doesn't exist", vpool: types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ @@ -294,7 +294,7 @@ func TestGetPoolPrices(t *testing.T) { } func TestEditSwapInvariant(t *testing.T) { - pair := asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD) + pair := asset.Registry.Pair(denoms.NIBI, denoms.NUSD) vpoolStart := types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(10 * common.Precision), diff --git a/x/vpool/keeper/prices_test.go b/x/vpool/keeper/prices_test.go index 02c6d4d9f..d5add58e4 100644 --- a/x/vpool/keeper/prices_test.go +++ b/x/vpool/keeper/prices_test.go @@ -28,14 +28,14 @@ func TestGetMarkPrice(t *testing.T) { }{ { name: "correctly fetch underlying price", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(1), expectedPrice: sdk.NewDec(40000), }, { name: "complex price", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(2_489_723_947), baseAssetReserve: sdk.NewDec(34_597_234), expectedPrice: sdk.MustNewDecFromStr("71.963092396345904415"), @@ -82,7 +82,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), baseAmount: sdk.ZeroDec(), @@ -91,7 +91,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -100,7 +100,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -109,7 +109,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("1000"), @@ -165,7 +165,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), quoteAmount: sdk.ZeroDec(), @@ -174,7 +174,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -183,7 +183,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -192,7 +192,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(1000), @@ -254,22 +254,22 @@ func TestCalcTwap(t *testing.T) { // expected price: ((95/10 * (35 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 10) + 100/1 * (10 - 5)) / (5 + 10 + 10 + 5) { name: "spot price twap calc, t=[5,35]", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -285,22 +285,22 @@ func TestCalcTwap(t *testing.T) { // expected price: (95/10 * (30 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 10)) / (10 + 10) { name: "spot price twap calc, t=[10,30]", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -316,22 +316,22 @@ func TestCalcTwap(t *testing.T) { // expected price: (95/10 * (35 - 30) + 85/10 * (30 - 20) + 90/10 * (20 - 11)) / (5 + 10 + 9) { name: "spot price twap calc, t=[11,35]", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -349,7 +349,7 @@ func TestCalcTwap(t *testing.T) { // expected price: 100/1 { name: "spot price twap calc, t=[0,0]", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{}, currentBlockTime: time.UnixMilli(0), currentBlockHeight: 1, @@ -363,16 +363,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((7.5 - 300/(40 + 10)) * (30 - 20) + (10 - 300/(30 + 10)) * (20 - 10)) / (10 + 10) { name: "quote asset swap twap calc, add to pool, t=[10,30]", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(30), time.UnixMilli(10), ), types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.MustNewDecFromStr("7.5"), sdk.NewDec(40), time.UnixMilli(20), @@ -392,16 +392,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((12 - 600/(50 - 10)) * (30 - 20) + (10 - 600/(60 - 10)) * (20 - 10)) / (10 + 10) { name: "quote asset swap twap calc, remove from pool, t=[10,30]", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(12), sdk.NewDec(50), time.UnixMilli(20), @@ -417,10 +417,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: quote asset reserve = asset amount", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(20), time.UnixMilli(20), @@ -440,16 +440,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((60 - 600/(10 + 10)) * (20 - 10) + (30 - 600/(20 + 10)) * (30 - 20)) / (10 + 10) { name: "base asset swap twap calc, add to pool, t=[10,30]", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(20), sdk.NewDec(30), time.UnixMilli(20), @@ -469,16 +469,16 @@ func TestCalcTwap(t *testing.T) { // expected price: ((60 - 600/(10 - 2)) * (20 - 10) + (75 - 600/(8 - 2)) * (30 - 20)) / (10 + 10) { name: "base asset swap twap calc, remove from pool, t=[10,30]", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(8), sdk.NewDec(75), time.UnixMilli(20), @@ -494,10 +494,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: base asset reserve = asset amount", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(20), @@ -541,7 +541,7 @@ func TestCalcTwap(t *testing.T) { for _, snapshot := range tc.reserveSnapshots { ctx = ctx.WithBlockTime(time.UnixMilli(snapshot.TimestampMs)) snapshot := types.NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), snapshot.BaseAssetReserve, snapshot.QuoteAssetReserve, ctx.BlockTime(), diff --git a/x/vpool/keeper/query_server_test.go b/x/vpool/keeper/query_server_test.go index d80c4ba7a..9dd7493ff 100644 --- a/x/vpool/keeper/query_server_test.go +++ b/x/vpool/keeper/query_server_test.go @@ -25,7 +25,7 @@ func TestQueryReserveAssets(t *testing.T) { t.Log("initialize vpool") pool := types.Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1 * common.Precision), BaseAssetReserve: sdk.NewDec(1000), Config: types.VpoolConfig{ @@ -42,7 +42,7 @@ func TestQueryReserveAssets(t *testing.T) { resp, err := queryServer.ReserveAssets( sdk.WrapSDKContext(ctx), &types.QueryReserveAssetsRequest{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), }, ) @@ -59,7 +59,7 @@ func TestQueryAllPools(t *testing.T) { queryServer := NewQuerier(vpoolKeeper) t.Log("initialize vpool") - pair := asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD) + pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) pool := &types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(1 * common.Precision), diff --git a/x/vpool/keeper/snapshot_test.go b/x/vpool/keeper/snapshot_test.go index cbd69aa52..4fef02fdd 100644 --- a/x/vpool/keeper/snapshot_test.go +++ b/x/vpool/keeper/snapshot_test.go @@ -26,7 +26,7 @@ func TestGetSnapshotPrice(t *testing.T) { }{ { name: "spot price calc", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(2), twapCalcOption: types.TwapCalcOption_SPOT, @@ -34,7 +34,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap add to pool calc", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_QUOTE_ASSET_SWAP, @@ -44,7 +44,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap remove from pool calc", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_QUOTE_ASSET_SWAP, @@ -54,7 +54,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap add to pool calc", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_BASE_ASSET_SWAP, @@ -64,7 +64,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap remove from pool calc", - pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(3_000), baseAssetReserve: sdk.NewDec(1_000), twapCalcOption: types.TwapCalcOption_BASE_ASSET_SWAP, diff --git a/x/vpool/simulation/genesis.go b/x/vpool/simulation/genesis.go index 163cc8ef4..5a5e4b67a 100644 --- a/x/vpool/simulation/genesis.go +++ b/x/vpool/simulation/genesis.go @@ -24,7 +24,7 @@ func RandomizedGenState(simState *module.SimulationState) { vpoolGenesis := types.GenesisState{ Vpools: []types.Vpool{ { - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(10e12).Add(simtypes.RandomDecAmount(simState.Rand, sdk.NewDec(10e12))), BaseAssetReserve: sdk.NewDec(10e12).Add(simtypes.RandomDecAmount(simState.Rand, sdk.NewDec(10e12))), Config: types.VpoolConfig{ diff --git a/x/vpool/types/gov_test.go b/x/vpool/types/gov_test.go index fcd616255..f4267721e 100644 --- a/x/vpool/types/gov_test.go +++ b/x/vpool/types/gov_test.go @@ -146,7 +146,7 @@ func TestMarshalProposalEditPoolConfig(t *testing.T) { proposal := EditPoolConfigProposal{ Title: "Edit vpool config for NIBI:NUSD", Description: "I want to take 100x leverage on my NIBI", - Pair: asset.AssetRegistry.Pair(denoms.NIBI, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), Config: VpoolConfig{ MaxLeverage: sdk.MustNewDecFromStr("100"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), diff --git a/x/vpool/types/pool_test.go b/x/vpool/types/pool_test.go index a66ce1423..636fdc8ea 100644 --- a/x/vpool/types/pool_test.go +++ b/x/vpool/types/pool_test.go @@ -506,7 +506,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "happy path", Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -515,7 +515,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil base", Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -524,7 +524,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero base", Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -533,7 +533,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil quote", Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.Dec{}, }, @@ -542,7 +542,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero quote", Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.ZeroDec(), }, @@ -568,7 +568,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "zero fluctuation limit ratio", pool: Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -584,7 +584,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "lower limit of fluctuation limit", pool: Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(999), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -600,7 +600,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "upper limit of fluctuation limit", pool: Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1001), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -616,7 +616,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "under fluctuation limit", pool: Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(998), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -632,7 +632,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "over fluctuation limit", pool: Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -651,7 +651,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { snapshot := NewReserveSnapshot( - asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec(), sdk.NewDec(1000), time.Now(), @@ -670,7 +670,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "happy path", vpool: Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10), QuoteAssetReserve: sdk.NewDec(10_000), }, @@ -679,7 +679,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid base", vpool: Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.NewDec(500), }, @@ -688,7 +688,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid quote", vpool: Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.Dec{}, }, @@ -697,7 +697,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative quote", vpool: Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.NewDec(-500), }, @@ -706,7 +706,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative base", vpool: Vpool{ - Pair: asset.AssetRegistry.Pair(denoms.BTC, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(-500), QuoteAssetReserve: sdk.NewDec(500), }, diff --git a/x/vpool/types/snapshot_test.go b/x/vpool/types/snapshot_test.go index e78ce4486..d27dcc6fc 100644 --- a/x/vpool/types/snapshot_test.go +++ b/x/vpool/types/snapshot_test.go @@ -21,7 +21,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "happy path", snapshot: ReserveSnapshot{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.OneDec(), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -41,7 +41,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "base asset negative", snapshot: ReserveSnapshot{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(-1), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -51,7 +51,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "quote asset negative", snapshot: ReserveSnapshot{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.NewDec(-1), TimestampMs: time.Now().UnixMilli(), @@ -62,7 +62,7 @@ func TestSnapshotValidate(t *testing.T) { name: "timestamp lower than smallest UTC ('0001-01-01 00:00:00 +0000 UTC')", // see time.UnixMilli(-62135596800000).UTC()) snapshot: ReserveSnapshot{ - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.ZeroDec(), TimestampMs: -62135596800000 - 1, diff --git a/x/wasm/cli/cli_test.go b/x/wasm/cli/cli_test.go index 9f9faf542..d49836cf2 100644 --- a/x/wasm/cli/cli_test.go +++ b/x/wasm/cli/cli_test.go @@ -50,7 +50,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: asset.AssetRegistry.Pair(denoms.ETH, denoms.NUSD), + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{