Skip to content

Commit

Permalink
refactor: remove GetTotalShares, GetTotalLiquidity and GetExitFee fro…
Browse files Browse the repository at this point in the history
…m PoolI (#4801)

* refactor: remove GetTotalShares, GetTotalLiquidity and GetExitFee from PoolI

* godoc

* remove obsolete panic param

* move comment

* pool non pool

* fix exit fee problem
  • Loading branch information
p0mvn authored Mar 31, 2023
1 parent 3767fa1 commit 8ec7dad
Show file tree
Hide file tree
Showing 23 changed files with 550 additions and 132 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#4336](https://github.com/osmosis-labs/osmosis/pull/4336) Move epochs module into its own go.mod
* [#4658](https://github.com/osmosis-labs/osmosis/pull/4658) Deprecate x/gamm Pool query. The new one is located in x/poolmanager.
* [#4682](https://github.com/osmosis-labs/osmosis/pull/4682) Deprecate x/gamm SpotPrice v2 query. The new one is located in x/poolmanager.
* [#4801](https://github.com/osmosis-labs/osmosis/pull/4801) remove GetTotalShares, GetTotalLiquidity and GetExitFee from PoolI. Define all on CFMMPoolI, define GetTotalLiquidity on PoolModuleI only.


## v15.0.0

Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ localnet-state-export-clean: localnet-clean
localnet-cl-create-positions:
go run tests/cl-go-client/main.go

###############################################################################
### Go Mock ###
###############################################################################

go-mock-update-pool-module:
mockgen -source=x/poolmanager/types/routes.go -destination=tests/mocks/pool_module.go -package=mocks

.PHONY: all build-linux install format lint \
go-mod-cache draw-deps clean build build-contract-tests-hooks \
test test-all test-build test-cover test-unit test-race benchmark
12 changes: 8 additions & 4 deletions app/upgrades/v15/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,28 @@ func (suite *UpgradeTestSuite) TestMigrateBalancerToStablePools() {
suite.Require().NoError(err)

// shares before migration
balancerPool, err := gammKeeper.GetPool(suite.Ctx, poolID)
balancerPool, err := gammKeeper.GetCFMMPool(suite.Ctx, poolID)
balancerLiquidity, err := gammKeeper.GetTotalPoolLiquidity(suite.Ctx, balancerPool.GetId())
suite.Require().NoError(err)

balancerShares := balancerPool.GetTotalShares()
balancerLiquidity := balancerPool.GetTotalPoolLiquidity(ctx).String()
// check balancer pool liquidity using the bank module
balancerBalances := suite.App.BankKeeper.GetAllBalances(ctx, balancerPool.GetAddress())

// test migrating the balancer pool to a stable pool
v15.MigrateBalancerPoolToSolidlyStable(ctx, gammKeeper, poolmanagerKeeper, suite.App.BankKeeper, poolID)

// check that the pool is now a stable pool
stablepool, err := gammKeeper.GetPool(ctx, poolID)
stablepool, err := gammKeeper.GetCFMMPool(ctx, poolID)
suite.Require().NoError(err)
suite.Require().Equal(stablepool.GetType(), poolmanagertypes.Stableswap)

// check that the number of stableswap LP shares is the same as the number of balancer LP shares
suite.Require().Equal(balancerShares.String(), stablepool.GetTotalShares().String())
// check that the pool liquidity is the same
suite.Require().Equal(balancerLiquidity, stablepool.GetTotalPoolLiquidity(ctx).String())
stableLiquidity, err := gammKeeper.GetTotalPoolLiquidity(suite.Ctx, balancerPool.GetId())
suite.Require().NoError(err)
suite.Require().Equal(balancerLiquidity.String(), stableLiquidity.String())
// check pool liquidity using the bank module
stableBalances := suite.App.BankKeeper.GetAllBalances(ctx, stablepool.GetAddress())
suite.Require().Equal(balancerBalances, stableBalances)
Expand Down
9 changes: 7 additions & 2 deletions app/upgrades/v15/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ func migrateBalancerPoolsToSolidlyStable(ctx sdk.Context, gammKeeper *gammkeeper

func migrateBalancerPoolToSolidlyStable(ctx sdk.Context, gammKeeper *gammkeeper.Keeper, poolmanagerKeeper *poolmanager.Keeper, bankKeeper bankkeeper.Keeper, poolId uint64) {
// fetch the pool with the given poolId
balancerPool, err := gammKeeper.GetPool(ctx, poolId)
balancerPool, err := gammKeeper.GetCFMMPool(ctx, poolId)
if err != nil {
panic(err)
}

balancerPoolLiquidity, err := gammKeeper.GetTotalPoolLiquidity(ctx, poolId)
if err != nil {
panic(err)
}
Expand All @@ -98,7 +103,7 @@ func migrateBalancerPoolToSolidlyStable(ctx sdk.Context, gammKeeper *gammkeeper.
stableswapPool, err := stableswap.NewStableswapPool(
poolId,
stableswap.PoolParams{SwapFee: balancerPool.GetSwapFee(ctx), ExitFee: balancerPool.GetExitFee(ctx)},
balancerPool.GetTotalPoolLiquidity(ctx),
balancerPoolLiquidity,
[]uint64{1, 1},
"osmo1k8c2m5cn322akk5wy8lpt87dd2f4yh9afcd7af", // Stride Foundation 2/3 multisig
"",
Expand Down
271 changes: 269 additions & 2 deletions tests/mocks/pool_module.go

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

Loading

0 comments on commit 8ec7dad

Please sign in to comment.