-
Notifications
You must be signed in to change notification settings - Fork 194
/
upgrades.go
97 lines (82 loc) · 3.33 KB
/
upgrades.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package v8
import (
"fmt"
"time"
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/Stride-Labs/stride/v19/utils"
autopilotkeeper "github.com/Stride-Labs/stride/v19/x/autopilot/keeper"
autopilottypes "github.com/Stride-Labs/stride/v19/x/autopilot/types"
claimkeeper "github.com/Stride-Labs/stride/v19/x/claim/keeper"
"github.com/Stride-Labs/stride/v19/x/claim/types"
claimtypes "github.com/Stride-Labs/stride/v19/x/claim/types"
)
var (
UpgradeName = "v8"
EvmosAirdropDistributor = "stride10dy5pmc2fq7fnmufjfschkfrxaqnpykl6ezy5j"
EvmosAirdropIdentifier = "evmos"
EvmosChainId = "evmos_9001-2"
AirdropDuration = time.Hour * 24 * 30 * 12 * 3 // 3 years
ResetAirdropIdentifiers = []string{"stride", "gaia", "osmosis", "juno", "stars"}
AirdropStartTime = time.Date(2023, 4, 3, 16, 0, 0, 0, time.UTC) // April 3, 2023 @ 16:00 UTC (12:00 EST)
)
// CreateUpgradeHandler creates an SDK upgrade handler for v8
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
cdc codec.Codec,
claimKeeper claimkeeper.Keeper,
autopilotKeeper autopilotkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting upgrade v8...")
// Reset Claims
ctx.Logger().Info("Resetting airdrop claims...")
for _, claimType := range ResetAirdropIdentifiers {
if err := claimKeeper.ResetClaimStatus(ctx, claimType); err != nil {
return vm, errorsmod.Wrapf(err, fmt.Sprintf("unable to reset %s claim status", claimType))
}
}
// Delete all unofficial airdrops from the store so they don't conflict with the evmos addition
claimParams, err := claimKeeper.GetParams(ctx)
if err != nil {
return vm, errorsmod.Wrapf(err, "unable to get claim parameters")
}
updatedAirdropList := []*types.Airdrop{}
for _, existingAirdrop := range claimParams.Airdrops {
if utils.ContainsString(ResetAirdropIdentifiers, existingAirdrop.AirdropIdentifier) {
updatedAirdropList = append(updatedAirdropList, existingAirdrop)
}
}
updatedClaimsParams := claimtypes.Params{
Airdrops: updatedAirdropList,
}
if err := claimKeeper.SetParams(ctx, updatedClaimsParams); err != nil {
return vm, errorsmod.Wrapf(err, "unable to remove unofficial airdrops")
}
// Add the evmos airdrop
ctx.Logger().Info("Adding evmos airdrop...")
duration := uint64(AirdropDuration.Seconds())
if err := claimKeeper.CreateAirdropAndEpoch(ctx, types.MsgCreateAirdrop{
Distributor: EvmosAirdropDistributor,
Identifier: EvmosAirdropIdentifier,
ChainId: EvmosChainId,
Denom: claimtypes.DefaultClaimDenom,
StartTime: uint64(AirdropStartTime.Unix()),
Duration: duration,
AutopilotEnabled: true,
}); err != nil {
return vm, err
}
ctx.Logger().Info("Loading airdrop allocations...")
claimKeeper.LoadAllocationData(ctx, allocations)
// Update autopilot params
autopilotParams := autopilottypes.DefaultParams()
autopilotKeeper.SetParams(ctx, autopilotParams)
ctx.Logger().Info("Running module migrations...")
return mm.RunMigrations(ctx, configurator, vm)
}
}