Skip to content

Commit

Permalink
adams suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
stackman27 committed Aug 2, 2023
1 parent 71433cc commit d64828a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
14 changes: 6 additions & 8 deletions app/upgrades/v17/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ func CreateUpgradeHandler(
CosmwasmWeight: 300,
})

// get all the existing CL pools
pools, err := keepers.ConcentratedLiquidityKeeper.GetPools(ctx)
// get all the existing CL pool Ids
poolIds, err := keepers.ConcentratedLiquidityKeeper.GetPoolIds(ctx)
if err != nil {
return nil, err
}

for _, pool := range pools {
// migrate twap records for CL Pools
err = FlipTwapSpotPriceRecords(ctx, []uint64{pool.GetId()}, keepers)
if err != nil {
return nil, err
}
// migrate twap records for CL Pools
err = FlipTwapSpotPriceRecords(ctx, poolIds, keepers)
if err != nil {
return nil, err
}

return migrations, nil
Expand Down
5 changes: 5 additions & 0 deletions app/upgrades/v17/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (suite *UpgradeTestSuite) TestUpgrade() {
upgradeSetup()
pool1 := suite.PrepareConcentratedPoolWithCoins("eth", "usdc")
pool2 := suite.PrepareConcentratedPoolWithCoins("uion", "uosmo")
suite.PrepareConcentratedPoolWithCoins("atom", "uosmo")

// create few TWAP records for the pools
t1 := dummyTwapRecord(pool1.GetId(), time.Unix(1257894000, 0).UTC(), "eth", "usdc", sdk.NewDec(2),
Expand All @@ -98,6 +99,10 @@ func (suite *UpgradeTestSuite) TestUpgrade() {
oldTwapRecordsPool2, err := suite.App.TwapKeeper.GetAllMostRecentRecordsForPool(suite.Ctx, 2)
suite.Require().NoError(err)

// this test is just to make sure that even thought we donot have TWAP record for poolId=3, it doesnot error
_, err = suite.App.TwapKeeper.GetAllMostRecentRecordsForPool(suite.Ctx, 3)
suite.Require().NoError(err)

// flip the twap records and see if the denoms actually flipped
dummyUpgrade(suite)
suite.Require().NotPanics(func() {
Expand Down
16 changes: 16 additions & 0 deletions x/concentrated-liquidity/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ func (k Keeper) GetPools(ctx sdk.Context) ([]poolmanagertypes.PoolI, error) {
)
}

// GetPoolIds returns all the poolIds for CL Pools
func (k Keeper) GetPoolIds(ctx sdk.Context) ([]uint64, error) {
poolIds := []uint64{}
// get all the existing CL pools
pools, err := k.GetPools(ctx)
if err != nil {
return nil, err
}

for _, pool := range pools {
poolIds = append(poolIds, pool.GetId())
}

return poolIds, nil
}

// setPool stores a ConcentratedPoolExtension in the Keeper's KVStore.
// It returns an error if the provided pool is not of type *model.Pool.
func (k Keeper) setPool(ctx sdk.Context, pool types.ConcentratedPoolExtension) error {
Expand Down

0 comments on commit d64828a

Please sign in to comment.