Skip to content

Commit

Permalink
Merge branch 'main' into otsea-base
Browse files Browse the repository at this point in the history
  • Loading branch information
PatelPrinci authored Jan 23, 2025
2 parents 293d761 + e8ca05d commit badb179
Show file tree
Hide file tree
Showing 33 changed files with 621 additions and 78 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
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')
)
}}
15 changes: 15 additions & 0 deletions dbt_subprojects/dex/seeds/trades/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4746,6 +4746,21 @@ seeds:
block_date: timestamp

- name: camelot_corn_base_trades_seed
config:
column_types:
blockchain: varchar
project: varchar
version: varchar
tx_hash: varbinary
evt_index: uint256
block_number: uint256
token_bought_address: varbinary
token_sold_address: varbinary
token_bought_amount_raw: uint256
token_sold_amount_raw: uint256
block_date: timestamp

- name: wagmi_sonic_base_trades_seed
config:
column_types:
blockchain: varchar
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw
sonic,wagmi,3,2025-01-21,0x8c447cc48a4488870ac0a5a39f42e764a50f159fa9fbadace10a2dca77640f1a,2,0x50c42deacd8fc9773493ed674b675be577f2634b,0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38,4847335,50421632945765830,271700000000000000000
sonic,wagmi,3,2025-01-21,0x38155f722ac19c89b6b9798d11467bcd9e2ec9ac463dbb09ad3e8b95d0e03cdd,8,0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38,0x50c42deacd8fc9773493ed674b675be577f2634b,4848299,2397204077986245906501,450000000000000000
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,39 @@ models:
- *project_contract_address
- *tx_hash
- *evt_index

- name: morpho_base_base_borrow
meta:
blockchain: base
sector: lending
project: Morpho
contributors: 0xDataWolf
config:
tags: ['lending', 'borrow', 'Morpho', 'base']
description: "Morpho borrow transactions on Base"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- transaction_type
- token_address
- tx_hash
- evt_index
- check_lending_base_borrow_seed:
seed_file: ref('morpho_base_base_borrow_seed')
columns:
- *blockchain
- *project
- *version
- *transaction_type
- *token_address
- *borrower
- *on_behalf_of
- *repayer
- *liquidator
- *amount
- *block_month
- *block_time
- *block_number
- *project_contract_address
- *tx_hash
- *evt_index
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
ref('seamlessprotocol_base_base_borrow'),
ref('moonwell_base_base_borrow'),
ref('sonne_finance_base_base_borrow'),
ref('granary_base_base_borrow')
ref('granary_base_base_borrow'),
ref('morpho_base_base_borrow')
]
%}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{{
config(
schema = 'morpho_base',
alias = 'base_borrow',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['transaction_type', 'token_address', 'tx_hash', 'evt_index'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
)
}}

WITH markets AS (
SELECT id
, from_hex(JSON_EXTRACT_SCALAR("marketParams", '$.loanToken')) AS loanToken
, from_hex(JSON_EXTRACT_SCALAR("marketParams", '$.collateralToken')) AS collateralToken
, from_hex(JSON_EXTRACT_SCALAR("marketParams", '$.oracle')) AS oracle
, JSON_EXTRACT_SCALAR("marketParams", '$.irm') AS irm
, JSON_EXTRACT_SCALAR("marketParams", '$.lltv') AS lltv
FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_CreateMarket') }}
)

, base_borrow AS (
SELECT 'borrow' AS transaction_type
, 'variable' AS loan_type
, loanToken AS token_address
, caller AS borrower
, onBehalf AS on_behalf_of
, CAST(NULL AS varbinary) AS repayer
, CAST(NULL AS varbinary) AS liquidator
, CAST(assets AS double) AS amount
, contract_address
, evt_tx_hash
, evt_index
, evt_block_time
, evt_block_number
FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_Borrow') }}
INNER JOIN markets USING (id)
{% if is_incremental() %}
WHERE {{ incremental_predicate('evt_block_time') }}
{% endif %}

UNION ALL

SELECT 'repay' AS transaction_type
, NULL AS loan_type
, loanToken AS token_address
, caller AS borrower
, onBehalf AS on_behalf_of
, caller AS repayer
, cast(null as varbinary) AS liquidator
, -1 * cast(assets AS double) AS amount
, contract_address
, evt_tx_hash
, evt_index
, evt_block_time
, evt_block_number
FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_Repay') }}
INNER JOIN markets USING (id)
{% if is_incremental() %}
WHERE {{ incremental_predicate('evt_block_time') }}
{% endif %}

UNION ALL

select 'borrow_liquidation' AS transaction_type
, null AS loan_type
, loanToken AS token_address
, borrower
, borrower AS on_behalf_of
, caller AS repayer
, caller AS liquidator
, -1 * cast(repaidAssets AS double) AS amount
, contract_address
, evt_tx_hash
, evt_index
, evt_block_time
, evt_block_number
FROM {{ source('morpho_blue_base', 'MorphoBlue_evt_Liquidate') }}
INNER JOIN markets USING (id)
{% if is_incremental() %}
WHERE {{ incremental_predicate('evt_block_time') }}
{% endif %}
)

SELECT 'base' AS blockchain
, 'morpho' AS project
, '1' AS version
, transaction_type
, loan_type
, token_address
, borrower
, on_behalf_of
, repayer
, liquidator
, amount
, CAST(date_trunc('month', evt_block_time) AS date) AS block_month
, evt_block_time AS block_time
, evt_block_number AS block_number
, contract_address AS project_contract_address
, evt_tx_hash AS tx_hash
, evt_index
FROM base_borrow
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,35 @@ models:
- *block_number
- *tx_hash
- *evt_index

- name: morpho_base_base_flashloans
meta:
blockchain: base
sector: lending
project: morpho
contributors: 0xDataWolf
config:
tags: ['lending', 'flashloans', 'morpho', 'base']
description: "Morpho flashloans transactions on Base"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index
- check_lending_base_flashloans_seed:
seed_file: ref('morpho_base_base_flashloans_seed')
columns:
- *blockchain
- *project
- *version
- *recipient
- *amount
- *fee
- *token_address
- *project_contract_address
- *block_month
- *block_time
- *block_number
- *tx_hash
- *evt_index

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
ref('aave_v3_base_base_flashloans'),
ref('seamlessprotocol_base_base_flashloans'),
ref('granary_base_base_flashloans'),
ref('balancer_v2_base_base_flashloans')
ref('balancer_v2_base_base_flashloans'),
ref('morpho_base_base_flashloans')
]
%}

Expand Down
Loading

0 comments on commit badb179

Please sign in to comment.