Skip to content

Commit

Permalink
Merge branch 'main' into macro-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hosuke authored Jan 23, 2025
2 parents 022c3a2 + 35d1d10 commit 80bacd4
Show file tree
Hide file tree
Showing 199 changed files with 1,423 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ FROM (VALUES
-- ,('Project', TBD , '[RFG-3] Trail of Bits Security Reviews', 'Season 4')
,('Project', 0xB6B9E9e56AB5a4AF927faa802ac93786352f3af9, 'Cantina.xyx and Spearbit Labs: RFG-3', 'Season 4')
,('Project', 0x697008C9CcA249eB5AbE9583f041A18A850453A4, 'LlamaNodes | High-Performant & Cost-Effective RPCs', 'Season 4')
-- ,('Project', TBD, 'FHE x OP ', 'Season 4')
-- ,('Project', TBD, 'Identity Fusion in the Optimism Ecosystem ', 'Season 4')
-- ,('Project', TBD, 'Metagov', 'Season 4')
-- ,('Project', TBD, 'Shapley Values', 'Season 4')
,('Project', 0x4a364125054B47b669af9D16cc65dCE6C6Fbd573, 'FHE x OP', 'Season 4')
,('Project', 0x6297Be9555d698916F1148507e6bA28B67cFbc54, 'Identity Fusion in the Optimism Ecosystem', 'Season 4')
,('Project', 0x9D31e30003f253563Ff108BC60B16Fdf2c93abb5, 'Metagov', 'Season 4')
,('Project', 0x6eDf76FD16Bb290A544fDc14fBB4b403D1DEeD9f, 'Shapley Values', 'Season 4')
,('Project', 0xd6E193cb08efaaF78ec2559fc0617F2ef7245e49, 'Tokenbound: Tooling for 6551', 'Season 4')
,('Project', 0x4a364125054B47b669af9D16cc65dCE6C6Fbd573, 'Compete Guide To Cross Chain / Rollup Interoperability', 'Season 4')
,('Project', 0x6297Be9555d698916F1148507e6bA28B67cFbc54, 'Cross-chain interoperability research', 'Season 4')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cover_sales as (
from {{ source('nexusmutual_ethereum', 'Cover_call_buyCover') }} c
cross join unnest(c.poolAllocationRequests) as t(pool_allocation)
where c.call_success
and c.contract_address = 0xcafeac0fF5dA0A2777d915531bfA6B29d282Ee62 -- proxy
),

staking_product_premiums as (
Expand All @@ -64,7 +65,8 @@ staking_product_premiums as (
call_tx_hash as tx_hash
from {{ source('nexusmutual_ethereum', 'StakingProducts_call_getPremium') }}
where call_success
and contract_address = 0xcafea573fbd815b5f59e8049e71e554bde3477e4
--and contract_address = 0xcafea573fbd815b5f59e8049e71e554bde3477e4
and contract_address <> 0xcafea524e89514e131ee9f8462536793d49d8738
),

cover_premiums as (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ staking_pools_created as (
call_tx_hash as tx_hash_created
from {{ source('nexusmutual_ethereum', 'Cover_call_createStakingPool') }}
where call_success
and contract_address = 0xcafeac0fF5dA0A2777d915531bfA6B29d282Ee62
and contract_address = 0xcafeac0fF5dA0A2777d915531bfA6B29d282Ee62 -- proxy
union all
select
select
call_block_time as block_time_created,
output_0 as pool_id,
output_1 as pool_address,
Expand Down Expand Up @@ -94,7 +94,8 @@ staking_pool_products_updated as (
from {{ source('nexusmutual_ethereum', 'StakingProducts_call_setProducts') }} as p
cross join unnest(params) as t(json)
where p.call_success
and p.contract_address = 0xcafea573fBd815B5f59e8049E71E554bde3477E4
--and p.contract_address = 0xcafea573fBd815B5f59e8049E71E554bde3477E4
and p.contract_address <> 0xcafea524e89514e131ee9f8462536793d49d8738
and cast(json_query(t.json, 'lax $.setTargetWeight') as boolean) = true
) t
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ select
, coalesce(dst_amount, taking_amount) as taking_amount
, order_hash
, map_concat(flags, map_from_entries(array[
('first', row_number() over(partition by coalesce(order_hash, tx_hash) order by block_number, tx_index, call_trace_address) = 1)
('first', row_number() over(partition by coalesce(order_hash, tx_hash), tx_success and call_success order by block_number, tx_index, call_trace_address) = 1)
, ('direct', call_from = tx_from and call_to = tx_to) -- == cardinality(call_trace_address) = 0, but because of zksync trace structure we switched to this
])) as flags
, remains
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ WITH base_trades as (
minute,
blockchain,
wrapped_token,
underlying_token,
underlying_token_symbol,
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
LEAD(minute, 1, NOW()) OVER (PARTITION BY wrapped_token ORDER BY minute) AS time_of_next_change
FROM {{ source('balancer_v3', 'erc4626_token_prices') }}
GROUP BY 1, 2, 3, 4
GROUP BY 1, 2, 3, 4, 5, 6
)

SELECT
Expand All @@ -85,9 +87,12 @@ SELECT
, block_date
, block_time
, block_number
, token_bought_symbol
, token_sold_symbol
, token_pair
, COALESCE(erc4626a.underlying_token_symbol,
token_bought_symbol) AS token_bought_symbol
, COALESCE(erc4626b.underlying_token_symbol,
token_sold_symbol) AS token_sold_symbol
, CONCAT(COALESCE(erc4626a.underlying_token_symbol, token_bought_symbol), '-',
COALESCE(erc4626b.underlying_token_symbol, token_sold_symbol)) AS token_pair
, token_bought_amount
, token_sold_amount
, token_bought_amount_raw
Expand All @@ -97,8 +102,10 @@ SELECT
dexs.token_bought_amount * erc4626a.price,
dexs.token_sold_amount * erc4626a.price
) AS amount_usd
, token_bought_address
, token_sold_address
, COALESCE(erc4626a.underlying_token,
token_bought_address) AS token_bought_address
, COALESCE(erc4626b.underlying_token,
token_sold_address) AS token_sold_address
, taker
, maker
, project_contract_address
Expand Down
1 change: 1 addition & 0 deletions dbt_subprojects/dex/models/dex_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,6 @@ FROM (VALUES
, ('enosys', 'Enosys', 'Direct', 'enosys_global')
, ('gravity_finance', 'GravityFinance', 'Direct', 'Gravity_Finance')
, ('fluid', 'Fluid DEX', 'Direct', '0xfluid')
, ('jojo', 'JOJO', 'Direct', 'jojo_exchange')
, ('beets', 'Beets DEX', 'Direct', 'beets_fi')
) AS temp_table (project, name, marketplace_type, x_username)
3 changes: 2 additions & 1 deletion dbt_subprojects/dex/models/trades/arbitrum/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ models:
blockchain: arbitrum
sector: dex
project: pancakeswap
contributors: chef_seaweed, tomfutago
contributors: chef_butterbeer, chef_seaweed, tomfutago
config:
tags: ["arbitrum", "dex", "trades", "pancakeswap", "uniswap", "v2"]
description: "Pancakeswap Arbitrum v2 base trades"
Expand All @@ -230,6 +230,7 @@ models:
version:
- 2
- stableswap
- pcsx

- name: balancer_v2_arbitrum_base_trades
meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dexs_macro AS (
}}
),

dexs AS (
dexs_ss AS (
-- PancakeSwap v2 stableswap
SELECT
'stableswap' AS version,
Expand All @@ -46,6 +46,51 @@ dexs AS (
{% if is_incremental() %}
WHERE {{ incremental_predicate('t.evt_block_time') }}
{% endif %}
),

transfer as (
select
tx_hash,
"from",
to,
contract_address,
sum(amount_raw) as amount_raw
from {{ source('tokens', 'transfers') }}
where blockchain = 'arbitrum'
and block_date >= date '2024-08-01'
and tx_hash in (select evt_tx_hash from {{ source('pancakeswap_arbitrum', 'ExclusiveDutchOrderReactor_evt_Fill') }})
{% if is_incremental() %}
and {{ incremental_predicate('block_time') }}
{% endif %}
group by 1,2,3,4
),

dexs_pcsx AS (
-- PancakeSwapX
SELECT
'pcsx' AS version,
a.evt_block_number AS block_number,
a.evt_block_time AS block_time,
a.swapper AS taker,
a.filler AS maker,
receive.amount_raw AS token_bought_amount_raw,
send.amount_raw AS token_sold_amount_raw,
receive.contract_address AS token_bought_address,
send.contract_address AS token_sold_address,
a.contract_address AS project_contract_address,
a.evt_tx_hash AS tx_hash,
a.evt_index

FROM {{ source('pancakeswap_arbitrum', 'ExclusiveDutchOrderReactor_evt_Fill') }} a

LEFT JOIN transfer AS send
ON a.evt_tx_hash = send.tx_hash AND a.swapper = send."from"

LEFT JOIN transfer AS receive
on a.evt_tx_hash = receive.tx_hash AND a.swapper = receive."to"
{% if is_incremental() %}
WHERE {{ incremental_predicate('a.evt_block_time') }}
{% endif %}
)

SELECT
Expand All @@ -70,18 +115,40 @@ UNION ALL
SELECT
'arbitrum' AS blockchain,
'pancakeswap' AS project,
dexs.version,
CAST(date_trunc('month', dexs.block_time) AS date) AS block_month,
CAST(date_trunc('day', dexs.block_time) AS date) AS block_date,
dexs.block_time,
dexs.block_number,
dexs.token_bought_amount_raw,
dexs.token_sold_amount_raw,
dexs.token_bought_address,
dexs.token_sold_address,
dexs.taker,
dexs.maker,
dexs.project_contract_address,
dexs.tx_hash,
dexs.evt_index
FROM dexs
dexs_ss.version,
CAST(date_trunc('month', dexs_ss.block_time) AS date) AS block_month,
CAST(date_trunc('day', dexs_ss.block_time) AS date) AS block_date,
dexs_ss.block_time,
dexs_ss.block_number,
dexs_ss.token_bought_amount_raw,
dexs_ss.token_sold_amount_raw,
dexs_ss.token_bought_address,
dexs_ss.token_sold_address,
dexs_ss.taker,
dexs_ss.maker,
dexs_ss.project_contract_address,
dexs_ss.tx_hash,
dexs_ss.evt_index
FROM dexs_ss
UNION ALL
SELECT
'arbitrum' AS blockchain,
'pancakeswap' AS project,
dexs_pcsx.version,
CAST(date_trunc('month', dexs_pcsx.block_time) AS date) AS block_month,
CAST(date_trunc('day', dexs_pcsx.block_time) AS date) AS block_date,
dexs_pcsx.block_time,
dexs_pcsx.block_number,
dexs_pcsx.token_bought_amount_raw,
dexs_pcsx.token_sold_amount_raw,
dexs_pcsx.token_bought_address,
dexs_pcsx.token_sold_address,
dexs_pcsx.taker,
dexs_pcsx.maker,
dexs_pcsx.project_contract_address,
dexs_pcsx.tx_hash,
dexs_pcsx.evt_index
FROM dexs_pcsx
WHERE token_sold_amount_raw > 0
AND token_bought_amount_raw > 0
AND token_bought_address is not NULL
17 changes: 17 additions & 0 deletions dbt_subprojects/dex/models/trades/base/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1041,3 +1041,20 @@ models:
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('akronswap_base_base_trades_seed')

- name: jojo_base_base_trades
meta:
blockchain: base
sector: dex
project: jojo
contributors: princi
config:
tags: [ 'base', 'dex', 'trades', 'jojo' ]
description: "jojo base base trades"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('jojo_base_base_trades_seed')
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
, ref('infusion_base_base_trades')
, ref('flashliquidity_base_base_trades')
, ref('akronswap_base_base_trades')
, ref('jojo_base_base_trades')
] %}

WITH base_union AS (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{ config(
schema = 'jojo_base',
alias = 'base_trades',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_date', 'blockchain', 'project', 'version', 'tx_hash', 'evt_index']
) }}

WITH token_swaps AS (
SELECT
evt_block_number AS block_number,
CAST(evt_block_time AS timestamp(3) with time zone) AS block_time,
evt_tx_from AS maker,
evt_tx_to AS taker,
payAmount AS token_sold_amount_raw,
receivedAmount AS token_bought_amount_raw,
fromToken AS token_sold_address,
toToken AS token_bought_address,
contract_address AS project_contract_address,
evt_tx_hash AS tx_hash,
evt_index AS evt_index
FROM
{{ source('jojo_base', 'FundingRateArbitrage_evt_Swap') }}
{% if is_incremental() %}
WHERE
{{ incremental_predicate('evt_block_time') }}
{% endif %}
)

SELECT
'base' AS blockchain,
'jojo' AS project,
'1' AS version,
CAST(date_trunc('month', token_swaps.block_time) AS date) AS block_month,
CAST(date_trunc('day', token_swaps.block_time) AS date) AS block_date,
token_swaps.block_time,
token_swaps.block_number,
token_swaps.token_sold_amount_raw,
token_swaps.token_bought_amount_raw,
token_swaps.token_sold_address,
token_swaps.token_bought_address,
token_swaps.maker,
token_swaps.taker,
token_swaps.project_contract_address,
token_swaps.tx_hash,
token_swaps.evt_index
FROM
token_swaps
19 changes: 18 additions & 1 deletion dbt_subprojects/dex/models/trades/sonic/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@ models:
- tx_hash
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('beets_sonic_base_trades_seed')
seed_file: ref('beets_sonic_base_trades_seed')

- name: wagmi_sonic_base_trades
meta:
blockchain: sonic
sector: dex
project: wagmi
contributors: hosuke
config:
tags: ['sonic', 'dex', 'trades', 'wagmi']
description: "wagmi sonic base trades"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('wagmi_sonic_base_trades_seed')
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

{% set base_models = [
ref('beets_sonic_base_trades')
, ref('wagmi_sonic_base_trades')
] %}

WITH base_union AS (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{
config(
schema = 'wagmi_sonic',
alias = 'base_trades',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['tx_hash', 'evt_index'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
)
}}

{{
uniswap_compatible_v3_trades(
blockchain = 'sonic',
project = 'wagmi',
version = '3',
Pair_evt_Swap = source('wagmi_sonic', 'UniswapV3Pool_evt_Swap'),
Factory_evt_PoolCreated = source('wagmi_sonic', 'UniswapV3Factory_evt_PoolCreated')
)
}}
Loading

0 comments on commit 80bacd4

Please sign in to comment.