Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
6def7d7
feat: draft: start adjusting delta v2 master template for dex integra…
alexshchur May 2, 2025
cf91b64
feat: draft: add couple timestamp columns
alexshchur May 2, 2025
6587c0e
feat: delta v2 - more columns to conform DEX trades shape
alexshchur May 5, 2025
c14db1d
feat: delta: add token_bought_amount, token_sold_amount
alexshchur May 5, 2025
9956fa4
feat: delta: more columns: token_bought_amount_raw, token_sold_amount…
alexshchur May 5, 2025
bcffd79
feat: delta: add more columns: taker, maker, project_contract_address…
alexshchur May 5, 2025
cf67b16
fix: delta unique key
alexshchur May 5, 2025
bd3eb81
fix: Column type is unknown: evt_index
alexshchur May 5, 2025
409457f
fix: add evt_index to `paraswap_delta_v2_ethereum_trades`
alexshchur May 5, 2025
155c48d
fix: tmp: explicitly cast NULL to define evt_index column type
alexshchur May 5, 2025
453ba07
fix: prop drill evt_index instead of override
alexshchur May 5, 2025
f1674c1
fix: Column 'method' cannot be resolved
alexshchur May 5, 2025
6807e8c
fix: attempt: "Column 'call_tx_hash' cannot be resolved" and more fil…
alexshchur May 5, 2025
ecdf294
fix: "Column 'call_tx_hash' cannot be resolved" and more fileds alike…
alexshchur May 5, 2025
fa62d57
fix: fix: "Column 'call_tx_hash' cannot be resolved" / now on Base an…
alexshchur May 5, 2025
de596c1
fix: delta v2: base schema (Column 'call_tx_hash' cannot be resolved)
alexshchur May 5, 2025
eba8231
Merge branch 'main' into feat/velora-delta-dex
alexshchur May 5, 2025
0779aa3
feat: delta v2: connect to ethereum paraswap's dex trades
alexshchur May 5, 2025
701747d
Merge branch 'feat/velora-delta-dex' of https://github.com/paraswap/s…
alexshchur May 5, 2025
0dbb48c
fix: Column 'token_bought_symbol' cannot be resolved, by adding toke…
alexshchur May 5, 2025
662fa5f
feat: add delta v2 to Base
alexshchur May 5, 2025
394fe84
undraft: remove dev code and better formatting
alexshchur May 5, 2025
2bc62c0
chore: cleanup
alexshchur May 5, 2025
a38d2a8
feat: delta v2 on optimism
alexshchur May 6, 2025
e059469
fix: add optimism "to_wrapped_native_token" macro
alexshchur May 6, 2025
10ae670
chore; extract `map_internal_to_dex` for reusing for Delta v1
alexshchur May 6, 2025
40d4bb3
chore: move delta_v1_settleSwap into method-specific macro to uniform…
alexshchur May 6, 2025
45e09dd
chore: now move delta_v1_safeSettleBatch into method-specific macro t…
alexshchur May 6, 2025
3108012
chore: cleanup delta v2 master macro
alexshchur May 6, 2025
2b373a2
feat: confirm delta v1 to dex models structure and connect it to para…
alexshchur May 6, 2025
c8d6cfa
Merge branch 'main' into feat/velora-delta-optimism
alexshchur May 6, 2025
bff64cb
fix: delta v1: unique key schema and config
alexshchur May 6, 2025
d0fac47
Merge branch 'main' into feat/velora-delta-optimism
alexshchur May 7, 2025
a77cd6d
Merge branch 'main' of https://github.com/duneanalytics/spellbook int…
alexshchur May 7, 2025
a76647a
Merge branch 'feat/velora-delta-optimism' of https://github.com/paras…
alexshchur May 7, 2025
af99c6d
Merge branch 'feat/velora-delta-optimism' of https://github.com/paras…
alexshchur May 7, 2025
7e97e69
feat: delta v2: add partner address
alexshchur May 7, 2025
29d6fb0
feat: computed_order_hash to more reliably join calls and events. Onl…
alexshchur May 9, 2025
2b1c1fa
chore: make v1 delta folder strucutre consistent with v2
alexshchur May 9, 2025
7a9abcd
fix: add dummy fields to delta v1 methods to conform to v2
alexshchur May 9, 2025
0ce3dbd
chore: swap_settle_batch simplify
alexshchur May 11, 2025
a607413
Merge branch 'main' into feat/more-data-for-delta-v2
alexshchur May 11, 2025
fca3400
draft: join events to swapSetlle too, display evt_order_hash. Todo - …
alexshchur May 12, 2025
512da7d
draft: add evt_order_hash
alexshchur May 12, 2025
58fc2be
fix: introduce compute_order_hash_with_bridge macro and properly enco…
alexshchur May 12, 2025
99a2081
Merge branch 'feat/more-data-for-delta-v2' of https://github.com/para…
alexshchur May 12, 2025
93bb2fe
fix: dynamic permit
alexshchur May 12, 2025
fab441f
fix: dynamically compute order hash with bridge
alexshchur May 12, 2025
60d5be9
fix: swapSettle - conditionally copmute order hash w. bridge / no bridge
alexshchur May 12, 2025
bd19ed5
undraft
alexshchur May 12, 2025
4430427
fix: swapSettleBatch: conditional orderHash computation w. bridge / n…
alexshchur May 12, 2025
41b1e2d
feat: delta v2: gas with fallback (actually paid native token price)
alexshchur May 16, 2025
4eee131
CUR2-66 init hide spell macro to remove from data explorer, hide bala…
jeff-dude Jul 31, 2025
2b2292d
Merge branch 'main' of https://github.com/duneanalytics/spellbook int…
alexshchur Aug 3, 2025
c2d1b41
fix: map_internal_to_dex macro (rely on from alias)
alexshchur Aug 3, 2025
505669a
fix: grab txs data from sources, not directly
alexshchur Aug 3, 2025
b5d1fa3
fix: delta v1 model evt_order_hash cannot be resolved
alexshchur Aug 3, 2025
3b37ecb
fix: restirct delta-v2-specific columns in the template
alexshchur Aug 3, 2025
5226357
fix: slit delta v1 and v2 belongings
alexshchur Aug 3, 2025
9cdb83b
fix: wrapped native token
alexshchur Aug 3, 2025
f13b482
fix: return base trades v6 augustus
alexshchur Aug 3, 2025
611cdbc
delta v2: gas_fee_usd annotations fix
alexshchur Aug 4, 2025
f06dde2
fix: add returnAmount, protocolFee and partnerFee to the delta v2 model
alexshchur Aug 4, 2025
446746d
fix: syntax / redundant comma
alexshchur Aug 4, 2025
7c07735
fix: some columns names
alexshchur Aug 4, 2025
fc9a501
fix: delta v2 dates
alexshchur Aug 4, 2025
28077af
fix: ordersCount for delta v2 batched
alexshchur Aug 4, 2025
09d5961
revert back model that was considered troublesom
alexshchur Aug 4, 2025
79aa89a
fix: delta v2: when relying on native token spent as gas fee for batc…
alexshchur Aug 4, 2025
9aa15f9
fix: Column 'orderscount' cannot be resolved
alexshchur Aug 4, 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
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{%- macro trino_properties(properties) -%}
map_from_entries(ARRAY[
{%- for key, value in properties.items() %}
ROW('{{ key }}', '{{ value }}')
{%- if not loop.last -%},{%- endif -%}
{%- endfor %}
])
{%- endmacro -%}

