Skip to content

Commit e65a9fe

Browse files
authored
feat: Velora (former paraswap) add Gnosis config
1 parent d68ff34 commit e65a9fe

4 files changed

Lines changed: 329 additions & 0 deletions

File tree

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
version: 2
2+
3+
models:
4+
- name: paraswap_v6_gnosis_trades
5+
meta:
6+
blockchain: gnosis
7+
sector: dex
8+
project: paraswap_v6
9+
contributors: eptighte
10+
config:
11+
tags: ['gnosis','paraswap_v6','trades', 'paraswap','dex', "velora"]
12+
description: >
13+
Paraswap V6 contract aggregator trades on gnosis
14+
data_tests:
15+
- dbt_utils.unique_combination_of_columns:
16+
combination_of_columns:
17+
- block_date
18+
- blockchain
19+
- project
20+
- version
21+
- tx_hash
22+
- method
23+
- trace_address
24+
25+
- check_dex_aggregator_seed:
26+
blockchain: gnosis
27+
project: paraswap
28+
version: 6
29+
columns:
30+
- *blockchain
31+
- *project
32+
- *version
33+
- *block_date
34+
- *block_time
35+
- *token_bought_symbol
36+
- *token_sold_symbol
37+
- *token_pair
38+
- *token_bought_amount
39+
- *token_sold_amount
40+
- *token_bought_amount_raw
41+
- *token_sold_amount_raw
42+
- *amount_usd
43+
- *token_bought_address
44+
- *token_sold_address
45+
- *taker
46+
- *maker
47+
- *project_contract_address
48+
- *tx_hash
49+
- *tx_from
50+
- *tx_to
51+
- *trace_address
52+
- *evt_index
53+
- &method
54+
name: method
55+
description: "Method"
56+
57+
- name: paraswap_gnosis_trades
58+
meta:
59+
blockchain: gnosis
60+
sector: dex
61+
project: paraswap
62+
contributors: springzh
63+
config:
64+
tags: ['gnosis','dex','trades', 'paraswap']
65+
description: >
66+
paraswap aggregator trades on gnosis across all contracts and versions. This table will load dex trades downstream.
67+
columns:
68+
- *blockchain
69+
- *project
70+
- *version
71+
- *block_date
72+
- *block_time
73+
- *token_bought_symbol
74+
- *token_sold_symbol
75+
- *token_pair
76+
- *token_bought_amount
77+
- *token_sold_amount
78+
- *token_bought_amount_raw
79+
- *token_sold_amount_raw
80+
- *amount_usd
81+
- *token_bought_address
82+
- *token_sold_address
83+
- *taker
84+
- *maker
85+
- *project_contract_address
86+
- *tx_hash
87+
- *tx_from
88+
- *tx_to
89+
- *trace_address
90+
- *evt_index
91+
92+
- name: paraswap_v6_gnosis_trades_decoded
93+
description: "Paraswap V6 trades decoded"
94+
data_tests:
95+
- dbt_utils.unique_combination_of_columns:
96+
combination_of_columns:
97+
- call_tx_hash
98+
- method
99+
- call_trace_address
100+
columns:
101+
- *blockchain
102+
- *project
103+
- *version
104+
- *block_date
105+
- *method
106+
- &blockTime
107+
name: blockTime
108+
description: "Block time"
109+
- name: blockNumber
110+
description: "Block number"
111+
- &call_tx_hash
112+
name: call_tx_hash
113+
description: "Transaction hash"
114+
- name: projectContractAddress
115+
description: "Project contract address"
116+
- &call_trace_address
117+
name: call_trace_address
118+
description: "Call trace address"
119+
- name: srcToken
120+
description: "Source token"
121+
- name: destToken
122+
description: "Destination token"
123+
- name: fromAmount
124+
description: "From amount"
125+
- name: spentAmount
126+
description: "Spent amount"
127+
- name: toAmount
128+
description: "To amount"
129+
- name: quotedAmount
130+
description: "Quoted amount"
131+
- name: receivedAmount
132+
description: "Received amount"
133+
- name: metadata
134+
description: "Metadata"
135+
- name: beneficiary
136+
description: "Beneficiary"
137+
- name: side
138+
description: "Side"
139+
- name: feeCode
140+
description: "Fee code"
141+
- name: partnerShare
142+
description: "Partner share"
143+
- name: paraswapShare
144+
description: "Paraswap share"
145+
- name: partnerAddress
146+
description: "Partner address"
147+
- name: feeBps
148+
description: "Fee in basis points"
149+
- name: isReferral
150+
description: "Is referral"
151+
- name: isTakeSurplus
152+
description: "Is take surplus"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{{ config(
2+
schema='paraswap_gnosis',
3+
alias = 'trades',
4+
5+
)
6+
}}
7+
8+
{% set paraswap_models = [
9+
ref('paraswap_v5_gnosis_trades')
10+
,ref('paraswap_v6_gnosis_trades')
11+
] %}
12+
13+
14+
SELECT *
15+
FROM (
16+
{% for dex_model in paraswap_models %}
17+
SELECT
18+
blockchain,
19+
project,
20+
version,
21+
block_month,
22+
block_date,
23+
block_time,
24+
token_bought_symbol,
25+
token_sold_symbol,
26+
token_pair,
27+
token_bought_amount,
28+
token_sold_amount,
29+
token_bought_amount_raw,
30+
token_sold_amount_raw,
31+
amount_usd,
32+
token_bought_address,
33+
token_sold_address,
34+
taker,
35+
maker,
36+
project_contract_address,
37+
tx_hash,
38+
tx_from,
39+
tx_to,
40+
trace_address,
41+
evt_index
42+
FROM {{ dex_model }}
43+
{% if not loop.last %}
44+
UNION ALL
45+
{% endif %}
46+
{% endfor %}
47+
)
48+
;
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{{ config(
2+
schema = 'paraswap_v6_gnosis',
3+
alias = 'trades',
4+
5+
partition_by = ['block_month'],
6+
materialized = 'incremental',
7+
file_format = 'delta',
8+
incremental_strategy = 'merge',
9+
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
10+
unique_key = ['block_date', 'blockchain', 'project', 'version', 'tx_hash', 'method', 'trace_address'],
11+
post_hook='{{ expose_spells(\'["gnosis"]\',
12+
"project",
13+
"paraswap_v6",
14+
\'["eptighte"]\') }}'
15+
)
16+
}}
17+
18+
{% set project_start_date = '2024-03-01' %}
19+
20+
with dexs AS (
21+
SELECT
22+
blockTime AS block_time,
23+
blockNumber AS block_number,
24+
from_hex(beneficiary) AS taker,
25+
null AS maker, -- TODO: can parse from traces
26+
receivedAmount AS token_bought_amount_raw,
27+
fromAmount AS token_sold_amount_raw,
28+
CAST(NULL AS double) AS amount_usd,
29+
method,
30+
CASE
31+
WHEN from_hex(destToken) = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
32+
THEN 0x4200000000000000000000000000000000000006 -- WETH
33+
ELSE from_hex(destToken)
34+
END AS token_bought_address,
35+
CASE
36+
WHEN from_hex(srcToken) = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
37+
THEN 0x4200000000000000000000000000000000000006 -- WETH
38+
ELSE from_hex(srcToken)
39+
END AS token_sold_address,
40+
projectContractAddress as project_contract_address,
41+
call_tx_hash as tx_hash,
42+
call_trace_address AS trace_address,
43+
CAST(-1 as integer) AS evt_index
44+
FROM {{ ref('paraswap_v6_gnosis_trades_decoded') }}
45+
{% if is_incremental() %}
46+
WHERE {{ incremental_predicate('blockTime') }}
47+
{% endif %}
48+
)
49+
50+
SELECT 'gnosis' AS blockchain,
51+
'paraswap' AS project,
52+
'6' AS version,
53+
cast(date_trunc('day', d.block_time) as date) as block_date,
54+
cast(date_trunc('month', d.block_time) as date) as block_month,
55+
d.block_time,
56+
method,
57+
e1.symbol AS token_bought_symbol,
58+
e2.symbol AS token_sold_symbol,
59+
CASE
60+
WHEN lower(e1.symbol) > lower(e2.symbol) THEN concat(e2.symbol, '-', e1.symbol)
61+
ELSE concat(e1.symbol, '-', e2.symbol)
62+
END AS token_pair,
63+
d.token_bought_amount_raw / power(10, e1.decimals) AS token_bought_amount,
64+
d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount,
65+
d.token_bought_amount_raw,
66+
d.token_sold_amount_raw,
67+
coalesce(
68+
d.amount_usd
69+
,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price
70+
,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price
71+
) AS amount_usd,
72+
d.token_bought_address,
73+
d.token_sold_address,
74+
coalesce(d.taker, tx."from") AS taker,
75+
coalesce(d.maker, tx."from") as maker,
76+
d.project_contract_address,
77+
d.tx_hash,
78+
tx."from" AS tx_from,
79+
tx.to AS tx_to,
80+
d.trace_address,
81+
d.evt_index
82+
FROM dexs d
83+
INNER JOIN {{ source('gnosis', 'transactions') }} tx ON d.tx_hash = tx.hash
84+
AND d.block_number = tx.block_number
85+
{% if not is_incremental() %}
86+
AND tx.block_time >= TIMESTAMP '{{project_start_date}}'
87+
{% endif %}
88+
{% if is_incremental() %}
89+
AND {{ incremental_predicate('tx.block_time') }}
90+
{% endif %}
91+
LEFT JOIN {{ source('tokens', 'erc20') }} e1 ON e1.contract_address = d.token_bought_address
92+
AND e1.blockchain = 'gnosis'
93+
LEFT JOIN {{ source('tokens', 'erc20') }} e2 on e2.contract_address = d.token_sold_address
94+
AND e2.blockchain = 'gnosis'
95+
LEFT JOIN {{ source('prices', 'usd') }} p1 ON p1.minute = date_trunc('minute', d.block_time)
96+
AND p1.contract_address = d.token_bought_address
97+
AND p1.blockchain = 'gnosis'
98+
{% if not is_incremental() %}
99+
AND p1.minute >= TIMESTAMP '{{project_start_date}}'
100+
{% endif %}
101+
{% if is_incremental() %}
102+
AND {{ incremental_predicate('p1.minute') }}
103+
{% endif %}
104+
LEFT JOIN {{ source('prices', 'usd') }} p2 ON p2.minute = date_trunc('minute', d.block_time)
105+
AND p2.contract_address = d.token_sold_address
106+
AND p2.blockchain = 'gnosis'
107+
{% if not is_incremental() %}
108+
AND p2.minute >= TIMESTAMP '{{project_start_date}}'
109+
{% endif %}
110+
{% if is_incremental() %}
111+
AND {{ incremental_predicate('p2.minute') }}
112+
{% endif %}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{ config(
2+
schema = 'paraswap_v6_gnosis',
3+
alias = 'trades_decoded',
4+
partition_by = ['block_month'],
5+
materialized = 'incremental',
6+
file_format = 'delta',
7+
incremental_strategy = 'merge',
8+
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.blockTime')],
9+
unique_key = ['call_tx_hash', 'method', 'call_trace_address'],
10+
post_hook='{{ expose_spells(blockchains = \'["gnosis"]\',
11+
spell_type = "project",
12+
spell_name = "paraswap_v6",
13+
contributors = \'["eptighte"]\') }}'
14+
)
15+
}}
16+
17+
{{ paraswap_v6_trades_master('gnosis', 'paraswap') }}

0 commit comments

Comments
 (0)