diff --git a/macros/models/_project/oneinch/oneinch_project_swaps_macro.sql b/macros/models/_project/oneinch/oneinch_project_swaps_macro.sql index 451739b6ba3..a835eb3fafa 100644 --- a/macros/models/_project/oneinch/oneinch_project_swaps_macro.sql +++ b/macros/models/_project/oneinch/oneinch_project_swaps_macro.sql @@ -1,6 +1,7 @@ {% macro - oneinch_epms( + oneinch_project_swaps_macro( blockchain + , date_from ) %} @@ -37,10 +38,11 @@ methods as ( , cardinality(trace_address) = 0 as direct , substr(input, 1, 4) as selector from {{ source(blockchain, 'traces') }} - where - {% if is_incremental() %} - {{ incremental_predicate('block_time') }} - {% endif %} + {% if is_incremental() %} + where {{ incremental_predicate('block_time') }} + {% else %} + where block_time >= timestamp '{{date_from}}' + {% endif %} ) join methods using(call_to, selector) join ( @@ -49,10 +51,11 @@ methods as ( , hash as tx_hash , "from" as tx_from from {{ source(blockchain, 'transactions') }} - where - {% if is_incremental() %} - {{ incremental_predicate('block_time') }} - {% endif %} + {% if is_incremental() %} + where {{ incremental_predicate('block_time') }} + {% else %} + where block_time >= timestamp '{{date_from}}' + {% endif %} ) using(block_number, tx_hash) ) @@ -69,6 +72,8 @@ methods as ( blockchain = '{{blockchain}}' {% if is_incremental() %} and {{ incremental_predicate('minute') }} + {% else %} + and minute >= timestamp '{{date_from}}' {% endif %} ) @@ -105,9 +110,11 @@ methods as ( from calls join ( select * - from {{ oneinch_parsed_transfers_from_calls_macro(blockchain) }} + from ({{ oneinch_parsed_transfers_from_calls_macro(blockchain) }}) {% if is_incremental() %} where {{ incremental_predicate('block_time') }} + {% else %} + where block_time >= timestamp '{{date_from}}' {% endif %} ) as transfers on calls.block_number = transfers.block_number @@ -142,6 +149,7 @@ select , user_amount_usd , caller_amount_usd , call_transfer_addresses + , date(date_trunc('month', block_time)) as block_month from amounts {% endmacro %} \ No newline at end of file diff --git a/models/oneinch/_meta/oneinch_mapped_methods.sql b/models/oneinch/_meta/oneinch_mapped_methods.sql index 7b2f89dd078..20218572791 100644 --- a/models/oneinch/_meta/oneinch_mapped_methods.sql +++ b/models/oneinch/_meta/oneinch_mapped_methods.sql @@ -44,7 +44,7 @@ static as ( , max_by(namespace, created_at) as namespace , max_by(name, created_at) as name from {{ source(blockchain, 'contracts') }} - join {{ ref('oneinch_mapped_contracts') }} using(blockchain, address) + join (select * from {{ ref('oneinch_mapped_contracts') }} where blockchain = '{{blockchain}}') using(address) where flags['user'] group by 1, 2 {% if not loop.last %} union all {% endif %} @@ -66,6 +66,7 @@ static as ( , name , tag , flags + , last_created_at from contracts, unnest(abi) as abi(entity) where json_value(entity, 'lax $.type') = 'function' @@ -112,7 +113,7 @@ static as ( -- output -- select - map_concat(flags, map_from_entries(array[('swap', swap), ('limits', _limits), ('intents', contains(intents, selector)), ('multi', multi), ('top', contains(top, project))])) as flags + map_concat(flags, map_from_entries(array[('swap', swap), ('limits', _limits), ('intents', contains(intents, selector)), ('multi', flags['multi']), ('top', contains(top, project))])) as flags , blockchain , address , last_created_at diff --git a/models/oneinch/base/oneinch_base_project_swaps.sql b/models/oneinch/base/oneinch_base_project_swaps.sql new file mode 100644 index 00000000000..0d6460fff85 --- /dev/null +++ b/models/oneinch/base/oneinch_base_project_swaps.sql @@ -0,0 +1,24 @@ +{% set blockchain = 'base' %} + + + +{{ + config( + schema = 'oneinch_' + blockchain, + alias = 'project_swaps', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['blockchain', 'tx_hash', 'call_trace_address'] + ) +}} + + + +{{ + oneinch_project_swaps_macro( + blockchain = blockchain + , date_from = '2024-01-01' + ) +}} \ No newline at end of file