Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: incentive accumulator migration #7416

Merged
merged 38 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
246e5f1
feat: scaling factor for pool uptime accumulator
p0mvn Feb 2, 2024
99022a2
changelog
p0mvn Feb 3, 2024
213cec6
updates
p0mvn Feb 5, 2024
04a91c6
updates
p0mvn Feb 5, 2024
880e3d1
Merge branch 'main' into roman/pool-incentive-scaling-factor
p0mvn Feb 5, 2024
1367d0c
handle overflows
p0mvn Feb 5, 2024
748edd8
Apply suggestions from code review
p0mvn Feb 5, 2024
3158f90
updates
p0mvn Feb 5, 2024
f76b9cb
Apply suggestions from code review
p0mvn Feb 5, 2024
f254a26
fix test and clean up
p0mvn Feb 5, 2024
e36f4a1
spelling
p0mvn Feb 5, 2024
9e10789
future proof multiplication overflow
p0mvn Feb 6, 2024
de4b9ba
clean up
p0mvn Feb 6, 2024
8a43a0b
comment
p0mvn Feb 6, 2024
bab4173
lint
p0mvn Feb 6, 2024
fea2d75
Merge branch 'main' into roman/pool-incentive-scaling-factor
p0mvn Feb 7, 2024
5ac3e97
rename
p0mvn Feb 7, 2024
2d49b83
feat: incentive accumulator upgrade handler migration
p0mvn Feb 6, 2024
c5decc9
lint
p0mvn Feb 6, 2024
b1ee555
go mod
p0mvn Feb 6, 2024
32aa8c9
fix test
p0mvn Feb 6, 2024
53bd32d
implement TestMigrateAccumulatorToScalingFactor
p0mvn Feb 7, 2024
c65aaa8
basic genesis test
p0mvn Feb 7, 2024
b58ccbf
fix comment
p0mvn Feb 7, 2024
c03d5e8
clean up tests
p0mvn Feb 7, 2024
e1f07d3
clean up helpers
p0mvn Feb 7, 2024
52b389a
add test for get position IDs by pool ID
p0mvn Feb 7, 2024
3f30364
test for getIncentiveScalingFactorForPool
p0mvn Feb 7, 2024
0004a14
upgrade handler test and tick migration
p0mvn Feb 7, 2024
ab7fa11
update spec
p0mvn Feb 7, 2024
99e3a8d
Merge branch 'main' into roman/upgrade-handler-migration
p0mvn Feb 7, 2024
c9bc00f
Merge branch 'main' into roman/upgrade-handler-migration
p0mvn Feb 8, 2024
7778fe1
updates
p0mvn Feb 8, 2024
68020b1
updates
p0mvn Feb 8, 2024
06c3ad1
feat/fix: add more pools to migrate, fix key parsing bug, add more lo…
p0mvn Feb 9, 2024
56b8146
introduce helper
p0mvn Feb 9, 2024
4ef439b
Update x/concentrated-liquidity/pool.go
p0mvn Feb 9, 2024
71b47b6
Merge branch 'main' into roman/upgrade-handler-migration
mergify[bot] Feb 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions app/upgrades/v23/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v23

import (
"sort"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
Expand All @@ -9,8 +11,12 @@ import (

"github.com/osmosis-labs/osmosis/v23/app/keepers"
"github.com/osmosis-labs/osmosis/v23/app/upgrades"
concentratedliquidity "github.com/osmosis-labs/osmosis/v23/x/concentrated-liquidity"
concentratedtypes "github.com/osmosis-labs/osmosis/v23/x/concentrated-liquidity/types"
)

const mainnetChainID = "osmosis-1"

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
Expand All @@ -27,6 +33,45 @@ func CreateUpgradeHandler(

keepers.IncentivesKeeper.SetParam(ctx, incentivestypes.KeyInternalUptime, incentivestypes.DefaultConcentratedUptime)

// Snapshot the pool ID migration threshold
// Get the next pool ID
nextPoolId := keepers.PoolManagerKeeper.GetNextPoolId(ctx)

lastPoolID := nextPoolId - 1

keepers.ConcentratedLiquidityKeeper.SetIncentivePoolIDMigrationThreshold(ctx, lastPoolID)

// We only perform the migration on mainnet pools since we hard-coded the pool IDs to migrate
// in the types package. To ensure correctness, we will spin up a state-exported mainnet testnet
// with the same chain ID.
if ctx.ChainID() == mainnetChainID {
if err := migrateMainnetPools(ctx, *keepers.ConcentratedLiquidityKeeper); err != nil {
return nil, err
}
}

return migrations, nil
}
}

