Skip to content

Commit bc88fc5

Browse files
committed
fix: update numeric handling in upsertProtocolDailyStatDetails
Refactored the SQL queries in the upsertProtocolDailyStatDetails function to ensure proper numeric handling by explicitly casting values to numeric types. This change improves the accuracy of calculations for rates, total assets, and yields, enhancing the overall data integrity in the protocol's daily statistics.
1 parent 7383ca1 commit bc88fc5

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/mainnet/processors/protocol/protocol-sql-simple.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ const upsertProtocolDailyStatDetails = async (ctx: Context, fromDate: string) =>
9292
a.date,
9393
'${product.product}' as product,
9494
(a.date::date + interval '1 day' - interval '1 second')::timestamp as timestamp,
95-
COALESCE(ROUND(a.rate_usd * 1e18), 0) as rate_usd,
96-
COALESCE(ROUND(a.rate_eth * 1e18), 0) as rate_eth,
97-
COALESCE(TRUNC(a.total_assets * POWER(10, 18 - a.asset_decimals[1]) * ROUND(a.rate_eth * 1e18) / 1e18, 0), 0) as earning_tvl,
98-
COALESCE(TRUNC(a.total_assets * POWER(10, 18 - a.asset_decimals[1]) * ROUND(a.rate_eth * 1e18) / 1e18, 0), 0) as tvl,
99-
COALESCE(TRUNC(a.total_supply * ROUND(a.rate_eth * 1e18) / 1e18, 0), 0) as supply,
100-
COALESCE(TRUNC((a.yield + a.fees) * POWER(10, 18 - a.asset_decimals[1]) * ROUND(a.rate_eth * 1e18) / 1e18, 0), 0) as yield,
101-
COALESCE(TRUNC(a.fees * POWER(10, 18 - a.asset_decimals[1]) * ROUND(a.rate_eth * 1e18) / 1e18, 0), 0) as revenue,
95+
COALESCE(ROUND(a.rate_usd::numeric * 1e18::numeric, 0), 0) as rate_usd,
96+
COALESCE(ROUND(a.rate_eth::numeric * 1e18::numeric, 0), 0) as rate_eth,
97+
COALESCE(TRUNC(a.total_assets * POWER(10::numeric, (18 - a.asset_decimals[1])::numeric) * ROUND(a.rate_eth::numeric * 1e18::numeric, 0) / 1e18::numeric, 0), 0) as earning_tvl,
98+
COALESCE(TRUNC(a.total_assets * POWER(10::numeric, (18 - a.asset_decimals[1])::numeric) * ROUND(a.rate_eth::numeric * 1e18::numeric, 0) / 1e18::numeric, 0), 0) as tvl,
99+
COALESCE(TRUNC(a.total_supply * ROUND(a.rate_eth::numeric * 1e18::numeric, 0) / 1e18::numeric, 0), 0) as supply,
100+
COALESCE(TRUNC((a.yield + a.fees) * POWER(10::numeric, (18 - a.asset_decimals[1])::numeric) * ROUND(a.rate_eth::numeric * 1e18::numeric, 0) / 1e18::numeric, 0), 0) as yield,
101+
COALESCE(TRUNC(a.fees * POWER(10::numeric, (18 - a.asset_decimals[1])::numeric) * ROUND(a.rate_eth::numeric * 1e18::numeric, 0) / 1e18::numeric, 0), 0) as revenue,
102102
COALESCE(a.apy, 0) as apy,
103103
0 as inherited_tvl,
104104
0 as inherited_yield,

0 commit comments

Comments
 (0)