From 9f5d0cb78d12352abaa57b2a16b1bab7595b8b4a Mon Sep 17 00:00:00 2001 From: Deividas Petraitis Date: Thu, 21 Nov 2024 15:41:17 +0200 Subject: [PATCH] BE-654 | Fix Go tests --- domain/route_test.go | 2 + pools/usecase/pools_usecase_test.go | 2 +- router/usecase/pools/export_test.go | 3 +- router/usecase/pools/pool_factory_test.go | 5 +- router/usecase/quote_out_given_in.go | 4 +- router/usecase/quote_test.go | 6 + router/usecase/route/route_test.go | 3 + .../parsing/quote_amount_in_response.json | 100 +++++++-------- .../quote_amount_in_response_base_fee.json | 115 ++++++++--------- .../quote_amount_in_response_simulated.json | 116 +++++++++--------- .../parsing/quote_amount_out_response.json | 100 +++++++-------- router/usecase/routertesting/quote.go | 29 ++++- router/usecase/routertesting/suite.go | 1 + sqsdomain/pools.go | 7 +- 14 files changed, 272 insertions(+), 221 deletions(-) diff --git a/domain/route_test.go b/domain/route_test.go index 7f21646a7..685b8bdc8 100644 --- a/domain/route_test.go +++ b/domain/route_test.go @@ -42,6 +42,7 @@ var ( DefaultCoin0 = routertesting.DefaultCoin0 DefaultCoin1 = routertesting.DefaultCoin1 + DefaultLiquidityCap = routertesting.DefaultLiquidityCap DefaultLiquidityAmt = routertesting.DefaultLiquidityAmt // router specific variables @@ -117,6 +118,7 @@ func (s *RouterTestSuite) TestPrepareResultPools() { DefaultSpreadFactor, DenomOne, DefaultTakerFee, + DefaultLiquidityCap, notCosmWasmPoolCodeID, ), }, diff --git a/pools/usecase/pools_usecase_test.go b/pools/usecase/pools_usecase_test.go index 3b4137936..d521cf7be 100644 --- a/pools/usecase/pools_usecase_test.go +++ b/pools/usecase/pools_usecase_test.go @@ -551,7 +551,7 @@ func (s *PoolsUsecaseTestSuite) TestCalcExitCFMMPool_HappyPath() { s.Require().NoError(err) // Create sqs pool - sqsPool := sqsdomain.NewPool(cfmmPool, cfmmPool.GetSpreadFactor(s.Ctx), poolBalances) + sqsPool := sqsdomain.NewPool(cfmmPool, cfmmPool.GetSpreadFactor(s.Ctx), poolBalances, s.PoolOneLiquidityCap()) // Create default use case poolsUseCase := s.newDefaultPoolsUseCase() diff --git a/router/usecase/pools/export_test.go b/router/usecase/pools/export_test.go index 012c48302..15dcdaf0b 100644 --- a/router/usecase/pools/export_test.go +++ b/router/usecase/pools/export_test.go @@ -24,8 +24,9 @@ func NewRoutableCosmWasmPoolWithCustomModel( cosmWasmPoolsParams cosmwasmdomain.CosmWasmPoolsParams, tokenOutDenom string, takerFee osmomath.Dec, + liquidityCap osmomath.Int, ) (domain.RoutablePool, error) { - return newRoutableCosmWasmPoolWithCustomModel(pool, cosmwasmPool, cosmWasmPoolsParams, tokenOutDenom, takerFee) + return newRoutableCosmWasmPoolWithCustomModel(pool, cosmwasmPool, cosmWasmPoolsParams, tokenOutDenom, takerFee, liquidityCap) } func (r *routableAlloyTransmuterPoolImpl) CheckStaticRateLimiter(tokenInCoin sdk.Coin) error { diff --git a/router/usecase/pools/pool_factory_test.go b/router/usecase/pools/pool_factory_test.go index 6b04f4d23..8fa152ea0 100644 --- a/router/usecase/pools/pool_factory_test.go +++ b/router/usecase/pools/pool_factory_test.go @@ -66,6 +66,7 @@ func TestNewRoutableCosmWasmPoolWithCustomModel(t *testing.T) { cosmWasmConfig domain.CosmWasmPoolRouterConfig tokenOutDenom string takerFee osmomath.Dec + liquidityCap osmomath.Int expectedRoutablePool domain.RoutablePool expectedError error }{ @@ -137,6 +138,7 @@ func TestNewRoutableCosmWasmPoolWithCustomModel(t *testing.T) { }, tokenOutDenom: "quote", takerFee: orderbookTakerFee, + liquidityCap: osmomath.NewInt(851594865), expectedRoutablePool: &pools.RoutableOrderbookPoolImpl{ ChainPool: &orderbookCosmWasmPool, OrderbookData: orderbookModel.Data.Orderbook, @@ -144,6 +146,7 @@ func TestNewRoutableCosmWasmPoolWithCustomModel(t *testing.T) { TokenOutDenom: "quote", TakerFee: orderbookTakerFee, SpreadFactor: orderbookSpreadFactor, + LiquidityCap: osmomath.NewInt(851594865), }, }, { @@ -194,7 +197,7 @@ func TestNewRoutableCosmWasmPoolWithCustomModel(t *testing.T) { cosmWasmPoolsParams := cosmwasmdomain.CosmWasmPoolsParams{ Config: tt.cosmWasmConfig, } - routablePool, err := pools.NewRoutableCosmWasmPoolWithCustomModel(tt.pool, tt.cosmwasmPool, cosmWasmPoolsParams, tt.tokenOutDenom, tt.takerFee) + routablePool, err := pools.NewRoutableCosmWasmPoolWithCustomModel(tt.pool, tt.cosmwasmPool, cosmWasmPoolsParams, tt.tokenOutDenom, tt.takerFee, tt.liquidityCap) if tt.expectedError != nil { require.Equal(t, tt.expectedError, err) diff --git a/router/usecase/quote_out_given_in.go b/router/usecase/quote_out_given_in.go index 9e5800057..b2efb8c7a 100644 --- a/router/usecase/quote_out_given_in.go +++ b/router/usecase/quote_out_given_in.go @@ -92,7 +92,9 @@ func (q *quoteExactAmountIn) PrepareResult(ctx context.Context, scalingFactor os // Calculate total liquidity cap for the route for _, pool := range newPools { - totalLiquidityCap = totalLiquidityCap.Add(pool.GetLiquidityCap()) + if cap := pool.GetLiquidityCap(); !cap.IsNil() { + totalLiquidityCap = totalLiquidityCap.Add(pool.GetLiquidityCap()) + } } resultRoutes = append(resultRoutes, &RouteWithOutAmount{ diff --git a/router/usecase/quote_test.go b/router/usecase/quote_test.go index 10c80f2aa..7527f9d59 100644 --- a/router/usecase/quote_test.go +++ b/router/usecase/quote_test.go @@ -87,6 +87,7 @@ func (s *RouterTestSuite) TestPrepareResult() { poolOne.GetSpreadFactor(sdk.Context{}), USDT, takerFeeOne, + s.PoolOneLiquidityCap(), notCosmWasmPoolCodeID, ), pools.NewRoutableResultPool( @@ -95,6 +96,7 @@ func (s *RouterTestSuite) TestPrepareResult() { poolTwo.GetSpreadFactor(sdk.Context{}), USDC, takerFeeTwo, + s.PoolTwoLiquidityCap(), notCosmWasmPoolCodeID, ), }, @@ -114,6 +116,7 @@ func (s *RouterTestSuite) TestPrepareResult() { poolThree.GetSpreadFactor(sdk.Context{}), USDC, takerFeeThree, + s.PoolThreeLiquidityCap(), notCosmWasmPoolCodeID, ), }, @@ -140,6 +143,7 @@ func (s *RouterTestSuite) TestPrepareResult() { poolOne.GetSpreadFactor(sdk.Context{}), USDT, takerFeeOne, + s.PoolOneLiquidityCap(), notCosmWasmPoolCodeID, ), pools.NewExactAmountOutRoutableResultPool( @@ -148,6 +152,7 @@ func (s *RouterTestSuite) TestPrepareResult() { poolTwo.GetSpreadFactor(sdk.Context{}), USDC, takerFeeTwo, + s.PoolTwoLiquidityCap(), notCosmWasmPoolCodeID, ), }, @@ -165,6 +170,7 @@ func (s *RouterTestSuite) TestPrepareResult() { poolThree.GetSpreadFactor(sdk.Context{}), USDC, takerFeeThree, + s.PoolThreeLiquidityCap(), notCosmWasmPoolCodeID, ), }, diff --git a/router/usecase/route/route_test.go b/router/usecase/route/route_test.go index 6cb6c2c23..1cad8da62 100644 --- a/router/usecase/route/route_test.go +++ b/router/usecase/route/route_test.go @@ -157,6 +157,7 @@ func (s *RouterTestSuite) TestPrepareResultPools() { DefaultSpreadFactor, DenomOne, DefaultTakerFee, + osmomath.NewInt(3195955), notCosmWasmPoolCodeID, ), }, @@ -183,6 +184,7 @@ func (s *RouterTestSuite) TestPrepareResultPools() { DefaultSpreadFactor, DenomOne, DefaultTakerFee, + osmomath.NewInt(515881661), notCosmWasmPoolCodeID, ), pools.NewRoutableResultPool( @@ -191,6 +193,7 @@ func (s *RouterTestSuite) TestPrepareResultPools() { DefaultSpreadFactor, DenomThree, DefaultTakerFee, + osmomath.NewInt(71519599), transmuter.GetCodeId(), ), }, diff --git a/router/usecase/routertesting/parsing/quote_amount_in_response.json b/router/usecase/routertesting/parsing/quote_amount_in_response.json index beeb74174..82c4216f4 100644 --- a/router/usecase/routertesting/parsing/quote_amount_in_response.json +++ b/router/usecase/routertesting/parsing/quote_amount_in_response.json @@ -1,50 +1,54 @@ { - "amount_in": { - "denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5", - "amount": "10000000" - }, - "amount_out": "40000000", - "route": [ - { - "pools": [ - { - "id": 1, - "type": 0, - "balances": [], - "spread_factor": "0.010000000000000000", - "token_out_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB", - "taker_fee": "0.020000000000000000" - }, - { - "id": 2, - "type": 0, - "balances": [], - "spread_factor": "0.030000000000000000", - "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - "taker_fee": "0.000400000000000000" - } - ], - "has-cw-pool": false, - "out_amount": "20000000", - "in_amount": "5000000" - }, - { - "pools": [ - { - "id": 3, - "type": 0, - "balances": [], - "spread_factor": "0.005000000000000000", - "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - "taker_fee": "0.003000000000000000" - } - ], - "has-cw-pool": false, - "out_amount": "20000000", - "in_amount": "5000000" - } - ], - "effective_fee": "0.011696000000000000", - "price_impact": "-0.565353638051463862", - "in_base_out_quote_spot_price": "4.500000000000000000" + "amount_in": { + "denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5", + "amount": "10000000" + }, + "amount_out": "40000000", + "route": [ + { + "pools": [ + { + "id": 1, + "type": 0, + "balances": [], + "spread_factor": "0.010000000000000000", + "token_out_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB", + "taker_fee": "0.020000000000000000", + "liquidity_cap": "1519153195" + }, + { + "id": 2, + "type": 0, + "balances": [], + "spread_factor": "0.030000000000000000", + "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", + "taker_fee": "0.000400000000000000", + "liquidity_cap": "85196078" + } + ], + "has-cw-pool": false, + "out_amount": "20000000", + "in_amount": "5000000" + }, + { + "pools": [ + { + "id": 3, + "type": 0, + "balances": [], + "spread_factor": "0.005000000000000000", + "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", + "taker_fee": "0.003000000000000000", + "liquidity_cap": "719951" + } + ], + "has-cw-pool": false, + "out_amount": "20000000", + "in_amount": "5000000" + } + ], + "liquidity_cap": "1605069224", + "effective_fee": "0.011696000000000000", + "price_impact": "-0.565353638051463862", + "in_base_out_quote_spot_price": "4.500000000000000000" } diff --git a/router/usecase/routertesting/parsing/quote_amount_in_response_base_fee.json b/router/usecase/routertesting/parsing/quote_amount_in_response_base_fee.json index d0e944600..c8068e184 100644 --- a/router/usecase/routertesting/parsing/quote_amount_in_response_base_fee.json +++ b/router/usecase/routertesting/parsing/quote_amount_in_response_base_fee.json @@ -1,57 +1,60 @@ { - "amount_in": { - "denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5", - "amount": "10000000" - }, - "amount_out": "40000000", - "route": [ - { - "pools": [ - { - "id": 1, - "type": 0, - "balances": [], - "spread_factor": "0.010000000000000000", - "token_out_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB", - "taker_fee": "0.020000000000000000" - }, - { - "id": 2, - "type": 0, - "balances": [], - "spread_factor": "0.030000000000000000", - "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - "taker_fee": "0.000400000000000000" - } - ], - "has-cw-pool": false, - "out_amount": "20000000", - "in_amount": "5000000" - }, - { - "pools": [ - { - "id": 3, - "type": 0, - "balances": [], - "spread_factor": "0.005000000000000000", - "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - "taker_fee": "0.003000000000000000" - } - ], - "has-cw-pool": false, - "out_amount": "20000000", - "in_amount": "5000000" - } - ], - "effective_fee": "0.011696000000000000", - "price_impact": "-0.565353638051463862", - "in_base_out_quote_spot_price": "4.500000000000000000", - "price_info": { - "fee_coin": { - "amount": "0" - }, - "base_fee": "0.500000000000000000" - } - } - \ No newline at end of file + "amount_in": { + "denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5", + "amount": "10000000" + }, + "amount_out": "40000000", + "route": [ + { + "pools": [ + { + "id": 1, + "type": 0, + "balances": [], + "spread_factor": "0.010000000000000000", + "token_out_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB", + "taker_fee": "0.020000000000000000", + "liquidity_cap": "1519153195" + }, + { + "id": 2, + "type": 0, + "balances": [], + "spread_factor": "0.030000000000000000", + "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", + "taker_fee": "0.000400000000000000", + "liquidity_cap": "85196078" + } + ], + "has-cw-pool": false, + "out_amount": "20000000", + "in_amount": "5000000" + }, + { + "pools": [ + { + "id": 3, + "type": 0, + "balances": [], + "spread_factor": "0.005000000000000000", + "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", + "taker_fee": "0.003000000000000000", + "liquidity_cap": "719951" + } + ], + "has-cw-pool": false, + "out_amount": "20000000", + "in_amount": "5000000" + } + ], + "liquidity_cap": "1605069224", + "effective_fee": "0.011696000000000000", + "price_impact": "-0.565353638051463862", + "in_base_out_quote_spot_price": "4.500000000000000000", + "price_info": { + "fee_coin": { + "amount": "0" + }, + "base_fee": "0.500000000000000000" + } +} diff --git a/router/usecase/routertesting/parsing/quote_amount_in_response_simulated.json b/router/usecase/routertesting/parsing/quote_amount_in_response_simulated.json index e034fadc6..a9d03ad53 100644 --- a/router/usecase/routertesting/parsing/quote_amount_in_response_simulated.json +++ b/router/usecase/routertesting/parsing/quote_amount_in_response_simulated.json @@ -1,58 +1,62 @@ { - "amount_in": { - "denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5", - "amount": "10000000" - }, - "amount_out": "40000000", - "route": [ - { - "pools": [ - { - "id": 1, - "type": 0, - "balances": [], - "spread_factor": "0.010000000000000000", - "token_out_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB", - "taker_fee": "0.020000000000000000" - }, - { - "id": 2, - "type": 0, - "balances": [], - "spread_factor": "0.030000000000000000", - "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - "taker_fee": "0.000400000000000000" - } - ], - "has-cw-pool": false, - "out_amount": "20000000", - "in_amount": "5000000" - }, - { - "pools": [ - { - "id": 3, - "type": 0, - "balances": [], - "spread_factor": "0.005000000000000000", - "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - "taker_fee": "0.003000000000000000" - } - ], - "has-cw-pool": false, - "out_amount": "20000000", - "in_amount": "5000000" - } - ], - "effective_fee": "0.011696000000000000", - "price_impact": "-0.565353638051463862", - "in_base_out_quote_spot_price": "4.500000000000000000", - "price_info": { - "adjusted_gas_used": 1000000, - "fee_coin": { - "denom": "uosmo", - "amount": "1000" - }, - "base_fee": "0.500000000000000000" - } + "amount_in": { + "denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5", + "amount": "10000000" + }, + "amount_out": "40000000", + "route": [ + { + "pools": [ + { + "id": 1, + "type": 0, + "balances": [], + "spread_factor": "0.010000000000000000", + "token_out_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB", + "taker_fee": "0.020000000000000000", + "liquidity_cap": "1519153195" + }, + { + "id": 2, + "type": 0, + "balances": [], + "spread_factor": "0.030000000000000000", + "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", + "taker_fee": "0.000400000000000000", + "liquidity_cap": "85196078" + } + ], + "has-cw-pool": false, + "out_amount": "20000000", + "in_amount": "5000000" + }, + { + "pools": [ + { + "id": 3, + "type": 0, + "balances": [], + "spread_factor": "0.005000000000000000", + "token_out_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", + "taker_fee": "0.003000000000000000", + "liquidity_cap": "719951" + } + ], + "has-cw-pool": false, + "out_amount": "20000000", + "in_amount": "5000000" + } + ], + "liquidity_cap": "1605069224", + "effective_fee": "0.011696000000000000", + "price_impact": "-0.565353638051463862", + "in_base_out_quote_spot_price": "4.500000000000000000", + "price_info": { + "adjusted_gas_used": 1000000, + "fee_coin": { + "denom": "uosmo", + "amount": "1000" + }, + "base_fee": "0.500000000000000000" + } } diff --git a/router/usecase/routertesting/parsing/quote_amount_out_response.json b/router/usecase/routertesting/parsing/quote_amount_out_response.json index bf873d501..bbd6e93f7 100644 --- a/router/usecase/routertesting/parsing/quote_amount_out_response.json +++ b/router/usecase/routertesting/parsing/quote_amount_out_response.json @@ -1,50 +1,54 @@ { - "amount_in": "40000000", - "amount_out": { - "denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5", - "amount": "10000000" - }, - "route": [ - { - "pools": [ - { - "id": 1, - "type": 0, - "balances": [], - "spread_factor": "0.010000000000000000", - "token_in_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB", - "taker_fee": "0.020000000000000000" - }, - { - "id": 2, - "type": 0, - "balances": [], - "spread_factor": "0.030000000000000000", - "token_in_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - "taker_fee": "0.000400000000000000" - } - ], - "has-cw-pool": false, - "out_amount": "5000000", - "in_amount": "13333333" - }, - { - "pools": [ - { - "id": 3, - "type": 0, - "balances": [], - "spread_factor": "0.005000000000000000", - "token_in_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", - "taker_fee": "0.003000000000000000" - } - ], - "has-cw-pool": false, - "out_amount": "2500000", - "in_amount": "8000000" - } - ], - "effective_fee": "0.010946000000000000", - "price_impact": "-0.593435820925030124", - "in_base_out_quote_spot_price": "3.500000000000000000" + "amount_in": "40000000", + "amount_out": { + "denom": "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5", + "amount": "10000000" + }, + "route": [ + { + "pools": [ + { + "id": 1, + "type": 0, + "balances": [], + "spread_factor": "0.010000000000000000", + "token_in_denom": "ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB", + "taker_fee": "0.020000000000000000", + "liquidity_cap": "1519153195" + }, + { + "id": 2, + "type": 0, + "balances": [], + "spread_factor": "0.030000000000000000", + "token_in_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", + "taker_fee": "0.000400000000000000", + "liquidity_cap": "85196078" + } + ], + "has-cw-pool": false, + "out_amount": "5000000", + "in_amount": "13333333" + }, + { + "pools": [ + { + "id": 3, + "type": 0, + "balances": [], + "spread_factor": "0.005000000000000000", + "token_in_denom": "ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", + "taker_fee": "0.003000000000000000", + "liquidity_cap": "719951" + } + ], + "has-cw-pool": false, + "out_amount": "2500000", + "in_amount": "8000000" + } + ], + "liquidity_cap": "1605069224", + "effective_fee": "0.010946000000000000", + "price_impact": "-0.593435820925030124", + "in_base_out_quote_spot_price": "3.500000000000000000" } diff --git a/router/usecase/routertesting/quote.go b/router/usecase/routertesting/quote.go index 520675781..fdae38c53 100644 --- a/router/usecase/routertesting/quote.go +++ b/router/usecase/routertesting/quote.go @@ -39,12 +39,29 @@ var ( sdk.NewCoin(ETH, defaultAmount), sdk.NewCoin(USDC, defaultAmount.MulRaw(4)), ) + + poolOneLiquidityCap = osmomath.NewInt(151_9153_195) + poolTwoLiquidityCap = osmomath.NewInt(85_196_078) + poolThreeLiquidityCap = osmomath.NewInt(719_951) ) +func (s *RouterTestHelper) PoolOneLiquidityCap() osmomath.Int { + return poolOneLiquidityCap +} + +func (s *RouterTestHelper) PoolTwoLiquidityCap() osmomath.Int { + return poolTwoLiquidityCap +} + +func (s *RouterTestHelper) PoolThreeLiquidityCap() osmomath.Int { + return poolThreeLiquidityCap +} + func (s *RouterTestHelper) newRoutablePool(pool sqsdomain.PoolI, tokenOutDenom string, takerFee osmomath.Dec) domain.RoutablePool { cosmWasmPoolsParams := cosmwasmdomain.CosmWasmPoolsParams{ ScalingFactorGetterCb: domain.UnsetScalingFactorGetterCb, } + routablePool, err := pools.NewRoutablePool(pool, tokenOutDenom, takerFee, cosmWasmPoolsParams) s.Require().NoError(err) @@ -65,12 +82,12 @@ func (s *RouterTestHelper) NewExactAmountInQuote(p1, p2, p3 poolmanagertypes.Poo RouteImpl: route.RouteImpl{ Pools: []domain.RoutablePool{ s.newRoutablePool( - sqsdomain.NewPool(p1, p1.GetSpreadFactor(sdk.Context{}), poolOneBalances), + sqsdomain.NewPool(p1, p1.GetSpreadFactor(sdk.Context{}), poolOneBalances, poolOneLiquidityCap), USDT, takerFeeOne, ), s.newRoutablePool( - sqsdomain.NewPool(p2, p2.GetSpreadFactor(sdk.Context{}), poolTwoBalances), + sqsdomain.NewPool(p2, p2.GetSpreadFactor(sdk.Context{}), poolTwoBalances, poolTwoLiquidityCap), USDC, takerFeeTwo, ), @@ -86,7 +103,7 @@ func (s *RouterTestHelper) NewExactAmountInQuote(p1, p2, p3 poolmanagertypes.Poo RouteImpl: route.RouteImpl{ Pools: []domain.RoutablePool{ s.newRoutablePool( - sqsdomain.NewPool(p3, p3.GetSpreadFactor(sdk.Context{}), poolThreeBalances), + sqsdomain.NewPool(p3, p3.GetSpreadFactor(sdk.Context{}), poolThreeBalances, poolThreeLiquidityCap), USDC, takerFeeThree, ), @@ -114,12 +131,12 @@ func (s *RouterTestHelper) NewExactAmountOutQuote(p1, p2, p3 poolmanagertypes.Po RouteImpl: route.RouteImpl{ Pools: []domain.RoutablePool{ s.newRoutablePool( - sqsdomain.NewPool(p1, p1.GetSpreadFactor(sdk.Context{}), poolOneBalances), + sqsdomain.NewPool(p1, p1.GetSpreadFactor(sdk.Context{}), poolOneBalances, poolOneLiquidityCap), USDT, takerFeeOne, ), s.newRoutablePool( - sqsdomain.NewPool(p2, p2.GetSpreadFactor(sdk.Context{}), poolTwoBalances), + sqsdomain.NewPool(p2, p2.GetSpreadFactor(sdk.Context{}), poolTwoBalances, poolTwoLiquidityCap), USDC, takerFeeTwo, ), @@ -133,7 +150,7 @@ func (s *RouterTestHelper) NewExactAmountOutQuote(p1, p2, p3 poolmanagertypes.Po RouteImpl: route.RouteImpl{ Pools: []domain.RoutablePool{ s.newRoutablePool( - sqsdomain.NewPool(p3, p3.GetSpreadFactor(sdk.Context{}), poolThreeBalances), + sqsdomain.NewPool(p3, p3.GetSpreadFactor(sdk.Context{}), poolThreeBalances, poolThreeLiquidityCap), USDC, takerFeeThree, ), diff --git a/router/usecase/routertesting/suite.go b/router/usecase/routertesting/suite.go index 097bae0ea..09ddfdfd1 100644 --- a/router/usecase/routertesting/suite.go +++ b/router/usecase/routertesting/suite.go @@ -79,6 +79,7 @@ var ( DefaultCoin1 = apptesting.DefaultCoin1 DefaultLiquidityAmt = apptesting.DefaultLiquidityAmt + DefaultLiquidityCap = osmomath.NewInt(10) // router specific variables DefaultTickModel = &sqsdomain.TickModel{ diff --git a/sqsdomain/pools.go b/sqsdomain/pools.go index 6ce6b71a6..b85868467 100644 --- a/sqsdomain/pools.go +++ b/sqsdomain/pools.go @@ -99,12 +99,13 @@ type PoolWrapper struct { var _ PoolI = &PoolWrapper{} -func NewPool(model poolmanagertypes.PoolI, spreadFactor osmomath.Dec, balances sdk.Coins) PoolI { +func NewPool(model poolmanagertypes.PoolI, spreadFactor osmomath.Dec, balances sdk.Coins, liquidityCap osmomath.Int) PoolI { return &PoolWrapper{ ChainModel: model, SQSModel: SQSPool{ - SpreadFactor: spreadFactor, - Balances: balances, + SpreadFactor: spreadFactor, + Balances: balances, + PoolLiquidityCap: liquidityCap, }, } }