Query editor
WITHeth_prices AS (SELECTdate_trunc('day', minute) AS _time,AVG(price) AS eth_priceFROMprices.usdWHEREcontract_address = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2GROUP BY1),my_loans AS (SELECTevt_block_time,loanId,eth_prices.eth_price,CASEWHEN json_query(loanTerms,'lax $.loanERC20Denomination' omit quotes) = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 THEN CAST(CAST(json_query(loanTerms, 'lax $.loanPrincipalAmount') AS UINT256) * CAST(100000 AS UINT256) / CAST(1e18 AS UINT256) AS DOUBLE) * eth_price / 100000ELSE CAST(CAST(json_query(loanTerms, 'lax $.loanPrincipalAmount') AS UINT256) * CAST(100000 AS UINT256) / CAST(1e18 AS UINT256) AS DOUBLE) / 100000END AS principalFROMnftfi_ethereum.DirectLoanFixedCollectionOffer_evt_LoanStartedLEFT JOIN eth_prices ON (date_trunc('day', evt_block_time) = eth_prices._time)WHERElender = 0xd8345fE045220f894f1f77ba29764793b93BD2a7),repaid_loans AS (SELECTevt_block_time,eth_prices.eth_price,loanId,CASEWHEN loanERC20Denomination = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 THEN CAST(CAST(amountPaidToLender AS UINT256) * CAST(100000 AS UINT256) / CAST(1e18 AS UINT256) AS DOUBLE) * eth_price / 100000ELSE CAST(CAST(amountPaidToLender AS UINT256) * CAST(100000 AS UINT256) / CAST(1e18 AS UINT256) AS DOUBLE) / 100000END AS repaid_amount_usdFROMnftfi_ethereum.DirectLoanFixedCollectionOffer_evt_LoanRepaidLEFT JOIN eth_prices ON (loanERC20Denomination = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2AND date_trunc('day', evt_block_time) = eth_prices._time)WHERE