-
-
Save jtieri/0b41fa96eac44ea1c0b5de63d23aa662 to your computer and use it in GitHub Desktop.
Sample Upgrade Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Before writing your upgrade handler, you will need to use the escrow-checker tool or some other means for identifying discrepancies | |
in the balances of escrow account addresses and the total supply of the assets on the associated counterparty chain. | |
Once you have identified which escrow accounts have discrepancies and what the delta is between the escrow balance and the counterparty's total supply, | |
you can define some type that contains the address and the assets that should be minted to reach parity between the escrow account and the counterparty total supply. | |
Then inside of the upgrade handler you can mint the necessary assets to the transfer module and send them from the transfer module to the escrow account. | |
NOTE: For v7 chains, you will have to modify the NewKeeper to remove the GetParams (moved to the AppModule()) and add a govMod address. | |
https://github.com/cosmos/ibc-apps/releases/tag/middleware%2Fpacket-forward-middleware%2Fv7.1.1 | |
packetforwardkeeper.NewKeeper( | |
appCodec, appKeepers.keys[packetforwardtypes.StoreKey], | |
appKeepers.TransferKeeper, | |
appKeepers.IBCKeeper.ChannelKeeper, | |
appKeepers.DistrKeeper, | |
appKeepers.BankKeeper, | |
appKeepers.HooksICS4Wrapper, | |
govModAddress, | |
) | |
... | |
packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)), | |
*/ | |
type EscrowUpdate struct { | |
EscrowAddress string | |
Assets []sdk.Coin | |
} | |
func CreateUpgradeHandler( | |
mm *module.Manager, | |
cfg module.Configurator, | |
k *keepers.AppKeepers, | |
) upgradetypes.UpgradeHandler { | |
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | |
// This slice needs to be initialized with objects that describe the escrow account address and the coins that need to be minted to fix the discrepancy. | |
updates := []EscrowUpdate{} | |
for _, update := range updates { | |
for _, coin := range update.Assets { | |
coins := sdk.NewCoins(coin) | |
if err := k.bankKeeper.MintCoins(ctx, transfertypes.ModuleName, coins); err != nil { | |
return nil, err | |
} | |
if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, transfertypes.ModuleName, update.EscrowAddress, coins); err != nil { | |
return nil, err | |
} | |
// For ibc-go v7+ you will also need to update the transfer module's store for the total escrow amounts. | |
currentTotalEscrow := k.transferKeeper.GetTotalEscrowForDenom(ctx, coin.GetDenom()) | |
newTotalEscrow := currentTotalEscrow.Add(coin) | |
k.transferKeeper.SetTotalEscrowForDenom(ctx, newTotalEscrow) | |
} | |
} | |
// Run migrations. | |
versionMap, err := mm.RunMigrations(ctx, cfg, vm) | |
if err != nil { | |
return nil, err | |
} | |
return versionMap, err | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment