diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f3bea15fee..dad1090553e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/x/gamm/pool-models/balancer/pool.go b/x/gamm/pool-models/balancer/pool.go index b49b83451d9..c9315c81b0f 100644 --- a/x/gamm/pool-models/balancer/pool.go +++ b/x/gamm/pool-models/balancer/pool.go @@ -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 } @@ -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) (