Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace MinCoins with sdk coins.Min() #7127

Merged
merged 5 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions osmoutils/coin_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 4 additions & 5 deletions x/gamm/simulation/sim_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down