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: migrate fund from dead account #419

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
12 changes: 11 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ import (
v422 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_2_2"
v424 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_2_4"
v425 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_2_5"
v426 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_2_6"
"github.com/rakyll/statik/fs"

// unnamed import of statik for swagger UI support
Expand Down Expand Up @@ -1220,6 +1221,15 @@ func (app *MigalooApp) setupUpgradeHandlers() {
),
)

app.UpgradeKeeper.SetUpgradeHandler(
v426.UpgradeName,
v426.CreateUpgradeHandler(
app.mm,
app.BankKeeper,
app.configurator,
),
)

// When a planned update height is reached, the old binary will panic
// writing on disk the height and name of the update that triggered it
// This will read that value, and execute the preparations for the upgrade.
Expand All @@ -1232,7 +1242,7 @@ func (app *MigalooApp) setupUpgradeHandlers() {
return
}

if upgradeInfo.Name == v425.UpgradeName {
if upgradeInfo.Name == v426.UpgradeName {
storeUpgrades := &storetypes.StoreUpgrades{
Added: []string{},
Deleted: []string{},
Expand Down
13 changes: 13 additions & 0 deletions app/upgrades/v4_2_6/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package v4

// UpgradeName defines the on-chain upgrade name for the Migaloo v4.2.5 upgrade.
// this upgrade includes the fix for pfm
const (
UpgradeName = "v4.2.6"
)

const (
Denom = "ibc/BC5C0BAFD19A5E4133FDA0F3E04AE1FBEE75A4A226554B2CBB021089FF2E1F8A"
DeadContract = "migaloo1qelh4gv5drg3yhj282l6n84a6wrrz033kwyak3ee3syvqg3mu3msgphpk4"
Foundation = "migaloo10zqfqhw44e6gvu97frjzcghunndskhu40uyztwu00y6dr9qxrz6qcjfrf7"
)
67 changes: 67 additions & 0 deletions app/upgrades/v4_2_6/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package v4_test

import (
"testing"

"cosmossdk.io/math"
v4 "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app/upgrades/v4_2_6"
sdk "github.com/cosmos/cosmos-sdk/types"

apptesting "github.com/White-Whale-Defi-Platform/migaloo-chain/v4/app"
"github.com/stretchr/testify/suite"
)

const (
MockDeadContractBalance = 1000000000000000000
)

type UpgradeTestSuite struct {
apptesting.KeeperTestHelper
}

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

func (s *UpgradeTestSuite) MockBankBalances() {
deadContractAddr := sdk.MustAccAddressFromBech32(v4.DeadContract)

coins := sdk.NewCoins(
sdk.NewCoin(v4.Denom, math.NewInt(MockDeadContractBalance)),
)

// Mint coins to the dead contract
err := s.App.BankKeeper.MintCoins(s.Ctx, "mint", coins)
s.Require().NoError(err)
err = s.App.BankKeeper.SendCoinsFromModuleToAccount(s.Ctx, "mint", deadContractAddr, coins)
s.Require().NoError(err)

// require the balance is correct
balance := s.App.BankKeeper.GetAllBalances(s.Ctx, deadContractAddr)
s.Require().Equal(coins, balance)
}

// Ensures the test does not error out.
func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup(s.T())
// == CREATE MOCK VESTING ACCOUNT ==
s.MockBankBalances()

// == UPGRADE ==
upgradeHeight := int64(5)

// Execute upgrade
s.ConfirmUpgradeSucceeded(v4.UpgradeName, upgradeHeight)

// Dead contract balance get drained
deadContractAddr := sdk.MustAccAddressFromBech32(v4.DeadContract)
contractBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, deadContractAddr)
s.Require().Equal(int64(0), contractBalance.AmountOf(v4.Denom).Int64())

// Foundation balance is increased
foundationAddr := sdk.MustAccAddressFromBech32(v4.Foundation)
foundationBalance := s.App.BankKeeper.GetAllBalances(s.Ctx, foundationAddr)
s.T().Logf("balance: %v", foundationBalance)
s.Require().Equal(int64(MockDeadContractBalance), foundationBalance.AmountOf(v4.Denom).Int64()) // Add int64 cast

}
43 changes: 43 additions & 0 deletions app/upgrades/v4_2_6/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package v4

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// CreateUpgradeHandler that migrates the chain from v4.2.5 to v4.2.6
func CreateUpgradeHandler(
mm *module.Manager,
bankKeeper bankKeeper.Keeper,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// ignore the error if any
if err := migrateFundFromDeadContacts(ctx, bankKeeper); err != nil {
ctx.Logger().Error("migrateFundFromDeadContacts", "error", err)
}

return mm.RunMigrations(ctx, configurator, fromVM)
}
}

