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

multichain automated dex trades #7503

Draft
wants to merge 63 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
0165bcc
change back to a manual mapping
0xBoxer Nov 25, 2024
2daae41
adjust stuff
0xBoxer Nov 25, 2024
bfc14cb
add files for base blockchain
0xBoxer Nov 25, 2024
582f038
fix macro error
0xBoxer Nov 25, 2024
5349a00
fix factory address in macro
0xBoxer Nov 25, 2024
afe7cfa
trigger rerun of pipeline with prices
0xBoxer Nov 25, 2024
d902e6b
adding existing not identified dexes
0xBoxer Nov 26, 2024
c9fd803
ssss
0xBoxer Nov 26, 2024
37d5d3b
sss
0xBoxer Nov 26, 2024
3dd0f6d
Merge branch 'main' of https://github.com/duneanalytics/spellbook int…
0xBoxer Jan 2, 2025
aa68567
adjust approach to cron setup
0xBoxer Jan 2, 2025
f370cc4
ggwp
0xBoxer Jan 2, 2025
814e5de
Merge branch 'main' of https://github.com/duneanalytics/spellbook int…
0xBoxer Jan 20, 2025
710534f
init
0xBoxer Jan 20, 2025
fb4c136
working version of mass decoding
0xBoxer Jan 20, 2025
8a223d6
progress to all models
0xBoxer Jan 20, 2025
975a73e
limit date range via macro
0xBoxer Jan 20, 2025
1a956b5
go to one chain
0xBoxer Jan 21, 2025
55e2697
change join condition
0xBoxer Jan 21, 2025
c23e245
fix query
0xBoxer Jan 21, 2025
818765e
temp fix add_tx_info
0xBoxer Jan 21, 2025
9188b6f
remove transfers filters and date filters
0xBoxer Jan 22, 2025
f7eb3d9
remove topic0 filter
0xBoxer Jan 22, 2025
67417bf
full send
0xBoxer Jan 22, 2025
51554d6
stage tx_to and tx_from without joins
0xBoxer Jan 22, 2025
b85ecd8
smol send
0xBoxer Jan 22, 2025
d8999a0
fix dup tx index
0xBoxer Jan 22, 2025
dc58dd1
send it
0xBoxer Jan 22, 2025
63dced5
change partition keys and columns
0xBoxer Jan 22, 2025
f034eb4
change more part keys
0xBoxer Jan 22, 2025
06c2281
change to one blockchain directory
0xBoxer Jan 22, 2025
f402ac8
ALL THE CHAINS
0xBoxer Jan 22, 2025
7699401
ok some of the chains
0xBoxer Jan 22, 2025
5fda8b5
less blockchains more days
0xBoxer Jan 23, 2025
522e6bd
rerun
0xBoxer Jan 23, 2025
744cc2a
split into 2 chain lists
0xBoxer Jan 27, 2025
579cec4
remove redundant model
0xBoxer Jan 27, 2025
bf5ff0a
send it
0xBoxer Jan 27, 2025
8a44f89
fix model names and stuff
0xBoxer Jan 27, 2025
655740a
run all the chains
0xBoxer Jan 28, 2025
bc6cf85
remove chains that don't have sources yet
0xBoxer Jan 28, 2025
8613232
change folder struc
0xBoxer Jan 28, 2025
e7b5eb6
move mapping down in lineage
0xBoxer Jan 28, 2025
3032bad
fix lineage and remove date filters
0xBoxer Jan 28, 2025
40e7615
fix syntax
0xBoxer Jan 28, 2025
f0fe2c4
add dex mappings
0xBoxer Jan 29, 2025
a406a68
add incremental conditions
0xBoxer Jan 29, 2025
5e96f04
limit date range via incremental filters
0xBoxer Jan 29, 2025
577545b
fix filter
0xBoxer Jan 29, 2025
b6bd48f
really fix filter
0xBoxer Jan 29, 2025
d4e2fe9
fix fix
0xBoxer Jan 29, 2025
dae59bd
god one more
0xBoxer Jan 29, 2025
5a2aa7a
more fixes
0xBoxer Jan 29, 2025
85a58fe
fix tests and files
0xBoxer Jan 29, 2025
677a2aa
fix unique keys for merging
0xBoxer Jan 29, 2025
1da058d
take out date filter
0xBoxer Jan 30, 2025
3faad46
fix tests
0xBoxer Jan 30, 2025
677a497
fix creation traces join
0xBoxer Jan 30, 2025
c8d374a
also fix v3 macro
0xBoxer Jan 30, 2025
88ca20c
temp disable optimisim
0xBoxer Jan 31, 2025
d1d3e4c
rerun
0xBoxer Jan 31, 2025
54401a6
fix merge condition
0xBoxer Jan 31, 2025
8e20219
add filter for valid factories
0xBoxer Jan 31, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/dbt_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
dbt-test:
runs-on: [ self-hosted, linux, spellbook-trino-ci ]
timeout-minutes: 90
timeout-minutes: 300

