From ab96d898eea7db1de23bc05babe4be95fa8dba0c Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Wed, 25 Jan 2023 19:47:40 -0500 Subject: [PATCH] feat: asset registry (#1158) * feat: create asset registry * refactor: move denoms to separate file * refactor: use AssetRegistry instead of hard-coded constants * chore: update changelog * refactor(denom): move denoms to separate package * 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> * refactor: remove redundant Denom name * refactor: AssetRegistry in asset package * refactor: rename AssetRegistry to Registry Co-authored-by: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> --- CHANGELOG.md | 5 + cmd/nibid/cmd/testnet.go | 10 +- simapp/testapp.go | 8 +- x/common/asset/registry.go | 81 ++++ x/common/asset/registry_test.go | 82 ++++ x/common/common.go | 31 +- x/common/common_test.go | 11 +- x/common/denoms/denoms.go | 20 + x/common/error_test.go | 6 +- x/common/set.go | 36 -- x/common/set/set.go | 36 ++ x/common/{ => set}/set_test.go | 17 +- 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 | 456 +++++++++--------- x/dex/keeper/swap_test.go | 68 +-- x/dex/simulation/operations.go | 7 +- x/dex/types/params.go | 9 +- x/oracle/keeper/ballot_test.go | 34 +- x/oracle/keeper/keeper_test.go | 6 +- x/oracle/keeper/msg_server_test.go | 21 +- x/oracle/keeper/querier_test.go | 46 +- x/oracle/keeper/reward_test.go | 10 +- x/oracle/keeper/slash_test.go | 42 +- x/oracle/keeper/tally_fuzz_test.go | 14 +- x/oracle/keeper/test_utils.go | 11 +- x/oracle/keeper/update_exchange_rates_test.go | 122 ++--- x/oracle/simulation/decoder_test.go | 7 +- x/oracle/simulation/genesis.go | 12 +- x/oracle/simulation/operations.go | 4 +- x/oracle/types/ballot_test.go | 29 +- x/oracle/types/msgs_test.go | 5 +- x/oracle/types/params.go | 10 +- x/perp/client/cli/cli_test.go | 116 ++--- x/perp/genesis_test.go | 7 +- x/perp/keeper/calc_test.go | 4 +- x/perp/keeper/calc_unit_test.go | 26 +- .../keeper/clearing_house_integration_test.go | 86 ++-- x/perp/keeper/clearing_house_unit_test.go | 138 +++--- x/perp/keeper/grpc_query_test.go | 68 +-- x/perp/keeper/hooks_test.go | 19 +- x/perp/keeper/liquidate_unit_test.go | 189 ++++---- x/perp/keeper/margin_test.go | 18 +- x/perp/keeper/margin_unit_test.go | 88 ++-- x/perp/keeper/msg_server_test.go | 90 ++-- x/perp/simulation/genesis.go | 5 +- x/perp/simulation/operations.go | 30 +- x/perp/types/msgs_test.go | 10 +- x/stablecoin/abci.go | 5 +- x/stablecoin/abci_test.go | 16 +- x/stablecoin/client/cli/cli_test.go | 30 +- x/stablecoin/genesis_test.go | 4 +- x/stablecoin/keeper/collateral_ratio.go | 24 +- x/stablecoin/keeper/collateral_ratio_test.go | 212 ++++---- x/stablecoin/keeper/keeper.go | 4 +- x/stablecoin/keeper/mint_burn_stable.go | 16 +- x/stablecoin/keeper/mint_burn_stable_test.go | 134 ++--- 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 | 15 +- x/vpool/client/cli/cli_test.go | 26 +- x/vpool/keeper/keeper_test.go | 104 ++-- x/vpool/keeper/pool_state_test.go | 24 +- x/vpool/keeper/prices_test.go | 82 ++-- x/vpool/keeper/query_server_test.go | 8 +- x/vpool/keeper/snapshot_test.go | 12 +- x/vpool/simulation/genesis.go | 5 +- x/vpool/types/gov_test.go | 4 +- x/vpool/types/pool_test.go | 34 +- x/vpool/types/snapshot_test.go | 10 +- x/wasm/cli/cli_test.go | 6 +- 80 files changed, 1680 insertions(+), 1424 deletions(-) create mode 100644 x/common/asset/registry.go create mode 100644 x/common/asset/registry_test.go create mode 100644 x/common/denoms/denoms.go 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 7900faf36..02c698d93 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 @@ -60,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/cmd/nibid/cmd/testnet.go b/cmd/nibid/cmd/testnet.go index a1418b7a0..f1d4cb036 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.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(common.DenomNUSD, accTokens), - sdk.NewCoin(common.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(common.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 c633971b9..0056e7fc4 100644 --- a/simapp/testapp.go +++ b/simapp/testapp.go @@ -16,6 +16,8 @@ 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" ) // NewTestNibiruApp creates an application instance ('app.NibiruApp') with an in-memory @@ -36,8 +38,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, 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)) return newNibiruApp, ctx @@ -122,7 +124,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.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 new file mode 100644 index 000000000..0efb23afb --- /dev/null +++ b/x/common/asset/registry.go @@ -0,0 +1,81 @@ +package asset + +import ( + "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/denoms" + "github.com/NibiruChain/nibiru/x/common/set" +) + +type registry map[string]set.Set[string] + +var Registry registry + +func init() { + // map of base asset to supported quote assets + // quote assets are usually stables + 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), + 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), + } +} + +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)) + } + } + + return "" +} + +// Returns all supported base denoms +func (r registry) BaseDenoms() set.Set[string] { + baseSet := make(set.Set[string]) + for d := range r { + baseSet.Add(d) + } + return baseSet +} + +// Returns all supported quote denoms +func (r registry) QuoteDenoms() set.Set[string] { + quoteSet := make(set.Set[string]) + for base := range r { + for q := range r[base] { + quoteSet.Add(q) + } + } + return quoteSet +} + +// Checks if the provided denom is a supported base denom +func (r registry) IsSupportedBaseDenom(denom string) bool { + _, ok := r[denom] + return ok +} + +// Checks if the provided denom is a supported quote denom +func (r registry) IsSupportedQuoteDenom(denom string) bool { + return r.QuoteDenoms().Has(denom) +} + +// Checks if the provided denom is a supported denom +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 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/common.go b/x/common/common.go index de84233a6..a540b6d83 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) ) @@ -126,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/common_test.go b/x/common/common_test.go index f059322ec..920c28863 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.NIBI, 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.NIBI, common.PairSeparator, denoms.NUSD, + common.PairSeparator, denoms.USDC), common.ErrInvalidTokenPair, }, { "different separator", - fmt.Sprintf("%s%s%s", common.DenomNIBI, "%", common.DenomNUSD), + fmt.Sprintf("%s%s%s", denoms.NIBI, "%", denoms.NUSD), common.ErrInvalidTokenPair, }, { "correct pair", - fmt.Sprintf("%s%s%s", common.DenomNIBI, common.PairSeparator, common.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 new file mode 100644 index 000000000..5256f86c0 --- /dev/null +++ b/x/common/denoms/denoms.go @@ -0,0 +1,20 @@ +package denoms + +const ( // stablecoins + USDC = "uusdc" + NUSD = "unusd" + USD = "uusd" + USDT = "uusdt" +) + +const ( // volatile assets + 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 b65bbf8d0..39ed99cd7 100644 --- a/x/common/error_test.go +++ b/x/common/error_test.go @@ -9,6 +9,8 @@ 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" ) @@ -86,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.Pair_USDC_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{common.Pair_BTC_NUSD, common.Pair_ETH_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/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/dex/client/testutil/cli_test.go b/x/dex/client/testutil/cli_test.go index 2b678adfa..31841009d 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.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(common.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 c29456818..19d401208 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.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 ba8e9b838..70b1cbf87 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.NUSD, 100), ), coinsToSpend: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 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.NUSD, 100), ), expectedError: sdkerrors.ErrInsufficientFunds, }, diff --git a/x/dex/keeper/grpc_query_test.go b/x/dex/keeper/grpc_query_test.go index 11a0aeeec..bd30e7c85 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.NUSD, 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.USDC, 100), ), /*shares=*/ 100, ), mock.DexPool( /*poolId=*/ 2, /*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, ), mock.DexPool( /*poolId=*/ 3, /*assets=*/ sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 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.NIBI, 1e18), + sdk.NewInt64Coin(denoms.NUSD, 1e18), + sdk.NewInt64Coin(denoms.USDC, 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.NUSD, 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.NUSD, 100), ), /*shares=*/ 100, ), - tokenInDenom: common.DenomNUSD, + tokenInDenom: denoms.NUSD, 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.NUSD, 200), ), /*shares=*/ 100, ), - tokenInDenom: common.DenomNUSD, + tokenInDenom: denoms.NUSD, 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.NUSD, 200), ), /*shares=*/ 100, ), tokenInDenom: "unibi", - tokenOutDenom: common.DenomNUSD, + tokenOutDenom: denoms.NUSD, 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.NUSD, 100), ), /*shares=*/ 100, ), - tokenIn: sdk.NewInt64Coin(common.DenomNUSD, 100), + tokenIn: sdk.NewInt64Coin(denoms.NUSD, 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.NUSD, 4684496849), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 586848), - tokenOutDenom: common.DenomNUSD, + tokenOutDenom: denoms.NUSD, // https://www.wolframalpha.com/input?i=4684496849+-+%2834844867+*+4684496849+%2F+%2834844867%2B586848%29+%29 - expectedTokenOut: sdk.NewInt64Coin(common.DenomNUSD, 77588330), + expectedTokenOut: sdk.NewInt64Coin(denoms.NUSD, 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.NUSD, 100), ), /*shares=*/ 100, ), tokenOut: sdk.NewInt64Coin("unibi", 50), - tokenInDenom: common.DenomNUSD, + tokenInDenom: denoms.NUSD, // there's a swap fee that we take the ceiling of to round int - expectedTokenIn: sdk.NewInt64Coin(common.DenomNUSD, 101), + expectedTokenIn: sdk.NewInt64Coin(denoms.NUSD, 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.NUSD, 4684496849), ), /*shares=*/ 100, ), - tokenOut: sdk.NewInt64Coin(common.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), @@ -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.NUSD, 100), ), /*shares=*/ 100, ), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 100), - sdk.NewInt64Coin(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 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.NUSD, 100), ), /*shares=*/ 100, ), tokensIn: sdk.NewCoins( sdk.NewInt64Coin("unibi", 50), - sdk.NewInt64Coin(common.DenomNUSD, 75), + sdk.NewInt64Coin(denoms.NUSD, 75), ), expectedPoolSharesOut: sdk.NewIntFromUint64(50), expectedRemCoins: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 25), + sdk.NewInt64Coin(denoms.NUSD, 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.NUSD, 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.NUSD, 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.NUSD, 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.NUSD, 49), ), }, } diff --git a/x/dex/keeper/keeper_test.go b/x/dex/keeper/keeper_test.go index f630607d5..fd004b3e5 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.BTC, sdk.NewInt(1000)), Weight: sdk.NewInt(1), }, { - Token: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1000)), + Token: sdk.NewCoin(denoms.NUSD, 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.NIBI, 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.NIBI, 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.NIBI, 1)) err = simapp.FundAccount(app.BankKeeper, ctx, userAddr, sdk.NewCoins( - sdk.NewCoin(common.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 a3db08f84..46c04018c 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.USDC, 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.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(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.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(common.DenomNIBI, 1), + Token: sdk.NewInt64Coin(denoms.NIBI, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.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(common.DenomNUSD, 1), + Token: sdk.NewInt64Coin(denoms.NUSD, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 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.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(common.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(common.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(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.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(common.DenomNIBI, 1), + Token: sdk.NewInt64Coin(denoms.NIBI, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.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(common.DenomNUSD, 1), + Token: sdk.NewInt64Coin(denoms.NUSD, 1), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1), + Token: sdk.NewInt64Coin(denoms.USDC, 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.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(common.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.NUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.USDC, 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.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(common.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.NUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.USDC, 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.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(common.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.NUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.USDC, 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.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(common.DenomNUSD, 1_000), + Token: sdk.NewInt64Coin(denoms.NUSD, 1_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin(common.DenomUSDC, 1_000), + Token: sdk.NewInt64Coin(denoms.USDC, 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.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(common.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(common.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(common.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(common.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: common.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: common.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 85d2c1a3a..61cc57dc7 100644 --- a/x/dex/keeper/swap_test.go +++ b/x/dex/keeper/swap_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" @@ -13,7 +14,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" ) @@ -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(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 100), - tokenOutDenom: common.DenomNUSD, - expectedTokenOut: sdk.NewInt64Coin(common.DenomNUSD, 50), + tokenOutDenom: denoms.NUSD, + expectedTokenOut: sdk.NewInt64Coin(denoms.NUSD, 50), expectedUserFinalFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 50), + sdk.NewInt64Coin(denoms.NUSD, 50), ), expectedFinalPool: mock.DexPool( /*poolId=*/ 1, /*assets=*/ sdk.NewCoins( sdk.NewInt64Coin("unibi", 200), - sdk.NewInt64Coin(common.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(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("unibi", 100), - tokenOutDenom: common.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(common.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(common.DenomNUSD, 100), + sdk.NewInt64Coin(denoms.NUSD, 100), ), /*shares=*/ 100, ), tokenIn: sdk.NewInt64Coin("foo", 100), - tokenOutDenom: common.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(common.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(common.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(common.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(common.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(common.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 e12a0ff0f..f93ff6260 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" ) @@ -364,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(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.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 ba2668875..6e0495e9f 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.NIBI, 1000*common.Precision)), // 1000 NIBI WhitelistedAsset: []string{ - common.DenomNIBI, - common.DenomUSDC, - common.DenomNUSD, + denoms.NIBI, + denoms.USDC, + denoms.NUSD, }, } } diff --git a/x/oracle/keeper/ballot_test.go b/x/oracle/keeper/ballot_test.go index 6bf9d3bd6..1d5f8bf63 100644 --- a/x/oracle/keeper/ballot_test.go +++ b/x/oracle/keeper/ballot_test.go @@ -11,6 +11,8 @@ 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,14 +34,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), 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), 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), 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 { @@ -78,11 +80,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[asset.Registry.Pair(denoms.BTC, denoms.NUSD)]) + sort.Sort(ballotMap[asset.Registry.Pair(denoms.ETH, denoms.NUSD)]) - require.Equal(t, btcBallot, ballotMap[common.Pair_BTC_NUSD]) - require.Equal(t, ethBallot, ballotMap[common.Pair_ETH_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) { @@ -103,14 +105,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), 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), 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), 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 fcdcb4cf4..a758fa896 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -6,6 +6,8 @@ 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" @@ -30,8 +32,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, + 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 07f197d5d..d14b67c64 100644 --- a/x/oracle/keeper/msg_server_test.go +++ b/x/oracle/keeper/msg_server_test.go @@ -3,7 +3,8 @@ 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" @@ -19,7 +20,7 @@ func TestMsgServer_FeederDelegation(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate, }, } @@ -86,43 +87,43 @@ func TestMsgServer_AggregatePrevoteVote(t *testing.T) { salt := "1" exchangeRates := types.ExchangeRateTuples{ { - Pair: common.Pair_NIBI_NUSD, + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } otherExchangeRate := types.ExchangeRateTuples{ { - Pair: common.Pair_NIBI_NUSD, + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.29"), }, { - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("0.27"), }, } unintendedExchangeRateStr := types.ExchangeRateTuples{ { - Pair: common.Pair_NIBI_NUSD, + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: sdk.MustNewDecFromStr("1000.23"), }, { - Pair: common.Pair_ETH_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 99c8c41bf..0daf1e47e 100644 --- a/x/oracle/keeper/querier_test.go +++ b/x/oracle/keeper/querier_test.go @@ -11,6 +11,8 @@ 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" ) @@ -31,7 +33,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, asset.Registry.Pair(denoms.ETH, denoms.NUSD), rate) // empty request _, err := querier.ExchangeRate(ctx, nil) @@ -39,7 +41,7 @@ func TestQueryExchangeRate(t *testing.T) { // Query to grpc res, err := querier.ExchangeRate(ctx, &types.QueryExchangeRateRequest{ - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), }) require.NoError(t, err) require.Equal(t, rate, res.ExchangeRate) @@ -71,15 +73,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, 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: common.Pair_BTC_NUSD, ExchangeRate: rate}, - {Pair: common.Pair_ETH_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) } @@ -89,12 +91,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, asset.Registry.Pair(denoms.BTC, denoms.NUSD), rate) - _, err := querier.ExchangeRateTwap(ctx, &types.QueryExchangeRateRequest{Pair: common.Pair_ETH_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: common.Pair_BTC_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) } @@ -114,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.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), priceSnapshots: []types.PriceSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("90000.0"), TimestampMs: time.UnixMilli(1).UnixMilli(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("9.0"), TimestampMs: time.UnixMilli(10).UnixMilli(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("8.5"), TimestampMs: time.UnixMilli(20).UnixMilli(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Price: sdk.MustNewDecFromStr("9.5"), TimestampMs: time.UnixMilli(30).UnixMilli(), }, @@ -166,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.Pair_BTC_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: common.Pair_BTC_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, @@ -186,17 +188,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, 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{ - common.Pair_BTC_NUSD, - common.Pair_ETH_NUSD, - common.Pair_NIBI_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 c80419689..a22d345c4 100644 --- a/x/oracle/keeper/reward_test.go +++ b/x/oracle/keeper/reward_test.go @@ -8,6 +8,8 @@ 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" "github.com/NibiruChain/nibiru/x/oracle/types" @@ -57,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.Pair_NIBI_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++ { @@ -65,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.Pair_NIBI_NUSD, + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), ExchangeRate: randomExchangeRate, }}, valIndex) } @@ -82,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.Pair_NIBI_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, common.Pair_NIBI_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 3bcb90163..7c053b399 100644 --- a/x/oracle/keeper/slash_test.go +++ b/x/oracle/keeper/slash_test.go @@ -11,6 +11,8 @@ 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" types3 "github.com/NibiruChain/nibiru/x/oracle/types" @@ -90,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.Pair_NIBI_NUSD} + params.Whitelist = []common.AssetPair{asset.Registry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) - input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, common.Pair_NIBI_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) @@ -102,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.Pair_NIBI_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: common.Pair_NIBI_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: common.Pair_NIBI_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)) @@ -119,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.Pair_NIBI_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: common.Pair_NIBI_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: common.Pair_NIBI_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) @@ -144,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.Pair_NIBI_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: common.Pair_NIBI_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)) @@ -158,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.Pair_NIBI_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: common.Pair_NIBI_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) @@ -171,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.Pair_NIBI_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, common.Pair_NIBI_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: common.Pair_NIBI_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)) @@ -194,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.Pair_NIBI_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, common.Pair_NIBI_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) @@ -210,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.Pair_NIBI_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: common.Pair_NIBI_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: common.Pair_NIBI_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 804512bbb..d6ac2d2ee 100644 --- a/x/oracle/keeper/tally_fuzz_test.go +++ b/x/oracle/keeper/tally_fuzz_test.go @@ -11,6 +11,9 @@ 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" "github.com/NibiruChain/nibiru/x/testutil" ) @@ -131,11 +134,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}, + 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}, }, - common.Pair_ETH_NUSD: types.ExchangeRateBallots{ - {Pair: common.Pair_BTC_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}, }, }, }, @@ -220,7 +223,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) diff --git a/x/oracle/keeper/test_utils.go b/x/oracle/keeper/test_utils.go index 282c3d867..ba5ec30cf 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.NIBI, 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.NIBI, 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.NIBI 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.NIBI, 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.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 b85d69d59..7c5541ed7 100644 --- a/x/oracle/keeper/update_exchange_rates_test.go +++ b/x/oracle/keeper/update_exchange_rates_test.go @@ -15,6 +15,8 @@ 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" "github.com/NibiruChain/nibiru/x/oracle/types" @@ -23,7 +25,7 @@ import ( func TestOracleThreshold(t *testing.T) { exchangeRates := types.ExchangeRateTuples{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: randomExchangeRate, }, } @@ -120,15 +122,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, asset.Registry.Pair(denoms.NIBI, denoms.NUSD), 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: 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, common.Pair_NIBI_NUSD) + _, err := input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) require.Error(t, err) } @@ -142,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.Pair_BTC_NUSD}}.ToString() + {ExchangeRate: decExchangeRate, Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD)}}.ToString() require.NoError(t, err) salt := fmt.Sprintf("%d", i) @@ -161,7 +163,7 @@ func TestOracleTally(t *testing.T) { } vote := types.NewExchangeRateBallot( - decExchangeRate, common.Pair_BTC_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 @@ -221,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.Pair_BTC_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) @@ -230,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.Pair_BTC_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, common.Pair_BTC_NUSD) + _, err = input.OracleKeeper.ExchangeRates.Get(input.Ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) require.NoError(t, err) } @@ -246,13 +248,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: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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: 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, common.Pair_BTC_NUSD, rewardAllocation, 1) + keeper.AllocateRewards(t, input, asset.Registry.Pair(denoms.BTC, denoms.NUSD), rewardAllocation, 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -260,32 +262,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.NIBI).TruncateInt().String()) } 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{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, common.Pair_NIBI_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: common.Pair_NIBI_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: common.Pair_NIBI_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: common.Pair_NIBI_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) @@ -295,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.Pair_NIBI_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: common.Pair_NIBI_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: common.Pair_NIBI_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) @@ -325,7 +327,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.Gov, rewardAmt))) require.NoError(t, err) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -337,11 +339,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.Gov).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.Gov).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.Gov).TruncateInt()) } */ @@ -355,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.Pair_ETH_NUSD, ExchangeRate: ethStableExchangeRate}, {Pair: common.Pair_NIBI_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: common.Pair_ETH_NUSD, ExchangeRate: ethStableExchangeRate}, {Pair: common.Pair_NIBI_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: common.Pair_NIBI_NUSD, ExchangeRate: govStableExchangeRate}, {Pair: common.Pair_BTC_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, common.Pair_ETH_NUSD, sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, common.Pair_NIBI_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) @@ -403,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.Pair_ETH_NUSD, ExchangeRate: ethStableRate1}, {Pair: common.Pair_NIBI_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: common.Pair_ETH_NUSD, ExchangeRate: ethStableRate2}, {Pair: common.Pair_NIBI_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: common.Pair_ETH_NUSD, ExchangeRate: govStableRate3}, {Pair: common.Pair_NIBI_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) @@ -427,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.Pair_NIBI_NUSD, ExchangeRate: govStableRate1}, {Pair: common.Pair_ETH_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: common.Pair_NIBI_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: common.Pair_NIBI_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: common.Pair_NIBI_NUSD, ExchangeRate: govStableRate2}, {Pair: common.Pair_ETH_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: common.Pair_NIBI_NUSD, ExchangeRate: govStableRate2}, {Pair: common.Pair_ETH_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, common.Pair_ETH_NUSD, sdk.NewCoins(ethStableRewards), 1) - keeper.AllocateRewards(t, input, common.Pair_NIBI_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, common.Pair_NIBI_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, common.Pair_ETH_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) @@ -485,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.Pair_NIBI_NUSD) + input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) // 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: 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{common.Pair_NIBI_NUSD, common.Pair_BTC_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) @@ -503,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.Pair_BTC_NUSD, common.Pair_NIBI_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: 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: 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{common.Pair_NIBI_NUSD} + params.Whitelist = []common.AssetPair{asset.Registry.Pair(denoms.NIBI, denoms.NUSD)} input.OracleKeeper.SetParams(input.Ctx, params) oracle.EndBlocker(input.Ctx, input.OracleKeeper) @@ -520,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.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{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: 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: 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) @@ -542,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.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, 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, common.Pair_NIBI_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 6bf419996..9c8d06212 100644 --- a/x/oracle/simulation/decoder_test.go +++ b/x/oracle/simulation/decoder_test.go @@ -4,7 +4,8 @@ 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" "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.Pair_NIBI_NUSD, ExchangeRate: sdk.NewDecWithPrec(1234, 1)}, - {Pair: common.Pair_ETH_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 5d94b2fdb..d36f6e92a 100644 --- a/x/oracle/simulation/genesis.go +++ b/x/oracle/simulation/genesis.go @@ -8,6 +8,8 @@ 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" "github.com/cosmos/cosmos-sdk/types/module" @@ -97,17 +99,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, + 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: common.Pair_BTC_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 c9c8e8a66..6cf11ed98 100644 --- a/x/oracle/simulation/operations.go +++ b/x/oracle/simulation/operations.go @@ -7,6 +7,8 @@ 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" "github.com/cosmos/cosmos-sdk/codec" @@ -30,7 +32,7 @@ const ( ) var ( - whitelist = []common.AssetPair{common.Pair_BTC_NUSD, common.Pair_ETH_NUSD, common.Pair_NIBI_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 9581ea1eb..1c8ce12fa 100644 --- a/x/oracle/types/ballot_test.go +++ b/x/oracle/types/ballot_test.go @@ -6,7 +6,8 @@ import ( "sort" "strconv" - "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/common/asset" + "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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.NewDec(1600), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), ExchangeRate: sdk.ZeroDec(), Power: 100, }, { Voter: sdk.ValAddress(secp256k1.GenPrivKey().PubKey().Address()), - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_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, common.Pair_BTC_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), common.Pair_BTC_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(), common.Pair_BTC_NUSD, valAddr, 0)) + cb = append(cb, types.NewExchangeRateBallot(sdk.ZeroDec(), asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_ETH_NUSD, + asset.Registry.Pair(denoms.ETH, denoms.NUSD), valAccAddrs[i], power, ) @@ -153,7 +154,7 @@ func TestPBPower(t *testing.T) { faceValAddr := sdk.ValAddress(pubKey.Address()) fakeVote := types.NewExchangeRateBallot( sdk.OneDec(), - common.Pair_ETH_NUSD, + asset.Registry.Pair(denoms.ETH, denoms.NUSD), faceValAddr, 0, ) @@ -224,7 +225,7 @@ func TestPBWeightedMedian(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDec(int64(input)), - common.Pair_ETH_NUSD, + asset.Registry.Pair(denoms.ETH, denoms.NUSD), valAddr, power, ) @@ -291,7 +292,7 @@ func TestPBStandardDeviation(t *testing.T) { vote := types.NewExchangeRateBallot( sdk.NewDecWithPrec(int64(input*base), int64(types.OracleDecPrecision)), - common.Pair_ETH_NUSD, + asset.Registry.Pair(denoms.ETH, denoms.NUSD), valAddr, power, ) @@ -310,12 +311,12 @@ func TestPBStandardDeviationOverflow(t *testing.T) { pb := types.ExchangeRateBallots{types.NewExchangeRateBallot( sdk.ZeroDec(), - common.Pair_ETH_NUSD, + asset.Registry.Pair(denoms.ETH, denoms.NUSD), valAddr, 2, ), types.NewExchangeRateBallot( exchangeRate, - common.Pair_ETH_NUSD, + asset.Registry.Pair(denoms.ETH, denoms.NUSD), valAddr, 1, )} diff --git a/x/oracle/types/msgs_test.go b/x/oracle/types/msgs_test.go index d678ddee6..f85ebfd85 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.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 ac08fe41f..e40f463db 100644 --- a/x/oracle/types/params.go +++ b/x/oracle/types/params.go @@ -7,6 +7,8 @@ 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" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -38,10 +40,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, + 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 4362a8724..201a83aa0 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -16,6 +16,8 @@ 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" perptypes "github.com/NibiruChain/nibiru/x/perp/types" @@ -51,7 +53,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: common.Pair_BTC_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{ @@ -63,7 +65,7 @@ func (s *IntegrationTestSuite) SetupSuite() { }, }, { - Pair: common.Pair_ETH_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{ @@ -81,11 +83,11 @@ func (s *IntegrationTestSuite) SetupSuite() { perpGenesis := perptypes.DefaultGenesis() perpGenesis.PairMetadata = []perptypes.PairMetadata{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), }, { - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, } @@ -94,12 +96,12 @@ func (s *IntegrationTestSuite) SetupSuite() { oracleGenesis := oracletypes.DefaultGenesisState() oracleGenesis.Params.Whitelist = []common.AssetPair{ - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), } 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: 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) @@ -123,56 +125,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.NIBI, 10*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 10*common.Precision), + sdk.NewInt64Coin(denoms.NUSD, 50*common.Precision), ), val, - common.DenomNIBI, + denoms.NIBI, ), ) 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.NIBI, 1000), + sdk.NewInt64Coin(denoms.USDC, 1000), + sdk.NewInt64Coin(denoms.NUSD, 100000), ), val, - common.DenomNIBI, + denoms.NIBI, ), ) 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.NIBI, 1000), + sdk.NewInt64Coin(denoms.USDC, 1000), + sdk.NewInt64Coin(denoms.NUSD, 49*common.Precision), ), val, - common.DenomNIBI, + denoms.NIBI, ), ) 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.NIBI, 1000), + sdk.NewInt64Coin(denoms.USDC, 1000), + sdk.NewInt64Coin(denoms.NUSD, 100000), ), val, - common.DenomNIBI, + denoms.NIBI, ), ) s.NoError( testutilcli.FillWalletFromValidator(user5, - sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000)), + sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 1000)), val, - common.DenomNIBI, + denoms.NIBI, ), ) } @@ -186,25 +188,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, 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, common.Pair_BTC_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, common.Pair_BTC_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", - common.Pair_BTC_NUSD.String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAssetLimit */ "1"}, @@ -213,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.Pair_BTC_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, common.Pair_BTC_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(common.Pair_BTC_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) @@ -236,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.Pair_BTC_NUSD.String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "2", /* quoteAmt */ "1000000", // 10^6 uNUSD /* baseAmtLimit */ "0", @@ -245,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.Pair_BTC_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(common.Pair_BTC_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) @@ -260,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.Pair_BTC_NUSD.String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "100", // 100 uNUSD /* baseAssetLimit */ "1", @@ -269,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.Pair_BTC_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, common.Pair_BTC_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(common.Pair_BTC_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) @@ -291,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.Pair_BTC_NUSD.String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), /* leverage */ "1", /* quoteAmt */ "4000000", // 4*10^6 uNUSD /* baseAssetLimit */ "0", @@ -300,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.Pair_BTC_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(common.Pair_BTC_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) @@ -315,13 +317,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(), + 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, common.Pair_BTC_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) @@ -335,12 +337,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, 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{ - common.Pair_ETH_NUSD.String(), + asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) } @@ -349,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.Pair_BTC_NUSD) + queryResp, err := testutilcli.QueryCumulativePremiumFraction(val.ClientCtx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) s.NoError(err) s.EqualValues(sdk.NewDec(2), queryResp.CumulativePremiumFraction) } @@ -359,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.Pair_BTC_NUSD.String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), "10", // Leverage "1", // Quote asset amount "0.0000001", @@ -370,15 +372,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.Pair_BTC_NUSD.String(), - fmt.Sprintf("%s%s", "100", common.DenomNUSD), + asset.Registry.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.Pair_ETH_NUSD + pair := asset.Registry.Pair(denoms.ETH, denoms.NUSD) // Open a new position s.T().Log("opening a position with user 3....") @@ -410,7 +412,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { { name: "FAIL: position not found", args: []string{ - common.Pair_BTC_NUSD.String(), + asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), fmt.Sprintf("%s%s", "10000", pair.QuoteDenom()), }, expectedCode: 1, @@ -437,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.Pair_ETH_NUSD.String(), + asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), s.users[1].String(), }) s.Contains(err.Error(), collections.ErrNotFound.Error()) @@ -445,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.Pair_ETH_NUSD.String(), + asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), "15", // Leverage "90000", // Quote asset amount "0", @@ -455,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.Pair_ETH_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") @@ -463,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.Pair_ETH_NUSD.String(), + asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), "15", // Leverage "45000000", // Quote asset amount "0", @@ -479,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.Pair_ETH_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 81cc8526b..e80e87b6d 100644 --- a/x/perp/genesis_test.go +++ b/x/perp/genesis_test.go @@ -7,6 +7,8 @@ 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" simapp2 "github.com/NibiruChain/nibiru/simapp" @@ -15,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" ) @@ -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.Pair_NIBI_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: common.Pair_NIBI_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 98ca599ba..93d12c476 100644 --- a/x/perp/keeper/calc_test.go +++ b/x/perp/keeper/calc_test.go @@ -10,6 +10,8 @@ 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" vpooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -28,7 +30,7 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { marginDelta := sdk.OneDec() _, err := nibiruApp.PerpKeeper.CalcRemainMarginWithFundingPayment( ctx, types.Position{ - Pair: common.Pair_NIBI_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 425b2d3c0..37a869749 100644 --- a/x/perp/keeper/calc_unit_test.go +++ b/x/perp/keeper/calc_unit_test.go @@ -4,6 +4,8 @@ import ( "testing" "time" + "github.com/NibiruChain/nibiru/x/common/asset" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -37,9 +39,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, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(false) - pos := types.ZeroPosition(ctx, common.Pair_BTC_NUSD, testutil.AccAddress()) + pos := types.ZeroPosition(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) _, err := k.calcFreeCollateral(ctx, pos) @@ -53,12 +55,12 @@ func TestCalcFreeCollateralErrors(t *testing.T) { k, mocks, ctx := getKeeper(t) mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.Pair_BTC_NUSD).Return(true) + ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.Pair_BTC_NUSD). + GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - pos := types.ZeroPosition(ctx, common.Pair_BTC_NUSD, testutil.AccAddress()) + pos := types.ZeroPosition(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), testutil.AccAddress()) freeCollateral, err := k.calcFreeCollateral(ctx, pos) @@ -150,7 +152,7 @@ func TestCalcFreeCollateralSuccess(t *testing.T) { pos := types.Position{ TraderAddress: testutil.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.positionSize, Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(1000), @@ -159,19 +161,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, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.Pair_BTC_NUSD). + GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.vpoolDirection, sdk.OneDec(), ).Return(tc.positionNotional, nil) mocks.mockVpoolKeeper.EXPECT().GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.vpoolDirection, sdk.OneDec(), 15*time.Minute, @@ -196,13 +198,13 @@ func TestGetLatestCumulativePremiumFraction(t *testing.T) { keeper, _, ctx := getKeeper(t) metadata := &types.PairMetadata{ - Pair: common.Pair_NIBI_NUSD, + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), LatestCumulativePremiumFraction: sdk.NewDec(2), } setPairMetadata(keeper, ctx, *metadata) latestCumulativePremiumFraction, err := keeper. - getLatestCumulativePremiumFraction(ctx, common.Pair_NIBI_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 f4858a48b..fe94695aa 100644 --- a/x/perp/keeper/clearing_house_integration_test.go +++ b/x/perp/keeper/clearing_house_integration_test.go @@ -6,6 +6,8 @@ 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" @@ -44,7 +46,7 @@ func TestOpenPositionSuccess(t *testing.T) { }{ { name: "new long position", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), initialPosition: nil, side: types.Side_BUY, margin: sdk.NewInt(1000), @@ -61,9 +63,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.NUSD, 1020)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -85,9 +87,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.NUSD, 10)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -109,9 +111,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.NUSD, 1060)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -133,7 +135,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.NUSD, 1*common.Precision*common.Precision)), initialPosition: nil, side: types.Side_BUY, margin: sdk.NewInt(47_619_047_619), @@ -150,7 +152,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "new short position", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), initialPosition: nil, side: types.Side_SELL, margin: sdk.NewInt(1000), @@ -167,9 +169,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.NUSD, 1020)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -191,9 +193,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.NUSD, 10)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -215,9 +217,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.NUSD, 1060)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10_000), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -239,7 +241,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.NUSD, 1*common.Precision*common.Precision)), initialPosition: nil, side: types.Side_SELL, margin: sdk.NewInt(47_619_047_619), @@ -267,7 +269,7 @@ func TestOpenPositionSuccess(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - common.Pair_BTC_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{ @@ -279,7 +281,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -294,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.Pair_BTC_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, common.Pair_BTC_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") @@ -315,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.Pair_BTC_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, common.Pair_BTC_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") @@ -330,19 +332,19 @@ 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: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: traderAddr.String(), - Margin: sdk.NewCoin(common.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(common.DenomNUSD, sdk.ZeroInt()), + BadDebt: sdk.NewCoin(denoms.NUSD, sdk.ZeroInt()), MarkPrice: tc.expectedMarkPrice, FundingPayment: sdk.ZeroDec(), - TransactionFee: sdk.NewCoin(common.DenomNUSD, feePoolFee.Add(ecosystemFundFee)), + TransactionFee: sdk.NewCoin(denoms.NUSD, feePoolFee.Add(ecosystemFundFee)), BlockHeight: ctx.BlockHeight(), BlockTimeMs: ctx.BlockTime().UnixMilli(), }) @@ -370,7 +372,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.NUSD, 999)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -381,10 +383,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.NUSD, 999)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.NewDec(1000), OpenNotional: sdk.NewDec(10_000), @@ -399,7 +401,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.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -410,7 +412,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.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -421,7 +423,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.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -432,7 +434,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.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -443,7 +445,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.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -454,7 +456,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.NUSD, 1020)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -465,7 +467,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.NUSD, 1*common.Precision*common.Precision)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, @@ -476,7 +478,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.NUSD, 1*common.Precision*common.Precision)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, @@ -487,7 +489,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.NUSD, 10_000*common.Precision)), poolTradeLimitRatio: sdk.MustNewDecFromStr("0.01"), initialPosition: nil, side: types.Side_BUY, @@ -498,7 +500,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.NUSD, 10_000*common.Precision)), poolTradeLimitRatio: sdk.MustNewDecFromStr("0.01"), initialPosition: nil, side: types.Side_SELL, @@ -519,7 +521,7 @@ func TestOpenPositionError(t *testing.T) { t.Log("initialize vpool") assert.NoError(t, nibiruApp.VpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* tradeLimitRatio */ /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), @@ -533,7 +535,7 @@ func TestOpenPositionError(t *testing.T) { }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -547,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.Pair_BTC_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 1ae921475..195f889c9 100644 --- a/x/perp/keeper/clearing_house_unit_test.go +++ b/x/perp/keeper/clearing_house_unit_test.go @@ -6,6 +6,8 @@ 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" "github.com/cosmos/cosmos-sdk/codec" @@ -116,7 +118,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -132,7 +134,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAmount=*/ sdk.NewDec(10), /*baseLimit=*/ sdk.NewDec(1), @@ -153,7 +155,7 @@ func TestSwapQuoteAssetForBase(t *testing.T) { baseAmount, err := perpKeeper.swapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.side, sdk.NewDec(10), sdk.NewDec(1), @@ -181,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.Pair_BTC_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 @@ -193,7 +195,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(50), @@ -203,7 +205,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -212,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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, ) @@ -255,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.Pair_BTC_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 @@ -267,7 +269,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(101), @@ -277,7 +279,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -285,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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -330,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.Pair_BTC_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 @@ -342,7 +344,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_ADD_TO_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(110), @@ -352,7 +354,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, /*baseAssetAmount=*/ sdk.NewDec(110), ). @@ -360,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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.2"), }) }, @@ -403,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.Pair_BTC_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 @@ -415,7 +417,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(200), @@ -425,7 +427,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -433,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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -476,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.Pair_BTC_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 @@ -488,7 +490,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(100), /*baseAssetLimit=*/ sdk.NewDec(99), @@ -498,7 +500,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -506,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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) }, @@ -552,7 +554,7 @@ func TestIncreasePosition(t *testing.T) { // funding payment causes bad debt initPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_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 @@ -564,7 +566,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ vpooltypes.Direction_REMOVE_FROM_POOL, /*quoteAssetAmount=*/ sdk.NewDec(105), /*baseAssetLimit=*/ sdk.NewDec(100), @@ -574,7 +576,7 @@ func TestIncreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_REMOVE_FROM_POOL, /*baseAssetAmount=*/ sdk.NewDec(100), ). @@ -582,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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("-0.3"), }) }, @@ -656,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.Pair_BTC_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 @@ -664,7 +666,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -683,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.Pair_BTC_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 @@ -691,7 +693,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -710,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.Pair_BTC_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 @@ -718,7 +720,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_ADD_TO_POOL, @@ -739,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.Pair_BTC_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 @@ -747,7 +749,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -766,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.Pair_BTC_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 @@ -774,7 +776,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -793,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.Pair_BTC_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 @@ -801,7 +803,7 @@ func TestClosePositionEntirely(t *testing.T) { BlockNumber: 0, }, pairMetadata: types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }, direction: vpooltypes.Direction_REMOVE_FROM_POOL, @@ -826,7 +828,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -835,7 +837,7 @@ func TestClosePositionEntirely(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ tc.direction, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ tc.quoteAssetLimit, @@ -910,7 +912,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: 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 @@ -945,7 +947,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: 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 @@ -980,7 +982,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: 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 @@ -1017,7 +1019,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: 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 @@ -1052,7 +1054,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: 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 @@ -1087,7 +1089,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: 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 @@ -1122,7 +1124,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1131,7 +1133,7 @@ func TestDecreasePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*quoteAssetDirection=*/ tc.quoteAssetDir, /*quoteAssetAmount=*/ tc.quoteAmountToDecrease, /*baseAssetLimit=*/ tc.exchangedBaseAmount.Abs(), @@ -1140,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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1508,7 +1510,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { t.Log("set up initial position") currentPosition := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: tc.initialPositionSize, Margin: tc.initialPositionMargin, OpenNotional: tc.initialPositionOpenNotional, @@ -1521,7 +1523,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), ). @@ -1530,7 +1532,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.mockBaseDir, /*baseAssetAmount=*/ currentPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1541,7 +1543,7 @@ func TestCloseAndOpenReversePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_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()), @@ -1551,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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1689,7 +1691,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: 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 @@ -1715,7 +1717,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: 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 @@ -1743,7 +1745,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: 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 @@ -1769,7 +1771,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: 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 @@ -1806,7 +1808,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1815,7 +1817,7 @@ func TestClosePosition(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1852,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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.02"), }) @@ -1891,7 +1893,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(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), @@ -1919,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.Pair_BTC_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 @@ -1940,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.Pair_BTC_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 @@ -1969,7 +1971,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), ). @@ -1979,7 +1981,7 @@ func TestClosePositionWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /*baseAssetDirection=*/ tc.baseAssetDir, /*baseAssetAmount=*/ tc.initialPosition.Size_.Abs(), /*quoteAssetLimit=*/ sdk.ZeroDec(), @@ -1988,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.Pair_BTC_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 a8ba6de11..ea6cae39c 100644 --- a/x/perp/keeper/grpc_query_test.go +++ b/x/perp/keeper/grpc_query_test.go @@ -4,6 +4,8 @@ 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" @@ -30,7 +32,7 @@ func initAppVpools( t.Log("initialize vpool and pair") assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve, baseAssetReserve, vpooltypes.VpoolConfig{ @@ -42,12 +44,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_ETH_NUSD, + asset.Registry.Pair(denoms.ETH, denoms.NUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -59,12 +61,12 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_NIBI_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), /* quoteReserve */ sdk.MustNewDecFromStr("100000"), /* baseReserve */ sdk.MustNewDecFromStr("100000"), vpooltypes.VpoolConfig{ @@ -76,7 +78,7 @@ func initAppVpools( }, )) setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_NIBI_NUSD, + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) return ctx, nibiruApp, queryServer @@ -97,7 +99,7 @@ func TestQueryPosition(t *testing.T) { { name: "positive PnL", initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -114,7 +116,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, positive margin ratio", initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -131,7 +133,7 @@ func TestQueryPosition(t *testing.T) { { name: "negative PnL, negative margin ratio", initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -166,7 +168,7 @@ func TestQueryPosition(t *testing.T) { sdk.WrapSDKContext(ctx), &types.QueryPositionRequest{ Trader: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), }, ) require.NoError(t, err) @@ -192,7 +194,7 @@ func TestQueryPositions(t *testing.T) { name: "positive PnL", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -200,7 +202,7 @@ func TestQueryPositions(t *testing.T) { LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(10), Margin: sdk.NewDec(1), @@ -263,7 +265,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "empty string pair", initialPairMetadata: &types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -274,7 +276,7 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "pair metadata not found", initialPairMetadata: &types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ @@ -285,11 +287,11 @@ func TestQueryCumulativePremiumFraction(t *testing.T) { { name: "returns single funding payment", initialPairMetadata: &types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, query: &types.QueryCumulativePremiumFractionRequest{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), }, expectErr: false, expectedLatestCPF: sdk.ZeroDec(), @@ -304,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.Pair_BTC_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) @@ -339,7 +341,7 @@ func TestQueryMetrics(t *testing.T) { name: "two longs", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -347,7 +349,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -361,7 +363,7 @@ func TestQueryMetrics(t *testing.T) { name: "two shorts", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -369,7 +371,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -383,7 +385,7 @@ func TestQueryMetrics(t *testing.T) { name: "one long, one short", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), @@ -391,7 +393,7 @@ func TestQueryMetrics(t *testing.T) { }, { TraderAddress: "SHRIMP", - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), @@ -405,14 +407,14 @@ func TestQueryMetrics(t *testing.T) { name: "decrease position", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), @@ -427,42 +429,42 @@ func TestQueryMetrics(t *testing.T) { name: "swap positions", Positions: []*types.Position{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-10), OpenNotional: sdk.NewDec(100), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "WHALE", Size_: sdk.NewDec(-20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), LatestCumulativePremiumFraction: sdk.ZeroDec(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), TraderAddress: "SHRIMP", Size_: sdk.NewDec(20), OpenNotional: sdk.NewDec(200), @@ -488,7 +490,7 @@ func TestQueryMetrics(t *testing.T) { // Detect position decrease app.PerpKeeper.OnSwapEnd( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), position.OpenNotional, position.Size_, ) @@ -498,7 +500,7 @@ func TestQueryMetrics(t *testing.T) { resp, err := queryServer.Metrics( sdk.WrapSDKContext(ctx), &types.QueryMetricsRequest{ - Pair: common.Pair_BTC_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 803a54dce..72f692ccc 100644 --- a/x/perp/keeper/hooks_test.go +++ b/x/perp/keeper/hooks_test.go @@ -4,13 +4,14 @@ import ( "testing" "time" + "github.com/NibiruChain/nibiru/x/common/asset" + "github.com/NibiruChain/nibiru/x/common/denoms" testutilevents "github.com/NibiruChain/nibiru/x/testutil" sdk "github.com/cosmos/cosmos-sdk/types" "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" ) @@ -50,7 +51,7 @@ func TestEndOfEpochTwapCalculation(t *testing.T) { markPrice: sdk.NewDec(10), expectedLatestCumulativePremiumFraction: sdk.ZeroDec(), expectedFundingRateChangedEvent: &types.FundingRateChangedEvent{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_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) @@ -130,23 +131,23 @@ func initParams(ctx sdk.Context, k Keeper) { TwapLookbackWindow: 15 * time.Minute, }) setPairMetadata(k, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_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, common.Pair_BTC_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, common.Pair_BTC_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, common.Pair_BTC_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 21a932c2d..24c447813 100644 --- a/x/perp/keeper/liquidate_unit_test.go +++ b/x/perp/keeper/liquidate_unit_test.go @@ -7,6 +7,8 @@ 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" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,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" ) @@ -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.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 @@ -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.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 @@ -90,7 +91,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.Pair_BTC_NUSD).Return(true).Times(2) + ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.Pair_BTC_NUSD). + GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.Pair_BTC_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, common.Pair_BTC_NUSD).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, sdk.OneDec(), ). @@ -138,7 +139,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.exchangedSize, ). @@ -146,7 +147,7 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.NUSD). + Return(sdk.NewInt64Coin(denoms.NUSD, 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.Pair_BTC_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(common.Pair_BTC_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, common.Pair_BTC_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) @@ -195,15 +196,15 @@ func TestLiquidateIntoPartialLiquidation(t *testing.T) { assert.EqualValues(t, ctx.BlockHeight(), newPosition.BlockNumber) testutilevents.RequireHasTypedEvent(t, ctx, &types.PositionLiquidatedEvent{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.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(common.DenomNUSD, sdk.ZeroInt()), - Margin: sdk.NewCoin(common.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, @@ -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.NUSD, 12), // 923 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.NUSD, 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.NUSD, 11), + expectedPerpEFFee: sdk.NewInt64Coin(denoms.NUSD, 0), }, } @@ -265,7 +266,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { t.Log("set position") position := types.Position{ TraderAddress: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.Pair_BTC_NUSD).Return(true).Times(2) + ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.Pair_BTC_NUSD). + GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.Pair_BTC_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, common.Pair_BTC_NUSD).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -312,7 +313,7 @@ func TestLiquidateIntoFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.NUSD). + Return(sdk.NewInt64Coin(denoms.NUSD, 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.Pair_BTC_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(common.Pair_BTC_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: common.Pair_BTC_NUSD, + Pair: asset.Registry.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(common.DenomNUSD, sdk.ZeroInt()), - Margin: sdk.NewCoin(common.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 @@ -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.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"), @@ -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.NUSD, 11), // 899 * 0.025 / 2 + expectedPerpEFFee: sdk.NewInt64Coin(denoms.NUSD, 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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool keeper") mocks.mockVpoolKeeper.EXPECT(). - ExistsPool(ctx, common.Pair_BTC_NUSD).Return(true).Times(2) + ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(true).Times(2) mocks.mockVpoolKeeper.EXPECT(). - GetMaintenanceMarginRatio(ctx, common.Pair_BTC_NUSD). + GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)). Return(sdk.MustNewDecFromStr("0.0625"), nil) - mocks.mockVpoolKeeper.EXPECT().IsOverSpreadLimit(ctx, common.Pair_BTC_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, common.Pair_BTC_NUSD).Return(markPrice, nil) + mocks.mockVpoolKeeper.EXPECT().GetMarkPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).Return(markPrice, nil) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetTWAP( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpooltypes.Direction_ADD_TO_POOL, tc.initialPositionSize, ). @@ -483,7 +484,7 @@ func TestLiquidateIntoFullLiquidationWithBadDebt(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.NUSD). + Return(sdk.NewInt64Coin(denoms.NUSD, 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.NUSD, 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.Pair_BTC_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(common.Pair_BTC_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: common.Pair_BTC_NUSD, + Pair: asset.Registry.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(common.DenomNUSD, tc.expectedLiquidationBadDebt.Add(tc.expectedPositionBadDebt).RoundInt()), - Margin: sdk.NewInt64Coin(common.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 @@ -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.Pair_BTC_NUSD).Return(false) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), }, }, }, @@ -612,7 +613,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, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), }}, }, ) @@ -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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.Pair_BTC_NUSD).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -945,20 +946,20 @@ func TestKeeper_ExecuteFullLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapBaseForQuote( ctx, - common.Pair_BTC_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, common.Pair_BTC_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: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_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 @@ -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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.DenomNUSD, tc.expectedLiquidationBadDebt), - Margin: sdk.NewCoin(common.Pair_BTC_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(denoms.NUSD, tc.expectedLiquidationBadDebt), + Margin: sdk.NewCoin(asset.Registry.Pair(denoms.BTC, denoms.NUSD).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.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) t.Log("mock vpool") - mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, common.Pair_BTC_NUSD).AnyTimes().Return(true) + mocks.mockVpoolKeeper.EXPECT().ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)).AnyTimes().Return(true) mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Mul(tc.partialLiquidationRatio), ). @@ -1237,7 +1238,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). GetBaseAssetPrice( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetDirection, /*baseAssetAmount=*/ tc.initialPositionSize.Abs(), ). @@ -1247,7 +1248,7 @@ func TestKeeper_ExecutePartialLiquidation(t *testing.T) { mocks.mockVpoolKeeper.EXPECT(). SwapQuoteForBase( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_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: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_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: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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(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 d346918ac..0d689c7df 100644 --- a/x/perp/keeper/margin_test.go +++ b/x/perp/keeper/margin_test.go @@ -6,6 +6,8 @@ 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" @@ -32,11 +34,11 @@ func TestAddMarginSuccess(t *testing.T) { }{ { name: "add margin", - marginToAdd: sdk.NewInt64Coin(common.DenomNUSD, 100), + marginToAdd: sdk.NewInt64Coin(denoms.NUSD, 100), latestCumulativePremiumFraction: sdk.MustNewDecFromStr("0.001"), initialPosition: types.Position{ TraderAddress: testutilevents.AccAddress().String(), - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.NewDec(1_000), Margin: sdk.NewDec(100), OpenNotional: sdk.NewDec(500), @@ -67,7 +69,7 @@ func TestAddMarginSuccess(t *testing.T) { vpoolKeeper := &nibiruApp.VpoolKeeper assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens vpooltypes.VpoolConfig{ @@ -78,11 +80,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, asset.Registry.Pair(denoms.BTC, denoms.NUSD))) t.Log("set pair metadata") setPairMetadata(nibiruApp.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: tc.latestCumulativePremiumFraction, }, ) @@ -90,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.Pair_BTC_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, common.Pair_BTC_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) }) @@ -119,7 +121,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.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 17e1d175d..85e965a8b 100644 --- a/x/perp/keeper/margin_unit_test.go +++ b/x/perp/keeper/margin_unit_test.go @@ -7,16 +7,16 @@ 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/asset" + "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 +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: 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: common.Pair_BTC_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, - common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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, - common.Pair_BTC_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: common.Pair_BTC_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, - common.Pair_BTC_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, - common.Pair_BTC_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 d8f46a2ab..8887df872 100644 --- a/x/perp/keeper/msg_server_test.go +++ b/x/perp/keeper/msg_server_test.go @@ -15,6 +15,8 @@ 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" "github.com/NibiruChain/nibiru/x/testutil" @@ -33,37 +35,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.NUSD, 999)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - margin: sdk.NewInt64Coin(common.DenomNUSD, 1000), + margin: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "no initial position", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: nil, - margin: sdk.NewInt64Coin(common.DenomNUSD, 1000), + margin: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: collections.ErrNotFound, }, { name: "success", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - margin: sdk.NewInt64Coin(common.DenomNUSD, 1000), + margin: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: nil, }, } @@ -78,7 +80,7 @@ func TestMsgServerAddMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -90,7 +92,7 @@ func TestMsgServerAddMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -105,7 +107,7 @@ func TestMsgServerAddMargin(t *testing.T) { resp, err := msgServer.AddMargin(sdk.WrapSDKContext(ctx), &types.MsgAddMargin{ Sender: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Margin: tc.margin, }) @@ -140,51 +142,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.NUSD, 1000)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Size_: sdk.OneDec(), Margin: sdk.OneDec(), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, }, - marginToRemove: sdk.NewInt64Coin(common.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: types.ErrFailedRemoveMarginCanCauseBadDebt, }, { name: "no initial position", - vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 0)), + vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 0)), initialPosition: nil, - marginToRemove: sdk.NewInt64Coin(common.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: collections.ErrNotFound, }, { name: "vault insufficient funds", - vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 999)), + vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.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(common.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "success", - vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1000)), + vaultFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1000)), initialPosition: &types.Position{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.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(common.DenomNUSD, 1000), + marginToRemove: sdk.NewInt64Coin(denoms.NUSD, 1000), expectedErr: nil, }, } @@ -199,7 +201,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteReserve */ sdk.NewDec(1*common.Precision), /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -211,7 +213,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -228,7 +230,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { resp, err := msgServer.RemoveMargin(sdk.WrapSDKContext(ctx), &types.MsgRemoveMargin{ Sender: traderAddr.String(), - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Margin: tc.marginToRemove, }) @@ -262,15 +264,15 @@ func TestMsgServerOpenPosition(t *testing.T) { }{ { name: "trader not enough funds", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 999)), - pair: common.Pair_BTC_NUSD, + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 999)), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), sender: testutil.AccAddress().String(), expectedErr: sdkerrors.ErrInsufficientFunds, }, { name: "success", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1020)), - pair: common.Pair_BTC_NUSD, + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(denoms.NUSD, 1020)), + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), sender: testutil.AccAddress().String(), expectedErr: nil, }, @@ -286,7 +288,7 @@ func TestMsgServerOpenPosition(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ common.Pair_BTC_NUSD, + /* pair */ asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -298,7 +300,7 @@ func TestMsgServerOpenPosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -357,7 +359,7 @@ func TestMsgServerClosePosition(t *testing.T) { }{ { name: "success", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), traderAddr: testutil.AccAddress(), expectedErr: nil, }, @@ -373,7 +375,7 @@ func TestMsgServerClosePosition(t *testing.T) { assert.NoError(t, app.VpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -385,7 +387,7 @@ func TestMsgServerClosePosition(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) @@ -434,7 +436,7 @@ func TestMsgServerLiquidate(t *testing.T) { }{ { name: "success", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), liquidator: testutil.AccAddress().String(), trader: testutil.AccAddress().String(), expectedErr: nil, @@ -452,7 +454,7 @@ func TestMsgServerLiquidate(t *testing.T) { t.Log("create vpool") assert.NoError(t, app.VpoolKeeper.CreatePool( /* ctx */ ctx, - /* pair */ common.Pair_BTC_NUSD, + /* pair */ asset.Registry.Pair(denoms.BTC, denoms.NUSD), /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ @@ -464,7 +466,7 @@ func TestMsgServerLiquidate(t *testing.T) { }, )) setPairMetadata(app.PerpKeeper, ctx, types.PairMetadata{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), LatestCumulativePremiumFraction: sdk.ZeroDec(), }) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1).WithBlockTime(time.Now().Add(time.Minute)) @@ -472,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.Pair_BTC_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{ @@ -515,7 +517,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ctx = ctx.WithBlockTime(time.Now()) msgServer := keeper.NewMsgServerImpl(app.PerpKeeper) - pair := common.Pair_BTC_NUSD + pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) liquidator := testutil.AccAddress() atRiskTrader1 := testutil.AccAddress() @@ -543,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.Pair_BTC_NUSD, sdk.OneDec()) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec()) t.Log("create positions") atRiskPosition1 := types.Position{ @@ -641,14 +643,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.NUSD, 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.NUSD, 1e6)), + donation: sdk.NewInt64Coin(denoms.NUSD, 100), expectedErr: nil, }, } @@ -676,7 +678,7 @@ func TestMsgServerDonateToEcosystemFund(t *testing.T) { app.BankKeeper.GetBalance( ctx, app.AccountKeeper.GetModuleAddress(types.PerpEFModuleAccount), - common.DenomNUSD, + denoms.NUSD, ), ) } diff --git a/x/perp/simulation/genesis.go b/x/perp/simulation/genesis.go index b3277dfc6..f73611f6e 100644 --- a/x/perp/simulation/genesis.go +++ b/x/perp/simulation/genesis.go @@ -7,7 +7,8 @@ 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" ) @@ -17,7 +18,7 @@ func RandomizedGenState(simState *module.SimulationState) { Params: types.DefaultParams(), PairMetadata: []types.PairMetadata{ { - Pair: common.Pair_BTC_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 b8524567e..745e33d0e 100644 --- a/x/perp/simulation/operations.go +++ b/x/perp/simulation/operations.go @@ -13,6 +13,8 @@ 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" pooltypes "github.com/NibiruChain/nibiru/x/vpool/types" @@ -55,7 +57,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.NUSD))) leverage := simtypes.RandomDecAmount(r, pool.Config.MaxLeverage.Sub(sdk.OneDec())).Add(sdk.OneDec()) // between [1, MaxLeverage] openNotional := leverage.MulInt(quoteAmt) @@ -71,11 +73,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.NUSD, quoteAmt.Add(feesAmt))) msg := &types.MsgOpenPosition{ Sender: simAccount.Address.String(), - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Side: side, QuoteAssetAmount: quoteAmt, Leverage: leverage, @@ -170,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.Pair_BTC_NUSD + pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) 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(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 } @@ -208,22 +210,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.Pair_BTC_NUSD + pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) msg := &types.MsgAddMargin{} - _, err := k.Positions.Get(ctx, collections.Join(common.Pair_BTC_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 } spendableCoins := bk.SpendableCoins(ctx, simAccount.Address) - if spendableCoins.AmountOf(common.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(common.DenomNUSD)) + quoteAmt, _ := simtypes.RandPositiveInt(r, spendableCoins.AmountOf(denoms.NUSD)) - spentCoin := sdk.NewCoin(common.DenomNUSD, quoteAmt) + spentCoin := sdk.NewCoin(denoms.NUSD, quoteAmt) msg = &types.MsgAddMargin{ Sender: trader, @@ -257,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.Pair_BTC_NUSD + pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) 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(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 } @@ -280,7 +282,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.NUSD, marginToRemove) msg = &types.MsgRemoveMargin{ Sender: trader, @@ -315,7 +317,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.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 b41689231..b76ffeafb 100644 --- a/x/perp/types/msgs_test.go +++ b/x/perp/types/msgs_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "github.com/NibiruChain/nibiru/x/common/asset" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -335,7 +337,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, }}, @@ -346,7 +348,7 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, { @@ -361,11 +363,11 @@ func TestMsgMultiLiquidate_ValidateBasic(t *testing.T) { Sender: testutil.AccAddress().String(), Liquidations: []*MsgMultiLiquidate_MultiLiquidation{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Trader: testutil.AccAddress().String(), }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), Trader: "invalid", }, }}, diff --git a/x/stablecoin/abci.go b/x/stablecoin/abci.go index 984d429d7..467acaf11 100644 --- a/x/stablecoin/abci.go +++ b/x/stablecoin/abci.go @@ -3,7 +3,8 @@ 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" ) @@ -19,7 +20,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, 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 f9b927bf1..f48686152 100644 --- a/x/stablecoin/abci_test.go +++ b/x/stablecoin/abci_test.go @@ -10,6 +10,8 @@ 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" ) @@ -38,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.Pair_USDC_NUSD, price) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -52,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.Pair_USDC_NUSD, price) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -82,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.Pair_USDC_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, common.Pair_USDC_NUSD, price) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -100,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.Pair_USDC_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, common.Pair_USDC_NUSD, price) + app.OracleKeeper.SetPrice(ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD), price) epochs.BeginBlocker(ctx, app.EpochsKeeper) }, }, @@ -141,7 +143,7 @@ func TestEpochInfoChangesCollateralValidity(t *testing.T) { epochs.BeginBlocker(ctx, app.EpochsKeeper) pairs := common.AssetPairs{ - common.Pair_USDC_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 d913c377f..1e74c783d 100644 --- a/x/stablecoin/client/cli/cli_test.go +++ b/x/stablecoin/client/cli/cli_test.go @@ -17,6 +17,8 @@ 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" stabletypes "github.com/NibiruChain/nibiru/x/stablecoin/types" @@ -49,13 +51,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.USDC, sdk.NewInt(10000*common.Precision)) genesisState[stabletypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(stableGen) 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: 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 @@ -80,8 +82,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.NIBI, 100*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 100*common.Precision), ), val, s.cfg.BondDenom, @@ -90,7 +92,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.NIBI, sdk.NewInt(10))).String()), } testCases := []struct { @@ -142,7 +144,7 @@ func (s IntegrationTestSuite) TestMintStableCmd() { s.NoError(err) s.Require().Equal( - balRes.Balances.AmountOf(common.DenomNUSD), tc.expectedStable) + balRes.Balances.AmountOf(denoms.NUSD), tc.expectedStable) } }) } @@ -155,7 +157,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.NUSD, 50*common.Precision), ), val, s.cfg.BondDenom, @@ -163,7 +165,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.NIBI, sdk.NewInt(10))).String() commonArgs := []string{ fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), @@ -191,8 +193,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.USDC, 50_000)), + expectedEf: sdk.NewCoins(sdk.NewInt64Coin(denoms.USDC, 50_000)), expectErr: false, respType: &sdk.TxResponse{}, expectedCode: 0, @@ -241,11 +243,11 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { s.NoError(err) s.Require().Equal( - tc.expectedColl, balRes.Balances.AmountOf(common.DenomUSDC)) + tc.expectedColl, balRes.Balances.AmountOf(denoms.USDC)) s.Require().Equal( - tc.expectedGov, balRes.Balances.AmountOf(common.DenomNIBI)) + tc.expectedGov, balRes.Balances.AmountOf(denoms.NIBI)) s.Require().Equal( - tc.expectedStable, balRes.Balances.AmountOf(common.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 e2d23efdd..4f9e8e4c0 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.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 a55ca90ad..d19b1e85b 100644 --- a/x/stablecoin/keeper/collateral_ratio.go +++ b/x/stablecoin/keeper/collateral_ratio.go @@ -7,6 +7,8 @@ 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" ) @@ -86,7 +88,7 @@ func (k *Keeper) EvaluateCollRatio(ctx sdk.Context) (err error) { upperBound := params.GetPriceUpperBoundAsDec() stablePrice, err := k.OracleKeeper.GetExchangeRateTwap( - ctx, common.Pair_USDC_NUSD) + ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return err } @@ -113,14 +115,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.USDC} currentTotalCollUSD := sdk.ZeroDec() for _, collDenom := range collDenoms { amtColl := moduleCoins.AmountOf(collDenom) priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_USDC_NUSD) + ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.ZeroDec(), err } @@ -138,7 +140,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, asset.Registry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -222,7 +224,7 @@ func (k Keeper) Recollateralize( // Compute GOV rewarded to user priceCollStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_USDC_NUSD) + ctx, asset.Registry.Pair(denoms.USDC, denoms.NUSD)) if err != nil { return response, err } @@ -231,7 +233,7 @@ func (k Keeper) Recollateralize( if err != nil { return response, err } - outGov := sdk.NewCoin(common.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)) @@ -293,7 +295,7 @@ func (k *Keeper) GovAmtFromRecollateralize( bonusRate := params.GetBonusRateRecollAsDec() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_NIBI_NUSD) + ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -336,7 +338,7 @@ func (k *Keeper) BuybackGovAmtForTargetCollRatio( neededUSDForRecoll, _ := k.StableRequiredForTargetCollRatio(ctx) neededUSDForBuyback := neededUSDForRecoll.Neg() priceGovStable, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_NIBI_NUSD) + ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return sdk.Int{}, err } @@ -413,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.Pair_NIBI_NUSD) + ctx, asset.Registry.Pair(denoms.NIBI, denoms.NUSD)) if err != nil { return response, err } @@ -424,7 +426,7 @@ func (k Keeper) Buyback( if err != nil { return response, err } - outColl := sdk.NewCoin(common.DenomUSDC, outCollAmount) + outColl := sdk.NewCoin(denoms.USDC, outCollAmount) // Send COLL from the module to the caller err = k.BankKeeper.SendCoinsFromModuleToAccount( @@ -473,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.Pair_USDC_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 f3e497bc4..d3148cbb2 100644 --- a/x/stablecoin/keeper/collateral_ratio_test.go +++ b/x/stablecoin/keeper/collateral_ratio_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "github.com/NibiruChain/nibiru/x/common/asset" + "github.com/NibiruChain/nibiru/x/common/denoms" "github.com/NibiruChain/nibiru/x/testutil" simapp2 "github.com/NibiruChain/nibiru/simapp" @@ -81,7 +83,7 @@ func TestSetCollRatioUpdate(t *testing.T) { stablecoinKeeper := &nibiruApp.StablecoinKeeper oracleKeeper := &nibiruApp.OracleKeeper - oracleKeeper.SetPrice(ctx, common.Pair_USDC_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) @@ -178,7 +180,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(500), priceCollStable: sdk.OneDec(), // startCollUSD = 500 * 1 -> 500 postedAssetPairs: []common.AssetPair{ - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.6"), // 0.6 * 1000 = 600 @@ -189,7 +191,7 @@ func TestStableRequiredForTargetCollRatio(t *testing.T) { protocolColl: sdk.NewInt(600), priceCollStable: sdk.OneDec(), // startCollUSD = 600 * 1 = 600 postedAssetPairs: []common.AssetPair{ - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, stableSupply: sdk.NewInt(1000), targetCollRatio: sdk.MustNewDecFromStr("0.5"), // 0.5 * 1000 = 500 @@ -215,14 +217,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.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.Pair_USDC_NUSD: tc.priceCollStable, + asset.Registry.Pair(denoms.USDC, denoms.NUSD): tc.priceCollStable, } for _, pair := range tc.postedAssetPairs { nibiruApp.OracleKeeper.SetPrice(ctx, pair, prices[pair]) @@ -289,13 +291,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.USDC, tc.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.stableSupply), ), )) // Post the price - pair := common.Pair_USDC_NUSD + pair := asset.Registry.Pair(denoms.USDC, denoms.NUSD) nibiruApp.OracleKeeper.SetPrice(ctx, pair, tc.priceCollStable) neededCollAmount, err := stablecoinKeeper.RecollateralizeCollAmtForTargetCollRatio(ctx) @@ -328,13 +330,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.USDC, tc.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.stableSupply), ), )) // Post the price - // pair := common.Pair_USDC_NUSD + // pair := asset.AssetRegistry.Pair(denoms.USDC, denoms.NUSD) // nibiruApp.OracleKeeper.SetPrice(ctx, pair, tc.priceCollStable) neededCollAmount, err := stablecoinKeeper.RecollateralizeCollAmtForTargetCollRatio(ctx) @@ -377,7 +379,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}, + asset.Registry.Pair(denoms.USDC, denoms.NUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -388,7 +390,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}, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD)}, govOut: sdk.Int{}, expectedPass: false, }, @@ -398,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.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(2), @@ -414,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.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -430,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.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceCollStable: sdk.OneDec(), priceGovStable: sdk.NewDec(10), @@ -450,14 +452,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.USDC, tc.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.stableSupply), ), )) prices := map[common.AssetPair]sdk.Dec{ - common.Pair_NIBI_NUSD: tc.priceGovStable, - common.Pair_USDC_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]) @@ -465,8 +467,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, + 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]) @@ -518,8 +520,8 @@ func TestRecollateralize(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -530,13 +532,13 @@ func TestRecollateralize(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.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(common.DenomUSDC, sdk.NewInt(100_000)), + Coll: sdk.NewCoin(denoms.USDC, sdk.NewInt(100_000)), }, response: &types.MsgRecollateralizeResponse{ /* @@ -544,15 +546,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.NIBI, sdk.NewInt(100_200)), }, expectedPass: true, }, { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), @@ -563,13 +565,13 @@ func TestRecollateralize(t *testing.T) { }, priceGovStable: sdk.NewDec(5), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.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(common.DenomUSDC, sdk.NewInt(50_000)), + Coll: sdk.NewCoin(denoms.USDC, sdk.NewInt(50_000)), }, response: &types.MsgRecollateralizeResponse{ /* @@ -579,15 +581,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.NIBI, sdk.NewInt(11_021)), }, expectedPass: true, }, { name: "protocol has sufficient collateral - error", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -599,13 +601,13 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("-49.9995"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 1*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 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.USDC, sdk.NewInt(100)), }, expectedPass: false, err: fmt.Errorf("protocol has sufficient COLL"), @@ -613,8 +615,8 @@ func TestRecollateralize(t *testing.T) { { name: "caller is broke - error", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -626,13 +628,13 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("150"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 99), + sdk.NewInt64Coin(denoms.USDC, 99), ), // Since 'neededUSD' is msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewCoin(common.DenomUSDC, sdk.NewInt(200)), + Coll: sdk.NewCoin(denoms.USDC, sdk.NewInt(200)), }, expectedPass: false, err: fmt.Errorf("Not enough balance"), @@ -640,8 +642,8 @@ func TestRecollateralize(t *testing.T) { { name: "negative msg.Coll.Amount - error", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -653,21 +655,21 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("400"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 400), + sdk.NewInt64Coin(denoms.USDC, 400), ), msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.Coin{Denom: common.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", common.DenomUSDC), + "collateral input, -200%v, must be positive", denoms.USDC), }, { name: "oracle prices are expired - error", postedAssetPairs: []common.AssetPair{ - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, priceGovStable: sdk.NewDec(1), scenario: NeededCollScenario{ @@ -679,11 +681,11 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("400"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 400), + sdk.NewInt64Coin(denoms.USDC, 400), ), msg: types.MsgRecollateralize{ Creator: testutil.AccAddress().String(), - Coll: sdk.NewInt64Coin(common.DenomUSDC, 400), + Coll: sdk.NewInt64Coin(denoms.USDC, 400), }, expectedPass: false, @@ -701,8 +703,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.USDC, tc.scenario.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.scenario.stableSupply), ), )) // Fund account @@ -716,8 +718,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, + 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]) @@ -725,8 +727,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, + 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]) @@ -772,7 +774,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.USDC, 100), } _, err := nibiruApp.StablecoinKeeper.Recollateralize(goCtx, msg) require.ErrorContains(t, err, "collections: not found") @@ -849,8 +851,8 @@ func TestBuyback(t *testing.T) { { name: "both prices are $1", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -861,32 +863,32 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 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.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(common.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(common.DenomUSDC, sdk.NewInt(100_000)), + Coll: sdk.NewCoin(denoms.USDC, sdk.NewInt(100_000)), }, expectedPass: true, }, { name: "arbitrary valid prices", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(850_000), @@ -897,17 +899,17 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.NewDec(5), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 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.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(common.DenomNIBI, sdk.NewInt(50_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(50_000)), }, response: &types.MsgBuybackResponse{ /* @@ -919,15 +921,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.USDC, sdk.NewInt(213_636)), }, expectedPass: true, }, { name: "msg has more NIBI than the protocol needs, only needed sent", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -938,29 +940,29 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(denoms.NIBI, 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.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(common.DenomNIBI, sdk.NewInt(200_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(200_000)), }, response: &types.MsgBuybackResponse{ // Coll.Amount = inUSD * / priceCollStable - Coll: sdk.NewCoin(common.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.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -971,13 +973,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.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(common.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -985,8 +987,8 @@ func TestBuyback(t *testing.T) { { name: "caller has insufficient funds", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -997,13 +999,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1), + sdk.NewInt64Coin(denoms.NIBI, 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.NIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -1011,7 +1013,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing collateral price post", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1022,13 +1024,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.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(common.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -1036,7 +1038,7 @@ func TestBuyback(t *testing.T) { { name: "fail: missing NIBI price post", postedAssetPairs: []common.AssetPair{ - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1047,13 +1049,13 @@ func TestBuyback(t *testing.T) { }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.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(common.DenomNIBI, sdk.NewInt(100_000)), + Gov: sdk.NewCoin(denoms.NIBI, sdk.NewInt(100_000)), }, response: &types.MsgBuybackResponse{}, expectedPass: false, @@ -1072,8 +1074,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.USDC, tc.scenario.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.scenario.stableSupply), ), )) @@ -1089,8 +1091,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, + 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]) @@ -1131,8 +1133,8 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, correct amount out", postedAssetPairs: []common.AssetPair{ - common.Pair_NIBI_NUSD, - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.NIBI, denoms.NUSD), + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1162,7 +1164,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { { name: "both prices $1, only coll price posted", postedAssetPairs: []common.AssetPair{ - common.Pair_USDC_NUSD, + asset.Registry.Pair(denoms.USDC, denoms.NUSD), }, scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), @@ -1185,14 +1187,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.USDC, tc.scenario.protocolColl), + sdk.NewCoin(denoms.NUSD, tc.scenario.stableSupply), ), )) prices := map[common.AssetPair]sdk.Dec{ - common.Pair_NIBI_NUSD: tc.priceGovStable, - common.Pair_USDC_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/keeper.go b/x/stablecoin/keeper/keeper.go index 5222de886..591e553df 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.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 cac9ea492..9a9490c61 100644 --- a/x/stablecoin/keeper/mint_burn_stable.go +++ b/x/stablecoin/keeper/mint_burn_stable.go @@ -12,6 +12,8 @@ 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" ) @@ -93,16 +95,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.Pair_NIBI_NUSD) + ctx, asset.Registry.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(common.DenomNIBI, neededGovAmt) + neededGov := sdk.NewCoin(denoms.NIBI, neededGovAmt) govFeeAmt := neededGovAmt.ToDec().Mul(feeRatio).RoundInt() - govFee := sdk.NewCoin(common.DenomNIBI, govFeeAmt) + govFee := sdk.NewCoin(denoms.NIBI, govFeeAmt) return neededGov, govFee, nil } @@ -115,16 +117,16 @@ func (k Keeper) calcNeededCollateralAndFees( feeRatio sdk.Dec, ) (sdk.Coin, sdk.Coin, error) { priceColl, err := k.OracleKeeper.GetExchangeRate( - ctx, common.Pair_USDC_NUSD) + ctx, asset.Registry.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(common.DenomUSDC, neededCollAmt) + neededColl := sdk.NewCoin(denoms.USDC, neededCollAmt) collFeeAmt := neededCollAmt.ToDec().Mul(feeRatio).RoundInt() - collFee := sdk.NewCoin(common.DenomUSDC, collFeeAmt) + collFee := sdk.NewCoin(denoms.USDC, collFeeAmt) return neededColl, collFee, nil } @@ -252,7 +254,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.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 164e7c180..bf66ba1be 100644 --- a/x/stablecoin/keeper/mint_burn_stable_test.go +++ b/x/stablecoin/keeper/mint_burn_stable_test.go @@ -3,6 +3,8 @@ 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" simapp2 "github.com/NibiruChain/nibiru/simapp" @@ -54,10 +56,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.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), @@ -81,7 +83,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.NUSD, sdk.NewInt(1*common.Precision)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), @@ -93,18 +95,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.NUSD, sdk.NewInt(1*common.Precision)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.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(common.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(common.DenomNUSD, sdk.NewInt(1*common.Precision)), + supplyNUSD: sdk.NewCoin(denoms.NUSD, sdk.NewInt(1*common.Precision)), err: nil, isCollateralRatioValid: true, }, @@ -144,8 +146,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, 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)) @@ -170,7 +172,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.USDC, collFeesInEf)), efModuleBalance) // Check balances in Treasury treasuryModuleBalance := nibiruApp.BankKeeper. @@ -180,8 +182,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.USDC, collFeesInTreasury), + sdk.NewCoin(denoms.NIBI, govFeesInTreasury), ), treasuryModuleBalance, ) @@ -202,70 +204,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.USDC, sdk.NewInt(9001)), + sdk.NewCoin(denoms.NIBI, sdk.NewInt(0)), ), msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(100)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(100)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(0)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(0)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), - err: types.NotEnoughBalance.Wrap(common.DenomNIBI), + err: types.NotEnoughBalance.Wrap(denoms.NIBI), }, { 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.USDC, sdk.NewInt(0)), + sdk.NewCoin(denoms.NIBI, sdk.NewInt(9001)), ), msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(100)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(100)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(0)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(0)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), - err: types.NotEnoughBalance.Wrap(common.DenomUSDC), + err: types.NotEnoughBalance.Wrap(denoms.USDC), }, { name: "Not enough GOV", accFunds: sdk.NewCoins( - sdk.NewCoin(common.DenomUSDC, sdk.NewInt(9001)), - sdk.NewCoin(common.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(common.DenomNUSD, sdk.NewInt(1000)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(1000)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.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(common.DenomNIBI, sdk.NewInt(1)).String()), + sdk.NewCoin(denoms.NIBI, 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.USDC, sdk.NewInt(1)), + sdk.NewCoin(denoms.NIBI, sdk.NewInt(9001)), ), msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(100)), + Stable: sdk.NewCoin(denoms.NUSD, sdk.NewInt(100)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.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(common.DenomUSDC, sdk.NewInt(1)).String()), + sdk.NewCoin(denoms.USDC, sdk.NewInt(1)).String()), }, } @@ -301,8 +303,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, 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)) @@ -376,14 +378,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.NUSD, 10)), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(common.DenomNUSD, 9001), + Stable: sdk.NewInt64Coin(denoms.NUSD, 9001), }, msgResponse: &types.MsgBurnStableResponse{ - Collateral: sdk.NewCoin(common.DenomNIBI, sdk.ZeroInt()), - Gov: sdk.NewCoin(common.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"), @@ -395,22 +397,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.NUSD, 1000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.ZeroInt()), + Stable: sdk.NewCoin(denoms.NUSD, sdk.ZeroInt()), }, msgResponse: &types.MsgBurnStableResponse{ - Gov: sdk.NewCoin(common.DenomNIBI, sdk.ZeroInt()), - Collateral: sdk.NewCoin(common.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(common.DenomNUSD).Error(), + err: types.NoCoinFound.Wrap(denoms.NUSD).Error(), }, } @@ -448,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.Pair_NIBI_NUSD, tc.govPrice) - nibiruApp.OracleKeeper.SetPrice(ctx, common.Pair_USDC_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)) @@ -494,17 +496,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.NUSD, 1_000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(common.DenomNUSD, 10*common.Precision), + Stable: sdk.NewInt64Coin(denoms.NUSD, 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.USDC, 9000)), + treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(denoms.USDC, 9000), sdk.NewInt64Coin(denoms.NIBI, 100)), expectedPass: false, isCollateralRatioValid: false, err: types.NoValidCollateralRatio, @@ -514,27 +516,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.NUSD, 1_000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(denoms.USDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(common.DenomNUSD, 10*common.Precision), + Stable: sdk.NewInt64Coin(denoms.NUSD, 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.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(common.DenomNIBI, 200), - sdk.NewInt64Coin(common.DenomUSDC, 18_000), + sdk.NewInt64Coin(denoms.NIBI, 200), + sdk.NewInt64Coin(denoms.USDC, 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.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, }, @@ -569,8 +571,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, 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/stablecoin/keeper/supply.go b/x/stablecoin/keeper/supply.go index 706278058..5c55a8767 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.NUSD) } func (k Keeper) GetSupplyNIBI( ctx sdk.Context, ) sdk.Coin { - return k.BankKeeper.GetSupply(ctx, common.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, common.DenomNIBI, common.DenomNUSD) + pool, err := k.DexKeeper.FetchPoolFromPair(ctx, denoms.NIBI, denoms.NUSD) if err != nil { return sdk.Int{}, err } - price, err := pool.CalcSpotPrice(common.DenomNIBI, common.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 4a77bd87a..a61ee6660 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.NUSD, 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.NIBI, 2*common.Precision), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), + Token: sdk.NewInt64Coin(denoms.NUSD, 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.NIBI, 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.NIBI, 2*common.Precision), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), + Token: sdk.NewInt64Coin(denoms.NUSD, 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.NIBI, 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.NUSD, 1*common.Precision), )) require.NoError(t, err) diff --git a/x/stablecoin/simulation/msg.go b/x/stablecoin/simulation/msg.go index 37a8eda4a..e7509d7b5 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.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 ebed44b9d..bb41c9ceb 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.USDC, sdk.ZeroInt()), } } diff --git a/x/testutil/cli/network.go b/x/testutil/cli/network.go index 4ca70aa7c..b8a9483d0 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.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(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.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 c5a6b295c..3a6b1ecdc 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.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 9a9e3baeb..a7595bf4c 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.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(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.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 d25b57224..8ac6cf01c 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.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 8454d86e9..8ab57fa14 100644 --- a/x/vpool/abci_test.go +++ b/x/vpool/abci_test.go @@ -10,7 +10,8 @@ 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" "github.com/NibiruChain/nibiru/x/vpool/types" @@ -31,7 +32,7 @@ func TestSnapshotUpdates(t *testing.T) { require.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_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, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), 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.Pair_BTC_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 cda955ea9..f03edf4ec 100644 --- a/x/vpool/client/cli/cli_test.go +++ b/x/vpool/client/cli/cli_test.go @@ -16,6 +16,8 @@ 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" "github.com/NibiruChain/nibiru/x/vpool/client/cli" @@ -34,8 +36,8 @@ func TestIntegrationTestSuite(t *testing.T) { } var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ - common.Pair_ETH_NUSD: { - Pair: common.Pair_ETH_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{ @@ -46,8 +48,8 @@ var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ MaxLeverage: sdk.MustNewDecFromStr("15"), }, }, - common.Pair_NIBI_NUSD: { - Pair: common.Pair_NIBI_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{ @@ -73,14 +75,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[asset.Registry.Pair(denoms.ETH, denoms.NUSD)], + START_VPOOLS[asset.Registry.Pair(denoms.NIBI, denoms.NUSD)], } 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: 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 @@ -168,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.Pair_ETH_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, common.Pair_ETH_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) @@ -186,7 +188,7 @@ func (s *IntegrationTestSuite) TestCmdEditPoolConfigProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[common.Pair_ETH_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", @@ -252,7 +254,7 @@ func (s *IntegrationTestSuite) TestCmdEditSwapInvariantsProposal() { // ---------------------------------------------------------------------- s.T().Log("load example proposal json as bytes") // ---------------------------------------------------------------------- - startVpool := START_VPOOLS[common.Pair_NIBI_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 98cfaf247..767746031 100644 --- a/x/vpool/keeper/keeper_test.go +++ b/x/vpool/keeper/keeper_test.go @@ -12,6 +12,8 @@ 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" ) @@ -32,7 +34,7 @@ func TestSwapQuoteForBase(t *testing.T) { }{ { name: "quote amount == 0", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(0), baseLimit: sdk.NewDec(10), @@ -44,7 +46,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap add", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(49504), @@ -56,7 +58,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "normal swap remove", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(100_000), baseLimit: sdk.NewDec(50506), @@ -78,7 +80,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount less than base limit in Long", - pair: common.Pair_BTC_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), @@ -88,7 +90,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "base amount more than base limit in Short", - pair: common.Pair_BTC_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), @@ -98,7 +100,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when removing quote", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -108,7 +110,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over trading limit when adding quote", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, quoteAmount: sdk.NewDec(9_000_001), baseLimit: sdk.ZeroDec(), @@ -118,7 +120,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: common.Pair_BTC_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), @@ -128,7 +130,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: common.Pair_BTC_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), @@ -138,7 +140,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: common.Pair_BTC_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), @@ -150,7 +152,7 @@ func TestSwapQuoteForBase(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: common.Pair_BTC_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), @@ -172,7 +174,7 @@ func TestSwapQuoteForBase(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_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{ @@ -200,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.Pair_BTC_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") @@ -225,7 +227,7 @@ func TestSwapBaseForQuote(t *testing.T) { }{ { name: "zero base asset swap", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.ZeroDec(), quoteLimit: sdk.ZeroDec(), @@ -237,7 +239,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "add base asset swap", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196078), @@ -249,7 +251,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "remove base asset", - pair: common.Pair_BTC_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), @@ -271,7 +273,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount less than quote limit in Long", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(100_000), quoteLimit: sdk.NewDec(196079), @@ -281,7 +283,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "quote amount more than quote limit in Short", - pair: common.Pair_BTC_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), @@ -291,7 +293,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when removing base", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -301,7 +303,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over trading limit when adding base", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), direction: types.Direction_ADD_TO_POOL, baseAmt: sdk.NewDec(4_500_001), quoteLimit: sdk.ZeroDec(), @@ -311,7 +313,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on add", - pair: common.Pair_BTC_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), @@ -321,7 +323,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit fails on remove", - pair: common.Pair_BTC_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), @@ -331,7 +333,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on add", - pair: common.Pair_BTC_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), @@ -343,7 +345,7 @@ func TestSwapBaseForQuote(t *testing.T) { }, { name: "over fluctuation limit allowed on remove", - pair: common.Pair_BTC_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), @@ -365,7 +367,7 @@ func TestSwapBaseForQuote(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_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{ @@ -394,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.Pair_BTC_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) @@ -410,7 +412,7 @@ func TestGetVpools(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), sdk.NewDec(5*common.Precision), types.VpoolConfig{ @@ -423,7 +425,7 @@ func TestGetVpools(t *testing.T) { )) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_ETH_NUSD, + asset.Registry.Pair(denoms.ETH, denoms.NUSD), sdk.NewDec(5*common.Precision), sdk.NewDec(10*common.Precision), types.VpoolConfig{ @@ -440,7 +442,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: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(5 * common.Precision), QuoteAssetReserve: sdk.NewDec(10 * common.Precision), Config: types.VpoolConfig{ @@ -452,7 +454,7 @@ func TestGetVpools(t *testing.T) { }, }) require.EqualValues(t, pools[1], types.Vpool{ - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10 * common.Precision), QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: types.VpoolConfig{ @@ -476,7 +478,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses latest snapshot - does not result in error", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -489,13 +491,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -506,7 +508,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "uses previous snapshot - results in error", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -519,7 +521,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -530,7 +532,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "only one snapshot - no error", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -543,7 +545,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -554,7 +556,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "zero fluctuation limit - no error", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -567,13 +569,13 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), TimestampMs: 1, @@ -584,7 +586,7 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { { name: "multiple pools - no overlap", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -597,25 +599,25 @@ func TestCheckFluctuationLimitRatio(t *testing.T) { }, existingSnapshots: []types.ReserveSnapshot{ { - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.Pair_NIBI_NUSD, + Pair: asset.Registry.Pair(denoms.NIBI, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(2000), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, }, { - Pair: common.Pair_USDC_NUSD, + Pair: asset.Registry.Pair(denoms.USDC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), TimestampMs: 0, @@ -637,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) @@ -666,7 +668,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -677,7 +679,7 @@ func TestGetMaintenanceMarginRatio(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.DefaultVpoolConfig(). @@ -694,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.Pair_BTC_NUSD) + mmr, err := vpoolKeeper.GetMaintenanceMarginRatio(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) assert.NoError(t, err) assert.EqualValues(t, tc.expectedMaintenanceMarginRatio, mmr) }) @@ -711,7 +713,7 @@ func TestGetMaxLeverage(t *testing.T) { { name: "zero fluctuation limit ratio", pool: types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: types.VpoolConfig{ @@ -734,7 +736,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, 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 c0304a488..f931ed2d1 100644 --- a/x/vpool/keeper/pool_state_test.go +++ b/x/vpool/keeper/pool_state_test.go @@ -10,6 +10,8 @@ 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" ) @@ -18,7 +20,7 @@ func TestCreatePool(t *testing.T) { assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10*common.Precision), // 10 tokens sdk.NewDec(5*common.Precision), // 5 tokens @@ -31,7 +33,7 @@ func TestCreatePool(t *testing.T) { }, )) - exists := vpoolKeeper.ExistsPool(ctx, common.Pair_BTC_NUSD) + exists := vpoolKeeper.ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) require.True(t, exists) notExist := vpoolKeeper.ExistsPool(ctx, "BTC:OTHER") @@ -39,7 +41,7 @@ func TestCreatePool(t *testing.T) { } func TestEditPoolConfig(t *testing.T) { - pair := common.Pair_BTC_NUSD + pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) vpoolStart := types.Vpool{ Pair: pair, QuoteAssetReserve: sdk.NewDec(10 * common.Precision), @@ -57,12 +59,12 @@ func TestEditPoolConfig(t *testing.T) { vpoolKeeper, _, ctx := getKeeper(t) assert.NoError(t, vpoolKeeper.CreatePool( ctx, - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), vpoolStart.QuoteAssetReserve, vpoolStart.BaseAssetReserve, vpoolStart.Config, )) - exists := vpoolKeeper.ExistsPool(ctx, common.Pair_BTC_NUSD) + exists := vpoolKeeper.ExistsPool(ctx, asset.Registry.Pair(denoms.BTC, denoms.NUSD)) require.True(t, exists) return vpoolKeeper, ctx } @@ -188,7 +190,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool + pricefeed active", vpool: types.Vpool{ - Pair: common.Pair_ETH_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{ @@ -202,7 +204,7 @@ func TestGetPoolPrices(t *testing.T) { shouldCreateVpool: true, mockIndexPrice: sdk.NewDec(99), expectedPoolPrices: types.PoolPrices{ - Pair: common.Pair_ETH_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(), @@ -213,7 +215,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "happy path - vpool active, but no index price", vpool: types.Vpool{ - Pair: common.Pair_ETH_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{ @@ -228,7 +230,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: asset.Registry.Pair(denoms.ETH, denoms.NUSD), MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.OneDec().Neg().String(), @@ -239,7 +241,7 @@ func TestGetPoolPrices(t *testing.T) { { name: "vpool doesn't exist", vpool: types.Vpool{ - Pair: common.Pair_ETH_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{ @@ -292,7 +294,7 @@ func TestGetPoolPrices(t *testing.T) { } func TestEditSwapInvariant(t *testing.T) { - pair := common.Pair_NIBI_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 82a167b2e..d5add58e4 100644 --- a/x/vpool/keeper/prices_test.go +++ b/x/vpool/keeper/prices_test.go @@ -12,6 +12,8 @@ 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" ) @@ -26,14 +28,14 @@ func TestGetMarkPrice(t *testing.T) { }{ { name: "correctly fetch underlying price", - pair: common.Pair_BTC_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: common.Pair_BTC_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"), @@ -80,7 +82,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), baseAmount: sdk.ZeroDec(), @@ -89,7 +91,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -98,7 +100,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("500"), @@ -107,7 +109,7 @@ func TestGetBaseAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), baseAmount: sdk.MustNewDecFromStr("1000"), @@ -163,7 +165,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }{ { name: "zero base asset means zero price", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(10_000), quoteAmount: sdk.ZeroDec(), @@ -172,7 +174,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple add base to pool", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -181,7 +183,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "simple remove base from pool", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(500), @@ -190,7 +192,7 @@ func TestGetQuoteAssetPrice(t *testing.T) { }, { name: "too much base removed results in error", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), baseAssetReserve: sdk.NewDec(1000), quoteAssetReserve: sdk.NewDec(1000), quoteAmount: sdk.NewDec(1000), @@ -252,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.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -283,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.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -314,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.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(90), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(85), time.UnixMilli(20), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(95), time.UnixMilli(30), @@ -347,7 +349,7 @@ func TestCalcTwap(t *testing.T) { // expected price: 100/1 { name: "spot price twap calc, t=[0,0]", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{}, currentBlockTime: time.UnixMilli(0), currentBlockHeight: 1, @@ -361,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.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(30), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.MustNewDecFromStr("7.5"), sdk.NewDec(40), time.UnixMilli(20), @@ -390,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.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(12), sdk.NewDec(50), time.UnixMilli(20), @@ -415,10 +417,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: quote asset reserve = asset amount", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(20), time.UnixMilli(20), @@ -438,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.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(20), sdk.NewDec(30), time.UnixMilli(20), @@ -467,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.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(10), ), types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(8), sdk.NewDec(75), time.UnixMilli(20), @@ -492,10 +494,10 @@ func TestCalcTwap(t *testing.T) { }, { name: "Error: base asset reserve = asset amount", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), reserveSnapshots: []types.ReserveSnapshot{ types.NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.NewDec(10), sdk.NewDec(60), time.UnixMilli(20), @@ -539,7 +541,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, + 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 f01a563fc..9dd7493ff 100644 --- a/x/vpool/keeper/query_server_test.go +++ b/x/vpool/keeper/query_server_test.go @@ -10,6 +10,8 @@ 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" ) @@ -23,7 +25,7 @@ func TestQueryReserveAssets(t *testing.T) { t.Log("initialize vpool") pool := types.Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1 * common.Precision), BaseAssetReserve: sdk.NewDec(1000), Config: types.VpoolConfig{ @@ -40,7 +42,7 @@ func TestQueryReserveAssets(t *testing.T) { resp, err := queryServer.ReserveAssets( sdk.WrapSDKContext(ctx), &types.QueryReserveAssetsRequest{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), }, ) @@ -57,7 +59,7 @@ func TestQueryAllPools(t *testing.T) { queryServer := NewQuerier(vpoolKeeper) t.Log("initialize vpool") - pair := common.Pair_BTC_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 44818b666..4fef02fdd 100644 --- a/x/vpool/keeper/snapshot_test.go +++ b/x/vpool/keeper/snapshot_test.go @@ -8,6 +8,8 @@ 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" ) @@ -24,7 +26,7 @@ func TestGetSnapshotPrice(t *testing.T) { }{ { name: "spot price calc", - pair: common.Pair_BTC_NUSD, + pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), quoteAssetReserve: sdk.NewDec(40_000), baseAssetReserve: sdk.NewDec(2), twapCalcOption: types.TwapCalcOption_SPOT, @@ -32,7 +34,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap add to pool calc", - pair: common.Pair_BTC_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, @@ -42,7 +44,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "quote asset swap remove from pool calc", - pair: common.Pair_BTC_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, @@ -52,7 +54,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap add to pool calc", - pair: common.Pair_BTC_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, @@ -62,7 +64,7 @@ func TestGetSnapshotPrice(t *testing.T) { }, { name: "base asset swap remove from pool calc", - pair: common.Pair_BTC_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 c2ba99785..5a5e4b67a 100644 --- a/x/vpool/simulation/genesis.go +++ b/x/vpool/simulation/genesis.go @@ -8,7 +8,8 @@ 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" ) @@ -23,7 +24,7 @@ func RandomizedGenState(simState *module.SimulationState) { vpoolGenesis := types.GenesisState{ Vpools: []types.Vpool{ { - Pair: common.Pair_BTC_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 29827dc0a..f4267721e 100644 --- a/x/vpool/types/gov_test.go +++ b/x/vpool/types/gov_test.go @@ -11,6 +11,8 @@ 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" "github.com/stretchr/testify/require" @@ -144,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.Pair_NIBI_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 9bfc7aa5c..636fdc8ea 100644 --- a/x/vpool/types/pool_test.go +++ b/x/vpool/types/pool_test.go @@ -10,6 +10,8 @@ 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" ) @@ -504,7 +506,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "happy path", Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -513,7 +515,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil base", Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -522,7 +524,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero base", Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.MustNewDecFromStr("10000"), }, @@ -531,7 +533,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "nil quote", Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.Dec{}, }, @@ -540,7 +542,7 @@ func TestVpool_GetMarkPrice(t *testing.T) { { "zero quote", Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.MustNewDecFromStr("10"), QuoteAssetReserve: sdk.ZeroDec(), }, @@ -566,7 +568,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "zero fluctuation limit ratio", pool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.OneDec(), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -582,7 +584,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "lower limit of fluctuation limit", pool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(999), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -598,7 +600,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "upper limit of fluctuation limit", pool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1001), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -614,7 +616,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "under fluctuation limit", pool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(998), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -630,7 +632,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { { name: "over fluctuation limit", pool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), QuoteAssetReserve: sdk.NewDec(1002), BaseAssetReserve: sdk.OneDec(), Config: VpoolConfig{ @@ -649,7 +651,7 @@ func TestVpool_IsOverFluctuationLimit(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { snapshot := NewReserveSnapshot( - common.Pair_BTC_NUSD, + asset.Registry.Pair(denoms.BTC, denoms.NUSD), sdk.OneDec(), sdk.NewDec(1000), time.Now(), @@ -668,7 +670,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "happy path", vpool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(10), QuoteAssetReserve: sdk.NewDec(10_000), }, @@ -677,7 +679,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid base", vpool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.Dec{}, QuoteAssetReserve: sdk.NewDec(500), }, @@ -686,7 +688,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err invalid quote", vpool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.Dec{}, }, @@ -695,7 +697,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative quote", vpool: Vpool{ - Pair: common.Pair_BTC_NUSD, + Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), BaseAssetReserve: sdk.NewDec(500), QuoteAssetReserve: sdk.NewDec(-500), }, @@ -704,7 +706,7 @@ func TestVpool_ToSnapshot(t *testing.T) { { name: "err negative base", vpool: Vpool{ - Pair: common.Pair_BTC_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 61b6ce4f9..d27dcc6fc 100644 --- a/x/vpool/types/snapshot_test.go +++ b/x/vpool/types/snapshot_test.go @@ -8,6 +8,8 @@ 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" ) func TestSnapshotValidate(t *testing.T) { @@ -19,7 +21,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "happy path", snapshot: ReserveSnapshot{ - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.OneDec(), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -39,7 +41,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "base asset negative", snapshot: ReserveSnapshot{ - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.NewDec(-1), QuoteAssetReserve: sdk.OneDec(), TimestampMs: time.Now().UnixMilli(), @@ -49,7 +51,7 @@ func TestSnapshotValidate(t *testing.T) { { name: "quote asset negative", snapshot: ReserveSnapshot{ - Pair: common.Pair_ETH_NUSD, + Pair: asset.Registry.Pair(denoms.ETH, denoms.NUSD), BaseAssetReserve: sdk.ZeroDec(), QuoteAssetReserve: sdk.NewDec(-1), TimestampMs: time.Now().UnixMilli(), @@ -60,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.Pair_ETH_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 9f16197a7..d49836cf2 100644 --- a/x/wasm/cli/cli_test.go +++ b/x/wasm/cli/cli_test.go @@ -16,6 +16,8 @@ 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" ) @@ -24,7 +26,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.NIBI, sdk.NewInt(10))).String()), } type IntegrationTestSuite struct { @@ -48,7 +50,7 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis := vpooltypes.DefaultGenesis() vpoolGenesis.Vpools = []vpooltypes.Vpool{ { - Pair: common.Pair_ETH_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{