Skip to content

Commit

Permalink
chore: add validation of pool token amount in withraw
Browse files Browse the repository at this point in the history
  • Loading branch information
soring323 committed Jul 24, 2023
1 parent edd0837 commit 9217f71
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func (k msgServer) MultiAssetWithdraw(goCtx context.Context, msg *types.MsgMulti
return nil, errorsmod.Wrapf(types.ErrFailedDeposit, "invalid denom in local withdraw message:%s", msg.PoolToken.Denom)
}

tokenBalance := k.bankKeeper.GetBalance(ctx, sdk.AccAddress(msg.Receiver), msg.PoolId)
if tokenBalance.Amount.LT(msg.PoolToken.Amount) {
return nil, errorsmod.Wrapf(types.ErrFailedDeposit, "sender don't have enough pool token amount:%s", msg.PoolToken.Amount)
}

// PoolCoin.Denom is just poolID.
pool, found := k.GetInterchainLiquidityPool(ctx, msg.PoolToken.Denom)

Expand Down
6 changes: 3 additions & 3 deletions modules/apps/101-interchain-swap/types/market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ func TestSingleDeposit(t *testing.T) {
// }

func TestSwap(t *testing.T) {
const initialX = 4000000 // USDT
const initialY = 2000 // ETH
const initialX = 550000000000 // USDT
const initialY = 550000000000 // ETH
// create mock pool
denoms := []string{"a", "b"}
poolId := GetPoolId("test", "test", denoms)
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestSwap(t *testing.T) {
)
out, err := amm.LeftSwap(types.Coin{
Denom: denoms[0],
Amount: types.NewInt(100),
Amount: types.NewInt(5000),
},
denoms[1])

Expand Down

0 comments on commit 9217f71

Please sign in to comment.