Query editor
with iv_mint as (select tx_hash,max(case when varbinary_starts_with(input, 0x77097fc8) then 'mint'when varbinary_starts_with(input, 0xd717d59d) then 'redeem'end) as div,max(from_utf8(substr(input, 101, 1000))) as promo_codefrom arbitrum.traceswhere to = 0xbc14d8563b248b79689ecbc43bba53290e0b6b66and block_time >= timestamp '2023-12-01'and successand ( varbinary_starts_with(input, 0x77097fc8) -- mintor varbinary_starts_with(input, 0xd717d59d) -- redeem)group by 1),iv_cost as (select a.tx_hash,sum(value/1e18) as tot_costfrom arbitrum.traces ainner join iv_mint b on b.tx_hash = a.tx_hashwhere to = 0xfcf7248c495d6fd3641ee43f861c48ebe402c878and a.block_time >= timestamp '2023-12-01'and successgroup by 1),iv_tier as (select cast(index as integer) + 1 as tier,quantity as amount,sum(quantity) over (order by index) - quantity + 1 as token_str_id,sum(quantity) over (order by index) as token_end_id,list_pricefrom (select a.*,a.price/1e18 as list_price,row_number() over (partition by index order by evt_block_time desc, evt_index desc) as rkfrom xai_snl_arbitrum.NodeLicense5_evt_PricingTierSetOrAdded a) awhere rk = 1),iv_raw as (select a.evt_block_time as block_time,a.to as buyer,cast(tokenId as decimal) as token_id,r.div,case when length(r.promo_code) > 0 then 'Y'else 'N'end as promo_applied,case when length(r.promo_code) > 0 then r.promo_codeelse '[None]'end as promo_code,a.evt_tx_hash as tx_hash,c.tot_cost as tx_cost,sum(1) over (partition by a.evt_tx_hash) as mint_per_tx-- ,sum(case when div = 'mint' then 1 end) over (order by cast(tokenId as decimal)) as actual_mint_ord,t.tier,round(t.list_price,7) as list_price,round(c.tot_cost / sum(1) over (partition by a.evt_tx_hash),7) as actual_price,round(1 - c.tot_cost / sum(1) over (partition by a.evt_tx_hash) / t.list_price, 4) as discount_ratiofrom erc721_arbitrum.evt_Transfer aleft join iv_mint r on r.tx_hash = a.evt_tx_hashleft join iv_cost c on c.tx_hash = a.evt_tx_hash