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

added stToken burn to unregister host zone function #1175

Merged
merged 5 commits into from
Apr 13, 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
23 changes: 23 additions & 0 deletions x/stakeibc/keeper/host_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ func (k Keeper) UnregisterHostZone(ctx sdk.Context, chainId string) error {
return types.ErrHostZoneNotFound.Wrapf("host zone %s not found", chainId)
}

// Burn all outstanding stTokens
stTokenDenom := utils.StAssetDenomFromHostZoneDenom(hostZone.HostDenom)
for _, account := range k.AccountKeeper.GetAllAccounts(ctx) {
stTokenBalance := k.bankKeeper.GetBalance(ctx, account.GetAddress(), stTokenDenom)
stTokensToBurn := sdk.NewCoins(stTokenBalance)
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, account.GetAddress(), types.ModuleName, stTokensToBurn); err != nil {
return err
}
if err := k.bankKeeper.BurnCoins(ctx, types.ModuleName, stTokensToBurn); err != nil {
return err
}
}

// Set the escrow'd tokens to 0 (all the escrowed tokens should have been burned from the above)
k.RecordsKeeper.TransferKeeper.SetTotalEscrowForDenom(ctx, sdk.NewCoin(stTokenDenom, sdk.ZeroInt()))

// Remove module accounts
depositAddress := types.NewHostZoneDepositAddress(chainId)
communityPoolStakeAddress := types.NewHostZoneModuleAddress(chainId, CommunityPoolStakeHoldingAddressKey)
Expand Down Expand Up @@ -148,6 +164,13 @@ func (k Keeper) UnregisterHostZone(ctx sdk.Context, chainId string) error {
k.RecordsKeeper.SetEpochUnbondingRecord(ctx, epochUnbondingRecord)
}

// Remove all user redemption records for the host zone
for _, userRedemptionRecord := range k.RecordsKeeper.GetAllUserRedemptionRecord(ctx) {
if userRedemptionRecord.HostZoneId == chainId {
k.RecordsKeeper.RemoveUserRedemptionRecord(ctx, userRedemptionRecord.Id)
}
}

// Remove whitelisted address pairs from rate limit module
rewardCollectorAddress := k.AccountKeeper.GetModuleAccount(ctx, types.RewardCollectorName).GetAddress()
k.RatelimitKeeper.RemoveWhitelistedAddressPair(ctx, hostZone.DepositAddress, hostZone.DelegationIcaAddress)
Expand Down
1 change: 1 addition & 0 deletions x/stakeibc/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type AccountKeeper interface {
NewAccount(sdk.Context, authtypes.AccountI) authtypes.AccountI
SetAccount(ctx sdk.Context, acc authtypes.AccountI)
GetAccount(ctx sdk.Context, addr sdk.AccAddress) types.AccountI
GetAllAccounts(ctx sdk.Context) []types.AccountI
GetModuleAccount(ctx sdk.Context, moduleName string) types.ModuleAccountI
RemoveAccount(ctx sdk.Context, acc authtypes.AccountI)
}
Expand Down
Loading