Skip to content

Commit 467b3d7

Browse files
author
sam
committed
feat(abstractions): dune-abstractions update
sync abstractions with dune-analytics repo
1 parent 2a040f7 commit 467b3d7

34 files changed

+977
-788
lines changed

.editorconfig

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
# EditorConfig http://EditorConfig.org
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
# All files
8+
[*]
9+
charset = utf-8
10+
end_of_line = lf
11+
indent_size = 2
12+
indent_style = space
13+
insert_final_newline = true
14+
trim_trailing_whitespace = true
15+
16+
# Solidity Contracts
17+
[*.{sol,solidity}]
18+
indent_size = 4
19+
20+
# JavaScript, JSON, JSX, JavaScript Modules, TypeScript
21+
[*.{cjs,js,json,jsx,mjs,ts,tsx}]
22+
indent_size = 2
23+
indent_style = space
24+
25+
# Shell
26+
[*.{bash,sh,zsh}]
27+
indent_size = 2
28+
indent_style = space
29+
30+
# TOML
31+
[*.toml]
32+
indent_size = 2
33+
indent_style = space
34+
35+
# YAML
36+
[*.{yaml,yml}]
37+
indent_size = 2
38+
indent_style = space

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
.DS_Store
22
node_modules
3+
package-lock.json
4+
*.tgz
5+
*.zip
6+
*.tar.gz
7+
*.tar
8+
*.log
9+
10+
.vscode/*
11+
!.vscode/settings.json.default
12+
tmp/

.prettierrc.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @file Prettier configuration for Solidity
3+
* @version 1.0.3
4+
* @summary base config adapted from AirBNB to minizmie diff churn
5+
* @overrides solidity settings from Solidity Documentation
6+
*/
7+
8+
'use strict';
9+
10+
module.exports = {
11+
arrowParens: "always",
12+
bracketSpacing: true,
13+
endOfLine: "lf",
14+
printWidth: 100,
15+
singleQuote: true,
16+
tabWidth: 2,
17+
trailingComma: "all",
18+
};

CHANGELOG.md

-73
This file was deleted.

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
define npm_script_targets
2+
TARGETS := $(shell node -e 'for (var k in require("./package.json").scripts) {console.log(k.replace(/:/g, "-"));}')
3+
$$(TARGETS):
4+
npm run $(subst -,:,$(MAKECMDGOALS))
5+
6+
.PHONY: $$(TARGETS)
7+
endef
8+
9+
$(eval $(call npm_script_targets))

VERSION

-1
This file was deleted.

dune/aave/Borrow_Amt30.sql

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
SELECT sum(amt*price) as borrow
2+
FROM
3+
(
4+
5+
-- Aave v1
6+
SELECT sum("_amount"/10^decimals) as amt
7+
,t.symbol as token
8+
,date(evt_block_time) as dt
9+
FROM aave."LendingPool_evt_Borrow" Borrow
10+
LEFT JOIN erc20."tokens" t ON Borrow."_reserve" = t.contract_address
11+
WHERE evt_block_time > now() - interval '30 days'
12+
GROUP BY 2,3
13+
14+
UNION ALL
15+
16+
-- Aave v2
17+
SELECT sum("amount"/10^decimals) as amt
18+
,t.symbol as token
19+
,date(evt_block_time) as dt
20+
FROM aave_v2."LendingPool_evt_Borrow" Borrow
21+
LEFT JOIN erc20."tokens" t ON Borrow."reserve" = t.contract_address
22+
WHERE evt_block_time > now() - interval '30 days'
23+
GROUP BY 2,3
24+
25+
)main
26+
27+
LEFT JOIN
28+
29+
30+
(SELECT avg(price) AS price,
31+
date(MINUTE) AS dt,
32+
symbol
33+
FROM prices.usd
34+
WHERE symbol<>'ETH'
35+
AND MINUTE > now() - interval '30 days'
36+
GROUP BY 2,
37+
3
38+
39+
UNION SELECT avg(price) AS price,
40+
date(MINUTE) AS dt,
41+
symbol
42+
FROM prices.layer1_usd_eth
43+
WHERE symbol='ETH'
44+
AND MINUTE > now() - interval '30 days'
45+
GROUP BY 2,
46+
3)p
47+
48+
ON main.dt = p.dt
49+
AND p.symbol = main.token

