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

fix: cosmwasm pool model code ID migration #7595

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#7509](https://github.com/osmosis-labs/osmosis/pull/7509) Distributing ProtoRev profits to the community pool and burn address
* [#7550](https://github.com/osmosis-labs/osmosis/pull/7550) Speedup small CL swaps, by only fetching CL uptime accumulators if there is a tick crossing.
* [#7562](https://github.com/osmosis-labs/osmosis/pull/7562) Speedup Protorev estimation logic by removing unnecessary taker fee simulations.
* [#7595](https://github.com/osmosis-labs/osmosis/pull/7595) Fix cosmwasm pool model code ID migration.

### State Compatible

Expand Down
4 changes: 4 additions & 0 deletions x/cosmwasmpool/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (k Keeper) migrateCosmwasmPools(ctx sdk.Context, poolIds []uint64, newCodeI
if err != nil {
return err
}

// Update code ID to the updated one in state
cwPool.SetCodeId(newCodeId)
k.SetPool(ctx, cwPool)
}

// Whitelist new code id. No-op if already whitelisted.
Expand Down
17 changes: 15 additions & 2 deletions x/cosmwasmpool/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func (s *CWPoolGovSuite) TestMigrateCosmwasmPools() {
preUploadCodeIdPlaceholder uint64 = 1000
zeroCodeId uint64 = 0
defaultPoolCountToPreCreate uint64 = 3

// We create a code id for each pool. Since we provide code to upload in this test,
// we expect the code id to be one greater than the default pool count.
expectedNewCodeId uint64 = defaultPoolCountToPreCreate + 1
)

type MigrateMsg struct{}
Expand Down Expand Up @@ -181,7 +185,7 @@ func (s *CWPoolGovSuite) TestMigrateCosmwasmPools() {
byteCode: emptyByteCode,
migrateMsg: emptyMigrateMsg,

expectedCodeId: validCodeId,
expectedCodeId: expectedNewCodeId,
},
{
name: "happy path with code id to upload",
Expand All @@ -192,7 +196,7 @@ func (s *CWPoolGovSuite) TestMigrateCosmwasmPools() {
migrateMsg: emptyMigrateMsg,
shouldWhitelistCWPoolModuleAccountUpload: true,

expectedCodeId: validCodeId,
expectedCodeId: expectedNewCodeId,
},
{
name: "error: contract without migration entrypoint",
Expand Down Expand Up @@ -298,6 +302,15 @@ func (s *CWPoolGovSuite) TestMigrateCosmwasmPools() {
// Check that the code id is whitelisted.
s.Require().True(cosmwasmPoolKeeper.IsWhitelisted(s.Ctx, tc.expectedCodeId))

s.Require().NotEqual(0, len(tc.poolIdsToMigrate))
for _, poolID := range tc.poolIdsToMigrate {
// Check that the pool is migrated.
pool, err := cosmwasmPoolKeeper.GetPoolById(s.Ctx, poolID)
s.Require().NoError(err)

s.Require().Equal(tc.expectedCodeId, pool.GetCodeId())
}

// Validate that the event is emitted.
s.AssertEventEmitted(s.Ctx, types.TypeEvtMigratedCosmwasmPoolCode, 1)
})
Expand Down
5 changes: 5 additions & 0 deletions x/cosmwasmpool/model/store_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,8 @@ func (p CosmWasmPool) SetWasmKeeper(wasmKeeper types.WasmKeeper) {
func (p *CosmWasmPool) GetPoolDenoms(ctx sdk.Context) []string {
panic("CosmWasmPool.GetPoolDenoms not implemented")
}

// SetCodeId implements types.CosmWasmExtension.
func (p *CosmWasmPool) SetCodeId(codeId uint64) {
p.CodeId = codeId
}
2 changes: 2 additions & 0 deletions x/cosmwasmpool/types/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ type CosmWasmExtension interface {
SetWasmKeeper(wasmKeeper WasmKeeper)

GetTotalPoolLiquidity(ctx sdk.Context) sdk.Coins

SetCodeId(codeId uint64)
}