Skip to content

Commit

Permalink
refactor(gamm): improve error handling and messages when parsing pool…
Browse files Browse the repository at this point in the history
… assets (backport #2804) (#2901)

* resolve conflicts

* Update CHANGELOG.md

Co-authored-by: Roman <[email protected]>
  • Loading branch information
mergify[bot] and p0mvn authored Oct 1, 2022
1 parent 4b388b0 commit 06c9c84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#2739](https://github.com/osmosis-labs/osmosis/pull/2739) Add pool type query
* [#2803](https://github.com/osmosis-labs/osmosis/pull/2803) Fix total pool liquidity CLI query.

### Misc Improvements

* [#2804](https://github.com/osmosis-labs/osmosis/pull/2804) Improve error handling and messages when parsing pool assets.

## v12.0.0

This release includes several cosmwasm-developer and appchain-ecosystem affecting upgrades:
Expand Down
13 changes: 10 additions & 3 deletions x/gamm/pool-models/balancer/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,12 @@ func (p Pool) parsePoolAssetsByDenoms(tokenADenom, tokenBDenom string) (
) {
Aasset, found1 := getPoolAssetByDenom(p.PoolAssets, tokenADenom)
Basset, found2 := getPoolAssetByDenom(p.PoolAssets, tokenBDenom)
if !(found1 && found2) {
return Aasset, Basset, errors.New("one of the provided pool denoms does not exist in pool")

if !found1 {
return PoolAsset{}, PoolAsset{}, fmt.Errorf("(%s) does not exist in the pool", tokenADenom)
}
if !found2 {
return PoolAsset{}, PoolAsset{}, fmt.Errorf("(%s) does not exist in the pool", tokenBDenom)
}
return Aasset, Basset, nil
}
Expand All @@ -261,7 +265,10 @@ func (p Pool) parsePoolAssets(tokensA sdk.Coins, tokenBDenom string) (
return tokenA, Aasset, Basset, errors.New("expected tokensB to be of length one")
}
Aasset, Basset, err = p.parsePoolAssetsByDenoms(tokensA[0].Denom, tokenBDenom)
return tokensA[0], Aasset, Basset, err
if err != nil {
return sdk.Coin{}, PoolAsset{}, PoolAsset{}, err
}
return tokensA[0], Aasset, Basset, nil
}

func (p Pool) parsePoolAssetsCoins(tokensA sdk.Coins, tokensB sdk.Coins) (
Expand Down

0 comments on commit 06c9c84

Please sign in to comment.