Query editor
-- 元クエリ: 2387181 "Historical apy calc as apr aUSDCb2" / https://dune.com/queries/2387181-- a3USDC borrow apr16 プールの満期までの実現 APY を逆算する。-- 変更点(元 SQL のバグ修正を含む。セマンティクスが変わる箇所は明記):-- - 元 SQL の `TIMESTAMP '1685523600'` は epoch 秒を TIMESTAMP リテラルに渡していて不正。`from_unixtime(1685523600)`(= 2023-05-31 09:00:00 UTC)に修正-- - uint256 / int256 列の除算・乗算に cast(... as double) を明示(Trino は整数同士の除算を切り捨て、uint256×double も暗黙変換しない)。合計は sum(cast(col as decimal(38,0))) で Spark と同じ精度を保つwithdataset as (SELECTevt_block_time,date_diff('second',from_unixtime(1685523600),evt_block_time) as sincestart,- cast(fixedTokenDeltaUnbalanced as double) / 1e18 as ufix,cast(variableTokenDelta as double) / 1e18 as var,- cast(fixedTokenDelta as double) / 1e18 as fix,recipientfromvoltz_arbitrum.a3USDC_borrow_may31_92days_vamm_evt_Swap),setting as (SELECTevt_block_time,ufix / var as price,fix / var as prediction,sincestartfromdataset),calc as (SELECTevt_block_time,(prediction * 7959600 - (7959600 - sincestart) * price) / sincestart as apy,price,prediction,sincestartfromsetting),calc2 as (SELECTevt_block_time,apy,price,prediction,sincestart,apy * sincestart / (36 * 24 * 365 * 1e4) as accruedfromcalc),calc3 as (selectevt_block_time,apy,price,prediction,accrued,