-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restore calcuation of epoch days (#2610)
* Revert "Disable the referrals button, and the redemption feature (#2548)" This reverts commit 1ac1705. * update 24 hour airdrop leaderboard query * restore calculation of epoch days
- Loading branch information
Showing
3 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
database/102-up-timescale/20240408160403-airdrop_leaderboard_24_hours_add_fly_staked.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
-- migrate:up | ||
|
||
CREATE OR REPLACE FUNCTION airdrop_leaderboard_24_hours(epoch_ lootbox_epoch) | ||
RETURNS SETOF airdrop_leaderboard_return | ||
LANGUAGE sql | ||
STABLE | ||
AS $function$ | ||
SELECT | ||
lb.address, | ||
-- placeholder | ||
ROW_NUMBER() OVER () AS rank, | ||
COUNT(DISTINCT referee) AS referral_count, | ||
lb.total_box_count, | ||
lb.highest_reward_tier, | ||
COALESCE(liquidity.result, 1) AS liquidity_multiplier, | ||
COALESCE(lootbox_amounts_rewarded_fusdc.amount_earned, 0), | ||
COALESCE(lootbox_amounts_rewarded_arb.amount_earned, 0), | ||
fly_staked.amount AS fly_staked | ||
FROM ( | ||
-- subquery to avoid re-summing lootbox_count for every referee | ||
SELECT address, SUM(lootbox_count) as total_box_count, MAX(reward_tier) as highest_reward_tier | ||
FROM lootbox | ||
WHERE awarded_time > now() - interval '1 day' AND epoch = epoch_ | ||
GROUP BY address | ||
) lb | ||
LEFT JOIN ( | ||
SELECT amount_earned, winner | ||
FROM lootbox_amounts_rewarded | ||
WHERE token_short_name = 'USDC' AND epoch = epoch_ | ||
) AS lootbox_amounts_rewarded_fusdc ON lb.address = lootbox_amounts_rewarded_fusdc.winner | ||
LEFT JOIN ( | ||
SELECT amount_earned, winner | ||
FROM lootbox_amounts_rewarded | ||
WHERE token_short_name = 'ARB' AND epoch = epoch_ | ||
) AS lootbox_amounts_rewarded_arb ON lb.address = lootbox_amounts_rewarded_arb.winner | ||
LEFT JOIN lootbox_referrals | ||
ON lb.address = lootbox_referrals.referrer | ||
LEFT JOIN fly_staked | ||
ON lb.address = fly_staked.address, | ||
LATERAL calculate_a_y(lb.address, now()::TIMESTAMP) AS liquidity | ||
GROUP BY | ||
lb.address, | ||
liquidity_multiplier, | ||
total_box_count, | ||
highest_reward_tier, | ||
lootbox_amounts_rewarded_fusdc.amount_earned, | ||
lootbox_amounts_rewarded_arb.amount_earned, | ||
fly_staked.address, | ||
fly_staked.amount | ||
$function$; | ||
|
||
-- migrate:down | ||
|
||
CREATE OR REPLACE FUNCTION airdrop_leaderboard_24_hours(epoch_ lootbox_epoch) | ||
RETURNS SETOF airdrop_leaderboard_return | ||
LANGUAGE sql | ||
STABLE | ||
AS $function$ | ||
SELECT | ||
address, | ||
-- placeholder | ||
ROW_NUMBER() OVER () AS rank, | ||
COUNT(DISTINCT referee) AS referral_count, | ||
lb.total_box_count, | ||
lb.highest_reward_tier, | ||
COALESCE(liquidity.result, 1) AS liquidity_multiplier, | ||
COALESCE(lootbox_amounts_rewarded_fusdc.amount_earned, 0), | ||
COALESCE(lootbox_amounts_rewarded_arb.amount_earned, 0) | ||
FROM ( | ||
-- subquery to avoid re-summing lootbox_count for every referee | ||
SELECT address, SUM(lootbox_count) as total_box_count, MAX(reward_tier) as highest_reward_tier | ||
FROM lootbox | ||
WHERE awarded_time > now() - interval '1 day' AND epoch = epoch_ | ||
GROUP BY address | ||
) lb | ||
LEFT JOIN ( | ||
SELECT amount_earned, winner | ||
FROM lootbox_amounts_rewarded | ||
WHERE token_short_name = 'USDC' AND epoch = epoch_ | ||
) AS lootbox_amounts_rewarded_fusdc ON lb.address = lootbox_amounts_rewarded_fusdc.winner | ||
LEFT JOIN ( | ||
SELECT amount_earned, winner | ||
FROM lootbox_amounts_rewarded | ||
WHERE token_short_name = 'ARB' AND epoch = epoch_ | ||
) AS lootbox_amounts_rewarded_arb ON lb.address = lootbox_amounts_rewarded_arb.winner | ||
LEFT JOIN lootbox_referrals | ||
ON lb.address = lootbox_referrals.referrer, | ||
LATERAL calculate_a_y(address, now()::TIMESTAMP) AS liquidity | ||
GROUP BY | ||
address, | ||
liquidity_multiplier, | ||
total_box_count, | ||
highest_reward_tier, | ||
lootbox_amounts_rewarded_fusdc.amount_earned, | ||
lootbox_amounts_rewarded_arb.amount_earned | ||
$function$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters