From 741931464dff36a8bcabafd368925674912540af Mon Sep 17 00:00:00 2001 From: levisyin <150114626+levisyin@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:02:49 +0800 Subject: [PATCH] refactor: using coins.Denoms() from sdk instead of osmoutils (#7126) --- .../sqs/router/usecase/pools/routable_transmuter_pool.go | 3 +-- osmoutils/coin_helper.go | 9 --------- x/cosmwasmpool/model/pool.go | 3 +-- x/gamm/keeper/pool.go | 3 +-- x/gamm/pool-models/balancer/pool.go | 3 +-- x/gamm/pool-models/stableswap/pool.go | 3 +-- x/gamm/simulation/sim_msgs.go | 2 +- x/twap/listeners_test.go | 3 +-- x/twap/logic_test.go | 3 +-- 9 files changed, 8 insertions(+), 24 deletions(-) diff --git a/ingest/sqs/router/usecase/pools/routable_transmuter_pool.go b/ingest/sqs/router/usecase/pools/routable_transmuter_pool.go index 32c1d528292..1e780aa3ac2 100644 --- a/ingest/sqs/router/usecase/pools/routable_transmuter_pool.go +++ b/ingest/sqs/router/usecase/pools/routable_transmuter_pool.go @@ -7,7 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/osmosis-labs/osmosis/osmomath" - "github.com/osmosis-labs/osmosis/osmoutils" "github.com/osmosis-labs/osmosis/v21/ingest/sqs/domain" cwpoolmodel "github.com/osmosis-labs/osmosis/v21/x/cosmwasmpool/model" poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types" @@ -30,7 +29,7 @@ func (r *routableTransmuterPoolImpl) GetId() uint64 { // GetPoolDenoms implements domain.RoutablePool. func (r *routableTransmuterPoolImpl) GetPoolDenoms() []string { - return osmoutils.CoinsDenoms(r.Balances) + return r.Balances.Denoms() } // GetType implements domain.RoutablePool. diff --git a/osmoutils/coin_helper.go b/osmoutils/coin_helper.go index 3a60712a907..e7c04e56ac2 100644 --- a/osmoutils/coin_helper.go +++ b/osmoutils/coin_helper.go @@ -7,15 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// TODO: Get this into the SDK https://github.com/cosmos/cosmos-sdk/issues/12538 -func CoinsDenoms(coins sdk.Coins) []string { - denoms := make([]string, len(coins)) - for i, coin := range coins { - denoms[i] = coin.Denom - } - return denoms -} - // MinCoins returns the minimum of each denom between both coins. // For now it assumes they have the same denoms. // TODO: Replace with method in SDK once we update our version diff --git a/x/cosmwasmpool/model/pool.go b/x/cosmwasmpool/model/pool.go index 181e0439464..be4119f2f9e 100644 --- a/x/cosmwasmpool/model/pool.go +++ b/x/cosmwasmpool/model/pool.go @@ -5,7 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/osmosis-labs/osmosis/osmoutils" "github.com/osmosis-labs/osmosis/v21/x/cosmwasmpool/cosmwasm/msg" "github.com/osmosis-labs/osmosis/v21/x/cosmwasmpool/types" poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types" @@ -141,7 +140,7 @@ func (p *Pool) SetWasmKeeper(wasmKeeper types.WasmKeeper) { // GetPoolDenoms implements types.PoolI. func (p *Pool) GetPoolDenoms(ctx sdk.Context) []string { poolLiquidity := p.GetTotalPoolLiquidity(ctx) - return osmoutils.CoinsDenoms(poolLiquidity) + return poolLiquidity.Denoms() } func (p Pool) AsSerializablePool() poolmanagertypes.PoolI { diff --git a/x/gamm/keeper/pool.go b/x/gamm/keeper/pool.go index 38341c0e0fe..db31361b1e0 100644 --- a/x/gamm/keeper/pool.go +++ b/x/gamm/keeper/pool.go @@ -241,8 +241,7 @@ func (k Keeper) GetPoolDenoms(ctx sdk.Context, poolId uint64) ([]string, error) return nil, err } - denoms := osmoutils.CoinsDenoms(pool.GetTotalPoolLiquidity(ctx)) - return denoms, err + return pool.GetTotalPoolLiquidity(ctx).Denoms(), err } // setNextPoolId sets next pool Id. diff --git a/x/gamm/pool-models/balancer/pool.go b/x/gamm/pool-models/balancer/pool.go index f781e1b4d58..2f24501d6d6 100644 --- a/x/gamm/pool-models/balancer/pool.go +++ b/x/gamm/pool-models/balancer/pool.go @@ -11,7 +11,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/osmosis-labs/osmosis/osmomath" - "github.com/osmosis-labs/osmosis/osmoutils" "github.com/osmosis-labs/osmosis/v21/x/gamm/pool-models/internal/cfmm_common" "github.com/osmosis-labs/osmosis/v21/x/gamm/types" poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types" @@ -987,5 +986,5 @@ func (p *Pool) AsSerializablePool() poolmanagertypes.PoolI { // GetPoolDenoms implements types.CFMMPoolI. func (p *Pool) GetPoolDenoms(ctx sdk.Context) []string { liquidity := p.GetTotalPoolLiquidity(ctx) - return osmoutils.CoinsDenoms(liquidity) + return liquidity.Denoms() } diff --git a/x/gamm/pool-models/stableswap/pool.go b/x/gamm/pool-models/stableswap/pool.go index 9ed2927b4ac..8d68db2ac08 100644 --- a/x/gamm/pool-models/stableswap/pool.go +++ b/x/gamm/pool-models/stableswap/pool.go @@ -10,7 +10,6 @@ import ( errorsmod "cosmossdk.io/errors" "github.com/osmosis-labs/osmosis/osmomath" - "github.com/osmosis-labs/osmosis/osmoutils" "github.com/osmosis-labs/osmosis/v21/x/gamm/pool-models/internal/cfmm_common" "github.com/osmosis-labs/osmosis/v21/x/gamm/types" poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types" @@ -497,5 +496,5 @@ func (p *Pool) AsSerializablePool() poolmanagertypes.PoolI { // GetPoolDenoms implements types.CFMMPoolI. func (p *Pool) GetPoolDenoms(ctx sdk.Context) []string { liquidity := p.GetTotalPoolLiquidity(ctx) - return osmoutils.CoinsDenoms(liquidity) + return liquidity.Denoms() } diff --git a/x/gamm/simulation/sim_msgs.go b/x/gamm/simulation/sim_msgs.go index 6b8385efb31..58239807cea 100644 --- a/x/gamm/simulation/sim_msgs.go +++ b/x/gamm/simulation/sim_msgs.go @@ -27,7 +27,7 @@ func RandomJoinPoolMsg(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Context) ( if err != nil { return nil, err } - poolDenoms := osmoutils.CoinsDenoms(pool.GetTotalPoolLiquidity(ctx)) + poolDenoms := pool.GetTotalPoolLiquidity(ctx).Denoms() // get address that has all denoms from the randomly selected pool sender, tokenIn, senderExists := sim.SelAddrWithDenoms(ctx, poolDenoms) diff --git a/x/twap/listeners_test.go b/x/twap/listeners_test.go index 8ad793d6370..47f0d1d3523 100644 --- a/x/twap/listeners_test.go +++ b/x/twap/listeners_test.go @@ -7,7 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/osmosis-labs/osmosis/osmomath" - "github.com/osmosis-labs/osmosis/osmoutils" "github.com/osmosis-labs/osmosis/v21/x/twap" "github.com/osmosis-labs/osmosis/v21/x/twap/types" @@ -58,7 +57,7 @@ func (s *TestSuite) TestAfterPoolCreatedHook() { s.RunBasicSwap(poolId) } - denoms := osmoutils.CoinsDenoms(tc.poolCoins) + denoms := tc.poolCoins.Denoms() denomPairs := types.GetAllUniqueDenomPairs(denoms) expectedRecords := []types.TwapRecord{} for _, denomPair := range denomPairs { diff --git a/x/twap/logic_test.go b/x/twap/logic_test.go index b8e1b3ba645..ff8bac7b699 100644 --- a/x/twap/logic_test.go +++ b/x/twap/logic_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/require" "github.com/osmosis-labs/osmosis/osmomath" - "github.com/osmosis-labs/osmosis/osmoutils" "github.com/osmosis-labs/osmosis/osmoutils/osmoassert" gammtypes "github.com/osmosis-labs/osmosis/v21/x/gamm/types" poolmanagertypes "github.com/osmosis-labs/osmosis/v21/x/poolmanager/types" @@ -1323,7 +1322,7 @@ func (s *TestSuite) TestAfterCreatePool() { s.Require().Equal(tc.poolId, poolId) s.Require().NoError(err) - denoms := osmoutils.CoinsDenoms(tc.poolCoins) + denoms := tc.poolCoins.Denoms() denomPairs := types.GetAllUniqueDenomPairs(denoms) expectedRecords := []types.TwapRecord{} for _, denomPair := range denomPairs {