|
| 1 | +package v5 |
| 2 | + |
| 3 | +import ( |
| 4 | + "cosmossdk.io/math" |
| 5 | + "github.com/Pylons-tech/pylons/x/pylons/types" |
| 6 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 7 | + "github.com/cosmos/cosmos-sdk/types/module" |
| 8 | + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" |
| 9 | + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" |
| 10 | + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" |
| 11 | + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" |
| 12 | +) |
| 13 | + |
| 14 | +const ( |
| 15 | + // Master Wallet address |
| 16 | + MasterWallet = "pylo1vnwhaymaazugzz9ln2sznddveyed6shz3x8xwl" |
| 17 | +) |
| 18 | + |
| 19 | +var ( |
| 20 | + TotalUbedrock = math.NewIntFromUint64(1_000_000_000_000_000) // 1 bedrock = 1_000_000 ubedrock |
| 21 | + MasterWalletbalance = math.NewIntFromUint64(1e15) |
| 22 | +) |
| 23 | + |
| 24 | +func CreateUpgradeHandler( |
| 25 | + mm *module.Manager, |
| 26 | + configurator module.Configurator, |
| 27 | + bankKeeper bankkeeper.Keeper, |
| 28 | + accKeeper *authkeeper.AccountKeeper, |
| 29 | + staking *stakingkeeper.Keeper, |
| 30 | +) upgradetypes.UpgradeHandler { |
| 31 | + return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { |
| 32 | + // logger := ctx.Logger() |
| 33 | + |
| 34 | + if types.IsMainnet(ctx.ChainID()) { |
| 35 | + |
| 36 | + bankBaseKeeper, _ := bankKeeper.(bankkeeper.BaseKeeper) |
| 37 | + BurnToken(ctx, accKeeper, &bankBaseKeeper, staking) |
| 38 | + MintUbedrockForInitialAccount(ctx, &bankBaseKeeper, staking) |
| 39 | + } |
| 40 | + return mm.RunMigrations(ctx, configurator, fromVM) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// Burn stripeUSD denom token |
| 45 | +func BurnToken(ctx sdk.Context, accKeeper *authkeeper.AccountKeeper, bank *bankkeeper.BaseKeeper, staking *stakingkeeper.Keeper) { |
| 46 | + // only burn stripe usd token |
| 47 | + denom := types.StripeCoinDenom |
| 48 | + // Get all account balances |
| 49 | + accs := bank.GetAccountsBalances(ctx) |
| 50 | + for _, acc := range accs { |
| 51 | + balance := acc.Coins.AmountOf(denom) |
| 52 | + // Check if denom token amount GT 0 |
| 53 | + if balance.GT(math.ZeroInt()) { |
| 54 | + amount := sdk.NewCoin(denom, balance) |
| 55 | + // Send denom token to module |
| 56 | + err := bank.SendCoinsFromAccountToModule(ctx, sdk.MustAccAddressFromBech32(acc.Address), types.PaymentsProcessorName, sdk.NewCoins(amount)) |
| 57 | + if err != nil { |
| 58 | + panic(err) |
| 59 | + } |
| 60 | + // Burn denom token in module |
| 61 | + err = bank.BurnCoins(ctx, types.PaymentsProcessorName, sdk.NewCoins(amount)) |
| 62 | + if err != nil { |
| 63 | + panic(err) |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +// Mint ubedrock for master wallet |
| 70 | +func MintUbedrockForInitialAccount(ctx sdk.Context, bank *bankkeeper.BaseKeeper, staking *stakingkeeper.Keeper) { |
| 71 | + // Get currect balance of master wallet address |
| 72 | + balance := bank.GetBalance(ctx, sdk.MustAccAddressFromBech32(MasterWallet), types.StakingCoinDenom) |
| 73 | + |
| 74 | + // check difference in amount to add |
| 75 | + toAdd := MasterWalletbalance.Sub(balance.Amount) |
| 76 | + |
| 77 | + // Mint coin for module |
| 78 | + err := bank.MintCoins(ctx, types.PaymentsProcessorName, sdk.NewCoins(sdk.NewCoin(types.StakingCoinDenom, toAdd))) |
| 79 | + if err != nil { |
| 80 | + panic(err) |
| 81 | + } |
| 82 | + // Send coin required to meet master wallet balance from module to account |
| 83 | + err = bank.SendCoinsFromModuleToAccount( |
| 84 | + ctx, |
| 85 | + types.PaymentsProcessorName, |
| 86 | + sdk.MustAccAddressFromBech32(MasterWallet), |
| 87 | + sdk.NewCoins(sdk.NewCoin(types.StakingCoinDenom, toAdd)), |
| 88 | + ) |
| 89 | + if err != nil { |
| 90 | + panic(err) |
| 91 | + } |
| 92 | +} |
0 commit comments