// migrateMainnetPools migrates the specified mainnet pools to the new accumulator scaling factor.
func migrateMainnetPools(ctx sdk.Context, concentratedKeeper concentratedliquidity.Keeper) error {
poolIDsToMigrate := make([]uint64, 0, len(concentratedtypes.MigratedIncentiveAccumulatorPoolIDs))
for poolID := range concentratedtypes.MigratedIncentiveAccumulatorPoolIDs {
poolIDsToMigrate = append(poolIDsToMigrate, poolID)
}

// Sort for determinism
sort.Slice(poolIDsToMigrate, func(i, j int) bool {
return poolIDsToMigrate[i] < poolIDsToMigrate[j]
})

// Migrate concentrated pools
for _, poolId := range poolIDsToMigrate {
if err := concentratedKeeper.MigrateAccumulatorToScalingFactor(ctx, poolId); err != nil {
return err
}
}

return nil
}
122 changes: 122 additions & 0 deletions app/upgrades/v23/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package v23_test

import (
"testing"
"time"

"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

abci "github.com/cometbft/cometbft/abci/types"

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v23/app/apptesting"

concentratedtypes "github.com/osmosis-labs/osmosis/v23/x/concentrated-liquidity/types"
)

const (
v23UpgradeHeight = int64(10)
)

type UpgradeTestSuite struct {
apptesting.KeeperTestHelper
}

func TestUpgradeTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()

// Set the migration pool ID threshold to far away to simulate pre-migration state.
s.App.ConcentratedLiquidityKeeper.SetIncentivePoolIDMigrationThreshold(s.Ctx, 1000)

concentratedPoolIDs := []uint64{}

// Create two sets of all pools
allPoolsOne := s.PrepareAllSupportedPools()
allPoolsTwo := s.PrepareAllSupportedPools()

concentratedPoolIDs = append(concentratedPoolIDs, allPoolsOne.ConcentratedPoolID)
concentratedPoolIDs = append(concentratedPoolIDs, allPoolsTwo.ConcentratedPoolID)

// Update authorized quote denoms
concentratedParams := s.App.ConcentratedLiquidityKeeper.GetParams(s.Ctx)
concentratedParams.AuthorizedQuoteDenoms = append(concentratedParams.AuthorizedQuoteDenoms, apptesting.USDC)
s.App.ConcentratedLiquidityKeeper.SetParams(s.Ctx, concentratedParams)

// Create two more concentrated pools with positions
secondLastPoolID := s.App.PoolManagerKeeper.GetNextPoolId(s.Ctx)
lastPoolID := secondLastPoolID + 1
concentratedPoolIDs = append(concentratedPoolIDs, secondLastPoolID)
concentratedPoolIDs = append(concentratedPoolIDs, lastPoolID)
s.CreateConcentratedPoolsAndFullRangePosition([][]string{
{"uion", "uosmo"},
{apptesting.ETH, apptesting.USDC},
})

lastPoolPositionID := s.App.ConcentratedLiquidityKeeper.GetNextPositionId(s.Ctx) - 1

// Create incentive record for last pool
incentiveCoin := sdk.NewCoin("uosmo", sdk.NewInt(1000000))
_, err := s.App.ConcentratedLiquidityKeeper.CreateIncentive(s.Ctx, lastPoolID, s.TestAccs[0], incentiveCoin, osmomath.OneDec(), s.Ctx.BlockTime(), concentratedtypes.DefaultAuthorizedUptimes[0])
s.Require().NoError(err)

// Create incentive record for second last pool
_, err = s.App.ConcentratedLiquidityKeeper.CreateIncentive(s.Ctx, secondLastPoolID, s.TestAccs[0], incentiveCoin, osmomath.OneDec(), s.Ctx.BlockTime(), concentratedtypes.DefaultAuthorizedUptimes[0])
s.Require().NoError(err)

// Make 60 seconds pass
s.Ctx = s.Ctx.WithBlockTime(s.Ctx.BlockTime().Add(time.Minute))

err = s.App.ConcentratedLiquidityKeeper.UpdatePoolUptimeAccumulatorsToNow(s.Ctx, lastPoolID)
s.Require().NoError(err)

// Migrated pool claim
migratedPoolBeforeUpgradeIncentives, _, err := s.App.ConcentratedLiquidityKeeper.GetClaimableIncentives(s.Ctx, lastPoolPositionID)
s.Require().NoError(err)
s.Require().NotEmpty(migratedPoolBeforeUpgradeIncentives)

// Non-migrated pool claim
nonMigratedPoolBeforeUpgradeIncentives, _, err := s.App.ConcentratedLiquidityKeeper.GetClaimableIncentives(s.Ctx, lastPoolPositionID-1)
s.Require().NoError(err)
s.Require().NotEmpty(nonMigratedPoolBeforeUpgradeIncentives)

// Overwrite the migration list with the desired pool ID.
oldMigrationList := concentratedtypes.MigratedIncentiveAccumulatorPoolIDs
concentratedtypes.MigratedIncentiveAccumulatorPoolIDs = map[uint64]struct{}{}
concentratedtypes.MigratedIncentiveAccumulatorPoolIDs[lastPoolID] = struct{}{}

dummyUpgrade(s)
s.Require().NotPanics(func() {
s.App.BeginBlocker(s.Ctx, abci.RequestBeginBlock{})
})

// Migrated pool: ensure that the claimable incentives are the same before and after migration
migratedPoolAfterUpgradeIncentives, _, err := s.App.ConcentratedLiquidityKeeper.GetClaimableIncentives(s.Ctx, lastPoolPositionID)
s.Require().NoError(err)
s.Require().Equal(migratedPoolBeforeUpgradeIncentives.String(), migratedPoolAfterUpgradeIncentives.String())

// Non-migrated pool: ensure that the claimable incentives are the same before and after migration
nonMigratedPoolAfterUpgradeIncentives, _, err := s.App.ConcentratedLiquidityKeeper.GetClaimableIncentives(s.Ctx, lastPoolPositionID-1)
s.Require().NoError(err)
s.Require().Equal(nonMigratedPoolBeforeUpgradeIncentives.String(), nonMigratedPoolAfterUpgradeIncentives.String())

// Restore the migration list for use by other tests
concentratedtypes.MigratedIncentiveAccumulatorPoolIDs = oldMigrationList
}