{% macro expose_spells(blockchains, spell_type, spell_name, contributors) %}
{%- set validated_contributors = tojson(fromjson(contributors | as_text)) -%}
{%- if ("%s" % validated_contributors) == "null" -%}
Expand All @@ -24,11 +33,20 @@
{%- endif -%}
{%- endmacro -%}

{%- macro trino_properties(properties) -%}
map_from_entries(ARRAY[
{%- for key, value in properties.items() %}
ROW('{{ key }}', '{{ value }}')
{%- if not loop.last -%},{%- endif -%}
{%- endfor %}
])
{%- endmacro -%}
{% macro hide_spells() %}
{%- if target.name == 'prod' -%}
{%- set properties = {
'dune.public': 'false',
'dune.data_explorer.category': 'abstraction',
'dune.vacuum': '{"enabled":true}'
} -%}
{%- if model.config.materialized == "view" -%}
CALL {{ model.database }}._internal.alter_view_properties('{{ model.schema }}', '{{ model.alias }}',
{{ trino_properties(properties) }}
)
{%- else -%}
ALTER TABLE {{ this }}
SET PROPERTIES extra_properties = {{ trino_properties(properties) }}
{%- endif -%}
{%- endif -%}
{%- endmacro -%}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,42 @@ select
COALESCE(evt_index, 0) as evt_index, -- TMP: after joining envents in swapSettle can remove it
order_index,
method
{% if version == 'v2' %}
,from_hex(regexp_replace(
try_cast(
TRY_CAST(
BITWISE_RIGHT_SHIFT(partnerAndFee, 96) AS VARBINARY
) as VARCHAR
),
'0x(00){12}'
)) AS partnerAddress
,computed_order_hash
,evt_order_hash
,bridgeMultiCallHandler
,bridgeOutputToken
,bridgeMaxRelayerFee
,bridgeDestinationChainId
,bridge
,"order"
,"owner"
,ordersCount
,call_block_number as block_number
,raw_tx_gas_used
,raw_tx_gas_price
,{{from_alias}}.gas_fee_usd
,wnt_price_usd
,executor
,evt_return_amount -- uint256
,evt_protocol_fee -- uint256
,evt_partner_fee -- uint256
{% endif %}
from {{from_alias}}
LEFT JOIN
{{ source('tokens', 'erc20') }} t_src_token
ON t_src_token.blockchain = '{{blockchain}}'
AND t_src_token.contract_address = src_token
AND t_src_token.contract_address = src_token_for_joining
LEFT JOIN
{{ source('tokens', 'erc20') }} t_dest_token
ON t_dest_token.blockchain = '{{blockchain}}'
AND t_dest_token.contract_address = dest_token
AND t_dest_token.contract_address = dest_token_for_joining
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{% macro compute_order_hash(blockchain) %}

