Query editor
witharcade as(select call_block_time,loanId,lender,borrower,durationdays,principal,((apr * principal)/(principal))/(durationdays)*365 as APR,loan_currency,CASE WHEN loan_currency != 'ETH' THEN principal / eth_price.eth_priceELSE principalEND as loan_value_eth,rollover,date_add('day',CAST(durationdays AS BIGINT),call_block_time) as due_date,contract_address,eth_price.eth_price as daily_eth_price,call_tx_hash as tx_hashFROM(SELECT call_block_time, date_trunc('day', call_block_time) as day,loanId, lender, borrower,durationsecs/86400 as durationdays,contract_address, call_tx_hash,CASE WHEN currency = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 THEN 'ETH'WHEN currency = 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 THEN 'USDC'WHEN currency = 0x6b175474e89094c44da98b954eedeac495271d0f THEN 'DAI'ELSE CAST(currency AS VARCHAR) END AS loan_currency,CASE WHEN currency = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 THEN principal/1e18WHEN currency = 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 THEN principal/1e6WHEN currency = 0x6b175474e89094c44da98b954eedeac495271d0f THEN principal/1e18ELSE NULL END as principal, rollover,aprFROM(SELECT call_block_time,loanId, lender, borrower,contract_address, call_tx_hash,created_qv.durationsecs, created_qv.currency, created_qv.principal,CAST(((created_qv.interest/created_qv.principal) / (created_qv.durationsecs/86400)*365)*100 AS DOUBLE) as APR,'No' as RolloverFROM(SELECT *FROM pawnfi_ethereum.LoanCore_call_startLoanWHERE call_success) as svLEFT JOIN(select CAST(json_extract_scalar(terms, '$.durationSecs') AS UINT256) AS durationSecs,CAST(json_extract_scalar(terms, '$.interest') AS UINT256) AS interest,CAST(json_extract_scalar(terms, '$.principal') AS UINT256) AS principal,from_hex(json_extract_scalar(terms, '$.payableCurrency')) AS currency,cv.evt_tx_hash,'No' as RolloverFROM pawnfi_ethereum.LoanCore_evt_LoanCreated cv)as created_qvon sv.call_tx_hash = created_qv.evt_tx_hashUNION ALL