Skip to content

Commit

Permalink
fix & add base
Browse files Browse the repository at this point in the history
  • Loading branch information
grkhr committed Apr 24, 2024
1 parent 63a24f0 commit 2ab0ff3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
28 changes: 18 additions & 10 deletions macros/models/_project/oneinch/oneinch_project_swaps_macro.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% macro
oneinch_epms(
oneinch_project_swaps_macro(
blockchain
, date_from
)
%}

Expand Down Expand Up @@ -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 (
Expand All @@ -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)
)

Expand All @@ -69,6 +72,8 @@ methods as (
blockchain = '{{blockchain}}'
{% if is_incremental() %}
and {{ incremental_predicate('minute') }}
{% else %}
and minute >= timestamp '{{date_from}}'
{% endif %}
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 %}
5 changes: 3 additions & 2 deletions models/oneinch/_meta/oneinch_mapped_methods.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions models/oneinch/base/oneinch_base_project_swaps.sql
Original file line number Diff line number Diff line change
@@ -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'
)
}}

0 comments on commit 2ab0ff3

Please sign in to comment.