From 42520627fff8de3a51e7495c84504a79e636c717 Mon Sep 17 00:00:00 2001 From: sampocs Date: Thu, 11 Apr 2024 22:36:24 -0500 Subject: [PATCH 1/3] added stToken burn to unregister host zone function --- x/stakeibc/keeper/host_zone.go | 20 ++++++++++++++++++++ x/stakeibc/keeper/msg_server_test.go | 6 ++++++ x/stakeibc/types/expected_keepers.go | 1 + 3 files changed, 27 insertions(+) diff --git a/x/stakeibc/keeper/host_zone.go b/x/stakeibc/keeper/host_zone.go index 6bec755b18..b03f035c65 100644 --- a/x/stakeibc/keeper/host_zone.go +++ b/x/stakeibc/keeper/host_zone.go @@ -120,6 +120,19 @@ 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 + } + } + // Remove module accounts depositAddress := types.NewHostZoneDepositAddress(chainId) communityPoolStakeAddress := types.NewHostZoneModuleAddress(chainId, CommunityPoolStakeHoldingAddressKey) @@ -148,6 +161,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) diff --git a/x/stakeibc/keeper/msg_server_test.go b/x/stakeibc/keeper/msg_server_test.go index e07b2b7cdc..64c7cc103a 100644 --- a/x/stakeibc/keeper/msg_server_test.go +++ b/x/stakeibc/keeper/msg_server_test.go @@ -239,6 +239,12 @@ func (s *KeeperTestSuite) TestRegisterHostZone_Success_Unregister() { s.Require().NoError(err, "no error expected when re-registering host") } +func (s *KeeperTestSuite) TestT() { + s.FundAccount(s.TestAccs[0], sdk.NewCoin("denom", sdk.NewInt(1000))) + err := s.App.BankKeeper.BurnCoins(s.Ctx, stakeibctypes.ModuleName, sdk.NewCoins(sdk.NewCoin("denom", sdk.NewInt(1000)))) + fmt.Println(err.Error()) +} + func (s *KeeperTestSuite) TestRegisterHostZone_InvalidConnectionId() { tc := s.SetupRegisterHostZone() msg := tc.validMsg diff --git a/x/stakeibc/types/expected_keepers.go b/x/stakeibc/types/expected_keepers.go index 95a013f7ca..990fd88729 100644 --- a/x/stakeibc/types/expected_keepers.go +++ b/x/stakeibc/types/expected_keepers.go @@ -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) } From 82ebe7d9f9813998a3ca3e452cec9b1eb9e21f40 Mon Sep 17 00:00:00 2001 From: sampocs Date: Fri, 12 Apr 2024 09:59:32 -0500 Subject: [PATCH 2/3] set escrowed tokens to 0 --- x/stakeibc/keeper/host_zone.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/stakeibc/keeper/host_zone.go b/x/stakeibc/keeper/host_zone.go index b03f035c65..3ca965c469 100644 --- a/x/stakeibc/keeper/host_zone.go +++ b/x/stakeibc/keeper/host_zone.go @@ -133,6 +133,9 @@ func (k Keeper) UnregisterHostZone(ctx sdk.Context, chainId string) error { } } + // 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) From 4d6beaf6c2581e3ebb7419a8352a44ad16fcd649 Mon Sep 17 00:00:00 2001 From: sampocs Date: Fri, 12 Apr 2024 20:06:48 -0500 Subject: [PATCH 3/3] nit --- x/stakeibc/keeper/msg_server_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/x/stakeibc/keeper/msg_server_test.go b/x/stakeibc/keeper/msg_server_test.go index 64c7cc103a..e07b2b7cdc 100644 --- a/x/stakeibc/keeper/msg_server_test.go +++ b/x/stakeibc/keeper/msg_server_test.go @@ -239,12 +239,6 @@ func (s *KeeperTestSuite) TestRegisterHostZone_Success_Unregister() { s.Require().NoError(err, "no error expected when re-registering host") } -func (s *KeeperTestSuite) TestT() { - s.FundAccount(s.TestAccs[0], sdk.NewCoin("denom", sdk.NewInt(1000))) - err := s.App.BankKeeper.BurnCoins(s.Ctx, stakeibctypes.ModuleName, sdk.NewCoins(sdk.NewCoin("denom", sdk.NewInt(1000)))) - fmt.Println(err.Error()) -} - func (s *KeeperTestSuite) TestRegisterHostZone_InvalidConnectionId() { tc := s.SetupRegisterHostZone() msg := tc.validMsg