Skip to content

Commit

Permalink
x/gamm: Add check for correct input asset denoms to CalcJoinPoolShares (
Browse files Browse the repository at this point in the history
  • Loading branch information
AlpinYukseloglu authored Jul 5, 2022
1 parent c35d886 commit 49d632f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion x/gamm/pool-models/balancer/amm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions x/gamm/pool-models/balancer/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion x/superfluid/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 49d632f

Please sign in to comment.