Skip to content

Commit

Permalink
Feature/airdrop (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
antstalepresh authored Nov 17, 2022
1 parent fb03e0d commit 9be3314
Show file tree
Hide file tree
Showing 81 changed files with 12,797 additions and 5 deletions.
35 changes: 32 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ import (
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

claimvesting "github.com/Stride-Labs/stride/x/claim/vesting"
claimvestingtypes "github.com/Stride-Labs/stride/x/claim/vesting/types"

"github.com/Stride-Labs/stride/x/mint"
mintkeeper "github.com/Stride-Labs/stride/x/mint/keeper"
minttypes "github.com/Stride-Labs/stride/x/mint/types"
Expand Down Expand Up @@ -111,6 +114,9 @@ import (
interchainquerykeeper "github.com/Stride-Labs/stride/x/interchainquery/keeper"
interchainquerytypes "github.com/Stride-Labs/stride/x/interchainquery/types"

"github.com/Stride-Labs/stride/x/claim"
claimkeeper "github.com/Stride-Labs/stride/x/claim/keeper"
claimtypes "github.com/Stride-Labs/stride/x/claim/types"
icacallbacksmodule "github.com/Stride-Labs/stride/x/icacallbacks"
icacallbacksmodulekeeper "github.com/Stride-Labs/stride/x/icacallbacks/keeper"
icacallbacksmoduletypes "github.com/Stride-Labs/stride/x/icacallbacks/types"
Expand Down Expand Up @@ -175,13 +181,15 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
claimvesting.AppModuleBasic{},
// monitoringp.AppModuleBasic{},
stakeibcmodule.AppModuleBasic{},
epochsmodule.AppModuleBasic{},
interchainquery.AppModuleBasic{},
ica.AppModuleBasic{},
recordsmodule.AppModuleBasic{},
icacallbacksmodule.AppModuleBasic{},
claim.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand All @@ -196,6 +204,7 @@ var (
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
stakeibcmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
claimtypes.ModuleName: nil,
interchainquerytypes.ModuleName: nil,
icatypes.ModuleName: nil,
// this line is used by starport scaffolding # stargate/app/maccPerms
Expand Down Expand Up @@ -269,6 +278,7 @@ type StrideApp struct {
RecordsKeeper recordsmodulekeeper.Keeper
ScopedIcacallbacksKeeper capabilitykeeper.ScopedKeeper
IcacallbacksKeeper icacallbacksmodulekeeper.Keeper
ClaimKeeper claimkeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

mm *module.Manager
Expand Down Expand Up @@ -310,6 +320,7 @@ func NewStrideApp(
icacontrollertypes.StoreKey, icahosttypes.StoreKey,
recordsmoduletypes.StoreKey,
icacallbacksmoduletypes.StoreKey,
claimtypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -352,6 +363,7 @@ func NewStrideApp(
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
)
epochsKeeper := epochsmodulekeeper.NewKeeper(appCodec, keys[epochsmoduletypes.StoreKey])
app.MintKeeper = mintkeeper.NewKeeper(
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.EpochsKeeper, authtypes.FeeCollectorName,
)
Expand All @@ -366,13 +378,19 @@ func NewStrideApp(
app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName,
)

app.ClaimKeeper = *claimkeeper.NewKeeper(
appCodec,
keys[claimtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper, app.StakingKeeper, app.DistrKeeper, epochsKeeper)

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks(), app.ClaimKeeper.Hooks()),
)

// ... other modules keepers
Expand Down Expand Up @@ -455,7 +473,7 @@ func NewStrideApp(

scopedStakeibcKeeper := app.CapabilityKeeper.ScopeToModule(stakeibcmoduletypes.ModuleName)
app.ScopedStakeibcKeeper = scopedStakeibcKeeper
app.StakeibcKeeper = stakeibcmodulekeeper.NewKeeper(
stakeibcKeeper := stakeibcmodulekeeper.NewKeeper(
appCodec,
keys[stakeibcmoduletypes.StoreKey],
keys[stakeibcmoduletypes.MemStoreKey],
Expand All @@ -472,6 +490,9 @@ func NewStrideApp(
app.StakingKeeper,
app.IcacallbacksKeeper,
)
app.StakeibcKeeper = *stakeibcKeeper.SetHooks(
stakeibcmoduletypes.NewMultiStakeIBCHooks(app.ClaimKeeper.Hooks()),
)

stakeibcModule := stakeibcmodule.NewAppModule(appCodec, app.StakeibcKeeper, app.AccountKeeper, app.BankKeeper)
stakeibcIBCModule := stakeibcmodule.NewIBCModule(app.StakeibcKeeper)
Expand All @@ -496,11 +517,11 @@ func NewStrideApp(
return nil
}

epochsKeeper := epochsmodulekeeper.NewKeeper(appCodec, keys[epochsmoduletypes.StoreKey])
app.EpochsKeeper = *epochsKeeper.SetHooks(
epochsmoduletypes.NewMultiEpochHooks(
app.StakeibcKeeper.Hooks(),
app.MintKeeper.Hooks(),
app.ClaimKeeper.Hooks(),
),
)
epochsModule := epochsmodule.NewAppModule(appCodec, app.EpochsKeeper)
Expand Down Expand Up @@ -576,6 +597,7 @@ func NewStrideApp(
),
auth.NewAppModule(appCodec, app.AccountKeeper, nil),
vesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
claimvesting.NewAppModule(app.AccountKeeper, app.BankKeeper),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
Expand All @@ -589,6 +611,7 @@ func NewStrideApp(
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
claim.NewAppModule(appCodec, app.ClaimKeeper),
transferModule,
// monitoringModule,
stakeibcModule,
Expand All @@ -613,6 +636,7 @@ func NewStrideApp(
evidencetypes.ModuleName,
stakingtypes.ModuleName,
vestingtypes.ModuleName,
claimvestingtypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
authtypes.ModuleName,
Expand All @@ -629,6 +653,7 @@ func NewStrideApp(
interchainquerytypes.ModuleName,
recordsmoduletypes.ModuleName,
icacallbacksmoduletypes.ModuleName,
claimtypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

Expand All @@ -642,6 +667,7 @@ func NewStrideApp(
distrtypes.ModuleName,
slashingtypes.ModuleName,
vestingtypes.ModuleName,
claimvestingtypes.ModuleName,
minttypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
Expand All @@ -657,6 +683,7 @@ func NewStrideApp(
interchainquerytypes.ModuleName,
recordsmoduletypes.ModuleName,
icacallbacksmoduletypes.ModuleName,
claimtypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)

Expand All @@ -672,6 +699,7 @@ func NewStrideApp(
distrtypes.ModuleName,
stakingtypes.ModuleName,
vestingtypes.ModuleName,
claimvestingtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
minttypes.ModuleName,
Expand All @@ -690,6 +718,7 @@ func NewStrideApp(
interchainquerytypes.ModuleName,
recordsmoduletypes.ModuleName,
icacallbacksmoduletypes.ModuleName,
claimtypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
)

Expand Down
12 changes: 12 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

v2 "github.com/Stride-Labs/stride/app/upgrades/v2"
v3 "github.com/Stride-Labs/stride/app/upgrades/v3"
claimtypes "github.com/Stride-Labs/stride/x/claim/types"
)

func (app *StrideApp) setupUpgradeHandlers() {
Expand All @@ -16,6 +18,12 @@ func (app *StrideApp) setupUpgradeHandlers() {
v2.CreateUpgradeHandler(app.mm, app.configurator),
)

// v3 upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(
v3.UpgradeName,
v3.CreateUpgradeHandler(app.mm, app.configurator, app.ClaimKeeper),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("Failed to read upgrade info from disk: %w", err))
Expand All @@ -29,6 +37,10 @@ func (app *StrideApp) setupUpgradeHandlers() {

switch upgradeInfo.Name {
// no store upgrades
case "v3":
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{claimtypes.StoreKey},
}
}

if storeUpgrades != nil {
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/v3/allocations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v3

// allocation data for airdrop users in csv format
var allocations = `identifier,address,weight
stride,stride1g7yxhuppp5x3yqkah5mw29eqq5s4sv2f222xmk,0.5
stride,stride1h4astdfzjhcwahtfrh24qtvndzzh49xvqtfftk,0.3`
52 changes: 52 additions & 0 deletions app/upgrades/v3/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package v3

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

claimkeeper "github.com/Stride-Labs/stride/x/claim/keeper"
claimtypes "github.com/Stride-Labs/stride/x/claim/types"
)

// Note: ensure these values are properly set before running upgrade
var (
UpgradeName = "v3"
airdropDistributors = []string{
"stride1thl8e7smew8q7jrz8at4f64wrjjl8mwan3nc4l",
"stride104az7rd5yh3p8qn4ary8n3xcwquuwgee4vnvvc",
"stride17kvetgthwt6caku5qjs2rx2njgh26vmg448r5u",
"stride1swvv9kpp75e60pvlv5x6mcw5f54qgpph239e5s",
"stride1ywrhas3ae7z3ljqxmgdzjx8wyaf3djwuh4hdlj",
}
airdropIdentifiers = []string{"stride", "gaia", "osmosis", "juno", "stars"}
airdropDuration = time.Hour * 24 * 30 * 12 * 3 // 3 years
)

// CreateUpgradeHandler creates an SDK upgrade handler for v3
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
ck claimkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
newVm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return newVm, err
}

// total number of airdrop distributors must be equal to identifiers
if len(airdropDistributors) == len(airdropIdentifiers) {
for idx, airdropDistributor := range airdropDistributors {
err = ck.CreateAirdropAndEpoch(ctx, airdropDistributor, claimtypes.DefaultClaimDenom, uint64(ctx.BlockTime().Unix()), uint64(airdropDuration.Seconds()), airdropIdentifiers[idx])
if err != nil {
return newVm, err
}
}
}
ck.LoadAllocationData(ctx, allocations)
return newVm, nil
}
}
38 changes: 38 additions & 0 deletions proto/claim/v1beta1/claim.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
syntax = "proto3";
package Stridelabs.stride.claim.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/bank/v1beta1/genesis.proto";

option go_package = "github.com/Stride-Labs/stride/x/claim/types";

enum Action {
option (gogoproto.goproto_enum_prefix) = false;

ActionFree = 0;
ActionLiquidStake = 1;
ActionDelegateStake = 2;
}

// A Claim Records is the metadata of claim data per address
message ClaimRecord {
// airdrop identifier
string airdrop_identifier = 1 [ (gogoproto.moretags) = "yaml:\"airdrop_identifier\"" ];

// address of claim user
string address = 2 [ (gogoproto.moretags) = "yaml:\"address\"" ];

// weight that represent the portion from total allocation
string weight = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"weight\""
];

// true if action is completed
// index of bool in array refers to action enum #
repeated bool action_completed = 4 [
(gogoproto.moretags) = "yaml:\"action_completed\""
];
}
27 changes: 27 additions & 0 deletions proto/claim/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";
package Stridelabs.stride.claim.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/bank/v1beta1/genesis.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "claim/v1beta1/claim.proto";
import "claim/v1beta1/params.proto";

option go_package = "github.com/Stride-Labs/stride/x/claim/types";

// GenesisState defines the claim module's genesis state.
message GenesisState {
// params defines all the parameters of the module.
Params params = 1 [
(gogoproto.moretags) = "yaml:\"params\"",
(gogoproto.nullable) = false
];

// list of claim records, one for every airdrop recipient
repeated ClaimRecord claim_records = 2 [
(gogoproto.moretags) = "yaml:\"claim_records\"",
(gogoproto.nullable) = false
];
}
34 changes: 34 additions & 0 deletions proto/claim/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
syntax = "proto3";
package Stridelabs.stride.claim.v1beta1;

import "gogoproto/gogo.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/Stride-Labs/stride/x/claim/types";

// Params defines the claim module's parameters.
message Params {
repeated Airdrop airdrops = 1;
}

message Airdrop {
string airdrop_identifier = 1 [ (gogoproto.moretags) = "yaml:\"airdrop_identifier\"" ];
// seconds
google.protobuf.Timestamp airdrop_start_time = 2 [
(gogoproto.stdtime) = true,
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"airdrop_start_time\""
];
// seconds
google.protobuf.Duration airdrop_duration = 3 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true,
(gogoproto.jsontag) = "airdrop_duration,omitempty",
(gogoproto.moretags) = "yaml:\"airdrop_duration\""
];
// denom of claimable asset
string claim_denom = 4;
// airdrop distribution account
string distributor_address = 5;
}
Loading

0 comments on commit 9be3314

Please sign in to comment.