{% set network_to_chain_id = {
'ethereum': 1,
'optimism': 10,
'base': 8453,
} %}

-- SELECT
keccak(
concat(
X'1901',

-- domain separator
keccak(
concat(
keccak(to_utf8('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)')),
keccak(to_utf8('Portikus')),
keccak(to_utf8('2.0.0')),
lpad(cast(cast({{ network_to_chain_id[blockchain]}} AS uint256) AS varbinary), 32, X'00'),
lpad(from_hex('0000000000bbf5c5fd284e657f01bd000933c96d'), 32, X'00')
)
),

-- struct hash
keccak(
concat(
keccak(to_utf8('Order(address owner,address beneficiary,address srcToken,address destToken,uint256 srcAmount,uint256 destAmount,uint256 expectedDestAmount,uint256 deadline,uint256 nonce,uint256 partnerAndFee,bytes permit)')),
-- lpad(from_hex('12924049e2d21664e35387c69429c98e9891a820'), 32, X'00'), -- owner
lpad(owner, 32, X'00'),
-- lpad(from_hex('12924049e2d21664e35387c69429c98e9891a820'), 32, X'00'), -- beneficiary
lpad(beneficiary, 32, X'00'), -- beneficiary
-- lpad(from_hex('04c154b66cb340f3ae24111cc767e0184ed00cc6'), 32, X'00'), -- srcToken
lpad(srcToken, 32, X'00'), -- srcToken
-- lpad(from_hex('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), 32, X'00'), -- destToken
lpad(destToken, 32, X'00'), -- destToken
-- lpad(cast(cast('1202939820354578' AS uint256) AS varbinary), 32, X'00'), -- srcAmount
lpad(cast(srcAmount AS varbinary), 32, X'00'), -- srcAmount
-- lpad(cast(cast('868930905657826' AS uint256) AS varbinary), 32, X'00'), -- destAmount
lpad(cast(destAmount AS varbinary), 32, X'00'), -- destAmount
-- lpad(cast(cast('873297392620931' AS uint256) AS varbinary), 32, X'00'), -- expectedDestAmount
lpad(cast(expectedDestAmount AS varbinary), 32, X'00'), -- expectedDestAmount
-- lpad(cast(cast('1740790593' AS uint256) AS varbinary), 32, X'00'), -- deadline
lpad(cast(deadline AS varbinary), 32, X'00'), -- deadline
-- lpad(cast(cast('1740787014424' AS uint256) AS varbinary), 32, X'00'), -- nonce
lpad(cast(nonce AS varbinary), 32, X'00'), -- nonce
-- lpad(cast(cast('90631063861114836560958097440945986548822432573276877133894239693005947666432' AS uint256) AS varbinary), 32, X'00'), -- partnerAndFee
lpad(cast(partnerAndFee AS varbinary), 32, X'00'), -- partnerAndFee
-- permit:
-- lpad(
-- keccak(from_hex(
-- '00000000000000000000000012924049e2d21664e35387c69429c98e9891a8200000000000000000000000000000000000bbf5c5fd284e657f01bd000933c96d0000000000000000000000000000000000000000000000000004461140adac120000000000000000000000000000000000000000000000000000000067c641b2000000000000000000000000000000000000000000000000000000000000001bae25978476dcaf13eb21c5140c058bc49fd4d087f0f0d23b1ccede8f9288bb33450886d34539305ede3448c44206e89074d91afcdc8e07cabbe23cf45c67dd7c'
-- )),
-- 32, X'00'
-- )
lpad(
keccak(permit),
32, X'00'
)
)
)
)
)
-- ) AS eip712_final_hash


{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{% macro compute_order_hash_with_bridge(blockchain) %}

{% set network_to_chain_id = {
'ethereum': 1,
'optimism': 10,
'base': 8453,
} %}

-- SELECT
keccak(
concat(
X'1901',

-- domain separator
keccak(
concat(
keccak(to_utf8('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)')),
keccak(to_utf8('Portikus')),
keccak(to_utf8('2.0.0')),
lpad(cast(cast({{ network_to_chain_id[blockchain]}} AS uint256) AS varbinary), 32, X'00'),
lpad(from_hex('0000000000bbf5c5fd284e657f01bd000933c96d'), 32, X'00')
)
),

-- Order struct hash
keccak(
concat(
keccak(to_utf8(
'Order(address owner,address beneficiary,address srcToken,address destToken,uint256 srcAmount,uint256 destAmount,uint256 expectedDestAmount,uint256 deadline,uint256 nonce,uint256 partnerAndFee,bytes permit,Bridge bridge)Bridge(uint256 maxRelayerFee,uint256 destinationChainId,address outputToken,address multiCallHandler)'
)),

-- lpad(from_hex('6d383975c64eebe1251e50c3ab0e53537342bde9'), 32, X'00'), -- owner
lpad(owner, 32, X'00'),
-- lpad(from_hex('6d383975c64eebe1251e50c3ab0e53537342bde9'), 32, X'00'), -- beneficiary
lpad(beneficiary, 32, X'00'), -- beneficiary
-- lpad(from_hex('f469fbd2abcd6b9de8e169d128226c0fc90a012e'), 32, X'00'), -- srcToken
lpad(srcToken, 32, X'00'), -- srcToken
-- lpad(from_hex('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), 32, X'00'), -- destToken
lpad(destToken, 32, X'00'), -- destToken
-- lpad(cast(cast('422561' as uint256) AS varbinary), 32, X'00'),
lpad(cast(srcAmount AS varbinary), 32, X'00'), -- srcAmount
-- lpad(cast(cast('168106215780811752' as uint256) AS varbinary), 32, X'00'),
lpad(cast(destAmount AS varbinary), 32, X'00'), -- destAmount
-- lpad(cast(cast('168950970633981661' as uint256) AS varbinary), 32, X'00'),
lpad(cast(expectedDestAmount AS varbinary), 32, X'00'), -- expectedDestAmount
-- lpad(cast(cast('1747024424' as uint256) AS varbinary), 32, X'00'),
lpad(cast(deadline AS varbinary), 32, X'00'), -- deadline
-- lpad(cast(cast('1747020844040' as uint256) AS varbinary), 32, X'00'),
lpad(cast(nonce AS varbinary), 32, X'00'), -- nonce
-- lpad(cast(cast('90631063861114836560958097440945986548822432573276877133894239693005947666447' as uint256) AS varbinary), 32, X'00'),
lpad(cast(partnerAndFee AS varbinary), 32, X'00'), -- partnerAndFee

-- Permit (empty: 0x, not 0x00)
-- lpad(keccak(from_hex('')), 32, X'00'),
lpad(
keccak(permit),
32, X'00'
),
-- Bridge struct hash (inlined)
keccak(
concat(
keccak(to_utf8('Bridge(uint256 maxRelayerFee,uint256 destinationChainId,address outputToken,address multiCallHandler)')),
lpad(cast(cast(bridgeMaxRelayerFee as uint256) AS varbinary), 32, X'00'),
lpad(cast(cast(bridgeDestinationChainId as uint256) AS varbinary), 32, X'00'),
lpad(bridgeOutputToken, 32, X'00'),
lpad(bridgeMultiCallHandler, 32, X'00')
)
)
)
)
)
)
-- ) AS eip712_body_hash;


{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
-- }
CASE
WHEN executor = 0x6bb000067005450704003100632eb93ea00c0000 THEN varbinary_to_uint256(varbinary_substring(executorData, 161, 32))
-- WHEN executor = 0x0500b5050c40e06ed700005dd7cb0ef0b0d0a000 THEN "TODO: join augustus executor contract call and return the output"
-- WHEN executor = 0x10100dcac00088044067a00d520a0f7900000770 THEN "TODO: join augustus executor contract call and return the output"
-- 0x0500b5050c40e06ed700005dd7cb0ef0b0d0a000 - staging one
ELSE 0
END as "executorFeeAmount"
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{% macro gas_fee_usd() %}
COALESCE(
d.price * w.executorFeeAmount / POWER(10, d.decimals), -- compute directly (dest token is gas fee compensation if it's augustus axecutor)
s.price * w.srcAmount / POWER(10, s.decimals) * CAST (w.executorFeeAmount AS DECIMAL) / (CAST (w.destAmount AS DECIMAL)), -- compute pro-rata based on src token if it's augustus executor
-- TODO: also add 3rd party executor fee compensation -- based on spent native token, divided by amount of orders if multiple
0
) AS gas_fee_usd
case
WHEN w.executorFeeAmount > 0
then
COALESCE(
d.price * w.executorFeeAmount / POWER(10, d.decimals), -- compute directly (dest token is gas fee compensation if it's augustus axecutor)
s.price * w.srcAmount / POWER(10, s.decimals) * CAST (w.executorFeeAmount AS DECIMAL) / (CAST (w.destAmount AS DECIMAL)) -- compute pro-rata based on src token if it's augustus executor
)
else
-- if can't parse executorFeeAmount - fall back to spent native token, divided by amount of orders if multiple
wnt_usd.price * raw_tx_gas_used * raw_tx_gas_price / POWER(10, wnt_usd.decimals) / ordersCount
END AS gas_fee_usd
{% endmacro %}
Loading
Loading