steps:
- name: Check out repository code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@ FROM TABLE (
decode_evm_event (
abi => '{{abi}}',
input => TABLE (
SELECT l.*
SELECT block_number,
block_time,
block_date,
date_trunc('month', block_date) as block_month,
block_hash,
contract_address,
topic0,
topic1,
topic2,
topic3,
data,
tx_hash,
index as evt_index,
tx_index,
tx_from,
tx_to
FROM {{logs}} l
WHERE topic0 = {{topic0}}
{% if is_incremental() %}
AND {{ incremental_predicate('block_time') }}
{% else %}
AND block_date >= (SELECT MIN(block_date) FROM {{logs}} WHERE topic0 = {{topic0}})
{% endif %}
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% macro uniswap_old_blockchains_list() %}
{{ return([
"arbitrum"
, "avalanche_c"
, "base"
, "bnb"
, "ethereum"
, "gnosis"
, "polygon"
]) }}
{% endmacro %}


{% macro uniswap_new_blockchains_list() %}
{{ return([
"blast"
, "bob"
, "celo"
, "degen"
, "fantom"
, "kaia"
, "linea"
, "mantle"
, "mode"
, "nova"
, "ronin"
, "scroll"
, "sei"
, "worldchain"
, "zkevm"
, "zksync"
, "zora"
]) }}
{% endmacro %}


-- "optimism" has some problems with traces, need to fix later
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
{% set topic0 = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' %}

{{ evm_event_decoding_base(logs, abi, topic0) }}
{% if is_incremental() %}
WHERE {{ incremental_predicate('block_time') }}
{% endif %}

{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
{% set topic0 = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' %}

{{ evm_event_decoding_base(logs, abi, topic0) }}

{% if is_incremental() %}
WHERE {{ incremental_predicate('block_time') }}
{% endif %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{% macro uniswap_v2_forks_trades(
blockchain = null
, dex_type = 'uni-v2'
, project = null
dex_type = 'uni-v2'
, version = null
, Pair_evt_Swap = null
, Factory_evt_PairCreated = null
, pair_column_name = 'pair'
)
%}

WITH evt_swap AS (
SELECT
block_number
blockchain
, block_number
, block_time
, to
, contract_address
, tx_hash
, index
, evt_index
, amount0In
, amount0Out
, amount1In
, amount1Out
, tx_from
, tx_to
, tx_index
FROM {{ Pair_evt_Swap }}
{% if is_incremental() %}
WHERE {{ incremental_predicate('block_time') }}
Expand All @@ -30,7 +31,8 @@ WITH evt_swap AS (
, dexs AS
(
SELECT
t.block_number
t.blockchain
, t.block_number
, t.block_time
, t.to AS taker
, t.contract_address AS maker
Expand All @@ -40,85 +42,51 @@ WITH evt_swap AS (
, CASE WHEN amount0In = UINT256 '0' OR amount1Out = UINT256 '0' THEN f.token1 ELSE f.token0 END AS token_sold_address
, t.contract_address AS project_contract_address
, t.tx_hash
, t.index AS evt_index
, t.evt_index
, f.contract_address as factory_address
, t.tx_from
, t.tx_to
, t.tx_index
FROM
evt_swap t
INNER JOIN
{{ Factory_evt_PairCreated }} f
ON f.{{ pair_column_name }} = t.contract_address
INNER JOIN {{ source(blockchain, 'creation_traces') }} ct
ON f.{{ pair_column_name }} = ct.address
ON f.pair = t.contract_address
AND f.blockchain = t.blockchain
INNER JOIN (
SELECT address, "from", blockchain, MAX(block_number) as latest_block
FROM {{ source('evms', 'creation_traces') }}
GROUP BY address, "from", blockchain
) ct
ON f.pair = ct.address
AND f.contract_address = ct."from"
AND ct.blockchain = t.blockchain
)

, base_trades AS (
SELECT
'{{ blockchain }}' AS blockchain
, '{{project}}' AS project
, '{{ version }}' AS version
, '{{dex_type}}' AS dex_type
, CAST(date_trunc('month', dexs.block_time) AS date) AS block_month
, CAST(date_trunc('day', dexs.block_time) AS date) AS block_date
, dexs.block_time
, dexs.block_number
, dexs.token_bought_amount_raw
, dexs.token_sold_amount_raw
, dexs.token_bought_address
, dexs.token_sold_address
, dexs.taker
, dexs.maker
, dexs.project_contract_address
, dexs.tx_hash
, dexs.evt_index
, dexs.factory_address
FROM
dexs
)

SELECT base_trades.blockchain
, COALESCE(contracts.namespace, base_trades.project) AS project
, base_trades.version
, base_trades.dex_type
, base_trades.factory_address
, base_trades.block_month
, base_trades.block_date
, base_trades.block_time
, base_trades.block_number
, base_trades.token_bought_amount_raw
, base_trades.token_sold_amount_raw
, base_trades.token_bought_address
, base_trades.token_sold_address
, base_trades.taker
, base_trades.maker
, base_trades.project_contract_address
, base_trades.tx_hash
, base_trades.evt_index
FROM base_trades
INNER JOIN (
SELECT
tx_hash,
array_agg(DISTINCT contract_address) as contract_addresses
FROM {{ source('tokens', 'transfers') }}
WHERE blockchain = '{{ blockchain }}'
{% if is_incremental() %}
AND {{ incremental_predicate('block_time') }}
{% endif %}
GROUP BY tx_hash
) AS transfers
ON transfers.tx_hash = base_trades.tx_hash
AND contains(transfers.contract_addresses, base_trades.token_bought_address)
AND contains(transfers.contract_addresses, base_trades.token_sold_address)
LEFT JOIN (
SELECT
address,
blockchain,
namespace
FROM {{ source('evms', 'contracts') }}
WHERE blockchain = '{{ blockchain }}'
AND namespace IS NOT NULL
) AS contracts
ON base_trades.project_contract_address = contracts.address
AND base_trades.blockchain = contracts.blockchain
SELECT
blockchain
, '{{ version }}' AS version
, '{{dex_type}}' AS dex_type
, CAST(date_trunc('month', block_time) AS date) AS block_month
, CAST(date_trunc('day', block_time) AS date) AS block_date
, block_time
, block_number
, token_bought_amount_raw
, token_sold_amount_raw
, token_bought_address
, token_sold_address
, taker
, maker
, project_contract_address
, tx_hash
, evt_index
, factory_address
, tx_from
, tx_to
, tx_index
FROM dexs
{% if is_incremental() %}
WHERE {{ incremental_predicate('block_time') }}
{% endif %}

{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
{% set topic0 = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' %}

{{ evm_event_decoding_base(logs, abi, topic0) }}

{% if is_incremental() %}
WHERE {{ incremental_predicate('block_time') }}
{% endif %}
{% endmacro %}

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
{% set topic0 = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' %}

{{ evm_event_decoding_base(logs, abi, topic0) }}

{% if is_incremental() %}
WHERE {{ incremental_predicate('block_time') }}
{% endif %}
{% endmacro %}

Loading