SELECT
b.CTOKEN_SYMBOL AS asset_class,
AVG(r.REPAYED_AMOUNT_USD) AS average_repayment_amount_usd,
AVG(DATEDIFF('hour', b.BLOCK_TIMESTAMP, r.BLOCK_TIMESTAMP)) AS average_repayment_time_hours
FROM
ethereum.compound.ez_repayments AS r
INNER JOIN
ethereum.compound.ez_borrows AS b
ON
r.BORROWER = b.BORROWER
AND r.CTOKEN = b.CTOKEN
AND r.TX_HASH <> b.TX_HASH -- Ensuring a repayment is a different transaction from the borrow
AND r.BLOCK_TIMESTAMP > b.BLOCK_TIMESTAMP -- Ensures that repayment is after borrowing
GROUP BY
asset_class