Skip to content

Commit

Permalink
restore calcuation of epoch days (#2610)
Browse files Browse the repository at this point in the history
* 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
eli-d authored Apr 8, 2024
1 parent 81cd0cf commit 214cfa9
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 3 deletions.
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$;
18 changes: 18 additions & 0 deletions web/app.fluidity.money/app/routes/$network/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
Modal,
ProvideLiquidity,
BurgerMenu,
Referral,
CardModal,
ArrowUp,
ArrowDown,
Expand Down Expand Up @@ -688,6 +689,23 @@ export default function Dashboard() {
</>
)}

{/* Referrals Button (desktop only) */}
{isTablet || isMobile || (
<GeneralButton
type="transparent"
size="small"
layout="before"
handleClick={() => {
width < airdropMobileBreakpoint
? navigate(`/${network}/dashboard/airdrop#referrals`)
: setReferralModalVisibility(true);
}}
icon={<Referral />}
>
{isMobile ? "" : "Referral"}
</GeneralButton>
)}

{/* Fluidify button (desktop only) */}
{isTablet || isMobile || (
<GeneralButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ const Airdrop = () => {
defaultTokens.map((tok) => ({ ...tok, userTokenBalance: new BN(0) }))
);

const [leaderboardFilterIndex, setLeaderboardFilterIndex] = useState(1);
const [leaderboardFilterIndex, setLeaderboardFilterIndex] = useState(0);

const { width } = useViewport();

Expand Down Expand Up @@ -1351,8 +1351,10 @@ const AirdropStats = ({
navigate,
isMobile,
}: IAirdropStats) => {
const epochDaysLeft = 89;
const epochPercentage = 0;
const dayDiff = epochMax - epochDays
const epochDaysLeft = dayDiff > 0 ? dayDiff : 0
const percentage = Math.floor((epochDays / epochMax) * 100)
const epochPercentage = percentage < 100 ? percentage : 100

return (
<div
Expand Down Expand Up @@ -1801,6 +1803,14 @@ const Leaderboard = ({
</Text>
</div>
<div className="leaderboard-header-filters">
<GeneralButton
type={filterIndex === 0 ? "primary" : "transparent"}
handleClick={() => setFilterIndex(0)}
>
<Text code size="sm" style={{ color: "inherit" }}>
24 HOURS
</Text>
</GeneralButton>
<GeneralButton
type={filterIndex === 1 ? "primary" : "transparent"}
handleClick={() => setFilterIndex(1)}
Expand Down

0 comments on commit 214cfa9

Please sign in to comment.