func dummyUpgrade(s *UpgradeTestSuite) {
s.Ctx = s.Ctx.WithBlockHeight(v23UpgradeHeight - 1)
plan := upgradetypes.Plan{Name: "v23", Height: v23UpgradeHeight}
err := s.App.UpgradeKeeper.ScheduleUpgrade(s.Ctx, plan)
s.Require().NoError(err)
_, exists := s.App.UpgradeKeeper.GetUpgradePlan(s.Ctx)
s.Require().True(exists)

s.Ctx = s.Ctx.WithBlockHeight(v23UpgradeHeight)
}
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/ory/dockertest/v3 v3.10.0
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3
github.com/osmosis-labs/osmosis/osmomath v0.0.8
github.com/osmosis-labs/osmosis/osmoutils v0.0.8
github.com/osmosis-labs/osmosis/osmoutils v0.0.9-0.20240206013051-b1a74295e6e9
github.com/osmosis-labs/osmosis/x/epochs v0.0.4
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.10
github.com/osmosis-labs/sqs/sqsdomain v0.0.0-20240208025415-894605171463
Expand Down Expand Up @@ -104,6 +104,7 @@ require (
github.com/ghostiam/protogetter v0.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/s2a-go v0.1.7 // indirect
Expand All @@ -121,6 +122,7 @@ require (
github.com/kkHAIKE/contextcheck v1.1.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/linxGnu/grocksdb v1.8.11 // indirect
github.com/macabu/inamedparam v0.1.2 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
Expand All @@ -131,7 +133,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nunnatsa/ginkgolinter v0.14.1 // indirect
github.com/osmosis-labs/osmosis/v22 v22.0.0-rc0 // indirect
github.com/osmosis-labs/sqs v0.0.0-20240109224414-786ae137f7c4 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1513,10 +1513,10 @@ github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:Ylmch
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3/go.mod h1:lV6KnqXYD/ayTe7310MHtM3I2q8Z6bBfMAi+bhwPYtI=
github.com/osmosis-labs/osmosis/osmomath v0.0.8 h1:jm6D5UgzQ0GQGtyFezs7tQRgwakf3cTBsE8oJIQdPZE=
github.com/osmosis-labs/osmosis/osmomath v0.0.8/go.mod h1:4iPfmy6R0qbImLe5urBLS0thndfLxfmHOdnYboDS1Qo=
github.com/osmosis-labs/osmosis/osmoutils v0.0.8 h1:CdRBGDP9NtrnLzeimUNjwFkMkYpfboGQK9cZW073onA=
github.com/osmosis-labs/osmosis/osmoutils v0.0.8/go.mod h1:/8dLv13+yB97YNAxpKsaF0Kd+KFARGcm709Xv7Ix0cU=
github.com/osmosis-labs/osmosis/v22 v22.0.0-rc0 h1:HNmPE7IN3dRzu/1UlAI0ymio39VHdqRikP+xRLBFmXY=
github.com/osmosis-labs/osmosis/v22 v22.0.0-rc0/go.mod h1:+pcbJEj6kt6ZNOPlYTxAMajuzEGBwgXLUoeTSvprQBg=
github.com/osmosis-labs/osmosis/osmoutils v0.0.9-0.20240206013051-b1a74295e6e9 h1:dVe/Lfng/y5QSVc5KHVM5ieQzXvqHLVwq8gdwfczuFo=
github.com/osmosis-labs/osmosis/osmoutils v0.0.9-0.20240206013051-b1a74295e6e9/go.mod h1:uNKaL8tCfSAoj7pBj9B+s67GUvRBbhiMSSwuDj4Nnag=
github.com/osmosis-labs/osmosis/v22 v22.0.0 h1:eb0ywQgvymb7RAf16ByrPgBO1ldXlvRku+V617gmyPI=
github.com/osmosis-labs/osmosis/v22 v22.0.0/go.mod h1:PHPdUS2GBd2ikAde7Z3/jW9KcF7nbf4cZrF8gbYIXXg=
github.com/osmosis-labs/osmosis/x/epochs v0.0.4 h1:5c5LQpjN+XpbhXobC4VG3V6/+4O3bm26NP0BKvHsQdg=
github.com/osmosis-labs/osmosis/x/epochs v0.0.4/go.mod h1:mTga2OJuy+RBhYvJUDJe9fdCZ4RBtM6ISvJrQzvFFAI=
github.com/osmosis-labs/osmosis/x/ibc-hooks v0.0.10 h1:s4Y1ZeOmQ+iTgODCbnuge0mcBeyOtZF80Q5nmqu8Tio=
Expand Down Expand Up @@ -1739,6 +1739,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
Expand Down
13 changes: 13 additions & 0 deletions osmoutils/accum/accum.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ func MakeAccumulatorWithValueAndShare(accumStore store.KVStore, accumName string
return setAccumulator(&newAccum, accumValue, totalShares)
}

// OverwriteAccumulatorUnsafe overwrites the accumulator with the given name in accumStore.
// Use with caution as this method is only meant for use in migrations.
func OverwriteAccumulatorUnsafe(accumStore store.KVStore, accumName string, accumValue sdk.DecCoins, totalShares osmomath.Dec) error {
if !accumStore.Has(formatAccumPrefixKey(accumName)) {
return errors.New("Accumulator with given name does not exist in store")
}

newAccum := AccumulatorObject{accumStore, accumName, accumValue, totalShares}
p0mvn marked this conversation as resolved.
Show resolved Hide resolved

// Stores accumulator in state
return setAccumulator(&newAccum, accumValue, totalShares)
}

// Gets the current value of the accumulator corresponding to accumName in accumStore
func GetAccumulator(accumStore store.KVStore, accumName string) (*AccumulatorObject, error) {
accumContent := AccumulatorContent{}
Expand Down
4 changes: 4 additions & 0 deletions proto/osmosis/concentratedliquidity/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ message GenesisState {

uint64 next_incentive_record_id = 5
[ (gogoproto.moretags) = "yaml:\"next_incentive_record_id\"" ];

uint64 incentives_accumulator_pool_id_migration_threshold = 6
[ (gogoproto.moretags) =
"yaml:\"incentives_accumulator_pool_id_migration_threshold\"" ];
}

message AccumObject {
Expand Down
18 changes: 14 additions & 4 deletions x/concentrated-liquidity/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var (
TwoHundredFooCoins = sdk.NewDecCoin("foo", osmomath.NewInt(200))
TwoHundredBarCoins = sdk.NewDecCoin("bar", osmomath.NewInt(200))
PerUnitLiqScalingFactor = perUnitLiqScalingFactor

OneDecScalingFactor = oneDecScalingFactor
)

func (k Keeper) SetPool(ctx sdk.Context, pool types.ConcentratedPoolExtension) error {
Expand Down Expand Up @@ -232,8 +234,8 @@ func (k Keeper) CreateUptimeAccumulators(ctx sdk.Context, poolId uint64) error {
return k.createUptimeAccumulators(ctx, poolId)
}

func CalcAccruedIncentivesForAccum(ctx sdk.Context, accumUptime time.Duration, qualifyingLiquidity osmomath.Dec, timeElapsed osmomath.Dec, poolIncentiveRecords []types.IncentiveRecord) (sdk.DecCoins, []types.IncentiveRecord, error) {
return calcAccruedIncentivesForAccum(ctx, accumUptime, qualifyingLiquidity, timeElapsed, poolIncentiveRecords, 0)
func CalcAccruedIncentivesForAccum(ctx sdk.Context, accumUptime time.Duration, qualifyingLiquidity osmomath.Dec, timeElapsed osmomath.Dec, poolIncentiveRecords []types.IncentiveRecord, scalingFactorForPool osmomath.Dec) (sdk.DecCoins, []types.IncentiveRecord, error) {
return calcAccruedIncentivesForAccum(ctx, accumUptime, qualifyingLiquidity, timeElapsed, poolIncentiveRecords, 0, scalingFactorForPool)
}

func (k Keeper) UpdateGivenPoolUptimeAccumulatorsToNow(ctx sdk.Context, pool types.ConcentratedPoolExtension, uptimeAccums []*accum.AccumulatorObject) error {
Expand Down Expand Up @@ -346,10 +348,18 @@ func (k Keeper) GetPoolHookContract(ctx sdk.Context, poolId uint64, actionPrefix
return k.getPoolHookContract(ctx, poolId, actionPrefix)
}

func ScaleUpTotalEmittedAmount(totalEmittedAmount osmomath.Dec) (scaledTotalEmittedAmount osmomath.Dec, err error) {
return scaleUpTotalEmittedAmount(totalEmittedAmount)
func ScaleUpTotalEmittedAmount(totalEmittedAmount osmomath.Dec, scalingFactor osmomath.Dec) (scaledTotalEmittedAmount osmomath.Dec, err error) {
return scaleUpTotalEmittedAmount(totalEmittedAmount, scalingFactor)
}

func ComputeTotalIncentivesToEmit(timeElapsedSeconds osmomath.Dec, emissionRate osmomath.Dec) (totalEmittedAmount osmomath.Dec, err error) {
return computeTotalIncentivesToEmit(timeElapsedSeconds, emissionRate)
}

func (k Keeper) GetPositionIDsByPoolID(ctx sdk.Context, poolID uint64) ([]uint64, error) {
return k.getPositionIDsByPoolID(ctx, poolID)
}

func (k Keeper) GetIncentiveScalingFactorForPool(ctx sdk.Context, poolID uint64) (osmomath.Dec, error) {
return k.getIncentiveScalingFactorForPool(ctx, poolID)
}
9 changes: 9 additions & 0 deletions x/concentrated-liquidity/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState genesis.GenesisState) {

// set total liquidity
k.setTotalLiquidity(ctx, totalLiquidity)

k.SetIncentivePoolIDMigrationThreshold(ctx, genState.IncentivesAccumulatorPoolIdMigrationThreshold)
}

// ExportGenesis returns the concentrated-liquidity module's exported genesis state.
Expand Down Expand Up @@ -230,12 +232,19 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *genesis.GenesisState {
})
}

// Get the incentive pool ID migration threshold
incentivesAccumulatorPoolIDMigrationThreshold, err := k.GetIncentivePoolIDMigrationThreshold(ctx)
if err != nil {
panic(err)
}

return &genesis.GenesisState{
Params: k.GetParams(ctx),
PoolData: poolData,
PositionData: positionData,
NextPositionId: k.GetNextPositionId(ctx),
NextIncentiveRecordId: k.GetNextIncentiveRecordId(ctx),
IncentivesAccumulatorPoolIdMigrationThreshold: incentivesAccumulatorPoolIDMigrationThreshold,
}
}

Expand Down
9 changes: 9 additions & 0 deletions x/concentrated-liquidity/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
PoolData: []genesis.PoolData{},
NextIncentiveRecordId: 2,
NextPositionId: 3,
IncentivesAccumulatorPoolIdMigrationThreshold: 3,
}
testCoins = sdk.NewDecCoins(cl.HundredFooCoins)
testTickInfo = model.TickInfo{
Expand Down Expand Up @@ -595,6 +596,11 @@ func (s *KeeperTestSuite) TestInitGenesis() {
}
// Validate next position id.
s.Require().Equal(tc.genesis.NextPositionId, clKeeper.GetNextPositionId(ctx))

// Validate incentive migration threshold
incentiveMigrationThreshold, err := clKeeper.GetIncentivePoolIDMigrationThreshold(ctx)
s.Require().NoError(err)
s.Require().Equal(tc.genesis.IncentivesAccumulatorPoolIdMigrationThreshold, incentiveMigrationThreshold)
})
}
}
Expand Down Expand Up @@ -814,6 +820,9 @@ func (s *KeeperTestSuite) TestExportGenesis() {

// Validate next position id.
s.Require().Equal(tc.genesis.NextPositionId, actualExported.NextPositionId)

// Validate incentive migration threshold
s.Require().Equal(tc.genesis.IncentivesAccumulatorPoolIdMigrationThreshold, actualExported.IncentivesAccumulatorPoolIdMigrationThreshold)
})
}
}
Expand Down
Loading