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

[CL]: Export Position_lock_id mappings to GenesisState #4912

Merged
merged 7 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
5 changes: 4 additions & 1 deletion proto/osmosis/concentrated-liquidity/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ message GenesisState {

repeated Position positions = 3 [ (gogoproto.nullable) = false ];

uint64 next_position_id = 4
uint64 position_lock_id = 4
stackman27 marked this conversation as resolved.
Show resolved Hide resolved
[ (gogoproto.moretags) = "yaml:\"position_lock_id\"" ];

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

Expand Down
13 changes: 12 additions & 1 deletion x/concentrated-liquidity/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/osmoutils/accum"
"github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/model"
types "github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types"
"github.com/osmosis-labs/osmosis/v15/x/concentrated-liquidity/types/genesis"
)

type PositionWrapper struct {
Position model.Position
LockId uint64
}

// InitGenesis initializes the concentrated-liquidity module with the provided genesis state.
func (k Keeper) InitGenesis(ctx sdk.Context, genState genesis.GenesisState) {
k.SetParams(ctx, genState.Params)
Expand Down Expand Up @@ -64,8 +70,13 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState genesis.GenesisState) {
panic(fmt.Sprintf("found position with pool id (%d) but there is no pool with such id that exists", position.PoolId))
}

pos := PositionWrapper{
Position: position,
LockId: genState.PositionLockId,
}

// We hardcode the underlying lock id to 0, because genesisState should already hold the positionId to lockId connections
err := k.SetPosition(ctx, position.PoolId, sdk.MustAccAddressFromBech32(position.Address), position.LowerTick, position.UpperTick, position.JoinTime, position.Liquidity, position.PositionId, 0)
err := k.SetPosition(ctx, pos.Position.PoolId, sdk.MustAccAddressFromBech32(pos.Position.Address), pos.Position.LowerTick, pos.Position.UpperTick, pos.Position.JoinTime, pos.Position.Liquidity, pos.Position.PositionId, pos.LockId)
if err != nil {
panic(err)
}
Expand Down
21 changes: 20 additions & 1 deletion x/concentrated-liquidity/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type singlePoolGenesisEntry struct {
feeAccumValues genesis.AccumObject
incentiveAccumulators []genesis.AccumObject
incentiveRecords []types.IncentiveRecord
positionId uint64
}

var (
Expand Down Expand Up @@ -138,6 +139,7 @@ func setupGenesis(baseGenesis genesis.GenesisState, poolGenesisEntries []singleP
IncentiveRecords: poolGenesisEntry.incentiveRecords,
})
baseGenesis.Positions = append(baseGenesis.Positions, poolGenesisEntry.positions...)
baseGenesis.PositionLockId = uint64(poolGenesisEntry.positionId)
baseGenesis.NextPositionId = uint64(len(poolGenesisEntry.positions))

}
Expand Down Expand Up @@ -210,6 +212,7 @@ func (s *KeeperTestSuite) TestInitGenesis() {
MinUptime: testUptimeOne,
},
},
positionId: DefaultPositionId,
},
}),
expectedPools: []model.Pool{
Expand Down Expand Up @@ -286,6 +289,7 @@ func (s *KeeperTestSuite) TestInitGenesis() {
MinUptime: testUptimeOne,
},
},
positionId: DefaultPositionId,
},
{
pool: *poolTwo,
Expand Down Expand Up @@ -315,6 +319,7 @@ func (s *KeeperTestSuite) TestInitGenesis() {
MinUptime: testUptimeOne,
},
},
positionId: DefaultPositionId + 1,
},
}),
expectedPools: []model.Pool{
Expand Down Expand Up @@ -465,6 +470,11 @@ func (s *KeeperTestSuite) TestInitGenesis() {
}
// Validate next position id.
s.Require().Equal(tc.genesis.NextPositionId, clKeeper.GetNextPositionId(ctx))

lockId, err := clKeeper.GetPositionIdToLock(ctx, baseCase.positionId)
s.Require().NoError(err)

s.Require().Equal(tc.genesis.PositionLockId, lockId)
})
}
}
Expand Down Expand Up @@ -531,6 +541,7 @@ func (s *KeeperTestSuite) TestExportGenesis() {
MinUptime: testUptimeOne,
},
},
positionId: DefaultPositionId,
},
}),
},
Expand Down Expand Up @@ -564,6 +575,7 @@ func (s *KeeperTestSuite) TestExportGenesis() {
MinUptime: testUptimeOne,
},
},
positionId: DefaultPositionId,
},
{
pool: *poolTwo,
Expand Down Expand Up @@ -592,7 +604,8 @@ func (s *KeeperTestSuite) TestExportGenesis() {
MinUptime: testUptimeOne,
},
},
positions: []model.Position{withPositionId(positionWithPoolId(testPositionModel, 2), DefaultPositionId+1)},
positions: []model.Position{withPositionId(positionWithPoolId(testPositionModel, 2), DefaultPositionId+1)},
positionId: DefaultPositionId + 1,
},
}),
},
Expand Down Expand Up @@ -652,6 +665,12 @@ func (s *KeeperTestSuite) TestExportGenesis() {

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

// validate position lockId
lockId, err := clKeeper.GetPositionIdToLock(ctx, baseCase.positionId)
s.Require().NoError(err)

s.Require().Equal(tc.genesis.PositionLockId, lockId)
})
}
}
Expand Down
134 changes: 85 additions & 49 deletions x/concentrated-liquidity/types/genesis/genesis.pb.go

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