Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(poolmanager): GetPoolDenoms method on PoolI for SQS (backport #6863) #6902

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### API Breaks

* [#6805](https://github.com/osmosis-labs/osmosis/pull/6805) return bucket index of the current tick from LiquidityPerTickRange query
<<<<<<< HEAD
=======
p0mvn marked this conversation as resolved.
Show resolved Hide resolved
* [#6530](https://github.com/osmosis-labs/osmosis/pull/6530) Improve error message when CL LP fails due to slippage bound hit.
p0mvn marked this conversation as resolved.
Show resolved Hide resolved
* [#6863](https://github.com/osmosis-labs/osmosis/pull/6863) GetPoolDenoms method on PoolI interface in poolmanager

### Bug Fixes

* [#6840](https://github.com/osmosis-labs/osmosis/pull/6840) fix: change TypeMsgUnbondConvertAndStake value to "unbond_convert_and_stake" and improve error message when epoch currentEpochStartHeight less than zero
* [#6769](https://github.com/osmosis-labs/osmosis/pull/6769) fix: improve dust handling in EstimateTradeBasedOnPriceImpact
* [#6841](https://github.com/osmosis-labs/osmosis/pull/6841) fix: fix receive_ack response field and imporove error message of InvalidCrosschainSwapsContract and NoDenomTrace
>>>>>>> 4c54425c (refactor(poolmanager): GetPoolDenoms method on PoolI for SQS (#6863))
p0mvn marked this conversation as resolved.
Show resolved Hide resolved

## v20.0.0

Expand Down
42 changes: 42 additions & 0 deletions tests/mocks/cfmm_pool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/mocks/cl_pool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/mocks/pool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions x/concentrated-liquidity/model/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,11 @@ func (p *Pool) ApplySwap(newLiquidity osmomath.Dec, newCurrentTick int64, newCur
func (p *Pool) AsSerializablePool() poolmanagertypes.PoolI {
return p
}

// GetPoolDenoms implements types.ConcentratedPoolExtension.
func (p *Pool) GetPoolDenoms(ctx sdk.Context) []string {
return []string{
p.GetToken0(),
p.GetToken1(),
}
}
17 changes: 17 additions & 0 deletions x/concentrated-liquidity/model/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,3 +857,20 @@ func (suite *ConcentratedPoolTestSuite) TestPoolSetMethods() {
})
}
}

// Test that the right denoms are returned.
func (s *ConcentratedPoolTestSuite) TestGetPoolDenoms() {
s.Setup()

const (
expectedDenom1 = "bar"
expectedDenom2 = "foo"
)

pool := s.PrepareConcentratedPoolWithCoins(expectedDenom1, expectedDenom2)

denoms := pool.GetPoolDenoms(s.Ctx)
s.Require().Equal(2, len(denoms))
s.Require().Equal(expectedDenom1, denoms[0])
s.Require().Equal(expectedDenom2, denoms[1])
}
7 changes: 7 additions & 0 deletions x/cosmwasmpool/model/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/osmosis/v20/x/cosmwasmpool/cosmwasm/msg"
"github.com/osmosis-labs/osmosis/v20/x/cosmwasmpool/types"
poolmanagertypes "github.com/osmosis-labs/osmosis/v20/x/poolmanager/types"
Expand Down Expand Up @@ -137,6 +138,12 @@ func (p *Pool) SetWasmKeeper(wasmKeeper types.WasmKeeper) {
p.WasmKeeper = wasmKeeper
}

// GetPoolDenoms implements types.PoolI.
func (p *Pool) GetPoolDenoms(ctx sdk.Context) []string {
poolLiquidity := p.GetTotalPoolLiquidity(ctx)
return osmoutils.CoinsDenoms(poolLiquidity)
}

func (p Pool) AsSerializablePool() poolmanagertypes.PoolI {
return &CosmWasmPool{
ContractAddress: p.ContractAddress,
Expand Down
7 changes: 7 additions & 0 deletions x/cosmwasmpool/model/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ func (s *CosmWasmPoolSuite) TestSpotPrice() {

s.Require().Equal(expectedSpotPrice, actualSpotPrice)
}

// TestGetPoolDenoms validates that pool denoms are returned correctly.
func (s *CosmWasmPoolSuite) TestGetPoolDenoms() {
cwPool := s.PrepareCosmWasmPool()
poolDenoms := cwPool.GetPoolDenoms(s.Ctx)
s.Require().Equal([]string{apptesting.DefaultTransmuterDenomA, apptesting.DefaultTransmuterDenomB}, poolDenoms)
}
5 changes: 5 additions & 0 deletions x/cosmwasmpool/model/store_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ func (p CosmWasmPool) GetStoreModel() poolmanagertypes.PoolI {
func (p CosmWasmPool) SetWasmKeeper(wasmKeeper types.WasmKeeper) {
panic("CosmWasmPool.SetWasmKeeeper not implemented")
}

// GetPoolDenoms implements types.PoolI.
func (p *CosmWasmPool) GetPoolDenoms(ctx sdk.Context) []string {
panic("CosmWasmPool.GetPoolDenoms not implemented")
}
7 changes: 7 additions & 0 deletions x/gamm/pool-models/balancer/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/osmosis/v20/x/gamm/pool-models/internal/cfmm_common"
"github.com/osmosis-labs/osmosis/v20/x/gamm/types"
poolmanagertypes "github.com/osmosis-labs/osmosis/v20/x/poolmanager/types"
Expand Down Expand Up @@ -982,3 +983,9 @@ func (p *Pool) ExitSwapExactAmountOut(
func (p *Pool) AsSerializablePool() poolmanagertypes.PoolI {
return p
}

// GetPoolDenoms implements types.CFMMPoolI.
func (p *Pool) GetPoolDenoms(ctx sdk.Context) []string {
liquidity := p.GetTotalPoolLiquidity(ctx)
return osmoutils.CoinsDenoms(liquidity)
}
20 changes: 19 additions & 1 deletion x/gamm/pool-models/balancer/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"
"testing"
time "time"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1363,3 +1363,21 @@ func TestCalcJoinPoolNoSwapShares(t *testing.T) {
})
}
}

// Test that the right denoms are returned.
func (s *KeeperTestSuite) TestGetPoolDenoms() {
const (
expectedDenom1 = "bar"
expectedDenom2 = "foo"
)

poolID := s.PrepareBalancerPoolWithCoins(sdk.NewCoin(expectedDenom1, osmomath.NewInt(100)), sdk.NewCoin(expectedDenom2, osmomath.NewInt(100)))

pool, err := s.App.PoolManagerKeeper.GetPool(s.Ctx, poolID)
s.Require().NoError(err)

denoms := pool.GetPoolDenoms(s.Ctx)
s.Require().Equal(2, len(denoms))
s.Require().Equal(expectedDenom1, denoms[0])
s.Require().Equal(expectedDenom2, denoms[1])
}
7 changes: 7 additions & 0 deletions x/gamm/pool-models/stableswap/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
errorsmod "cosmossdk.io/errors"

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/osmoutils"
"github.com/osmosis-labs/osmosis/v20/x/gamm/pool-models/internal/cfmm_common"
"github.com/osmosis-labs/osmosis/v20/x/gamm/types"
poolmanagertypes "github.com/osmosis-labs/osmosis/v20/x/poolmanager/types"
Expand Down Expand Up @@ -492,3 +493,9 @@ func applyScalingFactorMultiplier(scalingFactors []uint64) ([]uint64, error) {
func (p *Pool) AsSerializablePool() poolmanagertypes.PoolI {
return p
}

// GetPoolDenoms implements types.CFMMPoolI.
func (p *Pool) GetPoolDenoms(ctx sdk.Context) []string {
liquidity := p.GetTotalPoolLiquidity(ctx)
return osmoutils.CoinsDenoms(liquidity)
}
3 changes: 3 additions & 0 deletions x/poolmanager/types/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type PoolI interface {
// Returns whether the pool has swaps enabled at the moment
IsActive(ctx sdk.Context) bool

// GetPoolDenoms returns the pool's denoms.
GetPoolDenoms(sdk.Context) []string

// Returns the spot price of the 'base asset' in terms of the 'quote asset' in the pool,
// errors if either baseAssetDenom, or quoteAssetDenom does not exist.
// For example, if this was a UniV2 50-50 pool, with 2 ETH, and 8000 UST
Expand Down