Query editor
-- 元クエリ: 2783004 "Rysk DHV PL" / https://dune.com/queries/2783004-- Rysk DHV の建玉/損益をオプション単位で集計する。-- 変更点(元 SQL のバグ修正を含む。セマンティクスが変わる箇所は明記):-- - 元 SQL の `CAST(... AS INT)` は uint256 の生値を 32bit 整数に入れようとして "Overflow when converting UINT256 to Integer" で落ちる。`CAST(... AS DOUBLE)` に変更した(切り捨てが無くなるので小数以下が残る=値の精度が上がる方向)withoptions as (select- CAST(optionamount / 1e18 as DOUBLE) as optionamount,evt_block_time,- CAST(premium as DOUBLE) as premium,seriesfromrysk_beyond_arbitrum.optionexchange_evt_optionssold socunion allselectCAST(optionamount / 1e18 as DOUBLE) as optionamount,evt_block_time,CAST(premium as DOUBLE) as premium,seriesfromrysk_beyond_arbitrum.optionexchange_evt_optionsbought),positions as (selectseries,sum(optionamount) as netAmount,sum(premium) / 1e6 as plfromoptionsgroup byseries),settle as (SELECTcollateralLost / 1e6 as pl,seriesfromrysk_beyond_arbitrum.LiquidityPool_evt_SettleVaultWHEREevt_block_time >= TIMESTAMP '2023-07-28'),profit as (selectsettle.series as series,SUM(settle.pl + positions.pl) as totalPLfromsettlejoin positions ON settle.series = positions.seriesGROUP BYsettle.series)selectseries,totalPLfromprofit