Skip to content

Commit

Permalink
fix: null no registration case
Browse files Browse the repository at this point in the history
  • Loading branch information
gpsanant committed Dec 12, 2024
1 parent cc55b0f commit 16314fd
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions pkg/rewards/7_goldActiveODRewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ active_rewards_cleaned AS (
)
-- Step 8: Divide by the number of snapshots that the operator was registered
num_registered_snapshots AS (
op_avs_num_registered_snapshots AS (
SELECT
arc.avs,
arc.operator,
Expand All @@ -133,25 +133,32 @@ num_registered_snapshots AS (
),
-- Step 9: Divide amount to pay by the number of snapshots that the operator was registered
active_rewards_final AS (
active_rewards_with_registered_snapshots AS (
SELECT
arc.*,
nrs.num_registered_snapshots,
COALESCE(nrs.num_registered_snapshots, 0) as num_registered_snapshots,
FROM active_rewards_cleaned arc
LEFT JOIN op_avs_num_registered_snapshots nrs
ON
arc.avs = nrs.avs
AND arc.operator = nrs.operator
),
-- Step 10: Divide amount to pay by the number of snapshots that the operator was registered
active_rewards_final AS (
SELECT
ar.*,
CASE
-- If the operator was not registered for any snapshots, just get regular tokens per day to refund the AVS
WHEN nrs.num_registered_snapshots = 0 THEN arc.amount_decimal / (duration / 86400)
ELSE arc.amount_decimal / nrs.num_registered_snapshots
WHEN ar.num_registered_snapshots = 0 THEN ar.amount_decimal / (duration / 86400)
ELSE ar.amount_decimal / ar.num_registered_snapshots
END AS tokens_per_day_decimal,
CASE
-- If the operator was not registered for any snapshots, just get regular tokens per day to refund the AVS
WHEN nrs.num_registered_snapshots = 0 THEN arc.amount / (duration / 86400)
ELSE arc.amount / nrs.num_registered_snapshots
WHEN ar.num_registered_snapshots = 0 THEN ar.amount / (duration / 86400)
ELSE ar.amount / ar.num_registered_snapshots
END AS tokens_per_day
FROM active_rewards_cleaned arc
JOIN num_registered_snapshots nrs
ON
arc.avs = nrs.avs
AND arc.operator = nrs.operator
FROM active_rewards_with_registered_snapshots ar
)
SELECT * FROM active_rewards_final
Expand Down

0 comments on commit 16314fd

Please sign in to comment.