Unverified Commit 1c6c3c04 authored by Mirel Dalčeković's avatar Mirel Dalčeković Committed by GitHub
Browse files

x/gamm module minor code improvements (#3704)

* JoinPoolNoSwap change due to tokenInMaxs checks

* panic message better explained
Showing with 17 additions and 4 deletions
+17 -4
......@@ -160,15 +160,19 @@ func (k Keeper) JoinPoolNoSwap(
}
// check that needed lp liquidity does not exceed the given `tokenInMaxs` parameter. Return error if so.
// if tokenInMaxs == 0, don't do this check.
//if tokenInMaxs == 0, don't do this check.
if tokenInMaxs.Len() != 0 {
if !(neededLpLiquidity.DenomsSubsetOf(tokenInMaxs) && tokenInMaxs.IsAllGTE(neededLpLiquidity)) {
return nil, sdk.ZeroInt(), sdkerrors.Wrapf(types.ErrLimitMaxAmount, "TokenInMaxs is less than the needed LP liquidity to this JoinPoolNoSwap,"+
if !(neededLpLiquidity.DenomsSubsetOf(tokenInMaxs)) {
return nil, sdk.ZeroInt(), sdkerrors.Wrapf(types.ErrLimitMaxAmount, "TokenInMaxs does not include all the tokens that are part of the target pool,"+
" upperbound: %v, needed %v", tokenInMaxs, neededLpLiquidity)
} else if !(tokenInMaxs.DenomsSubsetOf(neededLpLiquidity)) {
return nil, sdk.ZeroInt(), sdkerrors.Wrapf(types.ErrDenomNotFoundInPool, "TokenInMaxs includes tokens that are not part of the target pool,"+
" input tokens: %v, pool tokens %v", tokenInMaxs, neededLpLiquidity)
}
if !(tokenInMaxs.IsAllGTE(neededLpLiquidity)) {
return nil, sdk.ZeroInt(), sdkerrors.Wrapf(types.ErrLimitMaxAmount, "TokenInMaxs is less than the needed LP liquidity to this JoinPoolNoSwap,"+
" upperbound: %v, needed %v", tokenInMaxs, neededLpLiquidity)
}
}
sharesOut, err = pool.JoinPoolNoSwap(ctx, neededLpLiquidity, pool.GetSwapFee(ctx))
......
......@@ -341,6 +341,15 @@ func (suite *KeeperTestSuite) TestJoinPoolNoSwap() {
},
expectPass: false,
},
{
name: "join no swap with TokenInMaxs not containing every token in pool",
txSender: suite.TestAccs[1],
sharesRequested: types.OneShare.MulRaw(50),
tokenInMaxs: sdk.Coins{
fiveKFooAndBar[0],
},
expectPass: false,
},
}
for _, test := range tests {
......
......@@ -89,7 +89,7 @@ func (msg MsgCreateBalancerPool) InitialLiquidity() sdk.Coins {
coins = append(coins, asset.Token)
}
if coins == nil {
panic("Shouldn't happen")
panic("InitialLiquidity coins is equal to nil - this shouldn't happen")
}
coins = coins.Sort()
return coins
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment