diff --git a/osmoutils/coin_helper.go b/osmoutils/coin_helper.go index e7c04e56ac2..0cb81f8d16f 100644 --- a/osmoutils/coin_helper.go +++ b/osmoutils/coin_helper.go @@ -7,21 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// 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 -func MinCoins(coinsA sdk.Coins, coinsB sdk.Coins) sdk.Coins { - resCoins := sdk.Coins{} - for i, coin := range coinsA { - if coinsB[i].Amount.GT(coin.Amount) { - resCoins = append(resCoins, coin) - } else { - resCoins = append(resCoins, coinsB[i]) - } - } - return resCoins -} - // SubDecCoinArrays subtracts the contents of the second param from the first (decCoinsArrayA - decCoinsArrayB) // Note that this takes in two _arrays_ of DecCoins, meaning that each term itself is of type DecCoins (i.e. an array of DecCoin). func SubDecCoinArrays(decCoinsArrayA []sdk.DecCoins, decCoinsArrayB []sdk.DecCoins) ([]sdk.DecCoins, error) { diff --git a/x/gamm/simulation/sim_msgs.go b/x/gamm/simulation/sim_msgs.go index 58239807cea..79d7a1661e7 100644 --- a/x/gamm/simulation/sim_msgs.go +++ b/x/gamm/simulation/sim_msgs.go @@ -9,7 +9,6 @@ import ( legacysimulationtype "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/osmosis-labs/osmosis/osmomath" - "github.com/osmosis-labs/osmosis/osmoutils" "github.com/osmosis-labs/osmosis/v21/simulation/simtypes" "github.com/osmosis-labs/osmosis/v21/x/gamm/keeper" balancertypes "github.com/osmosis-labs/osmosis/v21/x/gamm/pool-models/balancer" @@ -36,7 +35,7 @@ func RandomJoinPoolMsg(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Context) ( } // cap joining pool to the pool liquidity - tokenIn = osmoutils.MinCoins(tokenIn, pool.GetTotalPoolLiquidity(ctx)) + tokenIn = tokenIn.Min(pool.GetTotalPoolLiquidity(ctx)) // TODO: Fix API so this is a one liner, pool.CalcJoinPoolNoSwapShares() minShareOutAmt, err := deriveRealMinShareOutAmt(ctx, tokenIn, pool) @@ -195,7 +194,7 @@ func RandomSwapExactAmountOut(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk.Con } // set the subset of coins to be upper-bound to the minimum between the address and the pool itself - randomCoinInSubset := osmoutils.MinCoins(sdk.NewCoins(coinIn), sdk.NewCoins(accCoin)) + randomCoinInSubset := sdk.NewCoins(coinIn).Min(sdk.NewCoins(accCoin)) // utilize CalcOutAmtGivenIn to calculate tokenOut and use tokenOut to calculate tokenInMax tokenOut, err := pool.CalcOutAmtGivenIn(ctx, randomCoinInSubset, coinOut.Denom, pool.GetSpreadFactor(ctx)) @@ -241,7 +240,7 @@ func RandomJoinSwapExternAmountIn(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk } // cap joining pool to the pool liquidity - newTokenIn := osmoutils.MinCoins(sdk.NewCoins(coinIn), sdk.NewCoins(tokenIn)) + newTokenIn := sdk.NewCoins(coinIn).Min(sdk.NewCoins(tokenIn)) // calc shares out with tokenIn minShareOutAmt, _, err := pool.CalcJoinPoolShares(ctx, newTokenIn, pool.GetSpreadFactor(ctx)) @@ -274,7 +273,7 @@ func RandomJoinSwapShareAmountOut(k keeper.Keeper, sim *simtypes.SimCtx, ctx sdk } // cap joining pool to the pool liquidity - newTokenIn := osmoutils.MinCoins(sdk.NewCoins(coinIn), sdk.NewCoins(tokenIn)) + newTokenIn := sdk.NewCoins(coinIn).Min(sdk.NewCoins(tokenIn)) // calc shares out with tokenIn minShareOutAmt, _, err := pool.CalcJoinPoolShares(ctx, newTokenIn, pool.GetSpreadFactor(ctx))