-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2.11): upgrade handler fixing the escrow accounts balances
- Loading branch information
Showing
9 changed files
with
85 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,4 +220,5 @@ const ( | |
Upgrade2_8 = "v2.8" | ||
Upgrade2_9 = "v2.9" | ||
Upgrade2_10 = "v2.10" | ||
Upgrade2_11 = "v2.11" | ||
) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package v2_11 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" | ||
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" | ||
custombankkeeper "github.com/terra-money/core/v2/x/bank/keeper" | ||
) | ||
|
||
type EscrowUpdate struct { | ||
EscrowAddress sdk.AccAddress | ||
Assets []sdk.Coin | ||
} | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
cfg module.Configurator, | ||
bankKeeper custombankkeeper.Keeper, | ||
transferKeeper ibctransferkeeper.Keeper, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
// This slice is initialized with objects that describe the escrow account address and the coins that need to be minted to fix the discrepancy. | ||
// To find the escrow account and address have been used the following software: | ||
// https://github.com/strangelove-ventures/escrow-checker/commit/adf0d867e2210c9ff0a27d8dff1c74ed0c8a00dc | ||
updates := []EscrowUpdate{ | ||
{ | ||
EscrowAddress: sdk.AccAddress("terra1s308jav50mgct9x4f87u23w2tfe8q6qe45y7s4"), | ||
Assets: []sdk.Coin{sdk.NewCoin("ibc/815FC81EB6BD612206BD9A9909A02F7691D24A5B97CDFE2124B1BDCA9D4AB14C", sdk.NewInt(1000000000))}, | ||
}, | ||
} | ||
|
||
for _, update := range updates { | ||
for _, coin := range update.Assets { | ||
coins := sdk.NewCoins(coin) | ||
|
||
if err := bankKeeper.MintCoins(ctx, transfertypes.ModuleName, coins); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := 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 := transferKeeper.GetTotalEscrowForDenom(ctx, coin.GetDenom()) | ||
newTotalEscrow := currentTotalEscrow.Add(coin) | ||
transferKeeper.SetTotalEscrowForDenom(ctx, newTotalEscrow) | ||
} | ||
} | ||
|
||
// Run migrations. | ||
versionMap, err := mm.RunMigrations(ctx, cfg, vm) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return versionMap, err | ||
} | ||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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