Query editor
with gm as (select symbol, address, address_bnb, address_sol from dune.ondo_team.result_ondo_assets where symbol <> 'USDon'),gm_px as (select symbol, max_by(price, day) price from query_5653985 where price is not null and day >= current_date - interval '14' day group by 1),evm_tokens (blockchain, contract_address, product, symbol, px) as (select 'ethereum', address, 'GM', g.symbol, p.price from gm g join gm_px p on p.symbol = g.symbol where address is not nullunion allselect 'bnb', address_bnb, 'GM', g.symbol, p.price from gm g join gm_px p on p.symbol = g.symbol where address_bnb is not nullunion allselect * from (values('ethereum', 0x96f6ef951840721adbf46ac996b59e0235cb985c, 'USDY', 'USDY', 1.150928e0),('ethereum', 0xaf37c1167910ebc994e266949387d2c7c326b879, 'USDY', 'rUSDY', 1.0e0),('mantle', 0x5be26527e817998a7206475496fde1e68957c5a6, 'USDY', 'USDY', 1.150928e0),('mantle', 0xab575258d37eaa5c8956efabe71f4ee8f6397cf3, 'USDY', 'mUSD', 1.0e0),('arbitrum', 0x35e050d3c0ec2d29d269a8ecea763a183bdf9a9d, 'USDY', 'USDY', 1.150928e0),('ethereum', 0x1b19c19393e2d034d8ff31ff34c81252fcbbee92, 'OUSG', 'OUSG', 115.7e0),('ethereum', 0x54043c656f0fad0652d9ae2603cdf347c5578d00, 'OUSG', 'rOUSG', 1.0e0),('polygon', 0xba11c5effa33c4d6f8f593cfa394241cfe925811, 'OUSG', 'OUSG', 115.7e0)) as t(blockchain, contract_address, product, symbol, px)),excluded (a) as (values0x0000000000000000000000000000000000000000,0xaf37c1167910ebc994e266949387d2c7c326b879, -- rUSDY wrapper (holds USDY)0x54043c656f0fad0652d9ae2603cdf347c5578d00, -- rOUSG wrapper (holds OUSG)0xab575258d37eaa5c8956efabe71f4ee8f6397cf3 -- mUSD wrapper (holds USDY)),xfers as (select 'ethereum' blockchain, contract_address, "from", "to", value from erc20_ethereum.evt_transferwhere evt_block_date >= date '2023-01-01' and contract_address in (select contract_address from evm_tokens where blockchain='ethereum')union allselect 'bnb', contract_address, "from", "to", value from erc20_bnb.evt_transferwhere evt_block_date >= date '2025-10-01' and contract_address in (select contract_address from evm_tokens where blockchain='bnb')union allselect 'mantle', contract_address, "from", "to", value from erc20_mantle.evt_transferwhere evt_block_date >= date '2023-07-01' and contract_address in (select contract_address from evm_tokens where blockchain='mantle')union allselect 'arbitrum', contract_address, "from", "to", value from erc20_arbitrum.evt_transferwhere evt_block_date >= date '2023-07-01' and contract_address in (select contract_address from evm_tokens where blockchain='arbitrum')union allselect 'polygon', contract_address, "from", "to", value from erc20_polygon.evt_transferwhere evt_block_date >= date '2023-07-01' and contract_address in (select contract_address from evm_tokens where blockchain='polygon')),deltas as (select blockchain, contract_address, "to" wallet, cast(value as double) d from xfersunion allselect blockchain, contract_address, "from", -cast(value as double) from xfers),evm_bal as (select lower(cast(d.wallet as varchar)) wallet, t.product, sum(d.d) / 1e18 * max(t.px) usdfrom deltas d join evm_tokens t on t.blockchain = d.blockchain and t.contract_address = d.contract_addresswhere d.wallet not in (select a from excluded)group by 1, 2, d.blockchain, d.contract_address),sol_tokens (mint, product, px) as (select address_sol, 'GM', p.price from gm g join gm_px p on p.symbol = g.symbol where address_sol is not nullunion all select 'A1KLoBrKBde8Ty9qtNQUtq3C2ortoC3u7twggz7sEto6', 'USDY', 1.150928e0union all select 'i7u4r16TcsJTgq1kAG8opmVZyVnAKBwLKu6ZPMwzxNc', 'OUSG', 115.7e0),