Skip to content

Commit

Permalink
feat(abstractions): dune-abstractions update
Browse files Browse the repository at this point in the history
sync abstractions with dune-analytics repo
  • Loading branch information
sam committed Mar 7, 2021
1 parent 2a040f7 commit 467b3d7
Show file tree
Hide file tree
Showing 34 changed files with 977 additions and 788 deletions.
38 changes: 38 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# EditorConfig http://EditorConfig.org

# top-most EditorConfig file
root = true

# All files
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

# Solidity Contracts
[*.{sol,solidity}]
indent_size = 4

# JavaScript, JSON, JSX, JavaScript Modules, TypeScript
[*.{cjs,js,json,jsx,mjs,ts,tsx}]
indent_size = 2
indent_style = space

# Shell
[*.{bash,sh,zsh}]
indent_size = 2
indent_style = space

# TOML
[*.toml]
indent_size = 2
indent_style = space

# YAML
[*.{yaml,yml}]
indent_size = 2
indent_style = space
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
.DS_Store
node_modules
package-lock.json
*.tgz
*.zip
*.tar.gz
*.tar
*.log

.vscode/*
!.vscode/settings.json.default
tmp/
18 changes: 18 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @file Prettier configuration for Solidity
* @version 1.0.3
* @summary base config adapted from AirBNB to minizmie diff churn
* @overrides solidity settings from Solidity Documentation
*/

'use strict';

module.exports = {
arrowParens: "always",
bracketSpacing: true,
endOfLine: "lf",
printWidth: 100,
singleQuote: true,
tabWidth: 2,
trailingComma: "all",
};
73 changes: 0 additions & 73 deletions CHANGELOG.md

This file was deleted.

9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
define npm_script_targets
TARGETS := $(shell node -e 'for (var k in require("./package.json").scripts) {console.log(k.replace(/:/g, "-"));}')
$$(TARGETS):
npm run $(subst -,:,$(MAKECMDGOALS))

.PHONY: $$(TARGETS)
endef

$(eval $(call npm_script_targets))
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

49 changes: 49 additions & 0 deletions dune/aave/Borrow_Amt30.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
SELECT sum(amt*price) as borrow
FROM
(

-- Aave v1
SELECT sum("_amount"/10^decimals) as amt
,t.symbol as token
,date(evt_block_time) as dt
FROM aave."LendingPool_evt_Borrow" Borrow
LEFT JOIN erc20."tokens" t ON Borrow."_reserve" = t.contract_address
WHERE evt_block_time > now() - interval '30 days'
GROUP BY 2,3

UNION ALL

-- Aave v2
SELECT sum("amount"/10^decimals) as amt
,t.symbol as token
,date(evt_block_time) as dt
FROM aave_v2."LendingPool_evt_Borrow" Borrow
LEFT JOIN erc20."tokens" t ON Borrow."reserve" = t.contract_address
WHERE evt_block_time > now() - interval '30 days'
GROUP BY 2,3

)main

LEFT JOIN


(SELECT avg(price) AS price,
date(MINUTE) AS dt,
symbol
FROM prices.usd
WHERE symbol<>'ETH'
AND MINUTE > now() - interval '30 days'
GROUP BY 2,
3

UNION SELECT avg(price) AS price,
date(MINUTE) AS dt,
symbol
FROM prices.layer1_usd_eth
WHERE symbol='ETH'
AND MINUTE > now() - interval '30 days'
GROUP BY 2,
3)p

