Query editor
with markets as (select evt_block_time, id, initialPrice, payoutToken, quoteToken, vestingfrom bondprotocol_ethereum.BondFixedTermSDA_evt_MarketCreated),bonds as (select evt_block_time, evt_tx_hash, id,cast(amount as double) as amount, cast(payout as double) as payoutfrom bondprotocol_ethereum.BondFixedTermTeller_evt_Bonded),prices as (select * from prices.usdwhere minute >= cast('2022-11-01' as timestamp)and blockchain = 'ethereum'),tab as (selectb.evt_block_time,b.id,-- b.amount as quoteAmountRaw,-- b.payout as payoutAmountRaw,b.amount / power(10, pq.decimals) as quoteAmount,b.payout / power(10, pp.decimals) as payoutAmount,m.quoteToken,m.payoutToken,date_add('second', m.vesting, b.evt_block_time) as vesting,(b.amount / power(10, pq.decimals))* pq.price/ (b.payout / power(10, pp.decimals)) as bondPrice,pp.price as marketPrice,evt_tx_hashfrom bonds binner join markets mon b.id = m.idleft join prices pqon m.quoteToken = pq.contract_addressand date_trunc('minute', b.evt_block_time) = pq.minuteleft join prices ppon m.payoutToken = pp.contract_addressand date_trunc('minute', b.evt_block_time) = pp.minute)select -100 * (bondPrice - marketPrice) / marketPrice as discount,*from tabwhere 1 is not nullorder by 1 desc