Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create evt_borrow.sql #1

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions schema/compound_v2/evt_borrow.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SELECT t.symbol AS "symbol",
"borrowAmount"/10^t.decimals AS "borrowAmount",
"borrowAmount"/10^t.decimals*p.price AS "borrowAmountUSD",
"accountBorrows"/10^t.decimals AS "accountBorrows",
"totalBorrows"/10^t.decimals AS "totalBorrows",
events.contract_address AS "cToken",
c."underlying_token_address" AS "underlyingToken",
evt_tx_hash as tx_hash,
tx.block_time AS block_time
FROM
(SELECT * FROM compound_v2."cErc20_evt_Borrow"
UNION
SELECT * FROM compound_v2."cEther_evt_Borrow"
UNION
SELECT * FROM compound_v2."CErc20Delegator_evt_Borrow"
) events
LEFT JOIN compound_v2.view_ctokens c ON events.contract_address = c.contract_address
LEFT JOIN ethereum.transactions tx ON events.evt_tx_hash = tx.hash
LEFT JOIN erc20.tokens t ON c.underlying_token_address = t.contract_address
LEFT JOIN prices.usd p ON p.minute = date_trunc('minute', tx.block_time) AND p.contract_address = c.underlying_token_address
;