From ac97a0a30cf5479ba9f3c5093770a32c39a3aeb8 Mon Sep 17 00:00:00 2001 From: max-morrow Date: Fri, 14 Jun 2024 17:34:23 +0300 Subject: [PATCH] 1inch-U25: upgrade project_swaps & project_orders flow (#6155) * huge upgrade project_swaps & project_orders flow - fixed calls to proxy contracts - fixed incorrect parsing contract abi * fixes * retrigger ci * fix bracket * redesigned lineage to optimize future refills - created project_calls flow - some fixes * fix & added blockchains project_orders spellbooks - fix unique keys in project_swaps & project_orders flows * retrigger * retrigger * fix * retrigger * fix * ambigous fix * fix * retrigger ci * retrigger ci * fix * fix * fix * fix * fix * true dates returned --------- Co-authored-by: grkhr --- .../_meta/oneinch_mapped_contracts_macro.sql | 22 +- .../oneinch/oneinch_project_calls_macro.sql | 122 +++++++++ .../oneinch/oneinch_project_orders_macro.sql | 77 ++++-- .../oneinch/oneinch_project_swaps_macro.sql | 258 ++++++++++++------ .../oneinch_arbitrum_project_calls.sql | 24 ++ .../oneinch_arbitrum_project_swaps.sql | 2 +- .../oneinch_avalanche_c_project_calls.sql | 24 ++ .../oneinch_avalanche_c_project_swaps.sql | 2 +- .../base/oneinch_base_project_calls.sql | 24 ++ .../base/oneinch_base_project_swaps.sql | 2 +- .../oneinch/bnb/oneinch_bnb_project_calls.sql | 24 ++ .../oneinch/bnb/oneinch_bnb_project_swaps.sql | 2 +- .../oneinch_ethereum_project_calls.sql | 24 ++ .../oneinch_ethereum_project_swaps.sql | 2 +- .../fantom/oneinch_fantom_project_calls.sql | 24 ++ .../fantom/oneinch_fantom_project_swaps.sql | 2 +- .../gnosis/oneinch_gnosis_project_calls.sql | 24 ++ .../gnosis/oneinch_gnosis_project_swaps.sql | 2 +- models/oneinch/oneinch_project_orders.sql | 102 +++---- models/oneinch/oneinch_project_swaps.sql | 2 +- .../oneinch_optimism_project_calls.sql | 24 ++ .../oneinch_optimism_project_swaps.sql | 2 +- .../polygon/oneinch_polygon_project_calls.sql | 24 ++ .../polygon/oneinch_polygon_project_swaps.sql | 2 +- .../zksync/oneinch_zksync_project_calls.sql | 24 ++ .../zksync/oneinch_zksync_project_swaps.sql | 2 +- 26 files changed, 659 insertions(+), 184 deletions(-) create mode 100644 macros/models/_project/oneinch/oneinch_project_calls_macro.sql create mode 100644 models/oneinch/arbitrum/oneinch_arbitrum_project_calls.sql create mode 100644 models/oneinch/avalanche_c/oneinch_avalanche_c_project_calls.sql create mode 100644 models/oneinch/base/oneinch_base_project_calls.sql create mode 100644 models/oneinch/bnb/oneinch_bnb_project_calls.sql create mode 100644 models/oneinch/ethereum/oneinch_ethereum_project_calls.sql create mode 100644 models/oneinch/fantom/oneinch_fantom_project_calls.sql create mode 100644 models/oneinch/gnosis/oneinch_gnosis_project_calls.sql create mode 100644 models/oneinch/optimism/oneinch_optimism_project_calls.sql create mode 100644 models/oneinch/polygon/oneinch_polygon_project_calls.sql create mode 100644 models/oneinch/zksync/oneinch_zksync_project_calls.sql diff --git a/macros/models/_project/oneinch/_meta/oneinch_mapped_contracts_macro.sql b/macros/models/_project/oneinch/_meta/oneinch_mapped_contracts_macro.sql index 7af3f895b43..32375d18623 100644 --- a/macros/models/_project/oneinch/_meta/oneinch_mapped_contracts_macro.sql +++ b/macros/models/_project/oneinch/_meta/oneinch_mapped_contracts_macro.sql @@ -45,6 +45,7 @@ , ('0xa218543cc21ee9388fa1e509f950fd127ca82155', 'true', '1inch' , 'SettlementV1' , ['fantom']) , ('0x7f069df72b7a39bce9806e3afaf579e54d8cf2b9', 'true', '1inch' , 'SettlementV1' , ['base']) , ('0x11de482747d1b39e599f120d526af512dd1a9326', 'true', '1inch' , 'SettlementV1' , ['zksync']) + , ('0xfb2809a5314473e1165f6b58018e20ed8f07b840', 'true', '1inch' , 'SettlementV2' , ['ethereum','bnb','polygon','arbitrum','avalanche_c','gnosis','optimism','fantom','base']) , ('0x0cae51e1032e8461f4806e26332c030e34de3adb', 'true', 'AnySwap' , 'AnyswapV3Router' , ['arbitrum']) , ('0x7782046601e7b9b05ca55a3899780ce6ee6b8b2b', 'true', 'AnySwap' , 'AnyswapV6Router' , ['ethereum']) , ('0xb0731d50c681c45856bfc3f7539d5f61d4be81d8', 'true', 'AnySwap' , 'UNDEFINED' , ['avalanche_c']) @@ -72,6 +73,7 @@ , ('0x99a58482bd75cbab83b27ec03ca68ff489b5788f', 'true', 'Curvefi' , 'SwapRouter' , ['ethereum']) , ('0xbebc44782c7db0a1a60cb6fe97d0b483032ff1c7', 'true', 'Curvefi' , 'ThreepoolSwap' , ['ethereum']) , ('0xdc24316b9ae028f1497c275eb9192a3ea0f67022', 'true', 'Curvefi' , 'StETHSwap' , ['ethereum']) + , ('0xF0d4c12A5768D806021F80a262B4d39d26C58b8D', 'true', 'Curvefi' , 'CurveRouterV1' , ['ethereum']) , ('0x1d8b86e3d88cdb2d34688e87e72f388cb541b7c8', 'true', 'Curvefi' , 'VyperContract' , ['polygon']) , ('0x43b4fdfd4ff969587185cdb6f0bd875c5fc83f8c', 'true', 'Curvefi' , 'Vyper' , ['ethereum']) , ('0x0656fd85364d03b103ceeda192fb2d3906a6ac15', 'true', 'DODO' , 'DODOFeeRouteProxy' , ['bnb']) @@ -111,8 +113,7 @@ , ('0x1fc3607fa67b58deddb0faf7a116f417a20c551c', 'true', 'Kyber' , 'AggregationRouter' , ['fantom']) , ('0x546c79662e028b661dfb4767664d0273184e4dd1', 'true', 'Kyber' , 'AggregationRouter' , ['polygon']) , ('0x617dee16b86534a5d792a4d7a62fb491b544111e', 'true', 'Kyber' , 'MetaAggregationRouterV1' , ['ethereum','polygon','fantom']) - , ('0x6131b5fae19ea4f9d964eac0408e4408b66337b5', 'true', 'Kyber' , 'MetaAggregationRouterV2' , ['ethereum','bnb','polygon','arbitrum','avalanche_c','fantom']) - , ('0x6131b5fae19ea4f9d964eac0408e4408b66337b5', 'true', 'Kyber' , 'MetaAggregationRouterV2' , ['optimism']) + , ('0x6131b5fae19ea4f9d964eac0408e4408b66337b5', 'true', 'Kyber' , 'MetaAggregationRouterV2' , ['ethereum','bnb','polygon','arbitrum','avalanche_c','optimism','fantom']) , ('0xdf1a1b60f2d438842916c0adc43748768353ec25', 'true', 'Kyber' , 'AggregationRouterV2' , ['polygon','fantom']) , ('0xb18d4f69627f8320619a696202ad2c430cef7c53', 'true', 'LevinSwap' , 'UniswapV2Router02' , ['gnosis']) , ('0x1231deb6f5749ef6ce6943a275a1d3e7486f4eae', 'true', 'LiFi' , 'DiamondV2' , ['ethereum','bnb','polygon','arbitrum','avalanche_c','gnosis','optimism','fantom']) @@ -358,21 +359,6 @@ contracts as ( , 'TransitSwap' , 'ZeroEx' ], project) as multi - , contains(array[ - '1inch' - , 'ZeroEx' - , 'Clipper' - , 'Hashflow' - , 'Native' - , 'Swaap' - , 'Paraswap' - ], project) as lop - , contains(array[ - '1inch' - , 'CoWSwap' - , 'Uniswap' - , 'Bebop' - ], project) as auction , tag from (values {% for row in config if blockchain in row[4] %} @@ -400,7 +386,7 @@ select , address , project , tag - , map_from_entries(array[('user', user), ('multi', multi), ('lop', lop), ('auction', auction)]) as flags + , map_from_entries(array[('user', user), ('multi', multi), ('recreated', first_created_at <> last_created_at)]) as flags , first_created_at , last_created_at , last_creator diff --git a/macros/models/_project/oneinch/oneinch_project_calls_macro.sql b/macros/models/_project/oneinch/oneinch_project_calls_macro.sql new file mode 100644 index 00000000000..92b18a8090f --- /dev/null +++ b/macros/models/_project/oneinch/oneinch_project_calls_macro.sql @@ -0,0 +1,122 @@ +{% macro + oneinch_project_calls_macro( + blockchain + , date_from = '2024-01-01' + ) +%} + +{% set native_addresses = '(0x0000000000000000000000000000000000000000, 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee)' %} + + + +with + +static as ( + select + array['swap', 'settle', 'change', 'exact', 'batch', 'trade', 'sell', 'buy', 'fill', 'route', 'zap', 'symbiosis', 'aggregate', 'multicall', 'execute', 'wrap', 'transform'] as suitables + , array['add', 'remove', 'mint', 'increase', 'decrease', 'cancel', 'destroy', 'claim', 'rescue', 'withdraw', 'simulate', 'join', 'exit', 'interaction', '721', '1155', 'nft', 'create'] as exceptions +) + +, meta as ( + select + wrapped_native_token_address + , native_token_symbol as native_symbol + from ({{ oneinch_blockchain_macro(blockchain) }}) +) + +, contracts as ( + select + blockchain + , address as call_to + , any_value(project) as project + , any_value(tag) as tag + , any_value(flags) as flags + from {{ ref('oneinch_' + blockchain + '_mapped_contracts') }} + where + project not in ('MEVBot', 'Unknown') + group by 1, 2 +) + +, signatures as ( + select + id as selector + , min(signature) as signature + , min(split_part(signature, '(', 1)) as method + from {{ source('abi', 'signatures') }} + where length(id) = 4 + group by 1 +) + +, calls as ( + select * + from ( + select + block_number + , block_time + , tx_hash + , "from" as call_from + , "to" as call_to + , trace_address as call_trace_address + , cardinality(trace_address) = 0 as direct + , substr(input, 1, 4) as selector + , success as call_success + , tx_success + from {{ source(blockchain, 'traces') }} + where + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= timestamp '{{date_from}}' + {% endif %} + ) + join contracts using(call_to) + join signatures using(selector) + join static on true + join meta on true + join ( + select + block_number + , block_time + , hash as tx_hash + , "from" as tx_from + , "to" as tx_to + , gas_used as tx_gas_used + from {{ source(blockchain, 'transactions') }} + where + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= timestamp '{{date_from}}' + {% endif %} + + ) using(block_number, block_time, tx_hash) + where + not reduce(exceptions, false, (r, x) -> if(position(x in lower(replace(method, '_'))) > 0, true, r), r -> r) -- without "exception" methods + and reduce(suitables, false, (r, x) -> if(position(x in lower(replace(method, '_'))) > 0, true, r), r -> r) -- "suitable" methods only +) + +-- output -- + +select + blockchain + , block_number + , block_time + , tx_hash + , tx_from + , tx_to + , tx_success + , tx_gas_used + , call_trace_address + , project + , tag + , map_concat(flags, map_from_entries(array[('direct', direct)])) as flags + , selector as call_selector + , method + , signature + , call_from + , call_to + , call_success + , date(date_trunc('month', block_time)) as block_month +from calls + +{% endmacro %} \ No newline at end of file diff --git a/macros/models/_project/oneinch/oneinch_project_orders_macro.sql b/macros/models/_project/oneinch/oneinch_project_orders_macro.sql index 7f391ddab53..111724c504b 100644 --- a/macros/models/_project/oneinch/oneinch_project_orders_macro.sql +++ b/macros/models/_project/oneinch/oneinch_project_orders_macro.sql @@ -600,8 +600,8 @@ "receiver": "substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*8 + 12 + 1, 32)", "maker_asset": "substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*5 + 24 + 1, 8)) + 32 * least(x, bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*5 + 24 + 1, 8))) + 12 + 1, 20)", "taker_asset": "substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*4 + 24 + 1, 8)) + 32 * least(x, bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*4 + 24 + 1, 8))) + 12 + 1, 20)", - "maker_max_amount": "substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*7 + 24 + 1, 8)) + 32 * least(x, bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*7 + 24 + 1, 8))) + 1, 32)", - "taker_max_amount": "substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*6 + 24 + 1, 8)) + 32 * least(x, bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*6 + 24 + 1, 8))) + 1, 32)", + "making_amount": "substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*7 + 24 + 1, 8)) + 32 * least(x, bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*7 + 24 + 1, 8))) + 1, 32)", + "taking_amount": "substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*6 + 24 + 1, 8)) + 32 * least(x, bytearray_to_bigint(substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*6 + 24 + 1, 8))) + 1, 32)", "deadline": "substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*1 + 24 + 1, 8)", "nonce": "substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*3 + 1, 32)", "order_hash": "substr(input, 4 + bytearray_to_bigint(substr(input, 4 + 24 + 1, 8)) + 32*10 + 1, 16)", @@ -783,6 +783,29 @@ logs as ( , joined as ( select * + , coalesce(log_maker, call_maker, call_to) as maker + , coalesce(log_taker, call_taker) as taker + , coalesce(log_receiver, call_receiver) as receiver + , coalesce(log_maker_asset, call_maker_asset) as maker_asset + , coalesce(log_taker_asset, call_taker_asset) as taker_asset + , coalesce(log_maker_max_amount, call_maker_max_amount) as maker_max_amount + , coalesce(log_taker_max_amount, call_taker_max_amount) as taker_max_amount + , coalesce(log_maker_min_amount, call_maker_min_amount) as maker_min_amount + , coalesce(log_taker_min_amount, call_taker_min_amount) as taker_min_amount + , coalesce(log_making_amount, call_making_amount) as making_amount + , coalesce(log_taking_amount, call_taking_amount) as taking_amount + , coalesce(log_start, call_start) as order_start + , coalesce(log_end, call_end) as order_end + , coalesce(log_deadline, call_deadline) as order_deadline + , coalesce(log_maker_fee_amount, call_maker_fee_amount) as maker_fee_amount + , coalesce(log_taker_fee_amount, call_taker_fee_amount) as taker_fee_amount + , coalesce(log_fee_asset, call_fee_asset) as fee_asset + , coalesce(log_fee_max_amount, call_fee_max_amount) as fee_max_amount + , coalesce(log_fee_min_amount, call_fee_min_amount) as fee_min_amount + , coalesce(log_fee_amount, call_fee_amount) as fee_amount + , coalesce(log_fee_receiver, call_fee_receiver) as fee_receiver + , coalesce(log_nonce, call_nonce) as order_nonce + , coalesce(log_order_hash, call_order_hash, concat(tx_hash, to_big_endian_32(cast(call_trade_counter as int)))) as order_hash , count(*) over(partition by blockchain, block_number, tx_hash, call_trace_address, call_trade) as trades from calls full join logs using(block_number, tx_hash, topic0) @@ -812,7 +835,9 @@ select blockchain , project , tag - , flags + , map_concat(flags, map_from_entries(array[ + ('auction', coalesce(order_start, uint256 '0') > uint256 '0' or project in ('CoWSwap', 'Bebop')) + ])) as flags , block_number , block_time , tx_hash @@ -827,29 +852,29 @@ select , call_error , call_trade , method - , coalesce(coalesce(log_maker, call_maker), call_to) as maker - , coalesce(log_taker, call_taker) as taker - , coalesce(log_receiver, call_receiver) as receiver - , coalesce(log_maker_asset, call_maker_asset) as maker_asset - , coalesce(log_taker_asset, call_taker_asset) as taker_asset - , coalesce(log_maker_max_amount, call_maker_max_amount) as maker_max_amount - , coalesce(log_taker_max_amount, call_taker_max_amount) as taker_max_amount - , coalesce(log_maker_min_amount, call_maker_min_amount) as maker_min_amount - , coalesce(log_taker_min_amount, call_taker_min_amount) as taker_min_amount - , coalesce(log_making_amount, call_making_amount) as making_amount - , coalesce(log_taking_amount, call_taking_amount) as taking_amount - , coalesce(log_start, call_start) as order_start - , coalesce(log_end, call_end) as order_end - , coalesce(log_deadline, call_deadline) as order_deadline - , coalesce(log_maker_fee_amount, call_maker_fee_amount) as maker_fee_amount - , coalesce(log_taker_fee_amount, call_taker_fee_amount) as taker_fee_amount - , coalesce(log_fee_asset, call_fee_asset) as fee_asset - , coalesce(log_fee_max_amount, call_fee_max_amount) as fee_max_amount - , coalesce(log_fee_min_amount, call_fee_min_amount) as fee_min_amount - , coalesce(log_fee_amount, call_fee_amount) as fee_amount - , coalesce(log_fee_receiver, call_fee_receiver) as fee_receiver - , coalesce(log_nonce, call_nonce) as order_nonce - , coalesce(log_order_hash, call_order_hash, to_big_endian_64(call_trade_counter)) as order_hash + , maker + , taker + , receiver + , maker_asset + , taker_asset + , maker_max_amount + , taker_max_amount + , maker_min_amount + , taker_min_amount + , coalesce(making_amount, if(order_start = uint256 '0' or order_start = order_end, maker_max_amount, maker_max_amount - cast(to_unixtime(block_time) - order_start as double) / (order_end - order_start) * (cast(maker_max_amount as double) - cast(maker_min_amount as double))), maker_max_amount, maker_min_amount) as making_amount + , coalesce(taking_amount, if(order_start = uint256 '0' or order_start = order_end, taker_max_amount, taker_max_amount - cast(to_unixtime(block_time) - order_start as double) / (order_end - order_start) * (cast(taker_max_amount as double) - cast(taker_min_amount as double))), taker_max_amount, taker_min_amount) as taking_amount + , order_start + , order_end + , order_deadline + , maker_fee_amount + , taker_fee_amount + , fee_asset + , fee_max_amount + , fee_min_amount + , fee_amount + , fee_receiver + , order_nonce + , order_hash , array[input] as call_input , array[output] as call_output , index as event_index diff --git a/macros/models/_project/oneinch/oneinch_project_swaps_macro.sql b/macros/models/_project/oneinch/oneinch_project_swaps_macro.sql index b858aed3386..79ec7f980e4 100644 --- a/macros/models/_project/oneinch/oneinch_project_swaps_macro.sql +++ b/macros/models/_project/oneinch/oneinch_project_swaps_macro.sql @@ -5,78 +5,139 @@ ) %} +{% set native_addresses = '(0x0000000000000000000000000000000000000000, 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee)' %} + with -methods as ( +meta as ( + select + chain_id + , wrapped_native_token_address + , native_token_symbol as native_symbol + from ({{ oneinch_blockchain_macro(blockchain) }}) +) + +, orders as ( select - blockchain - , address as call_to + block_number + , tx_hash + , call_trace_address , project - , method - , selector - , flags - from {{ ref('oneinch_' + blockchain + '_mapped_methods') }} - where flags['swap'] + , order_hash + , maker + , maker_asset + , making_amount + , taker_asset + , taking_amount + , flags as order_flags + from {{ ref('oneinch_' + blockchain + '_project_orders') }} + where + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= timestamp '{{date_from}}' + {% endif %} + and call_success + + union all + + select + block_number + , tx_hash + , call_trace_address + , '1inch' as project + , coalesce(order_hash, concat(tx_hash, to_big_endian_32(cast(counter as int)))) as order_hash + , maker + , maker_asset + , making_amount + , taker_asset + , taking_amount + , flags as order_flags + from ( + select *, row_number() over(partition by block_number, tx_hash order by call_trace_address) as counter + from {{ ref('oneinch_' + blockchain + '_lop') }} + where + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= timestamp '{{date_from}}' + {% endif %} + and call_success + ) ) , calls as ( select - * - , array_agg((call_trace_address, flags)) over(partition by block_number, tx_hash, project) as call_trace_addresses + blockchain + , block_number + , tx_hash + , tx_from + , tx_to + , call_trace_address + , project + , tag + , flags + , call_selector + , method + , call_from + , call_to + , order_hash + , order_flags + , maker + , maker_asset + , making_amount + , taker_asset + , taking_amount + , call_trace_addresses + , if(maker_asset in {{native_addresses}}, wrapped_native_token_address, maker_asset) as _maker_asset + , if(taker_asset in {{native_addresses}}, wrapped_native_token_address, taker_asset) as _taker_asset + , coalesce(order_hash, to_big_endian_64(counter)) as call_trade_id from ( select - block_number - , block_time - , tx_hash - , "from" as call_from - , "to" as call_to - , trace_address as call_trace_address - , cardinality(trace_address) = 0 as direct - , substr(input, 1, 4) as selector - from {{ source(blockchain, 'traces') }} - {% if is_incremental() %} - where {{ incremental_predicate('block_time') }} - {% else %} - where block_time >= timestamp '{{date_from}}' - {% endif %} + * + , array_agg(call_trace_address) over(partition by block_number, tx_hash, project) as call_trace_addresses + , row_number() over(partition by block_number, tx_hash order by call_trace_address) as counter + from {{ ref('oneinch_' + blockchain + '_project_calls') }} + where + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= timestamp '{{date_from}}' + {% endif %} and (tx_success or tx_success is null) - and success + and call_success ) - join methods using(call_to, selector) - join ( - select - block_number - , hash as tx_hash - , "from" as tx_from - from {{ source(blockchain, 'transactions') }} - {% if is_incremental() %} - where {{ incremental_predicate('block_time') }} - {% else %} - where block_time >= timestamp '{{date_from}}' - {% endif %} - and (success or success is null) - - ) using(block_number, tx_hash) + left join orders using(block_number, tx_hash, call_trace_address, project) + join meta on true + where + reduce(call_trace_addresses, true, (r, x) -> if(r and x <> call_trace_address and slice(call_trace_address, 1, cardinality(x)) = x, false, r), r -> r) -- only not nested calls of the project in tx + or order_hash is not null -- all orders +) + +, tokens as ( + select + contract_address + , symbol + from {{ source('tokens', 'erc20') }} + where blockchain = '{{blockchain}}' ) , prices as ( select - blockchain - , contract_address + contract_address , minute , price , decimals - , symbol from {{ source('prices', 'usd') }} where - blockchain = '{{blockchain}}' {% if is_incremental() %} - and {{ incremental_predicate('minute') }} + {{ incremental_predicate('minute') }} {% else %} - and minute >= timestamp '{{date_from}}' + minute >= timestamp '{{date_from}}' {% endif %} + and blockchain = '{{blockchain}}' ) , creations as ( @@ -91,57 +152,78 @@ methods as ( (0x0000000000000000000000000000000000000000, 0) ) -, amounts as ( +, swaps as ( select * - , transform(filter(array_distinct(flatten(call_transfer_addresses)), x -> x[2]), x -> (x[1])) as users + , transform(filter(array_distinct(flatten(call_transfer_addresses)), x -> not x.contract), x -> (x.address)) as users , array_agg( cast(row(project, call_trace_address, coalesce(user_amount_usd, amount_usd)) as row(project varchar, call_trace_address array(bigint), amount_usd double)) ) over(partition by block_number, tx_hash) as amounts - , coalesce(if(direct, user_amount_usd, caller_amount_usd), amount_usd) as result_amount_usd + , coalesce(if(flags['direct'], user_amount_usd, caller_amount_usd), amount_usd) as result_amount_usd from ( select - calls.blockchain + blockchain , calls.block_number , calls.tx_hash , calls.call_trace_address - , any_value(calls.block_time) as block_time - , any_value(calls.tx_from) as tx_from - , any_value(calls.project) as project - , any_value(calls.call_from) as call_from - , any_value(calls.call_to) as call_to - , any_value(calls.method) as method - , any_value(calls.flags) as flags - , any_value(calls.direct) as direct + , call_trade_id + , any_value(block_time) as block_time + , any_value(tx_from) as tx_from + , any_value(tx_to) as tx_to + , any_value(project) as project + , any_value(tag) as tag + , any_value(flags) as flags + , any_value(call_from) as call_from + , any_value(call_to) as call_to + , any_value(call_selector) as call_selector + , any_value(method) as method + , any_value(order_hash) as order_hash + , any_value(maker) as maker + , any_value(maker_asset) as maker_asset + , any_value(making_amount) as making_amount + , any_value(taker_asset) as taker_asset + , any_value(taking_amount) as taking_amount + , any_value(order_flags) as order_flags + , array_agg(distinct if(native, native_symbol, symbol)) as tokens , max(amount * price / pow(10, decimals)) as amount_usd , max(amount * price / pow(10, decimals)) filter(where creations_from.block_number is null or creations_to.block_number is null) as user_amount_usd , max(amount * price / pow(10, decimals)) filter(where transfer_from = call_from or transfer_to = call_from) as caller_amount_usd , array_agg(array[ - cast(row(transfer_from, creations_from.block_number is null) as row(address varbinary, success boolean)), - cast(row(transfer_to, creations_to.block_number is null) as row(address varbinary, success boolean)) - ]) as call_transfer_addresses + cast(row(transfer_from, creations_from.block_number is not null) as row(address varbinary, contract boolean)) + , cast(row(transfer_to, creations_to.block_number is not null) as row(address varbinary, contract boolean)) + ]) as call_transfer_addresses from calls join ( - select * - from ({{ oneinch_parsed_transfers_from_calls_macro(blockchain) }}) - {% if is_incremental() %} - where {{ incremental_predicate('block_time') }} - {% else %} - where block_time >= timestamp '{{date_from}}' - {% endif %} + select + block_number + , block_time + , tx_hash + , transfer_trace_address + , if(type = 'native', wrapped_native_token_address, contract_address) as contract_address + , type = 'native' as native + , amount + , native_symbol + , transfer_from + , transfer_to + , date_trunc('minute', block_time) as minute + from ({{ oneinch_parsed_transfers_from_calls_macro(blockchain) }}), meta + where + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= timestamp '{{date_from}}' + {% endif %} ) as transfers on calls.block_number = transfers.block_number and calls.tx_hash = transfers.tx_hash - and slice(transfer_trace_address, 1, cardinality(call_trace_address)) = call_trace_address - and reduce(call_trace_addresses, call_trace_address, (r, x) -> if(slice(transfer_trace_address, 1, cardinality(x[1])) = x[1] and r < x[1], x[1], r), r -> r) = call_trace_address - left join prices on - prices.contract_address = transfers.contract_address - and prices.minute = date_trunc('minute', transfers.block_time) + and slice(transfer_trace_address, 1, cardinality(call_trace_address)) = call_trace_address -- nested transfers only + and reduce(call_trace_addresses, call_trace_address, (r, x) -> if(slice(transfer_trace_address, 1, cardinality(x)) = x and x > r, x, r), r -> r) = call_trace_address -- transfers related to the call only + and (order_hash is null or contract_address in (_maker_asset, _taker_asset)) -- transfers related to the order only + left join prices using(contract_address, minute) + left join tokens using(contract_address) left join creations as creations_from on creations_from.address = transfers.transfer_from left join creations as creations_to on creations_to.address = transfers.transfer_to - where - reduce(call_trace_addresses, true, (r, x) -> if(r and x[1] <> call_trace_address and slice(call_trace_address, 1, cardinality(x[1])) = x[1] and x[2] = flags, false, r), r -> r) - group by 1, 2, 3, 4 + group by 1, 2, 3, 4, 5 ) ) @@ -150,22 +232,34 @@ methods as ( select blockchain , block_number - , tx_hash - , call_trace_address , block_time + , tx_hash , tx_from + , tx_to + , call_trace_address , project + , tag + , flags + , call_selector + , method , call_from , call_to - , method - , map_concat(flags, map_from_entries(array[('direct', direct)])) as flags + , order_hash + , maker + , maker_asset + , making_amount + , taker_asset + , taking_amount + , order_flags + , tokens , amount_usd , user_amount_usd , caller_amount_usd , result_amount_usd , amounts - , if(cardinality(users) = 0 or not flags['limits'], array_union(users, array[tx_from]), users) as users + , if(cardinality(users) = 0 or order_hash is null, array_union(users, array[tx_from]), users) as users , date(date_trunc('month', block_time)) as block_month -from amounts + , call_trade_id +from swaps {% endmacro %} \ No newline at end of file diff --git a/models/oneinch/arbitrum/oneinch_arbitrum_project_calls.sql b/models/oneinch/arbitrum/oneinch_arbitrum_project_calls.sql new file mode 100644 index 00000000000..f9a52ca41b9 --- /dev/null +++ b/models/oneinch/arbitrum/oneinch_arbitrum_project_calls.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'arbitrum' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'project_calls', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address'] + ) +}} + + + +{{ + oneinch_project_calls_macro( + blockchain = blockchain + ) +}} \ No newline at end of file diff --git a/models/oneinch/arbitrum/oneinch_arbitrum_project_swaps.sql b/models/oneinch/arbitrum/oneinch_arbitrum_project_swaps.sql index 9a560bdcf91..7f0ef20cd25 100644 --- a/models/oneinch/arbitrum/oneinch_arbitrum_project_swaps.sql +++ b/models/oneinch/arbitrum/oneinch_arbitrum_project_swaps.sql @@ -11,7 +11,7 @@ file_format = 'delta', incremental_strategy = 'merge', incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'call_trade_id'] ) }} diff --git a/models/oneinch/avalanche_c/oneinch_avalanche_c_project_calls.sql b/models/oneinch/avalanche_c/oneinch_avalanche_c_project_calls.sql new file mode 100644 index 00000000000..108b2656d2d --- /dev/null +++ b/models/oneinch/avalanche_c/oneinch_avalanche_c_project_calls.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'avalanche_c' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'project_calls', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address'] + ) +}} + + + +{{ + oneinch_project_calls_macro( + blockchain = blockchain + ) +}} \ No newline at end of file diff --git a/models/oneinch/avalanche_c/oneinch_avalanche_c_project_swaps.sql b/models/oneinch/avalanche_c/oneinch_avalanche_c_project_swaps.sql index 2165d04fa7a..1163d3cf2b6 100644 --- a/models/oneinch/avalanche_c/oneinch_avalanche_c_project_swaps.sql +++ b/models/oneinch/avalanche_c/oneinch_avalanche_c_project_swaps.sql @@ -11,7 +11,7 @@ file_format = 'delta', incremental_strategy = 'merge', incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'call_trade_id'] ) }} diff --git a/models/oneinch/base/oneinch_base_project_calls.sql b/models/oneinch/base/oneinch_base_project_calls.sql new file mode 100644 index 00000000000..0e032672355 --- /dev/null +++ b/models/oneinch/base/oneinch_base_project_calls.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'base' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'project_calls', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address'] + ) +}} + + + +{{ + oneinch_project_calls_macro( + blockchain = blockchain + ) +}} \ No newline at end of file diff --git a/models/oneinch/base/oneinch_base_project_swaps.sql b/models/oneinch/base/oneinch_base_project_swaps.sql index 68373480266..0ee0f02ba5c 100644 --- a/models/oneinch/base/oneinch_base_project_swaps.sql +++ b/models/oneinch/base/oneinch_base_project_swaps.sql @@ -11,7 +11,7 @@ file_format = 'delta', incremental_strategy = 'merge', incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'call_trade_id'] ) }} diff --git a/models/oneinch/bnb/oneinch_bnb_project_calls.sql b/models/oneinch/bnb/oneinch_bnb_project_calls.sql new file mode 100644 index 00000000000..ce8b3a478fe --- /dev/null +++ b/models/oneinch/bnb/oneinch_bnb_project_calls.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'bnb' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'project_calls', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address'] + ) +}} + + + +{{ + oneinch_project_calls_macro( + blockchain = blockchain + ) +}} \ No newline at end of file diff --git a/models/oneinch/bnb/oneinch_bnb_project_swaps.sql b/models/oneinch/bnb/oneinch_bnb_project_swaps.sql index dd0d00a2bb8..cda7a0bab41 100644 --- a/models/oneinch/bnb/oneinch_bnb_project_swaps.sql +++ b/models/oneinch/bnb/oneinch_bnb_project_swaps.sql @@ -11,7 +11,7 @@ file_format = 'delta', incremental_strategy = 'merge', incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'call_trade_id'] ) }} diff --git a/models/oneinch/ethereum/oneinch_ethereum_project_calls.sql b/models/oneinch/ethereum/oneinch_ethereum_project_calls.sql new file mode 100644 index 00000000000..1c569f7bbad --- /dev/null +++ b/models/oneinch/ethereum/oneinch_ethereum_project_calls.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'ethereum' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'project_calls', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address'] + ) +}} + + + +{{ + oneinch_project_calls_macro( + blockchain = blockchain + ) +}} \ No newline at end of file diff --git a/models/oneinch/ethereum/oneinch_ethereum_project_swaps.sql b/models/oneinch/ethereum/oneinch_ethereum_project_swaps.sql index 62ede1328e7..ce18756de7a 100644 --- a/models/oneinch/ethereum/oneinch_ethereum_project_swaps.sql +++ b/models/oneinch/ethereum/oneinch_ethereum_project_swaps.sql @@ -11,7 +11,7 @@ file_format = 'delta', incremental_strategy = 'merge', incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'call_trade_id'] ) }} diff --git a/models/oneinch/fantom/oneinch_fantom_project_calls.sql b/models/oneinch/fantom/oneinch_fantom_project_calls.sql new file mode 100644 index 00000000000..73caf1173c6 --- /dev/null +++ b/models/oneinch/fantom/oneinch_fantom_project_calls.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'fantom' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'project_calls', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address'] + ) +}} + + + +{{ + oneinch_project_calls_macro( + blockchain = blockchain + ) +}} \ No newline at end of file diff --git a/models/oneinch/fantom/oneinch_fantom_project_swaps.sql b/models/oneinch/fantom/oneinch_fantom_project_swaps.sql index 04c4a8ce828..cc21fa718aa 100644 --- a/models/oneinch/fantom/oneinch_fantom_project_swaps.sql +++ b/models/oneinch/fantom/oneinch_fantom_project_swaps.sql @@ -11,7 +11,7 @@ file_format = 'delta', incremental_strategy = 'merge', incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'call_trade_id'] ) }} diff --git a/models/oneinch/gnosis/oneinch_gnosis_project_calls.sql b/models/oneinch/gnosis/oneinch_gnosis_project_calls.sql new file mode 100644 index 00000000000..1e16a2a37d4 --- /dev/null +++ b/models/oneinch/gnosis/oneinch_gnosis_project_calls.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'gnosis' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'project_calls', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address'] + ) +}} + + + +{{ + oneinch_project_calls_macro( + blockchain = blockchain + ) +}} \ No newline at end of file diff --git a/models/oneinch/gnosis/oneinch_gnosis_project_swaps.sql b/models/oneinch/gnosis/oneinch_gnosis_project_swaps.sql index 5c140abcfbc..522d0483f5a 100644 --- a/models/oneinch/gnosis/oneinch_gnosis_project_swaps.sql +++ b/models/oneinch/gnosis/oneinch_gnosis_project_swaps.sql @@ -11,7 +11,7 @@ file_format = 'delta', incremental_strategy = 'merge', incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'call_trade_id'] ) }} diff --git a/models/oneinch/oneinch_project_orders.sql b/models/oneinch/oneinch_project_orders.sql index e02589fd236..d3e68e9f1d5 100644 --- a/models/oneinch/oneinch_project_orders.sql +++ b/models/oneinch/oneinch_project_orders.sql @@ -7,44 +7,64 @@ incremental_strategy = 'merge', partition_by = ['block_month'], incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'order_hash'] ) }} +{% set + orders_base_columns = [ + 'blockchain', + 'block_number', + 'block_time', + 'tx_hash', + 'method', + 'call_selector', + 'call_trace_address', + 'call_from', + 'call_to', + 'call_gas_used', + 'maker', + 'maker_asset', + 'making_amount', + 'taker_asset', + 'taking_amount', + 'order_hash', + 'flags', + ] +%} + +{% set native_addresses = '(0x0000000000000000000000000000000000000000, 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee)' %} + with - -orders as ( + +meta as ( + select + blockchain + , wrapped_native_token_address + , native_token_symbol as native_symbol + from {{ ref('oneinch_blockchains') }} +) + +, orders as ( select * - , array[maker_asset, taker_asset] as assets + , array[ + if(maker_asset in {{native_addresses}}, wrapped_native_token_address, maker_asset) + , if(taker_asset in {{native_addresses}}, wrapped_native_token_address, taker_asset) + ] as assets , date_trunc('minute', block_time) as minute - , row_number() over(partition by blockchain, block_number, tx_hash, project order by call_trace_address) as counter + , row_number() over(partition by blockchain, block_number, tx_hash order by call_trace_address, order_hash) as counter from ( {% for blockchain in oneinch_exposed_blockchains_list() %} select - blockchain - , block_number - , block_time - , tx_hash + {{ orders_base_columns | join(', ') }} + , tag , project - , method - , call_selector - , call_trace_address - , call_from - , call_to - , call_gas_used - , maker - , maker_asset - , coalesce(making_amount, if(order_start = uint256 '0', maker_max_amount, maker_max_amount - cast(block_unixtime - order_start as double) / (order_end - order_start) * (cast(maker_max_amount as double) - cast(maker_min_amount as double)))) as making_amount - , taker_asset - , coalesce(taking_amount, if(order_start = uint256 '0', taker_max_amount, taker_max_amount - cast(block_unixtime - order_start as double) / (order_end - order_start) * (cast(taker_max_amount as double) - cast(taker_min_amount as double)))) as taking_amount - , order_hash , order_start , order_end , order_deadline - , flags from {{ ref('oneinch_' + blockchain + '_project_orders') }} where call_success {% if not loop.last %} union all {% endif %} @@ -53,30 +73,16 @@ orders as ( union all select - blockchain - , block_number - , block_time - , tx_hash + {{ orders_base_columns | join(', ') }} + , contract_name as tag , '1inch' as project - , method - , call_selector - , call_trace_address - , call_from - , call_to - , call_gas_used - , maker - , maker_asset - , making_amount - , taker_asset - , taking_amount - , order_hash , null as order_start , null as order_end , null as order_deadline - , flags from {{ ref('oneinch_lop') }} where call_success ) + join meta using(blockchain) {% if is_incremental() %} where {{ incremental_predicate('block_time') }} {% endif %} @@ -102,6 +108,7 @@ orders as ( , block_number , tx_hash , call_trace_address + , coalesce(order_hash, concat(tx_hash, to_big_endian_32(cast(counter as int)))) as order_hash , any_value(block_time) as block_time , any_value(project) as project , any_value(call_selector) as call_selector @@ -111,20 +118,20 @@ orders as ( , any_value(maker) as maker , any_value(maker_asset) as maker_asset , any_value(taker_asset) as taker_asset - , any_value(symbol) filter(where contract_address = maker_asset) as maker_asset_symbol - , any_value(symbol) filter(where contract_address = taker_asset) as taker_asset_symbol + , any_value(if(maker_asset = assets[1], symbol, native_symbol)) filter(where contract_address = assets[1]) as maker_asset_symbol + , any_value(if(taker_asset = assets[2], symbol, native_symbol)) filter(where contract_address = assets[2]) as taker_asset_symbol , any_value(making_amount) as making_amount , any_value(taking_amount) as taking_amount - , any_value(making_amount * price / pow(10, decimals)) filter(where contract_address = maker_asset) as making_amount_usd - , any_value(taking_amount * price / pow(10, decimals)) filter(where contract_address = taker_asset) as taking_amount_usd - , any_value(coalesce(order_hash, concat(tx_hash, to_big_endian_32(cast(counter as int))))) as order_hash + , any_value(making_amount * price / pow(10, decimals)) filter(where contract_address = assets[1]) as making_amount_usd + , any_value(taking_amount * price / pow(10, decimals)) filter(where contract_address = assets[2]) as taking_amount_usd , any_value(order_start) as order_start , any_value(order_end) as order_end , any_value(order_deadline) as order_deadline , any_value(flags) as flags - from (select * from orders, unnest(assets) as assets(contract_address)) + , any_value(tag) as tag + from (select * from orders, unnest(assets) as a(contract_address)) left join prices using(blockchain, contract_address, minute) - group by 1, 2, 3, 4 + group by 1, 2, 3, 4, 5 ) -- output -- @@ -134,8 +141,8 @@ select , block_number , block_time , tx_hash - , call_trace_address , project + , call_trace_address , call_selector , call_from , call_to @@ -155,5 +162,6 @@ select , order_end , order_deadline , flags + , tag , date(date_trunc('month', block_time)) as block_month from joined \ No newline at end of file diff --git a/models/oneinch/oneinch_project_swaps.sql b/models/oneinch/oneinch_project_swaps.sql index bf3968c152b..fb1169899c0 100644 --- a/models/oneinch/oneinch_project_swaps.sql +++ b/models/oneinch/oneinch_project_swaps.sql @@ -3,7 +3,7 @@ schema = 'oneinch', alias = 'project_swaps', materialized = 'view', - unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'call_trade_id'] ) }} diff --git a/models/oneinch/optimism/oneinch_optimism_project_calls.sql b/models/oneinch/optimism/oneinch_optimism_project_calls.sql new file mode 100644 index 00000000000..461d4f3b7d2 --- /dev/null +++ b/models/oneinch/optimism/oneinch_optimism_project_calls.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'optimism' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'project_calls', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address'] + ) +}} + + + +{{ + oneinch_project_calls_macro( + blockchain = blockchain + ) +}} \ No newline at end of file diff --git a/models/oneinch/optimism/oneinch_optimism_project_swaps.sql b/models/oneinch/optimism/oneinch_optimism_project_swaps.sql index 5715b69e0eb..d9b13c84eb9 100644 --- a/models/oneinch/optimism/oneinch_optimism_project_swaps.sql +++ b/models/oneinch/optimism/oneinch_optimism_project_swaps.sql @@ -11,7 +11,7 @@ file_format = 'delta', incremental_strategy = 'merge', incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'call_trade_id'] ) }} diff --git a/models/oneinch/polygon/oneinch_polygon_project_calls.sql b/models/oneinch/polygon/oneinch_polygon_project_calls.sql new file mode 100644 index 00000000000..cedb4fb0901 --- /dev/null +++ b/models/oneinch/polygon/oneinch_polygon_project_calls.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'polygon' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'project_calls', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address'] + ) +}} + + + +{{ + oneinch_project_calls_macro( + blockchain = blockchain + ) +}} \ No newline at end of file diff --git a/models/oneinch/polygon/oneinch_polygon_project_swaps.sql b/models/oneinch/polygon/oneinch_polygon_project_swaps.sql index b93244d2cb1..6f1e098e8e9 100644 --- a/models/oneinch/polygon/oneinch_polygon_project_swaps.sql +++ b/models/oneinch/polygon/oneinch_polygon_project_swaps.sql @@ -11,7 +11,7 @@ file_format = 'delta', incremental_strategy = 'merge', incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'call_trade_id'] ) }} diff --git a/models/oneinch/zksync/oneinch_zksync_project_calls.sql b/models/oneinch/zksync/oneinch_zksync_project_calls.sql new file mode 100644 index 00000000000..01091d61d0c --- /dev/null +++ b/models/oneinch/zksync/oneinch_zksync_project_calls.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'zksync' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'project_calls', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address'] + ) +}} + + + +{{ + oneinch_project_calls_macro( + blockchain = blockchain + ) +}} \ No newline at end of file diff --git a/models/oneinch/zksync/oneinch_zksync_project_swaps.sql b/models/oneinch/zksync/oneinch_zksync_project_swaps.sql index c5fe2f1848d..db6d4809a23 100644 --- a/models/oneinch/zksync/oneinch_zksync_project_swaps.sql +++ b/models/oneinch/zksync/oneinch_zksync_project_swaps.sql @@ -11,7 +11,7 @@ file_format = 'delta', incremental_strategy = 'merge', incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], - unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + unique_key = ['blockchain', 'block_number', 'tx_hash', 'call_trace_address', 'call_trade_id'] ) }}