Skip to content

Commit

Permalink
refactor(poolmanager): GetPoolDenoms method on PoolI for SQS (backport
Browse files Browse the repository at this point in the history
…#6863) (#6902)

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

* refactor(poolmanager): GetPoolDenoms method on PoolI for SQS

* changelog

* mocks

* change proto dep

* transmuter pool

* cfmm test

* CL test

(cherry picked from commit 4c54425)

# Conflicts:
#	CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Roman <roman@osmosis.team>
  • Loading branch information
mergify[bot] and p0mvn committed Nov 21, 2023
1 parent 4230756 commit eeb3af7
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ 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
* [#6863](https://github.com/osmosis-labs/osmosis/pull/6863) GetPoolDenoms method on PoolI interface in poolmanager


## 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

0 comments on commit eeb3af7

Please sign in to comment.