Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,10 @@
-- evt_index for 1inch LOP fills: numbered over ALL limits fills of a tx, BEFORE any
-- exclusion, so kept rows retain their dex_<blockchain>_trades merge keys when fills
-- are reclassified (merge can only upsert, never delete).
-- Both sides of the dex.trades / dex_aggregator.trades split must agree on this
-- numbering: oneinch_lop_own_trades computes it at query time, while
-- oneinch_lop_venue_settled_fills persists it for oneinch_lop_aggregator_trades.

{% macro oneinch_lop_evt_index() -%}
row_number() over(partition by tx_hash order by call_trace_address)
{%- endmacro %}
114 changes: 113 additions & 1 deletion dbt_subprojects/dex/models/_projects/oneinch/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,12 @@ models:
config:
tags: ['oneinch', 'lo', 'trades']
description: >
1inch limit order protocol trades - special for dex.trades
1inch limit order protocol trades - special for dex.trades.
Fills settled by a resolver on an underlying DEX in the same tx are excluded here
(the venue's own row already represents the trade in dex.trades) and reclassified
into dex_aggregator.trades via oneinch_lop_aggregator_trades. Fills pass through
with a maturity delay so the venue side's decoded events have landed before
dex_<blockchain>_trades merges them.
data_tests:
- dbt_utils.unique_combination_of_columns:
arguments:
Expand All @@ -372,6 +377,9 @@ models:
- tx_hash
- evt_index
- oneinch_no_cross_chain_placeholder_tokens
- check_dex_base_trades_seed:
arguments:
seed_file: ref('oneinch_lop_own_trades_seed')
columns:
- name: blockchain
data_tests:
Expand Down Expand Up @@ -404,6 +412,110 @@ models:
data_tests:
- not_null

- name: oneinch_lop_venue_settled_fills
meta:
blockchain: ['ethereum', 'bnb', 'polygon', 'arbitrum', 'avalanche_c', 'gnosis', 'optimism', 'fantom', 'base', 'zksync', 'linea', 'sonic', 'unichain']
sector: oneinch
contributors: ['thevaizman']
config:
tags: ['oneinch', 'lo']
description: >
1inch limit order protocol fills that a resolver settled on an underlying DEX in
the same tx (the venue's own row co-occurs in dex_<blockchain>_base_trades).
These fills are excluded from oneinch_lop_own_trades (dex.trades) and emitted
into dex_aggregator.trades via oneinch_lop_aggregator_trades. Fills nested under
a classic/fusion/cross-chain execution and direct fills are kept out of this set.
data_tests:
- dbt_utils.unique_combination_of_columns:
arguments:
combination_of_columns:
- blockchain
- block_month
- block_date
- execution_id
columns:
- name: blockchain
data_tests:
- not_null
- name: block_month
data_tests:
- not_null
- name: block_date
data_tests:
- not_null
- name: block_time
- name: tx_hash
data_tests:
- not_null
- name: call_trace_address
data_tests:
- not_null
- name: execution_id
data_tests:
- not_null
- name: evt_index
data_tests:
- not_null

- name: oneinch_lop_aggregator_trades
meta:
blockchain: ['ethereum', 'bnb', 'polygon', 'arbitrum', 'avalanche_c', 'gnosis', 'optimism', 'fantom', 'base', 'zksync', 'linea', 'sonic', 'unichain']
sector: oneinch
contributors: ['thevaizman']
config:
tags: ['oneinch', 'lo', 'trades']
description: >
1inch limit order protocol fills settled on an underlying DEX - special for
dex_aggregator.trades, served as-is like oneinch_ar_trades (the venue's own row
stays in dex.trades; the intent-layer fill is recorded here, user perspective,
carrying 1inch's own amounts and guarded amount_usd - these values are NOT
re-derived by generic erc20-decimals enrichment, which is unsafe for this
lineage's raw amounts; see CUR2-2693 / the #9747 revert)
data_tests:
- dbt_utils.unique_combination_of_columns:
arguments:
combination_of_columns:
- blockchain
- tx_hash
- trace_address
- evt_index
- check_dex_aggregator_seed:
arguments:
blockchain: arbitrum
project: 1inch-LOP
version: '4.0'
columns:
- name: blockchain
data_tests:
- not_null
- name: project
- name: version
- name: block_date
- name: block_month
- name: block_time
- name: token_bought_symbol
- name: token_sold_symbol
- name: token_pair
- name: token_bought_amount
- name: token_sold_amount
- name: token_bought_amount_raw
- name: token_sold_amount_raw
- name: amount_usd
- name: token_bought_address
- name: token_sold_address
- name: taker
- name: maker
- name: project_contract_address
- name: tx_hash
data_tests:
- not_null
- name: tx_from
- name: tx_to
- name: trace_address
data_tests:
- not_null
- name: evt_index

- name: oneinch_intent_resolvers
meta:
blockchain: ['ethereum', 'bnb', 'polygon', 'arbitrum', 'avalanche_c', 'gnosis', 'optimism', 'fantom', 'base', 'zksync', 'linea', 'sonic', 'unichain']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{
config(
schema = 'oneinch',
alias = 'lop_aggregator_trades',
materialized = 'view',
unique_key = ['blockchain', 'block_month', 'tx_hash', 'trace_address', 'evt_index'],
)
}}

{% set src_symbol = "coalesce(src_executed_symbol, '')" %}
{% set dst_symbol = "coalesce(dst_executed_symbol, '')" %}



-- venue-settled LOP fills: the underlying venue's own row stays in dex.trades, so the
-- intent-layer fill is recorded here instead (user perspective, like oneinch_ar_trades).
-- evt_index comes persisted from oneinch_lop_venue_settled_fills (same numbering as
-- oneinch_lop_own_trades via oneinch_lop_evt_index()); keeping this view window-free
-- lets consumers' block_time predicates push down into the oneinch_swaps scan
select
f.blockchain
, '1inch-LOP' as project
, cast(f.protocol_version as varchar) as version
, f.block_date
, f.block_month
, f.block_time
, {{ dst_symbol }} as token_bought_symbol
, {{ src_symbol }} as token_sold_symbol
, case
when lower({{ src_symbol }}) > lower({{ dst_symbol }}) then concat({{ dst_symbol }}, '-', {{ src_symbol }})
else concat({{ src_symbol }}, '-', {{ dst_symbol }})
end as token_pair
, cast(f.dst_executed_amount as double) / pow(10, cast(element_at(f.complement, 'dst_decimals') as bigint)) as token_bought_amount
, cast(f.src_executed_amount as double) / pow(10, cast(element_at(f.complement, 'src_decimals') as bigint)) as token_sold_amount
, f.dst_executed_amount as token_bought_amount_raw
, f.src_executed_amount as token_sold_amount_raw
, f.amount_usd
, f.dst_token_address as token_bought_address
, f.src_token_address as token_sold_address
, f.user as taker
, cast(null as varbinary) as maker
, f.call_to as project_contract_address
, f.tx_hash
, f.tx_from
, f.tx_to
, f.call_trace_address as trace_address
, v.evt_index
from {{ ref('oneinch_swaps') }} as f
join {{ ref('oneinch_lop_venue_settled_fills') }} as v
on v.blockchain = f.blockchain
and v.block_month = f.block_month
and v.execution_id = f.execution_id
where true
and f.mode = 'limits'
and f.tx_success
and f.call_success
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{
{{
config(
schema = 'oneinch',
alias = 'lop_own_trades',
Expand All @@ -10,9 +10,26 @@
{% set src_symbol = "coalesce(src_executed_symbol, '')" %}
{% set dst_symbol = "coalesce(dst_executed_symbol, '')" %}
{% set placeholder_tokens = oneinch_cross_chain_placeholder_tokens_cfg_macro() | join(', ') %}
{% set maturity_delay = "interval '6' hour" %}



with fills as (
-- evt_index is numbered over ALL limits fills, before the venue-settled exclusion:
-- kept rows must retain their historical evt_index because dex_<blockchain>_trades
-- merges can only upsert, never delete
select *
, {{ oneinch_lop_evt_index() }} as evt_index
from {{ ref('oneinch_swaps') }}
where true
and mode = 'limits'
and tx_success
and call_success
-- exclude Fusion+ cross-chain fills: the ERC20True placeholder leg makes these degenerate single-chain rows
and (src_token_address is null or src_token_address not in ({{ placeholder_tokens }}))
and (dst_token_address is null or dst_token_address not in ({{ placeholder_tokens }}))
)

select
blockchain
, '1inch-LOP' as project
Expand Down Expand Up @@ -40,12 +57,19 @@ select
, tx_hash
, tx_from
, tx_to
, row_number() over(partition by tx_hash order by call_trace_address) as evt_index
from {{ ref('oneinch_swaps') }}
, evt_index
from fills as f
where true
and mode = 'limits'
and tx_success
and call_success
-- exclude Fusion+ cross-chain fills: the ERC20True placeholder leg makes these degenerate single-chain rows
and (src_token_address is null or src_token_address not in ({{ placeholder_tokens }}))
and (dst_token_address is null or dst_token_address not in ({{ placeholder_tokens }}))
and not exists ( -- venue-settled fills are reclassified into dex_aggregator.trades (see oneinch_lop_aggregator_trades)
select 1
from {{ ref('oneinch_lop_venue_settled_fills') }} as v
where true
and v.blockchain = f.blockchain
and v.block_month = f.block_month
and v.execution_id = f.execution_id
)
-- maturity delay: the 1inch lineage builds from raw traces while venue base trades
-- build from decoded events; a fill merged into dex_<blockchain>_trades before its
-- venue's event decodes would never be removed (merge can't delete), so fills only
-- pass through once old enough for the venue side to have landed
and f.block_time <= now() - {{ maturity_delay }}
Comment thread
thevaizman marked this conversation as resolved.
Loading
Loading