// migrate fund from dead contacts to foundation
func migrateFundFromDeadContacts(
ctx sdk.Context,
bankKeeper bankKeeper.Keeper,
) error {
deadContractAddr := sdk.MustAccAddressFromBech32(DeadContract)
foundationAddr := sdk.MustAccAddressFromBech32(Foundation)

// transfer token from dead contract to foundation

// Get all balances from the dead contract
allBalances := bankKeeper.GetAllBalances(ctx, deadContractAddr)
if allBalances.IsZero() {
return nil // Return early if no balances
}

return bankKeeper.SendCoins(ctx, deadContractAddr, foundationAddr, allBalances)
}
80 changes: 39 additions & 41 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
module github.com/White-Whale-Defi-Platform/migaloo-chain/v4

go 1.22.5
go 1.22.9

require (
cosmossdk.io/math v1.3.0
cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d
cosmossdk.io/tools/rosetta v0.2.1
github.com/CosmWasm/wasmd v0.46.0
github.com/cometbft/cometbft v0.37.9
github.com/cometbft/cometbft v0.37.13
github.com/cometbft/cometbft-db v0.12.0
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.47.13
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/cosmos-sdk v0.47.14
github.com/cosmos/gogoproto v1.7.0
github.com/cosmos/ibc-apps/modules/ibc-hooks/v7 v7.0.0-20231017170841-8fd49ec0f017
github.com/cosmos/ibc-go/v7 v7.7.0
github.com/cosmos/ibc-go/v7 v7.8.0
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_golang v1.20.4
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.6.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/terra-money/alliance v0.3.6
github.com/terra-money/core/v2 v2.11.4
google.golang.org/grpc v1.64.0
google.golang.org/grpc v1.67.0
)

require (
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/log v1.4.1 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
Expand All @@ -38,13 +38,13 @@ require (
github.com/iancoleman/orderedmap v0.2.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/linxGnu/grocksdb v1.8.14 // indirect
github.com/linxGnu/grocksdb v1.9.3 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rs/zerolog v1.32.0 // indirect
golang.org/x/sync v0.6.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
github.com/rs/zerolog v1.33.0 // indirect
golang.org/x/sync v0.8.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
)

require (
Expand All @@ -58,8 +58,7 @@ require (

require (
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/compute v1.25.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.38.0 // indirect
cosmossdk.io/api v0.3.1 // indirect
Expand All @@ -68,7 +67,7 @@ require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/ChainSafe/go-schnorrkel v1.1.0 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go v1.44.203 // indirect
Expand All @@ -77,7 +76,7 @@ require (
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/apd/v2 v2.0.2 // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
Expand All @@ -91,7 +90,7 @@ require (
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.4 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
github.com/creachadair/taskgroup v0.4.2 // indirect
github.com/creachadair/taskgroup v0.10.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
Expand All @@ -103,18 +102,18 @@ require (
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/kit v0.13.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/glog v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
Expand All @@ -123,7 +122,7 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
Expand All @@ -142,31 +141,31 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/minio/highwayhash v1.0.3 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.59.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/rs/cors v1.11.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/sasha-s/go-deadlock v0.3.5 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand All @@ -186,18 +185,17 @@ require (
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.171.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
Expand Down
Loading
Loading