@@ -18,25 +18,70 @@ package upgrade
1818
1919import (
2020 "context"
21+ "errors"
2122
23+ "cosmossdk.io/core/address"
2224 "cosmossdk.io/log"
2325 upgradetypes "cosmossdk.io/x/upgrade/types"
2426 "github.com/cosmos/cosmos-sdk/types/module"
27+ authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
28+ bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
29+ authoritykeeper "github.com/noble-assets/authority/keeper"
2530)
2631
2732func CreateUpgradeHandler (
2833 mm * module.Manager ,
2934 cfg module.Configurator ,
3035 logger log.Logger ,
36+ addressCodec address.Codec ,
37+ authorityKeeper * authoritykeeper.Keeper ,
38+ bankKeeper bankkeeper.Keeper ,
3139) upgradetypes.UpgradeHandler {
3240 return func (ctx context.Context , _ upgradetypes.Plan , vm module.VersionMap ) (module.VersionMap , error ) {
3341 vm , err := mm .RunMigrations (ctx , cfg , vm )
3442 if err != nil {
3543 return vm , err
3644 }
3745
46+ err = ClaimDistributionFunds (ctx , logger , addressCodec , authorityKeeper , bankKeeper )
47+ if err != nil {
48+ return vm , err
49+ }
50+
3851 logger .Info (UpgradeASCII )
3952
4053 return vm , nil
4154 }
4255}
56+
57+ // ClaimDistributionFunds transfers all transaction fees accrued by Noble prior
58+ // to the v8 Helium upgrade (November 2024) to the x/authority owner. The funds
59+ // are currently stuck as the x/distribution module was removed and replaced by
60+ // the x/authority module without a proper migration of funds.
61+ func ClaimDistributionFunds (ctx context.Context , logger log.Logger , addressCodec address.Codec , authorityKeeper * authoritykeeper.Keeper , bankKeeper bankkeeper.Keeper ) error {
62+ // NOTE: We hardcode the x/distribution module name to avoid an import.
63+ address := authtypes .NewModuleAddress ("distribution" )
64+ balance := bankKeeper .GetAllBalances (ctx , address )
65+ if balance .IsZero () {
66+ // We return early in the case that there are no claimable funds.
67+ return nil
68+ }
69+
70+ authority , err := authorityKeeper .Owner .Get (ctx )
71+ if err != nil {
72+ return errors .New ("unable to get underlying authority address from state" )
73+ }
74+ authorityBz , err := addressCodec .StringToBytes (authority )
75+ if err != nil {
76+ return errors .New ("unable to decode underlying authority address" )
77+ }
78+
79+ err = bankKeeper .SendCoins (ctx , address , authorityBz , balance )
80+ if err != nil {
81+ return errors .New ("unable to transfer stuck distribution funds" )
82+ }
83+
84+ logger .Info ("claimed stuck distribution module funds" , "amount" , balance .String ())
85+
86+ return nil
87+ }
0 commit comments