dune/aave/Borrow_Amt7.sql

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
SELECT sum(amt*price) as borrow
2+
FROM
3+
(
4+
5+
-- Aave v1
6+
SELECT sum("_amount"/10^decimals) as amt
7+
,t.symbol as token
8+
,date(evt_block_time) as dt
9+
FROM aave."LendingPool_evt_Borrow" Borrow
10+
LEFT JOIN erc20."tokens" t ON Borrow."_reserve" = t.contract_address
11+
WHERE evt_block_time > now() - interval '7 days'
12+
GROUP BY 2,3
13+
14+
UNION ALL
15+
16+
-- Aave v2
17+
SELECT sum("amount"/10^decimals) as amt
18+
,t.symbol as token
19+
,date(evt_block_time) as dt
20+
FROM aave_v2."LendingPool_evt_Borrow" Borrow
21+
LEFT JOIN erc20."tokens" t ON Borrow."reserve" = t.contract_address
22+
WHERE evt_block_time > now() - interval '7 days'
23+
GROUP BY 2,3
24+
25+
)main
26+
27+
LEFT JOIN
28+
29+
30+
(SELECT avg(price) AS price,
31+
date(MINUTE) AS dt,
32+
symbol
33+
FROM prices.usd
34+
WHERE symbol<>'ETH'
35+
AND MINUTE > now() - interval '7 days'
36+
GROUP BY 2,
37+
3
38+
39+
UNION SELECT avg(price) AS price,
40+
date(MINUTE) AS dt,
41+
symbol
42+
FROM prices.layer1_usd_eth
43+
WHERE symbol='ETH'
44+
AND MINUTE > now() - interval '7 days'
45+
GROUP BY 2,
46+
3)p
47+
48+
ON main.dt = p.dt
49+
AND p.symbol = main.token

dune/aave/FlashLoanCumluative.sql

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
WITH fl AS
2+
(
3+
SELECT
4+
evt_block_time,
5+
t.symbol as token,
6+
sum("amount"/10^decimals) as amount
7+
FROM aave_v2."LendingPool_evt_FlashLoan" fl
8+
LEFT JOIN erc20."tokens" t ON fl."asset" = t.contract_address
9+
GROUP BY 1,2
10+
)
11+
12+
select dt, sum(USDamt) over (
13+
ORDER BY dt ASC ROWS BETWEEN unbounded preceding AND CURRENT ROW) AS total_usd
14+
from
15+
(select dt,sum(USDamt) as USDamt
16+
from
17+
(select min(day) as dt,
18+
USDvalue as USDamt
19+
from
20+
(SELECT
21+
date_trunc('day',evt_block_time) as day,
22+
sum(amount*price) As USDvalue
23+
from fl
24+
LEFT JOIN
25+
(SELECT avg(price) AS price,
26+
date(MINUTE) AS dt,
27+
symbol
28+
FROM prices.usd
29+
WHERE symbol<>'ETH'
30+
GROUP BY 2,
31+
3
32+
UNION SELECT avg(price) AS price,
33+
date(MINUTE) AS dt,
34+
symbol
35+
FROM prices.layer1_usd_eth
36+
WHERE symbol='ETH'
37+
GROUP BY 2,
38+
3)p
39+
ON date(evt_block_time) = p.dt
40+
AND p.symbol = fl.token
41+
group by 1) t1
42+
group by 2) t2
43+
group by 1)t3
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
with transactions as
2+
(
3+
select tok.symbol
4+
, evt_block_time
5+
, sum("value"/10^v.decimals) as amt
6+
from erc20."ERC20_evt_Transfer" t
7+
inner join
8+
(
9+
select * from dune_user_generated."view_v2_atokens"
10+
union all
11+
select * from dune_user_generated."view_v1_atokens"
12+
) v
13+
on v. contract_address = t.contract_address
14+
left join erc20."tokens" tok on tok.contract_address = v.underlying_token_address
15+
--where evt_block_time > now() - interval '1 days'
16+
17+
18+
group by 1,2
19+
order by 3 desc
20+
21+
)
22+
23+
, prices as
24+
(
25+
SELECT avg(price) AS price,
26+
date(MINUTE) AS dt,
27+
symbol
28+
FROM prices.usd
29+
WHERE symbol<>'ETH'
30+
--and minute > now() - interval '1 days'
31+
32+
GROUP BY 2,3
33+
34+
UNION SELECT avg(price) AS price,
35+
date(MINUTE) AS dt,
36+
symbol
37+
FROM prices.layer1_usd_eth
38+
WHERE symbol='ETH'
39+
-- and minute > now() - interval '1 days'
40+
GROUP BY 2,3
41+
)
42+
43+
SELECT t.symbol
44+
, date_trunc('month', evt_block_time) as month
45+
, sum(amt*price) as "usd amount"
46+
from transactions t
47+
left join prices p on date(evt_block_time) = p.dt
48+
AND p.symbol = t.symbol
49+
group by 1,2
50+
order by 3 desc
51+
52+
53+
54+
55+
--select * from erc20."tokens"

dune/abstractions/VERSION

-1
This file was deleted.

0 commit comments

Comments
 (0)