Skip to content

Commit

Permalink
updated airdrop query to include the date index and airdrop length (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs authored Jul 25, 2024
1 parent a1f8144 commit d6e4e68
Show file tree
Hide file tree
Showing 9 changed files with 945 additions and 153 deletions.
1 change: 1 addition & 0 deletions dockernet/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ HOST_DAY_EPOCH_DURATION="60s"
HOST_HOUR_EPOCH_DURATION="60s"
HOST_WEEK_EPOCH_DURATION="60s"
HOST_MINT_EPOCH_DURATION="60s"
AIRDROP_PERIOD_LENGTH="86400"
UNBONDING_TIME="240s"
MAX_DEPOSIT_PERIOD="30s"
VOTING_PERIOD="30s"
Expand Down
4 changes: 4 additions & 0 deletions dockernet/scripts/airdrop/allocations_prod.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
stride1qtzlx93h8xlmej42pjqyez6yp9nscfgxsmtt59,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000
stride183g7tx3u4lmtwv7ph9fpq862e6dyapamexywru,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000
stride13k0vj64yr3dxq4e24v5s2ptqmnxmyl7xn5pz7q,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000
dym1np5x8s6lufkv8ghu8lzj5xtlgae5pwl8y8ne6x,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000
132 changes: 132 additions & 0 deletions dockernet/scripts/airdrop/setup_prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../../config.sh

# NOTE: Before running this script, you must change AIRDROP_PERIOD_LENGTH to "86400" in config.sh

# Options: fresh-start, midway-before-deadline, midway-after-deadline, distribution-ended
STAGE="fresh-start"

AIRDROP_NAME="sttia"
OS=$(uname)

# stride1wxv8jnusl5s2che9kp33jrsxz3kxcwm6fgfs0z
DISTRIBUTOR_MNEMONIC="wire elephant soldier improve million minor image identify analyst black kangaroo word dose run olive heavy usual sound copy diamond market accident other clean"
# stride1v0t265yce4pwdvmzs4ew0ll4fnk2t6updfg6hf
ALLOCATOR_MNEMONIC="board stamp journey usage pen warfare burst that detect rain solid skill affair cactus forward insect video bitter goddess tank syrup hunt pond flat"
# stride1krn5q0s83qfx9v67awsj7leaql99tmyydcukhl
LINKER_MNEMONIC="add special provide zebra gasp above tube shield judge vapor tortoise snow receive vibrant couch true tide snack goat fee risk viable coil mutual"

# stride1qtzlx93h8xlmej42pjqyez6yp9nscfgxsmtt59
CLAIMER_1_MNEMONIC="breeze reason effort latin mask orbit ball raw security gown category royal copper scheme fiction flame few wise siege car text snake famous render"
# stride183g7tx3u4lmtwv7ph9fpq862e6dyapamexywru
CLAIMER_2_MNEMONIC="glance trigger upgrade keep nature glad wreck snake grief trap utility curtain bracket large drama ridge loud token service idea smart crisp flavor carpet"
# stride13k0vj64yr3dxq4e24v5s2ptqmnxmyl7xn5pz7q
CLAIMER_3_MNEMONIC="pet garlic cram security clock element truth soda stomach ugly you dress narrow black space grab concert cancel depend crawl corn worry miss submit"

# Same mnemonic as claimer 3
LINKED_CLAIMER_ADDRESS="dym1np5x8s6lufkv8ghu8lzj5xtlgae5pwl8y8ne6x"

current_time_minus_day_offset() {
days=$1
if [[ "$OS" == "Darwin" ]]; then
date -u -v-"${days}d" +"%Y-%m-%dT00:00:00"
else
date -u +"%Y-%m-%dT00:00:00" -d "$days days ago"
fi
}
current_time_plus_day_offset() {
days=$1
if [[ "$OS" == "Darwin" ]]; then
date -u -v+"${days}d" +"%Y-%m-%dT00:00:00"
else
date -u +"%Y-%m-%dT00:00:00" -d "$days days"
fi
}

echo ">>> Creating admin accounts..."
echo $DISTRIBUTOR_MNEMONIC | $STRIDE_MAIN_CMD keys add distributor --recover -- | grep -E "address|name"
echo $ALLOCATOR_MNEMONIC | $STRIDE_MAIN_CMD keys add allocator --recover | grep -E "address|name"
echo $LINKER_MNEMONIC | $STRIDE_MAIN_CMD keys add linker --recover | grep -E "address|name"

echo -e "\n>>> Creating claimer accounts..."
echo $CLAIMER_1_MNEMONIC | $STRIDE_MAIN_CMD keys add claimer1 --recover | grep -E "address|name"
echo $CLAIMER_2_MNEMONIC | $STRIDE_MAIN_CMD keys add claimer2 --recover | grep -E "address|name"
echo $CLAIMER_3_MNEMONIC | $STRIDE_MAIN_CMD keys add claimer3 --recover | grep -E "address|name"

distributor_address=$($STRIDE_MAIN_CMD keys show distributor -a)
allocator_address=$($STRIDE_MAIN_CMD keys show allocator -a)
linker_address=$($STRIDE_MAIN_CMD keys show linker -a)

claimer_1_address=$($STRIDE_MAIN_CMD keys show claimer1 -a)
claimer_2_address=$($STRIDE_MAIN_CMD keys show claimer2 -a)
claimer_3_address=$($STRIDE_MAIN_CMD keys show claimer3 -a)

echo -e "\n>>> Funding admin accounts..."
$STRIDE_MAIN_CMD tx bank send val1 $distributor_address 5000000000ustrd --from val1 -y | TRIM_TX
sleep 3
$STRIDE_MAIN_CMD tx bank send val1 $allocator_address 1ustrd --from val1 -y | TRIM_TX
sleep 3
$STRIDE_MAIN_CMD tx bank send val1 $linker_address 1ustrd --from val1 -y | TRIM_TX
sleep 3

echo -e "\n>>> Funding claimer accounts..."
$STRIDE_MAIN_CMD tx bank send val1 $claimer_1_address 10000000ustrd --from val1 -y | TRIM_TX
sleep 3
$STRIDE_MAIN_CMD tx bank send val1 $claimer_2_address 10000000ustrd --from val1 -y | TRIM_TX
sleep 3
$STRIDE_MAIN_CMD tx bank send val1 $claimer_3_address 10000000ustrd --from val1 -y | TRIM_TX
sleep 3

if [[ "$STAGE" == "fresh-start" ]]; then
start_date=$(current_time_plus_day_offset 0)
end_date=$(current_time_plus_day_offset 149)
clawback_date=$(current_time_plus_day_offset 160)
deadline_date=$(current_time_plus_day_offset 30)
fi

if [[ "$STAGE" == "midway-before-deadline" ]]; then
start_date=$(current_time_minus_day_offset 10)
end_date=$(current_time_plus_day_offset 139)
clawback_date=$(current_time_plus_day_offset 150)
deadline_date=$(current_time_plus_day_offset 20)
fi

if [[ "$STAGE" == "midway-after-deadline" ]]; then
start_date=$(current_time_minus_day_offset 40)
end_date=$(current_time_plus_day_offset 109)
clawback_date=$(current_time_plus_day_offset 120)
deadline_date=$(current_time_minus_day_offset 10)
fi

if [[ "$STAGE" == "distribution-ended" ]]; then
start_date=$(current_time_minus_day_offset 155)
end_date=$(current_time_minus_day_offset 6)
clawback_date=$(current_time_plus_day_offset 25)
deadline_date=$(current_time_minus_day_offset 125)
fi

echo -e "\n>>> Creating airdrop..."
$STRIDE_MAIN_CMD tx airdrop create-airdrop $AIRDROP_NAME \
--distribution-start-date $start_date \
--distribution-end-date $end_date \
--clawback-date $clawback_date \
--claim-type-deadline-date $deadline_date \
--early-claim-penalty 0.5 \
--distributor-address $distributor_address \
--allocator-address $allocator_address \
--linker-address $linker_address \
--from admin -y | TRIM_TX
sleep 3

echo -e "\n>>> Adding allocations..."
$STRIDE_MAIN_CMD tx airdrop add-allocations $AIRDROP_NAME ${SCRIPT_DIR}/allocations_prod.csv \
--from allocator -y --gas 1000000 | TRIM_TX
sleep 3

echo -e "\n>>> Airdrops:"
$STRIDE_MAIN_CMD q airdrop airdrops

echo -e "\n>>> Allocations:"
$STRIDE_MAIN_CMD q airdrop all-allocations $AIRDROP_NAME | head -n 10
echo "..."
2 changes: 1 addition & 1 deletion dockernet/src/init_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ set_stride_genesis() {
jq '.app_state.staketia.host_zone.native_token_ibc_denom = $newVal' --arg newVal "${host_ibc_denom}" $genesis_config > json.tmp && mv json.tmp $genesis_config
fi

jq '.app_state.airdrop.params.period_length_seconds = $newVal' --arg newVal "60" $genesis_config > json.tmp && mv json.tmp $genesis_config
jq '.app_state.airdrop.params.period_length_seconds = $newVal' --arg newVal "${AIRDROP_PERIOD_LENGTH}" $genesis_config > json.tmp && mv json.tmp $genesis_config
}

set_host_genesis() {
Expand Down
54 changes: 50 additions & 4 deletions proto/stride/airdrop/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "cosmos_proto/cosmos.proto";
import "google/protobuf/timestamp.proto";

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

Expand Down Expand Up @@ -53,7 +54,55 @@ service Query {

// Airdrop
message QueryAirdropRequest { string id = 1; };
message QueryAirdropResponse { Airdrop airdrop = 1; }
message QueryAirdropResponse {
// Airdrop ID
string id = 1;

// Denom used when distributing rewards
string reward_denom = 2;

// The first date that claiming begins and rewards are distributed
google.protobuf.Timestamp distribution_start_date = 3
[ (gogoproto.stdtime) = true ];

// The last date for rewards to be distributed. Immediately after this date
// the rewards can no longer be claimed, but rewards have not been clawed back
// yet
google.protobuf.Timestamp distribution_end_date = 4
[ (gogoproto.stdtime) = true ];

// Date with which the rewards are clawed back (occurs after the distribution
// end date)
google.protobuf.Timestamp clawback_date = 5 [ (gogoproto.stdtime) = true ];

// Deadline for the user to make a decision on their claim type
google.protobuf.Timestamp claim_type_deadline_date = 6
[ (gogoproto.stdtime) = true ];

// Penalty for claiming rewards early - e.g. 0.5 means claiming early will
// result in losing 50% of rewards
string early_claim_penalty = 7 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

// Account that holds the total reward balance and distributes to users
string distributor_address = 8
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// Admin account with permissions to add or update allocations
string allocator_address = 9
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// Admin account with permissions to link addresseses
string linker_address = 10 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// The current date index into the airdrop array
int64 current_date_index = 11;

// The length of the airdrop (i.e. number of periods in the airdrop array)
int64 airdrop_length = 12;
}

// Airdrops
message QueryAllAirdropsRequest {};
Expand Down Expand Up @@ -118,7 +167,4 @@ message QueryUserSummaryResponse {
(gogoproto.nullable) = false,
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int"
];

// The current date index into the airdrop array
int64 current_date_index = 6;
}
40 changes: 31 additions & 9 deletions x/airdrop/keeper/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,30 @@ func (k Keeper) Airdrop(goCtx context.Context, req *types.QueryAirdropRequest) (
return nil, status.Errorf(codes.NotFound, "airdrop %s not found", req.Id)
}

return &types.QueryAirdropResponse{Airdrop: &airdrop}, nil
periodLengthSeconds := k.GetParams(ctx).PeriodLengthSeconds
currentDateIndex, err := airdrop.GetCurrentDateIndex(ctx, periodLengthSeconds)
if err == types.ErrAirdropNotStarted || err == types.ErrAirdropEnded {
currentDateIndex = -1
} else if err != nil {
return nil, status.Errorf(codes.FailedPrecondition, err.Error())
}

airdropResponse := types.QueryAirdropResponse{
Id: airdrop.Id,
RewardDenom: airdrop.RewardDenom,
DistributionStartDate: airdrop.DistributionStartDate,
DistributionEndDate: airdrop.DistributionEndDate,
ClawbackDate: airdrop.ClawbackDate,
ClaimTypeDeadlineDate: airdrop.ClaimTypeDeadlineDate,
EarlyClaimPenalty: airdrop.EarlyClaimPenalty,
DistributorAddress: airdrop.DistributorAddress,
AllocatorAddress: airdrop.AllocatorAddress,
LinkerAddress: airdrop.LinkerAddress,
CurrentDateIndex: int64(currentDateIndex),
AirdropLength: airdrop.GetAirdropPeriods(periodLengthSeconds),
}

return &airdropResponse, nil
}

// Queries all airdrop configurations
Expand Down Expand Up @@ -117,13 +140,13 @@ func (k Keeper) UserSummary(goCtx context.Context, req *types.QueryUserSummaryRe
}

// If the airdrop hasn't started yet or has ended, return date index -1 and claimable 0
claimable := sdkmath.ZeroInt()
var claimable sdkmath.Int
periodLengthSeconds := k.GetParams(ctx).PeriodLengthSeconds
currentDateIndex, err := airdrop.GetCurrentDateIndex(ctx, periodLengthSeconds)
if err == nil {
claimable = allocation.GetClaimableAllocation(currentDateIndex)
} else if err == types.ErrAirdropNotStarted || err == types.ErrAirdropEnded {
currentDateIndex = -1
claimable = sdkmath.ZeroInt()
} else {
return nil, status.Errorf(codes.FailedPrecondition, err.Error())
}
Expand All @@ -134,12 +157,11 @@ func (k Keeper) UserSummary(goCtx context.Context, req *types.QueryUserSummaryRe
}

summary := &types.QueryUserSummaryResponse{
ClaimType: claimType.String(),
Claimed: allocation.Claimed,
Claimable: claimable,
Forfeited: allocation.Forfeited,
Remaining: allocation.GetRemainingAllocations(),
CurrentDateIndex: int64(currentDateIndex),
ClaimType: claimType.String(),
Claimed: allocation.Claimed,
Claimable: claimable,
Forfeited: allocation.Forfeited,
Remaining: allocation.GetRemainingAllocations(),
}

return summary, nil
Expand Down
Loading

0 comments on commit d6e4e68

Please sign in to comment.