From 16314fde1ec37670aea97b676156be443abe62c6 Mon Sep 17 00:00:00 2001 From: gpsanant Date: Wed, 11 Dec 2024 21:24:09 -0800 Subject: [PATCH] fix: null no registration case --- pkg/rewards/7_goldActiveODRewards.go | 31 +++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/rewards/7_goldActiveODRewards.go b/pkg/rewards/7_goldActiveODRewards.go index 8d22fba8..07dc1539 100644 --- a/pkg/rewards/7_goldActiveODRewards.go +++ b/pkg/rewards/7_goldActiveODRewards.go @@ -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, @@ -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