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: supply offsets for osmo token #8751

Merged
merged 3 commits into from
Oct 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 @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [#8682](https://github.com/osmosis-labs/osmosis/pull/8682) chore: bump cosmwasm-optimizer
* [#8734](https://github.com/osmosis-labs/osmosis/pull/8734) chore: update cosmwasm vm
* [#8751](https://github.com/osmosis-labs/osmosis/pull/8751) fix: supply offsets for osmo token
* [#8764](https://github.com/osmosis-labs/osmosis/pull/8764) chore: add cosmwasm 1_3 feature
* [#8779](https://github.com/osmosis-labs/osmosis/pull/8779) chore: bump cometbft/cosmos-sdk versions

Expand Down
5 changes: 4 additions & 1 deletion app/upgrades/v27/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
)

// UpgradeName defines the on-chain upgrade name for the Osmosis v27 upgrade.
const UpgradeName = "v27"
const (
UpgradeName = "v27"
OsmoToken = "uosmo"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
Expand Down
10 changes: 10 additions & 0 deletions app/upgrades/v27/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ func CreateUpgradeHandler(
if err != nil {
return nil, err
}
bk := keepers.BankKeeper

// Get the old offset from the old key: []byte{0x88}
offsetOld := bk.GetSupplyOffsetOld(ctx, OsmoToken)
czarcas7ic marked this conversation as resolved.
Show resolved Hide resolved

// Add the old offset to the new key: collection.NewPrefix(88)
bk.AddSupplyOffset(ctx, OsmoToken, offsetOld)

// Remove the old key: []byte{0x88}
bk.RemoveOldSupplyOffset(ctx, OsmoToken)

return migrations, nil
}
Expand Down
77 changes: 77 additions & 0 deletions app/upgrades/v27/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package v27_test

import (
"testing"
"time"

"github.com/stretchr/testify/suite"

"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/header"
upgradetypes "cosmossdk.io/x/upgrade/types"

"github.com/osmosis-labs/osmosis/v26/app/apptesting"
v27 "github.com/osmosis-labs/osmosis/v26/app/upgrades/v27"

"cosmossdk.io/x/upgrade"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"

"github.com/osmosis-labs/osmosis/osmomath"
)

const (
v27UpgradeHeight = int64(10)
)

type UpgradeTestSuite struct {
apptesting.KeeperTestHelper
preModule appmodule.HasPreBlocker
}

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

func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()
s.preModule = upgrade.NewAppModule(s.App.UpgradeKeeper, addresscodec.NewBech32Codec("osmo"))

s.PrepareSupplyOffsetTest()

// Run the upgrade
dummyUpgrade(s)
s.Require().NotPanics(func() {
_, err := s.preModule.PreBlock(s.Ctx)
s.Require().NoError(err)
})

s.ExecuteSupplyOffsetTest()
}

func dummyUpgrade(s *UpgradeTestSuite) {
s.Ctx = s.Ctx.WithBlockHeight(v27UpgradeHeight - 1)
plan := upgradetypes.Plan{Name: v27.Upgrade.UpgradeName, Height: v27UpgradeHeight}
err := s.App.UpgradeKeeper.ScheduleUpgrade(s.Ctx, plan)
s.Require().NoError(err)
_, err = s.App.UpgradeKeeper.GetUpgradePlan(s.Ctx)
s.Require().NoError(err)

s.Ctx = s.Ctx.WithHeaderInfo(header.Info{Height: v27UpgradeHeight, Time: s.Ctx.BlockTime().Add(time.Second)}).WithBlockHeight(v27UpgradeHeight)
}

func (s *UpgradeTestSuite) PrepareSupplyOffsetTest() {
// Set some supply offsets
s.App.BankKeeper.AddSupplyOffset(s.Ctx, v27.OsmoToken, osmomath.NewInt(1000))
s.App.BankKeeper.AddSupplyOffsetOld(s.Ctx, v27.OsmoToken, osmomath.NewInt(-500))
}

func (s *UpgradeTestSuite) ExecuteSupplyOffsetTest() {
coin := s.App.BankKeeper.GetSupplyWithOffset(s.Ctx, v27.OsmoToken)
offset := s.App.BankKeeper.GetSupplyOffset(s.Ctx, v27.OsmoToken)
oldOffset := s.App.BankKeeper.GetSupplyOffsetOld(s.Ctx, v27.OsmoToken)

s.Require().Equal("500uosmo", coin.String())
s.Require().Equal("500", offset.String())
s.Require().Equal("0", oldOffset.String())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this become 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the old value is removed from the store! I think we could delete the old state in a later migration to be safe? wdyt?

}
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ use ./x/ibc-hooks
use ./x/epochs

replace github.com/onsi/ginkgo => github.com/onsi/ginkgo v1.16.5
replace github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.50.10-v26-osmo-1.0.20241002161840-d2ff8f7253c7