Skip to content

Commit

Permalink
Merge branch 'main' into dex-blast-bladeswap-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Hosuke authored Jul 2, 2024
2 parents d5354bd + d30a005 commit f55f35e
Show file tree
Hide file tree
Showing 97 changed files with 1,954 additions and 132 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ select
,count(*) as transfers_in
,sum(amount_usd) as usd_in
from {{source('labels','owner_addresses')}} l
inner join {{ref('tokens_transfers')}} t
inner join {{source('tokens', 'transfers')}} t
on t.blockchain = l.blockchain
and "to" = l.address
and amount_usd < pow(10,12)
Expand All @@ -45,7 +45,7 @@ select
,count(*) as transfers_out
,sum(amount_usd) as usd_out
from {{source('labels','owner_addresses')}} l
inner join {{ref('tokens_transfers')}} t
inner join {{source('tokens', 'transfers')}} t
on t.blockchain = l.blockchain
and "from" = l.address
and amount_usd < pow(10,12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ select
,max_by(tx_hash, block_time) as last_tx_hash
,max(block_time) as last_block_time
from {{source('labels','owner_addresses')}} l
inner join {{ref('tokens_transfers')}} t
inner join {{source('tokens', 'transfers')}} t
on t.blockchain = l.blockchain
and "to" = l.address
and amount_usd < pow(10,12)
Expand All @@ -40,7 +40,7 @@ select
,max_by(tx_hash, block_time) as last_tx_hash
,max(block_time) as last_block_time
from {{source('labels','owner_addresses')}} l
inner join {{ref('tokens_transfers')}} t
inner join {{source('tokens', 'transfers')}} t
on t.blockchain = l.blockchain
and "from" = l.address
and amount_usd < pow(10,12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ select
,count(*) as transfers_in
,sum(amount_usd) as usd_in
from {{source('labels','owner_addresses')}} l
inner join {{ref('tokens_transfers')}} t
inner join {{source('tokens', 'transfers')}} t
on t.blockchain = l.blockchain
and "to" = l.address
and amount_usd < pow(10,12)
Expand All @@ -40,7 +40,7 @@ select
,count(*) as transfers_out
,sum(amount_usd) as usd_out
from {{source('labels','owner_addresses')}} l
inner join {{ref('tokens_transfers')}} t
inner join {{source('tokens', 'transfers')}} t
on t.blockchain = l.blockchain
and "from" = l.address
and amount_usd < pow(10,12)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
@@ -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 %}
Loading

0 comments on commit f55f35e

Please sign in to comment.