Skip to content

Commit

Permalink
added balancer pool type
Browse files Browse the repository at this point in the history
  • Loading branch information
stackman27 committed Apr 24, 2023
1 parent e187780 commit df04795
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 9 deletions.
76 changes: 76 additions & 0 deletions x/concentrated-liquidity/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,79 @@ func (s *KeeperTestSuite) TestValidateAuthorizedQuoteDenoms() {
})
}
}

func (s *KeeperTestSuite) TestGetTotalPoolLiquidity() {
var (
defaultPoolCoinOne = sdk.NewCoin(USDC, sdk.OneInt())
defaultPoolCoinTwo = sdk.NewCoin(ETH, sdk.NewInt(2))
nonPoolCool = sdk.NewCoin("uosmo", sdk.NewInt(3))

defaultCoins = sdk.NewCoins(defaultPoolCoinOne, defaultPoolCoinTwo)
)

tests := []struct {
name string
poolId uint64
poolLiquidity sdk.Coins
expectedResult sdk.Coins
expectedErr error
}{
{
name: "valid with 2 coins",
poolId: defaultPoolId,
poolLiquidity: defaultCoins,
expectedResult: defaultCoins,
},
{
name: "valid with 1 coin",
poolId: defaultPoolId,
poolLiquidity: sdk.NewCoins(defaultPoolCoinTwo),
expectedResult: sdk.NewCoins(defaultPoolCoinTwo),
},
{
// can only happen if someone sends extra tokens to pool
// address. Should not occur in practice.
name: "valid with 3 coins",
poolId: defaultPoolId,
poolLiquidity: sdk.NewCoins(defaultPoolCoinTwo, defaultPoolCoinOne, nonPoolCool),
expectedResult: defaultCoins,
},
{
// this can happen if someone sends random dust to pool address.
name: "only non-pool coin - does not show up in result",
poolId: defaultPoolId,
poolLiquidity: sdk.NewCoins(nonPoolCool),
expectedResult: sdk.Coins(nil),
},
{
name: "invalid pool id",
poolId: defaultPoolId + 1,
expectedErr: types.PoolNotFoundError{PoolId: defaultPoolId + 1},
},
}

for _, tc := range tests {
tc := tc
s.Run(tc.name, func() {
s.SetupTest()

// Create default CL pool
pool := s.PrepareConcentratedPool()

s.FundAcc(pool.GetAddress(), tc.poolLiquidity)

// Get pool defined in test case
actual, err := s.App.ConcentratedLiquidityKeeper.GetTotalPoolLiquidity(s.Ctx, tc.poolId)

if tc.expectedErr != nil {
s.Require().Error(err)
s.Require().ErrorIs(err, tc.expectedErr)
s.Require().Nil(actual)
return
}

s.Require().NoError(err)
s.Require().Equal(tc.expectedResult, actual)
})
}
}
25 changes: 16 additions & 9 deletions x/poolmanager/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/golang/mock/gomock"

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v15/app/apptesting"
"github.com/osmosis-labs/osmosis/v15/tests/mocks"
cl "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity"
cltypes "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types"
Expand Down Expand Up @@ -2007,36 +2008,42 @@ func (s *KeeperTestSuite) TestGetTotalPoolLiquidity() {
expectedErr error
}{
{
name: "valid with 2 coins",
name: "CL Pool: valid with 2 coins",
poolId: 1,
poolLiquidity: defaultCoins,
expectedResult: defaultCoins,
},
{
name: "valid with 1 coin",
name: "CL Pool: valid with 1 coin",
poolId: 1,
poolLiquidity: sdk.NewCoins(defaultPoolCoinTwo),
expectedResult: sdk.NewCoins(defaultPoolCoinTwo),
},
{
// can only happen if someone sends extra tokens to pool
// address. Should not occur in practice.
name: "valid with 3 coins",
name: "CL Pool: valid with 3 coins",
poolId: 1,
poolLiquidity: sdk.NewCoins(defaultPoolCoinTwo, defaultPoolCoinOne, nonPoolCool),
expectedResult: defaultCoins,
},
{
// this can happen if someone sends random dust to pool address.
name: "only non-pool coin - does not show up in result",
name: "CL Pool:only non-pool coin - does not show up in result",
poolId: 1,
poolLiquidity: sdk.NewCoins(nonPoolCool),
expectedResult: sdk.Coins(nil),
},
{
name: "Balancer Pool: with default pool assets",
poolId: 2,
poolLiquidity: sdk.NewCoins(apptesting.DefaultPoolAssets[0].Token, apptesting.DefaultPoolAssets[1].Token, apptesting.DefaultPoolAssets[2].Token, apptesting.DefaultPoolAssets[3].Token),
expectedResult: sdk.NewCoins(apptesting.DefaultPoolAssets[0].Token, apptesting.DefaultPoolAssets[1].Token, apptesting.DefaultPoolAssets[2].Token, apptesting.DefaultPoolAssets[3].Token),
},
{
name: "round not found because pool id doesnot exist",
poolId: 2,
expectedErr: types.FailedToFindRouteError{PoolId: 2},
poolId: 3,
expectedErr: types.FailedToFindRouteError{PoolId: 3},
},
}

Expand All @@ -2046,13 +2053,13 @@ func (s *KeeperTestSuite) TestGetTotalPoolLiquidity() {
s.SetupTest()

// Create default CL pool
pool := s.PrepareConcentratedPool()
clPool := s.PrepareConcentratedPool()
s.PrepareBalancerPool()

s.FundAcc(pool.GetAddress(), tc.poolLiquidity)
s.FundAcc(clPool.GetAddress(), tc.poolLiquidity)

// Get pool defined in test case
actual, err := s.App.PoolManagerKeeper.GetTotalPoolLiquidity(s.Ctx, tc.poolId)

if tc.expectedErr != nil {
s.Require().Error(err)
s.Require().ErrorIs(err, tc.expectedErr)
Expand Down

0 comments on commit df04795

Please sign in to comment.