From 49d632f7717408fd4fe18795fbd3c07103e041df Mon Sep 17 00:00:00 2001 From: alpo <62043214+AlpinYukseloglu@users.noreply.github.com> Date: Tue, 5 Jul 2022 13:07:05 -0500 Subject: [PATCH] x/gamm: Add check for correct input asset denoms to CalcJoinPoolShares (#1931) --- CHANGELOG.md | 1 + x/gamm/pool-models/balancer/amm.go | 2 +- x/gamm/pool-models/balancer/pool.go | 9 +++++++++ x/superfluid/keeper/grpc_query.go | 3 ++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5af33dbbffe..b8b3207a9a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [1716](https://github.com/osmosis-labs/osmosis/pull/1716) Fix secondary over-LP shares bug with uneven swap amounts in `CalcJoinPoolShares`. * [1759](https://github.com/osmosis-labs/osmosis/pull/1759) Fix pagination filter in incentives query. * [1698](https://github.com/osmosis-labs/osmosis/pull/1698) Register wasm snapshotter extension. +* [1931](https://github.com/osmosis-labs/osmosis/pull/1931) Add explicit check for input denoms to `CalcJoinPoolShares` ## [v9.0.0 - Nitrogen](https://github.com/osmosis-labs/osmosis/releases/tag/v9.0.0) diff --git a/x/gamm/pool-models/balancer/amm.go b/x/gamm/pool-models/balancer/amm.go index cd05a5c3ef6..a574cef411d 100644 --- a/x/gamm/pool-models/balancer/amm.go +++ b/x/gamm/pool-models/balancer/amm.go @@ -161,7 +161,7 @@ func getPoolAssetsByDenom(poolAssets []PoolAsset) (map[string]PoolAsset, error) // updateIntermediaryPoolAssetsLiquidity updates poolAssetsByDenom with liquidity. // -// all liqidity coins must exist in poolAssetsByDenom. Returns error, if not. +// all liquidity coins must exist in poolAssetsByDenom. Returns error, if not. // // This is a helper function that is useful for updating the pool asset amounts // as an intermediary step in a multi-join methods such as CalcJoinPoolShares. diff --git a/x/gamm/pool-models/balancer/pool.go b/x/gamm/pool-models/balancer/pool.go index 45764549043..16c33bccb36 100644 --- a/x/gamm/pool-models/balancer/pool.go +++ b/x/gamm/pool-models/balancer/pool.go @@ -24,6 +24,7 @@ const ( errMsgFormatFailedInterimLiquidityUpdate = "failed to update interim liquidity - pool asset %s does not exist" errMsgFormatRepeatingPoolAssetsNotAllowed = "repeating pool assets not allowed, found %s" errMsgFormatNoPoolAssetFound = "can't find the PoolAsset (%s)" + errMsgFormatInvalidInputDenoms = "input denoms must already exist in the pool (%s)" ) var ( @@ -685,6 +686,14 @@ func (p *Pool) CalcJoinPoolShares(ctx sdk.Context, tokensIn sdk.Coins, swapFee s return sdk.ZeroInt(), sdk.NewCoins(), err } + // check to make sure the input denoms exist in the pool + for _, coin := range tokensIn { + _, ok := poolAssetsByDenom[coin.Denom] + if !ok { + return sdk.ZeroInt(), sdk.NewCoins(), fmt.Errorf(errMsgFormatInvalidInputDenoms, coin.Denom) + } + } + totalShares := p.GetTotalShares() if tokensIn.Len() == 1 { // 2) Single token provided, so do single asset join and exit. diff --git a/x/superfluid/keeper/grpc_query.go b/x/superfluid/keeper/grpc_query.go index 593b5d8074c..117b3741441 100644 --- a/x/superfluid/keeper/grpc_query.go +++ b/x/superfluid/keeper/grpc_query.go @@ -440,7 +440,8 @@ func (q Querier) TotalDelegationByDelegator(goCtx context.Context, req *types.Qu } superfluidDelegationResp, err := q.SuperfluidDelegationsByDelegator(goCtx, &types.SuperfluidDelegationsByDelegatorRequest{ - DelegatorAddress: req.DelegatorAddress}) + DelegatorAddress: req.DelegatorAddress, + }) if err != nil { return nil, err }