Skip to content

Commit

Permalink
refactor!: return code ID in pools for quotes (#108)
Browse files Browse the repository at this point in the history
* refactor!: return code ID in pools for quotes

* changelog
  • Loading branch information
p0mvn authored Mar 16, 2024
1 parent 4e63f77 commit 1a34d37
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ Ref: https://keepachangelog.com/en/1.0.0/

# Changelog

## v0.10.0

* [#108](https://github.com/osmosis-labs/sqs/pull/107) Add code id (omitempty) to /quote route response
* [#107](https://github.com/osmosis-labs/sqs/pull/107) Invert spot price in quotes. Break quote API

## v0.9.1

Hot fix for white whale base quote confusion
Expand Down
5 changes: 5 additions & 0 deletions domain/mocks/pool_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ func (*MockRoutablePool) IsGeneralizedCosmWasmPool() bool {
return false
}

// GetCodeID implements sqsdomain.RoutablePool.
func (mp *MockRoutablePool) GetCodeID() uint64 {
return 0
}

func deepCopyPool(mp *MockRoutablePool) *MockRoutablePool {
newDenoms := make([]string, len(mp.Denoms))
copy(newDenoms, mp.Denoms)
Expand Down
5 changes: 5 additions & 0 deletions domain/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ var (
func (s *RouterTestSuite) TestPrepareResultPools() {
s.Setup()

const (
notCosmWasmPoolCodeID = 0
)

balancerPoolID := s.PrepareBalancerPoolWithCoins(sdk.NewCoins(
sdk.NewCoin(DenomOne, sdk.NewInt(1_000_000_000)),
sdk.NewCoin(DenomTwo, sdk.NewInt(1_000_000_000)),
Expand Down Expand Up @@ -111,6 +115,7 @@ func (s *RouterTestSuite) TestPrepareResultPools() {
DefaultSpreadFactor,
DenomOne,
DefaultTakerFee,
notCosmWasmPoolCodeID,
),
},
},
Expand Down
5 changes: 5 additions & 0 deletions router/usecase/pools/routable_balancer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,8 @@ func (r *routableBalancerPoolImpl) CalcSpotPrice(ctx context.Context, baseDenom
func (*routableBalancerPoolImpl) IsGeneralizedCosmWasmPool() bool {
return false
}

// GetCodeID implements sqsdomain.RoutablePool.
func (r *routableBalancerPoolImpl) GetCodeID() uint64 {
return notCosmWasmPoolCodeID
}
5 changes: 5 additions & 0 deletions router/usecase/pools/routable_concentrated_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,8 @@ func (r *routableConcentratedPoolImpl) CalcSpotPrice(ctx context.Context, baseDe
func (*routableConcentratedPoolImpl) IsGeneralizedCosmWasmPool() bool {
return false
}

// GetCodeID implements sqsdomain.RoutablePool.
func (r *routableConcentratedPoolImpl) GetCodeID() uint64 {
return notCosmWasmPoolCodeID
}
8 changes: 8 additions & 0 deletions router/usecase/pools/routable_cw_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const (
astroportPCLCodeID = 580
whiteWhaleCodeIDA = 503
whiteWhaleCodeIDB = 572

// placeholder for the code id of the pool that is not a cosm wasm pool
notCosmWasmPoolCodeID = 0
)

var _ sqsdomain.RoutablePool = &routableCosmWasmPoolImpl{}
Expand Down Expand Up @@ -141,3 +144,8 @@ func (r *routableCosmWasmPoolImpl) CalcSpotPrice(ctx context.Context, baseDenom
func (*routableCosmWasmPoolImpl) IsGeneralizedCosmWasmPool() bool {
return true
}

// GetCodeID implements sqsdomain.RoutablePool.
func (r *routableCosmWasmPoolImpl) GetCodeID() uint64 {
return r.ChainPool.CodeId
}
5 changes: 5 additions & 0 deletions router/usecase/pools/routable_cw_transmuter_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ func (r *routableTransmuterPoolImpl) CalcSpotPrice(ctx context.Context, baseDeno
func (*routableTransmuterPoolImpl) IsGeneralizedCosmWasmPool() bool {
return false
}

// GetCodeID implements sqsdomain.RoutablePool.
func (r *routableTransmuterPoolImpl) GetCodeID() uint64 {
return r.ChainPool.CodeId
}
9 changes: 8 additions & 1 deletion router/usecase/pools/routable_result_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@ type routableResultPoolImpl struct {
SpreadFactor osmomath.Dec "json:\"spread_factor\""
TokenOutDenom string "json:\"token_out_denom\""
TakerFee osmomath.Dec "json:\"taker_fee\""
CodeID uint64 "json:\"code_id,omitempty\""
}

// GetCodeID implements sqsdomain.RoutablePool.
func (r *routableResultPoolImpl) GetCodeID() uint64 {
panic("unimplemented")
}

// NewRoutableResultPool returns the new routable result pool with the given parameters.
func NewRoutableResultPool(ID uint64, poolType poolmanagertypes.PoolType, spreadFactor osmomath.Dec, tokenOutDenom string, takerFee osmomath.Dec) sqsdomain.RoutablePool {
func NewRoutableResultPool(ID uint64, poolType poolmanagertypes.PoolType, spreadFactor osmomath.Dec, tokenOutDenom string, takerFee osmomath.Dec, codeID uint64) sqsdomain.RoutablePool {
return &routableResultPoolImpl{
ID: ID,
Type: poolType,
SpreadFactor: spreadFactor,
TokenOutDenom: tokenOutDenom,
TakerFee: takerFee,
CodeID: codeID,
}
}

Expand Down
5 changes: 5 additions & 0 deletions router/usecase/pools/routable_stableswap_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,8 @@ func (r *routableStableswapPoolImpl) CalcSpotPrice(ctx context.Context, baseDeno
func (*routableStableswapPoolImpl) IsGeneralizedCosmWasmPool() bool {
return false
}

// GetCodeID implements sqsdomain.RoutablePool.
func (r *routableStableswapPoolImpl) GetCodeID() uint64 {
return notCosmWasmPoolCodeID
}
7 changes: 7 additions & 0 deletions router/usecase/quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ var (
func (s *RouterTestSuite) TestPrepareResult() {
s.SetupTest()

const (
notCosmWasmPoolCodeID = 0
)

var (
takerFeeOne = osmomath.NewDecWithPrec(2, 2)
takerFeeTwo = osmomath.NewDecWithPrec(4, 4)
Expand Down Expand Up @@ -181,13 +185,15 @@ func (s *RouterTestSuite) TestPrepareResult() {
poolOne.GetSpreadFactor(sdk.Context{}),
USDT,
takerFeeOne,
notCosmWasmPoolCodeID,
),
pools.NewRoutableResultPool(
poolIDTwo,
poolmanagertypes.Balancer,
poolTwo.GetSpreadFactor(sdk.Context{}),
USDC,
takerFeeTwo,
notCosmWasmPoolCodeID,
),
},
},
Expand All @@ -206,6 +212,7 @@ func (s *RouterTestSuite) TestPrepareResult() {
poolThree.GetSpreadFactor(sdk.Context{}),
USDC,
takerFeeThree,
notCosmWasmPoolCodeID,
),
},
},
Expand Down
1 change: 1 addition & 0 deletions router/usecase/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (r RouteImpl) PrepareResultPools(ctx context.Context, tokenIn sdk.Coin) ([]
pool.GetSpreadFactor(),
pool.GetTokenOutDenom(),
pool.GetTakerFee(),
pool.GetCodeID(),
)

newPools = append(newPools, newPool)
Expand Down
7 changes: 7 additions & 0 deletions router/usecase/route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ var (
func (s *RouterTestSuite) TestPrepareResultPools() {
s.Setup()

const (
notCosmWasmPoolCodeID = 0
)

balancerPoolID := s.PrepareBalancerPoolWithCoins(sdk.NewCoins(
sdk.NewCoin(DenomOne, sdk.NewInt(2_000_000_000)),
sdk.NewCoin(DenomTwo, sdk.NewInt(1_000_000_000)),
Expand Down Expand Up @@ -152,6 +156,7 @@ func (s *RouterTestSuite) TestPrepareResultPools() {
DefaultSpreadFactor,
DenomOne,
DefaultTakerFee,
notCosmWasmPoolCodeID,
),
},

Expand All @@ -177,13 +182,15 @@ func (s *RouterTestSuite) TestPrepareResultPools() {
DefaultSpreadFactor,
DenomOne,
DefaultTakerFee,
notCosmWasmPoolCodeID,
),
pools.NewRoutableResultPool(
transmuter.GetId(),
poolmanagertypes.CosmWasm,
DefaultSpreadFactor,
DenomThree,
DefaultTakerFee,
transmuter.GetCodeId(),
),
},

Expand Down
4 changes: 4 additions & 0 deletions sqsdomain/routable_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ type RoutablePool interface {
// in the router.
IsGeneralizedCosmWasmPool() bool

// GetCodeID returns the code ID of the pool if this is a CosmWasm pool.
// If this is not a CosmWasm pool, it returns 0.
GetCodeID() uint64

GetPoolDenoms() []string

GetTokenOutDenom() string
Expand Down

0 comments on commit 1a34d37

Please sign in to comment.