diff --git a/dex/models/_projects/oneinch/arbitrum/oneinch_arbitrum_ar_raw_traces.sql b/dex/models/_projects/oneinch/arbitrum/oneinch_arbitrum_ar_raw_traces.sql new file mode 100644 index 00000000000..4e057128c66 --- /dev/null +++ b/dex/models/_projects/oneinch/arbitrum/oneinch_arbitrum_ar_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'arbitrum' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'ar_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_ar_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/arbitrum/oneinch_arbitrum_lop_raw_traces.sql b/dex/models/_projects/oneinch/arbitrum/oneinch_arbitrum_lop_raw_traces.sql new file mode 100644 index 00000000000..d72642d91db --- /dev/null +++ b/dex/models/_projects/oneinch/arbitrum/oneinch_arbitrum_lop_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'arbitrum' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'lop_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_lop_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/avalanche_c/oneinch_avalanche_c_ar_raw_traces.sql b/dex/models/_projects/oneinch/avalanche_c/oneinch_avalanche_c_ar_raw_traces.sql new file mode 100644 index 00000000000..1fc8df967e6 --- /dev/null +++ b/dex/models/_projects/oneinch/avalanche_c/oneinch_avalanche_c_ar_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'avalanche_c' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'ar_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_ar_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/avalanche_c/oneinch_avalanche_c_lop_raw_traces.sql b/dex/models/_projects/oneinch/avalanche_c/oneinch_avalanche_c_lop_raw_traces.sql new file mode 100644 index 00000000000..ab6678560c3 --- /dev/null +++ b/dex/models/_projects/oneinch/avalanche_c/oneinch_avalanche_c_lop_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'avalanche_c' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'lop_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_lop_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/base/oneinch_base_ar_raw_traces.sql b/dex/models/_projects/oneinch/base/oneinch_base_ar_raw_traces.sql new file mode 100644 index 00000000000..9d33ba381b2 --- /dev/null +++ b/dex/models/_projects/oneinch/base/oneinch_base_ar_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'base' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'ar_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_ar_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/base/oneinch_base_lop_raw_traces.sql b/dex/models/_projects/oneinch/base/oneinch_base_lop_raw_traces.sql new file mode 100644 index 00000000000..77722c0a205 --- /dev/null +++ b/dex/models/_projects/oneinch/base/oneinch_base_lop_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'base' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'lop_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_lop_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/bnb/oneinch_bnb_ar_raw_traces.sql b/dex/models/_projects/oneinch/bnb/oneinch_bnb_ar_raw_traces.sql new file mode 100644 index 00000000000..eee54e8d557 --- /dev/null +++ b/dex/models/_projects/oneinch/bnb/oneinch_bnb_ar_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'bnb' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'ar_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_ar_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/bnb/oneinch_bnb_lop_raw_traces.sql b/dex/models/_projects/oneinch/bnb/oneinch_bnb_lop_raw_traces.sql new file mode 100644 index 00000000000..007d7d09682 --- /dev/null +++ b/dex/models/_projects/oneinch/bnb/oneinch_bnb_lop_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'bnb' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'lop_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_lop_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/ethereum/oneinch_ethereum_ar_raw_traces.sql b/dex/models/_projects/oneinch/ethereum/oneinch_ethereum_ar_raw_traces.sql new file mode 100644 index 00000000000..fa8aefb54a0 --- /dev/null +++ b/dex/models/_projects/oneinch/ethereum/oneinch_ethereum_ar_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'ethereum' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'ar_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_ar_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/ethereum/oneinch_ethereum_lop_raw_traces.sql b/dex/models/_projects/oneinch/ethereum/oneinch_ethereum_lop_raw_traces.sql new file mode 100644 index 00000000000..a38e0e1ecfa --- /dev/null +++ b/dex/models/_projects/oneinch/ethereum/oneinch_ethereum_lop_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'ethereum' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'lop_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_lop_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/fantom/oneinch_fantom_ar_raw_traces.sql b/dex/models/_projects/oneinch/fantom/oneinch_fantom_ar_raw_traces.sql new file mode 100644 index 00000000000..04f01f6d9b6 --- /dev/null +++ b/dex/models/_projects/oneinch/fantom/oneinch_fantom_ar_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'fantom' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'ar_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_ar_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/fantom/oneinch_fantom_lop_raw_traces.sql b/dex/models/_projects/oneinch/fantom/oneinch_fantom_lop_raw_traces.sql new file mode 100644 index 00000000000..076d785ec6b --- /dev/null +++ b/dex/models/_projects/oneinch/fantom/oneinch_fantom_lop_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'fantom' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'lop_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_lop_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/gnosis/oneinch_gnosis_ar_raw_traces.sql b/dex/models/_projects/oneinch/gnosis/oneinch_gnosis_ar_raw_traces.sql new file mode 100644 index 00000000000..dfb714c48a4 --- /dev/null +++ b/dex/models/_projects/oneinch/gnosis/oneinch_gnosis_ar_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'gnosis' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'ar_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_ar_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/gnosis/oneinch_gnosis_lop_raw_traces.sql b/dex/models/_projects/oneinch/gnosis/oneinch_gnosis_lop_raw_traces.sql new file mode 100644 index 00000000000..e409b9f6909 --- /dev/null +++ b/dex/models/_projects/oneinch/gnosis/oneinch_gnosis_lop_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'gnosis' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'lop_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_lop_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/optimism/oneinch_optimism_ar_raw_traces.sql b/dex/models/_projects/oneinch/optimism/oneinch_optimism_ar_raw_traces.sql new file mode 100644 index 00000000000..50075932627 --- /dev/null +++ b/dex/models/_projects/oneinch/optimism/oneinch_optimism_ar_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'optimism' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'ar_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_ar_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/optimism/oneinch_optimism_lop_raw_traces.sql b/dex/models/_projects/oneinch/optimism/oneinch_optimism_lop_raw_traces.sql new file mode 100644 index 00000000000..84ae1797ac9 --- /dev/null +++ b/dex/models/_projects/oneinch/optimism/oneinch_optimism_lop_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'optimism' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'lop_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_lop_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/polygon/oneinch_polygon_ar_raw_traces.sql b/dex/models/_projects/oneinch/polygon/oneinch_polygon_ar_raw_traces.sql new file mode 100644 index 00000000000..d6ff1755542 --- /dev/null +++ b/dex/models/_projects/oneinch/polygon/oneinch_polygon_ar_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'polygon' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'ar_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_ar_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/polygon/oneinch_polygon_lop_raw_traces.sql b/dex/models/_projects/oneinch/polygon/oneinch_polygon_lop_raw_traces.sql new file mode 100644 index 00000000000..aad3483796f --- /dev/null +++ b/dex/models/_projects/oneinch/polygon/oneinch_polygon_lop_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'polygon' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'lop_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_lop_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/zksync/oneinch_zksync_ar_raw_traces.sql b/dex/models/_projects/oneinch/zksync/oneinch_zksync_ar_raw_traces.sql new file mode 100644 index 00000000000..f3a54916c59 --- /dev/null +++ b/dex/models/_projects/oneinch/zksync/oneinch_zksync_ar_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'zksync' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'ar_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_ar_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/dex/models/_projects/oneinch/zksync/oneinch_zksync_lop_raw_traces.sql b/dex/models/_projects/oneinch/zksync/oneinch_zksync_lop_raw_traces.sql new file mode 100644 index 00000000000..cbcc04701dd --- /dev/null +++ b/dex/models/_projects/oneinch/zksync/oneinch_zksync_lop_raw_traces.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'zksync' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'lop_raw_traces', + partition_by = ['block_date'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'trace_address', 'block_date'] + ) +}} + + + +{{ + oneinch_lop_raw_traces_macro( + blockchain = blockchain + ) +}} diff --git a/macros/models/_project/oneinch/AR/oneinch_ar_cfg_contracts_macro.sql b/macros/models/_project/oneinch/AR/oneinch_ar_cfg_contracts_macro.sql new file mode 100644 index 00000000000..0580f02afea --- /dev/null +++ b/macros/models/_project/oneinch/AR/oneinch_ar_cfg_contracts_macro.sql @@ -0,0 +1,213 @@ +{% macro oneinch_ar_cfg_contracts_macro() %} + +{% + set samples = { + "aggregate": { + "src_token_address": "fromToken", + "dst_token_address": "toToken", + "src_token_amount": "tokensAmount", + "dst_token_amount": "output_returnAmount", + "dst_token_amount_min": "minTokensAmount", + "router_type": "generic", + }, + "swap": { + "kit": "cast(json_parse(desc) as map(varchar, varchar))", + "src_token_address": "from_hex(kit['srcToken'])", + "dst_token_address": "from_hex(kit['dstToken'])", + "src_receiver": "from_hex(kit['srcReceiver'])", + "dst_receiver": "from_hex(kit['dstReceiver'])", + "src_token_amount": "cast(kit['amount'] as uint256)", + "dst_token_amount": "output_returnAmount", + "dst_token_amount_min": "cast(kit['minReturnAmount'] as uint256)", + "router_type": "generic", + }, + "unoswap v3-v5": { + "pools": "pools", + "src_token_amount": "amount", + "dst_token_amount": "output_returnAmount", + "dst_token_amount_min": "minReturn", + "direction_mask": "bytearray_to_uint256(rpad(0x80, 32, 0x00))", + "unwrap_mask": "bytearray_to_uint256(rpad(0x40, 32, 0x00))", + "router_type": "unoswap", + }, + "unoswap v6": { + "src_token_address": "substr(cast(token as varbinary), 13)", + "src_token_amount": "amount", + "dst_token_amount": "output_returnAmount", + "dst_token_amount_min": "minReturn", + "pool_type_mask": "bytearray_to_uint256(rpad(0xe0000000, 32, 0x00))", + "pool_type_offset": "253", + "direction_mask": "bytearray_to_uint256(rpad(0x00800000, 32, 0x00))", + "unwrap_mask": "bytearray_to_uint256(rpad(0x10000000, 32, 0x00))", + "src_token_mask": "bytearray_to_uint256(rpad(0x000000ff, 32, 0x00))", + "src_token_offset": "224", + "dst_token_mask": "bytearray_to_uint256(rpad(0x0000ff00, 32, 0x00))", + "dst_token_offset": "232", + "router_type": "unoswap", + }, + "clipper": { + "src_token_address": "srcToken", + "dst_token_address": "dstToken", + "src_token_amount": "inputAmount", + "dst_token_amount": "output_returnAmount", + "router_type": "clipper", + }, + } +%} + +-- EVENTS CONFIG +{% + set contracts = { + "ExchangeV1": { + "version": "0.1", + "blockchains": ["ethereum"], + "start": "2019-06-03", + "end": "2020-09-18", + "methods": { + "aggregate": samples["aggregate"], + }, + }, + "ExchangeV2": { + "version": "0.2", + "blockchains": ["ethereum"], + "start": "2019-06-10", + "end": "2020-09-18", + "methods": { + "aggregate": samples["aggregate"], + }, + }, + "ExchangeV3": { + "version": "0.3", + "blockchains": ["ethereum"], + "start": "2019-06-18", + "end": "2020-09-18", + "methods": { + "aggregate": samples["aggregate"], + }, + }, + "ExchangeV4": { + "version": "0.4", + "blockchains": ["ethereum"], + "start": "2019-07-18", + "end": "2020-09-18", + "methods": { + "aggregate": samples["aggregate"], + }, + }, + "ExchangeV5": { + "version": "0.5", + "blockchains": ["ethereum"], + "start": "2019-07-18", + "end": "2020-09-18", + "methods": { + "aggregate": samples["aggregate"], + }, + }, + "ExchangeV6": { + "version": "0.6", + "blockchains": ["ethereum"], + "start": "2019-07-19", + "end": "2020-09-18", + "methods": { + "aggregate": samples["aggregate"], + }, + }, + "ExchangeV7": { + "version": "0.7", + "blockchains": ["ethereum"], + "start": "2019-09-17", + "end": "2019-09-29", + "methods": { + "swap": dict(samples["aggregate"], src_token_amount="fromTokenAmount", dst_token_amount_min="minReturnAmount"), + }, + }, + "AggregationRouterV1": { + "version": "1", + "blockchains": ["ethereum"], + "start": "2019-09-28", + "methods": { + "swap": dict(samples["aggregate"], src_token_amount="fromTokenAmount", dst_token_amount_min="minReturnAmount"), + }, + }, + "AggregationRouterV2": { + "version": "2", + "blockchains": ["ethereum", "bnb"], + "start": "2020-11-04", + "methods": { + "swap": samples["swap"], + "discountedSwap": samples["swap"], + }, + }, + "AggregationRouterV3": { + "version": "3", + "blockchains": ["ethereum", "bnb", "polygon", "arbitrum", "optimism"], + "start": "2021-03-14", + "methods": { + "swap": samples["swap"], + "discountedSwap": samples["swap"], + "unoswap": dict(samples["unoswap v3-v5"], blockchains=["ethereum","bnb","polygon","arbitrum"], src_token_address="srcToken", pools="transform(_0, x -> bytearray_to_uint256(x))"), + "unoswapWithPermit": dict(samples["unoswap v3-v5"], blockchains=["ethereum","bnb","polygon","arbitrum"], src_token_address="srcToken", pools="transform(pools, x -> bytearray_to_uint256(x))"), + }, + }, + "AggregationRouterV4": { + "version": "4", + "blockchains": ["ethereum", "bnb", "polygon", "arbitrum", "optimism", "avalanche_c", "gnosis", "fantom"], + "start": "2021-11-05", + "methods": { + "swap": samples["swap"], + "discountedSwap": dict(samples["swap"], blockchains=["bnb", "polygon"]), + "clipperSwap": dict(samples["clipper"], src_token_amount="amount", dst_token_amount_min="minReturn", blockchains=["ethereum"]), + "clipperSwapTo": dict(samples["clipper"], src_token_amount="amount", dst_token_amount_min="minReturn", blockchains=["ethereum"], dst_receiver="recipient"), + "clipperSwapToWithPermit": dict(samples["clipper"], src_token_amount="amount", dst_token_amount_min="minReturn", blockchains=["ethereum"], dst_receiver="recipient"), + "unoswap": dict(samples["unoswap v3-v5"], src_token_address="srcToken", pools="transform(pools, x -> bytearray_to_uint256(x))"), + "unoswapWithPermit": dict(samples["unoswap v3-v5"], src_token_address="srcToken", pools="transform(pools, x -> bytearray_to_uint256(x))"), + "uniswapV3Swap": dict(samples["unoswap v3-v5"], unwrap_mask="bytearray_to_uint256(rpad(0x20, 32, 0x00))"), + "uniswapV3SwapTo": dict(samples["unoswap v3-v5"], dst_receiver="recipient", unwrap_mask="bytearray_to_uint256(rpad(0x20, 32, 0x00))"), + "uniswapV3SwapToWithPermit": dict(samples["unoswap v3-v5"], dst_receiver="recipient", unwrap_mask="bytearray_to_uint256(rpad(0x20, 32, 0x00))"), + }, + }, + "AggregationRouterV5": { + "version": "5", + "blockchains": ["ethereum", "bnb", "polygon", "arbitrum", "optimism", "avalanche_c", "gnosis", "fantom", "base", "zksync"], + "start": "2022-11-04", + "methods": { + "swap": samples["swap"], + "clipperSwap": samples["clipper"], + "clipperSwapTo": dict(samples["clipper"], dst_receiver="recipient"), + "clipperSwapToWithPermit": dict(samples["clipper"], dst_receiver="recipient"), + "unoswap": dict(samples["unoswap v3-v5"], src_token_address="srcToken"), + "unoswapTo": dict(samples["unoswap v3-v5"], src_token_address="srcToken", dst_receiver="recipient"), + "unoswapToWithPermit": dict(samples["unoswap v3-v5"], src_token_address="srcToken", dst_receiver="recipient"), + "uniswapV3Swap": dict(samples["unoswap v3-v5"], unwrap_mask="bytearray_to_uint256(rpad(0x20, 32, 0x00))"), + "uniswapV3SwapTo": dict(samples["unoswap v3-v5"], dst_receiver="recipient", unwrap_mask="bytearray_to_uint256(rpad(0x20, 32, 0x00))"), + "uniswapV3SwapToWithPermit": dict(samples["unoswap v3-v5"], dst_receiver="recipient", unwrap_mask="bytearray_to_uint256(rpad(0x20, 32, 0x00))"), + }, + }, + "AggregationRouterV6": { + "version": "6", + "blockchains": ["ethereum", "bnb", "polygon", "arbitrum", "optimism", "avalanche_c", "gnosis", "fantom", "base", "zksync"], + "start": "2024-02-12", + "methods": { + "swap": dict(samples["swap"], src_token_amount="output_spentAmount"), + "clipperSwap": dict(samples["clipper"], src_token_address="substr(cast(srcToken as varbinary), 13)", blockchains=["ethereum","bnb","polygon","arbitrum","optimism","avalanche_c","gnosis","fantom","base"]), + "clipperSwapTo": dict(samples["clipper"], src_token_address="substr(cast(srcToken as varbinary), 13)", blockchains=["ethereum","bnb","polygon","arbitrum","optimism","avalanche_c","gnosis","fantom","base"], dst_receiver="recipient"), + "ethUnoswap": dict(samples["unoswap v6"], src_token_address=native, src_token_amount="call_value", pools="array[dex]"), + "ethUnoswap2": dict(samples["unoswap v6"], src_token_address=native, src_token_amount="call_value", pools="array[dex,dex2]"), + "ethUnoswap3": dict(samples["unoswap v6"], src_token_address=native, src_token_amount="call_value", pools="array[dex,dex2,dex3]"), + "ethUnoswapTo": dict(samples["unoswap v6"], src_token_address=native, src_token_amount="call_value", dst_receiver='substr(cast("to" as varbinary), 13)', pools="array[dex]"), + "ethUnoswapTo2": dict(samples["unoswap v6"], src_token_address=native, src_token_amount="call_value", dst_receiver='substr(cast("to" as varbinary), 13)', pools="array[dex,dex2]"), + "ethUnoswapTo3": dict(samples["unoswap v6"], src_token_address=native, src_token_amount="call_value", dst_receiver='substr(cast("to" as varbinary), 13)', pools="array[dex,dex2,dex3]"), + "unoswap": dict(samples["unoswap v6"], pools="array[dex]"), + "unoswap2": dict(samples["unoswap v6"], pools="array[dex,dex2]"), + "unoswap3": dict(samples["unoswap v6"], pools="array[dex,dex2,dex3]"), + "unoswapTo": dict(samples["unoswap v6"], dst_receiver='substr(cast("to" as varbinary), 13)', pools="array[dex]"), + "unoswapTo2": dict(samples["unoswap v6"], dst_receiver='substr(cast("to" as varbinary), 13)', pools="array[dex,dex2]"), + "unoswapTo3": dict(samples["unoswap v6"], dst_receiver='substr(cast("to" as varbinary), 13)', pools="array[dex,dex2,dex3]"), + }, + }, + } +%} + +{{ return(contracts) }} + +{% endmacro %} \ No newline at end of file diff --git a/macros/models/_project/oneinch/AR/oneinch_ar_raw_traces_macro.sql b/macros/models/_project/oneinch/AR/oneinch_ar_raw_traces_macro.sql new file mode 100644 index 00000000000..dea86f05bdf --- /dev/null +++ b/macros/models/_project/oneinch/AR/oneinch_ar_raw_traces_macro.sql @@ -0,0 +1,55 @@ +{% macro oneinch_ar_raw_traces_macro( + blockchain + , date_from = '2019-06-01' +)%} + +with decoded_calls as ( + {% for contract, contract_data in oneinch_ar_cfg_contracts_macro().items() if blockchain in contract_data.blockchains %} + {% set outer_loop = loop %} + {% for method, method_data in contract_data.methods.items() if blockchain in method_data.get('blockchains', contract_data.blockchains) %} -- method-level blockchains override contract-level blockchains + select call_tx_hash as tx_hash, call_block_number as block_number, call_trace_address as trace_address, date(call_block_time) as block_date from {{ source('oneinch_' + blockchain, contract + '_call_' + method) }} + {% if is_incremental() %} + where {{ incremental_predicate('call_block_time') }} + {% else %} + where call_block_time >= greatest(timestamp '{{ contract_data['start'] }}', timestamp '{{date_from}}') + {% endif %} + {% if not outer_loop.last or not loop.last %} + union all + {% endif %} + {% endfor %} + {% endfor %} +) + +, traces as ( + select + block_number + , block_time + , tx_hash + , tx_success + , "from" + , "to" + , trace_address + , success + , substr(input, 1, 4) as selector + , gas_used + , call_type + , error + , input + , value + , length(input) as input_length + , output + , block_date + from {{ source(blockchain, 'traces') }} + where + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= timestamp '{{date_from}}' + {% endif %} +) + + +select * from traces +join decoded_calls using(tx_hash, block_number, trace_address, block_date) + +{% endmacro %} diff --git a/macros/models/_project/oneinch/LOP/oneinch_lop_cfg_contracts_macro.sql b/macros/models/_project/oneinch/LOP/oneinch_lop_cfg_contracts_macro.sql new file mode 100644 index 00000000000..fb8bd2407d6 --- /dev/null +++ b/macros/models/_project/oneinch/LOP/oneinch_lop_cfg_contracts_macro.sql @@ -0,0 +1,119 @@ +{% macro oneinch_lop_cfg_contracts_macro() %} + +-- METHODS SAMPLES +{% + set samples = { + "v2": { + "maker": "from_hex(order_map['maker'])", + "maker_asset": "from_hex(order_map['makerAsset'])", + "taker_asset": "from_hex(order_map['takerAsset'])", + "making_amount": "output_0", + "taking_amount": "output_1", + }, + "v4": { + "maker": "substr(cast(cast(order_map['maker'] as uint256) as varbinary), 13)", + "receiver": "substr(cast(cast(order_map['receiver'] as uint256) as varbinary), 13)", + "maker_asset": "substr(cast(cast(order_map['makerAsset'] as uint256) as varbinary), 13)", + "taker_asset": "substr(cast(cast(order_map['takerAsset'] as uint256) as varbinary), 13)", + "making_amount": "output_0", + "taking_amount": "output_1", + "order_hash": "output_2", + "order_remains": "varbinary_concat(0x01, substr(cast(cast(order_map['salt'] as uint256) as varbinary), 1, 4))", + "maker_traits": "cast(cast(order_map['makerTraits'] as uint256) as varbinary)", + "partial_bit": "1", + "multiple_bit": "2", + } + } +%} +-- partial_bit & multiple_bit: the number of the bit on the left starting from 1 to 256 in 32 bytes in MakerTraits struct +-- [the number of the bit] = 256 - [solidity offset (~ PARTIAL_FILLS & ~ MULTIPLE_FILLS)] + +-- CONTRACTS CONFIG +{% + set contracts = { + "LimitOrderProtocolV1": { + "version": "1", + "blockchains": ["ethereum", "bnb", "polygon", "arbitrum", "optimism"], + "start": "2021-06-03", + "methods": { + "fillOrder": dict(samples["v2"], maker="substr(from_hex(order_map['makerAssetData']), 4 + 12 + 1, 20)"), + "fillOrderRFQ": dict( + samples["v2"], + maker= "substr(from_hex(order_map['makerAssetData']), 4 + 12 + 1, 20)", + making_amount="bytearray_to_uint256(substr(from_hex(order_map['makerAssetData']), 4 + 32*2 + 1, 32))", + taking_amount="bytearray_to_uint256(substr(from_hex(order_map['takerAssetData']), 4 + 32*2 + 1, 32))", + ), + }, + }, + "LimitOrderProtocolV2": { + "version": "2", + "blockchains": ["ethereum", "bnb", "polygon", "arbitrum", "avalanche_c", "gnosis", "optimism"], + "start": "2021-11-26", + "methods": { + "fillOrder": samples["v2"], + "fillOrderTo": dict(samples["v2"], receiver="from_hex(order_map['receiver'])"), + "fillOrderToWithPermit": dict(samples["v2"], receiver="from_hex(order_map['receiver'])"), + "fillOrderRFQ": samples["v2"], + "fillOrderRFQTo": samples["v2"], + "fillOrderRFQToWithPermit": samples["v2"], + }, + }, + "AggregationRouterV4": { + "version": "2", + "blockchains": ["ethereum", "bnb", "polygon", "arbitrum", "avalanche_c", "gnosis", "optimism", "fantom"], + "start": "2021-11-05", + "methods": { + "fillOrderRFQ": samples["v2"], + "fillOrderRFQTo": samples["v2"], + "fillOrderRFQToWithPermit": samples["v2"], + }, + }, + "AggregationRouterV5": { + "version": "3", + "blockchains": ["ethereum", "bnb", "polygon", "arbitrum", "avalanche_c", "gnosis", "optimism", "fantom", "base", "zksync"], + "start": "2022-11-04", + "methods": { + "fillOrder": dict(samples["v2"], order_hash="output_2"), + "fillOrderTo": dict( + samples["v2"], + order = '"order_"', + making_amount = "output_actualMakingAmount", + taking_amount = "output_actualTakingAmount", + order_hash = "output_orderHash", + receiver = "from_hex(order_map['receiver'])", + ), + "fillOrderToWithPermit": dict(samples["v2"], order_hash="output_2", receiver="from_hex(order_map['receiver'])"), + "fillOrderRFQ": dict(samples["v2"], order_hash="output_2"), + "fillOrderRFQTo": dict( + samples["v2"], + making_amount = "output_filledMakingAmount", + taking_amount = "output_filledTakingAmount", + order_hash = "output_orderHash", + ), + "fillOrderRFQToWithPermit": dict(samples["v2"], order_hash="output_2"), + "fillOrderRFQCompact": dict( + samples["v2"], + making_amount = "output_filledMakingAmount", + taking_amount = "output_filledTakingAmount", + order_hash = "output_orderHash", + ), + }, + }, + "AggregationRouterV6": { + "version": "4", + "blockchains": ["ethereum", "bnb", "polygon", "arbitrum", "avalanche_c", "gnosis", "optimism", "fantom", "base"], + "start": "2024-02-12", + "methods": { + "fillOrder": samples["v4"], + "fillOrderArgs": dict(samples["v4"], args="args"), + "fillContractOrder": samples["v4"], + "fillContractOrderArgs": samples["v4"], + }, + }, + } +%} + + +{{ return(contracts) }} + +{% endmacro %} \ No newline at end of file diff --git a/macros/models/_project/oneinch/LOP/oneinch_lop_raw_traces_macro.sql b/macros/models/_project/oneinch/LOP/oneinch_lop_raw_traces_macro.sql new file mode 100644 index 00000000000..0e5667d171b --- /dev/null +++ b/macros/models/_project/oneinch/LOP/oneinch_lop_raw_traces_macro.sql @@ -0,0 +1,55 @@ +{% macro oneinch_lop_raw_traces_macro( + blockchain + , date_from = '2021-06-03' +)%} + +with decoded_calls as ( + {% for contract, contract_data in oneinch_lop_cfg_contracts_macro().items() if blockchain in contract_data.blockchains %} + {% set outer_loop = loop %} + {% for method, method_data in contract_data.methods.items() if blockchain in method_data.get('blockchains', contract_data.blockchains) %} -- method-level blockchains override contract-level blockchains + select call_tx_hash as tx_hash, call_block_number as block_number, call_trace_address as trace_address, date(call_block_time) as block_date from {{ source('oneinch_' + blockchain, contract + '_call_' + method) }} + {% if is_incremental() %} + where {{ incremental_predicate('call_block_time') }} + {% else %} + where call_block_time >= greatest(timestamp '{{ contract_data['start'] }}', timestamp '{{date_from}}') + {% endif %} + {% if not outer_loop.last or not loop.last %} + union all + {% endif %} + {% endfor %} + {% endfor %} +) + +, traces as ( + select + block_number + , block_time + , tx_hash + , tx_success + , "from" + , "to" + , trace_address + , success + , substr(input, 1, 4) as selector + , gas_used + , call_type + , error + , input + , value + , length(input) as input_length + , output + , block_date + from {{ source(blockchain, 'traces') }} + where + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= timestamp '{{date_from}}' + {% endif %} +) + + +select * from traces +join decoded_calls using(tx_hash, block_number, trace_address, block_date) + +{% endmacro %}