Skip to content

Commit

Permalink
Merge branch 'main' into chore-add-additional-openocean-fee-wallet-fo…
Browse files Browse the repository at this point in the history
…r-flokibot
  • Loading branch information
whalehunting authored Dec 20, 2024
2 parents 158e39c + 5236549 commit 786ea7c
Show file tree
Hide file tree
Showing 16 changed files with 1,180 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ config
(

schema = 'kyberswap_aggregator_avalanche_c',
alias = 'trades',
partition_by = ['block_month'],
Expand Down Expand Up @@ -36,8 +36,11 @@ WITH meta_router AS
,ARRAY[-1] AS trace_address
FROM
{{ source('kyber_avalanche_c', 'MetaAggregationRouterV2_evt_Swapped') }}
WHERE 0x250f8f7750735e3ab5dc9db3a542f6b71999ed38 not in (dstToken, srcToken)
-- There are 2 weird transactions with this token where the return and spent amounts in the event are not correct
-- these result in inflated volume, so we'll ignore this token in any trades.
{% if is_incremental() %}
WHERE evt_block_time >= date_trunc('day', now() - INTERVAL '7' DAY)
AND evt_block_time >= date_trunc('day', now() - INTERVAL '7' DAY)
{% endif %}
)
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ combined_batch_info as (
on b.evt_tx_hash = t.tx_hash
inner join {{ source('arbitrum', 'transactions') }} tx
on evt_tx_hash = hash
and evt_block_number = block_number
{% if is_incremental() %}
AND {{ incremental_predicate('block_time') }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{{ config(
schema = 'cow_protocol_base',
alias = 'batches',
materialized='incremental',
partition_by = ['block_date'],
unique_key = ['tx_hash'],
on_schema_change='sync_all_columns',
file_format ='delta',
incremental_strategy='merge',
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
post_hook='{{ expose_spells(blockchains = \'["base"]\',
spell_type = "project",
spell_name = "cow_protocol",
contributors = \'["felix"]\') }}'
)
}}

WITH
batch_counts as (
select try_cast(date_trunc('day', s.evt_block_time) as date) as block_date,
s.evt_block_number,
s.evt_block_time,
s.evt_tx_hash,
solver,
name,
sum(
case
when selector != 0x2e1a7d4d -- unwrap
and selector != 0x095ea7b3 -- approval
then 1
else 0
end) as dex_swaps,
sum(case when selector = 0x2e1a7d4d then 1 else 0 end) as unwraps,
sum(case when selector = 0x095ea7b3 then 1 else 0 end) as token_approvals
from {{ source('gnosis_protocol_v2_base', 'GPv2Settlement_evt_Settlement') }} s
left outer join {{ source('gnosis_protocol_v2_base', 'GPv2Settlement_evt_Interaction') }} i
on i.evt_tx_hash = s.evt_tx_hash
{% if is_incremental() %}
AND {{ incremental_predicate('i.evt_block_time') }}
{% endif %}
join {{ ref('cow_protocol_base_solvers') }}
on solver = address
{% if is_incremental() %}
WHERE {{ incremental_predicate('s.evt_block_time') }}
{% endif %}
group by s.evt_block_number, s.evt_block_time, s.evt_tx_hash, solver, name
),

batch_values as (
select
tx_hash,
count(*) as num_trades,
sum(usd_value) as batch_value,
sum(fee_usd) as fee_value,
price as eth_price
from {{ source('cow_protocol_base', 'trades') }}
left outer join {{ source('prices', 'usd') }} as p
on p.contract_address = 0x4200000000000000000000000000000000000006
{% if is_incremental() %}
and {{ incremental_predicate('minute') }}
{% endif %}
and p.minute = date_trunc('minute', block_time)
and blockchain = 'base'
{% if is_incremental() %}
WHERE {{ incremental_predicate('block_time') }}
{% endif %}
group by tx_hash, price
),

combined_batch_info as (
select
b.block_date,
evt_block_number as block_number,
evt_block_time as block_time,
num_trades,
dex_swaps,
batch_value,
solver as solver_address,
evt_tx_hash as tx_hash,
gas_price,
gas_used,
((gas_price / pow(10, 9)) * gas_used * eth_price) / pow(10, 9) as tx_cost_usd,
fee_value,
2 * bytearray_length(data) / 1024 as call_data_size,
unwraps,
token_approvals
from batch_counts b
join batch_values t
on b.evt_tx_hash = t.tx_hash
inner join {{ source('base', 'transactions') }} tx
on evt_tx_hash = hash
and evt_block_number = block_number
{% if is_incremental() %}
AND {{ incremental_predicate('block_time') }}
{% endif %}
where num_trades > 0 --! Exclude Withdraw Batches
)

select * from combined_batch_info
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 2

models:
- name: cow_protocol_base_solvers
meta:
blockchain: base
project: cow_protocol
contributors: felix
config:
tags: ["base", "cow_protocol", "solver"]
description: >
CoW Protocol solvers list on Base Chain
- name: cow_protocol_base_batches
meta:
blockchain: base
project: cow_protocol
contributors: felix
config:
tags: ["base", "cow_protocol", "trades", "dex", "aggregator", "auction"]
description: >
CoW Protocol enriched batches table on Base Chain
data_tests:
- unique:
column_name: tx_hash
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{{ config(
schema = 'cow_protocol_base',
alias='solvers',
post_hook='{{ expose_spells(blockchains = \'["base"]\',
spell_type = "project",
spell_name = "cow_protocol",
contributors = \'["felix"]\') }}'
)}}

WITH
-- Aggregate the solver added and removed events into a single table
-- with true/false for adds/removes respectively
solver_activation_events as (
select solver, evt_block_number, evt_index, True as activated
from {{ source('gnosis_protocol_v2_base', 'GPv2AllowListAuthentication_evt_SolverAdded') }}
union
select solver, evt_block_number, evt_index, False as activated
from {{ source('gnosis_protocol_v2_base', 'GPv2AllowListAuthentication_evt_SolverRemoved') }}
),
-- Sorting by (evt_block_number, evt_index) allows us to pick the most recent activation status of each unique solver
ranked_solver_events as (
select
rank() over (partition by solver order by evt_block_number desc, evt_index desc) as rk,
solver,
evt_block_number,
evt_index,
activated as active
from solver_activation_events
),
registered_solvers as (
select solver, active
from ranked_solver_events
where rk = 1
),
-- Manually inserting environment and name for each "known" solver
known_solver_metadata (address, environment, name) as (
select *
from (
VALUES
(0x8d98057b8c3d6c7cB02f1C1BE7E37D416F2D3e96, 'barn', 'Baseline'),
(0x351DfD19DfA0e3BfD3E7D9B22658C09e66Fd14AD, 'barn', 'Seasolver'),
(0xcE55eD17ddD7ED6E7eC396eaC772959A6D7252EA, 'barn', 'Naive'),
(0x8982b03D56de1F6f173d04A940B20A69F6A59239, 'barn', 'Gnosis_1inch'),
(0x5951400dE8fA58DA26Ab9402D2603ec0bD788273, 'barn', 'Gnosis_ParaSwap'),
(0x147d05987f3008A6C9Ec3E93A4ead430907ac3E1, 'barn', 'Gnosis_0x'),
(0x9451D27C993f7a61096BFC33e0241644a7566F66, 'barn', 'Gnosis_BalancerSOR'),
(0x0AC9287C83C2386A6a0bb27F847Ce59a0034183C, 'barn', 'Laita'),
(0x69d7F96dFD091652f317D0734A5F2B492ACcbE07, 'prod', 'Baseline'),
(0x4cb862E4821fea2dabBD1f0A69c17d52da2A58f6, 'prod', 'Seasolver'),
(0xF401ceF222F1CA2fE84a8C7BFC75A636A4542A74, 'prod', 'Naive'),
(0x8F7f754300B1ccfa37eA25fD48FB059af0F19e12, 'prod', 'Gnosis_1inch'),
(0xe321609c56aD89711EfB69c248ebe94922902F81, 'prod', 'Gnosis_ParaSwap'),
(0xbBcCE072fb1Bd2C096667E257322f47693D3dc96, 'prod', 'Gnosis_0x'),
(0x983aC485620E265730e367B2C7BCBf6Eb9d62A21, 'prod', 'Gnosis_BalancerSOR'),
(0x1A422923290fd16C2ED00ED16B4203cF4bb35d82, 'prod', 'Laita')
) as _
)
-- Combining the metadata with current activation status for final table
select solver as address,
case when environment is not null then environment else 'new' end as environment,
case when name is not null then name else 'Uncatalogued' end as name,
active
from registered_solvers
left outer join known_solver_metadata on solver = address
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,26 @@ FROM
unwraps,
token_approvals
FROM {{ ref('cow_protocol_arbitrum_batches') }}

UNION ALL

SELECT
'base' AS blockchain,
'cow_protocol' AS project,
'1' AS version,
block_date,
block_time,
num_trades,
dex_swaps,
batch_value,
solver_address,
tx_hash,
gas_price,
gas_used,
tx_cost_usd,
fee_value,
call_data_size,
unwraps,
token_approvals
FROM {{ ref('cow_protocol_base_batches') }}
)
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ combined_batch_info as (
on b.evt_tx_hash = t.tx_hash
inner join {{ source('ethereum', 'transactions') }} tx
on evt_tx_hash = hash
and evt_block_number = block_number
{% if is_incremental() %}
AND {{ incremental_predicate('block_time') }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ WITH
-- Find the PoC Query here: https://dune.com/queries/1722419
batch_counts as (
select try_cast(date_trunc('day', s.evt_block_time) as date) as block_date,
s.evt_block_number,
s.evt_block_time,
s.evt_tx_hash,
solver,
Expand All @@ -43,7 +44,7 @@ batch_counts as (
{% if is_incremental() %}
WHERE {{ incremental_predicate('s.evt_block_time') }}
{% endif %}
group by s.evt_tx_hash, solver, s.evt_block_time, name
group by s.evt_block_number, s.evt_tx_hash, solver, s.evt_block_time, name
),

batch_values as (
Expand All @@ -70,6 +71,7 @@ batch_values as (
combined_batch_info as (
select
b.block_date,
evt_block_number as block_number,
evt_block_time as block_time,
num_trades,
dex_swaps,
Expand All @@ -88,6 +90,7 @@ combined_batch_info as (
on b.evt_tx_hash = t.tx_hash
inner join {{ source('gnosis', 'transactions') }} tx
on evt_tx_hash = hash
and evt_block_number = block_number
{% if is_incremental() %}
AND {{ incremental_predicate('tx.block_time') }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,19 @@ FROM
('hon-heroes-of-nft','avalanche_c','HON',0xed2b42d3c9c6e97e11755bb37df29b6375ede3eb,18),
('bawls-bawls-onu','avalanche_c','BAWLS',0x2da8312e2c08b79104c6b18ba26bc7065abec704,18),
('shrap-shrapnel', 'avalanche_c', 'SHRAP', 0xd402298a793948698b9a63311404fbbee944eafd, 18),
('bal-balancer', 'avalanche_c', 'BAL', 0xe15bcb9e0ea69e6ab9fa080c4c4a5632896298c3, 18)
('bal-balancer', 'avalanche_c', 'BAL', 0xe15bcb9e0ea69e6ab9fa080c4c4a5632896298c3, 18),
('ausd-agora-dollar', 'avalanche_c', 'AUSD', 0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a, 6),
('stg-stargatetoken', 'avalanche_c', 'STG', 0x2F6F07CDcf3588944Bf4C42aC74ff24bF56e7590, 18),
--('tus-treasure-under-sea', 'avalanche_c', 'TUS', 0xf693248f96fe03422fea95ac0afbbbc4a8fdd172, 18),
--('cra-crabada', 'avalanche_c', 'CRA', 0xa32608e873f9ddef944b24798db69d80bbb4d1ed, 18),
('gmx-gmx', 'avalanche_c', 'GMX', 0x62edc0692bd897d2295872a9ffcac5425011c661, 18),
('klo-kalao', 'avalanche_c', 'KLO', 0xb27c8941a7df8958a1778c0259f76d1f8b711c35, 18),
('solvbtc-solv-protocol-solvbtc', 'avalanche_c', 'SolvBTC', 0xbc78d84ba0c46dfe32cf2895a19939c86b81a777, 18),
('sb-snowbank', 'avalanche_c', 'SB', 0x7d1232b90d3f809a54eeaeebc639c62df8a8942f, 9),
('euroc-euro-coin', 'avalanche_c', 'EURC', 0xC891EB4cbdEFf6e073e859e987815Ed1505c2ACD, 6),
('renbtc-renbtc', 'avalanche_c', 'renBTC', 0xdbf31df14b66535af65aac99c32e9ea844e14501, 8),
('arena-the-arena', 'avalanche_c', 'ARENA', 0xb8d7710f7d8349a506b75dd184f05777c82dad0c, 18),
('zro-layerzero', 'avalanche_c', 'ZRO', 0x6985884c4392d348587b19cb9eaaf157f13271cd, 18),
('beam-beam-eth', 'avalanche_c', 'BEAM', 0x62d0a8458ed7719fdaf978fe5929c6d342b0bfce, 18)

) as temp (token_id, blockchain, symbol, contract_address, decimals)
12 changes: 11 additions & 1 deletion dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,15 @@ FROM
('alb-alienbase', 'base', 'ALB',0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4, 18),
('clark-coinbase-mascot','base','CLARK',0x5f7373Fa845692b1dD7bfaE576D6c743482bf26a, 18),
('gyd-gyro-dollar','base','GYD',0xca5d8f8a8d49439357d3cf46ca2e720702f132b8, 18),
('virtual-virtual-protocol', 'base', 'VIRTUAL', 0x0b3e328455c4059EEb9e3f84b5543F74E24e7E1b, 18)
('virtual-virtual-protocol', 'base', 'VIRTUAL', 0x0b3e328455c4059EEb9e3f84b5543F74E24e7E1b, 18),
('bomb-fbomb', 'base', 'BOMB', 0x74ccbe53f77b08632ce0cb91d3a545bf6b8e0979, 18),
('play9-play', 'base', 'PLAY', 0x7404ac09adf614603d9c16a7ce85a1101f3514ba, 18),
('champ-super-champs', 'base', 'CHAMP', 0xeb6d78148f001f3aa2f588997c5e102e489ad341, 18),
('euroc-euro-coin', 'base', 'EURC', 0x60a3e35cc302bfa44cb288bc5a4f316fdb1adb42, 6),
('fai-freysa', 'base', 'FAI', 0xb33ff54b9f7242ef1593d2c9bcd8f9df46c77935, 18),
('ogn-origin-protocol', 'base', 'OGN', 0x7002458b1df59eccb57387bc79ffc7c29e22e6f7, 18),
('usdt-tether', 'base', 'USDT', 0xfde4c96c8593536e31f229ea8f37b2ada2699bb2, 6),
('klima-klimadao', 'base', 'KLIMA', 0xdcefd8c8fcc492630b943abcab3429f12ea9fea2, 9),
('yfi-yearnfinance', 'base', 'YFI', 0x9eaf8c1e34f05a589eda6bafdf391cf6ad3cb239, 18)
--('well-moonwell' ,'base', 'WELL', 0xa88594d404727625a9437c3f886c7643872296ae, 18)
) as temp (token_id, blockchain, symbol, contract_address, decimals)
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,8 @@ FROM
('sigma2-sigma', 'ethereum', 'SIGMA', 0x18a8D75F70eAEad79B5A55903D036ce337F623A5, 18),
('mstr-mstr2100', 'ethereum', 'MSTR', 0x42069026EAC8Eee0Fd9b5f7aDFa4f6E6D69a2B39, 9),
('usdl-lift-dollar', 'ethereum', 'USDL', 0xbdC7c08592Ee4aa51D06C27Ee23D5087D65aDbcD, 18),
('usr-resolv-usr', 'ethereum', 'USR', 0x66a1e37c9b0eaddca17d3662d6c05f4decf3e110, 18)
('usr-resolv-usr', 'ethereum', 'USR', 0x66a1e37c9b0eaddca17d3662d6c05f4decf3e110, 18),
('sovrn-sovrun','ethereum', 'SOVRN', 0x031B8d752d73d7Fe9678ACEf26e818280D0646b4, 18)
) as temp (token_id, blockchain, symbol, contract_address, decimals)
where contract_address not in (
-- bad price feeds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@ FROM
('ton-toncoin', null, 'TON', null,null),
('strk-starknet', null, 'STRK', null,null),
('kda-kadena', null, 'KDA', null, null),
('ron-ronin-token', null, 'RON', null, null)
('ron-ronin-token', null, 'RON', null, null),
('hype-hyperliquid', null, 'HYPE', null, null)
) as temp (token_id, blockchain, symbol, contract_address, decimals)
Original file line number Diff line number Diff line change
Expand Up @@ -710,5 +710,10 @@ FROM
('goat-goatseus-maximus', 'solana', 'GOAT', 'CzLSujWBLFsSjncfkh59rUFqvafWcY5tzedWJSuypump', 6),
('fwog-fwog', 'solana', 'FWOG', 'A8C3xuqscfmyLrte3VmTqrAq8kgMASius9AFNANwpump', 6),
('lester-litecoin-mascot', 'solana', 'LESTER', '5z3iCe53hUANTiG8Js8RjHNE2Arjik7L2CXLyr2rpump', 6),
('happy-happycat', 'solana', 'HAPPY', 'HAPPYwgFcjEJDzRtfWE6tiHE9zGdzpNky2FvjPHsvvGZ', 9)
('happy-happycat', 'solana', 'HAPPY', 'HAPPYwgFcjEJDzRtfWE6tiHE9zGdzpNky2FvjPHsvvGZ', 9),
('memesai-memes-ai', 'solana', 'MEMESAI', '39qibQxVzemuZTEvjSB7NePhw9WyyHdQCqP8xmBMpump', 6),
('grift1-orbit', 'solana', 'GRIFT', 'GekTNfm84QfyP2GdAHZ5AgACBRd69aNmgA5FDhZupump', 6),
('fxn-fxn', 'solana', 'FXN', '92cRC6kV5D7TiHX1j56AbkPbffo9jwcXxSDQZ8Mopump',6),
('griffain-test-griffaincom', 'solana', 'GRIFFAIN', 'KENJSUYLASHUMfHyy5o4Hp2FdNqZg1AsUPhfH2kYvEP', 6),
('tank-agenttank', 'solana', 'TANK', 'GAMwtMB6onAvBNBQJCJFuxoaqfPH8uCQ2dewNMVVpump', 6)
) as temp (token_id, blockchain, symbol, contract_address, decimals)
Original file line number Diff line number Diff line change
Expand Up @@ -409,5 +409,6 @@ FROM (VALUES
, (0x5f7373Fa845692b1dD7bfaE576D6c743482bf26a, 'CLARK', 18)
, (0xBAa5CC21fd487B8Fcc2F632f3F4E8D37262a0842, 'MORPHO', 18)
, (0xCA5d8F8a8d49439357d3CF46Ca2e720702F132b8, 'GYD', 18)
, (0xC0D3700000987C99b3C9009069E4f8413fD22330, 'cdxUSD', 18)
, (0xC0D3700000987C99b3C9009069E4f8413fD22330, 'cdxUSD', 18)
, (0xc694a91e6b071bf030a18bd3053a7fe09b6dae69, 'COW', 18)
) AS temp_table (contract_address, symbol, decimals)
Original file line number Diff line number Diff line change
Expand Up @@ -4740,4 +4740,5 @@ FROM (VALUES
, ( 0xa4f6b2cdcb67bf8f48baa459a333d2667aa4b100, 'shezETH', 8)
, ( 0x7F4B66FF703336CfC35b901144614496Ae0b0D27, 'shezUSD', 18)
, ( 0xa7b66dda0d7c7c1e43d3130491216172993d163d, 'EVS', 6)
, ( 0x2371e134e3455e0593363cbf89d3b6cf53740618, 'gtWETH', 18)
) AS temp_table (contract_address, symbol, decimals)
Loading

0 comments on commit 786ea7c

Please sign in to comment.