ON main.dt = p.dt
AND p.symbol = main.token
49 changes: 49 additions & 0 deletions dune/aave/Borrow_Amt7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
SELECT sum(amt*price) as borrow
FROM
(

-- Aave v1
SELECT sum("_amount"/10^decimals) as amt
,t.symbol as token
,date(evt_block_time) as dt
FROM aave."LendingPool_evt_Borrow" Borrow
LEFT JOIN erc20."tokens" t ON Borrow."_reserve" = t.contract_address
WHERE evt_block_time > now() - interval '7 days'
GROUP BY 2,3

UNION ALL

-- Aave v2
SELECT sum("amount"/10^decimals) as amt
,t.symbol as token
,date(evt_block_time) as dt
FROM aave_v2."LendingPool_evt_Borrow" Borrow
LEFT JOIN erc20."tokens" t ON Borrow."reserve" = t.contract_address
WHERE evt_block_time > now() - interval '7 days'
GROUP BY 2,3

)main

LEFT JOIN


(SELECT avg(price) AS price,
date(MINUTE) AS dt,
symbol
FROM prices.usd
WHERE symbol<>'ETH'
AND MINUTE > now() - interval '7 days'
GROUP BY 2,
3

UNION SELECT avg(price) AS price,
date(MINUTE) AS dt,
symbol
FROM prices.layer1_usd_eth
WHERE symbol='ETH'
AND MINUTE > now() - interval '7 days'
GROUP BY 2,
3)p

ON main.dt = p.dt
AND p.symbol = main.token
43 changes: 43 additions & 0 deletions dune/aave/FlashLoanCumluative.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
WITH fl AS
(
SELECT
evt_block_time,
t.symbol as token,
sum("amount"/10^decimals) as amount
FROM aave_v2."LendingPool_evt_FlashLoan" fl
LEFT JOIN erc20."tokens" t ON fl."asset" = t.contract_address
GROUP BY 1,2
)

select dt, sum(USDamt) over (
ORDER BY dt ASC ROWS BETWEEN unbounded preceding AND CURRENT ROW) AS total_usd
from
(select dt,sum(USDamt) as USDamt
from
(select min(day) as dt,
USDvalue as USDamt
from
(SELECT
date_trunc('day',evt_block_time) as day,
sum(amount*price) As USDvalue
from fl
LEFT JOIN
(SELECT avg(price) AS price,
date(MINUTE) AS dt,
symbol
FROM prices.usd
WHERE symbol<>'ETH'
GROUP BY 2,
3
UNION SELECT avg(price) AS price,
date(MINUTE) AS dt,
symbol
FROM prices.layer1_usd_eth
WHERE symbol='ETH'
GROUP BY 2,
3)p
ON date(evt_block_time) = p.dt
AND p.symbol = fl.token
group by 1) t1
group by 2) t2
group by 1)t3
55 changes: 55 additions & 0 deletions dune/aave/TransactionVolumePerMonth.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
with transactions as
(
select tok.symbol
, evt_block_time
, sum("value"/10^v.decimals) as amt
from erc20."ERC20_evt_Transfer" t
inner join
(
select * from dune_user_generated."view_v2_atokens"
union all
select * from dune_user_generated."view_v1_atokens"
) v
on v. contract_address = t.contract_address
left join erc20."tokens" tok on tok.contract_address = v.underlying_token_address
--where evt_block_time > now() - interval '1 days'


group by 1,2
order by 3 desc

)

, prices as
(
SELECT avg(price) AS price,
date(MINUTE) AS dt,
symbol
FROM prices.usd
WHERE symbol<>'ETH'
--and minute > now() - interval '1 days'

GROUP BY 2,3

UNION SELECT avg(price) AS price,
date(MINUTE) AS dt,
symbol
FROM prices.layer1_usd_eth
WHERE symbol='ETH'
-- and minute > now() - interval '1 days'
GROUP BY 2,3
)

SELECT t.symbol
, date_trunc('month', evt_block_time) as month
, sum(amt*price) as "usd amount"
from transactions t
left join prices p on date(evt_block_time) = p.dt
AND p.symbol = t.symbol
group by 1,2
order by 3 desc




--select * from erc20."tokens"
1 change: 0 additions & 1 deletion dune/abstractions/VERSION

This file was deleted.

Loading

0 comments on commit 467b3d7

Please sign in to comment.