From 30c9421c9bbd83f7ed83e0642ede5d59ea86c77e Mon Sep 17 00:00:00 2001 From: Demcruise <115721890+Demcruise@users.noreply.github.com> Date: Fri, 20 Sep 2024 21:44:04 +0700 Subject: [PATCH 01/59] Update prices_bnb_tokens.sql (#6780) add COOKIE price token --- dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql b/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql index 95a08b04129..414741581d4 100644 --- a/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql @@ -279,7 +279,8 @@ FROM ('bvsd-bvsd','bnb','BVSD',0x7f9ad7a5854658d984924e868187b2135514fb88, 18), ('coco-coco-coin', 'bnb', 'COCO', 0xf563e86e461de100cfcfd8b65daa542d3d4b0550, 18), ('zeta-zetachain', 'bnb', 'ZETA', 0x0000028a2eb8346cd5c0267856ab7594b7a55308, 18), - ('euri-eurite', 'bnb', 'EURI', 0x9d1a7a3191102e9f900faa10540837ba84dcbae7, 18) + ('euri-eurite', 'bnb', 'EURI', 0x9d1a7a3191102e9f900faa10540837ba84dcbae7, 18), + ('cookie-cookie', 'bnb', 'COOKIE', 0xc0041ef357b183448b235a8ea73ce4e4ec8c265f, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) where contract_address not in ( 0x2ab0e9e4ee70fff1fb9d67031e44f6410170d00e -- bXEN has bad price feed. From 23a7cbd5f797e355b76e44c0419ef0aae3437e19 Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Fri, 20 Sep 2024 10:44:15 -0400 Subject: [PATCH 02/59] add new sky governance token (#6781) --- .../tokens/models/prices/ethereum/prices_ethereum_tokens.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql b/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql index 841939dc332..b5fef3747e1 100644 --- a/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql @@ -1841,7 +1841,8 @@ FROM ('msn-mesonnetwork', 'ethereum', 'MSN', 0xaa247c0d81b83812e1abf8bab078e4540d87e3fb, 18), ('bubble-imaginary-ones', 'ethereum', 'BUBBLE', 0xe9689028ede16c2fdfe3d11855d28f8e3fc452a3, 18), ('zeta-zetachain', 'ethereum', 'ZETA', 0xf091867ec603a6628ed83d274e835539d82e9cc8, 18), - ('euri-eurite', 'ethereum', 'EURI', 0x9d1a7a3191102e9f900faa10540837ba84dcbae7, 18) + ('euri-eurite', 'ethereum', 'EURI', 0x9d1a7a3191102e9f900faa10540837ba84dcbae7, 18), + ('sky-sky', 'ethereum', 'SKY', 0x56072C95FAA701256059aa122697B133aDEd9279, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) where contract_address not in ( -- bad price feeds From 90ebc444cbf1bffe23f0ce9c50873873ee720c42 Mon Sep 17 00:00:00 2001 From: Kofi Date: Fri, 20 Sep 2024 16:28:53 +0100 Subject: [PATCH 03/59] Add cbbtc price info (#6783) --- .../tokens/models/prices/base/prices_base_tokens.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql index 39240512a7c..599e5b9343e 100644 --- a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql @@ -168,5 +168,6 @@ FROM ('tn100x-tn100x','base','TN100X',0x5b5dee44552546ecea05edea01dcd7be7aa6144a, 18), ('rdat-rdatadao','base','RDAT',0x4498cd8ba045e00673402353f5a4347562707e7d, 18), ('usdz-anzen-usdz', 'base', 'USDZ',0x04d5ddf5f3a8939889f11e97f8c4bb48317f1938, 18), - ('moxie-moxie', 'base', 'MOXIE',0x8C9037D1Ef5c6D1f6816278C7AAF5491d24CD527, 18) + ('moxie-moxie', 'base', 'MOXIE',0x8C9037D1Ef5c6D1f6816278C7AAF5491d24CD527, 18), + ('cbbtc-coinbase-wrapped-btc', 'base', 'cbBTC',0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf, 8) ) as temp (token_id, blockchain, symbol, contract_address, decimals) From 68e43bac4dab737a4bda9f5b696c2b742c5beaaa Mon Sep 17 00:00:00 2001 From: Rantum Date: Fri, 20 Sep 2024 09:01:08 -0700 Subject: [PATCH 04/59] add blast & mantle nft transfers (#6772) * add blast nft transfers * add blast transfers file * base_txns - not blast_txns * remove correction to linea_Transfers in schema for runtime improvmeents * remove nft_transfers changes * add mantle nft, fix blockchain value in linea schema --- .../nft/models/_sector/transfers/_schema.yml | 46 ++++++++++++++++++- .../transfers/chains/nft_blast_transfers.sql | 20 ++++++++ .../transfers/chains/nft_mantle_transfers.sql | 24 ++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 dbt_subprojects/nft/models/_sector/transfers/chains/nft_blast_transfers.sql create mode 100644 dbt_subprojects/nft/models/_sector/transfers/chains/nft_mantle_transfers.sql diff --git a/dbt_subprojects/nft/models/_sector/transfers/_schema.yml b/dbt_subprojects/nft/models/_sector/transfers/_schema.yml index 7000d0828b7..4b2fb972b35 100644 --- a/dbt_subprojects/nft/models/_sector/transfers/_schema.yml +++ b/dbt_subprojects/nft/models/_sector/transfers/_schema.yml @@ -378,7 +378,7 @@ models: - name: nft_linea_transfers meta: - blockchain: scroll + blockchain: linea sector: nft contributors: couralex config: @@ -397,3 +397,47 @@ models: - *token_standard - *transfer_type - *unique_transfer_id + + - name: nft_blast_transfers + meta: + blockchain: blast + sector: nft + contributors: rantum + config: + tags: [ 'nft', 'transfers' ] + description: > + NFT transfers + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - token_id + - amount + columns: + # only listing columns that have tests here for simplicity + - *token_standard + - *transfer_type + - *unique_transfer_id + + - name: nft_mantle_transfers + meta: + blockchain: mantle + sector: nft + contributors: rantum + config: + tags: [ 'nft', 'transfers' ] + description: > + NFT transfers + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - token_id + - amount + columns: + # only listing columns that have tests here for simplicity + - *token_standard + - *transfer_type + - *unique_transfer_id diff --git a/dbt_subprojects/nft/models/_sector/transfers/chains/nft_blast_transfers.sql b/dbt_subprojects/nft/models/_sector/transfers/chains/nft_blast_transfers.sql new file mode 100644 index 00000000000..4ba636a85ff --- /dev/null +++ b/dbt_subprojects/nft/models/_sector/transfers/chains/nft_blast_transfers.sql @@ -0,0 +1,20 @@ +{{ config( + + schema = 'nft_blast', + alias = 'transfers', + partition_by=['block_month'], + materialized='incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_hash', 'evt_index', 'token_id', 'amount'] +) +}} + +{{nft_transfers( + blockchain='blast' + , base_transactions = source('blast','transactions') + , erc721_transfers = source('erc721_blast','evt_transfer') + , erc1155_single = source('erc1155_blast','evt_transfersingle') + , erc1155_batch = source('erc1155_blast', 'evt_transferbatch') +)}} diff --git a/dbt_subprojects/nft/models/_sector/transfers/chains/nft_mantle_transfers.sql b/dbt_subprojects/nft/models/_sector/transfers/chains/nft_mantle_transfers.sql new file mode 100644 index 00000000000..2e8a287941c --- /dev/null +++ b/dbt_subprojects/nft/models/_sector/transfers/chains/nft_mantle_transfers.sql @@ -0,0 +1,24 @@ +{{ + config( + schema="nft_mantle", + alias="transfers", + partition_by=["block_month"], + materialized="incremental", + file_format="delta", + incremental_strategy="merge", + incremental_predicates=[ + incremental_predicate("DBT_INTERNAL_DEST.block_time") + ], + unique_key=["tx_hash", "evt_index", "token_id", "amount"], + ) +}} + +{{ + nft_transfers( + blockchain="mantle", + base_transactions=source("mantle", "transactions"), + erc721_transfers=source("erc721_mantle", "evt_transfer"), + erc1155_single=source("erc1155_mantle", "evt_transfersingle"), + erc1155_batch=source("erc1155_mantle", "evt_transferbatch"), + ) +}} From a869418f2dd614b1dc7e869082654526aeb99bb6 Mon Sep 17 00:00:00 2001 From: max-morrow Date: Fri, 20 Sep 2024 19:01:28 +0300 Subject: [PATCH 05/59] 1inch-U41: fixes & redesign (#6771) * fixed & optimised decimals logic * redesigned to submitted contracts - created escrow config factories macro - transferred lop_macro to submitted contracts - transferred escrow_dst_creations to submitted contracts - added necessary sources * added addition columns to the src <> dst join --- .../CC/oneinch_escrow_cfg_factories_macro.sql | 39 ++++++++ .../CC/oneinch_escrow_dst_creations_macro.sql | 87 ------------------ .../oneinch/LOP/oneinch_lop_macro.sql | 91 ++++++++++++------- .../oneinch/oneinch_escrow_dst_creations.sql | 82 ++++++++++++++++- .../_projects/oneinch/oneinch_swaps.sql | 34 +++---- .../arbitrum/oneinch_arbitrum_sources.yml | 2 + .../oneinch_avalanche_c_sources.yml | 2 + sources/oneinch/base/oneinch_base_sources.yml | 2 + sources/oneinch/bnb/oneinch_bnb_sources.yml | 2 + .../ethereum/oneinch_ethereum_sources.yml | 2 + .../oneinch/gnosis/oneinch_gnosis_sources.yml | 2 + .../optimism/oneinch_optimism_sources.yml | 2 + .../polygon/oneinch_polygon_sources.yml | 2 + 13 files changed, 206 insertions(+), 143 deletions(-) create mode 100644 dbt_subprojects/dex/macros/models/_project/oneinch/CC/oneinch_escrow_cfg_factories_macro.sql delete mode 100644 dbt_subprojects/dex/macros/models/_project/oneinch/CC/oneinch_escrow_dst_creations_macro.sql diff --git a/dbt_subprojects/dex/macros/models/_project/oneinch/CC/oneinch_escrow_cfg_factories_macro.sql b/dbt_subprojects/dex/macros/models/_project/oneinch/CC/oneinch_escrow_cfg_factories_macro.sql new file mode 100644 index 00000000000..c89daee18ed --- /dev/null +++ b/dbt_subprojects/dex/macros/models/_project/oneinch/CC/oneinch_escrow_cfg_factories_macro.sql @@ -0,0 +1,39 @@ +{% macro oneinch_escrow_cfg_factories_macro() %} + +-- CREATION IMMUTABLES SAMPLES +{% + set immutables = { + "v1": { + "order_hash": "from_hex(creation_map['orderHash'])", + "hashlock": "from_hex(creation_map['hashlock'])", + "maker": "substr(cast(cast(creation_map['maker'] as uint256) as varbinary), 13)", + "taker": "substr(cast(cast(creation_map['taker'] as uint256) as varbinary), 13)", + "token": "substr(cast(cast(creation_map['token'] as uint256) as varbinary), 13)", + "amount": "cast(creation_map['amount'] as uint256)", + "safety_deposit": "cast(creation_map['safetyDeposit'] as uint256)", + "timelocks": "cast(cast(creation_map['timelocks'] as uint256) as varbinary)", + }, + } +%} + +-- CONTRACTS CONFIG +{% + set contracts = { + "EscrowFactoryV1": { + "version": "1", + "blockchains": ["ethereum", "bnb", "polygon", "arbitrum", "avalanche_c", "gnosis", "optimism", "base"], + "start": "2024-08-20", + "dst_creation": dict(immutables["v1"], method="createDstEscrow"), + "src_created": dict(immutables["v1"], event="SrcEscrowCreated", + dst_maker="substr(cast(cast(complement_map['maker'] as uint256) as varbinary), 13)", + dst_token="substr(cast(cast(complement_map['token'] as uint256) as varbinary), 13)", + dst_amount="cast(complement_map['amount'] as uint256)", + dst_chain_id="cast(complement_map['chainId'] as uint256)", + ), + }, + } +%} + +{{ return(contracts) }} + +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/macros/models/_project/oneinch/CC/oneinch_escrow_dst_creations_macro.sql b/dbt_subprojects/dex/macros/models/_project/oneinch/CC/oneinch_escrow_dst_creations_macro.sql deleted file mode 100644 index bc7fa58b1f3..00000000000 --- a/dbt_subprojects/dex/macros/models/_project/oneinch/CC/oneinch_escrow_dst_creations_macro.sql +++ /dev/null @@ -1,87 +0,0 @@ -{% macro oneinch_escrow_dst_creations_macro(blockchain) %} - -{% set date_from = '2024-08-20' %} - -with - -factories as ( - select factory - from ({{ oneinch_blockchain_macro(blockchain) }}), unnest(escrow_factory_addresses) as f(factory) -) - -, createDstEscrow as ( - select - * - , substr(keccak(concat( - 0xff - , factory - , keccak(concat( - order_hash - , hashlock - , lpad(maker, 32, 0x00) - , lpad(taker, 32, 0x00) - , lpad(token, 32, 0x00) - , cast(amount as varbinary) - , cast(safety_deposit as varbinary) - , to_big_endian_32(cast(to_unixtime(block_time) as int)) - , substr(timelocks, 5) -- replace the first 4 bytes with current block time - )) - , keccak(concat( - 0x3d602d80600a3d3981f3363d3d373d3d3d363d73 - , substr(keccak(concat(0xd6, 0x94, factory, 0x03)), 13) -- dst nonce = 3 - , 0x5af43d82803e903d91602b57fd5bf3) - ) - )), 13) as escrow - from ( - -- will be converted to submitted contracts - select - '{{ blockchain }}' as blockchain - , block_number - , block_time - , tx_hash - , trace_address - , "to" as factory - , substr(input, 4 + 32*0 + 1, 32) as order_hash - , substr(input, 4 + 32*1 + 1, 32) as hashlock - , substr(input, 4 + 32*2 + 12 + 1, 20) as maker - , substr(input, 4 + 32*3 + 12 + 1, 20) as taker - , substr(input, 4 + 32*4 + 12 + 1, 20) as token - , bytearray_to_uint256(substr(input, 4 + 32*5 + 1, 32)) as amount - , bytearray_to_uint256(substr(input, 4 + 32*6 + 1, 32)) as safety_deposit - , substr(input, 4 + 32*7 + 1, 32) as timelocks - , success as call_success - from {{ source(blockchain, 'traces') }} - where - starts_with(input, 0xdea024e4) -- createDstEscrow - and "to" in (select factory from factories) - {% if is_incremental() %} - and {{ incremental_predicate('block_time') }} - {% else %} - and block_time > greatest(timestamp '{{ date_from }}', timestamp {{ oneinch_easy_date() }}) - {% endif %} - ) -) - --- output -- - -select - blockchain - , block_number - , block_time - , tx_hash - , trace_address - , factory - , escrow - , order_hash - , hashlock - , maker - , taker - , token - , amount - , safety_deposit - , timelocks - , call_success - , date_trunc('month', block_time) as block_month -from createDstEscrow - -{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/macros/models/_project/oneinch/LOP/oneinch_lop_macro.sql b/dbt_subprojects/dex/macros/models/_project/oneinch/LOP/oneinch_lop_macro.sql index f4e13b880ed..535b0483490 100644 --- a/dbt_subprojects/dex/macros/models/_project/oneinch/LOP/oneinch_lop_macro.sql +++ b/dbt_subprojects/dex/macros/models/_project/oneinch/LOP/oneinch_lop_macro.sql @@ -74,36 +74,58 @@ orders as ( {% endfor %} ) --- will be converted to submitted contracts , SrcEscrowCreated as ( - with - - factories as ( - select factory - from ({{ oneinch_blockchain_macro(blockchain) }}), unnest(escrow_factory_addresses) as f(factory) - ) - - select - block_number - , tx_hash - , contract_address as factory - , substr(data, 32*0 + 1, 32) as order_hash - , substr(data, 32*1 + 1, 32) as hashlock - , substr(data, 32*2 + 12 + 1, 20) as maker - , substr(data, 32*3 + 12 + 1, 20) as taker - , substr(data, 32*4 + 12 + 1, 20) as token - , bytearray_to_uint256(substr(data, 32*5 + 1, 32)) as amount - , bytearray_to_uint256(substr(data, 32*6 + 1, 32)) as safety_deposit - , substr(data, 32*7 + 1, 32) as timelocks - from {{ source(blockchain, 'logs') }} - where - contract_address in (select factory from factories) - and topic0 = 0x0e534c62f0afd2fa0f0fa71198e8aa2d549f24daf2bb47de0d5486c7ce9288ca - {% if is_incremental() %} - and {{ incremental_predicate('block_time') }} - {% else %} - and block_time > timestamp '2024-08-20' - {% endif %} + {% for factory, factory_data in oneinch_escrow_cfg_factories_macro().items() %} + {% if blockchain in factory_data.blockchains %} + select + evt_block_number as block_number + , evt_tx_hash as tx_hash + , contract_address as factory + , {{ factory_data.src_created.get("order_hash", "null") }} as order_hash + , {{ factory_data.src_created.get("hashlock", "null") }} as hashlock + , {{ factory_data.src_created.get("maker", "null") }} as maker + , {{ factory_data.src_created.get("taker", "null") }} as taker + , {{ factory_data.src_created.get("token", "null") }} as token + , {{ factory_data.src_created.get("amount", "null") }} as amount + , {{ factory_data.src_created.get("safety_deposit", "null") }} as safety_deposit + , {{ factory_data.src_created.get("timelocks", "null") }} as timelocks + , {{ factory_data.src_created.get("dst_maker", "cast(null as varbinary)") }} as dst_maker + , {{ factory_data.src_created.get("dst_token", "cast(null as varbinary)") }} as dst_token + , {{ factory_data.src_created.get("dst_amount", "null") }} as dst_amount + , {{ factory_data.src_created.get("dst_chain_id", "null") }} as dst_chain_id + from ( + select + * + , cast(json_parse({{ factory_data.src_created.get("srcImmutables", '"srcImmutables"') }}) as map(varchar, varchar)) as creation_map + , cast(json_parse({{ factory_data.src_created.get("dstImmutablesComplement", '"dstImmutablesComplement"') }}) as map(varchar, varchar)) as complement_map + from {{ source('oneinch_' + blockchain, factory + '_evt_' + factory_data.src_created.event) }} + {% if is_incremental() %} + where {{ incremental_predicate('evt_block_time') }} + {% else %} + where evt_block_time >= greatest(timestamp '{{ factory_data['start'] }}', timestamp {{ oneinch_easy_date() }}) + {% endif %} + ) + {% else %} + select + null as block_number + , cast(null as varbinary) as tx_hash + , cast(null as varbinary) as factory + , cast(null as varbinary) as order_hash + , cast(null as varbinary) as hashlock + , cast(null as varbinary) as maker + , cast(null as varbinary) as taker + , cast(null as varbinary) as token + , null as amount + , null as safety_deposit + , cast(null as varbinary) as timelocks + , cast(null as varbinary) as dst_maker + , cast(null as varbinary) as dst_token + , null as dst_amount + , null as dst_chain_id + where false + {% endif %} + {% if not loop.last %} union all {% endif %} + {% endfor %} ) , calculations as ( @@ -148,7 +170,11 @@ orders as ( , 0x5af43d82803e903d91602b57fd5bf3) ) )), 13)) as src_escrow - , row_number() over(partition by hashlock order by orders.block_number, orders.tx_hash, call_trace_address) as hashlockNum + , dst_maker + , dst_token + , dst_amount + , dst_chain_id + , row_number() over(partition by hashlock, dst_maker, dst_token, dst_amount, dst_chain_id order by orders.block_number, orders.tx_hash, call_trace_address) as hashlockNum from orders join ({{ oneinch_blockchain_macro(blockchain) }}) on true left join SrcEscrowCreated on @@ -165,6 +191,7 @@ orders as ( , dst as ( select blockchain as dst_blockchain + , chain_id as dst_chain_id , block_number as dst_block_number , block_time as dst_block_time , tx_hash as dst_tx_hash @@ -180,7 +207,7 @@ orders as ( , timelocks , call_success as dst_creation_call_success , wrapped_native_token_address as dst_wrapper - , row_number() over(partition by hashlock order by block_number, tx_hash, trace_address) as hashlockNum + , row_number() over(partition by hashlock, maker, token, amount, chain_id order by block_number, tx_hash, trace_address) as hashlockNum from {{ ref('oneinch_escrow_dst_creations') }} join {{ ref('oneinch_blockchains') }} using(blockchain) {% if is_incremental() %} @@ -250,6 +277,6 @@ from ({{ , columns = ['from', 'to', 'success', 'nonce', 'gas_price', 'priority_fee_per_gas', 'gas_used', 'index'] ) }}) as orders -left join dst using(hashlock, hashlockNum) +left join dst using(hashlock, dst_maker, dst_token, dst_amount, dst_chain_id, hashlockNum) {% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/oneinch/oneinch_escrow_dst_creations.sql b/dbt_subprojects/dex/models/_projects/oneinch/oneinch_escrow_dst_creations.sql index fbb2f6a2efd..5293fd66259 100644 --- a/dbt_subprojects/dex/models/_projects/oneinch/oneinch_escrow_dst_creations.sql +++ b/dbt_subprojects/dex/models/_projects/oneinch/oneinch_escrow_dst_creations.sql @@ -11,9 +11,85 @@ ) }} +{% set date_from = '2024-08-20' %} +with -{% for blockchain in oneinch_exposed_blockchains_list() %} - select * from ({{ oneinch_escrow_dst_creations_macro(blockchain) }}) +createDstEscrow as ({% for factory, factory_data in oneinch_escrow_cfg_factories_macro().items() %} + select * from ({% for blockchain in factory_data.blockchains %} + select + '{{ blockchain }}' as blockchain + , call_block_number as block_number + , call_block_time as block_time + , call_tx_hash as tx_hash + , call_trace_address as trace_address + , contract_address as factory + , {{ factory_data.dst_creation.get("order_hash", "null") }} as order_hash + , {{ factory_data.dst_creation.get("hashlock", "null") }} as hashlock + , {{ factory_data.dst_creation.get("maker", "null") }} as maker + , {{ factory_data.dst_creation.get("taker", "null") }} as taker + , {{ factory_data.dst_creation.get("token", "null") }} as token + , {{ factory_data.dst_creation.get("amount", "null") }} as amount + , {{ factory_data.dst_creation.get("safety_deposit", "null") }} as safety_deposit + , {{ factory_data.dst_creation.get("timelocks", "null") }} as timelocks + , call_success + from ( + select *, cast(json_parse({{ factory_data.dst_creation.get("dstImmutables", '"dstImmutables"') }}) as map(varchar, varchar)) as creation_map + from {{ source('oneinch_' + blockchain, factory + '_call_' + factory_data.dst_creation.method) }} + {% if is_incremental() %} + where {{ incremental_predicate('call_block_time') }} + {% else %} + where call_block_time >= greatest(timestamp '{{ factory_data['start'] }}', timestamp {{ oneinch_easy_date() }}) + {% endif %} + ) + {% if not loop.last %} union all {% endif %} + {% endfor %}) {% if not loop.last %} union all {% endif %} -{% endfor %} \ No newline at end of file +{% endfor %}) + +, calculations as ( + select + * + , substr(keccak(concat( + 0xff + , factory + , keccak(concat( + order_hash + , hashlock + , lpad(maker, 32, 0x00) + , lpad(taker, 32, 0x00) + , lpad(token, 32, 0x00) + , cast(amount as varbinary) + , cast(safety_deposit as varbinary) + , to_big_endian_32(cast(to_unixtime(block_time) as int)) + , substr(timelocks, 5) -- replace the first 4 bytes with current block time + )) + , keccak(concat( + 0x3d602d80600a3d3981f3363d3d373d3d3d363d73 + , substr(keccak(concat(0xd6, 0x94, factory, 0x03)), 13) -- dst nonce = 3 + , 0x5af43d82803e903d91602b57fd5bf3) + ) + )), 13) as escrow + from createDstEscrow +) +-- output -- + +select + blockchain + , block_number + , block_time + , tx_hash + , trace_address + , factory + , escrow + , order_hash + , hashlock + , maker + , taker + , token + , amount + , safety_deposit + , timelocks + , call_success + , date_trunc('month', block_time) as block_month +from calculations \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/oneinch/oneinch_swaps.sql b/dbt_subprojects/dex/models/_projects/oneinch/oneinch_swaps.sql index 8fc1e2cad53..f47c3a226a5 100644 --- a/dbt_subprojects/dex/models/_projects/oneinch/oneinch_swaps.sql +++ b/dbt_subprojects/dex/models/_projects/oneinch/oneinch_swaps.sql @@ -77,6 +77,7 @@ tokens as ( , contract_address , minute , price + , decimals , symbol from {{ source('prices', 'usd') }} {% if is_incremental() %} @@ -84,14 +85,6 @@ tokens as ( {% endif %} ) -, decimals_cte as ( - select - blockchain as transfer_blockchain - , contract_address - , decimals - from {{ source('tokens', 'erc20') }} -) - , calls as ( select * @@ -153,7 +146,7 @@ tokens as ( {% set src_condition = 'contract_address = _src_token_address' %} {% set dst_condition = 'contract_address = _dst_token_address' %} {% set symbol = 'coalesce(symbol, token_symbol)' %} -{% set decimals = 'coalesce(decimals, token_decimals)' %} +{% set decimals = 'coalesce(token_decimals, decimals)' %} , amounts as ( select @@ -179,29 +172,29 @@ tokens as ( , max(amount) filter(where {{ src_condition }} and amount <= src_token_amount) as _src_token_amount_true -- take only src token amounts less than in the call , max(amount) filter(where {{ dst_condition }} and amount <= dst_token_amount) as _dst_token_amount_true -- take only dst token amounts less than in the call - , max(amount * price / pow(10, decimals)) filter(where {{ src_condition }} and amount <= src_token_amount or {{ dst_condition }} and amount <= dst_token_amount) as sources_amount_usd - , max(amount * price / pow(10, decimals)) as transfers_amount_usd + , max(amount * price / pow(10, {{ decimals }})) filter(where {{ src_condition }} and amount <= src_token_amount or {{ dst_condition }} and amount <= dst_token_amount) as sources_amount_usd + , max(amount * price / pow(10, {{ decimals }})) as transfers_amount_usd -- src $ amount from user - , sum(amount * if(user = transfer_from, price, -price) / pow(10, decimals)) filter(where {{ src_condition }} and user in (transfer_from, transfer_to)) as _amount_usd_from_user + , sum(amount * if(user = transfer_from, price, -price) / pow(10, {{ decimals }})) filter(where {{ src_condition }} and user in (transfer_from, transfer_to)) as _amount_usd_from_user -- dst $ amount to user - , sum(amount * if(user = transfer_to, price, -price) / pow(10, decimals)) filter(where {{ dst_condition }} and user in (transfer_from, transfer_to)) as _amount_usd_to_user + , sum(amount * if(user = transfer_to, price, -price) / pow(10, {{ decimals }})) filter(where {{ dst_condition }} and user in (transfer_from, transfer_to)) as _amount_usd_to_user -- dst $ amount to receiver - , sum(amount * if(receiver = transfer_to, price, -price) / pow(10, decimals)) filter(where {{ dst_condition }} and receiver in (transfer_from, transfer_to)) as _amount_usd_to_receiver + , sum(amount * if(receiver = transfer_to, price, -price) / pow(10, {{ decimals }})) filter(where {{ dst_condition }} and receiver in (transfer_from, transfer_to)) as _amount_usd_to_receiver -- escrow results , sum(amount) filter(where result_escrow = src_escrow and result_method = 'withdraw') as src_withdraw_amount , sum(amount) filter(where result_escrow = src_escrow and result_method = 'cancel') as src_cancel_amount , sum(amount) filter(where result_escrow = src_escrow and result_method = 'rescueFunds') as src_rescue_amount - , sum(amount * price / pow(10, decimals)) filter(where result_escrow = src_escrow and result_method = 'withdraw') as src_withdraw_amount_usd - , sum(amount * price / pow(10, decimals)) filter(where result_escrow = src_escrow and result_method = 'cancel') as src_cancel_amount_usd - , sum(amount * price / pow(10, decimals)) filter(where result_escrow = src_escrow and result_method = 'rescueFunds') as src_rescue_amount_usd + , sum(amount * price / pow(10, {{ decimals }})) filter(where result_escrow = src_escrow and result_method = 'withdraw') as src_withdraw_amount_usd + , sum(amount * price / pow(10, {{ decimals }})) filter(where result_escrow = src_escrow and result_method = 'cancel') as src_cancel_amount_usd + , sum(amount * price / pow(10, {{ decimals }})) filter(where result_escrow = src_escrow and result_method = 'rescueFunds') as src_rescue_amount_usd , sum(amount) filter(where result_escrow = dst_escrow and result_method = 'withdraw') as dst_withdraw_amount , sum(amount) filter(where result_escrow = dst_escrow and result_method = 'cancel') as dst_cancel_amount , sum(amount) filter(where result_escrow = dst_escrow and result_method = 'rescueFunds') as dst_rescue_amount - , sum(amount * price / pow(10, decimals)) filter(where result_escrow = dst_escrow and result_method = 'withdraw') as dst_withdraw_amount_usd - , sum(amount * price / pow(10, decimals)) filter(where result_escrow = dst_escrow and result_method = 'cancel') as dst_cancel_amount_usd - , sum(amount * price / pow(10, decimals)) filter(where result_escrow = dst_escrow and result_method = 'rescueFunds') as dst_rescue_amount_usd + , sum(amount * price / pow(10, {{ decimals }})) filter(where result_escrow = dst_escrow and result_method = 'withdraw') as dst_withdraw_amount_usd + , sum(amount * price / pow(10, {{ decimals }})) filter(where result_escrow = dst_escrow and result_method = 'cancel') as dst_cancel_amount_usd + , sum(amount * price / pow(10, {{ decimals }})) filter(where result_escrow = dst_escrow and result_method = 'rescueFunds') as dst_rescue_amount_usd , count(distinct (contract_address, transfer_native)) as tokens -- count distinct tokens in transfers , count(*) as transfers -- count transfers @@ -213,7 +206,6 @@ tokens as ( {% endif %} ) using(blockchain, block_number, tx_hash, call_trace_address) -- block_number is needed for performance left join prices using(transfer_blockchain, contract_address, minute) - left join decimals_cte using(transfer_blockchain, contract_address) left join tokens using(transfer_blockchain, contract_address) group by 1, 2, 3, 4, 5 ) diff --git a/sources/oneinch/arbitrum/oneinch_arbitrum_sources.yml b/sources/oneinch/arbitrum/oneinch_arbitrum_sources.yml index 6675acccf30..1873950a396 100644 --- a/sources/oneinch/arbitrum/oneinch_arbitrum_sources.yml +++ b/sources/oneinch/arbitrum/oneinch_arbitrum_sources.yml @@ -64,5 +64,7 @@ sources: - name: AggregationRouterV6_call_fillOrderArgs - name: AggregationRouterV6_call_fillContractOrder - name: AggregationRouterV6_call_fillContractOrderArgs + - name: EscrowFactoryV1_call_createDstEscrow + - name: EscrowFactoryV1_evt_SrcEscrowCreated - name: lop - name: ar \ No newline at end of file diff --git a/sources/oneinch/avalanche_c/oneinch_avalanche_c_sources.yml b/sources/oneinch/avalanche_c/oneinch_avalanche_c_sources.yml index f7c820a652b..38f278b0daa 100644 --- a/sources/oneinch/avalanche_c/oneinch_avalanche_c_sources.yml +++ b/sources/oneinch/avalanche_c/oneinch_avalanche_c_sources.yml @@ -57,5 +57,7 @@ sources: - name: AggregationRouterV6_call_fillOrderArgs - name: AggregationRouterV6_call_fillContractOrder - name: AggregationRouterV6_call_fillContractOrderArgs + - name: EscrowFactoryV1_call_createDstEscrow + - name: EscrowFactoryV1_evt_SrcEscrowCreated - name: lop - name: ar \ No newline at end of file diff --git a/sources/oneinch/base/oneinch_base_sources.yml b/sources/oneinch/base/oneinch_base_sources.yml index 22dd420bd43..6309e59ba21 100644 --- a/sources/oneinch/base/oneinch_base_sources.yml +++ b/sources/oneinch/base/oneinch_base_sources.yml @@ -39,5 +39,7 @@ sources: - name: AggregationRouterV6_call_fillOrderArgs - name: AggregationRouterV6_call_fillContractOrder - name: AggregationRouterV6_call_fillContractOrderArgs + - name: EscrowFactoryV1_call_createDstEscrow + - name: EscrowFactoryV1_evt_SrcEscrowCreated - name: lop - name: ar \ No newline at end of file diff --git a/sources/oneinch/bnb/oneinch_bnb_sources.yml b/sources/oneinch/bnb/oneinch_bnb_sources.yml index 1b91847d046..8f608659113 100644 --- a/sources/oneinch/bnb/oneinch_bnb_sources.yml +++ b/sources/oneinch/bnb/oneinch_bnb_sources.yml @@ -68,5 +68,7 @@ sources: - name: AggregationRouterV6_call_fillOrderArgs - name: AggregationRouterV6_call_fillContractOrder - name: AggregationRouterV6_call_fillContractOrderArgs + - name: EscrowFactoryV1_call_createDstEscrow + - name: EscrowFactoryV1_evt_SrcEscrowCreated - name: lop - name: ar \ No newline at end of file diff --git a/sources/oneinch/ethereum/oneinch_ethereum_sources.yml b/sources/oneinch/ethereum/oneinch_ethereum_sources.yml index 725749da6bc..f8581952947 100644 --- a/sources/oneinch/ethereum/oneinch_ethereum_sources.yml +++ b/sources/oneinch/ethereum/oneinch_ethereum_sources.yml @@ -83,6 +83,8 @@ sources: - name: AggregationRouterV6_call_fillOrderArgs - name: AggregationRouterV6_call_fillContractOrder - name: AggregationRouterV6_call_fillContractOrderArgs + - name: EscrowFactoryV1_call_createDstEscrow + - name: EscrowFactoryV1_evt_SrcEscrowCreated - name: lop - name: ar diff --git a/sources/oneinch/gnosis/oneinch_gnosis_sources.yml b/sources/oneinch/gnosis/oneinch_gnosis_sources.yml index e62d7fc4ea9..8b886fe3f49 100644 --- a/sources/oneinch/gnosis/oneinch_gnosis_sources.yml +++ b/sources/oneinch/gnosis/oneinch_gnosis_sources.yml @@ -57,5 +57,7 @@ sources: - name: AggregationRouterV6_call_fillOrderArgs - name: AggregationRouterV6_call_fillContractOrder - name: AggregationRouterV6_call_fillContractOrderArgs + - name: EscrowFactoryV1_call_createDstEscrow + - name: EscrowFactoryV1_evt_SrcEscrowCreated - name: lop - name: ar \ No newline at end of file diff --git a/sources/oneinch/optimism/oneinch_optimism_sources.yml b/sources/oneinch/optimism/oneinch_optimism_sources.yml index 9f9f554174c..170f343992b 100644 --- a/sources/oneinch/optimism/oneinch_optimism_sources.yml +++ b/sources/oneinch/optimism/oneinch_optimism_sources.yml @@ -64,5 +64,7 @@ sources: - name: AggregationRouterV6_call_fillOrderArgs - name: AggregationRouterV6_call_fillContractOrder - name: AggregationRouterV6_call_fillContractOrderArgs + - name: EscrowFactoryV1_call_createDstEscrow + - name: EscrowFactoryV1_evt_SrcEscrowCreated - name: lop - name: ar \ No newline at end of file diff --git a/sources/oneinch/polygon/oneinch_polygon_sources.yml b/sources/oneinch/polygon/oneinch_polygon_sources.yml index 525dee8d1d4..c8bb04b5284 100644 --- a/sources/oneinch/polygon/oneinch_polygon_sources.yml +++ b/sources/oneinch/polygon/oneinch_polygon_sources.yml @@ -65,5 +65,7 @@ sources: - name: AggregationRouterV6_call_fillOrderArgs - name: AggregationRouterV6_call_fillContractOrder - name: AggregationRouterV6_call_fillContractOrderArgs + - name: EscrowFactoryV1_call_createDstEscrow + - name: EscrowFactoryV1_evt_SrcEscrowCreated - name: lop - name: ar \ No newline at end of file From 3b75fac4c982cc9c0c201d48bdf745a01897aafe Mon Sep 17 00:00:00 2001 From: max-morrow Date: Fri, 20 Sep 2024 19:01:53 +0300 Subject: [PATCH 06/59] added columns to project_orders linage (#6779) added tx_from & tx_to --- .../project/oneinch/project/oneinch_project_orders_macro.sql | 4 ++++ .../oneinch/project/oneinch_project_orders_raw_logs_macro.sql | 2 ++ 2 files changed, 6 insertions(+) diff --git a/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_orders_macro.sql b/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_orders_macro.sql index 38baf0dec05..b92475b80bf 100644 --- a/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_orders_macro.sql +++ b/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_orders_macro.sql @@ -16,6 +16,8 @@ logs as ( , block_number , block_time , tx_hash + , tx_from + , tx_to , index , contract_address , topic0 @@ -250,6 +252,8 @@ select , block_number , block_time , tx_hash + , tx_from + , tx_to , tx_success , call_from , call_to diff --git a/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_orders_raw_logs_macro.sql b/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_orders_raw_logs_macro.sql index 3f0cc9475ba..fe9a900cf06 100644 --- a/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_orders_raw_logs_macro.sql +++ b/dbt_subprojects/daily_spellbook/macros/project/oneinch/project/oneinch_project_orders_raw_logs_macro.sql @@ -7,6 +7,8 @@ select block_number , block_time , tx_hash + , tx_from + , tx_to , index , contract_address , topic0 From 188fac5a59e94445c772fdcaeb841f5b30a41730 Mon Sep 17 00:00:00 2001 From: Siciliabird <136583351+QianlongCry@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:11:41 +0200 Subject: [PATCH 07/59] docs: fix broken link (#6787) * docs: fix broken link * docs: fix broken link --- docs/general/sector_spell_design.md | 2 +- docs/macros/macro_overview.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/general/sector_spell_design.md b/docs/general/sector_spell_design.md index 1e2353b1748..ff1e211793a 100644 --- a/docs/general/sector_spell_design.md +++ b/docs/general/sector_spell_design.md @@ -4,7 +4,7 @@ Within Spellbook, there are two main spells which are considered the most popula **Note**: not all sectors are up-to-date in the new structure, but will be considered moving forward -Since these sector-level spells will have their own dedicated `readme` within their directory with specifics, this will remain a high-level overview. Example dex readme [here](/models/_sector/dex/readme.md). +Since these sector-level spells will have their own dedicated `readme` within their directory with specifics, this will remain a high-level overview. Example dex readme [here](/dbt_subprojects/dex/README.md). ## Model level of granularity diff --git a/docs/macros/macro_overview.md b/docs/macros/macro_overview.md index 3f41909e082..8f12ef32e17 100644 --- a/docs/macros/macro_overview.md +++ b/docs/macros/macro_overview.md @@ -28,7 +28,7 @@ Following [this](/dbt_subprojects/dex/macros/models/_project/uniswap_compatible_ - **Multiple Macros in One File** - It's common to have multiple macros within a single file, such as various versions of the uniswap contract code. Group similar macros together logically. -Within models, such as uniswap v2, call macro code with [this approach](/dbt_subprojects/dex/target/compiled/dex/models/trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql). +Within models, such as uniswap v2, call macro code with [this approach](/dbt_subprojects/dex/models/trades/ethereum/platforms/uniswap_v2_ethereum_base_trades.sql). ## When to Use a Macro From 9dc17bdbb9fb69a8421db61020a660966ee48958 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Mon, 23 Sep 2024 11:11:51 -0300 Subject: [PATCH 08/59] Add missing tokens to tokens.erc20 (#6803) * Update labels_balancer_v2_pools_polygon.sql * rerun * fix typo * add missing tokens to tokens.erc20 * Update _sources.yml --- .../tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql | 1 + .../tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql | 5 +++-- sources/_subprojects_outputs/hourly_spellbook/_sources.yml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql b/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql index fc06a736b80..3231c9df4d3 100644 --- a/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql @@ -100,6 +100,7 @@ FROM (VALUES , (0x90364aa61234b85251ad943681433904c35fa5ce, 'METIS', 18) , (0x4026affabd9032bcc87fa05c02f088905f3dc09b, 'SWISE', 18) , (0xf6d22e29496313d89ad6261fbae8d118181561de, 'GT', 18) + , (0x25ea98ac87a38142561ea70143fd44c4772a16b6, 'MORE', 18) , (0xe7076d4bb604dea53adaa424fce0336ee7f975ff, 'auraezETH/wstETH', 18) , (0xb3cf6721d8f88f7547d90ed8e4119e09945efa9a, 'aurarsETH/wETH', 18) , (0x2f7242373f4b2c831870c145376c4fc9ac76a35d, 'aurarsETH/rETH/wstETH', 18) diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql index cf35f9e8226..993f4784fb4 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql @@ -4589,7 +4589,9 @@ FROM (VALUES , ( 0x866a2bf4e572cbcf37d5071a7a58503bfb36be1b, 'M', 6) , ( 0x20157dbabb84e3bbfe68c349d0d44e48ae7b5ad2, 'dlcBTC', 8) , ( 0xe1B4d34E8754600962Cd944B535180Bd758E6c2e, 'agETH', 18) - , ( 0x5C5b196aBE0d54485975D1Ec29617D42D9198326, 'stdeUSD', 18) + , ( 0x5C5b196aBE0d54485975D1Ec29617D42D9198326, 'stdeUSD', 18) + , ( 0x6dc3ce9c57b20131347fdc9089d740daf6eb34c5, 'balETH', 18) + , ( 0x786f4782d1a5c602ea30bc4a95154110b9e231ea, 'shezBTC', 8) , ( 0x09db87a538bd693e9d08544577d5ccfaa6373a48, 'ynETH', 18) , ( 0x3b50805453023a91a8bf641e279401a0b23fa6f9, 'REZ', 18) , ( 0x7777cec341e7434126864195adef9b05dcc3489c, 'ONI', 18) @@ -4624,5 +4626,4 @@ FROM (VALUES , ( 0x60407266586e204792b69b024558aa18228ab12f, 'MBAKER', 18) , ( 0x048d07bd350ba516b84587e147284881b593eb86, 'SYNK', 18) , ( 0xbbd91d5cda7085a186b1354e1b0744bb58ad7cf6, 'ZOMBIE', 9) - ) AS temp_table (contract_address, symbol, decimals) diff --git a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml index fc633083e38..eac5c639ba9 100644 --- a/sources/_subprojects_outputs/hourly_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/hourly_spellbook/_sources.yml @@ -49,4 +49,4 @@ sources: - name: jelly_swap_sei tables: - - name: pools_metrics_daily \ No newline at end of file + - name: pools_metrics_daily From f50f1abb3879bb6088b9efbfe88fa4164340ed93 Mon Sep 17 00:00:00 2001 From: Mansi <122999960+IrishLatte19@users.noreply.github.com> Date: Mon, 23 Sep 2024 19:42:01 +0530 Subject: [PATCH 09/59] added fbux token price (#6802) --- .../tokens/models/prices/fantom/prices_fantom_tokens.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/fantom/prices_fantom_tokens.sql b/dbt_subprojects/tokens/models/prices/fantom/prices_fantom_tokens.sql index cc99d43fe1b..e3e632c3ece 100644 --- a/dbt_subprojects/tokens/models/prices/fantom/prices_fantom_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/fantom/prices_fantom_tokens.sql @@ -88,7 +88,7 @@ FROM ('polter-polterfinance-protocol-token', 'fantom', 'POLTER', 0x5c725631FD299703D0A74C23F89a55c6B9A0C52F, 18), ('equal-equalizer-dex', 'fantom', 'EQUAL', 0x3fd3a0c85b70754efc07ac9ac0cbbdce664865a6, 18), ('ftails-ftails', 'fantom', 'FTAILS', 0x5cf90b977c86415a53ce3b7be13b26f6abddfee2, 18), - -- ('fbux-fantom-money-market', 'fantom', 'FBUX', 0x1e2ea3f3209d66647f959cf00627107e079b870d, 18), + ('fbux-fantom-money-market', 'fantom', 'FBUX', 0x1e2ea3f3209d66647f959cf00627107e079b870d, 18), ('spirit-spiritswap', 'fantom', 'SPIRIT', 0x5cc61a78f164885776aa610fb0fe1257df78e59b, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) where contract_address not in ( From 87258899f6e2791a4e783ad26d8d6f997660f07a Mon Sep 17 00:00:00 2001 From: Rantum Date: Mon, 23 Sep 2024 07:12:11 -0700 Subject: [PATCH 10/59] add native tokens for scroll & linea (#6788) --- dbt_subprojects/tokens/models/tokens/_schema.yml | 6 +++--- dbt_subprojects/tokens/models/tokens/tokens_native.sql | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dbt_subprojects/tokens/models/tokens/_schema.yml b/dbt_subprojects/tokens/models/tokens/_schema.yml index 6de4d57b157..f1c1236c36a 100644 --- a/dbt_subprojects/tokens/models/tokens/_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/_schema.yml @@ -26,11 +26,11 @@ models: - name: tokens_native meta: - blockchain: avalanche_c, bnb, ethereum, gnosis, optimism, ethereum, arbitrum, solana, fantom, mantle, blast + blockchain: avalanche_c, bnb, ethereum, gnosis, optimism, ethereum, arbitrum, solana, fantom, mantle, blast, scroll, linea sector: tokens - contributors: ilemi + contributors: ilemi, rantum config: - tags: ['tokens','native', 'avalanche_c', 'bnb','ethereum', 'gnosis','optimism','ethereum','solana','arbitrum', 'fantom','mantle', 'blast'] + tags: ['tokens','native', 'avalanche_c', 'bnb','ethereum', 'gnosis','optimism','ethereum','solana','arbitrum', 'fantom','mantle', 'blast','scroll','linea'] description: > The chain native token and symbol, and the prices.usd symbol/address that is closest. columns: diff --git a/dbt_subprojects/tokens/models/tokens/tokens_native.sql b/dbt_subprojects/tokens/models/tokens/tokens_native.sql index 5251fdf0a61..b5d4a319539 100644 --- a/dbt_subprojects/tokens/models/tokens/tokens_native.sql +++ b/dbt_subprojects/tokens/models/tokens/tokens_native.sql @@ -1,10 +1,10 @@ {{ config( alias='native', tags=['static'], - post_hook='{{ expose_spells(\'["arbitrum","avalanche_c","bnb","ethereum","optimism", "gnosis", "fantom", "polygon","solana", "celo", "zksync", "mantle","blast"]\', + post_hook='{{ expose_spells(\'["arbitrum","avalanche_c","bnb","ethereum","optimism", "gnosis", "fantom", "polygon","solana", "celo", "zksync", "mantle","blast","scroll","linea"]\', "sector", "tokens", - \'["0xManny","hildobby","soispoke","dot2dotseurat","mtitus6","wuligy","lgingerich","angus_1","Henrystats"]\') }}')}} + \'["0xManny","hildobby","soispoke","dot2dotseurat","mtitus6","wuligy","lgingerich","angus_1","Henrystats","rantum"]\') }}')}} SELECT chain, symbol, price_symbol, price_address, decimals FROM (VALUES @@ -24,4 +24,6 @@ FROM (VALUES , ('mantle', 'MNT', 'WMNT', 0x78c1b0c915c4faa5fffa6cabf0219da63d7f4cb8, 18) , ('blast', 'ETH', 'WETH', 0x4300000000000000000000000000000000000004, 18) , ('mode', 'MODE', 'MODE', 0xdfc7c877a950e49d2610114102175a06c2e3167a, 18) + , ('scroll', 'ETH', 'WETH', 0x5300000000000000000000000000000000000004, 18) + , ('linea', 'ETH', 'WETH', 0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f, 18) ) AS temp_table (chain, symbol, price_symbol, price_address, decimals) From 9484d1be4a118bca77ee216d59d038c22d1b7d5c Mon Sep 17 00:00:00 2001 From: ppclunghe <90045511+ppclunghe@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:47:29 +0200 Subject: [PATCH 11/59] wstETH price on BNB (#6806) * prices-wsteth-bnb * fix --- dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql b/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql index 414741581d4..ed895f4d0f8 100644 --- a/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql @@ -280,7 +280,8 @@ FROM ('coco-coco-coin', 'bnb', 'COCO', 0xf563e86e461de100cfcfd8b65daa542d3d4b0550, 18), ('zeta-zetachain', 'bnb', 'ZETA', 0x0000028a2eb8346cd5c0267856ab7594b7a55308, 18), ('euri-eurite', 'bnb', 'EURI', 0x9d1a7a3191102e9f900faa10540837ba84dcbae7, 18), - ('cookie-cookie', 'bnb', 'COOKIE', 0xc0041ef357b183448b235a8ea73ce4e4ec8c265f, 18) + ('cookie-cookie', 'bnb', 'COOKIE', 0xc0041ef357b183448b235a8ea73ce4e4ec8c265f, 18), + ('wsteth-wrapped-liquid-staked-ether-20', 'bnb', 'wstETH', 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) where contract_address not in ( 0x2ab0e9e4ee70fff1fb9d67031e44f6410170d00e -- bXEN has bad price feed. From 7f6532b3b0294947403baf8f1e22a6df1a5f5d2f Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:48:39 -0300 Subject: [PATCH 12/59] add Avalanche-C models to Gyroscope (#6804) * fix typo * add Avalanche-C models to Gyroscope * again * update cross-chain trades model * update contributors --- .../gyroscope_avalanche_c_schema.yml | 94 +++++++++++++++++++ .../gyroscope_avalanche_c_trades.sql | 56 +++++++++++ .../models/gyroscope/gyroscope_schema.yml | 4 +- .../models/gyroscope/gyroscope_trades.sql | 5 +- .../labels_balancer_v2_pools_avalanche_c.sql | 16 +++- .../gyroscope_avalanche_c_sources.yml | 23 +++++ .../labels_balancer_v2_sources.yml | 29 +++++- 7 files changed, 221 insertions(+), 6 deletions(-) create mode 100644 dbt_subprojects/daily_spellbook/models/gyroscope/avalanche_c/gyroscope_avalanche_c_schema.yml create mode 100644 dbt_subprojects/daily_spellbook/models/gyroscope/avalanche_c/gyroscope_avalanche_c_trades.sql create mode 100644 sources/gyroscope/avalanche_c/gyroscope_avalanche_c_sources.yml diff --git a/dbt_subprojects/daily_spellbook/models/gyroscope/avalanche_c/gyroscope_avalanche_c_schema.yml b/dbt_subprojects/daily_spellbook/models/gyroscope/avalanche_c/gyroscope_avalanche_c_schema.yml new file mode 100644 index 00000000000..45cc3b0baf0 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/gyroscope/avalanche_c/gyroscope_avalanche_c_schema.yml @@ -0,0 +1,94 @@ +version: 2 + +models: + + - name: gyroscope_avalanche_c_trades + + meta: + + blockchain: avalanche_c + project: gyroscope + contributors: viniabussafi + + config: + + tags: ["avalanche_c", "gyroscope", "trades"] + + description: trades on gyroscope E-CLP pools on avalanche_c + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_time + - blockchain + - tx_hash + - evt_index + columns: + - &blockchain + name: blockchain + description: "blockchain name(avalanche_c)" + - &project + name: project + description: "gyroscope as project" + - &block_date + name: block_date + description: "UTC event block date" + - &block_month + name: block_month + description: "UTC event block month" + - &block_time + name: block_time + description: "UTC event block time" + - &token_bought_symbol + name: token_bought_symbol + description: "Token symbol for token bought in the trade" + - &token_sold_symbol + name: token_sold_symbol + description: "Token symbol for token sold in the trade" + - &token_pair + name: token_pair + description: "Token symbol pair for each token involved in the trade" + - &token_bought_amount + name: token_bought_amount + description: "Value of the token bought at time of execution in the original currency" + - &token_sold_amount + name: token_sold_amount + description: "Value of the token sold at time of execution in the original currency" + - &token_bought_amount_raw + name: token_bought_amount_raw + description: "Raw value of the token bought at time of execution in the original currency" + - &token_sold_amount_raw + name: token_sold_amount_raw + description: "Raw value of the token sold at time of execution in the original currency" + - &amount_usd + name: amount_usd + description: "USD value of the trade at time of execution" + - &token_bought_address + name: token_bought_address + description: "Contract address of the token bought" + - &token_sold_address + name: token_sold_address + description: "Contract address of the token sold" + - &taker + name: taker + description: "Address of trader who purchased a token" + - &project_contract_address + name: project_contract_address + description: "Ethereum address for the liquidity pool used in transaction" + - &pool_id + name: pool_id + description: "Unique encoded identifier that refers to each pool" + - &swap_fee + name: swap_fee + description: 'Swap fee' + - &tx_hash + name: tx_hash + description: "Transaction hash" + - &tx_from + name: tx_from + description: "transaction.from" + - &tx_to + name: tx_to + description: "transaction.to" + - &evt_index + name: evt_index + description: "Event index" \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/gyroscope/avalanche_c/gyroscope_avalanche_c_trades.sql b/dbt_subprojects/daily_spellbook/models/gyroscope/avalanche_c/gyroscope_avalanche_c_trades.sql new file mode 100644 index 00000000000..277c0491d1e --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/gyroscope/avalanche_c/gyroscope_avalanche_c_trades.sql @@ -0,0 +1,56 @@ +{{ config( + schema = 'gyroscope_avalanche_c', + alias = 'trades', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['block_time', 'blockchain', 'tx_hash', 'evt_index'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] + ) +}} + +with E_CLPs AS ( + SELECT + x.pool + , y.min_block_time + FROM {{ source('gyroscope_avalanche_c','GyroECLPPoolFactory_evt_PoolCreated') }} x + LEFT JOIN ( + SELECT min(evt_block_time) AS min_block_time + FROM {{ source('gyroscope_avalanche_c','GyroECLPPoolFactory_evt_PoolCreated') }} + ) y + on x.pool is not null +) + +SELECT + blockchain, + 'gyroscope' AS project, + block_date, + block_month, + block_time, + token_bought_symbol, + token_sold_symbol, + token_pair, + token_bought_amount, + token_sold_amount, + token_bought_amount_raw, + token_sold_amount_raw, + amount_usd, + token_bought_address, + token_sold_address, + taker, + maker, + project_contract_address, + pool_id, + swap_fee, + tx_hash, + tx_from, + tx_to, + evt_index +FROM {{ source('balancer_v2_avalanche_c', 'trades') }} x +inner join E_CLPs y +on x.block_time >= y.min_block_time +and x.project_contract_address = y.pool +{% if is_incremental() %} +WHERE + {{incremental_predicate('x.block_time')}} +{% endif %} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_schema.yml b/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_schema.yml index ca4964bad6e..1a5799bfb76 100644 --- a/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_schema.yml @@ -6,9 +6,9 @@ models: meta: - blockchain: ethereum, arbitrum, optimism, polygon + blockchain: ethereum, arbitrum, optimism, polygon, avalanche_c project: gyroscope - contributors: fmarrr + contributors: fmarrr, viniabussafi config: diff --git a/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_trades.sql b/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_trades.sql index 9a607a3d773..c7470f4c8f6 100644 --- a/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_trades.sql +++ b/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_trades.sql @@ -2,15 +2,16 @@ schema = 'gyroscope', alias = 'trades', materialized = 'view', - post_hook='{{ expose_spells(\'["arbitrum", "ethereum","optimism", "polygon"]\', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "ethereum","optimism", "polygon"]\', "project", "gyroscope", - \'["fmarrr"]\') }}' + \'["fmarrr", "viniabussafi"]\') }}' ) }} {% set gyroscope_models = [ ref('gyroscope_arbitrum_trades'), + ref('gyroscope_avalanche_c_trades'), ref('gyroscope_ethereum_trades'), ref('gyroscope_optimism_trades'), ref('gyroscope_polygon_trades') diff --git a/dbt_subprojects/dex/models/_projects/balancer/labels/avalanche_c/labels_balancer_v2_pools_avalanche_c.sql b/dbt_subprojects/dex/models/_projects/balancer/labels/avalanche_c/labels_balancer_v2_pools_avalanche_c.sql index ef71780d697..b70f0aee262 100644 --- a/dbt_subprojects/dex/models/_projects/balancer/labels/avalanche_c/labels_balancer_v2_pools_avalanche_c.sql +++ b/dbt_subprojects/dex/models/_projects/balancer/labels/avalanche_c/labels_balancer_v2_pools_avalanche_c.sql @@ -113,6 +113,20 @@ WITH pools AS ( CROSS JOIN UNNEST( CAST(json_extract(settingsParams, '$.tokens') AS ARRAY(VARCHAR)) ) AS t (tokens) + + UNION ALL + + SELECT + c.poolId AS pool_id, + t.tokens AS token_address, + 0 AS normalized_weight, + cc.symbol, + 'ECLP' AS pool_type + FROM {{ source('balancer_v2_avalanche_c', 'Vault_evt_PoolRegistered') }} c + INNER JOIN {{ source('gyroscope_avalanche_c', 'GyroECLPPoolFactory_call_create') }} cc + ON c.evt_tx_hash = cc.call_tx_hash + AND bytearray_substring(c.poolId, 1, 20) = cc.output_0 + CROSS JOIN UNNEST(cc.tokens) AS t(tokens) ), settings AS ( @@ -129,7 +143,7 @@ settings AS ( SELECT 'avalanche_c' AS blockchain, bytearray_substring(pool_id, 1, 20) AS address, - CASE WHEN pool_type IN ('stable', 'linear', 'LBP', 'FX', 'managed') + CASE WHEN pool_type IN ('stable', 'linear', 'LBP', 'FX', 'managed', 'ECLP') THEN lower(pool_symbol) ELSE lower(concat(array_join(array_agg(token_symbol ORDER BY token_symbol), '/'), ' ', array_join(array_agg(cast(norm_weight AS varchar) ORDER BY token_symbol), '/'))) diff --git a/sources/gyroscope/avalanche_c/gyroscope_avalanche_c_sources.yml b/sources/gyroscope/avalanche_c/gyroscope_avalanche_c_sources.yml new file mode 100644 index 00000000000..a27348c9163 --- /dev/null +++ b/sources/gyroscope/avalanche_c/gyroscope_avalanche_c_sources.yml @@ -0,0 +1,23 @@ +version: 2 + +sources: + - name: gyroscope_avalanche_c + description: > + Decoded tables related to gyroscope E-CLP pools on avalanche_c. + tables: + - name: GyroECLPPoolFactory_evt_PoolCreated + description: > + Decoded table of gyroscope pool created + columns: + - name: contract_address + description: 'creator address' + - name: evt_tx_hash + description: 'Primary key of the transaction' + - name: evt_index + description: 'Index value of the transaction' + - name: evt_block_time + description: 'Timestamp for block event time in UTC' + - name: evt_block_number + description: 'Block number which processed the unique transaction hash' + - name: pool + description: 'created ECLP pool address' \ No newline at end of file diff --git a/sources/labels/addresses/__single_category_labels__/balancer_v2/labels_balancer_v2_sources.yml b/sources/labels/addresses/__single_category_labels__/balancer_v2/labels_balancer_v2_sources.yml index 7ddea4f1b7d..885b9c30308 100644 --- a/sources/labels/addresses/__single_category_labels__/balancer_v2/labels_balancer_v2_sources.yml +++ b/sources/labels/addresses/__single_category_labels__/balancer_v2/labels_balancer_v2_sources.yml @@ -1870,4 +1870,31 @@ sources: - *swapFeePercentage - *rateProviders - *symbol - - *tokens \ No newline at end of file + - *tokens + + - name: gyroscope_avalanche_c + tables: + - name: GyroECLPPoolFactory_call_create + description: > + Decoded table of registered pools on the Gyroscope ECLP contract. + columns: + - *call_block_number + - *call_block_time + - *call_success + - *call_trace_address + - *call_tx_hash + - name: capManager + - name: capParams + - name: contract_address + description: "Address of the ECLP Pool contract" + - name: derivedECLPParams + - name: eclpParams + - name: name + - *output_0 + - *owner + - name: pauseManager + - name: pauseParams + - *swapFeePercentage + - *rateProviders + - *symbol + - *tokens \ No newline at end of file From 2d1d595264f2d31017a8ab152e71974917c4c2c0 Mon Sep 17 00:00:00 2001 From: Daniel <32246390+danielpartida@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:50:23 +0200 Subject: [PATCH 13/59] Safe mantle models (#6777) * Add v1.4.1 singletons L1 singleton 0x41675C099F32341bf84BFc5382aF534df5C7461a L2 singleton 0x29fcB43b46531BcA003ddC8FCB67FFE91900C76 * Change goerli test * Declare new Safe models for zkevm * Implement Safe models for zkevm * Update crosschain models with zkevm data Models updated are: - safe_native_transfers.all.sql -> Added safe_zkevm_matic_transfers - safe_safes_all.sql -> Added safe_zkevm_safes - safe_transactions_all.sql -> safe_zkevm_transactions * Bugfix: Joining correctly on celo transactions for safe_celo_transactions spell * Fix project start for safe_polygon_matic_transfers.sql * Implement Safe mantle transfers spell * Implement Safe mantle singletons model * Implement Safe mantle txs spell * Change project start date for Safe mantle models * Add Mantle data to native transfers spell * Add Safe mantles models for all Safes * Add Safe mantle txs to all txs spell * Add Safe mantle data to Safe schema * Create Safe mantle schema * Implement Safe mantle sources file * Removing zkevm transactions model from wrong directory * Fix names of proxy factory contracts * Change file of Safe mantle native token transfers --- .../safe/mantle/safe_mantle_mnt_transfers.sql | 26 +++ .../safe/mantle/safe_mantle_safes.sql | 48 ++++++ .../safe/mantle/safe_mantle_schema.yml | 161 ++++++++++++++++++ .../safe/mantle/safe_mantle_singletons.sql | 21 +++ .../safe/mantle/safe_mantle_transactions.sql | 20 +++ .../safe/safe_native_transfers_all.sql | 3 +- .../models/_project/safe/safe_safes_all.sql | 3 +- .../models/_project/safe/safe_schema.yml | 12 +- .../_project/safe/safe_transactions_all.sql | 3 +- sources/safe/mantle/safe_mantle_sources.yml | 45 +++++ 10 files changed, 333 insertions(+), 9 deletions(-) create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_mnt_transfers.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_safes.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_schema.yml create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_singletons.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_transactions.sql create mode 100644 sources/safe/mantle/safe_mantle_sources.yml diff --git a/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_mnt_transfers.sql b/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_mnt_transfers.sql new file mode 100644 index 00000000000..51b8f396243 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_mnt_transfers.sql @@ -0,0 +1,26 @@ +{{ + config( + schema = 'safe_mantle', + alias= 'mnt_transfers', + partition_by = ['block_month'], + on_schema_change='fail', + materialized='incremental', + file_format ='delta', + incremental_strategy='merge', + unique_key = ['block_date', 'address', 'tx_hash', 'trace_address'], + post_hook = '{{ expose_spells(blockchains = \'["mantle"]\', + spell_type = "project", + spell_name = "safe", + contributors = \'["danielpartida"]\') }}' + ) +}} + +{% set project_start_date = '2023-07-12' %} + +{{ + safe_native_transfers( + blockchain = 'mantle', + native_token_symbol = 'MNT', + project_start_date = project_start_date + ) +}} \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_safes.sql b/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_safes.sql new file mode 100644 index 00000000000..79f79916d38 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_safes.sql @@ -0,0 +1,48 @@ +{{ + config( + materialized='incremental', + schema = 'safe_mantle', + alias= 'safes', + partition_by = ['block_month'], + unique_key = ['block_date', 'address'], + on_schema_change='fail', + file_format ='delta', + incremental_strategy='merge', + post_hook = '{{ expose_spells( + blockchains = \'["mantle"]\', + spell_type = "project", + spell_name = "safe", + contributors = \'["danielpartida"]\') }}' + ) +}} + +{% set project_start_date = '2023-07-12' %} + +select + 'mantle' as blockchain, + et."from" as address, + case + when et.to = 0xd9db270c1b5e3bd161e8c8503c55ceabee709552 then '1.3.0' + when et.to = 0x3e5c63644e683549055b9be8653de26e0b4cd36e then '1.3.0L2' + when et.to = 0x41675C099F32341bf84BFc5382aF534df5C7461a then '1.4.1' + when et.to = 0x29fcB43b46531BcA003ddC8FCB67FFE91900C762 then '1.4.1L2' + else 'unknown' + end as creation_version, + try_cast(date_trunc('day', et.block_time) as date) as block_date, + CAST(date_trunc('month', et.block_time) as DATE) as block_month, + et.block_time as creation_time, + et.tx_hash +from {{ source('mantle', 'traces') }} et +join {{ ref('safe_mantle_singletons') }} s + on et.to = s.address +where et.success = true + and et.call_type = 'delegatecall' -- delegatecall to singleton is Safe (proxy) address + and bytearray_substring(et.input, 1, 4) in ( + 0xb63e800d -- setup method v1.3.0, v1.3.0L2, v1.4.1, v.1.4.1L2 + ) + and et.gas_used > 10000 -- to ensure the setup call was successful. excludes e.g. setup calls with missing params that fallback + {% if not is_incremental() %} + and et.block_time > TIMESTAMP '{{project_start_date}}' -- for initial query optimisation + {% else %} + and {{ incremental_predicate('et.block_time') }} + {% endif %} diff --git a/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_schema.yml b/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_schema.yml new file mode 100644 index 00000000000..1dcf7c5e6bb --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_schema.yml @@ -0,0 +1,161 @@ +version: 2 + +models: + - name: safe_mantle_safes + meta: + blockchain: mantle + project: safe + contributors: danielpartida + freshness: + warn_after: { count: 12, period: hour } + error_after: { count: 24, period: hour } + config: + tags: ['safe', 'mantle'] + description: "Safe addresses" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - address + columns: + - &blockchain + name: blockchain + description: "The blockchain on which the Safe is deployed" + - &address + name: address + description: "Safe contract address" + - &creation_version + name: creation_version + description: "Version of initially created safe" + - &block_date + name: block_date + - &block_month + name: block_month + - &creation_time + name: creation_time + description: "Date/time of safe creation" + - &tx_hash + name: tx_hash + + - name: safe_mantle_mnt_transfers + meta: + blockchain: mantle + project: safe + contributors: danielpartida + freshness: + warn_after: { count: 12, period: hour } + error_after: { count: 24, period: hour } + config: + tags: ['safe', 'transfers', 'mantle'] + description: "MNT transfers for safes" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - address + - tx_hash + - trace_address + columns: + - *blockchain + - &symbol + name: symbol + description: "Symbol of native gas token: MNT" + - *address + - *block_date + - *block_month + - &block_time + name: block_time + description: "Date of MNT transfer" + - &amount_raw + name: amount_raw + description: "Raw amount of transferred MNT" + - *tx_hash + - &trace_address + name: trace_address + - &amount_usd + name: amount_usd + description: "USD amount of transferred MNT" + + - name: safe_mantle_singletons + meta: + blockchain: mantle + project: safe + contributors: danielpartida + freshness: + warn_after: { count: 12, period: hour } + error_after: { count: 24, period: hour } + config: + tags: ['safe', 'singletons', 'mantle'] + description: "Singletons addresses used with Safes" + columns: + - name: address + description: "Safe contract address" + + - name: safe_mantle_transactions + meta: + blockchain: mantle + project: safe + contributors: danielpartida + freshness: + warn_after: { count: 12, period: hour } + error_after: { count: 24, period: hour } + config: + tags: ['safe', 'mantle'] + description: "Safe transactions" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - tx_hash + - trace_address + columns: + - *blockchain + - *block_date + - *block_month + - *block_time + - &block_number + name: block_number + description: "Number of block" + - *tx_hash + - name: address + description: "Safe contract address" + - &to + name: to + description: "Destination address" + - &value + name: value + description: "Value of transaction" + - &gas + name: gas + description: "Gas limit set for transaction" + - &execution_gas_used + name: execution_gas_used + description: "Execution gas used during transaction, for more details see https://dune.com/docs/data-tables/raw/evm/traces/?h=traces#gas-used-in-traces" + - &total_gas_used + name: total_gas_used + description: "Total gas used during transaction" + - &tx_index + name: tx_index + description: "Transaction index" + - &sub_traces + name: sub_traces + description: "Number of sub traces" + - *trace_address + - &success + name: success + description: "Success state of transaction" + - &error + name: error + description: "Error of transaction if any" + - &code + name: code + description: "Code" + - &input + name: input + description: "Input data" + - &output + name: output + description: "Output data" + - &method + name: method + description: "Function method" \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_singletons.sql b/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_singletons.sql new file mode 100644 index 00000000000..91ab724e511 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_singletons.sql @@ -0,0 +1,21 @@ +{{ + config( + materialized='table', + schema = 'safe_mantle', + alias= 'singletons', + post_hook = '{{ expose_spells( + blockchains = \'["mantle"]\', + spell_type = "project", + spell_name = "safe", + contributors = \'["danielpartida"]\') }}' + ) +}} + + +-- Fetch all known singleton/mastercopy addresses used via factories. +select distinct singleton as address +from {{ source('gnosis_safe_mantle', 'SafeProxyFactory_v1_3_0_evt_ProxyCreation') }} + +union +select distinct singleton as address +from {{ source('gnosis_safe_mantle', 'SafeProxyFactory_v1_4_1_evt_ProxyCreation') }} \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_transactions.sql b/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_transactions.sql new file mode 100644 index 00000000000..26ed337c0aa --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/safe/mantle/safe_mantle_transactions.sql @@ -0,0 +1,20 @@ +{{ + config( + materialized='incremental', + schema = 'safe_mantle', + alias= 'transactions', + partition_by = ['block_month'], + unique_key = ['block_date', 'tx_hash', 'trace_address'], + file_format ='delta', + incremental_strategy='merge', + post_hook = '{{ expose_spells( + blockchains = \'["mantle"]\', + spell_type = "project", + spell_name = "safe", + contributors = \'["danielpartida"]\') }}' + ) +}} + +{% set project_start_date = '2023-07-12' %} + +{{ safe_transactions('mantle', project_start_date) }} diff --git a/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_native_transfers_all.sql b/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_native_transfers_all.sql index f5e01729566..a93c63bef1a 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_native_transfers_all.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_native_transfers_all.sql @@ -1,7 +1,7 @@ {{ config( schema = 'safe', alias = 'native_transfers_all', - post_hook='{{ expose_spells(\'["arbitrum","avalanche_c","base","blast","bnb","celo","ethereum","gnosis","goerli","linea","optimism","polygon","scroll","zkevm","zksync"]\', + post_hook='{{ expose_spells(\'["arbitrum","avalanche_c","base","blast","bnb","celo","ethereum","gnosis","goerli","linea","mantle","optimism","polygon","scroll","zkevm","zksync"]\', "project", "safe", \'["kryptaki", "danielpartida"]\') }}' @@ -19,6 +19,7 @@ ,ref('safe_gnosis_xdai_transfers') ,ref('safe_goerli_eth_transfers') ,ref('safe_linea_eth_transfers') +,ref('safe_mantle_mnt_transfers') ,ref('safe_optimism_eth_transfers') ,ref('safe_polygon_matic_transfers') ,ref('safe_scroll_eth_transfers') diff --git a/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_safes_all.sql b/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_safes_all.sql index 422871b6bc2..e0c1da95cff 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_safes_all.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_safes_all.sql @@ -1,7 +1,7 @@ {{ config( schema = 'safe', alias = 'safes_all', - post_hook='{{ expose_spells(\'["arbitrum","avalanche_c","base","blast","bnb","celo","ethereum","fantom","gnosis","goerli","linea","optimism","polygon","scroll","zkevm","zksync"]\', + post_hook='{{ expose_spells(\'["arbitrum","avalanche_c","base","blast","bnb","celo","ethereum","fantom","gnosis","goerli","linea","mantle","optimism","polygon","scroll","zkevm","zksync"]\', "project", "safe", \'["tschubotz", "danielpartida", "kryptaki"]\') }}' @@ -20,6 +20,7 @@ ,ref('safe_gnosis_safes') ,ref('safe_goerli_safes') ,ref('safe_linea_safes') +,ref('safe_mantle_safes') ,ref('safe_optimism_safes') ,ref('safe_polygon_safes') ,ref('safe_scroll_safes') diff --git a/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_schema.yml b/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_schema.yml index f944311f8b7..a6cae3d8159 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_schema.yml @@ -3,11 +3,11 @@ version: 2 models: - name: safe_safes_all meta: - blockchain: arbitrum, avalanche_c, base, blast, bnb, celo, ethereum, fantom, gnosis, goerli, linea, optimism, polygon, scroll, zkevm, zksync + blockchain: arbitrum, avalanche_c, base, blast, bnb, celo, ethereum, fantom, gnosis, goerli, linea, , mantle, optimism, polygon, scroll, zkevm, zksync project: safe contributors: tschubotz, danielpartida, kryptaki config: - tags: ['arbitrum', 'avalanche_c', 'base', 'blast', 'bnb', 'celo','ethereum', 'fantom', 'gnosis', 'goerli', 'linea', 'optimism', 'polygon', 'safe', 'scroll', 'zkevm', 'zksync'] + tags: ['arbitrum', 'avalanche_c', 'base', 'blast', 'bnb', 'celo','ethereum', 'fantom', 'gnosis', 'goerli', 'linea', 'mantle', 'optimism', 'polygon', 'safe', 'scroll', 'zkevm', 'zksync'] description: > Lists all Safes across chains. columns: @@ -32,14 +32,14 @@ models: - name: safe_transactions_all meta: - blockchain: arbitrum, avalanche_c, base, blast, bnb, celo, ethereum, fantom, gnosis, goerli, linea, optimism, polygon, scroll, zkevm, zksync + blockchain: arbitrum, avalanche_c, base, blast, bnb, celo, ethereum, fantom, gnosis, goerli, linea, mantle, optimism, polygon, scroll, zkevm, zksync project: safe contributors: kryptaki, danielpartida freshness: warn_after: { count: 12, period: hour } error_after: { count: 24, period: hour } config: - tags: ['arbitrum', 'avalanche_c', 'base', 'blast', 'bnb', 'celo','ethereum', 'fantom', 'gnosis', 'goerli', 'linea', 'optimism', 'polygon', 'safe', 'scroll', 'zkevm', 'zksync'] + tags: ['arbitrum', 'avalanche_c', 'base', 'blast', 'bnb', 'celo','ethereum', 'fantom', 'gnosis', 'goerli', 'linea', 'mantle', 'optimism', 'polygon', 'safe', 'scroll', 'zkevm', 'zksync'] description: "Safe transactions" columns: - *blockchain @@ -94,14 +94,14 @@ models: - name: safe_native_transfers_all meta: - blockchain: arbitrum, avalanche_c, base, blast, bnb, celo, ethereum, gnosis, goerli, linea, optimism, polygon, scroll, zkevm, zksync + blockchain: arbitrum, avalanche_c, base, blast, bnb, celo, ethereum, gnosis, goerli, linea, mantle, optimism, polygon, scroll, zkevm, zksync project: safe contributors: kryptaki, tschubotz, danielpartida freshness: warn_after: { count: 12, period: hour } error_after: { count: 24, period: hour } config: - tags: ['arbitrum', 'avalanche_c', 'base', 'blast', 'bnb', 'celo','ethereum', 'gnosis', 'goerli', 'linea', 'optimism', 'polygon', 'safe', 'scroll', 'zkevm', 'zksync'] + tags: ['arbitrum', 'avalanche_c', 'base', 'blast', 'bnb', 'celo','ethereum', 'gnosis', 'goerli', 'linea', 'mantle', 'optimism', 'polygon', 'safe', 'scroll', 'zkevm', 'zksync'] description: "Native gas token transfers into or out of Safes" tests: - dbt_utils.unique_combination_of_columns: diff --git a/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_transactions_all.sql b/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_transactions_all.sql index e2b069e5cfa..292f471fddf 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_transactions_all.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/safe/safe_transactions_all.sql @@ -1,7 +1,7 @@ {{ config( schema = 'safe', alias = 'transactions_all', - post_hook='{{ expose_spells(\'["arbitrum","avalanche_c","base","blast","bnb","celo","ethereum","fantom","gnosis","goerli","linea","optimism","polygon","scroll","zkevm","zksync"]\', + post_hook='{{ expose_spells(\'["arbitrum","avalanche_c","base","blast","bnb","celo","ethereum","fantom","gnosis","goerli","linea","mantle","optimism","polygon","scroll","zkevm","zksync"]\', "project", "safe", \'["kryptaki", "danielpartida"]\') }}' @@ -20,6 +20,7 @@ ,ref('safe_gnosis_transactions') ,ref('safe_goerli_transactions') ,ref('safe_linea_transactions') +,ref('safe_mantle_transactions') ,ref('safe_optimism_transactions') ,ref('safe_polygon_transactions') ,ref('safe_scroll_transactions') diff --git a/sources/safe/mantle/safe_mantle_sources.yml b/sources/safe/mantle/safe_mantle_sources.yml new file mode 100644 index 00000000000..01237b0084e --- /dev/null +++ b/sources/safe/mantle/safe_mantle_sources.yml @@ -0,0 +1,45 @@ +version: 2 + +sources: + - name: gnosis_safe_mantle + freshness: + warn_after: { count: 12, period: hour } + tables: + - name: SafeProxyFactory_v1_3_0_evt_ProxyCreation + loaded_at_field: evt_block_time + description: "Safe v1.3.0 factory ProxyCreation events" + columns: + - &contract_address + name: contract_address + description: "Contract address" + - &evt_block_number + name: evt_block_number + description: "Event block number" + - &evt_block_time + name: evt_block_time + description: "Event block time" + - &evt_index + name: evt_index + description: "Event index" + - &evt_tx_hash + name: evt_tx_hash + description: "Event tx hash" + - &proxy + name: proxy + description: "Address of created Safe proxy" + - &singleton + name: singleton + description: "Singleton" + - name: SafeProxyFactory_v1_4_1_evt_ProxyCreation + loaded_at_field: evt_block_time + description: "Safe v1.4.1 factory ProxyCreation events" + columns: + - *contract_address + - *evt_block_number + - *evt_block_time + - *evt_index + - *evt_tx_hash + - name: proxy + description: "Address of created Safe proxy" + - name: singleton + description: "Singleton" \ No newline at end of file From f0507df098373405cbc334ab20f5010cd660d197 Mon Sep 17 00:00:00 2001 From: Andrew <47720952+andrewhong5297@users.noreply.github.com> Date: Tue, 24 Sep 2024 13:23:14 -0400 Subject: [PATCH 14/59] fix epochs (#6801) * Update staking_solana_validator_stake_account_epochs_raw.sql * Revert "Update staking_solana_validator_stake_account_epochs_raw.sql" This reverts commit dacd5334f5a4f5cf4d34c88d65dc1ced48988c2b. * increase lookup time for epochs --------- Co-authored-by: jeff-dude --- .../staking_solana_validator_stake_account_epochs_raw.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/solana/models/_sector/staking/solana/staking_solana_validator_stake_account_epochs_raw.sql b/dbt_subprojects/solana/models/_sector/staking/solana/staking_solana_validator_stake_account_epochs_raw.sql index ff6dd1975a6..11b607dae74 100644 --- a/dbt_subprojects/solana/models/_sector/staking/solana/staking_solana_validator_stake_account_epochs_raw.sql +++ b/dbt_subprojects/solana/models/_sector/staking/solana/staking_solana_validator_stake_account_epochs_raw.sql @@ -22,7 +22,7 @@ with LEFT JOIN {{ ref('solana_utils_epochs') }} epoch ON first_block_epoch = true --cross join {% if is_incremental() %} - AND {{incremental_predicate('epoch.block_time')}} + AND epoch.block_time >= date_trunc('day', now() - interval '7' day) {% endif %} WHERE vote.block_slot < epoch.block_slot --only get changes to accounts before start of epoch GROUP BY 1,2,3,4,5 From 3e11e53bb59a9cfc2bda825ce33e22e1f6708931 Mon Sep 17 00:00:00 2001 From: Rantum Date: Tue, 24 Sep 2024 10:23:45 -0700 Subject: [PATCH 15/59] add mantle & blast to cross-chain spell (#6784) --- dbt_subprojects/nft/models/_sector/transfers/_schema.yml | 6 +++--- .../nft/models/_sector/transfers/nft_transfers.sql | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dbt_subprojects/nft/models/_sector/transfers/_schema.yml b/dbt_subprojects/nft/models/_sector/transfers/_schema.yml index 4b2fb972b35..4ce60886e35 100644 --- a/dbt_subprojects/nft/models/_sector/transfers/_schema.yml +++ b/dbt_subprojects/nft/models/_sector/transfers/_schema.yml @@ -3,11 +3,11 @@ version: 2 models: - name: nft_transfers meta: - blockchain: ethereum, base, polygon, bnb, avalanche_c, gnosis, optimism, arbitrum, fantom, goerli, celo, zksync, zora + blockchain: ethereum, base, polygon, bnb, avalanche_c, gnosis, optimism, arbitrum, fantom, goerli, celo, zksync, zora, scroll, mantle, blast, sector: nft - contributors: hildobby + contributors: hildobby, rantum config: - tags: ['nft', 'ethereum', 'base', 'polygon', 'bnb', 'avalanche_c', 'gnosis', 'optimism', 'arbitrum', 'fantom', 'goerli', 'celo', 'zksync', 'zora', 'transfers'] + tags: ['nft', 'ethereum', 'base', 'polygon', 'bnb', 'avalanche_c', 'gnosis', 'optimism', 'arbitrum', 'fantom', 'goerli', 'celo', 'zksync', 'zora', 'scroll', 'mantle', 'blast', 'transfers'] description: > NFT transfers tests: diff --git a/dbt_subprojects/nft/models/_sector/transfers/nft_transfers.sql b/dbt_subprojects/nft/models/_sector/transfers/nft_transfers.sql index eb0fd05d822..f38899ca6dd 100644 --- a/dbt_subprojects/nft/models/_sector/transfers/nft_transfers.sql +++ b/dbt_subprojects/nft/models/_sector/transfers/nft_transfers.sql @@ -8,10 +8,10 @@ incremental_strategy = 'merge', incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], unique_key = ['tx_hash', 'evt_index', 'token_id', 'amount'], - post_hook='{{ expose_spells(\'["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum", "polygon", "fantom", "goerli", "base", "celo", "zksync"]\', + post_hook='{{ expose_spells(\'["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum", "polygon", "fantom", "goerli", "base", "celo", "zksync", "zora", "scroll", "linea", "blast", "mantle"]\', "sector", "nft", - \'["hildobby", "0xRob"]\') }}' + \'["hildobby", "0xRob", "rantum"]\') }}' ) }} @@ -31,6 +31,8 @@ ,ref('nft_celo_transfers') ,ref('nft_scroll_transfers') ,ref('nft_linea_transfers') +,ref('nft_blast_transfers') +,ref('nft_mantle_transfers') ] %} SELECT * From 9b8d39e0516415efacbc515c155923f8b293d513 Mon Sep 17 00:00:00 2001 From: Rantum Date: Tue, 24 Sep 2024 10:26:00 -0700 Subject: [PATCH 16/59] Add missing fields to evms.logs (#6813) * Add missing fields to evms.logs * remove blob fields --- dbt_subprojects/daily_spellbook/models/evms/evms_logs.sql | 5 ++++- dbt_subprojects/daily_spellbook/models/evms/evms_schema.yml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_logs.sql b/dbt_subprojects/daily_spellbook/models/evms/evms_logs.sql index 36a66355e7f..7eb81a4af1c 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_logs.sql +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_logs.sql @@ -5,7 +5,7 @@ post_hook='{{ expose_spells(\'["ethereum", "polygon", "bnb", "avalanche_c", "gnosis", "fantom", "optimism", "arbitrum", "celo", "base", "goerli", "zksync", "zora", "scroll", "linea", "zkevm", "blast", "mantle"]\', "sector", "evms", - \'["hildobby"]\') }}' + \'["hildobby","rantum"]\') }}' ) }} @@ -49,6 +49,9 @@ FROM ( , tx_hash , index , tx_index + , block_date + , tx_from + , tx_to FROM {{ logs_model[1] }} {% if not loop.last %} UNION ALL diff --git a/dbt_subprojects/daily_spellbook/models/evms/evms_schema.yml b/dbt_subprojects/daily_spellbook/models/evms/evms_schema.yml index 68b56b52d23..f6d861905c4 100644 --- a/dbt_subprojects/daily_spellbook/models/evms/evms_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/evms/evms_schema.yml @@ -155,7 +155,7 @@ models: meta: blockchain: ethereum, polygon, bnb, avalanche_c, gnosis, fantom, optimism, arbitrum, celo, base, goerli, zksync, zora, scroll, linea, zkevm, blast, mantle, mode, sei sector: evms - contributors: [hildobby, synthquest] + contributors: [hildobby, synthquest, rantum] config: tags: ['evms', 'logs'] description: "An EVM log can be used to describe an event within a smart contract, like a token transfer or a change of ownership." From feda163d186187362db203c14024c26d4a406a45 Mon Sep 17 00:00:00 2001 From: Rantum Date: Tue, 24 Sep 2024 10:29:15 -0700 Subject: [PATCH 17/59] add new stablecoins (#6812) * add new stablecoins * commas * add missing decimal value * add gho, dyad --- .../tokens_arbitrum_erc20_stablecoins.sql | 15 ++++++++++-- .../arbitrum/tokens_arbitrum_schema.yml | 2 +- .../tokens_avalanche_c_erc20_stablecoins.sql | 7 ++++-- .../avalanche_c/tokens_avalanche_c_schema.yml | 2 +- .../base/tokens_base_erc20_stablecoins.sql | 9 ++++--- .../models/tokens/base/tokens_base_schema.yml | 2 +- .../bnb/tokens_bnb_erc20_stablecoins.sql | 6 +++-- .../models/tokens/bnb/tokens_bnb_schema.yml | 2 +- .../tokens_ethereum_erc20_stablecoins.sql | 24 ++++++++++++++++--- .../ethereum/tokens_ethereum_schema.yml | 2 +- .../tokens_optimism_erc20_stablecoins.sql | 5 ++-- .../optimism/tokens_optimism_schema.yml | 2 +- .../tokens_polygon_erc20_stablecoins.sql | 5 ++-- .../tokens/polygon/tokens_polygon_schema.yml | 2 +- 14 files changed, 62 insertions(+), 23 deletions(-) diff --git a/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20_stablecoins.sql index 335216bcd6b..28bd841786b 100644 --- a/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20_stablecoins.sql +++ b/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20_stablecoins.sql @@ -5,7 +5,7 @@ , post_hook='{{ expose_spells(\'["arbitrum"]\', "sector", "tokens_arbitrum", - \'["synthquest"]\') }}' + \'["synthquest","rantum"]\') }}' , unique_key = ['contract_address'] ) }} @@ -30,5 +30,16 @@ FROM (VALUES ('arbitrum', 0x3509f19581afedeff07c53592bc0ca84e4855475, 'Crypto-backed stablecoin', 'xUSD', 18, ''), ('arbitrum', 0x59d9356e565ab3a36dd77763fc0d87feaf85508c, 'Fiat-backed stablecoin', 'USDM', 18, ''), ('arbitrum', 0xff970a61a04b1ca14834a43f5de4533ebddb5cc8, 'Fiat-backed stablecoin', 'USDC', 6, ''), - ('arbitrum', 0x4d15a3a2286d883af0aa1b3f21367843fac63e07, 'Fiat-backed stablecoin', 'TUSD', 18, '') + ('arbitrum', 0x4d15a3a2286d883af0aa1b3f21367843fac63e07, 'Fiat-backed stablecoin', 'TUSD', 18, ''), + ('arbitrum', 0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34, 'Crypto-backed stablecoin', 'USDe', 18, ''), + ('arbitrum', 0xeb466342c4d449bc9f53a865d5cb90586f405215, 'Crypto-backed stablecoin', 'axlUDC', 6, ''), + ('arbitrum', 0xd3443ee1e91af28e5fb858fbd0d72a63ba8046e0, 'Crypto-backed stablecoin', 'gUSDC', 6, ''), + ('arbitrum', 0x7cfadfd5645b50be87d546f42699d863648251ad, 'Crypto-backed stablecoin', 'stataArbUSDCn', 6, ''), + ('arbitrum', 0x12275dcb9048680c4be40942ea4d92c74c63b844, 'Crypto-backed stablecoin', 'eUSD', 18, ''), + ('arbitrum', 0xb165a74407fe1e519d6bcbdec1ed3202b35a4140, 'Crypto-backed stablecoin', 'stataArbUSDT', 6, ''), + ('arbitrum', 0x323665443cef804a3b5206103304bd4872ea4253, 'Crypto-backed stablecoin', 'USDV', 6, ''), + ('arbitrum', 0x4cfa50b7ce747e2d61724fcac57f24b748ff2b2a, 'Crypto-backed stablecoin', 'fUSDC', 6, ''), + ('arbitrum', 0x57f5e098cad7a3d1eed53991d4d66c45c9af7812, 'Crypto-backed stablecoin', 'sUSDM', 18, ''), + ('arbitrum', 0x7dff72693f6a4149b17e7c6314655f6a9f7c8b33, 'Crypto-backed stablecoin', 'GHO', 18, '') + ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) diff --git a/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_schema.yml b/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_schema.yml index 0d566872dc6..01c696367f9 100644 --- a/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_schema.yml @@ -86,7 +86,7 @@ models: meta: blockchain: arbitrum sector: stablecoins - contributors: synthquest + contributors: synthquest, rantum config: tags: ['tokens', 'arbitrum', 'erc20', 'stablecoins'] description: > diff --git a/dbt_subprojects/tokens/models/tokens/avalanche_c/tokens_avalanche_c_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/avalanche_c/tokens_avalanche_c_erc20_stablecoins.sql index c6d569bd584..7ab0fa26f00 100644 --- a/dbt_subprojects/tokens/models/tokens/avalanche_c/tokens_avalanche_c_erc20_stablecoins.sql +++ b/dbt_subprojects/tokens/models/tokens/avalanche_c/tokens_avalanche_c_erc20_stablecoins.sql @@ -5,7 +5,7 @@ , post_hook='{{ expose_spells(\'["avalanche_c"]\', "sector", "tokens_avalanche_c", - \'["synthquest"]\') }}' + \'["synthquest","rantum"]\') }}' , unique_key = ['contract_address'] ) }} @@ -27,6 +27,9 @@ FROM (VALUES ('avalanche_c', 0x1c20e891bab6b1727d14da358fae2984ed9b59eb, 'Fiat-backed stablecoin', 'TUSD', 18, ''), ('avalanche_c', 0xdacde03d7ab4d81feddc3a20faa89abac9072ce2, 'Crypto-backed stablecoin', 'USP', 18, ''), ('avalanche_c', 0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664, 'Crypto-backed stablecoin', 'USDC.e', 6, ''), - ('avalanche_c', 0x8861f5c40a0961579689fdf6cdea2be494f9b25a, 'Hybrid stablecoin', 'iUSDS', 18, '') + ('avalanche_c', 0x8861f5c40a0961579689fdf6cdea2be494f9b25a, 'Hybrid stablecoin', 'iUSDS', 18, ''), + ('avalanche_c', 0xc7198437980c041c805a1edcba50c1ce5db95118, 'Crypto-backed stablecoin', 'USDT.e', 6, ''), + ('avalanche_c', 0xabe7a9dfda35230ff60d1590a929ae0644c47dc1, 'Crypto-backed stablecoin', 'aUSD', 18, ''), + ('avalanche_c', 0xfab550568c688d5d8a52c7d794cb93edc26ec0ec, 'Crypto-backed stablecoin', 'axlUSD', 6, '') ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) diff --git a/dbt_subprojects/tokens/models/tokens/avalanche_c/tokens_avalanche_c_schema.yml b/dbt_subprojects/tokens/models/tokens/avalanche_c/tokens_avalanche_c_schema.yml index 22c9c8c7cec..20ae182a593 100644 --- a/dbt_subprojects/tokens/models/tokens/avalanche_c/tokens_avalanche_c_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/avalanche_c/tokens_avalanche_c_schema.yml @@ -90,7 +90,7 @@ models: meta: blockchain: avalanche_c sector: stablecoins - contributors: synthquest + contributors: synthquest, rantum config: tags: ['tokens', 'avalanche_c', 'erc20', 'stablecoins'] description: > diff --git a/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20_stablecoins.sql index 8cbcbdcb911..50f24ffc47c 100644 --- a/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20_stablecoins.sql +++ b/dbt_subprojects/tokens/models/tokens/base/tokens_base_erc20_stablecoins.sql @@ -5,7 +5,7 @@ , post_hook='{{ expose_spells(\'["base"]\', "sector", "tokens_base", - \'["synthquest"]\') }}' + \'["synthquest","rantum"]\') }}' , unique_key = ['contract_address'] ) }} @@ -20,7 +20,10 @@ FROM (VALUES ('base', 0x833589fcd6edb6e08f4c7c32d4f71b54bda02913, 'Fiat-backed stablecoin', 'USDC', 6, ''), ('base', 0x04d5ddf5f3a8939889f11e97f8c4bb48317f1938, 'Fiat-backed stablecoin', 'USDz', 18, ''), ('base', 0x4621b7a9c75199271f773ebd9a499dbd165c3191, 'Crypto-backed stablecoin', 'DOLA', 18, ''), - ('base', 0xca72827a3d211cfd8f6b00ac98824872b72cab49, 'Fiat-backed stablecoin', 'cgUSD', 6, '') - + ('base', 0xca72827a3d211cfd8f6b00ac98824872b72cab49, 'Fiat-backed stablecoin', 'cgUSD', 6, ''), + ('base', 0x4621b7a9c75199271f773ebd9a499dbd165c3191, 'Crypto-backed stablecoin', 'DOLA', 18, ''), + ('base', 0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca, 'Stable-backed stablecoin', 'USDbC', 6, ''), + ('base', 0xfde4c96c8593536e31f229ea8f37b2ada2699bb2, 'Stable-backed stablecoin', 'USDT', 6, ''), + ('base', 0xeb466342c4d449bc9f53a865d5cb90586f405215, 'Crypto-backed stablecoin', 'axlUSDC', 6, '') ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) diff --git a/dbt_subprojects/tokens/models/tokens/base/tokens_base_schema.yml b/dbt_subprojects/tokens/models/tokens/base/tokens_base_schema.yml index 3cd3f9fe144..85bfcdf06db 100644 --- a/dbt_subprojects/tokens/models/tokens/base/tokens_base_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/base/tokens_base_schema.yml @@ -86,7 +86,7 @@ models: meta: blockchain: base sector: stablecoins - contributors: synthquest + contributors: synthquest, rantum config: tags: ['tokens', 'base', 'erc20', 'stablecoins'] description: > diff --git a/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_erc20_stablecoins.sql index 2d1457e851f..bc06307d26f 100644 --- a/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_erc20_stablecoins.sql +++ b/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_erc20_stablecoins.sql @@ -5,7 +5,7 @@ , post_hook='{{ expose_spells(\'["bnb"]\', "sector", "tokens_bnb", - \'["synthquest"]\') }}' + \'["synthquest","rantum"]\') }}' , unique_key = ['contract_address'] ) }} @@ -36,7 +36,9 @@ FROM (VALUES ('bnb', 0xb5102cee1528ce2c760893034a4603663495fd72, 'Crypto-backed stablecoin', 'USX', 18, ''), ('bnb', 0xb7f8cd00c5a06c0537e2abff0b58033d02e5e094, 'Crypto-backed stablecoin', 'PAX', 18, ''), ('bnb', 0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3, 'Hybrid stablecoin', 'DAI', 18, ''), - ('bnb', 0xd17479997f34dd9156deef8f95a52d81d265be9c, 'Algorithmic stablecoin', 'USDD', 18, '') + ('bnb', 0xd17479997f34dd9156deef8f95a52d81d265be9c, 'Algorithmic stablecoin', 'USDD', 18, ''), + ('bnb', 0x4268b8f0b87b6eae5d897996e6b845ddbd99adf3, 'Crypto-backed stablecoin', 'axlUSDC', 6, '') + diff --git a/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_schema.yml b/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_schema.yml index 5ebe3c50929..efa478e7176 100644 --- a/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_schema.yml @@ -86,7 +86,7 @@ models: meta: blockchain: bnb sector: stablecoins - contributors: synthquest + contributors: synthquest, rantum config: tags: ['tokens', 'bnb', 'erc20', 'stablecoins'] description: > diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql index 8072f092389..69adcbb06ef 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql @@ -5,7 +5,7 @@ , post_hook='{{ expose_spells(\'["ethereum"]\', "sector", "tokens_ethereum", - \'["Henrystats", "synthquest"]\') }}' + \'["Henrystats", "synthquest","rantum"]\') }}' , unique_key = ['contract_address'] ) }} @@ -60,7 +60,25 @@ FROM (VALUES ('ethereum', 0x57Ab1E02fEE23774580C119740129eAC7081e9D3, 'Crypto-backed stablecoin', 'sUSD', 18, 'Synthetix sUSD'), ('ethereum', 0xa693b19d2931d498c5b318df961919bb4aee87a5, 'Crypto-backed stablecoin', 'UST', 6, 'UST (Wormhole)'), ('ethereum', 0xe07F9D810a48ab5c3c914BA3cA53AF14E4491e8A, 'Crypto-backed stablecoin', 'GYD', 18, 'Gyro Dollar'), - ('ethereum', 0xdb25f211ab05b1c97d595516f45794528a807ad8, 'Fiat-backed stablecoin', 'EURS', 18, 'STASIS EURS') - + ('ethereum', 0xdb25f211ab05b1c97d595516f45794528a807ad8, 'Fiat-backed stablecoin', 'EURS', 18, 'STASIS EURS'), + ('ethereum', 0x15f74458ae0bfdaa1a96ca1aa779d715cc1eefe4, 'Crypto-backed stablecoin', 'GRAI', 18, 'Gravita Protocol'), + ('ethereum', 0xf939e0a03fb07f59a73314e73794be0e57ac1b4e, 'Crypto-backed stablecoin', 'crvUSD', 18, ''), + ('ethereum', 0xab5eb14c09d416f0ac63661e57edb7aecdb9befa, 'Crypto-backed stablecoin', 'msUSD', 18, ''), + ('ethereum', 0x9d39a5de30e57443bff2a8307a4256c8797a3497, 'Crypto-backed stablecoin', 'sUSDe', 18, ''), + ('ethereum', 0x15700b564ca08d9439c58ca5053166e8317aa138, 'Crypto-backed stablecoin', 'deUSD', 18, ''), + ('ethereum', 0x085780639cc2cacd35e474e71f4d000e2405d8f6, 'Crypto-backed stablecoin', 'fxUSD', 18, ''), + ('ethereum', 0x00000000efe302beaa2b3e6e1b18d08d69a9012a, 'Crypto-backed stablecoin', 'AUSD', 6, ''), + ('ethereum', 0xa0d69e286b938e21cbf7e51d71f6a4c8918f482f, 'Crypto-backed stablecoin', 'eUSD', 18, ''), + ('ethereum', 0xa469b7ee9ee773642b3e93e842e5d9b5baa10067, 'Crypto-backed stablecoin', 'USDz', 18, ''), + ('ethereum', 0x59d9356e565ab3a36dd77763fc0d87feaf85508c, 'Crypto-backed stablecoin', 'USDM', 18, ''), + ('ethereum', 0x79c58f70905f734641735bc61e45c19dd9ad60bc, 'Crypto-backed stablecoin', 'usdc-dai-usdt', 18, 'Balancer'), + ('ethereum', 0x0000206329b97db379d5e1bf586bbdb969c63274, 'Crypto-backed stablecoin', 'USDA', 18, ''), + ('ethereum', 0x35d8949372d46b7a3d5a56006ae77b215fc69bc0, 'Crypto-backed stablecoin', 'USD0++', 18, ''), + ('ethereum', 0x4591dbff62656e7859afe5e45f6f47d3669fbb28, 'Crypto-backed stablecoin', 'mkUSD', 18, ''), + ('ethereum', 0x0bffdd787c83235f6f0afa0faed42061a4619b7a, 'Crypto-backed stablecoin', 'VUSD', 6, ''), + ('ethereum', 0xcfc5bd99915aaa815401c5a41a927ab7a38d29cf, 'Crypto-backed stablecoin', 'thUSD', 18, ''), + ('ethereum', 0xdf3ac4f479375802a821f7b7b46cd7eb5e4262cc, 'Crypto-backed stablecoin', 'eUSD', 18, ''), + ('ethereum', 0xbbaec992fc2d637151daf40451f160bf85f3c8c1, 'Crypto-backed stablecoin', 'USDM', 6, ''), + ('ethereum', 0x7945b0a6674b175695e5d1d08ae1e6f13744abb0, 'Crypto-backed stablecoin', 'BaoUSD', 18, '') ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_schema.yml b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_schema.yml index 2577f0e571e..52d06246f05 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_schema.yml @@ -89,7 +89,7 @@ models: meta: blockchain: ethereum sector: stablecoins - contributors: synthquest + contributors: synthquest, rantum config: tags: ['tokens', 'ethereum', 'erc20', 'stablecoins'] description: > diff --git a/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_erc20_stablecoins.sql index 42837c64d4d..81f65b76823 100644 --- a/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_erc20_stablecoins.sql +++ b/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_erc20_stablecoins.sql @@ -5,7 +5,7 @@ , post_hook='{{ expose_spells(\'["optimism"]\', "sector", "tokens_optimism", - \'["msilb7", "synthquest"]\') }}' + \'["msilb7", "synthquest","rantum"]\') }}' , unique_key = ['contract_address'] ) }} @@ -43,7 +43,8 @@ FROM (VALUES ('optimism', 0x2057c8ecb70afd7bee667d76b4cd373a325b1a20, 'Bridge-backed stablecoin', 'hUSDT', 6, 'Tether USD Hop Token'), ('optimism', 0x9485aca5bbbe1667ad97c7fe7c4531a624c8b1ed, 'Crypto-backed stablecoin', 'agEUR', 18, 'agEUR'), ('optimism', 0xbfd291da8a403daaf7e5e9dc1ec0aceacd4848b9, 'Crypto-backed stablecoin', 'USX', 18, 'dForce USD'), - ('optimism', 0xba28feb4b6a6b81e3f26f08b83a19e715c4294fd, 'Algorithmic stablecoin', 'UST', 6, 'UST (Wormhole)') + ('optimism', 0xba28feb4b6a6b81e3f26f08b83a19e715c4294fd, 'Algorithmic stablecoin', 'UST', 6, 'UST (Wormhole)'), + ('optimism', 0xeb466342c4d449bc9f53a865d5cb90586f405215, 'Crypto-backed stablecoin', 'axlUSDC', 6, 'Axelar USDC') ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) diff --git a/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_schema.yml b/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_schema.yml index b3bb4c83c68..9a23a764e8b 100644 --- a/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/optimism/tokens_optimism_schema.yml @@ -173,7 +173,7 @@ models: meta: blockchain: optimism sector: stablecoins - contributors: synthquest + contributors: synthquest, rantum config: tags: ['tokens', 'optimism', 'erc20', 'stablecoins'] description: > diff --git a/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_erc20_stablecoins.sql index 3e705292284..c4d2d4523eb 100644 --- a/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_erc20_stablecoins.sql +++ b/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_erc20_stablecoins.sql @@ -5,7 +5,7 @@ , post_hook='{{ expose_spells(\'["polygon"]\', "sector", "tokens_polygon", - \'["synthquest"]\') }}' + \'["synthquest","rantum"]\') }}' , unique_key = ['contract_address'] ) }} @@ -31,7 +31,8 @@ FROM (VALUES ('polygon', 0xa3fa99a148fa48d14ed51d610c367c61876997f1, 'Crypto-backed stablecoin', 'miMATIC', 18, ''), ('polygon', 0xdab529f40e671a1d4bf91361c21bf9f0c9712ab7, 'Fiat-backed stablecoin', 'BUSD', 18, ''), ('polygon', 0x3a3e7650f8b9f667da98f236010fbf44ee4b2975, 'Crypto-backed stablecoin', 'xUSD', 18, ''), - ('polygon', 0x23001f892c0c82b79303edc9b9033cd190bb21c7, 'Crypto-backed stablecoin', 'LUSD', 18, '') + ('polygon', 0x23001f892c0c82b79303edc9b9033cd190bb21c7, 'Crypto-backed stablecoin', 'LUSD', 18, ''), + ('polygon', 0x750e4c4984a9e0f12978ea6742bc1c5d248f40ed, 'Crypto-backed stablecoin', 'axlUSDC', 6, '') ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) diff --git a/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_schema.yml b/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_schema.yml index 69aa6724c74..f19ec34af9a 100644 --- a/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_schema.yml @@ -86,7 +86,7 @@ models: meta: blockchain: polygon sector: stablecoins - contributors: synthquest + contributors: synthquest, rantum config: tags: ['tokens', 'polygon', 'erc20', 'stablecoins'] description: > From 41cf356db46d692a07f469a815a2d076b0c8d968 Mon Sep 17 00:00:00 2001 From: Rantum Date: Tue, 24 Sep 2024 10:31:25 -0700 Subject: [PATCH 18/59] add stablecoins (blast, mantle, linea, scroll) (#6810) * add stablecoins on linea, scroll, blast, mantle * update backing * add to cross chain spell * blast * re-add blast * remove dai dup --- .../tokens/models/tokens/_schema.yml | 6 ++-- .../blast/tokens_blast_erc20_stablecoins.sql | 28 +++++++++++++++++++ .../tokens/blast/tokens_blast_schema.yml | 25 ++++++++++++++++- .../linea/tokens_linea_erc20_stablecoins.sql | 27 ++++++++++++++++++ .../tokens/linea/tokens_linea_schema.yml | 23 +++++++++++++++ .../tokens_mantle_erc20_stablecoins.sql | 20 +++++++++++++ .../tokens/mantle/tokens_mantle_schema.yml | 25 ++++++++++++++++- .../tokens_scroll_erc20_stablecoins.sql | 21 ++++++++++++++ .../tokens/scroll/tokens_scroll_schema.yml | 23 +++++++++++++++ .../tokens/tokens_erc20_stablecoins.sql | 8 ++++-- 10 files changed, 199 insertions(+), 7 deletions(-) create mode 100644 dbt_subprojects/tokens/models/tokens/blast/tokens_blast_erc20_stablecoins.sql create mode 100644 dbt_subprojects/tokens/models/tokens/linea/tokens_linea_erc20_stablecoins.sql create mode 100644 dbt_subprojects/tokens/models/tokens/mantle/tokens_mantle_erc20_stablecoins.sql create mode 100644 dbt_subprojects/tokens/models/tokens/scroll/tokens_scroll_erc20_stablecoins.sql diff --git a/dbt_subprojects/tokens/models/tokens/_schema.yml b/dbt_subprojects/tokens/models/tokens/_schema.yml index f1c1236c36a..d382c8644f7 100644 --- a/dbt_subprojects/tokens/models/tokens/_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/_schema.yml @@ -66,11 +66,11 @@ models: - name: tokens_erc20_stablecoins meta: - blockchain: arbitrum, avalanche_c, bnb, ethereum, fantom, gnosis, optimism, polygon, base + blockchain: arbitrum, avalanche_c, bnb, ethereum, fantom, gnosis, optimism, polygon, base, blast, linea, mantle, scroll sector: tokens - contributors: hildobby, synthquest + contributors: hildobby, synthquest, rantum config: - tags: ['tokens','stablecoin', 'arbitrum','avalanche_c','bnb','ethereum','fantom','gnosis','optimism','polygon','base'] + tags: ['tokens','stablecoin', 'arbitrum','avalanche_c','bnb','ethereum','fantom','gnosis','optimism','polygon','base', 'blast', 'liena', 'mantle', 'scroll'] description: > Stablecoin (ERC20) tokens tests: diff --git a/dbt_subprojects/tokens/models/tokens/blast/tokens_blast_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/blast/tokens_blast_erc20_stablecoins.sql new file mode 100644 index 00000000000..1f9dcc28ef4 --- /dev/null +++ b/dbt_subprojects/tokens/models/tokens/blast/tokens_blast_erc20_stablecoins.sql @@ -0,0 +1,28 @@ +{{ config( + schema = 'tokens_blast' + , alias = 'erc20_stablecoins' + , tags=['static'] + , post_hook='{{ expose_spells(\'["blast"]\', + "sector", + "tokens_blast", + \'["rantum"]\') }}' + , unique_key = ['contract_address'] + ) +}} + +SELECT blockchain, contract_address, backing, symbol, decimals, name +FROM (VALUES + ('blast', 0x4300000000000000000000000000000000000003, 'Hybrid stablecoin', 'USDB', 6, ''), + ('blast', 0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34, 'Crypto-backed stablecoin', 'USDe', 18, ''), + ('blast', 0xeb466342c4d449bc9f53a865d5cb90586f405215, 'Crypto-backed stablecoin', 'axlUSDC', 6, ''), + ('blast', 0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2, 'Crypto-backed stablecoin', 'sUSDe', 18, ''), + ('blast', 0x52056ed29fe015f4ba2e3b079d10c0b87f46e8c6, 'Fiat-backed stablecoin', 'USDz', 18, ''), + ('blast', 0x9d889e2d7ff49ece580e5354ce934ccd1d6e78dc, 'Crypto-backed stablecoin', 'expUSD', 18, ''), + ('blast', 0x1a3d9b2fa5c6522c8c071dc07125ce55df90b253, 'Fiat-backed stablecoin', 'DUSD', 18, ''), + ('blast', 0xc608dfb90a430df79a8a1edbc8be7f1a0eb4e763, 'Crypto-backed stablecoin', 'arUSD', 18, ''), + ('blast', 0x836aed3b0e0ee44c77e0b6db34d170abcce9baac, 'Fiat-backed stablecoin', 'USDBx', 18, ''), + ('blast', 0x578122317baca7a3c7bb5301460d2f4f96e9394a, 'Crypto-backed stablecoinn', 'DUSD', 18, ''), + ('blast', 0x837fe561e9c5dfa73f607fda679295dbc2be5e40, 'Crypto-backed stablecoin', 'MUSD', 18, '') + + + ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) diff --git a/dbt_subprojects/tokens/models/tokens/blast/tokens_blast_schema.yml b/dbt_subprojects/tokens/models/tokens/blast/tokens_blast_schema.yml index b2e34b596c1..3363cbebe19 100644 --- a/dbt_subprojects/tokens/models/tokens/blast/tokens_blast_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/blast/tokens_blast_schema.yml @@ -18,4 +18,27 @@ models: - name: symbol description: "ERC20 token symbol" - name: decimals - description: "Number of decimals, refers to how divisible an ERC20 token can be" \ No newline at end of file + description: "Number of decimals, refers to how divisible an ERC20 token can be" + + - name: tokens_blast_erc20_stablecoins + meta: + blockchain: blast + sector: stablecoins + contributors: rantum + config: + tags: ['tokens', 'blast', 'erc20', 'stablecoins'] + description: > + Selection of stablecoin token addresses. + columns: + - name: blockchain + description: "Blockchain name" + - name: contract_address + description: "Stablecoin contract address" + - name: backing + description: "Stablecoin backing" + - name: symbol + description: "Stablecoin symbol" + - name: name + description: "Stablecoin project name" + - name: decimals + description: "Number of decimals" \ No newline at end of file diff --git a/dbt_subprojects/tokens/models/tokens/linea/tokens_linea_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/linea/tokens_linea_erc20_stablecoins.sql new file mode 100644 index 00000000000..9ee2c37178d --- /dev/null +++ b/dbt_subprojects/tokens/models/tokens/linea/tokens_linea_erc20_stablecoins.sql @@ -0,0 +1,27 @@ +{{ config( + schema = 'tokens_linea' + , alias = 'erc20_stablecoins' + , tags=['static'] + , post_hook='{{ expose_spells(\'["linea"]\', + "sector", + "tokens_linea", + \'["rantum"]\') }}' + , unique_key = ['contract_address'] + ) +}} + +SELECT blockchain, contract_address, backing, symbol, decimals, name +FROM (VALUES + ('linea', 0xa219439258ca9da29e9cc4ce5596924745e12b93, 'Fiat-backed stablecoin', 'USDT', 6, ''), + ('linea', 0x176211869ca2b568f2a7d4ee941e073a821ee1ff, 'Fiat-backed stablecoin', 'USDC', 6, ''), + ('linea', 0x4af15ec2a0bd43db75dd04e62faa3b8ef36b00d5, 'Hybrid stablecoin', 'DAI', 18, ''), + ('linea', 0xeb466342c4d449bc9f53a865d5cb90586f405215, 'Fiat-backed stablecoin', 'axlUSDC', 6, ''), + ('linea', 0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34, 'Crypto-backed stablecoin', 'USDe', 18, ''), + ('linea', 0x7d43aabc515c356145049227cee54b608342c0ad, 'Fiat-backed stablecoin', 'BUSD', 18, ''), + ('linea', 0xba2f9e7ae9f5f03fce7d560f986743659e768bbf, 'Fiat-backed stablecoin', 'eUSD', 18, ''), + ('linea', 0xc608dfb90a430df79a8a1edbc8be7f1a0eb4e763, 'Fiat-backed stablecoin', 'arUSD', 18, ''), + ('linea', 0xa88b54e6b76fb97cdb8ecae868f1458e18a953f4, 'Fiat-backed stablecoin', 'DUSD', 18, ''), + ('linea', 0x894134a25a5fac1c2c26f1d8fbf05111a3cb9487, 'Fiat-backed stablecoin', 'GRAI', 18, ''), + ('linea', 0xb79dd08ea68a908a97220c76d19a6aa9cbde4376, 'Crypto-backed stablecoin', 'USD+', 18, ''), + ('linea', 0x1e1f509963a6d33e169d9497b11c7dbfe73b7f13, 'Crypto-backed stablecoin', 'USDT+', 18, '') + ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) diff --git a/dbt_subprojects/tokens/models/tokens/linea/tokens_linea_schema.yml b/dbt_subprojects/tokens/models/tokens/linea/tokens_linea_schema.yml index d2fb3fd6976..4f1659e727d 100644 --- a/dbt_subprojects/tokens/models/tokens/linea/tokens_linea_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/linea/tokens_linea_schema.yml @@ -19,3 +19,26 @@ models: description: "ERC20 token symbol" - name: decimals description: "Number of decimals, refers to how divisible an ERC20 token can be" + + - name: tokens_linea_erc20_stablecoins + meta: + blockchain: linea + sector: stablecoins + contributors: rantum + config: + tags: ['tokens', 'linea', 'erc20', 'stablecoins'] + description: > + Selection of stablecoin token addresses. + columns: + - name: blockchain + description: "Blockchain name" + - name: contract_address + description: "Stablecoin contract address" + - name: backing + description: "Stablecoin backing" + - name: symbol + description: "Stablecoin symbol" + - name: name + description: "Stablecoin project name" + - name: decimals + description: "Number of decimals" diff --git a/dbt_subprojects/tokens/models/tokens/mantle/tokens_mantle_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/mantle/tokens_mantle_erc20_stablecoins.sql new file mode 100644 index 00000000000..ec329f3f930 --- /dev/null +++ b/dbt_subprojects/tokens/models/tokens/mantle/tokens_mantle_erc20_stablecoins.sql @@ -0,0 +1,20 @@ +{{ config( + schema = 'tokens_mantle' + , alias = 'erc20_stablecoins' + , tags=['static'] + , post_hook='{{ expose_spells(\'["mantle"]\', + "sector", + "tokens_mantle", + \'["rantum"]\') }}' + , unique_key = ['contract_address'] + ) +}} + +SELECT blockchain, contract_address, backing, symbol, decimals, name +FROM (VALUES + ('mantle', 0x201eba5cc46d216ce6dc03f6a759e8e766e956ae, 'Fiat-backed stablecoin', 'USDT', 6, ''), + ('mantle', 0x09bc4e0d864854c6afb6eb9a9cdf58ac190d0df9, 'Fiat-backed stablecoin', 'USDC', 6, ''), + ('mantle', 0x5be26527e817998a7206475496fde1e68957c5a6, 'Fiat-backed stablecoin', 'USDY', 18, ''), + ('mantle', 0xeb466342c4d449bc9f53a865d5cb90586f405215, 'Crypto-backed stablecoin', 'axlUSDC', 6, ''), + ('mantle', 0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34, 'Crypto-backed stablecoin', 'USDe', 18, '') + ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) diff --git a/dbt_subprojects/tokens/models/tokens/mantle/tokens_mantle_schema.yml b/dbt_subprojects/tokens/models/tokens/mantle/tokens_mantle_schema.yml index e278f6121aa..6e9631ec3d6 100644 --- a/dbt_subprojects/tokens/models/tokens/mantle/tokens_mantle_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/mantle/tokens_mantle_schema.yml @@ -18,4 +18,27 @@ models: - name: symbol description: "ERC20 token symbol" - name: decimals - description: "Number of decimals, refers to how divisible an ERC20 token can be" \ No newline at end of file + description: "Number of decimals, refers to how divisible an ERC20 token can be" + + - name: tokens_mantle_erc20_stablecoins + meta: + blockchain: mantle + sector: stablecoins + contributors: rantum + config: + tags: ['tokens', 'mantle', 'erc20', 'stablecoins'] + description: > + Selection of stablecoin token addresses. + columns: + - name: blockchain + description: "Blockchain name" + - name: contract_address + description: "Stablecoin contract address" + - name: backing + description: "Stablecoin backing" + - name: symbol + description: "Stablecoin symbol" + - name: name + description: "Stablecoin project name" + - name: decimals + description: "Number of decimals" \ No newline at end of file diff --git a/dbt_subprojects/tokens/models/tokens/scroll/tokens_scroll_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/scroll/tokens_scroll_erc20_stablecoins.sql new file mode 100644 index 00000000000..34211e2092f --- /dev/null +++ b/dbt_subprojects/tokens/models/tokens/scroll/tokens_scroll_erc20_stablecoins.sql @@ -0,0 +1,21 @@ +{{ config( + schema = 'tokens_scroll' + , alias = 'erc20_stablecoins' + , tags=['static'] + , post_hook='{{ expose_spells(\'["scroll"]\', + "sector", + "tokens_scroll", + \'["rantum"]\') }}' + , unique_key = ['contract_address'] + ) +}} + +SELECT blockchain, contract_address, backing, symbol, decimals, name +FROM (VALUES + ('scroll', 0xf55bec9cafdbe8730f096aa55dad6d22d44099df, 'Fiat-backed stablecoin', 'USDT', 6, ''), + ('scroll', 0x06efdbff2a14a7c8e15944d1f4a48f9f95f663a4, 'Fiat-backed stablecoin', 'USDC', 6, ''), + ('scroll', 0xca77eb3fefe3725dc33bccb54edefc3d9f764f97, 'Hybrid stablecoin', 'DAI', 18, ''), + ('scroll', 0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34, 'Crypto-backed stablecoin', 'USDe', 18, ''), + ('scroll', 0x77fbf86399ed764a084f77b9accb049f3dbc32d2, 'Crypto-backed stablecoin', 'loreUSD', 18, ''), + ('scroll', 0xedeabc3a1e7d21fe835ffa6f83a710c70bb1a051, 'Crypto-backed stablecoin', 'LUSD', 18, '') + ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) diff --git a/dbt_subprojects/tokens/models/tokens/scroll/tokens_scroll_schema.yml b/dbt_subprojects/tokens/models/tokens/scroll/tokens_scroll_schema.yml index 72eef1c075c..ada743c5a98 100644 --- a/dbt_subprojects/tokens/models/tokens/scroll/tokens_scroll_schema.yml +++ b/dbt_subprojects/tokens/models/tokens/scroll/tokens_scroll_schema.yml @@ -19,3 +19,26 @@ models: description: "ERC20 token symbol" - name: decimals description: "Number of decimals, refers to how divisible an ERC20 token can be" + + - name: tokens_scroll_erc20_stablecoins + meta: + blockchain: scroll + sector: stablecoins + contributors: rantum + config: + tags: ['tokens', 'scroll', 'erc20', 'stablecoins'] + description: > + Selection of stablecoin token addresses. + columns: + - name: blockchain + description: "Blockchain name" + - name: contract_address + description: "Stablecoin contract address" + - name: backing + description: "Stablecoin backing" + - name: symbol + description: "Stablecoin symbol" + - name: name + description: "Stablecoin project name" + - name: decimals + description: "Number of decimals" diff --git a/dbt_subprojects/tokens/models/tokens/tokens_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/tokens_erc20_stablecoins.sql index a51741e0877..83d32e2c3c0 100644 --- a/dbt_subprojects/tokens/models/tokens/tokens_erc20_stablecoins.sql +++ b/dbt_subprojects/tokens/models/tokens/tokens_erc20_stablecoins.sql @@ -3,10 +3,10 @@ alias = 'erc20_stablecoins', materialized='table', tags = ['static'], - post_hook = '{{ expose_spells(\'["ethereum", "arbitrum", "gnosis", "optimism", "bnb", "avalanche_c", "polygon", "fantom", "base"]\', + post_hook = '{{ expose_spells(\'["ethereum", "arbitrum", "gnosis", "optimism", "bnb", "avalanche_c", "polygon", "fantom", "base", "mantle", "scroll", "blast", "linea"]\', "sector", "stablecoins", - \'["synthquest"]\') }}' + \'["synthquest","rantum"]\') }}' ) }} @@ -20,6 +20,10 @@ , ref('tokens_optimism_erc20_stablecoins') , ref('tokens_polygon_erc20_stablecoins') , ref('tokens_base_erc20_stablecoins') +, ref('tokens_blast_erc20_stablecoins') +, ref('tokens_mantle_erc20_stablecoins') +, ref('tokens_scroll_erc20_stablecoins') +, ref('tokens_linea_erc20_stablecoins') ] %} From 1b46dc499daf0d61167177ac178e727f1b97da3f Mon Sep 17 00:00:00 2001 From: synthquest <112836792+Synthquest@users.noreply.github.com> Date: Tue, 24 Sep 2024 13:35:33 -0400 Subject: [PATCH 19/59] Daily Arbitrum Stablecoin Balances (#6757) * initialize arbitrum stablecoin balances * update naming * move to daily spellbook * USDC test * limit start date * open time limit * update sources test * open time limit --------- Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../stablecoins_arbitrum_balances.sql | 38 +++++ .../arbitrum/stablecoins_arbitrum_schema.yml | 62 ++++++++ .../_subprojects_outputs/tokens/_sources.yml | 143 +++++++++++++++++- 3 files changed, 241 insertions(+), 2 deletions(-) create mode 100644 dbt_subprojects/daily_spellbook/models/_sector/stablecoins/arbitrum/stablecoins_arbitrum_balances.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_sector/stablecoins/arbitrum/stablecoins_arbitrum_schema.yml diff --git a/dbt_subprojects/daily_spellbook/models/_sector/stablecoins/arbitrum/stablecoins_arbitrum_balances.sql b/dbt_subprojects/daily_spellbook/models/_sector/stablecoins/arbitrum/stablecoins_arbitrum_balances.sql new file mode 100644 index 00000000000..547dfe30a39 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_sector/stablecoins/arbitrum/stablecoins_arbitrum_balances.sql @@ -0,0 +1,38 @@ +{{ + config( + schema = 'stablecoins_arbitrum', + alias = 'balances', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['day', 'address', 'token_address', 'blockchain'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.day')] + ) +}} + +with +stablecoin_tokens as ( + select + symbol, + contract_address as token_address + from + {{ source('tokens_arbitrum', 'erc20_stablecoins')}} +) + +,balances as ( + {{ + balances_incremental_subset_daily( + blockchain = 'arbitrum', + token_list = 'stablecoin_tokens', + start_date = '2021-05-26' + ) + }} +) + +select + t.symbol + ,b.* +from balances b +left join stablecoin_tokens t + on b.token_address = t.token_address + \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_sector/stablecoins/arbitrum/stablecoins_arbitrum_schema.yml b/dbt_subprojects/daily_spellbook/models/_sector/stablecoins/arbitrum/stablecoins_arbitrum_schema.yml new file mode 100644 index 00000000000..d86af2b6fde --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_sector/stablecoins/arbitrum/stablecoins_arbitrum_schema.yml @@ -0,0 +1,62 @@ +version: 2 + +models: + - name: stablecoins_arbitrum_balances + + meta: + blockchain: arbitrum + sector: stablecoin + project: stablecoin + contributors: synthquest + + config: + tags: ['stablecoin', 'balances'] + description: "Balances of stablecoin token holders" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - day + - address + - token_address + columns: + - &blockchain + name: blockchain + description: "Blockchain for the token" + - &symbol + name: symbol + description: "Symbol for the token" + - &version + name: version + description: "Version of the token" + - &day + name: day + description: "Date on which the token balance is logged" + - &address + name: address + description: "Address for the token holder" + - &token_symbol + name: token_symbol + description: "Symbol for the token" + - &token_address + name: token_address + description: "Address for the token" + - &token_standard + name: token_standard + description: "Standard for the token" + - &token_id + name: token_id + description: "ID for the token" + - &balance + name: balance + description: "Balance for the user" + - &balance_usd + name: balance_usd + description: "USD value of balance for the user" + - &last_updated + name: last_updated + description: "UTC timestamp when data was last updated" + - &next_update + name: next_update + description: "UTC timestamp when data is next updated" + + \ No newline at end of file diff --git a/sources/_subprojects_outputs/tokens/_sources.yml b/sources/_subprojects_outputs/tokens/_sources.yml index d965c7cba6c..dfdcf010e6a 100644 --- a/sources/_subprojects_outputs/tokens/_sources.yml +++ b/sources/_subprojects_outputs/tokens/_sources.yml @@ -107,6 +107,20 @@ sources: description: "NFT collection symbol" - name: standard description: "NFT collection standard" + - name: erc20_stablecoins + columns: + - name: blockchain + data_type: varchar + - name: contract_address + data_type: varbinary + - name: backing + data_type: varchar + - name: symbol + data_type: varchar + - name: decimals + data_type: integer + - name: name + data_type: varchar - name: tokens_arbitrum @@ -120,6 +134,20 @@ sources: - name: decimals data_type: integer - name: nft + - name: erc20_stablecoins + columns: + - name: blockchain + data_type: varchar + - name: contract_address + data_type: varbinary + - name: backing + data_type: varchar + - name: symbol + data_type: varchar + - name: decimals + data_type: integer + - name: name + data_type: varchar - name: tokens_avalanche_c tables: @@ -132,6 +160,20 @@ sources: - name: decimals data_type: integer - name: nft + - name: erc20_stablecoins + columns: + - name: blockchain + data_type: varchar + - name: contract_address + data_type: varbinary + - name: backing + data_type: varchar + - name: symbol + data_type: varchar + - name: decimals + data_type: integer + - name: name + data_type: varchar - name: tokens_base @@ -145,6 +187,20 @@ sources: - name: decimals data_type: integer - name: nft + - name: erc20_stablecoins + columns: + - name: blockchain + data_type: varchar + - name: contract_address + data_type: varbinary + - name: backing + data_type: varchar + - name: symbol + data_type: varchar + - name: decimals + data_type: integer + - name: name + data_type: varchar - name: tokens_bnb tables: @@ -157,6 +213,20 @@ sources: - name: decimals data_type: integer - name: nft + - name: erc20_stablecoins + columns: + - name: blockchain + data_type: varchar + - name: contract_address + data_type: varbinary + - name: backing + data_type: varchar + - name: symbol + data_type: varchar + - name: decimals + data_type: integer + - name: name + data_type: varchar - name: tokens_celo tables: @@ -182,13 +252,26 @@ sources: data_type: integer - name: nft - name: stablecoins - - name: rebase columns: - name: contract_address data_type: varbinary - name: symbol data_type: varchar + - name: erc20_stablecoins + columns: + - name: blockchain + data_type: varchar + - name: contract_address + data_type: varbinary + - name: backing + data_type: varchar + - name: symbol + data_type: varchar + - name: decimals + data_type: integer + - name: name + data_type: varchar - name: tokens_fantom @@ -202,6 +285,20 @@ sources: - name: decimals data_type: integer - name: nft + - name: erc20_stablecoins + columns: + - name: blockchain + data_type: varchar + - name: contract_address + data_type: varbinary + - name: backing + data_type: varchar + - name: symbol + data_type: varchar + - name: decimals + data_type: integer + - name: name + data_type: varchar - name: tokens_goerli tables: @@ -226,6 +323,20 @@ sources: - name: decimals data_type: integer - name: nft + - name: erc20_stablecoins + columns: + - name: blockchain + data_type: varchar + - name: contract_address + data_type: varbinary + - name: backing + data_type: varchar + - name: symbol + data_type: varchar + - name: decimals + data_type: integer + - name: name + data_type: varchar - name: tokens_optimism @@ -290,6 +401,20 @@ sources: data_type: timestamp(3) with time zone - name: nft - name: nft_bridged_mapping + - name: erc20_stablecoins + columns: + - name: blockchain + data_type: varchar + - name: contract_address + data_type: varbinary + - name: backing + data_type: varchar + - name: symbol + data_type: varchar + - name: decimals + data_type: integer + - name: name + data_type: varchar - name: tokens_polygon @@ -303,6 +428,20 @@ sources: - name: decimals data_type: integer - name: nft + - name: erc20_stablecoins + columns: + - name: blockchain + data_type: varchar + - name: contract_address + data_type: varbinary + - name: backing + data_type: varchar + - name: symbol + data_type: varchar + - name: decimals + data_type: integer + - name: name + data_type: varchar - name: tokens_zksync @@ -355,4 +494,4 @@ sources: - name: prices_native tables: - - name: tokens + - name: tokens \ No newline at end of file From 856941ffc3e7fc6513e3109e4153d7e8bb7ae5a9 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Tue, 24 Sep 2024 20:39:33 +0300 Subject: [PATCH 20/59] New Event Models for GMX Project (#6808) * Added OrderFrozen Event Model * Fix error in tests on uniqueness * Added Order Updated Event Model * Update markets_data event model * Run tests again --- .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 127 +++++++++-- .../gmx_v2_arbitrum_order_created.sql | 2 +- .../arbitrum/gmx_v2_arbitrum_order_frozen.sql | 178 +++++++++++++++ .../gmx_v2_arbitrum_order_updated.sql | 204 ++++++++++++++++++ .../gmx_v2_avalanche_c_event_schema.yml | 129 +++++++++-- .../gmx_v2_avalanche_c_order_created.sql | 2 +- .../gmx_v2_avalanche_c_order_frozen.sql | 178 +++++++++++++++ .../gmx_v2_avalanche_c_order_updated.sql | 204 ++++++++++++++++++ .../gmx/event/gmx_v2_event_schema.yml | 129 +++++++++-- .../gmx/event/gmx_v2_order_created.sql | 2 +- .../gmx/event/gmx_v2_order_frozen.sql | 37 ++++ .../gmx/event/gmx_v2_order_updated.sql | 41 ++++ .../arbitrum/gmx_v2_arbitrum_markets_data.sql | 6 +- .../gmx_v2_avalanche_c_markets_data.sql | 6 +- .../daily_spellbook/package-lock.yml | 4 +- 15 files changed, 1186 insertions(+), 63 deletions(-) create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_frozen.sql create mode 100644 dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index 73b2bedf455..d4cbca2f796 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -126,11 +126,13 @@ models: description: The change in initial collateral amount. tests: - not_null - - name: trigger_price + - &trigger_price + name: trigger_price description: The price that triggers the order execution. tests: - - not_null - - name: acceptable_price + - not_null + - &acceptable_price + name: acceptable_price description: The minimum acceptable price for order execution. tests: - not_null @@ -142,15 +144,17 @@ models: description: The gas limit set for callback functions. tests: - not_null - - name: min_output_amount + - &min_output_amount_raw + name: min_output_amount_raw description: The minimum amount of output tokens expected from the order, based on the markets in the swap path. tests: - not_null - name: updated_at_block description: The block number at which the order was last updated. tests: - - not_null - - name: updated_at_time + - not_null + - &updated_at_time + name: updated_at_time description: The timestamp when the order was last updated. - &is_long name: is_long @@ -161,7 +165,8 @@ models: description: Boolean indicating if the native token should be unwrapped. - name: is_frozen description: Boolean indicating if the order is frozen. - - name: key + - &key + name: key description: The unique identifier for the order, stored as a bytes32 value. tests: - not_null @@ -196,11 +201,7 @@ models: tests: - not_null - *msg_sender - - name: key - description: The key associated with the executed order. Extracted as a bytes32 value. - tests: - - not_null - - unique + - *key - name: account description: The address associated with the order - name: secondary_order_type @@ -243,11 +244,7 @@ models: tests: - not_null - *msg_sender - - name: key - description: The key associated with the cancelled order. Extracted as a bytes32 value - tests: - - not_null - - unique + - *key - name: account description: The address associated with the order - name: reason_bytes @@ -818,4 +815,98 @@ models: - *is_increase - *order_key - *position_key - - *referral_code \ No newline at end of file + - *referral_code + + + - name: gmx_v2_arbitrum_order_frozen + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'order_frozen'] + description: | + Extracts and decodes the `OrderFrozen` event log data from the Arbitrum blockchain. + This model processes log entries related to frozen orders, extracting key variables such as + account addresses, event keys, and strings representing the reason for the order being frozen. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - key + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - *tx_from + - *tx_to + - name: event_name + description: The type of event recorded, always 'OrderFrozen' for this model + tests: + - not_null + - *msg_sender + - name: key + description: The key associated with the frozen order. Extracted as a bytes32 value + tests: + - not_null + - name: account + description: The address associated with the order + - name: reason_bytes + description: The reason for the order being frozen in byte format. + tests: + - not_null + - name: reason + description: The reason for the order being frozen in string format. + tests: + - not_null + + + - name: gmx_v2_arbitrum_order_updated + meta: + blockchain: arbitrum + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'gmx', 'event', 'order_updated'] + description: | + Extracts and decodes the `OrderUpdated` event log data from the Arbitrum blockchain. + This model processes log entries related to updated orders, extracting key variables such as + account addresses, event keys, and strings representing the reason for cancellation. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - *tx_from + - *tx_to + - name: event_name + description: The type of event recorded, always 'OrderUpdated' for this model. + tests: + - not_null + - *msg_sender + - name: key + description: The key associated with the updated order. Extracted as a bytes32 value + tests: + - not_null + - name: market + description: The market in which the order was updated. + tests: + - not_null + - name: account + description: The address associated with the order. + - *size_delta_usd + - *trigger_price + - *acceptable_price + - *min_output_amount_raw + - *updated_at_time \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql index 97aa0cdc6aa..632bfaee161 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql @@ -275,7 +275,7 @@ WITH evt_data_1 AS ( END AS acceptable_price, execution_fee / POWER(10, 18) AS execution_fee, callback_gas_limit, - min_output_amount AS min_output_amount, + min_output_amount AS min_output_amount_raw, updated_at_block, CASE diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql new file mode 100644 index 00000000000..b0cc9d09f62 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_frozen.sql @@ -0,0 +1,178 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'order_frozen', + materialized = 'table' + ) +}} + +{%- set event_name = 'OrderFrozen' -%} +{%- set blockchain_name = 'arbitrum' -%} + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + + FROM + evt_data +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'key' THEN value END) AS key, + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(key) AS key, + from_hex(account) AS account, + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql new file mode 100644 index 00000000000..85af3142f28 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql @@ -0,0 +1,204 @@ +{{ + config( + schema = 'gmx_v2_arbitrum', + alias = 'order_updated', + materialized = 'table' + ) +}} + +{%- set event_name = 'OrderUpdated' -%} +{%- set blockchain_name = 'arbitrum' -%} + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_arbitrum','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION DISTINCT + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'key' THEN value END) AS key, + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'sizeDeltaUsd' THEN value END) AS size_delta_usd, + MAX(CASE WHEN key_name = 'acceptablePrice' THEN value END) AS acceptable_price, + MAX(CASE WHEN key_name = 'triggerPrice' THEN value END) AS trigger_price, + MAX(CASE WHEN key_name = 'minOutputAmount' THEN value END) AS min_output_amount, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(key) AS key, + from_hex(account) AS account, + TRY_CAST(size_delta_usd AS DOUBLE) AS size_delta_usd, + TRY_CAST(acceptable_price AS DOUBLE) AS acceptable_price, + TRY_CAST(trigger_price AS DOUBLE) AS trigger_price, + TRY_CAST(min_output_amount AS DOUBLE) AS min_output_amount, + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +-- full data +, full_data AS ( + SELECT + ED.blockchain, + ED.block_time, + DATE(ED.block_time) AS block_date, + ED.block_number, + ED.tx_hash, + ED.index, + ED.contract_address, + ED.event_name, + ED.msg_sender, + + ED.key, + OC.market, + ED.account, + ED.size_delta_usd / POWER(10, 30) AS size_delta_usd, + CASE + WHEN MD.index_token_decimals IS NULL THEN ED.acceptable_price / POWER(10, 30) + ELSE ED.acceptable_price / POWER(10, 30 - MD.index_token_decimals) + END AS acceptable_price, + CASE + WHEN MD.index_token_decimals IS NULL THEN ED.trigger_price / POWER(10, 30) + ELSE ED.trigger_price / POWER(10, 30 - MD.index_token_decimals) + END AS trigger_price, + ED.min_output_amount AS min_output_amount_raw, + CASE + WHEN ED.updated_at_time = 0 THEN NULL + ELSE ED.updated_at_time + END AS updated_at_time + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_arbitrum_order_created') }} AS OC + ON ED.key = OC.key + LEFT JOIN {{ ref('gmx_v2_arbitrum_markets_data') }} AS MD + ON OC.market = MD.market + +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml index 1ad13d266cc..e2845ea5e81 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml @@ -126,11 +126,13 @@ models: description: The change in initial collateral amount. tests: - not_null - - name: trigger_price + - &trigger_price + name: trigger_price description: The price that triggers the order execution. tests: - - not_null - - name: acceptable_price + - not_null + - &acceptable_price + name: acceptable_price description: The minimum acceptable price for order execution. tests: - not_null @@ -141,16 +143,18 @@ models: - name: callback_gas_limit description: The gas limit set for callback functions. tests: - - not_null - - name: min_output_amount + - not_null + - &min_output_amount_raw + name: min_output_amount_raw description: The minimum amount of output tokens expected from the order, based on the markets in the swap path. tests: - not_null - name: updated_at_block description: The block number at which the order was last updated. tests: - - not_null - - name: updated_at_time + - not_null + - &updated_at_time + name: updated_at_time description: The timestamp when the order was last updated. - &is_long name: is_long @@ -161,7 +165,8 @@ models: description: Boolean indicating if the native token should be unwrapped. - name: is_frozen description: Boolean indicating if the order is frozen. - - name: key + - &key + name: key description: The unique identifier for the order, stored as a bytes32 value. tests: - not_null @@ -196,11 +201,7 @@ models: tests: - not_null - *msg_sender - - name: key - description: The key associated with the executed order. Extracted as a bytes32 value. - tests: - - not_null - - unique + - *key - name: account description: The address associated with the order - name: secondary_order_type @@ -243,11 +244,7 @@ models: tests: - not_null - *msg_sender - - name: key - description: The key associated with the cancelled order. Extracted as a bytes32 value - tests: - - not_null - - unique + - *key - name: account description: The address associated with the order - name: reason_bytes @@ -818,4 +815,98 @@ models: - *is_increase - *order_key - *position_key - - *referral_code \ No newline at end of file + - *referral_code + + + - name: gmx_v2_avalanche_c_order_frozen + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'order_frozen'] + description: | + Extracts and decodes the `OrderFrozen` event log data from the Avalanche blockchain. + This model processes log entries related to frozen orders, extracting key variables such as + account addresses, event keys, and strings representing the reason for the order being frozen. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - key + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - *tx_from + - *tx_to + - name: event_name + description: The type of event recorded, always 'OrderFrozen' for this model + tests: + - not_null + - *msg_sender + - name: key + description: The key associated with the frozen order. Extracted as a bytes32 value + tests: + - not_null + - name: account + description: The address associated with the order + - name: reason_bytes + description: The reason for the order being frozen in byte format. + tests: + - not_null + - name: reason + description: The reason for the order being frozen in string format. + tests: + - not_null + + + - name: gmx_v2_avalanche_c_order_updated + meta: + blockchain: avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['avalanche_c', 'gmx', 'event', 'order_updated'] + description: | + Extracts and decodes the `OrderUpdated` event log data from the Avalanche blockchain. + This model processes log entries related to updated orders, extracting key variables such as + account addresses, event keys, and strings representing the reason for cancellation. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - *tx_from + - *tx_to + - name: event_name + description: The type of event recorded, always 'OrderUpdated' for this model. + tests: + - not_null + - *msg_sender + - name: key + description: The key associated with the updated order. Extracted as a bytes32 value + tests: + - not_null + - name: market + description: The market in which the order was updated. + tests: + - not_null + - name: account + description: The address associated with the order. + - *size_delta_usd + - *trigger_price + - *acceptable_price + - *min_output_amount_raw + - *updated_at_time \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql index 79bf89a1d44..5e04a171406 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql @@ -275,7 +275,7 @@ WITH evt_data_1 AS ( END AS acceptable_price, execution_fee / POWER(10, 18) AS execution_fee, callback_gas_limit, - min_output_amount AS min_output_amount, + min_output_amount AS min_output_amount_raw, updated_at_block, CASE diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql new file mode 100644 index 00000000000..0de9538f4a7 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_frozen.sql @@ -0,0 +1,178 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'order_frozen', + materialized = 'table' + ) +}} + +{%- set event_name = 'OrderFrozen' -%} +{%- set blockchain_name = 'avalanche_c' -%} + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.bytesItems' OMIT QUOTES) AS bytes_items, + json_query(data, 'lax $.stringItems' OMIT QUOTES) AS string_items + + FROM + evt_data +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, bytes_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, string_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(string_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM bytes_items_parsed + UNION ALL + SELECT * + FROM string_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'key' THEN value END) AS key, + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'reasonBytes' THEN value END) AS reason_bytes, + MAX(CASE WHEN key_name = 'reason' THEN value END) AS reason + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, full_data AS ( + SELECT + blockchain, + block_time, + DATE(block_time) AS block_date, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(key) AS key, + from_hex(account) AS account, + from_hex(reason_bytes) AS reason_bytes, + reason + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql new file mode 100644 index 00000000000..1515489060d --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql @@ -0,0 +1,204 @@ +{{ + config( + schema = 'gmx_v2_avalanche_c', + alias = 'order_updated', + materialized = 'table' + ) +}} + +{%- set event_name = 'OrderUpdated' -%} +{%- set blockchain_name = 'avalanche_c' -%} + +WITH evt_data_1 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog1')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +, evt_data_2 AS ( + SELECT + -- Main Variables + '{{ blockchain_name }}' AS blockchain, + evt_block_time AS block_time, + evt_block_number AS block_number, + evt_tx_hash AS tx_hash, + evt_index AS index, + contract_address, + eventName AS event_name, + eventData AS data, + msgSender AS msg_sender + FROM {{ source('gmx_v2_avalanche_c','EventEmitter_evt_EventLog2')}} + WHERE eventName = '{{ event_name }}' + ORDER BY evt_block_time ASC +) + +-- unite 2 tables +, evt_data AS ( + SELECT * + FROM evt_data_1 + UNION DISTINCT + SELECT * + FROM evt_data_2 +) + +, parsed_data AS ( + SELECT + tx_hash, + index, + json_query(data, 'lax $.bytes32Items' OMIT QUOTES) AS bytes32_items, + json_query(data, 'lax $.addressItems' OMIT QUOTES) AS address_items, + json_query(data, 'lax $.uintItems' OMIT QUOTES) AS uint_items + FROM + evt_data +) + +, bytes32_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(bytes32_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, address_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(address_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, uint_items_parsed AS ( + SELECT + tx_hash, + index, + json_extract_scalar(CAST(item AS VARCHAR), '$.key') AS key_name, + json_extract_scalar(CAST(item AS VARCHAR), '$.value') AS value + FROM + parsed_data, + UNNEST( + CAST(json_extract(uint_items, '$.items') AS ARRAY(JSON)) + ) AS t(item) +) + +, combined AS ( + SELECT * + FROM bytes32_items_parsed + UNION ALL + SELECT * + FROM address_items_parsed + UNION ALL + SELECT * + FROM uint_items_parsed +) + +, evt_data_parsed AS ( + SELECT + tx_hash, + index, + MAX(CASE WHEN key_name = 'key' THEN value END) AS key, + MAX(CASE WHEN key_name = 'account' THEN value END) AS account, + MAX(CASE WHEN key_name = 'sizeDeltaUsd' THEN value END) AS size_delta_usd, + MAX(CASE WHEN key_name = 'acceptablePrice' THEN value END) AS acceptable_price, + MAX(CASE WHEN key_name = 'triggerPrice' THEN value END) AS trigger_price, + MAX(CASE WHEN key_name = 'minOutputAmount' THEN value END) AS min_output_amount, + MAX(CASE WHEN key_name = 'updatedAtTime' THEN value END) AS updated_at_time + FROM + combined + GROUP BY tx_hash, index +) + +-- full data +, event_data AS ( + SELECT + blockchain, + block_time, + block_number, + ED.tx_hash, + ED.index, + contract_address, + event_name, + msg_sender, + + from_hex(key) AS key, + from_hex(account) AS account, + TRY_CAST(size_delta_usd AS DOUBLE) AS size_delta_usd, + TRY_CAST(acceptable_price AS DOUBLE) AS acceptable_price, + TRY_CAST(trigger_price AS DOUBLE) AS trigger_price, + TRY_CAST(min_output_amount AS DOUBLE) AS min_output_amount, + TRY_CAST(updated_at_time AS DOUBLE) AS updated_at_time + + FROM evt_data AS ED + LEFT JOIN evt_data_parsed AS EDP + ON ED.tx_hash = EDP.tx_hash + AND ED.index = EDP.index +) + +-- full data +, full_data AS ( + SELECT + ED.blockchain, + ED.block_time, + DATE(ED.block_time) AS block_date, + ED.block_number, + ED.tx_hash, + ED.index, + ED.contract_address, + ED.event_name, + ED.msg_sender, + + ED.key, + OC.market, + ED.account, + ED.size_delta_usd / POWER(10, 30) AS size_delta_usd, + CASE + WHEN MD.index_token_decimals IS NULL THEN ED.acceptable_price / POWER(10, 30) + ELSE ED.acceptable_price / POWER(10, 30 - MD.index_token_decimals) + END AS acceptable_price, + CASE + WHEN MD.index_token_decimals IS NULL THEN ED.trigger_price / POWER(10, 30) + ELSE ED.trigger_price / POWER(10, 30 - MD.index_token_decimals) + END AS trigger_price, + ED.min_output_amount AS min_output_amount_raw, + CASE + WHEN ED.updated_at_time = 0 THEN NULL + ELSE ED.updated_at_time + END AS updated_at_time + + FROM event_data AS ED + LEFT JOIN {{ ref('gmx_v2_avalanche_c_order_created') }} AS OC + ON ED.key = OC.key + LEFT JOIN {{ ref('gmx_v2_avalanche_c_markets_data') }} AS MD + ON OC.market = MD.market + +) + +--can be removed once decoded tables are fully denormalized +{{ + add_tx_columns( + model_cte = 'full_data' + , blockchain = blockchain_name + , columns = ['from', 'to'] + ) +}} diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml index e39685590bc..ebc5d3b69fb 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml @@ -126,11 +126,13 @@ models: description: The change in initial collateral amount. tests: - not_null - - name: trigger_price + - &trigger_price + name: trigger_price description: The price that triggers the order execution. tests: - - not_null - - name: acceptable_price + - not_null + - &acceptable_price + name: acceptable_price description: The minimum acceptable price for order execution. tests: - not_null @@ -141,16 +143,18 @@ models: - name: callback_gas_limit description: The gas limit set for callback functions. tests: - - not_null - - name: min_output_amount + - not_null + - &min_output_amount_raw + name: min_output_amount_raw description: The minimum amount of output tokens expected from the order, based on the markets in the swap path. tests: - not_null - name: updated_at_block description: The block number at which the order was last updated. tests: - - not_null - - name: updated_at_time + - not_null + - &updated_at_time + name: updated_at_time description: The timestamp when the order was last updated. - &is_long name: is_long @@ -161,7 +165,8 @@ models: description: Boolean indicating if the native token should be unwrapped. - name: is_frozen description: Boolean indicating if the order is frozen. - - name: key + - &key + name: key description: The unique identifier for the order, stored as a bytes32 value. tests: - not_null @@ -196,11 +201,7 @@ models: tests: - not_null - *msg_sender - - name: key - description: The key associated with the executed order. Extracted as a bytes32 value. - tests: - - not_null - - unique + - *key - name: account description: The address associated with the order - name: secondary_order_type @@ -243,11 +244,7 @@ models: tests: - not_null - *msg_sender - - name: key - description: The key associated with the cancelled order. Extracted as a bytes32 value - tests: - - not_null - - unique + - *key - name: account description: The address associated with the order - name: reason_bytes @@ -818,4 +815,98 @@ models: - *is_increase - *order_key - *position_key - - *referral_code \ No newline at end of file + - *referral_code + + + - name: gmx_v2_order_frozen + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum','avalanche_c', 'gmx', 'event', 'order_frozen'] + description: | + Extracts and decodes the `OrderFrozen` event log data from the Arbitrum and Avalanche blockchains. + This model processes log entries related to frozen orders, extracting key variables such as + account addresses, event keys, and strings representing the reason for the order being frozen. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - key + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - *tx_from + - *tx_to + - name: event_name + description: The type of event recorded, always 'OrderFrozen' for this model + tests: + - not_null + - *msg_sender + - name: key + description: The key associated with the frozen order. Extracted as a bytes32 value + tests: + - not_null + - name: account + description: The address associated with the order + - name: reason_bytes + description: The reason for the order being frozen in byte format. + tests: + - not_null + - name: reason + description: The reason for the order being frozen in string format. + tests: + - not_null + + + - name: gmx_v2_order_updated + meta: + blockchain: arbitrum, avalanche_c + sector: dex + project: gmx + contributors: ai_data_master, gmx-io + config: + tags: ['arbitrum', 'avalanche_c', 'gmx', 'event', 'order_updated'] + description: | + Extracts and decodes the `OrderUpdated` event log data from the Arbitrum and Avalanche blockchains. + This model processes log entries related to updated orders, extracting key variables such as + account addresses, event keys, and strings representing the reason for cancellation. + + columns: + - *blockchain + - *block_time + - *block_date + - *block_number + - *tx_hash + - *index + - *contract_address + - *tx_from + - *tx_to + - name: event_name + description: The type of event recorded, always 'OrderUpdated' for this model. + tests: + - not_null + - *msg_sender + - name: key + description: The key associated with the updated order. Extracted as a bytes32 value + tests: + - not_null + - name: market + description: The market in which the order was updated. + tests: + - not_null + - name: account + description: The address associated with the order. + - *size_delta_usd + - *trigger_price + - *acceptable_price + - *min_output_amount_raw + - *updated_at_time \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql index 6356fd3f027..02bf92593fb 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql @@ -41,7 +41,7 @@ SELECT acceptable_price, execution_fee, callback_gas_limit, - min_output_amount, + min_output_amount_raw, updated_at_block, updated_at_time, is_long, diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_frozen.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_frozen.sql new file mode 100644 index 00000000000..50bf3e8686f --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_frozen.sql @@ -0,0 +1,37 @@ +{{ config( + schema='gmx_v2', + alias = 'order_frozen', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} + +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + key, + account, + reason_bytes, + reason +FROM {{ ref('gmx_v2_' ~ chain ~ '_order_cancelled') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql new file mode 100644 index 00000000000..48361db2c6d --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql @@ -0,0 +1,41 @@ +{{ config( + schema='gmx_v2', + alias = 'order_updated', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c"]\', + "project", + "gmx", + \'["ai_data_master","gmx-io"]\') }}' + ) +}} + +{%- set chains = [ + 'arbitrum', + 'avalanche_c', +] -%} +{%- for chain in chains -%} +SELECT + blockchain, + block_time, + block_date, + block_number, + tx_hash, + index, + contract_address, + tx_from, + tx_to, + event_name, + msg_sender, + key, + market, + account, + size_delta_usd, + acceptable_price, + trigger_price, + min_output_amount_raw, + updated_at_time + +FROM {{ ref('gmx_v2_' ~ chain ~ '_order_updated') }} +{% if not loop.last %} +UNION ALL +{% endif %} +{%- endfor -%} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql index b107f7ef61f..5c4682b2fe8 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/arbitrum/gmx_v2_arbitrum_markets_data.sql @@ -8,7 +8,11 @@ SELECT MCE.market_token AS market, - CONCAT(ERC20_IT.symbol, '/USD [', ERC20_LT.symbol, '-', ERC20_ST.symbol, ']') AS market_name, + CASE + WHEN MCE.index_token = 0x0000000000000000000000000000000000000000 + THEN CONCAT('SWAP-ONLY [', ERC20_LT.symbol, '-', ERC20_ST.symbol, ']') + ELSE CONCAT(ERC20_IT.symbol, '/USD [', ERC20_LT.symbol, '-', ERC20_ST.symbol, ']') + END AS market_name, 'GM' AS market_token_symbol, 18 AS market_token_decimals, ERC20_IT.symbol AS index_token_symbol, diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql index 7a55c753da4..c8fda944fb9 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/tokens/avalanche_c/gmx_v2_avalanche_c_markets_data.sql @@ -8,7 +8,11 @@ SELECT MCE.market_token AS market, - CONCAT(ERC20_IT.symbol, '/USD [', ERC20_LT.symbol, '-', ERC20_ST.symbol, ']') AS market_name, + CASE + WHEN MCE.index_token = 0x0000000000000000000000000000000000000000 + THEN CONCAT('SWAP-ONLY [', ERC20_LT.symbol, '-', ERC20_ST.symbol, ']') + ELSE CONCAT(ERC20_IT.symbol, '/USD [', ERC20_LT.symbol, '-', ERC20_ST.symbol, ']') + END AS market_name, 'GM' AS market_token_symbol, 18 AS market_token_decimals, ERC20_IT.symbol AS index_token_symbol, diff --git a/dbt_subprojects/daily_spellbook/package-lock.yml b/dbt_subprojects/daily_spellbook/package-lock.yml index c0962720778..9159e5ec7e2 100644 --- a/dbt_subprojects/daily_spellbook/package-lock.yml +++ b/dbt_subprojects/daily_spellbook/package-lock.yml @@ -1,4 +1,4 @@ packages: - package: dbt-labs/dbt_utils - version: 1.1.1 -sha1_hash: 23451c207c1d4dd71b5925f12a5cd66f2ebb2b3b + version: 1.3.0 +sha1_hash: e60f3271d7a9f853b7ff6316d14feb1341ef78ea From b7c34d52eedad88cb8a073d69b50c7bcc6a26842 Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:37:48 -0400 Subject: [PATCH 21/59] `dex.prices_beta` filter out trades without a trusted token (#6824) * filter out trades without a trusted token * fix alias --- .../dex/models/prices/dex_prices_beta.sql | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/dbt_subprojects/dex/models/prices/dex_prices_beta.sql b/dbt_subprojects/dex/models/prices/dex_prices_beta.sql index 477e7b3b862..558a1b946f7 100644 --- a/dbt_subprojects/dex/models/prices/dex_prices_beta.sql +++ b/dbt_subprojects/dex/models/prices/dex_prices_beta.sql @@ -10,22 +10,35 @@ with dex_trades as ( select distinct - blockchain - , block_time - , token_bought_address - , token_bought_amount_raw - , token_bought_amount - , token_sold_address - , token_sold_amount_raw - , token_sold_amount - , amount_usd + t.blockchain + , t.block_time + , t.token_bought_address + , t.token_bought_amount_raw + , t.token_bought_amount + , t.token_sold_address + , t.token_sold_amount_raw + , t.token_sold_amount + , t.amount_usd from - {{ ref('dex_trades') }} + {{ ref('dex_trades') }} as t where 1 = 1 - and amount_usd > 0 + and t.amount_usd > 0 + and exists ( + -- only output trades which contain a trusted token on either side of the trade + select + 1 + from + {{ source('prices', 'trusted_tokens') }} as tt + where + t.blockchain = tt.blockchain + and ( + t.token_bought_address = tt.contract_address + or t.token_sold_address = tt.contract_address + ) + ) {% if is_incremental() %} - and block_time > (select max(block_time) from {{ this }}) + and t.block_time > (select max(block_time) from {{ this }}) {% endif %} ), dex_bought as ( From e33cdce2bc0dd54dd00a0f08f7dce142f0c93552 Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Tue, 24 Sep 2024 18:05:58 -0400 Subject: [PATCH 22/59] flip to inner join (#6827) --- .../dex/models/prices/dex_prices_beta.sql | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/dbt_subprojects/dex/models/prices/dex_prices_beta.sql b/dbt_subprojects/dex/models/prices/dex_prices_beta.sql index 558a1b946f7..ed10f98454e 100644 --- a/dbt_subprojects/dex/models/prices/dex_prices_beta.sql +++ b/dbt_subprojects/dex/models/prices/dex_prices_beta.sql @@ -21,22 +21,16 @@ with dex_trades as ( , t.amount_usd from {{ ref('dex_trades') }} as t + inner join + {{ source('prices', 'trusted_tokens') }} as tt -- only output trades which contain a trusted token on either side of the trade + on t.blockchain = tt.blockchain + and ( + t.token_bought_address = tt.contract_address + or t.token_sold_address = tt.contract_address + ) where 1 = 1 and t.amount_usd > 0 - and exists ( - -- only output trades which contain a trusted token on either side of the trade - select - 1 - from - {{ source('prices', 'trusted_tokens') }} as tt - where - t.blockchain = tt.blockchain - and ( - t.token_bought_address = tt.contract_address - or t.token_sold_address = tt.contract_address - ) - ) {% if is_incremental() %} and t.block_time > (select max(block_time) from {{ this }}) {% endif %} From fbc99f72aab8414095efb713d706f767072862d7 Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Tue, 24 Sep 2024 19:04:38 -0400 Subject: [PATCH 23/59] Revert dex prices updates (#6829) * Revert "flip to inner join (#6827)" This reverts commit e33cdce2bc0dd54dd00a0f08f7dce142f0c93552. * Revert "`dex.prices_beta` filter out trades without a trusted token (#6824)" This reverts commit b7c34d52eedad88cb8a073d69b50c7bcc6a26842. --- .../dex/models/prices/dex_prices_beta.sql | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/dbt_subprojects/dex/models/prices/dex_prices_beta.sql b/dbt_subprojects/dex/models/prices/dex_prices_beta.sql index ed10f98454e..477e7b3b862 100644 --- a/dbt_subprojects/dex/models/prices/dex_prices_beta.sql +++ b/dbt_subprojects/dex/models/prices/dex_prices_beta.sql @@ -10,29 +10,22 @@ with dex_trades as ( select distinct - t.blockchain - , t.block_time - , t.token_bought_address - , t.token_bought_amount_raw - , t.token_bought_amount - , t.token_sold_address - , t.token_sold_amount_raw - , t.token_sold_amount - , t.amount_usd + blockchain + , block_time + , token_bought_address + , token_bought_amount_raw + , token_bought_amount + , token_sold_address + , token_sold_amount_raw + , token_sold_amount + , amount_usd from - {{ ref('dex_trades') }} as t - inner join - {{ source('prices', 'trusted_tokens') }} as tt -- only output trades which contain a trusted token on either side of the trade - on t.blockchain = tt.blockchain - and ( - t.token_bought_address = tt.contract_address - or t.token_sold_address = tt.contract_address - ) + {{ ref('dex_trades') }} where 1 = 1 - and t.amount_usd > 0 + and amount_usd > 0 {% if is_incremental() %} - and t.block_time > (select max(block_time) from {{ this }}) + and block_time > (select max(block_time) from {{ this }}) {% endif %} ), dex_bought as ( From 2f0312e886e294e659e5ce5ab069b3418f245ffa Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Tue, 24 Sep 2024 19:33:41 -0400 Subject: [PATCH 24/59] exclude failing model (#6830) --- .../models/_projects/odos/optimism/odos_v1_optimism_trades.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/models/_projects/odos/optimism/odos_v1_optimism_trades.sql b/dbt_subprojects/dex/models/_projects/odos/optimism/odos_v1_optimism_trades.sql index 786d86c388e..1c05f62dbaa 100644 --- a/dbt_subprojects/dex/models/_projects/odos/optimism/odos_v1_optimism_trades.sql +++ b/dbt_subprojects/dex/models/_projects/odos/optimism/odos_v1_optimism_trades.sql @@ -1,5 +1,6 @@ {{ config( - schema = 'odos_v1_optimism' + tags = ['prod_exclude'] + ,schema = 'odos_v1_optimism' ,alias = 'trades' ,materialized = 'incremental' ,file_format = 'delta' From 84f62f406160534c26c879b76492c1d30c7f3a12 Mon Sep 17 00:00:00 2001 From: AIDataMaster Date: Wed, 25 Sep 2024 18:39:28 +0300 Subject: [PATCH 25/59] Upgrade OrderCreated and OrderUpdated Event Models (GMX) (#6833) * Update OrderCreated and OrderUpdated Event Models * Renamed column names --- .../arbitrum/gmx_v2_arbitrum_event_schema.yml | 20 ++++++++----------- .../gmx_v2_arbitrum_order_created.sql | 8 ++++---- .../gmx_v2_arbitrum_order_updated.sql | 8 ++++---- .../gmx_v2_avalanche_c_event_schema.yml | 20 ++++++++----------- .../gmx_v2_avalanche_c_order_created.sql | 8 ++++---- .../gmx_v2_avalanche_c_order_updated.sql | 8 ++++---- .../gmx/event/gmx_v2_event_schema.yml | 20 ++++++++----------- .../gmx/event/gmx_v2_order_created.sql | 4 ++-- .../gmx/event/gmx_v2_order_updated.sql | 4 ++-- 9 files changed, 44 insertions(+), 56 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml index d4cbca2f796..a9a096600cc 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_event_schema.yml @@ -126,16 +126,12 @@ models: description: The change in initial collateral amount. tests: - not_null - - &trigger_price - name: trigger_price - description: The price that triggers the order execution. - tests: - - not_null - - &acceptable_price - name: acceptable_price - description: The minimum acceptable price for order execution. - tests: - - not_null + - &trigger_price_raw + name: trigger_price_raw + description: The price that triggers the order execution. + - &acceptable_price_raw + name: acceptable_price_raw + description: The minimum acceptable price for order execution. - name: execution_fee description: The fee paid for executing the order in native tokens tests: @@ -906,7 +902,7 @@ models: - name: account description: The address associated with the order. - *size_delta_usd - - *trigger_price - - *acceptable_price + - *trigger_price_raw + - *acceptable_price_raw - *min_output_amount_raw - *updated_at_time \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql index 632bfaee161..503c46f61a8 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_created.sql @@ -266,13 +266,13 @@ WITH evt_data_1 AS ( size_delta_usd / POWER(10, 30) AS size_delta_usd, initial_collateral_delta_amount / POWER(10, collateral_token_decimals) AS initial_collateral_delta_amount, CASE - WHEN index_token_decimals IS NULL THEN trigger_price / POWER(10, 30) + WHEN index_token_decimals IS NULL THEN NULL ELSE trigger_price / POWER(10, 30 - index_token_decimals) - END AS trigger_price, + END AS trigger_price_raw, CASE - WHEN index_token_decimals IS NULL THEN acceptable_price / POWER(10, 30) + WHEN index_token_decimals IS NULL THEN NULL ELSE acceptable_price / POWER(10, 30 - index_token_decimals) - END AS acceptable_price, + END AS acceptable_price_raw, execution_fee / POWER(10, 18) AS execution_fee, callback_gas_limit, min_output_amount AS min_output_amount_raw, diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql index 85af3142f28..cbb9c0da7e1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/arbitrum/gmx_v2_arbitrum_order_updated.sql @@ -173,13 +173,13 @@ WITH evt_data_1 AS ( ED.account, ED.size_delta_usd / POWER(10, 30) AS size_delta_usd, CASE - WHEN MD.index_token_decimals IS NULL THEN ED.acceptable_price / POWER(10, 30) + WHEN MD.index_token_decimals IS NULL THEN NULL ELSE ED.acceptable_price / POWER(10, 30 - MD.index_token_decimals) - END AS acceptable_price, + END AS acceptable_price_raw, CASE - WHEN MD.index_token_decimals IS NULL THEN ED.trigger_price / POWER(10, 30) + WHEN MD.index_token_decimals IS NULL THEN NULL ELSE ED.trigger_price / POWER(10, 30 - MD.index_token_decimals) - END AS trigger_price, + END AS trigger_price_raw, ED.min_output_amount AS min_output_amount_raw, CASE WHEN ED.updated_at_time = 0 THEN NULL diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml index e2845ea5e81..c1c2ee3a4c3 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_event_schema.yml @@ -126,16 +126,12 @@ models: description: The change in initial collateral amount. tests: - not_null - - &trigger_price - name: trigger_price - description: The price that triggers the order execution. - tests: - - not_null - - &acceptable_price - name: acceptable_price - description: The minimum acceptable price for order execution. - tests: - - not_null + - &trigger_price_raw + name: trigger_price_raw + description: The price that triggers the order execution. + - &acceptable_price_raw + name: acceptable_price_raw + description: The minimum acceptable price for order execution. - name: execution_fee description: The fee paid for executing the order in native tokens tests: @@ -906,7 +902,7 @@ models: - name: account description: The address associated with the order. - *size_delta_usd - - *trigger_price - - *acceptable_price + - *trigger_price_raw + - *acceptable_price_raw - *min_output_amount_raw - *updated_at_time \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql index 5e04a171406..57c13a4488c 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_created.sql @@ -266,13 +266,13 @@ WITH evt_data_1 AS ( size_delta_usd / POWER(10, 30) AS size_delta_usd, initial_collateral_delta_amount / POWER(10, collateral_token_decimals) AS initial_collateral_delta_amount, CASE - WHEN index_token_decimals IS NULL THEN trigger_price / POWER(10, 30) + WHEN index_token_decimals IS NULL THEN NULL ELSE trigger_price / POWER(10, 30 - index_token_decimals) - END AS trigger_price, + END AS trigger_price_raw, CASE - WHEN index_token_decimals IS NULL THEN acceptable_price / POWER(10, 30) + WHEN index_token_decimals IS NULL THEN NULL ELSE acceptable_price / POWER(10, 30 - index_token_decimals) - END AS acceptable_price, + END AS acceptable_price_raw, execution_fee / POWER(10, 18) AS execution_fee, callback_gas_limit, min_output_amount AS min_output_amount_raw, diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql index 1515489060d..3199683750c 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/avalanche_c/gmx_v2_avalanche_c_order_updated.sql @@ -173,13 +173,13 @@ WITH evt_data_1 AS ( ED.account, ED.size_delta_usd / POWER(10, 30) AS size_delta_usd, CASE - WHEN MD.index_token_decimals IS NULL THEN ED.acceptable_price / POWER(10, 30) + WHEN MD.index_token_decimals IS NULL THEN NULL ELSE ED.acceptable_price / POWER(10, 30 - MD.index_token_decimals) - END AS acceptable_price, + END AS acceptable_price_raw, CASE - WHEN MD.index_token_decimals IS NULL THEN ED.trigger_price / POWER(10, 30) + WHEN MD.index_token_decimals IS NULL THEN NULL ELSE ED.trigger_price / POWER(10, 30 - MD.index_token_decimals) - END AS trigger_price, + END AS trigger_price_raw, ED.min_output_amount AS min_output_amount_raw, CASE WHEN ED.updated_at_time = 0 THEN NULL diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml index ebc5d3b69fb..11a605db364 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_event_schema.yml @@ -126,16 +126,12 @@ models: description: The change in initial collateral amount. tests: - not_null - - &trigger_price - name: trigger_price - description: The price that triggers the order execution. - tests: - - not_null - - &acceptable_price - name: acceptable_price - description: The minimum acceptable price for order execution. - tests: - - not_null + - &trigger_price_raw + name: trigger_price_raw + description: The price that triggers the order execution. + - &acceptable_price_raw + name: acceptable_price_raw + description: The minimum acceptable price for order execution. - name: execution_fee description: The fee paid for executing the order in native tokens tests: @@ -906,7 +902,7 @@ models: - name: account description: The address associated with the order. - *size_delta_usd - - *trigger_price - - *acceptable_price + - *trigger_price_raw + - *acceptable_price_raw - *min_output_amount_raw - *updated_at_time \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql index 02bf92593fb..1b8e9f5f5e1 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_created.sql @@ -37,8 +37,8 @@ SELECT decrease_position_swap_type, size_delta_usd, initial_collateral_delta_amount, - trigger_price, - acceptable_price, + trigger_price_raw, + acceptable_price_raw, execution_fee, callback_gas_limit, min_output_amount_raw, diff --git a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql index 48361db2c6d..ab790d79396 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/gmx/event/gmx_v2_order_updated.sql @@ -29,8 +29,8 @@ SELECT market, account, size_delta_usd, - acceptable_price, - trigger_price, + acceptable_price_raw, + trigger_price_raw, min_output_amount_raw, updated_at_time From da77ca33076cf496846a89abe052092e025c7c4c Mon Sep 17 00:00:00 2001 From: tomfutago <35136350+tomfutago@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:39:41 +0100 Subject: [PATCH 26/59] Nexus Mutual - staking updates (#3) (#6821) * fix: reset product_id as non-nullable * feat: add tranche expiry date & chain level, output full history * docs: add new columns to schema.yml * trigger re-run --- .../models/nexusmutual/ethereum/staking/_schema.yml | 5 +++++ .../staking/nexusmutual_ethereum_base_staking_pools.sql | 4 ++-- .../nexusmutual_ethereum_staking_deposit_extensions.sql | 8 ++++++-- .../staking/nexusmutual_ethereum_staking_pools.sql | 7 ++++--- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/_schema.yml b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/_schema.yml index e36496a3bee..468841a72ee 100644 --- a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/_schema.yml @@ -206,6 +206,11 @@ models: description: "current staking tranche period (most recent one in the chain of extensions)" - name: total_amount description: "total staking amount (initial deposit + all top-up amounts)" + - *tranche_expiry_date - *is_active + - name: chain_level + description: "chain (recursion) level" + - name: token_tranche_rn + description: "descending row number per pool, token & tranche" - *evt_index - *tx_hash diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_base_staking_pools.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_base_staking_pools.sql index 1bd487e9e6b..0ebf657ee4e 100644 --- a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_base_staking_pools.sql +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_base_staking_pools.sql @@ -104,7 +104,7 @@ staking_pool_products_combined as ( spp.block_time_created, spu.block_time_updated, coalesce(spp.pool_id, spu.pool_id) as pool_id, - coalesce(spp.product_id, spu.product_id) as product_id, + coalesce(spp.product_id, spu.product_id, -1) as product_id, spp.initial_price, spp.target_price, spu.target_price as updated_target_price, @@ -200,7 +200,7 @@ staking_pool_fee_updates as ( products as ( select - p.product_id, + cast(p.product_id as int) as product_id, p.product_name, pt.product_type_id, pt.product_type_name as product_type diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_extensions.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_extensions.sql index 2836497589b..58aefb450ff 100644 --- a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_extensions.sql +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_extensions.sql @@ -11,7 +11,7 @@ ) }} -with recursive deposit_chain (pool_address, token_id, tranche_id, new_tranche_id, total_amount, block_time, is_active, evt_index, tx_hash, chain_level) as ( +with recursive deposit_chain (pool_address, token_id, tranche_id, new_tranche_id, total_amount, block_time, tranche_expiry_date, is_active, evt_index, tx_hash, chain_level) as ( select pool_address, token_id, @@ -19,6 +19,7 @@ with recursive deposit_chain (pool_address, token_id, tranche_id, new_tranche_id tranche_id as new_tranche_id, sum(amount) as total_amount, max(block_time) as block_time, + max_by(tranche_expiry_date, block_time) as tranche_expiry_date, max_by(is_active, block_time) as is_active, max_by(evt_index, block_time) as evt_index, max_by(tx_hash, block_time) as tx_hash, @@ -36,6 +37,7 @@ with recursive deposit_chain (pool_address, token_id, tranche_id, new_tranche_id d.new_tranche_id, dc.total_amount + coalesce(d.topup_amount, 0) as total_amount, d.block_time, + d.tranche_expiry_date, d.is_active, d.evt_index, d.tx_hash, @@ -54,7 +56,10 @@ select tranche_id as init_tranche_id, new_tranche_id as current_tranche_id, total_amount, + tranche_expiry_date, is_active, + chain_level, + rn as token_tranche_rn, evt_index, tx_hash from ( @@ -63,4 +68,3 @@ from ( row_number() over (partition by pool_address, token_id, tranche_id order by chain_level desc) as rn from deposit_chain ) t -where rn = 1 diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_pools.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_pools.sql index ad21b3e3559..adce06fa39c 100644 --- a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_pools.sql +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_pools.sql @@ -38,6 +38,7 @@ select tx_hash_created, tx_hash_updated from {{ ref('nexusmutual_ethereum_base_staking_pools') }} -{% if is_incremental() %} -where {{ incremental_predicate('block_time_updated') }} -{% endif %} +where true + {% if is_incremental() %} + and {{ incremental_predicate('block_time_updated') }} + {% endif %} From 5b26a3a552005c270d16473ba87e6546f7a62782 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:45:20 -0300 Subject: [PATCH 27/59] add missing tokens to tokens.erc20 (#6834) --- .../tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql b/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql index 3231c9df4d3..9a4beed6aee 100644 --- a/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql @@ -112,4 +112,9 @@ FROM (VALUES , (0x9aee3c99934c88832399d6c6e08ad802112ebeab, 'FU', 18) , (0xe47ba52f326806559c1dec7ddd997f6957d0317d, 'SHELL', 18) , (0x79ead7a012d97ed8deece279f9bc39e264d7eef9, 'Bonsai', 18) + , (0x8b65c028b223b83b13fcf1d1f0873320e6cab132, 'UPDOGE', 18) + , (0x8d7c2588c365b9e98ea464b63dbccdf13ecd9809, 'AI', 18) + , (0xd2cc61a36c31425b3eb9bbeecce74a82a2e32e27, 'RATS', 18) + , (0x27f485b62c4a7e635f561a87560adf5090239e93, 'DFX', 18) + , (0x39a49bc5017fc668299cd32e734c9269acc35295, 'PHONON', 18) ) AS temp_table (contract_address, symbol, decimals) From 869051c364b1840e8c0ba5aaec4f10891dc1e6ae Mon Sep 17 00:00:00 2001 From: max-morrow Date: Wed, 25 Sep 2024 18:51:35 +0300 Subject: [PATCH 28/59] added columns to project_orders linage (#6793) added tx_from & tx_to --- .../models/_projects/oneinch/oneinch_project_orders.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/oneinch_project_orders.sql b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/oneinch_project_orders.sql index 10c5ba818e2..8b781421029 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/oneinch/oneinch_project_orders.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/oneinch/oneinch_project_orders.sql @@ -17,6 +17,8 @@ 'block_number', 'block_time', 'tx_hash', + 'tx_from', + 'tx_to', 'method', 'call_selector', 'call_trace_address', @@ -125,6 +127,8 @@ meta as ( , coalesce(order_hash, concat(tx_hash, to_big_endian_32(cast(counter as int)))) as order_hash , call_trade , any_value(block_time) as block_time + , any_value(tx_from) as tx_from + , any_value(tx_to) as tx_to , any_value(project) as project , any_value(call_selector) as call_selector , any_value(call_from) as call_from @@ -160,6 +164,8 @@ select , block_number , block_time , tx_hash + , tx_from + , tx_to , project , call_trace_address , call_selector From 5f769145a37d7855758137b8d801b3d23e34974b Mon Sep 17 00:00:00 2001 From: max-morrow Date: Wed, 25 Sep 2024 18:51:46 +0300 Subject: [PATCH 29/59] 1inch-U44: updates for fusion_executors (#6823) * updated fusion_executors added fusion+ executors promotions * fix * fix * fix * updated oneinch.blockchains * neat * cosmetic --- .../oneinch/_meta/oneinch_blockchains.sql | 19 +++++++++++++++++-- .../_meta/oneinch_fusion_executors.sql | 13 +++++++++---- .../dex/models/_projects/oneinch/_schema.yml | 2 ++ .../ethereum/oneinch_ethereum_sources.yml | 1 + 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/dbt_subprojects/dex/models/_projects/oneinch/_meta/oneinch_blockchains.sql b/dbt_subprojects/dex/models/_projects/oneinch/_meta/oneinch_blockchains.sql index d14b6444660..7e491baf44e 100644 --- a/dbt_subprojects/dex/models/_projects/oneinch/_meta/oneinch_blockchains.sql +++ b/dbt_subprojects/dex/models/_projects/oneinch/_meta/oneinch_blockchains.sql @@ -7,9 +7,24 @@ ) }} +{% set + blockchains = [ + 'ethereum', + 'bnb', + 'polygon', + 'arbitrum', + 'optimism', + 'avalanche_c', + 'gnosis', + 'fantom', + 'base', + 'zksync', + 'aurora', + 'klaytn', + ] +%} - -{% for blockchain in oneinch_exposed_blockchains_list() %} +{% for blockchain in blockchains %} {{ oneinch_blockchain_macro(blockchain) }} {% if not loop.last %} union all {% endif %} {% endfor %} diff --git a/dbt_subprojects/dex/models/_projects/oneinch/_meta/oneinch_fusion_executors.sql b/dbt_subprojects/dex/models/_projects/oneinch/_meta/oneinch_fusion_executors.sql index 20229c73a92..3c3108a8378 100644 --- a/dbt_subprojects/dex/models/_projects/oneinch/_meta/oneinch_fusion_executors.sql +++ b/dbt_subprojects/dex/models/_projects/oneinch/_meta/oneinch_fusion_executors.sql @@ -14,25 +14,30 @@ executors as ( promoter as resolver_address , promotee as resolver_executor , chainId as chain_id + , mode , min(evt_block_time) as first_promoted_at , max(evt_block_time) as last_promoted_at from ( - select promoter, promotee, chainId, evt_block_time + select promoter, promotee, chainId, evt_block_time, 'intra_chain' as mode from {{ source('oneinch_ethereum', 'FusionWhitelistRegistryV1_evt_Promotion') }} union all - select promoter, promotee, chainId, evt_block_time + select promoter, promotee, chainId, evt_block_time, 'intra_chain' as mode from {{ source('oneinch_ethereum', 'FusionWhitelistRegistryV2_evt_Promotion') }} + union all + select promoter, promotee, chainId, evt_block_time, 'cross_chain' as mode + from {{ source('oneinch_ethereum', 'CrosschainWhitelistRegistryV1_evt_Promotion') }} ) - group by 1, 2, 3 + group by 1, 2, 3, 4 ) -- output -- -select +select blockchain , resolver_address , resolver_executor , chain_id + , mode , first_promoted_at , last_promoted_at from executors diff --git a/dbt_subprojects/dex/models/_projects/oneinch/_schema.yml b/dbt_subprojects/dex/models/_projects/oneinch/_schema.yml index 8f961c8908c..8b8262bde46 100644 --- a/dbt_subprojects/dex/models/_projects/oneinch/_schema.yml +++ b/dbt_subprojects/dex/models/_projects/oneinch/_schema.yml @@ -500,6 +500,7 @@ models: - dbt_utils.unique_combination_of_columns: combination_of_columns: - chain_id + - resolver_address - resolver_executor columns: - name: resolver_address @@ -511,6 +512,7 @@ models: - name: chain_id tests: - not_null + - name: mode - name: first_promoted_at - name: last_promoted_at diff --git a/sources/oneinch/ethereum/oneinch_ethereum_sources.yml b/sources/oneinch/ethereum/oneinch_ethereum_sources.yml index f8581952947..84fe9496058 100644 --- a/sources/oneinch/ethereum/oneinch_ethereum_sources.yml +++ b/sources/oneinch/ethereum/oneinch_ethereum_sources.yml @@ -64,6 +64,7 @@ sources: - name: FusionWhitelistRegistryV2_evt_Registered - name: FusionWhitelistRegistryV2_evt_Unregistered - name: FusionWhitelistRegistryV2_evt_Promotion + - name: CrosschainWhitelistRegistryV1_evt_Promotion - name: AggregationRouterV6_call_swap - name: AggregationRouterV6_call_clipperSwap - name: AggregationRouterV6_call_clipperSwapTo From fe376e187f620cc3ad15e5230835065e14861817 Mon Sep 17 00:00:00 2001 From: Eduard Gorkh <40689054+grkhr@users.noreply.github.com> Date: Wed, 25 Sep 2024 18:51:56 +0300 Subject: [PATCH 30/59] dex raw pools: add fee column (#6820) * implement fee * apply easy date * Revert "apply easy date" This reverts commit dfb8e2a532c2240d5fd5b66e92ba5a783e73c4b7. * v2 fee * Reapply "apply easy date" This reverts commit 6e974313fba0fc6a0fa57dcf585f6206f80f4884. * Revert "Reapply "apply easy date"" This reverts commit 2e7d6e15f1fbc932d6cc9f8fa389078888144b87. --- dbt_subprojects/dex/models/pools/_schema.yml | 8 +++++--- .../dex/models/pools/dex_raw_pool_creations.sql | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dbt_subprojects/dex/models/pools/_schema.yml b/dbt_subprojects/dex/models/pools/_schema.yml index 2509126abe0..7b0eec51be6 100644 --- a/dbt_subprojects/dex/models/pools/_schema.yml +++ b/dbt_subprojects/dex/models/pools/_schema.yml @@ -69,6 +69,9 @@ models: - &tokens name: tokens description: "Tokens in the pool" + - &fee + name: fee + description: "Defined fee" - &creation_block_time name: creation_block_time description: "Block time of pool creation" @@ -101,6 +104,7 @@ models: - *token0 - *token1 - *tokens + - *fee - *creation_block_time - *creation_block_number - name: contract_address @@ -127,9 +131,7 @@ models: description: "Project name of the DEX" - *version - *pool - - &fee - name: fee - description: "Defined fee" + - *fee - *token0 - *token1 - *creation_block_time diff --git a/dbt_subprojects/dex/models/pools/dex_raw_pool_creations.sql b/dbt_subprojects/dex/models/pools/dex_raw_pool_creations.sql index 28c7161171c..5ba5991f3f6 100644 --- a/dbt_subprojects/dex/models/pools/dex_raw_pool_creations.sql +++ b/dbt_subprojects/dex/models/pools/dex_raw_pool_creations.sql @@ -58,24 +58,28 @@ 'version': 'Factory V1 Plain', 'tokens_position': 4 + 1 + 32 * 2, 'tokens_count': 4, + 'fee_position': 4 + 1 + 32 * 7, }, '0xd4b9e214': { 'type': 'curve_compatible', 'version': 'Factory V1 Plain', 'tokens_position': 4 + 1 + 32 * 2, 'tokens_count': 4, + 'fee_position': 4 + 1 + 32 * 7, }, '0xcd419bb5': { 'type': 'curve_compatible', 'version': 'Factory V1 Plain', 'tokens_position': 4 + 1 + 32 * 2, 'tokens_count': 4, + 'fee_position': 4 + 1 + 32 * 7, }, '0x5c16487b': { 'type': 'curve_compatible', 'version': 'Factory V1 Plain', 'tokens_position': 4 + 1 + 32 * 2, 'tokens_count': 4, + 'fee_position': 4 + 1 + 32 * 7, }, '0xc955fa04': { @@ -83,6 +87,7 @@ 'version': 'Factory V2', 'tokens_position': 4 + 1 + 32 * 2, 'tokens_count': 2, + 'fee_position': 4 + 1 + 32 * 4, }, '0xaa38b385': { 'type': 'curve_compatible', @@ -96,9 +101,8 @@ 'version': 'Factory V1 Plain Stableswap', 'tokens_position': 4 + 1 + 32 * 16, 'tokens_count': 8, + 'fee_position': 4 + 1 + 32 * 4, }, - - } %} @@ -157,6 +161,7 @@ uniswap_pool_created_logs as ( , substr(data, {{ data.pool_position }}, 20) as pool , substr(topic1, 13) as token0 , substr(topic2, 13) as token1 + , coalesce(bytearray_to_uint256(topic3), uint256 '3000') as fee , block_number , block_time , contract_address @@ -184,6 +189,7 @@ uniswap_pool_created_logs as ( , substr(output, 13, 20) as pool , trace_address , transform(sequence(1, 32 * {{ data.tokens_count }}, 32), x -> substr(substr(substr(input, {{ data.tokens_position }}, 32 * {{ data.tokens_count }}), x, 32), 13)) tokens + , {% if data.fee_position %} bytearray_to_uint256(substr(input, {{ data.fee_position }}, 32)) {% else %} cast(null as uint256) {% endif %} as fee , block_number , block_time , "to" as contract_address @@ -262,6 +268,7 @@ uniswap_pool_created_logs as ( , token0 , token1 , array[token0, token1] as tokens + , cast(fee as uint256) as fee , creation_block_time , creation_block_number , contract_address @@ -281,6 +288,7 @@ uniswap_pool_created_logs as ( , token0 , token1 , array[token0, token1] as tokens + , fee , block_time , block_number , contract_address @@ -297,6 +305,7 @@ uniswap_pool_created_logs as ( , tokens[1] as token0 , tokens[2] as token1 , tokens + , fee , block_time , block_number , contract_address @@ -314,6 +323,7 @@ uniswap_pool_created_logs as ( , token0 , token1 , tokens + , fee , block_time as creation_block_time , block_number as creation_block_number , contract_address From e111c62712e8f53d43974fa2eed1a06e1f566f31 Mon Sep 17 00:00:00 2001 From: Rantum Date: Wed, 25 Sep 2024 09:08:25 -0700 Subject: [PATCH 31/59] zeroex - add blast trades (#6786) * add mantle & blast to cross-chain spell * add seed * add seed * remove nft changes * restore nft schema changes * restore nft schema changes * restore nft schema changes * restore nft schema changes * add seed file * add blast model files * revise to use nft.transfers - not nft_blast.transfers --- .../zeroex/blast/zeroex_blast_schema.yml | 111 +++++++ .../blast/zeroex_blast_settler_trades.sql | 296 ++++++++++++++++++ .../zeroex/zeroex_api_fills_deduped.sql | 1 + .../models/_projects/zeroex/zeroex_schema.yml | 4 +- .../seeds/_project/zeroex/blast/_schema.yml | 11 + .../zeroex_blast_settler_trades_sample.csv | 3 + 6 files changed, 424 insertions(+), 2 deletions(-) create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml create mode 100644 dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql create mode 100644 dbt_subprojects/dex/seeds/_project/zeroex/blast/_schema.yml create mode 100644 dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml new file mode 100644 index 00000000000..d427aa5c7c2 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_schema.yml @@ -0,0 +1,111 @@ +version: 2 + +models: + - name: zeroex_blast_settler_trades + meta: + blockchain: blast + project: zeroex + contributors: rantum + config: + tags: ['blast','0x','dex_aggregator','dex','aggregator'] + description: > + 0x API erc20 trades through 0x Settler contracts. No fills, only deduped transactions. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_month + - block_date + - tx_hash + - evt_index + - check_seed: + seed_file: ref('zeroex_blast_settler_trades_sample') + match_columns: + - tx_hash + check_columns: + - taker + - maker_token + - taker_token + columns: + - &blockchain + name: blockchain + description: "Blockchain which the aggregator project is deployed" + - &block_date + name: block_date + description: "UTC event block date of each trade" + - &block_month + name: block_month + description: "UTC event block month of each trade" + - &block_time + name: block_time + description: "UTC event block time of each trade" + - &taker_symbol + name: taker_symbol + description: "Symbol of the token taker sells" + - &maker_symbol + name: maker_symbol + description: "Symbol of the token taker buys" + - &token_pair + name: token_pair + description: "Token pair traded" + - &taker_token_amount + name: taker_token_amount + description: "The after-decimal amount of the token taker sells" + - &taker_token_amount_raw + name: taker_token_amount_raw + description: "The raw amount of the token taker sells" + - &maker_token_amount + name: maker_token_amount + description: "The after-decimal amount of the token taker buys" + - &maker_token_amount_raw + name: maker_token_amount_raw + description: "The raw amount of the token taker buys" + - &volume_usd + name: volume_usd + description: "Trading volume measured in USD value" + - &taker_token + name: taker_token + description: "Contract address of the token taker sells" + - &maker_token + name: maker_token + description: "Contract address of the token taker buys" + - &maker + name: maker + description: "buyer of the trade" + - &taker + name: taker + description: "seller of the trade" + - &affiliate_address + name: affiliate_address + description: "The recipient address of the affiliate, or the applications that is using 0x API, for receiving affiliate fee" + - &tx_hash + name: tx_hash + description: "Transaction hash of the fill" + - &tx_from + name: tx_from + description: "Address which initiated the trade" + - &tx_to + name: tx_to + description: "Address which received the trade" + - &evt_index + name: evt_index + description: "Index of the corresponding order filled event" + - &type + name: type + description: "The liquidity route the order went thru" + - &swap_flag + name: swap_flag + description: "If the swap was filled/consumed thru 0x API" + - &contract_address + name: contract_address + desctiption: "The address of the contract which fired the fill/swap event" + - &fills_within + name: fills_within + description: "fills in then multihop, if present" + + + + + + + + \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql new file mode 100644 index 00000000000..1b741a62f5c --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/zeroex/blast/zeroex_blast_settler_trades.sql @@ -0,0 +1,296 @@ +{{ config( + schema = 'zeroex_blast', + alias = 'settler_trades', + materialized='incremental', + partition_by = ['block_month'], + unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'], + on_schema_change='sync_all_columns', + file_format ='delta', + incremental_strategy='merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] +)}} + +{% set zeroex_settler_start_date = '2024-07-15' %} + +WITH tbl_addresses AS ( + SELECT + blockchain, + token_id, + to AS settler_address, + block_time AS begin_block_time, + block_number AS begin_block_number + FROM + {{ source('nft', 'transfers') }} + WHERE + contract_address = 0x00000000000004533fe15556b1e086bb1a72ceae + AND blockchain = 'blast' + and block_time > TIMESTAMP '2024-05-23' +), + +tbl_end_times AS ( + SELECT + *, + LEAD(begin_block_time) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_time) AS end_block_time, + LEAD(begin_block_number) OVER (PARTITION BY blockchain, token_id ORDER BY begin_block_number) AS end_block_number + FROM + tbl_addresses +), + +result_0x_settler_addresses AS ( + SELECT + * + FROM + tbl_end_times + WHERE + settler_address != 0x0000000000000000000000000000000000000000 +), + +settler_txs AS ( + SELECT + tx_hash, + block_time, + block_number, + method_id, + contract_address, + settler_address, + MAX(varbinary_substring(tracker,2,12)) AS zid, + CASE + WHEN method_id = 0x1fff991f THEN MAX(varbinary_substring(tracker,14,3)) + WHEN method_id = 0xfd3ad6d4 THEN MAX(varbinary_substring(tracker,13,3)) + END AS tag + FROM ( + SELECT + tr.tx_hash, + block_number, + block_time, + "to" AS contract_address, + varbinary_substring(input,1,4) AS method_id, + varbinary_substring(input,varbinary_position(input,0xfd3ad6d4)+132,32) tracker, + a.settler_address + FROM + {{ source('blast', 'traces') }} AS tr + JOIN + result_0x_settler_addresses a ON a.settler_address = tr.to AND a.blockchain = 'blast' AND tr.block_time > a.begin_block_time + WHERE + (a.settler_address IS NOT NULL OR tr.to = 0xca11bde05977b3631167028862be2a173976ca11) + AND varbinary_substring(input,1,4) IN (0x1fff991f, 0xfd3ad6d4) + {% if is_incremental() %} + AND {{ incremental_predicate('block_time') }} + {% else %} + AND block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + GROUP BY + 1,2,3,4,5,6 +), +tbl_trades as ( + +with tbl_all_logs AS ( + SELECT + logs.tx_hash, + logs.block_time, + logs.block_number, + index, + coalesce(bytearray_substring(logs.topic2,13,20), first_value(bytearray_substring(logs.topic1,13,20)) over (partition by logs.tx_hash order by index) ) as taker, + logs.contract_address as maker_token, + first_value(logs.contract_address) over (partition by logs.tx_hash order by index) as taker_token, + first_value(try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) ) over (partition by logs.tx_hash order by index) as taker_amount, + try_cast(bytearray_to_uint256(bytearray_substring(DATA, 22,11)) as int256) as maker_amount, + method_id, + tag, + st.settler_address, + zid, + st.settler_address as contract_address + FROM + {{ source('blast', 'logs') }} AS logs + JOIN + settler_txs st ON st.tx_hash = logs.tx_hash AND logs.block_time = st.block_time AND st.block_number = logs.block_number + + WHERE + topic0 IN ( 0x7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65, + 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef, + 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c ) + and topic1 != 0x0000000000000000000000000000000000000000000000000000000000000000 + and zid != 0xa00000000000000000000000 + {% if is_incremental() %} + AND {{ incremental_predicate('logs.block_time') }} + {% else %} + AND logs.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ), + tbl_valid_logs as ( + select * + , row_number() over (partition by tx_hash order by index desc) rn + from tbl_all_logs + where maker_token != taker_token + ) + select * from tbl_valid_logs + where rn = 1 +), + + +tokens AS ( + with token_list as ( + select + distinct maker_token as token + from + tbl_trades + + union distinct + + select + distinct taker_token as token + from tbl_trades + ) + + select * + from + token_list tl + join + {{ source('tokens', 'erc20') }} AS te ON te.contract_address = tl.token + WHERE + te.blockchain = 'blast' +), + +prices AS ( + SELECT DISTINCT + pu.* + FROM + {{ source('prices', 'usd') }} AS pu + JOIN + tbl_trades ON (pu.contract_address = taker_token OR pu.contract_address = maker_token) AND date_trunc('minute',block_time) = minute + WHERE + pu.blockchain = 'blast' + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +fills as ( + with signatures as ( + select distinct signature + from {{ source('blast', 'logs_decoded') }} l + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + and event_name in ('TokenExchange', 'OtcOrderFilled', 'SellblastToken', 'Swap', 'BuyGem', 'DODOSwap', 'SellGem', 'Submitted') + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + ) + + select tt.tx_hash, tt.block_number, tt.block_time, count(*) fills_within + from {{ source('blast', 'logs') }} l + join signatures on signature = topic0 + join tbl_trades tt on tt.tx_hash = l.tx_hash and l.block_time = tt.block_time and l.block_number = tt.block_number + WHERE 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('l.block_time') }} + {% else %} + AND l.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} + group by 1,2,3 + ), + +results AS ( + SELECT + trades.block_time, + trades.block_number, + zid, + trades.contract_address, + method_id, + trades.tx_hash, + "from" AS tx_from, + "to" AS tx_to, + trades.index AS tx_index, + case when varbinary_substring(tr.data,1,4) = 0x500c22bc then "from" else taker end as taker, + CAST(NULL AS varbinary) AS maker, + taker_token, + pt.price, + COALESCE(tt.symbol, pt.symbol) AS taker_symbol, + taker_amount AS taker_token_amount_raw, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) AS taker_token_amount, + taker_amount / POW(10,COALESCE(tt.decimals,pt.decimals)) * pt.price AS taker_amount, + maker_token, + COALESCE(tm.symbol, pm.symbol) AS maker_symbol, + maker_amount AS maker_token_amount_raw, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) AS maker_token_amount, + maker_amount / POW(10,COALESCE(tm.decimals,pm.decimals)) * pm.price AS maker_amount, + tag, + fills_within + FROM + tbl_trades trades + JOIN + {{ source('blast', 'transactions') }} tr ON tr.hash = trades.tx_hash AND tr.block_time = trades.block_time AND tr.block_number = trades.block_number + LEFT JOIN + fills f ON f.tx_hash = trades.tx_hash AND f.block_time = trades.block_time AND f.block_number = trades.block_number + LEFT JOIN + tokens tt ON tt.blockchain = 'blast' AND tt.contract_address = taker_token + LEFT JOIN + tokens tm ON tm.blockchain = 'blast' AND tm.contract_address = maker_token + LEFT JOIN + prices pt ON pt.blockchain = 'blast' AND pt.contract_address = taker_token AND pt.minute = DATE_TRUNC('minute', trades.block_time) + LEFT JOIN + prices pm ON pm.blockchain = 'blast' AND pm.contract_address = maker_token AND pm.minute = DATE_TRUNC('minute', trades.block_time) + WHERE + 1=1 + {% if is_incremental() %} + AND {{ incremental_predicate('tr.block_time') }} + {% else %} + AND tr.block_time >= DATE '{{zeroex_settler_start_date}}' + {% endif %} +), + +results_usd AS ( + SELECT + 'blast' AS blockchain, + '0x-API' AS project, + 'settler' AS version, + DATE_TRUNC('day', block_time) block_date, + DATE_TRUNC('month', block_time) AS block_month, + block_time, + taker_symbol, + maker_symbol, + CASE WHEN LOWER(taker_symbol) > LOWER(maker_symbol) THEN CONCAT(maker_symbol, '-', taker_symbol) ELSE CONCAT(taker_symbol, '-', maker_symbol) END AS token_pair, + taker_token_amount, + maker_token_amount, + taker_token_amount_raw, + maker_token_amount_raw, + CASE WHEN maker_token IN (0x4300000000000000000000000000000000000004, + 0x4300000000000000000000000000000000000003, + 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND maker_amount IS NOT NULL + THEN maker_amount + WHEN taker_token IN (0x4300000000000000000000000000000000000004, + 0x4300000000000000000000000000000000000003, + 0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad ) AND taker_amount IS NOT NULL + THEN taker_amount + ELSE COALESCE(maker_amount, taker_amount) + END AS volume_usd, + taker_token, + maker_token, + taker, + maker, + tag, + zid, + tx_hash, + tx_from, + tx_to, + tx_index AS evt_index, + (ARRAY[-1]) AS trace_address, + 'settler' AS type, + TRUE AS swap_flag, + fills_within, + contract_address + FROM + results +) + +SELECT DISTINCT + * +FROM + results_usd +ORDER BY + block_time DESC \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql index 8bfdd619be5..f037d694f47 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_api_fills_deduped.sql @@ -31,6 +31,7 @@ ,ref('zeroex_arbitrum_settler_trades') ,ref('zeroex_scroll_settler_trades') ,ref('zeroex_linea_settler_trades') + ,ref('zeroex_blast_settler_trades') ] %} diff --git a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml index e93f4f91ef8..2af511b28f5 100644 --- a/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml +++ b/dbt_subprojects/dex/models/_projects/zeroex/zeroex_schema.yml @@ -105,7 +105,7 @@ models: - name: zeroex_api_fills_deduped meta: - blockchain: ethereum, optimism, polygon, arbitrum, fantom, avalanche, bnb, base, scroll, linea + blockchain: ethereum, optimism, polygon, arbitrum, fantom, avalanche, bnb, base, scroll, linea, blast sector: dex project: zeroex contributors: rantum, bakabhai993 @@ -158,7 +158,7 @@ models: - name: zeroex_trades meta: - blockchain: ethereum, optimism, polygon, arbitrum, fantom, avalanche, bnb, base, linea, scroll + blockchain: ethereum, optimism, polygon, arbitrum, fantom, avalanche, bnb, base, linea, scroll, blast project: zeroex contributors: rantum, danning.sui, bakabhai993 config: diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/blast/_schema.yml b/dbt_subprojects/dex/seeds/_project/zeroex/blast/_schema.yml new file mode 100644 index 00000000000..aab9ffaad7a --- /dev/null +++ b/dbt_subprojects/dex/seeds/_project/zeroex/blast/_schema.yml @@ -0,0 +1,11 @@ +version: 2 + +seeds: + - name: zeroex_blast_settler_trades_sample + config: + column_types: + tx_hash: varbinary + taker: varbinary + taker_token: varbinary + maker_token: varbinary + taker_token_amount: double \ No newline at end of file diff --git a/dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv b/dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv new file mode 100644 index 00000000000..6485f75e989 --- /dev/null +++ b/dbt_subprojects/dex/seeds/_project/zeroex/blast/zeroex_blast_settler_trades_sample.csv @@ -0,0 +1,3 @@ +tx_hash,taker,taker_token,maker_token,taker_token_amount +0x92f05d2cc3e693ae5863e5a3c08475a9fb62c1db76acce05461aa8538cb9689a,0x4ea754349ace5303c82f0d1d491041e042f2ad22,0x4300000000000000000000000000000000000003,0x4300000000000000000000000000000000000004,1 +0x4477ae1598016d0abee946f6bd7a0f6cbdbd6a87a3dde5eae1007d9f6a8ced06,0x4ea754349ace5303c82f0d1d491041e042f2ad22,0x4300000000000000000000000000000000000003,0x4300000000000000000000000000000000000004,1e-12 \ No newline at end of file From 0a6583d1fd122c6481dac434366717d6a21cfca1 Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:31:20 -0400 Subject: [PATCH 32/59] update sushiswap source (#6837) --- .../arbitrum/platforms/sushiswap_v2_arbitrum_base_trades.sql | 2 +- sources/_sector/dex/trades/arbitrum/_sources.yml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/models/trades/arbitrum/platforms/sushiswap_v2_arbitrum_base_trades.sql b/dbt_subprojects/dex/models/trades/arbitrum/platforms/sushiswap_v2_arbitrum_base_trades.sql index 98808748296..a880e132ddd 100644 --- a/dbt_subprojects/dex/models/trades/arbitrum/platforms/sushiswap_v2_arbitrum_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/arbitrum/platforms/sushiswap_v2_arbitrum_base_trades.sql @@ -16,6 +16,6 @@ project = 'sushiswap', version = '2', Pair_evt_Swap = source('sushiswap_v3_pool_arbitrum', 'UniswapV3Pool_evt_Swap'), - Factory_evt_PoolCreated = source('sushi_v2_arbitrum', 'Factory_evt_PoolCreated') + Factory_evt_PoolCreated = source('sushiswap_arbitrum', 'UniswapV3Factory_evt_PoolCreated') ) }} diff --git a/sources/_sector/dex/trades/arbitrum/_sources.yml b/sources/_sector/dex/trades/arbitrum/_sources.yml index 70ac7417282..a0e6345db2c 100644 --- a/sources/_sector/dex/trades/arbitrum/_sources.yml +++ b/sources/_sector/dex/trades/arbitrum/_sources.yml @@ -18,6 +18,9 @@ sources: tables: - name: Pair_evt_Swap - name: Factory_evt_PairCreated + - name: sushiswap_arbitrum + tables: + - name: UniswapV3Factory_evt_PoolCreated - name: sushi_v2_arbitrum tables: - name: Pool_evt_Swap From 3177cadeec20ce2b25dcfa12666d8c16b5f27f00 Mon Sep 17 00:00:00 2001 From: Rantum Date: Thu, 26 Sep 2024 07:18:09 -0700 Subject: [PATCH 33/59] add tokens (#6836) --- .../tokens/arbitrum/tokens_arbitrum_erc20.sql | 6 +++++- .../tokens/models/tokens/bnb/tokens_bnb_bep20.sql | 15 +++++++++++++++ .../tokens/ethereum/tokens_ethereum_erc20.sql | 6 ++++++ .../tokens/polygon/tokens_polygon_erc20.sql | 6 ++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql b/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql index 9a4beed6aee..286f6aadfcb 100644 --- a/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/arbitrum/tokens_arbitrum_erc20.sql @@ -116,5 +116,9 @@ FROM (VALUES , (0x8d7c2588c365b9e98ea464b63dbccdf13ecd9809, 'AI', 18) , (0xd2cc61a36c31425b3eb9bbeecce74a82a2e32e27, 'RATS', 18) , (0x27f485b62c4a7e635f561a87560adf5090239e93, 'DFX', 18) - , (0x39a49bc5017fc668299cd32e734c9269acc35295, 'PHONON', 18) + , (0x39a49bc5017fc668299cd32e734c9269acc35295, 'PHONON', 18) + , (0x89073b7aaae498771bdb789360b0d3de9d15ad56, 'STC', 18) + , (0xb59c8912c83157a955f9d715e556257f432c35d7, 'TRUF', 18) + , (0xe1d3495717f9534db67a6a8d4940dd17435b6a9e, 'LOCUS', 18) + , (0x764bfc309090e7f93edce53e5befa374cdcb7b8e, 'GRIMACE', 18) ) AS temp_table (contract_address, symbol, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_bep20.sql b/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_bep20.sql index 21782b7f17d..a9bfcdd9379 100644 --- a/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_bep20.sql +++ b/dbt_subprojects/tokens/models/tokens/bnb/tokens_bnb_bep20.sql @@ -593,4 +593,19 @@ FROM (VALUES , (0x6985884c4392d348587b19cb9eaaf157f13271cd, 'ZRO', 18) , (0xfceb31a79f71ac9cbdcf853519c1b12d379edc46, 'LISTA', 18) , (0x0e7779e698052f8fe56c415c3818fcf89de9ac6d, 'ULTI', 18) + , (0x617cab4aaae1f8dfb3ee138698330776a1e1b324, 'ARTY', 6) + , (0x2940566eb50f15129238f4dc599adc4f742d7d8e, 'BCCoin', 18) + , (0xc5d27f27f08d1fd1e3ebbaa50b3442e6c0d50439, 'APP', 18) + , (0x7b56748a3ef9970a5bae99c58ad8bc67b26c525f, 'CHAPZ', 10) + , (0x23b891e5c62e0955ae2bd185990103928ab817b3, 'nUSD', 18) + , (0xbda011d7f8ec00f66c1923b049b94c67d148d8b2, 'AI', 18) + , (0x4a8049c015ae1c6665fc9e49f053458ae3a102d0, 'BabyRWA', 9) + , (0x75e8ddb518bb757b4282cd5b83bb70d4101d12fb, 'NFP', 18) + , (0x51e72dd1f2628295cc2ef931cb64fdbdc3a0c599, 'KAS', 8) + , (0xe6d19cfa419fc81029b11b335ba5c53a0aa6e37f, 'DEMON', 18) + , (0xd404829f8634c99c7ac945b69a02a5b7a8d4de8c, 'MEMEAI', 18) + , (0xeb880acb83c63ea3eab4baae9693dc5dd9d324a3, 'SCPT', 18) + , (0xdb6c248902ad2722a5e01e9689824c28bd0a5f75, 'Baby-LP', 18) + , (0xd1b6d02c03e632a845460c8167eb05d2d9e03a35, 'Sorai', 18) + , (0x0f327343c7902233c0419724946b17fa664f2fe0, 'LBTC', 18) ) AS temp_table (contract_address, symbol, decimals) \ No newline at end of file diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql index 993f4784fb4..5a075a3286a 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql @@ -4626,4 +4626,10 @@ FROM (VALUES , ( 0x60407266586e204792b69b024558aa18228ab12f, 'MBAKER', 18) , ( 0x048d07bd350ba516b84587e147284881b593eb86, 'SYNK', 18) , ( 0xbbd91d5cda7085a186b1354e1b0744bb58ad7cf6, 'ZOMBIE', 9) + , ( 0xdd157bd06c1840fa886da18a138c983a7d74c1d7, 'GSTOP', 18) + , ( 0x525574c899a7c877a11865339e57376092168258, 'GURU', 18) + , ( 0xe9689028ede16c2fdfe3d11855d28f8e3fc452a3, 'BUBBLE', 9) + , ( 0xeb9951021698b42e4399f9cbb6267aa35f82d59d, 'LIF', 18) + , ( 0x707f9118e33a9b8998bea41dd0d46f38bb963fc8, 'bETH', 18) + ) AS temp_table (contract_address, symbol, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_erc20.sql b/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_erc20.sql index 6e911f2ebfd..4fe9958dc2c 100644 --- a/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/polygon/tokens_polygon_erc20.sql @@ -51,4 +51,10 @@ FROM (VALUES , (0x94f05506b6a9c564839d8e95b21f9fb4f42ff2aa, 'SFRIED', 18) , (0x9b8b6a1298d34b3c4bbddce8a7ff0149121592c1, 'AMBO', 18) , (0xe9d2fa815b95a9d087862a09079549f351dab9bd, 'BONSAI', 18) + , (0xe0cca86b254005889ac3a81e737f56a14f4a38f5, 'ALTA', 18) + , (0x421b9b487d5a9b76e4b81809c0f1b9bb8cb24cb9, 'PBOS', 18) + , (0x13646e0e2d768d31b75d1a1e375e3e17f18567f2, 'NWS', 18) + , (0xbae28251b2a4e621aa7e20538c06dee010bc06de, 'dHEDGE', 18) + , (0xdfe21992da3c135f009f273a281bfe4ee84d9872, 'XOXO', 18) + , (0xf9b2ebdfa24688f0dfb12cc55782e635f91e64a2, 'CLEO', 18) ) AS temp_table (contract_address, symbol, decimals) From 7f636d2cb12e458a064a5d55a3728742a9667dcd Mon Sep 17 00:00:00 2001 From: Andrew <47720952+andrewhong5297@users.noreply.github.com> Date: Thu, 26 Sep 2024 12:00:19 -0400 Subject: [PATCH 34/59] adding token2022 support for orca swaps (#6811) * basic * fix? * QAed --- .../_sector/dex/dex_solana_base_trades.sql | 1 + .../orca_whirlpool/orca_whirlpool_schema.yml | 13 + .../orca_whirlpool_v2_base_trades.sql | 257 ++++++++++++++++++ .../orca_whirlpool_trades_sources.yml | 5 +- 4 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 dbt_subprojects/solana/models/_sector/dex/orca_whirlpool/orca_whirlpool_v2_base_trades.sql diff --git a/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql b/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql index ad9e2b60a09..3816731b919 100644 --- a/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql +++ b/dbt_subprojects/solana/models/_sector/dex/dex_solana_base_trades.sql @@ -13,6 +13,7 @@ {% set solana_dexes = [ ref('orca_whirlpool_base_trades') + , ref('orca_whirlpool_v2_base_trades') , ref('raydium_v3_base_trades') , ref('raydium_v4_base_trades') , ref('phoenix_v1_base_trades') diff --git a/dbt_subprojects/solana/models/_sector/dex/orca_whirlpool/orca_whirlpool_schema.yml b/dbt_subprojects/solana/models/_sector/dex/orca_whirlpool/orca_whirlpool_schema.yml index 75576e495ae..2eb319d5473 100644 --- a/dbt_subprojects/solana/models/_sector/dex/orca_whirlpool/orca_whirlpool_schema.yml +++ b/dbt_subprojects/solana/models/_sector/dex/orca_whirlpool/orca_whirlpool_schema.yml @@ -14,6 +14,19 @@ models: - dbt_utils.unique_combination_of_columns: combination_of_columns: [ 'tx_id', 'outer_instruction_index', 'inner_instruction_index', 'tx_index', 'block_month' ] + - name: orca_whirlpool_v2_base_trades + meta: + blockchain: solana + contributors: [ ilemi ] + config: + tags: [ 'solana','dex' ] + description: > + all raw whirlpool dex trades on Solana + tests: + - check_columns_solana_dex_trades + - dbt_utils.unique_combination_of_columns: + combination_of_columns: [ 'tx_id', 'outer_instruction_index', 'inner_instruction_index', 'tx_index', 'block_month' ] + - name: orca_whirlpool_trades meta: blockchain: solana diff --git a/dbt_subprojects/solana/models/_sector/dex/orca_whirlpool/orca_whirlpool_v2_base_trades.sql b/dbt_subprojects/solana/models/_sector/dex/orca_whirlpool/orca_whirlpool_v2_base_trades.sql new file mode 100644 index 00000000000..12782363d95 --- /dev/null +++ b/dbt_subprojects/solana/models/_sector/dex/orca_whirlpool/orca_whirlpool_v2_base_trades.sql @@ -0,0 +1,257 @@ + {{ + config( + + schema = 'orca_whirlpool_v2', + alias = 'base_trades', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['tx_id', 'outer_instruction_index', 'inner_instruction_index', 'tx_index','block_month'], + pre_hook='{{ enforce_join_distribution("PARTITIONED") }}' + ) +}} + +{% set project_start_date = '2024-05-27' %} --blocktime of upgrade is 268396603 +--you can QA with the tx id 2P2hcK79CV82MqjXa6S4xxKoTHkgqmYkszWkxY1KmASvCek8YfSekSrB8rtdRJSTUYYyuCVxMXFrQd11bXDZqn6K + +with + whirlpools as ( + with + fee_tiers_defaults as ( + --the fee tier has defaults that can be changed. Once the pool is initialized, the fee tier is set to the default fee tier. + SELECT + account_feeTier as fee_tier + , defaultfeeRate as fee_rate + , call_block_time as fee_time + FROM {{ source('whirlpool_solana', 'whirlpool_call_initializeFeeTier') }} + + UNION ALL + + SELECT + account_feeTier as fee_tier + , defaultfeeRate as fee_rate + , call_block_time as fee_time + FROM {{ source('whirlpool_solana', 'whirlpool_call_setDefaultFeeRate') }} + ) + + --https://docs.orca.so/reference/trading-fees, should track protocol fees too. and rewards. + , fee_updates as ( + SELECT + whirlpool_id + , update_time + , fee_rate + FROM ( + --get defaultFeeRate at time of pool init based on account_feeTier + SELECT + fi.account_whirlpool as whirlpool_id + , fi.call_block_time as update_time + , fi.account_feeTier as fee_tier + , ftd.fee_time + , ftd.fee_rate + , row_number() over (partition by fi.account_whirlpool order by ftd.fee_time desc) as recent_update + FROM {{ source('whirlpool_solana', 'whirlpool_call_initializePoolV2') }} fi + LEFT JOIN fee_tiers_defaults ftd ON ftd.fee_tier = account_feeTier AND ftd.fee_time <= fi.call_block_time + ) + WHERE recent_update = 1 + + UNION all + + --after being initialized, the fee rate can be set manually using setFeeRate on the pool (does not update with defaultFeeRate) + SELECT + account_whirlpool as whirlpool_id + , call_block_time as update_time + , feeRate as fee_rate + FROM {{ source('whirlpool_solana', 'whirlpool_call_setFeeRate') }} + ) + + SELECT + account_tokenMintA as tokenA + , account_tokenVaultA as tokenAVault + , account_tokenMintB as tokenB + , account_tokenVaultB as tokenBVault + , ip.tickSpacing + , ip.account_whirlpool as whirlpool_id + , fu.update_time + , fu.fee_rate + , ip.call_tx_id as init_tx + FROM {{ source('whirlpool_solana', 'whirlpool_call_initializePoolV2') }} ip + LEFT JOIN fee_updates fu ON fu.whirlpool_id = ip.account_whirlpool + ) + + , two_hop as ( + SELECT + account_whirlpoolOne as account_whirlpool + , call_outer_instruction_index + , call_inner_instruction_index + , call_is_inner + , call_tx_signer + , call_tx_id + , call_tx_index + , call_block_time + , call_block_slot + , call_outer_executing_account + FROM {{ source('whirlpool_solana', 'whirlpool_call_twoHopSwapV2') }} sp + + UNION ALL + + --for second hop, we're going to spoof things so that the join on +1 and +2 still work just fine. + --this might not work in our token extension case since +2 is not guaranteed + SELECT + account_whirlpoolTwo as account_whirlpool + , call_outer_instruction_index + , COALESCE(call_inner_instruction_index,0) + 2 as call_inner_instruction_index + , true as call_is_inner + , call_tx_signer + , call_tx_id + , call_tx_index + , call_block_time + , call_block_slot + , call_outer_executing_account + FROM {{ source('whirlpool_solana', 'whirlpool_call_twoHopSwapV2') }} sp + ) + + , all_swaps as ( + SELECT + sp.call_block_time as block_time + , sp.call_block_slot as block_slot + , 'whirlpool' as project + , 2 as version + , 'solana' as blockchain + , case when sp.call_outer_executing_account = 'whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc' then 'direct' + else sp.call_outer_executing_account + end as trade_source + -- token bought is always the second instruction (transfer) in the inner instructions + , tr_2.amount as token_bought_amount_raw + , tr_1.amount as token_sold_amount_raw + , wp.fee_rate + , wp.whirlpool_id + , sp.call_tx_signer as trader_id + , sp.call_tx_id as tx_id + , sp.call_outer_instruction_index as outer_instruction_index + , COALESCE(sp.call_inner_instruction_index, 0) as inner_instruction_index + , sp.call_tx_index as tx_index + , case when tr_1.token_mint_address = wp.tokenA then wp.tokenB + else wp.tokenA + end as token_bought_mint_address + , case when tr_1.token_mint_address = wp.tokenA then wp.tokenA + else wp.tokenB + end as token_sold_mint_address + , case when tr_1.token_mint_address = wp.tokenA then wp.tokenBVault + else wp.tokenAVault + end as token_bought_vault + , case when tr_1.token_mint_address = wp.tokenA + then wp.tokenAVault + else wp.tokenBVault + end as token_sold_vault + , wp.update_time + --we need a row_number for the transfer out filter to get the first transfer out from the tr_2 join + , row_number() over (partition by sp.call_tx_id, sp.call_outer_instruction_index, sp.call_inner_instruction_index + order by COALESCE(tr_2.inner_instruction_index, 0) asc) as first_transfer_out + FROM ( + SELECT + account_whirlpool + , call_outer_instruction_index + , call_inner_instruction_index + , call_is_inner + , call_tx_signer + , call_tx_id + , call_tx_index + , call_block_time + , call_block_slot + , call_outer_executing_account + FROM {{ source('whirlpool_solana', 'whirlpool_call_swapV2') }} + WHERE 1=1 + {% if is_incremental() %} + AND {{incremental_predicate('call_block_time')}} + {% else %} + AND call_block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + + UNION ALL + + SELECT * FROM two_hop + WHERE 1=1 + {% if is_incremental() %} + AND {{incremental_predicate('call_block_time')}} + {% else %} + AND call_block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ) + sp + INNER JOIN whirlpools wp + ON sp.account_whirlpool = wp.whirlpool_id + AND sp.call_block_time >= wp.update_time + --join on memo program at index + 1 to see if the first token has memo extension active or not. if active everything gets offset by 1 + LEFT JOIN {{ source('solana', 'instruction_calls')}} memo + ON memo.tx_id = sp.call_tx_id + AND memo.block_slot = sp.call_block_slot + AND memo.outer_instruction_index = sp.call_outer_instruction_index + AND ((sp.call_is_inner = false AND memo.inner_instruction_index = 1) + OR (sp.call_is_inner = true AND memo.inner_instruction_index = sp.call_inner_instruction_index + 1) + ) + AND memo.executing_account = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr' + {% if is_incremental() %} + AND {{incremental_predicate('memo.block_time')}} + {% else %} + AND memo.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + --token extension transfer could be preceeded by the memo program and followed by a post execution hook + even potentially more instructions. + INNER JOIN {{ ref('tokens_solana_transfers') }} tr_1 + ON tr_1.tx_id = sp.call_tx_id + AND tr_1.block_slot = sp.call_block_slot + AND tr_1.outer_instruction_index = sp.call_outer_instruction_index + AND ((sp.call_is_inner = false AND tr_1.inner_instruction_index = CASE WHEN memo.tx_id IS NOT NULL THEN 2 ELSE 1 END) + OR (sp.call_is_inner = true AND tr_1.inner_instruction_index = sp.call_inner_instruction_index + CASE WHEN memo.tx_id IS NOT NULL THEN 2 ELSE 1 END)) + {% if is_incremental() %} + AND {{incremental_predicate('tr_1.block_time')}} + {% else %} + AND tr_1.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + INNER JOIN {{ ref('tokens_solana_transfers') }} tr_2 + ON tr_2.tx_id = sp.call_tx_id + AND tr_2.block_slot = sp.call_block_slot + AND tr_2.outer_instruction_index = sp.call_outer_instruction_index + AND ((sp.call_is_inner = false AND (tr_2.inner_instruction_index >= CASE WHEN memo.tx_id IS NOT NULL THEN 3 ELSE 2 END)) + OR (sp.call_is_inner = true AND (tr_2.inner_instruction_index >= sp.call_inner_instruction_index + CASE WHEN memo.tx_id IS NOT NULL THEN 3 ELSE 2 END)) + ) + {% if is_incremental() %} + AND {{incremental_predicate('tr_2.block_time')}} + {% else %} + AND tr_2.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ) + +SELECT + tb.blockchain + , tb.project + , tb.version + , CAST(date_trunc('month', tb.block_time) AS DATE) as block_month + , tb.block_time + , tb.block_slot + , tb.trade_source + , tb.token_bought_amount_raw + , tb.token_sold_amount_raw + , cast(tb.fee_rate as double)/1000000 as fee_tier + , tb.token_sold_mint_address + , tb.token_bought_mint_address + , tb.token_sold_vault + , tb.token_bought_vault + , tb.whirlpool_id as project_program_id + , 'whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc' as project_main_id + , tb.trader_id + , tb.tx_id + , tb.outer_instruction_index + , tb.inner_instruction_index + , tb.tx_index + , recent_update +FROM ( + SELECT + * + , row_number() OVER (partition by tx_id, outer_instruction_index, inner_instruction_index, tx_index order by update_time desc) as recent_update + FROM all_swaps + WHERE first_transfer_out = 1 + ) + tb +WHERE recent_update = 1 diff --git a/sources/orca_whirlpool/orca_whirlpool_trades_sources.yml b/sources/orca_whirlpool/orca_whirlpool_trades_sources.yml index 9c0b7183c69..ee2c9ce0519 100644 --- a/sources/orca_whirlpool/orca_whirlpool_trades_sources.yml +++ b/sources/orca_whirlpool/orca_whirlpool_trades_sources.yml @@ -5,8 +5,11 @@ sources: description: "whirlpool decoded tables" tables: - name: whirlpool_call_initializePool - - name: whirlpool_call_setFeeRate - name: whirlpool_call_swap - name: whirlpool_call_twoHopSwap + - name: whirlpool_call_initializePoolV2 + - name: whirlpool_call_swapV2 + - name: whirlpool_call_twoHopSwapV2 + - name: whirlpool_call_setFeeRate - name: whirlpool_call_initializeFeeTier - name: whirlpool_call_setDefaultFeeRate From 2caeeba2f0d8f39169c07536d598d9b436333944 Mon Sep 17 00:00:00 2001 From: max-morrow Date: Thu, 26 Sep 2024 22:10:38 +0300 Subject: [PATCH 35/59] implemented trusted tokens logic to 1inch lineage (#6841) --- .../dex/models/_projects/oneinch/oneinch_swaps.sql | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/dex/models/_projects/oneinch/oneinch_swaps.sql b/dbt_subprojects/dex/models/_projects/oneinch/oneinch_swaps.sql index f47c3a226a5..3353812373d 100644 --- a/dbt_subprojects/dex/models/_projects/oneinch/oneinch_swaps.sql +++ b/dbt_subprojects/dex/models/_projects/oneinch/oneinch_swaps.sql @@ -143,6 +143,15 @@ tokens as ( and cardinality(call_trace_address) = 0 ) +, trusted_tokens as ( + select + blockchain as transfer_blockchain + , contract_address + , true as trusted + from {{ source('prices', 'trusted_tokens') }} + group by 1, 2, 3 +) + {% set src_condition = 'contract_address = _src_token_address' %} {% set dst_condition = 'contract_address = _dst_token_address' %} {% set symbol = 'coalesce(symbol, token_symbol)' %} @@ -173,7 +182,9 @@ tokens as ( , max(amount) filter(where {{ src_condition }} and amount <= src_token_amount) as _src_token_amount_true -- take only src token amounts less than in the call , max(amount) filter(where {{ dst_condition }} and amount <= dst_token_amount) as _dst_token_amount_true -- take only dst token amounts less than in the call , max(amount * price / pow(10, {{ decimals }})) filter(where {{ src_condition }} and amount <= src_token_amount or {{ dst_condition }} and amount <= dst_token_amount) as sources_amount_usd + , max(amount * price / pow(10, {{ decimals }})) filter(where ({{ src_condition }} and amount <= src_token_amount or {{ dst_condition }} and amount <= dst_token_amount) and trusted) as sources_amount_usd_trusted , max(amount * price / pow(10, {{ decimals }})) as transfers_amount_usd + , max(amount * price / pow(10, {{ decimals }})) filter(where trusted) as transfers_amount_usd_trusted -- src $ amount from user , sum(amount * if(user = transfer_from, price, -price) / pow(10, {{ decimals }})) filter(where {{ src_condition }} and user in (transfer_from, transfer_to)) as _amount_usd_from_user @@ -207,6 +218,7 @@ tokens as ( ) using(blockchain, block_number, tx_hash, call_trace_address) -- block_number is needed for performance left join prices using(transfer_blockchain, contract_address, minute) left join tokens using(transfer_blockchain, contract_address) + left join trusted_tokens using(transfer_blockchain, contract_address) group by 1, 2, 3, 4, 5 ) @@ -256,7 +268,7 @@ select , coalesce(_dst_token_symbol_to_user, _dst_token_symbol_to_receiver, _dst_token_symbol) as dst_token_symbol , dst_token_decimals , coalesce(_dst_token_amount_true, dst_token_amount) as dst_token_amount - , coalesce(sources_amount_usd, transfers_amount_usd) as amount_usd -- sources $ amount first if found prices, then $ amount of connector tokens + , coalesce(sources_amount_usd_trusted, sources_amount_usd, transfers_amount_usd_trusted, transfers_amount_usd) as amount_usd -- sources $ amount first if found prices, then $ amount of connector tokens , sources_amount_usd , transfers_amount_usd , greatest(coalesce(_amount_usd_from_user, 0), coalesce(_amount_usd_to_user, _amount_usd_to_receiver, 0)) as user_amount_usd -- actual user $ amount From 85a13e0281e5a809b07103f34d04439b7b826c5e Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:01:44 -0400 Subject: [PATCH 36/59] update to median price per block (#6843) --- .../dex/models/prices/dex_prices_beta.sql | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/dbt_subprojects/dex/models/prices/dex_prices_beta.sql b/dbt_subprojects/dex/models/prices/dex_prices_beta.sql index 477e7b3b862..2468371f394 100644 --- a/dbt_subprojects/dex/models/prices/dex_prices_beta.sql +++ b/dbt_subprojects/dex/models/prices/dex_prices_beta.sql @@ -9,8 +9,9 @@ }} with dex_trades as ( - select distinct + select blockchain + , block_number , block_time , token_bought_address , token_bought_amount_raw @@ -34,6 +35,7 @@ dex_bought as ( , d.token_bought_address as contract_address , t.symbol as symbol , t.decimals as decimals + , d.block_number as block_number , d.block_time as block_time , d.token_bought_amount as amount , d.amount_usd @@ -60,6 +62,7 @@ dex_sold as ( , d.token_sold_address as contract_address , t.symbol as symbol , t.decimals as decimals + , d.block_number as block_number , d.block_time as block_time , d.token_sold_amount as amount , d.amount_usd @@ -105,17 +108,38 @@ volume_filter as ( sum(amount_usd) >= 10000 ) select - dp.blockchain - , dp.contract_address - , dp.symbol - , dp.decimals - , cast(date_trunc('month', dp.block_time) as date) as block_month -- for partitioning - , dp.block_time - , dp.amount - , dp.amount_usd - , dp.price + blockchain + , contract_address + , symbol + , decimals + , block_number + , cast(date_trunc('month', block_time) as date) as block_month -- for partitioning + , block_time + , amount + , amount_usd + , price from - dex_prices as dp -inner join volume_filter as vf - on dp.blockchain = vf.blockchain - and dp.contract_address = vf.contract_address \ No newline at end of file +( + select + dp.blockchain + , dp.contract_address + , dp.symbol + , dp.decimals + , dp.block_number + , dp.block_time + , sum(dp.amount) as amount + , sum(dp.amount_usd) as amount_usd + , approx_percentile(dp.price, 0.5) AS price + from + dex_prices as dp + inner join volume_filter as vf + on dp.blockchain = vf.blockchain + and dp.contract_address = vf.contract_address + group by + dp.blockchain + , dp.contract_address + , dp.symbol + , dp.decimals + , dp.block_number + , dp.block_time +) \ No newline at end of file From 7b6fc1cce4960ac481ead74988d88c57334e7c33 Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:47:12 -0400 Subject: [PATCH 37/59] remove bad price feeds (#6845) --- dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql | 2 +- .../tokens/models/prices/ethereum/prices_ethereum_tokens.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql b/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql index ed895f4d0f8..e638e058d1c 100644 --- a/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql @@ -274,7 +274,6 @@ FROM ('pepe-pepecoin-bsc', 'bnb', 'PEPE', 0xb46584e0efde3092e04010a13f2eae62adb3b9f0, 18), ('babydoge-baby-doge-coin', 'bnb', 'BABYDOGE', 0xc748673057861a797275cd8a068abb95a902e8de, 9), ('bwjup-bsc-wrapped-jupiter', 'bnb', 'bwJUP', 0x0231f91e02debd20345ae8ab7d71a41f8e140ce7, 18), - ('lovely-lovely-inu-finance', 'bnb', 'LOVELY', 0x9e24415d1e549ebc626a13a482bb117a2b43e9cf, 8), --('pvc-pvc-meta','bnb','PVC',0x75ca521892de7f2ecfb070cab545c250d0ceb7e3, 9), --token_id not found ('bvsd-bvsd','bnb','BVSD',0x7f9ad7a5854658d984924e868187b2135514fb88, 18), ('coco-coco-coin', 'bnb', 'COCO', 0xf563e86e461de100cfcfd8b65daa542d3d4b0550, 18), @@ -289,4 +288,5 @@ where contract_address not in ( ,0x7ddee176f665cd201f93eede625770e2fd911990 -- GALA doesn't exists on BSC, it's a scam-token address. ,0xe552fb52a4f19e44ef5a967632dbc320b0820639 -- METIS has bad price feed since PolyNetwork incident and will be replaced by new contract ,0x9fdc3ae5c814b79dca2556564047c5e7e5449c19 -- DG, bad price feed + ,0x9e24415d1e549ebc626a13a482bb117a2b43e9cf -- LOVELY, rugpull ) diff --git a/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql b/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql index b5fef3747e1..9e37d5e8f5c 100644 --- a/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql @@ -1839,7 +1839,6 @@ FROM ('usdz-anzen-usdz', 'ethereum', 'USDZ', 0xa469b7ee9ee773642b3e93e842e5d9b5baa10067, 18), ('lbtc-lombard-staked-btc', 'ethereum', 'LBTC', 0x8236a87084f8b84306f72007f36f2618a5634494, 8), ('msn-mesonnetwork', 'ethereum', 'MSN', 0xaa247c0d81b83812e1abf8bab078e4540d87e3fb, 18), - ('bubble-imaginary-ones', 'ethereum', 'BUBBLE', 0xe9689028ede16c2fdfe3d11855d28f8e3fc452a3, 18), ('zeta-zetachain', 'ethereum', 'ZETA', 0xf091867ec603a6628ed83d274e835539d82e9cc8, 18), ('euri-eurite', 'ethereum', 'EURI', 0x9d1a7a3191102e9f900faa10540837ba84dcbae7, 18), ('sky-sky', 'ethereum', 'SKY', 0x56072C95FAA701256059aa122697B133aDEd9279, 18) @@ -1869,4 +1868,5 @@ where contract_address not in ( ,0x630d98424efe0ea27fb1b3ab7741907dffeaad78 -- PEAKDEFI ,0xee06a81a695750e71a662b51066f2c74cf4478a0 -- DG, bad price feed ,0x9e24415d1e549ebc626a13a482bb117a2b43e9cf -- LOVELY, rugpull + ,0xe9689028ede16c2fdfe3d11855d28f8e3fc452a3 -- BUBBLE, bad price feed ) From ab3369546a6f436dc19265c87559468732318f5f Mon Sep 17 00:00:00 2001 From: Rantum Date: Fri, 27 Sep 2024 06:40:54 -0700 Subject: [PATCH 38/59] add gho, dyad (#6840) --- .../tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql index 69adcbb06ef..a2233cdf6e1 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql @@ -79,6 +79,8 @@ FROM (VALUES ('ethereum', 0xcfc5bd99915aaa815401c5a41a927ab7a38d29cf, 'Crypto-backed stablecoin', 'thUSD', 18, ''), ('ethereum', 0xdf3ac4f479375802a821f7b7b46cd7eb5e4262cc, 'Crypto-backed stablecoin', 'eUSD', 18, ''), ('ethereum', 0xbbaec992fc2d637151daf40451f160bf85f3c8c1, 'Crypto-backed stablecoin', 'USDM', 6, ''), - ('ethereum', 0x7945b0a6674b175695e5d1d08ae1e6f13744abb0, 'Crypto-backed stablecoin', 'BaoUSD', 18, '') + ('ethereum', 0x7945b0a6674b175695e5d1d08ae1e6f13744abb0, 'Crypto-backed stablecoin', 'BaoUSD', 18, ''), + ('ethereum', 0x40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f, 'Crypto-backed stablecoin', 'GHO', 18, ''), + ('ethereum', 0xfd03723a9a3abe0562451496a9a394d2c4bad4ab, 'Crypto-backed stablecoin', 'DYAD', 18, '') ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) From 125a91111868996534fc0527d7df05bb509506ff Mon Sep 17 00:00:00 2001 From: Bob Baxley Date: Fri, 27 Sep 2024 09:41:33 -0400 Subject: [PATCH 39/59] enable maverick v2 on zksync (#6842) --- .../trades/zksync/platforms/maverick_v2_zksync_base_trades.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/dbt_subprojects/dex/models/trades/zksync/platforms/maverick_v2_zksync_base_trades.sql b/dbt_subprojects/dex/models/trades/zksync/platforms/maverick_v2_zksync_base_trades.sql index 74933cc4505..16d2fd40861 100644 --- a/dbt_subprojects/dex/models/trades/zksync/platforms/maverick_v2_zksync_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/zksync/platforms/maverick_v2_zksync_base_trades.sql @@ -1,6 +1,5 @@ {{ config( - tags = ['prod_exclude'], schema = 'maverick_v2_zksync', alias = 'base_trades', materialized = 'incremental', From 92c3fd3c6f10a5d1f1c84fa32ec71f7748000006 Mon Sep 17 00:00:00 2001 From: Huang Geyang Date: Fri, 27 Sep 2024 21:41:43 +0800 Subject: [PATCH 40/59] Add firebird_finance_optimism_base_trades (#6816) * Add firebird_finance_optimism_base_trades * Refactor firebird_finance_optimism_trades --- .../firebird_finance/optimism/_schema.yml | 45 ++++++- .../firebird_finance_optimism_base_trades.sql | 73 +++++++++++ .../firebird_finance_optimism_trades.sql | 121 ++---------------- .../dex_aggregator_base_trades.sql | 1 + .../dex_aggregator_trades.sql | 1 - 5 files changed, 127 insertions(+), 114 deletions(-) create mode 100644 dbt_subprojects/dex/models/_projects/firebird_finance/optimism/firebird_finance_optimism_base_trades.sql diff --git a/dbt_subprojects/dex/models/_projects/firebird_finance/optimism/_schema.yml b/dbt_subprojects/dex/models/_projects/firebird_finance/optimism/_schema.yml index d28e89bb0e1..94b10960ae3 100644 --- a/dbt_subprojects/dex/models/_projects/firebird_finance/optimism/_schema.yml +++ b/dbt_subprojects/dex/models/_projects/firebird_finance/optimism/_schema.yml @@ -96,4 +96,47 @@ models: description: "" - &trace_address name: trace_address - description: "" \ No newline at end of file + description: "" + + - name: firebird_finance_optimism_base_trades + meta: + blockchain: optimism + sector: dex + project: firebird_finance + contributors: ARDev097, hosuke + config: + tags: [ 'optimism','trades', 'firebird_finance','dex' ] + description: > + firebird_finance dex base trades on optimism + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - project + - version + - tx_hash + - evt_index + - check_dex_aggregator_seed: + blockchain: optimism + project: firebird_finance + version: 1 + columns: + - *blockchain + - *project + - *version + - *block_date + - *block_time + - *token_bought_amount_raw + - *token_sold_amount_raw + - *token_bought_address + - *token_sold_address + - *taker + - *maker + - *project_contract_address + - *tx_hash + - *tx_from + - *tx_to + - *trace_address + - *evt_index + - *block_month \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/firebird_finance/optimism/firebird_finance_optimism_base_trades.sql b/dbt_subprojects/dex/models/_projects/firebird_finance/optimism/firebird_finance_optimism_base_trades.sql new file mode 100644 index 00000000000..0b025e9d5d9 --- /dev/null +++ b/dbt_subprojects/dex/models/_projects/firebird_finance/optimism/firebird_finance_optimism_base_trades.sql @@ -0,0 +1,73 @@ +{{ config( + alias='base_trades', + schema='firebird_finance_optimism', + partition_by=['block_month'], + materialized='incremental', + file_format='delta', + incremental_strategy='merge', + unique_key=['block_date', 'blockchain', 'project', 'version', 'tx_hash', 'evt_index'] + ) +}} + +{% set project_start_date = '2022-07-11' %} +{% set firebird_finance_optimism_evt_trade_tables = [ + source('firebird_finance_optimism', 'FireBirdRouter_evt_Swapped') +] %} + +with dexs as ( + {% for evt_trade_table in firebird_finance_optimism_evt_trade_tables %} + SELECT + evt_block_time AS block_time, + sender AS taker, + CAST(NULL as VARBINARY) AS maker, + returnAmount AS token_bought_amount_raw, + spentAmount AS token_sold_amount_raw, + CAST(NULL AS double) AS amount_usd, + dstToken AS token_bought_address, + srcToken AS token_sold_address, + contract_address AS project_contract_address, + evt_tx_hash AS tx_hash, + array[-1] AS trace_address, + evt_index + FROM {{ evt_trade_table }} + {% if is_incremental() %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% else %} + WHERE evt_block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + + {% if not loop.last %} + UNION ALL + {% endif %} + + {% endfor %} +) + +SELECT + 'optimism' AS blockchain, + 'firebird_finance' AS project, + '1' AS version, + TRY_CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date, + TRY_CAST(date_trunc('MONTH', dexs.block_time) AS date) AS block_month, + dexs.block_time, + dexs.token_bought_amount_raw AS token_bought_amount_raw, + dexs.token_sold_amount_raw AS token_sold_amount_raw, + dexs.token_bought_address, + dexs.token_sold_address, + COALESCE(dexs.taker, tx."from") AS taker, + dexs.maker, + dexs.project_contract_address, + dexs.tx_hash, + tx."from" AS tx_from, + tx.to AS tx_to, + dexs.evt_index, + dexs.trace_address +FROM dexs +INNER JOIN {{ source('optimism', 'transactions') }} tx + ON dexs.tx_hash = tx.hash + {% if not is_incremental() %} + AND tx.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + {% if is_incremental() %} + AND {{ incremental_predicate('tx.block_time') }} + {% endif %} \ No newline at end of file diff --git a/dbt_subprojects/dex/models/_projects/firebird_finance/optimism/firebird_finance_optimism_trades.sql b/dbt_subprojects/dex/models/_projects/firebird_finance/optimism/firebird_finance_optimism_trades.sql index 095a1b136f6..268059bfdad 100644 --- a/dbt_subprojects/dex/models/_projects/firebird_finance/optimism/firebird_finance_optimism_trades.sql +++ b/dbt_subprojects/dex/models/_projects/firebird_finance/optimism/firebird_finance_optimism_trades.sql @@ -1,118 +1,15 @@ {{ config( alias='trades', schema='firebird_finance_optimism', - partition_by=['block_month'], - materialized='incremental', - file_format='delta', - incremental_strategy='merge', - unique_key=['block_date', 'blockchain', 'project', 'version', 'tx_hash', 'evt_index'], - post_hook='{{ expose_spells(\'["optimism"]\', - "project", - "firebird_finance", - \'["ARDev097"]\') }}' + materialized='view', + post_hook='{{ expose_spells(blockchains = \'["optimism"]\', + spell_type = "project", + spell_name = "firebird_finance", + contributors = \'["ARDev097", "hosuke"]\') }}' ) }} -{% set project_start_date = '2022-07-11' %} -{% set firebird_finance_optimism_evt_trade_tables = [ - source('firebird_finance_optimism', 'FireBirdRouter_evt_Swapped') -] %} - -with dexs as ( - {% for evt_trade_table in firebird_finance_optimism_evt_trade_tables %} - SELECT - evt_block_time AS block_time, - sender AS taker, - CAST(NULL as VARBINARY) AS maker, - returnAmount AS token_bought_amount_raw, - spentAmount AS token_sold_amount_raw, - CAST(NULL AS double) AS amount_usd, - dstToken AS token_bought_address, - srcToken AS token_sold_address, - contract_address AS project_contract_address, - evt_tx_hash AS tx_hash, - array[-1] AS trace_address, - evt_index - FROM {{ evt_trade_table }} - {% if is_incremental() %} - WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) - {% else %} - WHERE evt_block_time >= TIMESTAMP '{{project_start_date}}' - {% endif %} - - {% if not loop.last %} - UNION ALL - {% endif %} - - {% endfor %} -) - -SELECT - 'optimism' AS blockchain, - 'firebird_finance' AS project, - '1' AS version, - TRY_CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date, - TRY_CAST(date_trunc('MONTH', dexs.block_time) AS date) AS block_month, - dexs.block_time, - erc20a.symbol AS token_bought_symbol, - erc20b.symbol AS token_sold_symbol, - CASE - WHEN lower(erc20a.symbol) > lower(erc20b.symbol) - THEN concat(erc20b.symbol, '-', erc20a.symbol) - ELSE concat(erc20a.symbol, '-', erc20b.symbol) - END AS token_pair, - dexs.token_bought_amount_raw / power(10, erc20a.decimals) AS token_bought_amount, - dexs.token_sold_amount_raw / power(10, erc20b.decimals) AS token_sold_amount, - dexs.token_bought_amount_raw AS token_bought_amount_raw, - dexs.token_sold_amount_raw AS token_sold_amount_raw, - COALESCE( - dexs.amount_usd, - (dexs.token_bought_amount_raw / power(10, erc20a.decimals)) * p_bought.price, - (dexs.token_sold_amount_raw / power(10, erc20b.decimals)) * p_sold.price - ) AS amount_usd, - dexs.token_bought_address, - dexs.token_sold_address, - COALESCE(dexs.taker, tx."from") AS taker, - dexs.maker, - dexs.project_contract_address, - dexs.tx_hash, - tx."from" AS tx_from, - tx.to AS tx_to, - dexs.evt_index, - dexs.trace_address -FROM dexs -INNER JOIN {{ source('optimism', 'transactions') }} tx - ON dexs.tx_hash = tx.hash - {% if not is_incremental() %} - AND tx.block_time >= TIMESTAMP '{{project_start_date}}' - {% endif %} - {% if is_incremental() %} - AND tx.block_time >= date_trunc('day', now() - interval '7' day) - {% endif %} -LEFT JOIN {{ source('tokens', 'erc20') }} erc20a - ON erc20a.contract_address = dexs.token_bought_address - AND erc20a.blockchain = 'optimism' -LEFT JOIN {{ source('tokens', 'erc20') }} erc20b - ON erc20b.contract_address = dexs.token_sold_address - AND erc20b.blockchain = 'optimism' -LEFT JOIN {{ source('prices', 'usd') }} p_bought - ON p_bought.minute = date_trunc('minute', dexs.block_time) - AND p_bought.contract_address = dexs.token_bought_address - AND p_bought.blockchain = 'optimism' - {% if not is_incremental() %} - AND p_bought.minute >= TIMESTAMP '{{project_start_date}}' - {% endif %} - {% if is_incremental() %} - AND p_bought.minute >= date_trunc('day', now() - interval '7' day) - {% endif %} -LEFT JOIN {{ source('prices', 'usd') }} p_sold - ON p_sold.minute = date_trunc('minute', dexs.block_time) - AND p_sold.contract_address = dexs.token_sold_address - AND p_sold.blockchain = 'optimism' - {% if not is_incremental() %} - AND p_sold.minute >= TIMESTAMP '{{project_start_date}}' - {% endif %} - {% if is_incremental() %} - AND p_sold.minute >= date_trunc('day', now() - interval '7' day) - {% endif %} - +SELECT * +FROM {{ ref('dex_aggregator_trades') }} +WHERE project = 'firebird_finance' + AND blockchain = 'optimism' diff --git a/dbt_subprojects/dex/models/aggregator_trades/dex_aggregator_base_trades.sql b/dbt_subprojects/dex/models/aggregator_trades/dex_aggregator_base_trades.sql index 9b7ee783f7e..21d6c86acf6 100644 --- a/dbt_subprojects/dex/models/aggregator_trades/dex_aggregator_base_trades.sql +++ b/dbt_subprojects/dex/models/aggregator_trades/dex_aggregator_base_trades.sql @@ -12,6 +12,7 @@ {% set base_trade_models = [ ref('lifi_base_trades') + , ref('firebird_finance_optimism_base_trades') ] %} with base_union as ( diff --git a/dbt_subprojects/dex/models/aggregator_trades/dex_aggregator_trades.sql b/dbt_subprojects/dex/models/aggregator_trades/dex_aggregator_trades.sql index ff4aefc4cb0..a153eb875df 100644 --- a/dbt_subprojects/dex/models/aggregator_trades/dex_aggregator_trades.sql +++ b/dbt_subprojects/dex/models/aggregator_trades/dex_aggregator_trades.sql @@ -22,7 +22,6 @@ ,ref('zeroex_trades') ,ref('kyberswap_aggregator_trades') ,ref('tokenlon_trades') - ,ref('firebird_finance_optimism_trades') ,ref('oneinch_ar_trades') ,ref('unidex_optimism_trades') ,ref('odos_trades') From f99d3464391ac15add839c6a979d04d8c3057f8e Mon Sep 17 00:00:00 2001 From: clizzard <145153355+clizzard7@users.noreply.github.com> Date: Fri, 27 Sep 2024 15:42:47 +0200 Subject: [PATCH 41/59] add jubot (#6835) * add jubot add jupbot sql and add to schema * update schema.yml * add seed * moved seedfile * fixed typo * seed from test query --------- Co-authored-by: whale_hunter <143016036+whalehunting@users.noreply.github.com> --- .../_sector/dex/bot_trades/solana/_schema.yml | 25 ++- .../platforms/jupbot_solana_bot_trades.sql | 151 ++++++++++++++++++ .../jupbot/jupbot_solana_trades_seed.csv | 21 +++ 3 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/jupbot_solana_bot_trades.sql create mode 100644 dbt_subprojects/solana/seeds/jupbot/jupbot_solana_trades_seed.csv diff --git a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml index 270652d829a..7b3cb551e7d 100644 --- a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml +++ b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/_schema.yml @@ -533,5 +533,26 @@ models: tags: ["solana", "dex", "bot_trades"] columns: - name: user - tests: unique - + tests: unique + + - name: jupbot_solana_bot_trades + meta: + blockchain: solana + sector: dex + project: jupbot + contributors: whale_hunter + config: + tags: ["solana", "dex", "jupbot", "trades"] + description: > + Jupbot trades on Solana + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - tx_id + - tx_index + - outer_instruction_index + - inner_instruction_index + - check_bot_trades_seed: + seed_file: ref('jupbot_solana_trades_seed') + blockchain: solana \ No newline at end of file diff --git a/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/jupbot_solana_bot_trades.sql b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/jupbot_solana_bot_trades.sql new file mode 100644 index 00000000000..3c8080a89a5 --- /dev/null +++ b/dbt_subprojects/solana/models/_sector/dex/bot_trades/solana/platforms/jupbot_solana_bot_trades.sql @@ -0,0 +1,151 @@ +{{ config( + alias = 'bot_trades', + schema = 'jupbot_solana', + partition_by = ['block_month'], + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], + unique_key = ['blockchain', 'tx_id', 'tx_index', 'outer_instruction_index', 'inner_instruction_index'] + ) +}} + +{% set project_start_date = '2024-09-12' %} +{% set buy_fee_receiver_1 = 'H2mM9cXi42efgwkSzTRKMVaWHrqJJx1nzNdV1NxWaHjC' %} +{% set wsol_token = 'So11111111111111111111111111111111111111112' %} + +WITH + allFeePayments AS ( + SELECT + tx_id, + 'SOL' AS feeTokenType, + balance_change / 1e9 AS fee_token_amount, + '{{wsol_token}}' AS fee_token_mint_address + FROM + {{ source('solana','account_activity') }} + WHERE + {% if is_incremental() %} + {{ incremental_predicate('block_time') }} + {% else %} + block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + AND tx_success + AND balance_change > 0 + AND address = '{{buy_fee_receiver_1}}' + + ), + botTrades AS ( + SELECT + trades.block_time, + CAST(date_trunc('day', trades.block_time) AS date) AS block_date, + CAST(date_trunc('month', trades.block_time) AS date) AS block_month, + 'solana' AS blockchain, + amount_usd, + IF( + token_sold_mint_address = '{{wsol_token}}', + 'Buy', + 'Sell' + ) AS type, + token_bought_amount, + token_bought_symbol, + token_bought_mint_address AS token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_mint_address AS token_sold_address, + fee_token_amount * price AS fee_usd, + fee_token_amount, + IF(feeTokenType = 'SOL', 'SOL', symbol) AS fee_token_symbol, + fee_token_mint_address AS fee_token_address, + project, + version, + token_pair, + project_program_id AS project_contract_address, + trader_id AS user, + trades.tx_id, + tx_index, + outer_instruction_index, + inner_instruction_index + FROM + {{ ref('dex_solana_trades') }} AS trades + JOIN allFeePayments AS feePayments ON trades.tx_id = feePayments.tx_id + LEFT JOIN {{ source('prices', 'usd') }} AS feeTokenPrices ON ( + feeTokenPrices.blockchain = 'solana' + AND fee_token_mint_address = toBase58 (feeTokenPrices.contract_address) + AND date_trunc('minute', block_time) = minute + {% if is_incremental() %} + AND {{ incremental_predicate('minute') }} + {% else %} + AND minute >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ) + JOIN {{ source('solana','transactions') }} AS transactions ON ( + trades.tx_id = id + {% if is_incremental() %} + AND {{ incremental_predicate('transactions.block_time') }} + {% else %} + AND transactions.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ) + WHERE + trades.trader_id != '{{buy_fee_receiver_1}}' -- Exclude trades signed by FeeWallet + AND transactions.signer != '{{buy_fee_receiver_1}}' -- Exclude trades signed by FeeWallet + {% if is_incremental() %} + AND {{ incremental_predicate('trades.block_time') }} + {% else %} + AND trades.block_time >= TIMESTAMP '{{project_start_date}}' + {% endif %} + ), + highestInnerInstructionIndexForEachTrade AS ( + SELECT + tx_id, + outer_instruction_index, + MAX(inner_instruction_index) AS highestInnerInstructionIndex + FROM + botTrades + GROUP BY + tx_id, + outer_instruction_index + ) +SELECT + block_time, + block_date, + block_month, + 'Jupbot' as bot, + blockchain, + amount_usd, + type, + token_bought_amount, + token_bought_symbol, + token_bought_address, + token_sold_amount, + token_sold_symbol, + token_sold_address, + fee_usd, + fee_token_amount, + fee_token_symbol, + fee_token_address, + project, + version, + token_pair, + project_contract_address, + user, + botTrades.tx_id, + tx_index, + botTrades.outer_instruction_index, + COALESCE(inner_instruction_index, 0) AS inner_instruction_index, + IF( + inner_instruction_index = highestInnerInstructionIndex, + true, + false + ) AS is_last_trade_in_transaction +FROM + botTrades + JOIN highestInnerInstructionIndexForEachTrade ON ( + botTrades.tx_id = highestInnerInstructionIndexForEachTrade.tx_id + AND botTrades.outer_instruction_index = highestInnerInstructionIndexForEachTrade.outer_instruction_index + ) +ORDER BY + block_time DESC, + tx_index DESC, + outer_instruction_index DESC, + inner_instruction_index DESC diff --git a/dbt_subprojects/solana/seeds/jupbot/jupbot_solana_trades_seed.csv b/dbt_subprojects/solana/seeds/jupbot/jupbot_solana_trades_seed.csv new file mode 100644 index 00000000000..ed7bd7a03cc --- /dev/null +++ b/dbt_subprojects/solana/seeds/jupbot/jupbot_solana_trades_seed.csv @@ -0,0 +1,21 @@ +block_time,block_date,block_month,bot,blockchain,amount_usd,type,token_bought_amount,token_bought_symbol,token_bought_address,token_sold_amount,token_sold_symbol,token_sold_address,fee_usd,fee_token_amount,fee_token_symbol,fee_token_address,project,version,token_pair,project_contract_address,user,tx_id,tx_index,outer_instruction_index,inner_instruction_index,is_last_trade_in_transaction +2024-09-22 22:05:57.000 UTC,2024-09-22,2024-09-01,Jupbot,solana,9.485474414359999,Sell,0.066883898,SOL,So11111111111111111111111111111111111111112,8541662.403881,RIZ0,rizo34MUwbCBqpSTSfnEktdWB4CTByqqYh8zBxL3WAR,0.18970935213999998,0.001337677,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-RIZ0,6nmiCc4QSXqjsNYWgPRBVtij7GdHfDTud71eEGqApqav,5MrieS7fwgyXxXyAAves9Fe3z76iG9c5xb6y7TJyg9jm,WB2eBeutgCmo3FTwQChLWM5wtjtA7VejtcVDUAtGRNvAQXoNqVKVUPpdPDdDqrMDMtjLe8o2B89kWuaTWV4455i,1207,3,1,true +2024-09-24 14:32:27.000 UTC,2024-09-24,2024-09-01,Jupbot,solana,140.53687770696,Buy,19.29906357,HNT,hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux,0.968952549,SOL,So11111111111111111111111111111111111111112,31.230417171519996,0.215322788,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-HNT,91axdGmMoqQQg2MPUXKxT3bdqX4p2RMLXqZSQgXn2JpM,DvfLpvgbuPSBi4CWw6o6vEPMBxfYcwv9f9yBCqSybqJZ,59vpKFmYzC4vo8KVK3m9CC3Adwv9AvH7j5vvw1EdBR3BZ2wqkMa6AeY599eh9ALtLiSdp4ueHnrVL5hXQiuffvv8,878,7,2,false +2024-09-24 14:32:27.000 UTC,2024-09-24,2024-09-01,Jupbot,solana,1420.9839871057598,Buy,195.14349727,HNT,hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux,9.797186894,SOL,So11111111111111111111111111111111111111112,31.230417171519996,0.215322788,SOL,So11111111111111111111111111111111111111112,whirlpool,1,SOL-HNT,CSP4RmB6kBHkKGkyTnzt9zYYXDA8SbZ5Do5WfZcjqjE4,DvfLpvgbuPSBi4CWw6o6vEPMBxfYcwv9f9yBCqSybqJZ,59vpKFmYzC4vo8KVK3m9CC3Adwv9AvH7j5vvw1EdBR3BZ2wqkMa6AeY599eh9ALtLiSdp4ueHnrVL5hXQiuffvv8,878,7,6,true +2024-09-19 17:55:09.000 UTC,2024-09-19,2024-09-01,Jupbot,solana,0.1403458,Buy,365.905989774,$PCORN,Ee4n93iv9vtY8cYcUEqFCpBtmCq1ZMKR3pLzPQsmDMY5,0.00098,SOL,So11111111111111111111111111111111111111112,0.002806916,0.0000196,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-$PCORN,FUJFiFpsZKkPhYpDviN2XN2S2vKbrvYKDEVPVZ8N6CPK,Ci1ar7awYyQYjTaFCoMtNNj3asw9mD59nBf5tMffTru7,2ZppJkVmStWbCWbBMcaX2NFPR6Fsm6pSe8ozFVQuQGAfdc5X6eR5DNeh23HA955AJAdtfMMP4ffb5RDYAsfeCSHX,33,5,1,true +2024-09-23 20:57:52.000 UTC,2024-09-23,2024-09-01,Jupbot,solana,893.2176223468562,Sell,0.001683402,,2e6NAJy1qaKMq8PaswP2uzimMDvbr71Tbw38G6q9SNZ2,893.042586,USDT,Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB,17.870368238759998,0.124384828,SOL,So11111111111111111111111111111111111111112,lifinity,2,,EiEAydLqSKFqRPpuwYoVxEJ6h9UZh9tsTaHgs4f8b8Z5,Cv8yQZhb2p4hLaWPF9RPwGSuVeBnQMM2X2Y7UjPmUwzB,57trXhPHMbPfDtaWoq9FV2UMnx4qBZF3pbCT9Nh4eVc8UBGkA7tZZWCKPfCaCd9Qibfr9hTgq1eJTjPbqgcMKxex,300,3,1,true +2024-09-24 17:48:21.000 UTC,2024-09-24,2024-09-01,Jupbot,solana,557.300951807754,Buy,557.500537,USDT,Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB,3.76316083,SOL,So11111111111111111111111111111111111111112,11.15701913984,0.075263216,SOL,So11111111111111111111111111111111111111112,whirlpool,1,USDT-SOL,FwewVm8u6tFPGewAyHmWAqad9hmF7mvqxK4mJ7iNqqGC,Dup31RWDS3MTTGMiHZwuWMVchpyihtz12uX53BpzDXUT,2VixUV9nXftBMHtF2NVWgEQ8YpumsCMGtZPTwoP9Tfahvo9yoMndiKtJwRsmfLXUReXmuL78obmw2M8EfifB9nXB,134,7,2,true +2024-09-24 09:12:00.000 UTC,2024-09-24,2024-09-01,Jupbot,solana,124.31130723228,Buy,19229.630419948,USEDCAR,9gwTegFJJErDpWJKjPfLr2g2zrE3nL1v5zpwbtsk3c6P,0.840054786,SOL,So11111111111111111111111111111111111111112,2.4862260380999994,0.016801095,SOL,So11111111111111111111111111111111111111112,raydium,4,USEDCAR-SOL,Cf628kRZSmUb5VZf6KGpRDRRxWRT8b4vLuYPEtLs73WD,HZB1puYqXJsj4XpPMHaEpWCQcxUFWmjNTufFCUosDPnd,PC3Ji6S7ZKAkZ3V1k4gcgp91AdVUKT5c9hstM1ZVUr5BS9fXNd79atNK3WiY9Q75zzz8sBvNvsaB7FLcDJZ4bow,194,6,1,true +2024-09-24 09:49:31.000 UTC,2024-09-24,2024-09-01,Jupbot,solana,1724.495158701,Buy,19116.709495,MOTHER,3S8qX1MsMqRbiwKg2cQyx7nis1oHMgaCuc9c4VfvVdPN,11.731259583,SOL,So11111111111111111111111111111111111111112,34.489903077,0.234625191,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-MOTHER,HcPgh6B2yHNvT6JsEmkrHYT8pVHu9Xiaoxm4Mmn2ibWw,9fvVi6TDjMgRcPJ8y6GmyWuFwueReyCyoStToUFkM4So,5VyevQMA2wDQDcEEXiCGHKrWS5VeLmFV6RRPF4v9fcrmmbW5pJgeLD3Xhw2nAYGNMUL1ZcaJqZqSQoExRrrgWQJR,1430,7,1,true +2024-09-24 11:10:40.000 UTC,2024-09-24,2024-09-01,Jupbot,solana,634.2138995739999,Sell,4.343930819,SOL,So11111111111111111111111111111111111111112,40983.562948,BRAINLET,8NNXWrWVctNw1UFeaBypffimTdcLCcD8XJzHvYsmgwpF,12.684277936,0.086878616,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-BRAINLET,CW9DFoTWEUiwxyxVGnQFYhbrYEfGkvaqXEgxKZG7d7X1,27JwZFWWeHwPKM9Ua7ag8indKfE8zKXjBe91jj9AWZbN,3Vahc42snvcQwezC1t843LLmtqbgtLR2iufdfUA3kAUCFGJhpG6EKv3Nq95aCuySsENfBd97mgoLCsCCutFyWc7x,289,3,1,true +2024-09-22 05:52:18.000 UTC,2024-09-22,2024-09-01,Jupbot,solana,7.2299500000000005,Buy,328188.720296788,XP,HDdBA7kHSMpSyCJMcr3CWh7a6HU5cgVUpKADKWG71j8w,0.049,SOL,So11111111111111111111111111111111111111112,0.144599,0.00098,SOL,So11111111111111111111111111111111111111112,raydium,4,XP-SOL,2WpYE3efcuXCffkwzKz4BCH5Tm42sWFGHtVQGzgf6ZdS,5MrieS7fwgyXxXyAAves9Fe3z76iG9c5xb6y7TJyg9jm,45CxudRR76PyBM1Xar3YeSiEPLxTkpJJLkVp5YHUidzHJinRoo4kxYK7MEPDwbMRHGkCbhABZtQH7hq6T4pPvqVe,128,6,1,true +2024-09-19 18:19:58.000 UTC,2024-09-19,2024-09-01,Jupbot,solana,0.1405418,Buy,365.904209342,$PCORN,Ee4n93iv9vtY8cYcUEqFCpBtmCq1ZMKR3pLzPQsmDMY5,0.00098,SOL,So11111111111111111111111111111111111111112,0.0028108359999999997,0.0000196,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-$PCORN,FUJFiFpsZKkPhYpDviN2XN2S2vKbrvYKDEVPVZ8N6CPK,Ci1ar7awYyQYjTaFCoMtNNj3asw9mD59nBf5tMffTru7,3rBabEtvxHgxX5YJrW1uzAWXgzfTfhtoSWFuwUwoNkCvqnj9pGVLV22MaT88pbnWmspybbDVzxAHHpLAWmQcytqp,918,5,1,true +2024-09-23 15:44:42.000 UTC,2024-09-23,2024-09-01,Jupbot,solana,1080.6260739674499,Sell,7.486152227,SOL,So11111111111111111111111111111111111111112,29795.437741,hehe,BreuhVohXX5fv6q41uyb3sojtAuGoGaiAhKBMtcrpump,21.6125214014,0.149723044,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-hehe,23KJaRate7XthAQ7C5XbJJYK5cyG1sNA2ikCPsiAcbVP,5hT6rWEUyULoWux1h66CTjtNYxXBdxk5FiTfbKPKiEXG,4x4a4BA5R6oyqW65KjQrL4aXUT8ATDMQqp8MNaAUUZBKy4qE3SvhQzN8V1pUNZr7Hz9RD3yU2oBZ7dMokciuEq5z,145,3,1,true +2024-09-24 07:52:24.000 UTC,2024-09-24,2024-09-01,Jupbot,solana,296.32371093252,Sell,2.018828934,SOL,So11111111111111111111111111111111111111112,1.655689816,mSOL,mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So,5.926474118840001,0.040376578,SOL,So11111111111111111111111111111111111111112,meteora,1,SOL-mSOL,HcjZvfeSNJbNkfLD4eEcRBr96AD3w1GpmMppaeRZf7ur,6ozPcBDF7opwtmg8EkQwiYRC2FwGnbeGHu5w8aQBN1PE,3y2Y7RYmwwtGjzWZX4AWYidcf7cAHnEhQB6oedWAHHBMFNHD84c328Q8BM2fykKfMQBffao6PuGXTEYHumsgRjS3,1447,4,1,true +2024-09-21 15:55:21.000 UTC,2024-09-21,2024-09-01,Jupbot,solana,5.7929759999999995,Buy,5616.738498,BONKEY,6y4rgKVoPUc8HMcnWfca8siuBa3gAjxNaRrHxVmMpump,0.0392,SOL,So11111111111111111111111111111111111111112,0.11585952,0.000784,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-BONKEY,BecDGSmGxdiiQV6pMCf1evuNjmgNB4mJhCseNSshrhcD,7DtLV4eguy7Eg9Wf6AehfjfjSZNFwYE4TGqk4Fob6vHE,5zkRQybxM2XigDy5UyFQZ7ZQuMZMB5pb27xepke5G8Nz8xt9PtPdrgjX5uKBAv49bubf7q5tKpayoewnduUuA92d,1382,6,1,true +2024-09-25 01:13:05.000 UTC,2024-09-25,2024-09-01,Jupbot,solana,494.92799795428,Sell,0.070543,,DriFtupJYLTosbwoN8koMbEYSx54aFAVLddWsbksjwg7,494.89484,USDC,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,9.888836797799998,0.06499827,SOL,So11111111111111111111111111111111111111112,phoenix,1,,8BV6rrWsUabnTDA3dE6A69oUDJAj3hMhtBHTJyXB7czp,ET71c3wQF92i4EGn5aztAMYPszmZrE8AJFLvyLTBAqqw,2ajcuXNQQcKo7Uy4VjHF4MhitmV1PrnhJbx8DNHVa3e1DVwxsS9oMXkoMLhoqPyyRKH5v4sAtjmP9kC5AWTpEKsv,115,7,7,true +2024-09-24 19:08:59.000 UTC,2024-09-24,2024-09-01,Jupbot,solana,383.36847314116005,Sell,2.606530277,SOL,So11111111111111111111111111111111111111112,2.287962514,JitoSOL,J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn,7.667377325720001,0.052130659,SOL,So11111111111111111111111111111111111111112,raydium,3,SOL-JitoSOL,2uoKbPEidR7KAMYtY4x7xdkHXWqYib5k4CutJauSL3Mc,3PtzA1bgtFY6rN7rsoRfZsryC5qSmuvuAYVqXPZKfvEG,2vrF2VneYFA7gdAwGzUbtKXQVvTEzhDzhfPnVn22jV8uvvWgKxbPCtidmo9h2CF8RX83eCKaaGBWr7S7zr1sAtML,367,3,1,true +2024-09-24 15:45:57.000 UTC,2024-09-24,2024-09-01,Jupbot,solana,954.11638561901,Buy,1059086.353385,ball,HPfY3VCj1twecf556rDFWLJpDfh1vPoTtBjPehzKpump,6.574218877,SOL,So11111111111111111111111111111111111111112,19.082327634010003,0.131484377,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-ball,7jaj84BxnuwWc9a2VEFEudvPQ5AxkrUKFCmTZRM1cbdE,8i5QapkUnbnb6vEaEFcJFpsR1x3XF5N4FyL6HEAb1gpf,2iSBpMcxmjob6f1amwUC7M5bV9ZNAQ9kDsu8Z2s7J8aTTow9in7k5asjVqFcz8EtvyZUx3RQVjWEMdNdtyw7zuKV,1200,6,1,true +2024-09-23 20:52:52.000 UTC,2024-09-23,2024-09-01,Jupbot,solana,930.15180360432,Sell,6.474674952,SOL,So11111111111111111111111111111111111111112,6.334130789,sSOL,sSo14endRuUbvQaJS3dq36Q829a3A6BEfoeeRGJywEh,18.60303606634,0.129493499,SOL,So11111111111111111111111111111111111111112,whirlpool,1,sSOL-SOL,8X5tAh7EcafARDGhmLHxkiG5CousuB1yLtYsbuM9tD1T,EkN4oxatCq7RRndbzw8bZRV4uA7YvW2wDbKcQKZPBgpw,5QiDGEUH6FL2eZrUS1usQ9YuX41ZgguNxdQSGXeuc5TdqzU4yeSn2wB2VwbS2bMDuNDbcDthzgBtBHfTYghry7rC,265,3,1,true +2024-09-24 13:20:12.000 UTC,2024-09-24,2024-09-01,Jupbot,solana,0.0011863542,Sell,0.000008054,SOL,So11111111111111111111111111111111111111112,1186.791951,USDC,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,23.731174815600003,0.161107772,SOL,So11111111111111111111111111111111111111112,phoenix,1,USDC-SOL,HUaSnNPwGZv18W7XynTfrgTAUWSMMHsdGXXLaEQbnKJz,CY7trDMTcg8KVBJWXbAdUX9uQCtEffAfKHLzuRmeSKzW,3tkxMBas8SPQZBWE5SW7acxZZYLTzEiphjsqziTVUfBxFmrtRoVk7ai4D5Tahy4XXHQGK3kr1iugjVvnz7eRKP7Z,942,4,6,true +2024-09-24 15:27:40.000 UTC,2024-09-24,2024-09-01,Jupbot,solana,1101.81663929152,Sell,7.554968728,SOL,So11111111111111111111111111111111111111112,1264106.88068,ball,HPfY3VCj1twecf556rDFWLJpDfh1vPoTtBjPehzKpump,22.026021962,0.151028675,SOL,So11111111111111111111111111111111111111112,raydium,4,SOL-ball,7jaj84BxnuwWc9a2VEFEudvPQ5AxkrUKFCmTZRM1cbdE,GKN8EJjLhtBeKwzcA9CQCdiKEHPGso2KtFCMFTJwCkgD,66npQKbqogUKyrpPJCNcUNeuFp5nhicJhFLaRKGRDyXvnPC1Du2nYNxz88Qnh5Gn5zbpK6tvbNvSWJEq7pgSvMrf,1053,3,1,true \ No newline at end of file From f24b9893c00486dd5b0d0463b968be2a22c9e65d Mon Sep 17 00:00:00 2001 From: Rantum Date: Mon, 30 Sep 2024 08:02:24 -0700 Subject: [PATCH 42/59] add USDS [sky] (#6848) * add USDS - sky * add to tokens and prices lists * remove inactives --- .../tokens/models/prices/ethereum/prices_ethereum_tokens.sql | 5 +++-- .../tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql | 1 + .../tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql b/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql index 9e37d5e8f5c..0dc3d95b49c 100644 --- a/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql @@ -1840,8 +1840,9 @@ FROM ('lbtc-lombard-staked-btc', 'ethereum', 'LBTC', 0x8236a87084f8b84306f72007f36f2618a5634494, 8), ('msn-mesonnetwork', 'ethereum', 'MSN', 0xaa247c0d81b83812e1abf8bab078e4540d87e3fb, 18), ('zeta-zetachain', 'ethereum', 'ZETA', 0xf091867ec603a6628ed83d274e835539d82e9cc8, 18), - ('euri-eurite', 'ethereum', 'EURI', 0x9d1a7a3191102e9f900faa10540837ba84dcbae7, 18), - ('sky-sky', 'ethereum', 'SKY', 0x56072C95FAA701256059aa122697B133aDEd9279, 18) + ('euri-eurite', 'ethereum', 'EURI', 0x9d1a7a3191102e9f900faa10540837ba84dcbae7, 18) + --('sky-sky', 'ethereum', 'SKY', 0x56072C95FAA701256059aa122697B133aDEd9279, 18), + --('usds-usds', 'ethereum', 'USDS', 0xdc035d45d973e3ec169d2276ddab16f1e407384f, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) where contract_address not in ( -- bad price feeds diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql index 5a075a3286a..1e9ef995585 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql @@ -4631,5 +4631,6 @@ FROM (VALUES , ( 0xe9689028ede16c2fdfe3d11855d28f8e3fc452a3, 'BUBBLE', 9) , ( 0xeb9951021698b42e4399f9cbb6267aa35f82d59d, 'LIF', 18) , ( 0x707f9118e33a9b8998bea41dd0d46f38bb963fc8, 'bETH', 18) + , ( 0xdc035d45d973e3ec169d2276ddab16f1e407384f, 'USDS', 18) ) AS temp_table (contract_address, symbol, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql index a2233cdf6e1..bb049ac987b 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20_stablecoins.sql @@ -81,6 +81,7 @@ FROM (VALUES ('ethereum', 0xbbaec992fc2d637151daf40451f160bf85f3c8c1, 'Crypto-backed stablecoin', 'USDM', 6, ''), ('ethereum', 0x7945b0a6674b175695e5d1d08ae1e6f13744abb0, 'Crypto-backed stablecoin', 'BaoUSD', 18, ''), ('ethereum', 0x40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f, 'Crypto-backed stablecoin', 'GHO', 18, ''), - ('ethereum', 0xfd03723a9a3abe0562451496a9a394d2c4bad4ab, 'Crypto-backed stablecoin', 'DYAD', 18, '') + ('ethereum', 0xfd03723a9a3abe0562451496a9a394d2c4bad4ab, 'Crypto-backed stablecoin', 'DYAD', 18, ''), + ('ethereum', 0xdc035d45d973e3ec169d2276ddab16f1e407384f, 'Crypto-backed stablecoin', 'USDS', 18, '') ) AS temp_table (blockchain, contract_address, backing, symbol, decimals, name) From bc30cab394ffc45ce0f36686d8c06772842c26ac Mon Sep 17 00:00:00 2001 From: Rantum Date: Mon, 30 Sep 2024 08:04:20 -0700 Subject: [PATCH 43/59] add new tokens from coinpaprika updates (#6849) * add new tokens from coinpaprika * babyrwa * remove inactive * remove inactive * remove more inactive * fix commas after remove inactives --- .../tokens/models/prices/base/prices_base_tokens.sql | 5 ++++- .../tokens/models/prices/bnb/prices_bnb_tokens.sql | 8 +++++++- .../models/prices/polygon/prices_polygon_tokens.sql | 4 +++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql index 599e5b9343e..371c686f3a0 100644 --- a/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/base/prices_base_tokens.sql @@ -169,5 +169,8 @@ FROM ('rdat-rdatadao','base','RDAT',0x4498cd8ba045e00673402353f5a4347562707e7d, 18), ('usdz-anzen-usdz', 'base', 'USDZ',0x04d5ddf5f3a8939889f11e97f8c4bb48317f1938, 18), ('moxie-moxie', 'base', 'MOXIE',0x8C9037D1Ef5c6D1f6816278C7AAF5491d24CD527, 18), - ('cbbtc-coinbase-wrapped-btc', 'base', 'cbBTC',0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf, 8) + ('cbbtc-coinbase-wrapped-btc', 'base', 'cbBTC',0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf, 8), + --('weirdo-weirdo', 'base', 'weirdo',0x76734b57dfe834f102fb61e1ebf844adf8dd931e, 8), + --('lune-luneko', 'base', 'LUNE',0xacd1caef47e4c47bafe8a51b3f4305fc38203b7a, 18), + ('peach-based-peaches', 'base', 'PEACH',0x8319767a7b602f88e376368dca1b92d38869b9b4, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) diff --git a/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql b/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql index e638e058d1c..eacc6918696 100644 --- a/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/bnb/prices_bnb_tokens.sql @@ -280,7 +280,13 @@ FROM ('zeta-zetachain', 'bnb', 'ZETA', 0x0000028a2eb8346cd5c0267856ab7594b7a55308, 18), ('euri-eurite', 'bnb', 'EURI', 0x9d1a7a3191102e9f900faa10540837ba84dcbae7, 18), ('cookie-cookie', 'bnb', 'COOKIE', 0xc0041ef357b183448b235a8ea73ce4e4ec8c265f, 18), - ('wsteth-wrapped-liquid-staked-ether-20', 'bnb', 'wstETH', 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C, 18) + ('wsteth-wrapped-liquid-staked-ether-20', 'bnb', 'wstETH', 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C, 18), + ('arty-artyfact', 'bnb', 'ARTY', 0x617cab4aaae1f8dfb3ee138698330776a1e1b324, 6), + ('bccoin-blackcardcoin', 'bnb', 'BCCOIN', 0x2940566eb50f15129238f4dc599adc4f742d7d8e, 18), + ('app-moon-app', 'bnb', 'APP', 0xc5d27f27f08d1fd1e3ebbaa50b3442e6c0d50439, 18), + ('chapz-chappyz', 'bnb', 'CHAPZ', 0x7b56748a3ef9970a5bae99c58ad8bc67b26c525f, 10), + ('babyrwa-babyrwa', 'bnb', 'BABYRWA', 0x4a8049c015ae1c6665fc9e49f053458ae3a102d0, 9) + ) as temp (token_id, blockchain, symbol, contract_address, decimals) where contract_address not in ( 0x2ab0e9e4ee70fff1fb9d67031e44f6410170d00e -- bXEN has bad price feed. diff --git a/dbt_subprojects/tokens/models/prices/polygon/prices_polygon_tokens.sql b/dbt_subprojects/tokens/models/prices/polygon/prices_polygon_tokens.sql index 313d323bf7c..1fa36eb8255 100644 --- a/dbt_subprojects/tokens/models/prices/polygon/prices_polygon_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/polygon/prices_polygon_tokens.sql @@ -138,7 +138,9 @@ FROM ('next-connext-eth', 'polygon', 'NEXT', 0x58b9cb810a68a7f3e1e4f8cb45d1b9b3c79705e8, 18), ('usdm-mountain-protocol-usd', 'polygon', 'USDM', 0x57f5e098cad7a3d1eed53991d4d66c45c9af7812, 18), ('crowd-crowdswap', 'polygon', 'CROWD', 0x483dd3425278c1f79f377f1034d9d2cae55648b6, 18), - ('trb-tellor', 'polygon', 'TRB', 0xe3322702bedaaed36cddab233360b939775ae5f1, 18) + ('trb-tellor', 'polygon', 'TRB', 0xe3322702bedaaed36cddab233360b939775ae5f1, 18) + --('alta-alta-finance', 'polygon', 'ALTA', 0xe0cca86b254005889ac3a81e737f56a14f4a38f5, 18), + --('pbos-phobos-token', 'polygon', 'PBOS', 0x421b9b487d5a9b76e4b81809c0f1b9bb8cb24cb9, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) where contract_address not in ( 0xef938b6da8576a896f6e0321ef80996f4890f9c4 -- DG, bad price feed From e89dfe947f969a2c0a942db9f3ade3d99fbdf97e Mon Sep 17 00:00:00 2001 From: 0xroll <96259407+0xroll@users.noreply.github.com> Date: Mon, 30 Sep 2024 23:04:51 +0800 Subject: [PATCH 44/59] Update README.md (#6851) --- dbt_subprojects/tokens/models/prices/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt_subprojects/tokens/models/prices/README.md b/dbt_subprojects/tokens/models/prices/README.md index 59db804c5d2..990fc8d0c19 100644 --- a/dbt_subprojects/tokens/models/prices/README.md +++ b/dbt_subprojects/tokens/models/prices/README.md @@ -11,7 +11,7 @@ - Find the API ID in the overview section, slightly down the page: `uni-uniswap` - Test the API call result in my web browser: https://api.coinpaprika.com/v1/coins/uni-uniswap - Ensure the token feed via the API is live, with the `"is_active":true` flag -- Add a row to the Ethereum prices spell: https://github.com/duneanalytics/spellbook/blob/main/models/prices/ethereum/prices_ethereum_tokens.sql +- Add a row to the Ethereum prices spell: https://github.com/duneanalytics/spellbook/blob/main/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql - In the PR process to add a token, tests will run to ensure unique address value - Tests against the API will also run, to ensure results return as expected - Request review from maintainers to get PR merged @@ -46,4 +46,4 @@ Any time! Dune team will do their best to merge as quickly as possible to get li - If a token is cross-chain with the same address, but a blockchain isn't supported, the data can be pulled from the other blockchain -- be sure to keep blockchain consistent with the spell it's in, even if pulling from different one on the API - What if my token can't be found on Coinpaprika? - Please follow their process to add tokens [here](https://coinpaprika.com/add/) - - If request is urgent, Dune team may be able to expedite request once it's made in above link \ No newline at end of file + - If request is urgent, Dune team may be able to expedite request once it's made in above link From 4cec2424c3e0498aa56be5b8af410f359a1eb8b0 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:05:56 -0300 Subject: [PATCH 45/59] add missing tokens (#6852) Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../models/gyroscope/gyroscope_gyro_tokens.sql | 2 ++ .../tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql | 5 ++++- .../tokens/models/tokens/gnosis/tokens_gnosis_erc20.sql | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_gyro_tokens.sql b/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_gyro_tokens.sql index cc7cf42684d..d581e22edf0 100644 --- a/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_gyro_tokens.sql +++ b/dbt_subprojects/daily_spellbook/models/gyroscope/gyroscope_gyro_tokens.sql @@ -14,6 +14,8 @@ WITH gyro_tokens as ( (0x4EA71A20e655794051D1eE8b6e4A3269B13ccaCc, 'stataBasUSDC', 6, 'base'), (0x270ba1f35d8b87510d24f693fccc0da02e6e4eeb, 'stataGnoUSDC', 6, 'base'), (0x862c57d48becB45583AEbA3f489696D22466Ca1b, 'stataEthUSDT', 6, 'ethereum'), + (0x848107491e029afde0ac543779c7790382f15929, 'stataEthcrvUSD', 18, 'ethereum'), + (0xDBf5E36569798D1E39eE9d7B1c61A7409a74F23A, 'stataEthLUSD', 18, 'ethereum'), (0x87A1fdc4C726c459f597282be639a045062c0E46, 'stataPolUSDT', 6, 'polygon'), (0x2dCa80061632f3F87c9cA28364d1d0c30cD79a19, 'stataPolUSDCn', 6, 'polygon'), (0x4dd03dfd36548c840b563745e3fbec320f37ba7e, 'stataOptUSDCn', 6, 'optimism'), diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql index 1e9ef995585..4f45276ca99 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql @@ -4631,6 +4631,9 @@ FROM (VALUES , ( 0xe9689028ede16c2fdfe3d11855d28f8e3fc452a3, 'BUBBLE', 9) , ( 0xeb9951021698b42e4399f9cbb6267aa35f82d59d, 'LIF', 18) , ( 0x707f9118e33a9b8998bea41dd0d46f38bb963fc8, 'bETH', 18) + , ( 0x848107491e029afde0ac543779c7790382f15929, 'stataEthcrvUSD', 18) + , ( 0xDBf5E36569798D1E39eE9d7B1c61A7409a74F23A, 'stataEthLUSD', 18) + , ( 0x63e5dC7C071C1F18d44b69bc86f4c80F24851388, 'KAI', 18) + , ( 0xFFd9c960bC303b8d3aAED58229ce8a7310bCc5b8, 'KAIAURA', 18) , ( 0xdc035d45d973e3ec169d2276ddab16f1e407384f, 'USDS', 18) - ) AS temp_table (contract_address, symbol, decimals) diff --git a/dbt_subprojects/tokens/models/tokens/gnosis/tokens_gnosis_erc20.sql b/dbt_subprojects/tokens/models/tokens/gnosis/tokens_gnosis_erc20.sql index d99c973b8bc..04262687f94 100644 --- a/dbt_subprojects/tokens/models/tokens/gnosis/tokens_gnosis_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/gnosis/tokens_gnosis_erc20.sql @@ -7798,4 +7798,9 @@ FROM (VALUES , ( 0x4e5af8c1bd8ec1ffafa8a6043e57c3d384a7c574, 'ZTLN', 18) , ( 0x0deee1f9b96cac0b0ec85e8f800bc0b33e901e9a, 'IDOL', 18) , ( 0xfef5f9d8fe3b23fe4a242a461e537bb69364de94, 'VCUSD', 18) + , ( 0x14a5f2872396802c3cc8942a39ab3e4118ee5038, 'bTSLA', 18) + , ( 0x7212088a11b4d8f6fc90fbb3dfe793b45dd72323, 'bGME', 18) + , ( 0xac28c9178acc8ba4a11a29e013a3a2627086e422, 'bMSTR', 18) + , ( 0xa34c5e0abe843e10461e2c9586ea03e55dbcc495, 'bNVDA', 18) + , ( 0xbbcb0356bb9e6b3faa5cbf9e5f36185d53403ac9, 'bCOIN', 18) ) AS temp_table (contract_address, symbol, decimals) From c62a18284439c4ced55f1d795702b60e207c3470 Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Mon, 30 Sep 2024 13:21:51 -0400 Subject: [PATCH 46/59] exclude due to dupes failing prod (#6854) --- .../daily_spellbook/models/dao/balances/dao_balances.sql | 1 + .../daily_spellbook/models/dao/balances/dao_balances_steth.sql | 2 +- .../transactions/ethereum/dao_transactions_ethereum_erc20.sql | 2 +- .../dao/transactions/ethereum/dao_transactions_ethereum_eth.sql | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dbt_subprojects/daily_spellbook/models/dao/balances/dao_balances.sql b/dbt_subprojects/daily_spellbook/models/dao/balances/dao_balances.sql index 418150e1abf..89689d569a0 100644 --- a/dbt_subprojects/daily_spellbook/models/dao/balances/dao_balances.sql +++ b/dbt_subprojects/daily_spellbook/models/dao/balances/dao_balances.sql @@ -1,4 +1,5 @@ {{ config( + tags = ['prod_exclude'], schema = 'dao', alias = 'balances', materialized = 'table', diff --git a/dbt_subprojects/daily_spellbook/models/dao/balances/dao_balances_steth.sql b/dbt_subprojects/daily_spellbook/models/dao/balances/dao_balances_steth.sql index 0001f4b7fcc..c84751d58bd 100644 --- a/dbt_subprojects/daily_spellbook/models/dao/balances/dao_balances_steth.sql +++ b/dbt_subprojects/daily_spellbook/models/dao/balances/dao_balances_steth.sql @@ -1,5 +1,5 @@ {{ config( - + tags = ['prod_exclude'], alias = 'balances_steth', materialized = 'table', file_format = 'delta', diff --git a/dbt_subprojects/daily_spellbook/models/dao/transactions/ethereum/dao_transactions_ethereum_erc20.sql b/dbt_subprojects/daily_spellbook/models/dao/transactions/ethereum/dao_transactions_ethereum_erc20.sql index e74f72321ae..74ae570c317 100644 --- a/dbt_subprojects/daily_spellbook/models/dao/transactions/ethereum/dao_transactions_ethereum_erc20.sql +++ b/dbt_subprojects/daily_spellbook/models/dao/transactions/ethereum/dao_transactions_ethereum_erc20.sql @@ -1,5 +1,5 @@ {{ config( - + tags = ['prod_exclude'], alias = 'transactions_ethereum_erc20', partition_by = ['block_month'], materialized = 'incremental', diff --git a/dbt_subprojects/daily_spellbook/models/dao/transactions/ethereum/dao_transactions_ethereum_eth.sql b/dbt_subprojects/daily_spellbook/models/dao/transactions/ethereum/dao_transactions_ethereum_eth.sql index 4491c5f4da9..ca7c74e7157 100644 --- a/dbt_subprojects/daily_spellbook/models/dao/transactions/ethereum/dao_transactions_ethereum_eth.sql +++ b/dbt_subprojects/daily_spellbook/models/dao/transactions/ethereum/dao_transactions_ethereum_eth.sql @@ -1,5 +1,5 @@ {{ config( - + tags = ['prod_exclude'], alias = 'transactions_ethereum_eth', partition_by = ['block_month'], materialized = 'incremental', From 3a8f8371eb47f20415998ac7f30d0b9eb4ce106e Mon Sep 17 00:00:00 2001 From: Tiago <66181828+tiagofilipenunes@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:28:27 +0100 Subject: [PATCH 47/59] Re-add cREAL now that it has more volume (#6853) --- .../tokens/models/prices/celo/prices_celo_tokens.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/celo/prices_celo_tokens.sql b/dbt_subprojects/tokens/models/prices/celo/prices_celo_tokens.sql index 8bb307e023b..88ef25c5f76 100644 --- a/dbt_subprojects/tokens/models/prices/celo/prices_celo_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/celo/prices_celo_tokens.sql @@ -19,7 +19,7 @@ FROM ('celo-celo', 'celo', 'CELO', 0x471ece3750da237f93b8e339c536989b8978a438, 18), ('cusd-celo-dollar', 'celo', 'cUSD', 0x765de816845861e75a25fca122bb6898b8b1282a, 18), ('ceur-celo-euro', 'celo', 'cEUR', 0xd8763cba276a3738e6de85b4b3bf5fded6d6ca73, 18), --requested add to coinPaprika 2023-08-10 - --('creal-celo-brazilian-real', 'celo', 'cREAL', 0xe8537a3d056DA446677B9E9d6c5dB704EaAb4787, 18), --listed but no much volume + ('creal-celo-brazilian-real', 'celo', 'cREAL', 0xe8537a3d056DA446677B9E9d6c5dB704EaAb4787, 18), ('ico-axelar', 'celo', 'AXL', 0x23ee2343B892b1BB63503a4FAbc840E0e2C6810f, 6), --requested add to coinPaprika 2023-08-10 --('mimatic-mimatic', 'celo', 'MAI', 0xb9c8f0d3254007ee4b98970b94544e473cd610ec, 18), --requested add to coinPaprika 2023-08-10 ('wbtc-wrapped-bitcoin', 'celo', 'WBTC', 0xd629eb00deced2a080b7ec630ef6ac117e614f1b, 18), From 6cb4ee648e7981ba6b1e30ed511c5afa230cf4c0 Mon Sep 17 00:00:00 2001 From: stabble-devops <110252704+stabble-devops@users.noreply.github.com> Date: Mon, 30 Sep 2024 13:29:24 -0400 Subject: [PATCH 48/59] add stabble to jupiter_solana_aggregator (#6844) --- .../solana/models/jupiter/jupiter_solana_aggregator_swaps.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dbt_subprojects/solana/models/jupiter/jupiter_solana_aggregator_swaps.sql b/dbt_subprojects/solana/models/jupiter/jupiter_solana_aggregator_swaps.sql index ebcc159fcb7..44e2459824a 100644 --- a/dbt_subprojects/solana/models/jupiter/jupiter_solana_aggregator_swaps.sql +++ b/dbt_subprojects/solana/models/jupiter/jupiter_solana_aggregator_swaps.sql @@ -22,6 +22,8 @@ with FROM ( --use this api https://station.jup.ag/api-v6/get-program-id-to-label values + ('stabble Stable Swap', 'swapNyd8XiQwJ6ianp9snpu4brUqFxadzvHebnAXjJZ'), + ('stabble Weighted Swap', 'swapFpHZwjELNnjvThjajtiVmkz3yPQEHjLtka2fwHW'), ('Invariant', 'HyaB3W9q6XdA5xwpU4XnSZV94htfmbmqJXZcEbRaJutt'), ('Saber (Decimals)', 'DecZY86MU5Gj7kppfUCEmd4LbXXuyZH1yHaP2NTqdiZB'), ('Balansol', 'D3BBjqUdCYuP18fNvvMbPAZ8DpcRi4io2EsYHQawJDag'), From 95d42ef7d710860475902823eaeda4ebae96ebe1 Mon Sep 17 00:00:00 2001 From: henrystats <65398020+henrystats@users.noreply.github.com> Date: Tue, 1 Oct 2024 14:10:01 +0100 Subject: [PATCH 49/59] Add eigen to tokens.erc20 (#6860) --- .../tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql index 4f45276ca99..dc0ed2338d6 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql @@ -4636,4 +4636,5 @@ FROM (VALUES , ( 0x63e5dC7C071C1F18d44b69bc86f4c80F24851388, 'KAI', 18) , ( 0xFFd9c960bC303b8d3aAED58229ce8a7310bCc5b8, 'KAIAURA', 18) , ( 0xdc035d45d973e3ec169d2276ddab16f1e407384f, 'USDS', 18) + , ( 0xec53bF9167f50cDEB3Ae105f56099aaaB9061F83, 'EIGEN', 18) ) AS temp_table (contract_address, symbol, decimals) From c82170935a85dc620d94970dc3adf03e472f62f9 Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:10:11 -0300 Subject: [PATCH 50/59] Update prices_ethereum_tokens.sql (#6859) --- .../tokens/models/prices/ethereum/prices_ethereum_tokens.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql b/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql index 0dc3d95b49c..71c8e1028f8 100644 --- a/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql +++ b/dbt_subprojects/tokens/models/prices/ethereum/prices_ethereum_tokens.sql @@ -1840,7 +1840,8 @@ FROM ('lbtc-lombard-staked-btc', 'ethereum', 'LBTC', 0x8236a87084f8b84306f72007f36f2618a5634494, 8), ('msn-mesonnetwork', 'ethereum', 'MSN', 0xaa247c0d81b83812e1abf8bab078e4540d87e3fb, 18), ('zeta-zetachain', 'ethereum', 'ZETA', 0xf091867ec603a6628ed83d274e835539d82e9cc8, 18), - ('euri-eurite', 'ethereum', 'EURI', 0x9d1a7a3191102e9f900faa10540837ba84dcbae7, 18) + ('euri-eurite', 'ethereum', 'EURI', 0x9d1a7a3191102e9f900faa10540837ba84dcbae7, 18), + ('eigen-eigenlayer', 'ethereum', 'EIGEN', 0xec53bF9167f50cDEB3Ae105f56099aaaB9061F83, 18) --('sky-sky', 'ethereum', 'SKY', 0x56072C95FAA701256059aa122697B133aDEd9279, 18), --('usds-usds', 'ethereum', 'USDS', 0xdc035d45d973e3ec169d2276ddab16f1e407384f, 18) ) as temp (token_id, blockchain, symbol, contract_address, decimals) From 6bfd75541bde5ee19b0bd8be0d379721844ccf7f Mon Sep 17 00:00:00 2001 From: hildobby Date: Tue, 1 Oct 2024 15:10:34 +0200 Subject: [PATCH 51/59] fantasy.events small update (#6858) * add traded_ids col * fix --- .../daily_spellbook/models/_projects/fantasy/_schema.yml | 2 ++ .../models/_projects/fantasy/fantasy_events.sql | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/daily_spellbook/models/_projects/fantasy/_schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/fantasy/_schema.yml index 6baed668877..628ddb341a7 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/fantasy/_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/_projects/fantasy/_schema.yml @@ -33,6 +33,8 @@ models: description: "The list of minted fantasy.top card token ids" - name: burned_ids description: "The list of burned fantasy.top card token ids" + - name: traded_ids + description: "The list of traded fantasy.top card token ids" - name: traded_with description: "Who was on the other side of this executed trade" - name: tx_from diff --git a/dbt_subprojects/daily_spellbook/models/_projects/fantasy/fantasy_events.sql b/dbt_subprojects/daily_spellbook/models/_projects/fantasy/fantasy_events.sql index 4ee6c7bc4f4..63233f8b65b 100644 --- a/dbt_subprojects/daily_spellbook/models/_projects/fantasy/fantasy_events.sql +++ b/dbt_subprojects/daily_spellbook/models/_projects/fantasy/fantasy_events.sql @@ -57,6 +57,7 @@ SELECT m.evt_block_time AS block_time , m.firstTokenId+90, m.firstTokenId+91, m.firstTokenId+92, m.firstTokenId+93, m.firstTokenId+94, m.firstTokenId+95, m.firstTokenId+96, m.firstTokenId+97, m.firstTokenId+98, m.firstTokenId+99 ], x -> x <= lastTokenId) AS minted_ids , NULL AS burned_ids +, NULL AS traded_ids , NULL AS traded_with , m.evt_tx_from AS tx_from , m.evt_tx_to AS tx_to @@ -93,6 +94,7 @@ SELECT evt_block_time AS block_time , CAST(cardinality(burntTokenIds) AS double) AS cards_burned , ARRAY[mintedTokenId] AS minted_ids , burntTokenIds AS burned_ids +, NULL AS traded_ids , NULL AS traded_with , evt_tx_from AS tx_from , evt_tx_to AS tx_to @@ -125,6 +127,7 @@ SELECT evt_block_time AS block_time , CAST(cardinality(burntTokenIds) AS double) AS cards_burned , mintedTokenIds AS minted_ids , burntTokenIds AS burned_ids +, NULL AS traded_ids , NULL AS traded_with , evt_tx_from AS tx_from , evt_tx_to AS tx_to @@ -157,6 +160,7 @@ SELECT nftt.block_time , CAST(0 AS double) AS cards_burned , NULL AS minted_ids , NULL AS burned_ids +, nftt.token_id AS traded_ids , CASE WHEN nftt.trade_category='Buy' THEN nftt.seller ELSE nftt.buyer END AS traded_with , nftt.tx_from , nftt.tx_to @@ -178,7 +182,7 @@ INNER JOIN {{ source('blast', 'transactions') }} txs ON txs.block_number=nftt.bl AND txs.hash=nftt.tx_hash LEFT JOIN {{source('nft_blast', 'wash_trades')}} wt ON wt.project = 'fantasy' AND wt.block_number=nftt.block_number - AND wt.tx_hash=nftt.tx_hash + AND nftt.unique_trade_id=wt.unique_trade_id WHERE nftt.blockchain = 'blast' AND nftt.project = 'fantasy' @@ -196,6 +200,7 @@ SELECT block_time , CAST(0 AS double) AS cards_burned , NULL AS minted_ids , NULL AS burned_ids +, NULL AS traded_ids , NULL AS traded_with , tx_from , tx_to From a32b0e638aca16ed77ec80382494f0843999eac5 Mon Sep 17 00:00:00 2001 From: Vitalii Tsyhulov <83537328+0xVitalii@users.noreply.github.com> Date: Tue, 1 Oct 2024 06:10:44 -0700 Subject: [PATCH 52/59] Update prices_optimism_tokens_curated.sql (#6856) Adding new token --- .../models/prices/optimism/prices_optimism_tokens_curated.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/prices/optimism/prices_optimism_tokens_curated.sql b/dbt_subprojects/tokens/models/prices/optimism/prices_optimism_tokens_curated.sql index fb2f1cc0a5d..9691ac9393c 100644 --- a/dbt_subprojects/tokens/models/prices/optimism/prices_optimism_tokens_curated.sql +++ b/dbt_subprojects/tokens/models/prices/optimism/prices_optimism_tokens_curated.sql @@ -134,5 +134,6 @@ FROM ('dola-dola', 'DOLA',0x8ae125e8653821e851f12a49f7765db9a9ce7384, 18), ('wld-worldcoin', 'WLD',0xdc6ff44d5d932cbd77b52e5612ba0529dc6226f1, 18), ('pendle-pendle', 'PENDLE',0xbc7b1ff1c6989f006a1185318ed4e7b5796e66e1, 18), - ('trb-tellor', 'TRB', 0xaf8ca653fa2772d58f4368b0a71980e9e3ceb888, 18) + ('trb-tellor', 'TRB', 0xaf8ca653fa2772d58f4368b0a71980e9e3ceb888, 18), + ('dtoro-dextoro', 'DTORO', 0x1cef2d62af4cd26673c7416957cc4ec619a696a7, 18) ) as temp (token_id, symbol, contract_address, decimals) From 8fd4c15e0a6d7b0f67d1ff2166a8e42d4d9223eb Mon Sep 17 00:00:00 2001 From: hildobby Date: Tue, 1 Oct 2024 15:19:51 +0200 Subject: [PATCH 53/59] add puffer addresses (#6825) --- ..._ethereum_entities_depositor_addresses.sql | 289 +++++++++++------- 1 file changed, 181 insertions(+), 108 deletions(-) diff --git a/dbt_subprojects/hourly_spellbook/models/_sector/staking/ethereum/entities/staking_ethereum_entities_depositor_addresses.sql b/dbt_subprojects/hourly_spellbook/models/_sector/staking/ethereum/entities/staking_ethereum_entities_depositor_addresses.sql index 4d57d43f058..22ee2f9e356 100644 --- a/dbt_subprojects/hourly_spellbook/models/_sector/staking/ethereum/entities/staking_ethereum_entities_depositor_addresses.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/staking/ethereum/entities/staking_ethereum_entities_depositor_addresses.sql @@ -121,114 +121,187 @@ FROM , (0xea674fdde714fd979de3edf0f56aa9716b898ec8, 'Ethermine', 'Ethermine', 'Staking Pool') , (0x25e821b7197b146f7713c3b89b6a4d83516b912d, 'ether.fi', 'ether.fi', 'Liquid Restaking') , (0xe60ca7abf24de99af64e7d9057659ae2dbc2eb2c, 'Puffer Finance', 'Puffer Finance 1', 'Liquid Restaking') - , (0x53bdF36503864593406D8e0e9fe848f2cEB91817, 'Puffer Finance', 'Puffer Finance 2', 'Liquid Restaking') - , (0x4d7c3fc856ab52753b91a6c9213adf013309dd25, 'Puffer Finance', 'Puffer Finance 3', 'Liquid Restaking') - , (0xf831b40e80ffd364b0a08619666ee09df3a3f73a, 'Puffer Finance', 'Puffer Finance 4', 'Liquid Restaking') - , (0x6d069d7210A97a5F86150698Ccc8D750fcA2512f, 'Puffer Finance', 'Puffer Finance 5', 'Liquid Restaking') - , (0x175da1e44c8fbf124714a3bba5dc18a7e65664d6, 'Puffer Finance', 'Puffer Finance 6', 'Liquid Restaking') - , (0xf5d31b441b8f1c53c7c5beb80089fec228c531fb, 'Puffer Finance', 'Puffer Finance 7', 'Liquid Restaking') - , (0x1719e587d4Cb7e9F3a0e9351c83ADc48dC9e7bCF, 'Puffer Finance', 'Puffer Finance 8', 'Liquid Restaking') - , (0x73f23013c5a4c209de945cdc58595a4d53d23084, 'Puffer Finance', 'Puffer Finance 9', 'Liquid Restaking') - , (0xa4c78fdae426d16baa010acedeec87706ac3f76b, 'Puffer Finance', 'Puffer Finance 10', 'Liquid Restaking') - , (0x0e3AC3cD91889343B6F9D24Fda634E571BBCE643, 'Puffer Finance', 'Puffer Finance 11', 'Liquid Restaking') - , (0x59639aeee35c4108923fd16e66055b347fbeadd2, 'Puffer Finance', 'Puffer Finance 12', 'Liquid Restaking') - , (0xbb43dcafa77fb5d1888a087ce6a30c287981c391, 'Puffer Finance', 'Puffer Finance 13', 'Liquid Restaking') - , (0xc8c131befBeFE0bC0eD06C0C263335a01322D000, 'Puffer Finance', 'Puffer Finance 14', 'Liquid Restaking') - , (0xdd6859450e80665db854022e85fb0ed2f0240cb9, 'Puffer Finance', 'Puffer Finance 15', 'Liquid Restaking') - , (0xbca580b952801236322734bb146f3e27894f736e, 'Puffer Finance', 'Puffer Finance 16', 'Liquid Restaking') - , (0x6Ab300BA5C74d3F2AaC53F730fa16A9E1588B46c, 'Puffer Finance', 'Puffer Finance 17', 'Liquid Restaking') - , (0xe48e7102c03812dfa1fdf0bbe6dbba6dc70b0f33, 'Puffer Finance', 'Puffer Finance 18', 'Liquid Restaking') - , (0x48c09cad9d785e21210a4e84fcb0ff5a3a73c58d, 'Puffer Finance', 'Puffer Finance 19', 'Liquid Restaking') - , (0x0e54A434b0a8Fb4c7f549FBEc551638754736944, 'Puffer Finance', 'Puffer Finance 20', 'Liquid Restaking') - , (0xe859a34cdd097ac7e8167ad828ca9ad969925a6a, 'Puffer Finance', 'Puffer Finance 21', 'Liquid Restaking') - , (0x5fde1b2d371243edca74b77082d40e01c5f15b31, 'Puffer Finance', 'Puffer Finance 22', 'Liquid Restaking') - , (0x92223B7CaCCDCc1A1164F581BA41C9356482932e, 'Puffer Finance', 'Puffer Finance 23', 'Liquid Restaking') - , (0xc327e3152ef9784faf0190cfa2592ddea5455430, 'Puffer Finance', 'Puffer Finance 24', 'Liquid Restaking') - , (0xC06B5AEbE343336C382ef397c718f4dfdcEB3424, 'Puffer Finance', 'Puffer Finance 25', 'Liquid Restaking') - , (0x4cee5738cc8cc1ff262034c4ddcf42675504afa9, 'Puffer Finance', 'Puffer Finance 26', 'Liquid Restaking') - , (0x1c354702D52b3aCf46372fd3578CE7ba9170F70c, 'Puffer Finance', 'Puffer Finance 27', 'Liquid Restaking') - , (0x9afca71c47910fe300fe0419a621a29c79537337, 'Puffer Finance', 'Puffer Finance 28', 'Liquid Restaking') - , (0xaCc1C68400C589BBA01b8F1CAA2Cb82eE9f389a4, 'Puffer Finance', 'Puffer Finance 29', 'Liquid Restaking') - , (0x0c9e6af5ad0d4826d81b8d51c4f4c2044ad05763, 'Puffer Finance', 'Puffer Finance 30', 'Liquid Restaking') - , (0xEDdB5f8dbEEF8959208daA10B931BB060F90CD6E, 'Puffer Finance', 'Puffer Finance 31', 'Liquid Restaking') - , (0xf66a37b7d6e99b9af3d835d1b33c80abe339915d, 'Puffer Finance', 'Puffer Finance 32', 'Liquid Restaking') - , (0x62d9019E0CCd6c8257F64651640BCd1AE23BC61f, 'Puffer Finance', 'Puffer Finance 33', 'Liquid Restaking') - , (0x2ab60aa450c7f16afd70f27a789833ebc638a9d0, 'Puffer Finance', 'Puffer Finance 34', 'Liquid Restaking') - , (0x40dcF0463a9b7FD50a8D8c7D8601798E12Effd36, 'Puffer Finance', 'Puffer Finance 35', 'Liquid Restaking') - , (0xc6910530820b3b85053be0db2863f332d6f45792, 'Puffer Finance', 'Puffer Finance 36', 'Liquid Restaking') - , (0x9d64c17F8C0fE43173818f9BD42D68638d3eD127, 'Puffer Finance', 'Puffer Finance 37', 'Liquid Restaking') - , (0x4d92687163dcfd582bb9e103e9086904901b55f8, 'Puffer Finance', 'Puffer Finance 38', 'Liquid Restaking') - , (0x9C938360b31bDDeab8C1B372b14dBd7E6270c5a8, 'Puffer Finance', 'Puffer Finance 39', 'Liquid Restaking') - , (0xfbe7657e38fe774027978271603ec22d95c1eb54, 'Puffer Finance', 'Puffer Finance 40', 'Liquid Restaking') - , (0x9481dC8d24578256A38e9Fe094A4493fdcf72b4e, 'Puffer Finance', 'Puffer Finance 41', 'Liquid Restaking') - , (0xf22a3f429905f9faa2ebe5947fc2d58b6ecce440, 'Puffer Finance', 'Puffer Finance 42', 'Liquid Restaking') - , (0xeBD58Fd9125ADaA16dB719bCf85dCFf1Eb71FAAc, 'Puffer Finance', 'Puffer Finance 43', 'Liquid Restaking') - , (0x5a2b0b1a12af2b10c7d6a4ab612a667cb8ba278d, 'Puffer Finance', 'Puffer Finance 44', 'Liquid Restaking') - , (0x7CBab465543E4cCE8E81bf25732A4bac551cCC3c, 'Puffer Finance', 'Puffer Finance 45', 'Liquid Restaking') - , (0xfe80649dc2cb126dd10603be02f0d94afc364fc9, 'Puffer Finance', 'Puffer Finance 46', 'Liquid Restaking') - , (0x2aAc86bD3bc5baE447bBcAF5a201656a95fACE7C, 'Puffer Finance', 'Puffer Finance 47', 'Liquid Restaking') - , (0x2d8f1a00e3e768d679fa7bd6fe567faa70f726b2, 'Puffer Finance', 'Puffer Finance 48', 'Liquid Restaking') - , (0x95401f1B03C11E16840119556a495549953F47A6, 'Puffer Finance', 'Puffer Finance 49', 'Liquid Restaking') - , (0x3000ca8ae328ae3996ee22c30b609d8e2b701599, 'Puffer Finance', 'Puffer Finance 50', 'Liquid Restaking') - , (0x67e3020efd52b14be4158eb888611f6d6930e02a, 'Puffer Finance', 'Puffer Finance 51', 'Liquid Restaking') - , (0x7822be4356b5e633bb8a445952c3d35fdb642986, 'Puffer Finance', 'Puffer Finance 52', 'Liquid Restaking') - , (0x031f5c9a8c1af1eb5ad48b9f6ab4253a66c5d4b6, 'Puffer Finance', 'Puffer Finance 53', 'Liquid Restaking') - , (0xda2dcde31b020b6b6f8c02d2bf4821db22091750, 'Puffer Finance', 'Puffer Finance 54', 'Liquid Restaking') - , (0x21b5e2044f73b257cdbe3bdc402f02b404cbfbf1, 'Puffer Finance', 'Puffer Finance 55', 'Liquid Restaking') - , (0x32eec068c4d0578b94169726890d5395d4647dc4, 'Puffer Finance', 'Puffer Finance 56', 'Liquid Restaking') - , (0xd346547f70ef624b36d5ec284c6d27710920b712, 'Puffer Finance', 'Puffer Finance 57', 'Liquid Restaking') - , (0x70d8c06125145281710dd73de382b7c1938200ea, 'Puffer Finance', 'Puffer Finance 58', 'Liquid Restaking') - , (0xd52fcbb08732de26a99a7f0c0a50412820a4b683, 'Puffer Finance', 'Puffer Finance 59', 'Liquid Restaking') - , (0x55efc9f901a5ada996011276450f7320729223b0, 'Puffer Finance', 'Puffer Finance 60', 'Liquid Restaking') - , (0x970601aeecf72a18c3afddd29078fd89a4bc267e, 'Puffer Finance', 'Puffer Finance 61', 'Liquid Restaking') - , (0xc1102180394132f19b6a50a158ec313ceffc4a3a, 'Puffer Finance', 'Puffer Finance 62', 'Liquid Restaking') - , (0x779190349f31c7bba1db2da051f118bf3074a477, 'Puffer Finance', 'Puffer Finance 63', 'Liquid Restaking') - , (0xf2d65e8093201c1645b822f9849fe375ea96056a, 'Puffer Finance', 'Puffer Finance 64', 'Liquid Restaking') - , (0x3923eb2d93c84baf3fa60a277db720228647def7, 'Puffer Finance', 'Puffer Finance 65', 'Liquid Restaking') - , (0xb1ee744162e94cced7cab1d53d81664950e41c39, 'Puffer Finance', 'Puffer Finance 66', 'Liquid Restaking') - , (0xd7988e9347f0eaea570695e88acea9cc6b66be13, 'Puffer Finance', 'Puffer Finance 67', 'Liquid Restaking') - , (0x6c6f3c472b5180df84efc7d65e81f7950d87a3f6, 'Puffer Finance', 'Puffer Finance 68', 'Liquid Restaking') - , (0xdf762d0afc382850c5160e6a4d3cf521774032f9, 'Puffer Finance', 'Puffer Finance 69', 'Liquid Restaking') - , (0xca3964974bae15cb7d941b32712302b2b6c5d4ab, 'Puffer Finance', 'Puffer Finance 70', 'Liquid Restaking') - , (0xf8baa75b11d8dda80ad286254aac9d08edb505c1, 'Puffer Finance', 'Puffer Finance 71', 'Liquid Restaking') - , (0xb53d7bcbc30652ff35650246e3b591a064266b2b, 'Puffer Finance', 'Puffer Finance 72', 'Liquid Restaking') - , (0x57f514aab0ec72cdb9d2d01cae0dd6ecd4981ce1, 'Puffer Finance', 'Puffer Finance 73', 'Liquid Restaking') - , (0xfa33e7d1bdfcb213e0cffa6e981fcad12d1638fa, 'Puffer Finance', 'Puffer Finance 74', 'Liquid Restaking') - , (0x8e59e546b97eaaab54f9650c89dc3875556d9635, 'Puffer Finance', 'Puffer Finance 75', 'Liquid Restaking') - , (0x024d2378d80df4c6f49cb1f388d5a53d42c3e5fd, 'Puffer Finance', 'Puffer Finance 76', 'Liquid Restaking') - , (0x4bbe8d3bb39d30e1f29678ad0b3039b397c1d55f, 'Puffer Finance', 'Puffer Finance 77', 'Liquid Restaking') - , (0x8c81d590cc94ca2451c4bde24c598193da74a575, 'Puffer Finance', 'Puffer Finance 78', 'Liquid Restaking') - , (0x2a89d38a2fd5b3d90c6f3813d23e0c2ed33cd7e2, 'Puffer Finance', 'Puffer Finance 79', 'Liquid Restaking') - , (0x9ae3eb1948e70c7f9804e30a34e8c25e0dd8261d, 'Puffer Finance', 'Puffer Finance 80', 'Liquid Restaking') - , (0x5905361a292c4582139a9ceaec1a71ea950d0677, 'Puffer Finance', 'Puffer Finance 81', 'Liquid Restaking') - , (0x3c12e47bd31b7c72ab05b514abae4b5abe871072, 'Puffer Finance', 'Puffer Finance 82', 'Liquid Restaking') - , (0x4cda1525b7d6577a59b6325201b3a68939da91d8, 'Puffer Finance', 'Puffer Finance 83', 'Liquid Restaking') - , (0xe097f793464e4503616e55d28294bf0fb982d14f, 'Puffer Finance', 'Puffer Finance 84', 'Liquid Restaking') - , (0xb92ac33d59ec4f93787acc773ba6e26ef536749a, 'Puffer Finance', 'Puffer Finance 85', 'Liquid Restaking') - , (0xad3f79fdf705cda1e8d9d7c398a678ee6ebb2cab, 'Puffer Finance', 'Puffer Finance 86', 'Liquid Restaking') - , (0xdbe13208672a329ac8827d5752ba3e63253617aa, 'Puffer Finance', 'Puffer Finance 87', 'Liquid Restaking') - , (0x11d28e6a3a8513432af889b25318d9b94bcb0d99, 'Puffer Finance', 'Puffer Finance 88', 'Liquid Restaking') - , (0xd695b18944902c0a2c899aaa789e06d30e6b0c6c, 'Puffer Finance', 'Puffer Finance 89', 'Liquid Restaking') - , (0xec77866c71f19b694b2d1640b0dc8585a3555596, 'Puffer Finance', 'Puffer Finance 90', 'Liquid Restaking') - , (0x5fee3852b09fd5be7043ba5eca71e674ea80c3ff, 'Puffer Finance', 'Puffer Finance 91', 'Liquid Restaking') - , (0x00c89174d831744ab9f004fc8056f85152443acc, 'Puffer Finance', 'Puffer Finance 92', 'Liquid Restaking') - , (0x4e15b6331eadaa84750870e4e24b84780c88ff91, 'Puffer Finance', 'Puffer Finance 93', 'Liquid Restaking') - , (0x444595c69006f6ac6acbf55d362d3036f5b636aa, 'Puffer Finance', 'Puffer Finance 94', 'Liquid Restaking') - , (0xd44cf40b14249811a50dcb6dbd809e94e421929e, 'Puffer Finance', 'Puffer Finance 95', 'Liquid Restaking') - , (0x572c5dfcbbec6815978adf2a835a34e8f04156fb, 'Puffer Finance', 'Puffer Finance 96', 'Liquid Restaking') - , (0xfe41129f707591fda06bfa30df467351d09f1806, 'Puffer Finance', 'Puffer Finance 97', 'Liquid Restaking') - , (0x5cc1a39d0b448ece222a3e2891315b7d3c104d62, 'Puffer Finance', 'Puffer Finance 98', 'Liquid Restaking') - , (0xc360a5080719b3819531e6a9135d7062a9aa71a4, 'Puffer Finance', 'Puffer Finance 99', 'Liquid Restaking') - , (0xd96ffffb94f1484903c4022f128830f636c696ef, 'Puffer Finance', 'Puffer Finance 100', 'Liquid Restaking') - , (0x1d5b496c6992e6ebcf7a38a4097017fad76457a8, 'Puffer Finance', 'Puffer Finance 101', 'Liquid Restaking') - , (0x364942ade69dd27ec53092aece9b0604c1ec45ae, 'Puffer Finance', 'Puffer Finance 102', 'Liquid Restaking') - , (0x31710a5588cd7fadbf5002744ee433a3ec5bf75b, 'Puffer Finance', 'Puffer Finance 103', 'Liquid Restaking') - , (0x75408e3a95a0d4db54a11b171e591f706d991e7a, 'Puffer Finance', 'Puffer Finance 104', 'Liquid Restaking') - , (0xb25cfe029b6dcd87d5d9ae333e587b7a4873ce29, 'Puffer Finance', 'Puffer Finance 105', 'Liquid Restaking') - , (0xd338e780a5b900ac66d16c106f8babb47040e47b, 'Puffer Finance', 'Puffer Finance 106', 'Liquid Restaking') - , (0xdd86602cda86bfa8d26cadb8fdafccf325e35433, 'Puffer Finance', 'Puffer Finance 107', 'Liquid Restaking') - , (0x97f51ba27bdee65bb87ffe38e4a88c9c938272f7, 'Puffer Finance', 'Puffer Finance 108', 'Liquid Restaking') - , (0xe1e2cac176c707d83206d27b49ade82d94807212, 'Puffer Finance', 'Puffer Finance 109', 'Liquid Restaking') + , (0x53bdf36503864593406d8e0e9fe848f2ceb91817, 'Puffer Finance', 'Puffer Finance 2', 'Liquid Restaking') + , (0xf831b40e80ffd364b0a08619666ee09df3a3f73a, 'Puffer Finance', 'Puffer Finance 3', 'Liquid Restaking') + , (0x6d069d7210a97a5f86150698ccc8d750fca2512f, 'Puffer Finance', 'Puffer Finance 4', 'Liquid Restaking') + , (0xf5d31b441b8f1c53c7c5beb80089fec228c531fb, 'Puffer Finance', 'Puffer Finance 5', 'Liquid Restaking') + , (0x1719e587d4cb7e9f3a0e9351c83adc48dc9e7bcf, 'Puffer Finance', 'Puffer Finance 6', 'Liquid Restaking') + , (0x9afca71c47910fe300fe0419a621a29c79537337, 'Puffer Finance', 'Puffer Finance 7', 'Liquid Restaking') + , (0xacc1c68400c589bba01b8f1caa2cb82ee9f389a4, 'Puffer Finance', 'Puffer Finance 8', 'Liquid Restaking') + , (0x0c9e6af5ad0d4826d81b8d51c4f4c2044ad05763, 'Puffer Finance', 'Puffer Finance 9', 'Liquid Restaking') + , (0xeddb5f8dbeef8959208daa10b931bb060f90cd6e, 'Puffer Finance', 'Puffer Finance 10', 'Liquid Restaking') + , (0xf66a37b7d6e99b9af3d835d1b33c80abe339915d, 'Puffer Finance', 'Puffer Finance 11', 'Liquid Restaking') + , (0x62d9019e0ccd6c8257f64651640bcd1ae23bc61f, 'Puffer Finance', 'Puffer Finance 12', 'Liquid Restaking') + , (0x2ab60aa450c7f16afd70f27a789833ebc638a9d0, 'Puffer Finance', 'Puffer Finance 13', 'Liquid Restaking') + , (0x40dcf0463a9b7fd50a8d8c7d8601798e12effd36, 'Puffer Finance', 'Puffer Finance 14', 'Liquid Restaking') + , (0xc6910530820b3b85053be0db2863f332d6f45792, 'Puffer Finance', 'Puffer Finance 15', 'Liquid Restaking') + , (0x9d64c17f8c0fe43173818f9bd42d68638d3ed127, 'Puffer Finance', 'Puffer Finance 16', 'Liquid Restaking') + , (0x4d92687163dcfd582bb9e103e9086904901b55f8, 'Puffer Finance', 'Puffer Finance 17', 'Liquid Restaking') + , (0x9c938360b31bddeab8c1b372b14dbd7e6270c5a8, 'Puffer Finance', 'Puffer Finance 18', 'Liquid Restaking') + , (0xfbe7657e38fe774027978271603ec22d95c1eb54, 'Puffer Finance', 'Puffer Finance 19', 'Liquid Restaking') + , (0x9481dc8d24578256a38e9fe094a4493fdcf72b4e, 'Puffer Finance', 'Puffer Finance 20', 'Liquid Restaking') + , (0xf22a3f429905f9faa2ebe5947fc2d58b6ecce440, 'Puffer Finance', 'Puffer Finance 21', 'Liquid Restaking') + , (0xebd58fd9125adaa16db719bcf85dcff1eb71faac, 'Puffer Finance', 'Puffer Finance 22', 'Liquid Restaking') + , (0x5a2b0b1a12af2b10c7d6a4ab612a667cb8ba278d, 'Puffer Finance', 'Puffer Finance 23', 'Liquid Restaking') + , (0x7cbab465543e4cce8e81bf25732a4bac551ccc3c, 'Puffer Finance', 'Puffer Finance 24', 'Liquid Restaking') + , (0xfe80649dc2cb126dd10603be02f0d94afc364fc9, 'Puffer Finance', 'Puffer Finance 25', 'Liquid Restaking') + , (0x2aac86bd3bc5bae447bbcaf5a201656a95face7c, 'Puffer Finance', 'Puffer Finance 26', 'Liquid Restaking') + , (0x2d8f1a00e3e768d679fa7bd6fe567faa70f726b2, 'Puffer Finance', 'Puffer Finance 27', 'Liquid Restaking') + , (0x95401f1b03c11e16840119556a495549953f47a6, 'Puffer Finance', 'Puffer Finance 28', 'Liquid Restaking') + , (0x3000ca8ae328ae3996ee22c30b609d8e2b701599, 'Puffer Finance', 'Puffer Finance 29', 'Liquid Restaking') + , (0x67e3020efd52b14be4158eb888611f6d6930e02a, 'Puffer Finance', 'Puffer Finance 30', 'Liquid Restaking') + , (0x7822be4356b5e633bb8a445952c3d35fdb642986, 'Puffer Finance', 'Puffer Finance 31', 'Liquid Restaking') + , (0x031f5c9a8c1af1eb5ad48b9f6ab4253a66c5d4b6, 'Puffer Finance', 'Puffer Finance 32', 'Liquid Restaking') + , (0xda2dcde31b020b6b6f8c02d2bf4821db22091750, 'Puffer Finance', 'Puffer Finance 33', 'Liquid Restaking') + , (0x21b5e2044f73b257cdbe3bdc402f02b404cbfbf1, 'Puffer Finance', 'Puffer Finance 34', 'Liquid Restaking') + , (0x32eec068c4d0578b94169726890d5395d4647dc4, 'Puffer Finance', 'Puffer Finance 35', 'Liquid Restaking') + , (0xd346547f70ef624b36d5ec284c6d27710920b712, 'Puffer Finance', 'Puffer Finance 36', 'Liquid Restaking') + , (0x70d8c06125145281710dd73de382b7c1938200ea, 'Puffer Finance', 'Puffer Finance 37', 'Liquid Restaking') + , (0xd52fcbb08732de26a99a7f0c0a50412820a4b683, 'Puffer Finance', 'Puffer Finance 38', 'Liquid Restaking') + , (0x55efc9f901a5ada996011276450f7320729223b0, 'Puffer Finance', 'Puffer Finance 39', 'Liquid Restaking') + , (0x970601aeecf72a18c3afddd29078fd89a4bc267e, 'Puffer Finance', 'Puffer Finance 40', 'Liquid Restaking') + , (0xc1102180394132f19b6a50a158ec313ceffc4a3a, 'Puffer Finance', 'Puffer Finance 41', 'Liquid Restaking') + , (0x779190349f31c7bba1db2da051f118bf3074a477, 'Puffer Finance', 'Puffer Finance 42', 'Liquid Restaking') + , (0xf2d65e8093201c1645b822f9849fe375ea96056a, 'Puffer Finance', 'Puffer Finance 43', 'Liquid Restaking') + , (0x3923eb2d93c84baf3fa60a277db720228647def7, 'Puffer Finance', 'Puffer Finance 44', 'Liquid Restaking') + , (0xb1ee744162e94cced7cab1d53d81664950e41c39, 'Puffer Finance', 'Puffer Finance 45', 'Liquid Restaking') + , (0xd7988e9347f0eaea570695e88acea9cc6b66be13, 'Puffer Finance', 'Puffer Finance 46', 'Liquid Restaking') + , (0x6c6f3c472b5180df84efc7d65e81f7950d87a3f6, 'Puffer Finance', 'Puffer Finance 47', 'Liquid Restaking') + , (0xdf762d0afc382850c5160e6a4d3cf521774032f9, 'Puffer Finance', 'Puffer Finance 48', 'Liquid Restaking') + , (0xca3964974bae15cb7d941b32712302b2b6c5d4ab, 'Puffer Finance', 'Puffer Finance 49', 'Liquid Restaking') + , (0xf8baa75b11d8dda80ad286254aac9d08edb505c1, 'Puffer Finance', 'Puffer Finance 50', 'Liquid Restaking') + , (0xb53d7bcbc30652ff35650246e3b591a064266b2b, 'Puffer Finance', 'Puffer Finance 51', 'Liquid Restaking') + , (0x57f514aab0ec72cdb9d2d01cae0dd6ecd4981ce1, 'Puffer Finance', 'Puffer Finance 52', 'Liquid Restaking') + , (0xfa33e7d1bdfcb213e0cffa6e981fcad12d1638fa, 'Puffer Finance', 'Puffer Finance 53', 'Liquid Restaking') + , (0x8e59e546b97eaaab54f9650c89dc3875556d9635, 'Puffer Finance', 'Puffer Finance 54', 'Liquid Restaking') + , (0x024d2378d80df4c6f49cb1f388d5a53d42c3e5fd, 'Puffer Finance', 'Puffer Finance 55', 'Liquid Restaking') + , (0x4bbe8d3bb39d30e1f29678ad0b3039b397c1d55f, 'Puffer Finance', 'Puffer Finance 56', 'Liquid Restaking') + , (0x2a89d38a2fd5b3d90c6f3813d23e0c2ed33cd7e2, 'Puffer Finance', 'Puffer Finance 57', 'Liquid Restaking') + , (0x9ae3eb1948e70c7f9804e30a34e8c25e0dd8261d, 'Puffer Finance', 'Puffer Finance 58', 'Liquid Restaking') + , (0x5905361a292c4582139a9ceaec1a71ea950d0677, 'Puffer Finance', 'Puffer Finance 59', 'Liquid Restaking') + , (0x3c12e47bd31b7c72ab05b514abae4b5abe871072, 'Puffer Finance', 'Puffer Finance 60', 'Liquid Restaking') + , (0x4cda1525b7d6577a59b6325201b3a68939da91d8, 'Puffer Finance', 'Puffer Finance 61', 'Liquid Restaking') + , (0xe097f793464e4503616e55d28294bf0fb982d14f, 'Puffer Finance', 'Puffer Finance 62', 'Liquid Restaking') + , (0xb92ac33d59ec4f93787acc773ba6e26ef536749a, 'Puffer Finance', 'Puffer Finance 63', 'Liquid Restaking') + , (0xad3f79fdf705cda1e8d9d7c398a678ee6ebb2cab, 'Puffer Finance', 'Puffer Finance 64', 'Liquid Restaking') + , (0xdbe13208672a329ac8827d5752ba3e63253617aa, 'Puffer Finance', 'Puffer Finance 65', 'Liquid Restaking') + , (0x11d28e6a3a8513432af889b25318d9b94bcb0d99, 'Puffer Finance', 'Puffer Finance 66', 'Liquid Restaking') + , (0xd695b18944902c0a2c899aaa789e06d30e6b0c6c, 'Puffer Finance', 'Puffer Finance 67', 'Liquid Restaking') + , (0xec77866c71f19b694b2d1640b0dc8585a3555596, 'Puffer Finance', 'Puffer Finance 68', 'Liquid Restaking') + , (0x5fee3852b09fd5be7043ba5eca71e674ea80c3ff, 'Puffer Finance', 'Puffer Finance 69', 'Liquid Restaking') + , (0x00c89174d831744ab9f004fc8056f85152443acc, 'Puffer Finance', 'Puffer Finance 70', 'Liquid Restaking') + , (0x4e15b6331eadaa84750870e4e24b84780c88ff91, 'Puffer Finance', 'Puffer Finance 71', 'Liquid Restaking') + , (0x444595c69006f6ac6acbf55d362d3036f5b636aa, 'Puffer Finance', 'Puffer Finance 72', 'Liquid Restaking') + , (0xd44cf40b14249811a50dcb6dbd809e94e421929e, 'Puffer Finance', 'Puffer Finance 73', 'Liquid Restaking') + , (0x572c5dfcbbec6815978adf2a835a34e8f04156fb, 'Puffer Finance', 'Puffer Finance 74', 'Liquid Restaking') + , (0xfe41129f707591fda06bfa30df467351d09f1806, 'Puffer Finance', 'Puffer Finance 75', 'Liquid Restaking') + , (0x5cc1a39d0b448ece222a3e2891315b7d3c104d62, 'Puffer Finance', 'Puffer Finance 76', 'Liquid Restaking') + , (0xc360a5080719b3819531e6a9135d7062a9aa71a4, 'Puffer Finance', 'Puffer Finance 77', 'Liquid Restaking') + , (0xd96ffffb94f1484903c4022f128830f636c696ef, 'Puffer Finance', 'Puffer Finance 78', 'Liquid Restaking') + , (0x1d5b496c6992e6ebcf7a38a4097017fad76457a8, 'Puffer Finance', 'Puffer Finance 79', 'Liquid Restaking') + , (0x364942ade69dd27ec53092aece9b0604c1ec45ae, 'Puffer Finance', 'Puffer Finance 80', 'Liquid Restaking') + , (0x31710a5588cd7fadbf5002744ee433a3ec5bf75b, 'Puffer Finance', 'Puffer Finance 81', 'Liquid Restaking') + , (0x75408e3a95a0d4db54a11b171e591f706d991e7a, 'Puffer Finance', 'Puffer Finance 82', 'Liquid Restaking') + , (0xb25cfe029b6dcd87d5d9ae333e587b7a4873ce29, 'Puffer Finance', 'Puffer Finance 83', 'Liquid Restaking') + , (0xd338e780a5b900ac66d16c106f8babb47040e47b, 'Puffer Finance', 'Puffer Finance 84', 'Liquid Restaking') + , (0xe859a34cdd097ac7e8167ad828ca9ad969925a6a, 'Puffer Finance', 'Puffer Finance 85', 'Liquid Restaking') + , (0xdd86602cda86bfa8d26cadb8fdafccf325e35433, 'Puffer Finance', 'Puffer Finance 86', 'Liquid Restaking') + , (0x97f51ba27bdee65bb87ffe38e4a88c9c938272f7, 'Puffer Finance', 'Puffer Finance 87', 'Liquid Restaking') + , (0xe1e2cac176c707d83206d27b49ade82d94807212, 'Puffer Finance', 'Puffer Finance 88', 'Liquid Restaking') + , (0x56bfcc391b0be76a0fbd3c1b3c5e934680c92b0c, 'Puffer Finance', 'Puffer Finance 89', 'Liquid Restaking') + , (0xb74f9126dd7f3817dc69ae0830e25c03bdb5475f, 'Puffer Finance', 'Puffer Finance 90', 'Liquid Restaking') + , (0xef9c44b3b1a8101eba04e75c21f6ac67a4e0e626, 'Puffer Finance', 'Puffer Finance 91', 'Liquid Restaking') + , (0x36b955ca9b2a40d47a0b0ba39c1e70331e344918, 'Puffer Finance', 'Puffer Finance 92', 'Liquid Restaking') + , (0xa709eb9a291304f99b830017523af8f1b9196fdf, 'Puffer Finance', 'Puffer Finance 93', 'Liquid Restaking') + , (0x3a4c38b8f96c55ca42d7d1185cae7443d1d15c2b, 'Puffer Finance', 'Puffer Finance 94', 'Liquid Restaking') + , (0x4b408f1ca8f09d0d9707ae5124238f451175d2ac, 'Puffer Finance', 'Puffer Finance 95', 'Liquid Restaking') + , (0x29346db21c7a5cdc9cd6fca73bbfea30054ab5dc, 'Puffer Finance', 'Puffer Finance 96', 'Liquid Restaking') + , (0x141e6f34ff332e998f431199bedd6b0d0d10f860, 'Puffer Finance', 'Puffer Finance 97', 'Liquid Restaking') + , (0xc303c9f5fa828c01a85434e53fe0c8f899585461, 'Puffer Finance', 'Puffer Finance 98', 'Liquid Restaking') + , (0xc7b096aa18541d4d9a3d617108f6935e65e5d069, 'Puffer Finance', 'Puffer Finance 99', 'Liquid Restaking') + , (0xfbd2ab8d3b73a101e004bcfbac71caccf59071a5, 'Puffer Finance', 'Puffer Finance 100', 'Liquid Restaking') + , (0x4bd8704cc263618e0620db01dbe30211de1dc72e, 'Puffer Finance', 'Puffer Finance 101', 'Liquid Restaking') + , (0x6b54b0c3df5c0b40f56ecc47761ba28d00776c16, 'Puffer Finance', 'Puffer Finance 102', 'Liquid Restaking') + , (0x09d4a923d904a86898898a79530190c40f5259e6, 'Puffer Finance', 'Puffer Finance 103', 'Liquid Restaking') + , (0xde377a6dc62a749daf6598cb0dba960c63d96ce7, 'Puffer Finance', 'Puffer Finance 104', 'Liquid Restaking') + , (0xc764054bded8ec0b71558e84615745f75cb6fd5c, 'Puffer Finance', 'Puffer Finance 105', 'Liquid Restaking') + , (0x123f83325405375fec9aa1be806668ee67d0602a, 'Puffer Finance', 'Puffer Finance 106', 'Liquid Restaking') + , (0xc63bf25a5f1f0ddaf87708087c8a1ea6de97ff23, 'Puffer Finance', 'Puffer Finance 107', 'Liquid Restaking') + , (0xdd5546d2849fbf9af452df2b1f8f00f8c32cd645, 'Puffer Finance', 'Puffer Finance 108', 'Liquid Restaking') + , (0x940c8dfad0c5e596d98e6acbf34d5edfbef11042, 'Puffer Finance', 'Puffer Finance 109', 'Liquid Restaking') + , (0x4a012f0388b469615740ebfbbd2dcd847922659b, 'Puffer Finance', 'Puffer Finance 110', 'Liquid Restaking') + , (0x311a752130c8e136dd1c6de8313d269b6105d319, 'Puffer Finance', 'Puffer Finance 111', 'Liquid Restaking') + , (0xdd6c3b2f31e0db1eaadbd55245cfcb69d9c7a67c, 'Puffer Finance', 'Puffer Finance 112', 'Liquid Restaking') + , (0x4f0f64afca99e253a89823c835ddb4d950cf6652, 'Puffer Finance', 'Puffer Finance 113', 'Liquid Restaking') + , (0x3a431a60e0281bcd600fd02e6d4ab03ca72d7210, 'Puffer Finance', 'Puffer Finance 114', 'Liquid Restaking') + , (0x0753edfd731698a1ac669c7c07602cbc3946bc5b, 'Puffer Finance', 'Puffer Finance 115', 'Liquid Restaking') + , (0x5a575603eaba67982da722f94b6ea60cf9b877b0, 'Puffer Finance', 'Puffer Finance 116', 'Liquid Restaking') + , (0xfb31d482c5736a1bde326ac4621af0a142ce4046, 'Puffer Finance', 'Puffer Finance 117', 'Liquid Restaking') + , (0x0b45151f012adcbf717f007d18a18302e020c01f, 'Puffer Finance', 'Puffer Finance 118', 'Liquid Restaking') + , (0x7b658386c82cd2752eb839f7a188cf048744686f, 'Puffer Finance', 'Puffer Finance 119', 'Liquid Restaking') + , (0x7de3ed7d22cb8d443ca2e67d9c23cc2b14a99f35, 'Puffer Finance', 'Puffer Finance 120', 'Liquid Restaking') + , (0xad9b35123d1921a36a34ec806589e5d7c0777e72, 'Puffer Finance', 'Puffer Finance 121', 'Liquid Restaking') + , (0x092af2ef103626f55507b5a0efe1ed3f69af2c70, 'Puffer Finance', 'Puffer Finance 122', 'Liquid Restaking') + , (0xb2a550fcf3cfd3b16758b6efc7394aaf2ddf0601, 'Puffer Finance', 'Puffer Finance 123', 'Liquid Restaking') + , (0x0018ad99b4c14f03f23012032fc50d1c3c011967, 'Puffer Finance', 'Puffer Finance 124', 'Liquid Restaking') + , (0x18d2df1cc6a44c32b52ffef413b15f14970f4002, 'Puffer Finance', 'Puffer Finance 125', 'Liquid Restaking') + , (0x7c1b25774b2eb89499a73c71b629aa03f0ba4c3c, 'Puffer Finance', 'Puffer Finance 126', 'Liquid Restaking') + , (0xb21f8d9fc1d40ca63e190394fa8ad65cb4048d6f, 'Puffer Finance', 'Puffer Finance 127', 'Liquid Restaking') + , (0x89c31588cc483227355ad2f315f58c4c4db5026d, 'Puffer Finance', 'Puffer Finance 128', 'Liquid Restaking') + , (0xc2159dfff1c97c79678b40ae234eef8246ff6332, 'Puffer Finance', 'Puffer Finance 129', 'Liquid Restaking') + , (0xd20ec2ccff5a0918179f351b15cd476e6ce7a5f3, 'Puffer Finance', 'Puffer Finance 130', 'Liquid Restaking') + , (0xca36526e36283a6420d740ff8d6b3b5a834c363e, 'Puffer Finance', 'Puffer Finance 131', 'Liquid Restaking') + , (0xaad53d757777594c36c6651db07f71bbd8fe1930, 'Puffer Finance', 'Puffer Finance 132', 'Liquid Restaking') + , (0x055057b3f45c308b7b45c1fdd5b68ae17d3f781f, 'Puffer Finance', 'Puffer Finance 133', 'Liquid Restaking') + , (0x3bd05798c9d0ed496a1765a132f26f210b9dadc7, 'Puffer Finance', 'Puffer Finance 134', 'Liquid Restaking') + , (0x98968937aa45a038a33c9874aac8d054a1bb8746, 'Puffer Finance', 'Puffer Finance 135', 'Liquid Restaking') + , (0x3de5c8a0e6de069a3de7f45e52b90904cf55835f, 'Puffer Finance', 'Puffer Finance 136', 'Liquid Restaking') + , (0xd9dc6ae799c8b6ab05e52f9afc11e2a9d7d51652, 'Puffer Finance', 'Puffer Finance 137', 'Liquid Restaking') + , (0xadac63898060366642ba068650054d3a8c5e73d9, 'Puffer Finance', 'Puffer Finance 138', 'Liquid Restaking') + , (0x32e0c22fce8996ccf63fad5aaa13b5556bec13ef, 'Puffer Finance', 'Puffer Finance 139', 'Liquid Restaking') + , (0x05e8728dd7e1e10f06c9db765cbeabbf194c3e3f, 'Puffer Finance', 'Puffer Finance 140', 'Liquid Restaking') + , (0xccc08fe71dbec373c58053c58a3ccbec3a820369, 'Puffer Finance', 'Puffer Finance 141', 'Liquid Restaking') + , (0x9b0255f8a853df6c32e1a355cb8b93281250f558, 'Puffer Finance', 'Puffer Finance 142', 'Liquid Restaking') + , (0x09f2180e5636a00f561853e39e0ac65dbfc79232, 'Puffer Finance', 'Puffer Finance 143', 'Liquid Restaking') + , (0x623bf63a1ff6f302a027439ba274057752172b38, 'Puffer Finance', 'Puffer Finance 144', 'Liquid Restaking') + , (0xc97474cdc5e92c6ff908cbcbacd310d57d0c73fe, 'Puffer Finance', 'Puffer Finance 145', 'Liquid Restaking') + , (0x7fae2df6c1c5baff660596d4d9c406b15d47d003, 'Puffer Finance', 'Puffer Finance 146', 'Liquid Restaking') + , (0x026503a3c936366d47527d9354d1c614365af921, 'Puffer Finance', 'Puffer Finance 147', 'Liquid Restaking') + , (0x163994918de24bfd5151846b29f441aff6d2cd7b, 'Puffer Finance', 'Puffer Finance 148', 'Liquid Restaking') + , (0xdd5a51b834bd1ee100d2d23eb99c669ad8c11362, 'Puffer Finance', 'Puffer Finance 149', 'Liquid Restaking') + , (0x48e81b5d6ac6f03f71da4ac1a40217ebfad5351e, 'Puffer Finance', 'Puffer Finance 150', 'Liquid Restaking') + , (0xe141859cf4477f04c50c9c5f8c281204671c83cf, 'Puffer Finance', 'Puffer Finance 151', 'Liquid Restaking') + , (0x865b02589436c61e7c0c4ab0e14156c698b203b2, 'Puffer Finance', 'Puffer Finance 152', 'Liquid Restaking') + , (0xdc717de5d799fca961daf88c12f61385ce898212, 'Puffer Finance', 'Puffer Finance 153', 'Liquid Restaking') + , (0xa76e9964f530a5290a3507160a7225ec52cbf159, 'Puffer Finance', 'Puffer Finance 154', 'Liquid Restaking') + , (0xc3fa8b2a4fd55b33ac09e3054b2dbc2a36ef7eac, 'Puffer Finance', 'Puffer Finance 155', 'Liquid Restaking') + , (0x7d9a197229bc1cc75567a31391f6db4d815cf218, 'Puffer Finance', 'Puffer Finance 156', 'Liquid Restaking') + , (0xca4be9d9c8f038097cf0a8265da5202556960e52, 'Puffer Finance', 'Puffer Finance 157', 'Liquid Restaking') + , (0x45d43e2f059553c003029d66c0ed0827a9652260, 'Puffer Finance', 'Puffer Finance 158', 'Liquid Restaking') + , (0x32d334624fc6c8e95a531f6304e5448830c53fde, 'Puffer Finance', 'Puffer Finance 159', 'Liquid Restaking') + , (0xff08e263ac3fe9f480db17d9d32a84a380d7da61, 'Puffer Finance', 'Puffer Finance 160', 'Liquid Restaking') + , (0x5e46cc19b371577b91336cca60d071d694a74c6d, 'Puffer Finance', 'Puffer Finance 161', 'Liquid Restaking') + , (0x5dd6862e9ae19096a6c3e41070a0edeafea87ef0, 'Puffer Finance', 'Puffer Finance 162', 'Liquid Restaking') + , (0x6537dd3904653ec917b78d58f4ceac0235504464, 'Puffer Finance', 'Puffer Finance 163', 'Liquid Restaking') + , (0x39e6481ac8ce709fb8179769c0cbc9724c4e60f2, 'Puffer Finance', 'Puffer Finance 164', 'Liquid Restaking') + , (0x044be5d76576e34b00c199833a043dd483f8485b, 'Puffer Finance', 'Puffer Finance 165', 'Liquid Restaking') + , (0x4973a0a7de9b6942d297b82a783f6d0b8ec766cf, 'Puffer Finance', 'Puffer Finance 166', 'Liquid Restaking') + , (0x3b181d9b973265f2e690082b7b7deee660257384, 'Puffer Finance', 'Puffer Finance 167', 'Liquid Restaking') + , (0x83fc4377413827eca613a285376decce83354e02, 'Puffer Finance', 'Puffer Finance 168', 'Liquid Restaking') + , (0x5a2ea2b6d4ad7dab917e32ff45f85d1d5b4839ad, 'Puffer Finance', 'Puffer Finance 169', 'Liquid Restaking') + , (0x5418384a834ed08d2b5834f0ded7dcd4d8e02854, 'Puffer Finance', 'Puffer Finance 170', 'Liquid Restaking') + , (0xa74034c7f7f4388e024f63b33626213181d6b984, 'Puffer Finance', 'Puffer Finance 171', 'Liquid Restaking') + , (0xc9ac5524af6ca89f751aa49fb0da479cf5456bb0, 'Puffer Finance', 'Puffer Finance 172', 'Liquid Restaking') + , (0xc48e944c94be1ec121d6cf68f79f2ef94ec44ca5, 'Puffer Finance', 'Puffer Finance 173', 'Liquid Restaking') + , (0x01362e34c82d4e08a2218684f100391789921168, 'Puffer Finance', 'Puffer Finance 174', 'Liquid Restaking') + , (0x45b3dca5af653c791ca49387f64b1e83cb96994c, 'Puffer Finance', 'Puffer Finance 175', 'Liquid Restaking') + , (0xf5b0876efca1d435b619a694df60f446e93b3575, 'Puffer Finance', 'Puffer Finance 176', 'Liquid Restaking') + , (0x955d790417412ea7796676a16984c3a4ea5f830e, 'Puffer Finance', 'Puffer Finance 177', 'Liquid Restaking') + , (0x79a22635558dbae83af0b43d18b11e9d14d66764, 'Puffer Finance', 'Puffer Finance 178', 'Liquid Restaking') + , (0xd753548fc97aed8e3c30181bdb5f3a26836e4f4a, 'Puffer Finance', 'Puffer Finance 179', 'Liquid Restaking') + , (0xf2fe031f1c1bbecdb21d3aba73db5146885ad56b, 'Puffer Finance', 'Puffer Finance 180', 'Liquid Restaking') + , (0x13e0d6f093f4745b7f619a5cc03c434e435fb7c2, 'Puffer Finance', 'Puffer Finance 181', 'Liquid Restaking') + , (0xad3b31617912a21f07a000022f4ce69f28175d9c, 'Puffer Finance', 'Puffer Finance 182', 'Liquid Restaking') , (0xdf8f9a7f1f8eb645dc3c95354d2c909c2fdaf0e3, 'Eigenpie', 'Eigenpie 1', 'Liquid Restaking') , (0x7ef5d450be41fcbc6191cb09789c5783da53f3fc, 'Copper.co', 'Copper.co', 'Staking Pool') , (0x44894aeee56c2dd589c1d5c8cb04b87576967f97, 'Upbit', 'Upbit 1', 'CEX') From 57936734e195d6927e1c27e8e2be2419152a5404 Mon Sep 17 00:00:00 2001 From: jeff-dude <102681548+jeff-dude@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:34:09 -0400 Subject: [PATCH 54/59] `dex.prices_beta`: filter for trusted token per swap (#6847) * filter for trusted token per swap * update spell name to remove beta * attempt new logic * fix order of operations * fix array syntax * test merge strategy --- dbt_subprojects/dex/models/prices/_schema.yml | 14 +++++++-- ...x_prices_beta.sql => dex_prices_block.sql} | 30 ++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) rename dbt_subprojects/dex/models/prices/{dex_prices_beta.sql => dex_prices_block.sql} (79%) diff --git a/dbt_subprojects/dex/models/prices/_schema.yml b/dbt_subprojects/dex/models/prices/_schema.yml index c023a6b015d..da708e7d8ef 100644 --- a/dbt_subprojects/dex/models/prices/_schema.yml +++ b/dbt_subprojects/dex/models/prices/_schema.yml @@ -1,9 +1,19 @@ version: 2 models: - - name: dex_prices_beta + - name: dex_prices_block description: > - obtain pricing info from dex.trades to feed into prices pipeline + obtain pricing info from dex.trades to feed into prices pipeline, aggregate to the block level and obtain median price + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_month + - blockchain + - contract_address + - symbol + - decimals + - block_number + - block_time - name: dex_prices meta: diff --git a/dbt_subprojects/dex/models/prices/dex_prices_beta.sql b/dbt_subprojects/dex/models/prices/dex_prices_block.sql similarity index 79% rename from dbt_subprojects/dex/models/prices/dex_prices_beta.sql rename to dbt_subprojects/dex/models/prices/dex_prices_block.sql index 2468371f394..91e5eacdd43 100644 --- a/dbt_subprojects/dex/models/prices/dex_prices_beta.sql +++ b/dbt_subprojects/dex/models/prices/dex_prices_block.sql @@ -1,14 +1,16 @@ {{ config( schema = 'dex' - , alias = 'prices_beta' + , alias = 'prices_block' , partition_by = ['block_month'] , materialized = 'incremental' , file_format = 'delta' - , incremental_strategy = 'append' + , incremental_strategy = 'merge' + , unique_key = ['block_month', 'blockchain', 'contract_address', 'symbol', 'decimals', 'block_number', 'block_time'] + , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')] ) }} -with dex_trades as ( +with dex_trades_raw as ( select blockchain , block_number @@ -20,15 +22,35 @@ with dex_trades as ( , token_sold_amount_raw , token_sold_amount , amount_usd + , array[token_bought_address, token_sold_address] as tokens_swapped from {{ ref('dex_trades') }} where 1 = 1 and amount_usd > 0 {% if is_incremental() %} - and block_time > (select max(block_time) from {{ this }}) + and {{ incremental_predicate('block_time') }} {% endif %} ), +dex_trades as ( + select distinct + t.blockchain + , t.block_number + , t.block_time + , t.token_bought_address + , t.token_bought_amount_raw + , t.token_bought_amount + , t.token_sold_address + , t.token_sold_amount_raw + , t.token_sold_amount + , t.amount_usd + from + dex_trades_raw as t + --only output swaps which contain a trusted token + inner join {{ source('prices', 'trusted_tokens') }} as tt + on t.blockchain = tt.blockchain + and contains(t.tokens_swapped, tt.contract_address) +), dex_bought as ( select d.blockchain From e1feaa85df1145f98ce59e3eefcbe4834b87a54b Mon Sep 17 00:00:00 2001 From: viniabussafi <131974393+viniabussafi@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:03:43 -0300 Subject: [PATCH 55/59] Create balancer.view_pools_latest (#6819) * 1st attempt * first attempt * fix source * again * update schemas * fix * fix schema * retry * again * again * retry --- .../_project/balancer/pools/_schema.yml | 45 ++++++++++++++++--- .../pools/balancer_view_pools_latest.sql | 37 +++++++++++++++ sources/_datasets/dune_upload_sources.yml | 6 ++- .../ethereum/community_base_sources.yml | 3 +- 4 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/balancer_view_pools_latest.sql diff --git a/dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/_schema.yml b/dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/_schema.yml index 88b3adaa386..e4ae7af282d 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/_schema.yml @@ -42,7 +42,7 @@ models: config: tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm', 'balancer', 'pool', 'stats', 'volume', 'tvl', 'fee'] description: > - This spell aggregates data from the trades, liquidity and protocol fees spells, by day and pool, while also displaying some basic information about the pool + This spell aggregates data from the trades, liquidity and protocol fees spells, by day and pool, while also displaying some basic information about the pool. tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -77,7 +77,7 @@ models: description: "Total Value Locked on a pool, in USD" - &tvl_eth name: tvl_eth - description: "Total Value Locked on a pool, in eth" + description: "Total Value Locked on a pool, in ETH" - &fee_amount_usd name: fee_amount_usd description: "Daily fees collected on a pool, in USD" @@ -90,7 +90,7 @@ models: config: tags: ['balancer', 'amm', 'trades', 'dex', 'incentives'] description: > - Gauge to Pool mappings for balancer on all chains + Gauge to Pool mappings for balancer on all chains. columns: - *blockchain - *version @@ -119,5 +119,40 @@ models: name: evt_tx_hash description: 'Transaction hash' - &evt_index - name: evT_index - description: 'Event Index' \ No newline at end of file + name: evt_index + description: 'Event Index' + + - name: balancer_view_pools_latest + meta: + blockchain: arbitrum, avalanche_c, base, ethereum, gnosis, optimism, polygon, zkevm + contributors: viniabussafi + config: + tags: ['arbitrum', 'avalanche_c', 'base', 'ethereum', 'gnosis', 'optimism', 'polygon', 'zkevm', 'balancer', 'pool', 'stats', 'volume', 'tvl', 'fee'] + description: > + This spell aggregates data from the trades, liquidity, and protocol fees spells, by pool, while also displaying information about the pool creation. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - blockchain + - pool_id + columns: + - *blockchain + - name: pool_id + - name: pool_address + - name: pool_symbol + - name: pool_type + - name: factory_version + - name: factory_address + - name: creation_date + - name: tvl_usd + - name: tvl_eth + - name: swap_volume + - name: swap_volume_1y + - name: swap_volume_30d + - name: swap_volume_7d + - name: swap_volume_1d + - name: fees_collected + - name: fees_collected_1y + - name: fees_collected_30d + - name: fees_collected_7d + - name: fees_collected_1d diff --git a/dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/balancer_view_pools_latest.sql b/dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/balancer_view_pools_latest.sql new file mode 100644 index 00000000000..2386f636a48 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/balancer/pools/balancer_view_pools_latest.sql @@ -0,0 +1,37 @@ +{{ config( + schema = 'balancer', + alias = 'view_pools_latest', + post_hook='{{ expose_spells(blockchains = \'["arbitrum", "avalanche_c", "base", "ethereum", "gnosis", "optimism", "polygon", "zkevm"]\', + spell_type = "project", + spell_name = "balancer", + contributors = \'["viniabussafi"]\') }}' + ) +}} + +SELECT + m.blockchain, + m.pool_id, + m.pool_address, + m.pool_symbol, + m.pool_type, + m.factory_version, + m.factory_address, + m.creation_date, + SUM(CASE WHEN block_date = (SELECT MAX(block_date) FROM {{ref('balancer_pools_metrics_daily')}}) + THEN tvl_usd END) AS tvl_usd, + SUM(CASE WHEN block_date = (SELECT MAX(block_date) FROM {{ref('balancer_pools_metrics_daily')}}) + THEN tvl_eth END) AS tvl_eth, + SUM(swap_amount_usd) AS swap_volume, + SUM(CASE WHEN block_date > CURRENT_DATE - INTERVAL '365' day THEN swap_amount_usd END) AS swap_volume_1y, + SUM(CASE WHEN block_date > CURRENT_DATE - INTERVAL '30' day THEN swap_amount_usd END) AS swap_volume_30d, + SUM(CASE WHEN block_date > CURRENT_DATE - INTERVAL '7' day THEN swap_amount_usd END) AS swap_volume_7d, + SUM(CASE WHEN block_date > CURRENT_DATE - INTERVAL '1' day THEN swap_amount_usd END) AS swap_volume_1d, + SUM(fee_amount_usd) AS fees_collected, + SUM(CASE WHEN block_date > CURRENT_DATE - INTERVAL '365' day THEN fee_amount_usd END) AS fees_collected_1y, + SUM(CASE WHEN block_date > CURRENT_DATE - INTERVAL '30' day THEN fee_amount_usd END) AS fees_collected_30d, + SUM(CASE WHEN block_date > CURRENT_DATE - INTERVAL '7' day THEN fee_amount_usd END) AS fees_collected_7d, + SUM(CASE WHEN block_date > CURRENT_DATE - INTERVAL '1' day THEN fee_amount_usd END) AS fees_collected_1d +FROM {{ source("balancer", "dataset_factory_pool_mapping", database = "dune") }} m +LEFT JOIN {{ref('balancer_pools_metrics_daily')}} p ON m.blockchain = p.blockchain +AND m.pool_address = p.project_contract_address +GROUP BY 1, 2, 3, 4, 5, 6, 7, 8 \ No newline at end of file diff --git a/sources/_datasets/dune_upload_sources.yml b/sources/_datasets/dune_upload_sources.yml index fc30a52aa94..5fb8590b981 100644 --- a/sources/_datasets/dune_upload_sources.yml +++ b/sources/_datasets/dune_upload_sources.yml @@ -8,4 +8,8 @@ sources: - name: op_stack_chain_metadata - name: op_airdrop1_addresses_detailed_list - name: op_airdrop2_addresses_detailed_list - - name: op_airdrop_3_addresses_detailed_list \ No newline at end of file + - name: op_airdrop_3_addresses_detailed_list + + - name: balancer + tables: + - name: dataset_factory_pool_mapping \ No newline at end of file diff --git a/sources/_datasets/reservoir/ethereum/community_base_sources.yml b/sources/_datasets/reservoir/ethereum/community_base_sources.yml index 983e89be1b3..4ee4d1d7a8d 100644 --- a/sources/_datasets/reservoir/ethereum/community_base_sources.yml +++ b/sources/_datasets/reservoir/ethereum/community_base_sources.yml @@ -7,7 +7,6 @@ sources: tables: - name: collections - name: collection_floor_ask_events - description: "todo: add reservoir table description!" columns: - name: created_at @@ -27,4 +26,4 @@ sources: - name: tx_timestamp - name: valid_until - name: tx_timestamp_dt - - name: valid_until_dt \ No newline at end of file + - name: valid_until_dt From eead2f232efb9d49789fa0129cf9505785c123b0 Mon Sep 17 00:00:00 2001 From: ppclunghe <90045511+ppclunghe@users.noreply.github.com> Date: Wed, 2 Oct 2024 18:04:04 +0200 Subject: [PATCH 56/59] Lido liquidity updates (#6815) * lido liquidity updates * fix pancake bnb * pancake pools * thena pools * maverick pools * nuri pools * lynex pools * lynex fix * balancer pools --- ...lido_liquidity_arbitrum_balancer_pools.sql | 7 +- ...iquidity_arbitrum_pancakeswap_v3_pools.sql | 263 +++++++++++++++++ .../lido_liquidity_base_maverick_pools.sql | 254 ++++++++++++++++ ...do_liquidity_base_pancakeswap_v3_pools.sql | 263 +++++++++++++++++ ...ido_liquidity_bnb_pancakeswap_v3_pools.sql | 263 +++++++++++++++++ .../bnb/lido_liquidity_bnb_schema.yml | 64 ++++ .../bnb/lido_liquidity_bnb_thena_pools.sql | 242 +++++++++++++++ ...lido_liquidity_ethereum_balancer_pools.sql | 6 +- ...dity_ethereum_curve_wsteth_pufeth_pool.sql | 236 +++++++++++++++ .../lido_liquidity_linea_lynex_pools.sql | 275 +++++++++++++++++ .../lido_liquidity_scroll_maverick_pools.sql | 254 ++++++++++++++++ .../lido_liquidity_scroll_nuri_pools.sql | 276 ++++++++++++++++++ ..._liquidity_zksync_pancakeswap_v3_pools.sql | 263 +++++++++++++++++ .../lido_liquidity_arbitrum_sources.yml | 8 +- .../base/lido_liquidity_base_sources.yml | 13 + .../bnb/lido_liquidity_bnb_sources.yml | 22 ++ .../lido_liquidity_ethereum_sources.yml | 8 +- .../linea/lido_liquidity_linea_sources.yml | 5 + .../scroll/lido_liquidity_scroll_sources.yml | 12 + .../zksync/lido_liquidity_zksync_sources.yml | 7 +- 20 files changed, 2736 insertions(+), 5 deletions(-) create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/arbitrum/lido_liquidity_arbitrum_pancakeswap_v3_pools.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/base/lido_liquidity_base_maverick_pools.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/base/lido_liquidity_base_pancakeswap_v3_pools.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_pancakeswap_v3_pools.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_schema.yml create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_thena_pools.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/ethereum/lido_liquidity_ethereum_curve_wsteth_pufeth_pool.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/linea/lido_liquidity_linea_lynex_pools.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/scroll/lido_liquidity_scroll_maverick_pools.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/scroll/lido_liquidity_scroll_nuri_pools.sql create mode 100644 dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/zksync/lido_liquidity_zksync_pancakeswap_v3_pools.sql create mode 100644 sources/lido/liquidity/bnb/lido_liquidity_bnb_sources.yml diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/arbitrum/lido_liquidity_arbitrum_balancer_pools.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/arbitrum/lido_liquidity_arbitrum_balancer_pools.sql index e1bb4e49682..a867ab6a63e 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/arbitrum/lido_liquidity_arbitrum_balancer_pools.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/arbitrum/lido_liquidity_arbitrum_balancer_pools.sql @@ -25,7 +25,12 @@ values (0xfb5e6d0c1dfed2ba000fbc040ab8df3615ac329c000000000000000000000159, 0xfb5e6d0c1dfed2ba000fbc040ab8df3615ac329c), (0xb5bd58c733948e3d65d86ba9604e06e5da276fd10002000000000000000003e6, 0xb5bd58c733948e3d65d86ba9604e06e5da276fd1), (0x178e029173417b1f9c8bc16dcec6f697bc323746000200000000000000000158, 0x178e029173417b1f9c8bc16dcec6f697bc323746), -(0x45c4d1376943ab28802b995acffc04903eb5223f000000000000000000000470, 0x45c4d1376943ab28802b995acffc04903eb5223f) +(0x45c4d1376943ab28802b995acffc04903eb5223f000000000000000000000470, 0x45c4d1376943ab28802b995acffc04903eb5223f), +(0x9791d590788598535278552eecd4b211bfc790cb000000000000000000000498, 0x9791d590788598535278552eecd4b211bfc790cb), +(0x7967fa58b9501600d96bd843173b9334983ee6e600020000000000000000056e, 0x7967fa58b9501600d96bd843173b9334983ee6e6), +(0xb61371ab661b1acec81c699854d2f911070c059e000000000000000000000516, 0xb61371ab661b1acec81c699854d2f911070c059e), +(0xcdcef9765d369954a4a936064535710f7235110a000200000000000000000558, 0xcdcef9765d369954a4a936064535710f7235110a) + ) , tokens as ( diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/arbitrum/lido_liquidity_arbitrum_pancakeswap_v3_pools.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/arbitrum/lido_liquidity_arbitrum_pancakeswap_v3_pools.sql new file mode 100644 index 00000000000..abc8c3bc136 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/arbitrum/lido_liquidity_arbitrum_pancakeswap_v3_pools.sql @@ -0,0 +1,263 @@ +{{ config( + schema='lido_liquidity_arbitrum', + alias = 'pancakeswap_v3_pools', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool', 'time'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.time')], + post_hook='{{ expose_spells(blockchains = \'["arbitrum"]\', + spell_type = "project", + spell_name = "lido_liquidity", + contributors = \'["pipistrella"]\') }}' + ) +}} + +{% set project_start_date = '2023-11-22' %} + +with + +pools as ( +select pool as address, 'arbitrum' as blockchain, 'pancakeswap' as project, max(cast(fee as double))/10000 as fee +from {{ source('pancakeswap_v3_arbitrum','PancakeV3Factory_evt_PoolCreated')}} +where token0 = 0x5979D7b546E38E414F7E9822514be443A4800529 or token1 = 0x5979D7b546E38E414F7E9822514be443A4800529 +group by 1,2,3 +) + +, tokens as ( +select distinct token as address +from ( +select token1 as token +from {{ source('pancakeswap_v3_arbitrum','PancakeV3Factory_evt_PoolCreated')}} +where token0 = 0x5979D7b546E38E414F7E9822514be443A4800529 +union +select token0 +from {{ source('pancakeswap_v3_arbitrum','PancakeV3Factory_evt_PoolCreated')}} +where token1 = 0x5979D7b546E38E414F7E9822514be443A4800529 +union +select 0x5979D7b546E38E414F7E9822514be443A4800529 +) t +) + +, tokens_prices_daily AS ( + SELECT distinct + DATE_TRUNC('day', minute) AS time, + contract_address as token, + decimals, + symbol, + avg(price) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and date_trunc('day', minute) < current_date + and blockchain = 'arbitrum' + and contract_address in (select address from tokens) + group by 1,2,3,4 + union all + SELECT distinct + DATE_TRUNC('day', minute), + contract_address as token, + decimals, + symbol, + last_value(price) over (partition by DATE_TRUNC('day', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} + WHERE date_trunc('day', minute) = current_date + and blockchain = 'arbitrum' + and contract_address in (select address from tokens) +) + +, tokens_prices_hourly AS ( + select time, + lead(time,1, DATE_TRUNC('hour', now() + interval '1' hour)) over (partition by token order by time) as next_time, + token, price, decimals, symbol + from ( + SELECT distinct + DATE_TRUNC('hour', minute) time, + contract_address as token, + decimals, + symbol, + last_value(price) over (partition by DATE_TRUNC('hour', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and blockchain = 'arbitrum' + and contract_address in (select address from tokens) +) p +) + + +, swap_events as ( + select + date_trunc('day', sw.evt_block_time) as time, + sw.contract_address as pool, + cr.token0, cr.token1, + sum(cast(amount0 as DOUBLE)) as amount0, + sum(cast(amount1 as DOUBLE)) as amount1 + + from {{ source('pancakeswap_v3_arbitrum', 'PancakeV3Pool_evt_Swap') }} sw + left join {{ source('pancakeswap_v3_arbitrum', 'PancakeV3Factory_evt_PoolCreated') }} cr on sw.contract_address = cr.pool + join pools on sw.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + group by 1,2,3,4 +) + +, mint_events as ( + select + date_trunc('day', mt.evt_block_time) as time, + mt.contract_address as pool, + cr.token0, cr.token1, + sum(cast(amount0 as DOUBLE)) as amount0, + sum(cast(amount1 as DOUBLE)) as amount1 + from {{ source('pancakeswap_v3_arbitrum', 'PancakeV3Pool_evt_Mint') }} mt + left join {{ source('pancakeswap_v3_arbitrum', 'PancakeV3Factory_evt_PoolCreated') }} cr on mt.contract_address = cr.pool + join pools on mt.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', mt.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('mt.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + +, burn_events as ( + select + date_trunc('day', bn.evt_block_time) as time, + bn.contract_address as pool, + cr.token0, cr.token1, + (-1)*sum(cast(amount0 as DOUBLE)) as amount0, + (-1)*sum(cast(amount1 as DOUBLE)) as amount1 + from {{ source('pancakeswap_v3_arbitrum', 'PancakeV3Pool_evt_Burn') }} bn + left join {{ source('pancakeswap_v3_arbitrum', 'PancakeV3Factory_evt_PoolCreated') }} cr on bn.contract_address = cr.pool + join pools on bn.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', bn.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('bn.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + + , collect_events AS ( + SELECT + date_trunc('day', c.evt_block_time) as time, + c.contract_address AS pool, + cr.token0, + cr.token1, + (-1) * CAST(amount0 AS DOUBLE) AS amount0, + (-1) * CAST(amount1 AS DOUBLE) AS amount1, + c.evt_tx_hash + FROM + {{source('pancakeswap_v3_arbitrum','PancakeV3Pool_evt_Collect')}} AS c + LEFT JOIN {{source('pancakeswap_v3_arbitrum','PancakeV3Factory_evt_PoolCreated')}} AS cr ON c.contract_address = cr.pool + join pools on c.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', c.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('c.evt_block_time') }} + {% endif %} + + ) + + +, daily_delta_balance as ( + select time, pool, token0, token1, sum(coalesce(amount0, 0)) as amount0, sum(coalesce(amount1, 0)) as amount1 + from ( + select time, pool, token0, token1, amount0, amount1 + from swap_events + union all + select time, pool, token0, token1, amount0, amount1 + from mint_events + union all + select time, pool, token0, token1, amount0, amount1 + from collect_events + ) balance + group by 1,2,3,4 +) + +, pool_liquidity as ( + select time, + pool, + token0, + token1, + sum(amount0) as amount0, + sum(amount1) as amount1 + from daily_delta_balance + group by 1,2,3,4 +) + + +, swap_events_hourly as ( + select hour, pool, token0, token1, sum(amount0) as amount0, sum(amount1) as amount1 from ( + select + date_trunc('hour', sw.evt_block_time) as hour, + sw.contract_address as pool, + cr.token0, cr.token1, + coalesce(sum(cast(abs(amount0) as DOUBLE)),0) as amount0, + coalesce(sum(cast(abs(amount1) as DOUBLE)),0) as amount1 + + from {{source('pancakeswap_v3_arbitrum','PancakeV3Pool_evt_Swap')}} sw + left join {{source('pancakeswap_v3_arbitrum','PancakeV3Factory_evt_PoolCreated')}} cr on sw.contract_address = cr.pool + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + and sw.contract_address in (select address from pools) + group by 1,2,3,4 + + ) a group by 1,2,3,4 +) + +, trading_volume_hourly as ( + select hour as time, pool, token0, amount0, p.price, coalesce(p.price*amount0/power(10, p.decimals),0) as volume + from swap_events_hourly s + left join tokens t on s.token0 = t.address + left join tokens_prices_hourly p on s.hour >= p.time and s.hour < p.next_time and s.token0 = p.token + +) + +, trading_volume as ( +select distinct date_trunc('day', time) as time, pool, sum(volume) as volume +from trading_volume_hourly +group by 1,2 +) + +, all_metrics as ( +select l.pool, pools.blockchain, pools.project, pools.fee, cast(l.time as date) as time, + case when token0 = 0x5979D7b546E38E414F7E9822514be443A4800529 then token0 else token1 end main_token, + case when token0 = 0x5979D7b546E38E414F7E9822514be443A4800529 then p0.symbol else p1.symbol end main_token_symbol, + case when token0 = 0x5979D7b546E38E414F7E9822514be443A4800529 then token1 else token0 end paired_token, + case when token0 = 0x5979D7b546E38E414F7E9822514be443A4800529 then p1.symbol else p0.symbol end paired_token_symbol, + case when token0 = 0x5979D7b546E38E414F7E9822514be443A4800529 then amount0/power(10, p0.decimals) else amount1/power(10, p1.decimals) end main_token_reserve, + case when token0 = 0x5979D7b546E38E414F7E9822514be443A4800529 then amount1/power(10, p1.decimals) else amount0/power(10, p0.decimals) end paired_token_reserve, + case when token0 = 0x5979D7b546E38E414F7E9822514be443A4800529 then p0.price else p1.price end as main_token_usd_price, + case when token0 = 0x5979D7b546E38E414F7E9822514be443A4800529 then p1.price else p0.price end as paired_token_usd_price, + volume as trading_volume +from pool_liquidity l +left join pools on l.pool = pools.address +left join tokens t0 on l.token0 = t0.address +left join tokens t1 on l.token1 = t1.address +left join tokens_prices_daily p0 on l.time = p0.time and l.token0 = p0.token +left join tokens_prices_daily p1 on l.time = p1.time and l.token1 = p1.token +left join trading_volume tv on l.time = tv.time and l.pool = tv.pool +) + + + +select blockchain||' '||project||' '||COALESCE(paired_token_symbol, 'unknown')||':'||main_token_symbol||' '||format('%,.3f',round(coalesce(fee,0),4)) as pool_name,* +from all_metrics + diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/base/lido_liquidity_base_maverick_pools.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/base/lido_liquidity_base_maverick_pools.sql new file mode 100644 index 00000000000..2a578e58007 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/base/lido_liquidity_base_maverick_pools.sql @@ -0,0 +1,254 @@ +{{ config( + schema='lido_liquidity_base', + alias = 'maverick_pools', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool', 'time'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.time')], + post_hook='{{ expose_spells(blockchains = \'["base"]\', + spell_type = "project", + spell_name = "lido_liquidity", + contributors = \'["pipistrella"]\') }}' + ) +}} + +{% set project_start_date = '2024-06-23' %} + +with + +pools as ( +select poolAddress, tokenA, tokenB, cast(feeAIn as double)/1e16 as fee +from {{source('maverick_v2_base','V2Factory_evt_PoolCreated')}} +where tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 + or tokenB = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 +) + + +, tokens as ( +select distinct token as address +from ( +select tokenA as token +from {{source('maverick_v2_base','V2Factory_evt_PoolCreated')}} +where tokenB = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 +union +select tokenB +from {{source('maverick_v2_base','V2Factory_evt_PoolCreated')}} +where tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 +union +select 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 +) t +) + +, tokens_prices_daily AS ( + SELECT distinct + DATE_TRUNC('day', minute) AS time, + contract_address as token, + symbol, + decimals, + avg(price) AS price + FROM {{source('prices','usd')}} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and date_trunc('day', minute) < current_date + and blockchain = 'base' + and contract_address in (select address from tokens) + group by 1,2,3,4 + union all + SELECT distinct + DATE_TRUNC('day', minute), + contract_address as token, + symbol, + decimals, + last_value(price) over (partition by DATE_TRUNC('day', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{source('prices','usd')}} + WHERE date_trunc('day', minute) = current_date + and blockchain = 'base' + and contract_address in (select address from tokens) +) + +, wsteth_prices_hourly as ( + select time, lead(time,1, DATE_TRUNC('hour', now() + interval '1' hour)) over (order by time) as next_time, price + from ( + SELECT distinct + DATE_TRUNC('hour', minute) time, + last_value(price) over (partition by DATE_TRUNC('hour', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{source('prices','usd')}} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and blockchain = 'base' + and contract_address = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 + ) p +) + +, swap_events as ( + select + date_trunc('day', sw.evt_block_time) as time, + sw.contract_address as pool, + cr.tokenA, cr.tokenB, + sum(case when json_extract_scalar(params, '$.tokenAIn') = 'true' then cast(amountIn as double) else (-1)*cast(amountOut as double) end) as amountA, + sum(case when json_extract_scalar(params, '$.tokenAIn') = 'true' then (-1)*cast(amountOut as double) else cast(amountIn as double) end) as amountB + from {{source('maverick_v2_base','V2Pool_evt_PoolSwap')}} sw + left join {{source('maverick_v2_base','V2Factory_evt_PoolCreated')}} cr on sw.contract_address = cr.poolAddress + join pools on sw.contract_address = pools.poolAddress + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + group by 1,2,3,4 +) + +, addliquidity_events as ( + select date_trunc('day', a.evt_block_time) as time, + a.contract_address as pool, + cr.tokenA, cr.tokenB, + sum(cast(tokenAAmount as double)) as amountA, + sum(cast(tokenBAmount as double)) as amountB +from {{source('maverick_v2_base','V2Pool_evt_PoolAddLiquidity')}} a +left join {{source('maverick_v2_base','V2Factory_evt_PoolCreated')}} cr on a.contract_address = cr.poolAddress +join pools on a.contract_address = pools.poolAddress + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', a.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('a.evt_block_time') }} + {% endif %} +group by 1,2,3,4 +) + +, removeliquidity_events as ( +select date_trunc('day', a.evt_block_time) as time, + a.contract_address as pool, + cr.tokenA, cr.tokenB, + (-1)*sum(cast(tokenAOut as double)) as amountA, + (-1)*sum(cast(tokenBOut as double)) as amountB +from {{source('maverick_v2_base','V2Pool_evt_PoolRemoveLiquidity')}} a +left join {{source('maverick_v2_base','V2Factory_evt_PoolCreated')}} cr on a.contract_address = cr.poolAddress +join pools on a.contract_address = pools.poolAddress + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', a.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('a.evt_block_time') }} + {% endif %} +group by 1,2,3,4 +) + +, daily_delta_balance AS ( + +select time, pool, tokenA, tokenB, sum(amountA) as amountA, sum(amountB) as amountB +from ( +select time, pool,tokenA, tokenB, amountA, amountB +from swap_events + +union all + +select time, pool,tokenA, tokenB, amountA, amountB +from addliquidity_events + +union all + +select time, pool,tokenA, tokenB, amountA, amountB +from removeliquidity_events + +) group by 1,2,3,4 +) + + +, pool_liquidity as ( +SELECT time, pools.fee, + pool, + b.tokenA, + b.tokenB, + coalesce((SUM(amountA)),0) AS amountA, + coalesce((SUM(amountB)),0) AS amountB +FROM daily_delta_balance b +left join pools on b.pool = pools.poolAddress +GROUP BY 1,2,3,4,5 +) + + + +, wsteth_traded_hourly as ( + select + date_trunc('hour', sw.evt_block_time) as time, + sw.contract_address as pool, + cr.tokenA, cr.tokenB, + sum(case when (cr.tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 and json_extract_scalar(params, '$.tokenAIn') = 'true') then amountIn + when (cr.tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 and json_extract_scalar(params, '$.tokenAIn') = 'false') then amountOut + when (cr.tokenA != 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 and json_extract_scalar(params, '$.tokenAIn') = 'true') then amountOut + when (cr.tokenA != 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 and json_extract_scalar(params, '$.tokenAIn') = 'false') then amountIn + end) as amount + from {{source('maverick_v2_base','V2Pool_evt_PoolSwap')}} sw + left join {{source('maverick_v2_base','V2Factory_evt_PoolCreated')}} cr on sw.contract_address = cr.poolAddress + join pools on sw.contract_address = pools.poolAddress + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + +, trading_volume_hourly as ( +select t.time, pool, t.amount*wp.price as volume_raw +from wsteth_traded_hourly t +left join wsteth_prices_hourly wp on date_trunc('hour',t.time) >= wp.time and date_trunc('hour',t.time) < wp.next_time +order by 1,2 +) + +, trading_volume as ( + select distinct date_trunc('day', time) as time + , pool + , sum(volume_raw)/1e18 as volume + from trading_volume_hourly + GROUP by 1,2 +) + +, all_metrics as ( +select + o.pool, + 'base' as blockchain, + 'maverick' as project, + format('%,.3f',round(coalesce(fee,0),4)) as fee, + cast(o.time as date) time, + case when o.tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then o.tokenA else o.tokenB end as main_token, + case when o.tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then pA.symbol else pB.symbol end as main_token_symbol, + case when o.tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then o.tokenB else o.tokenA end as paired_token, + case when o.tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then pB.symbol else pA.symbol end as paired_token_symbol, + case when o.tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then amountA/power(10,pA.decimals) else amountB/power(10,pB.decimals) end as main_token_reserve, + case when o.tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then amountB/power(10,pB.decimals) else amountA/power(10,pA.decimals) end as paired_token_reserve, + case when o.tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then pA.price else pB.price end as main_token_usd_price, + case when o.tokenA = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then pB.price else pA.price end as paired_token_usd_price, + coalesce(t.volume,0) as trading_volume +from pool_liquidity o +left join tokens_prices_daily pA on o.time = pA.time and o.tokenA = pA.token +left join tokens_prices_daily pB on o.time = pB.time and o.tokenB = pB.token +left join trading_volume t on o.time = t.time and o.pool = t.pool +) + + +select blockchain||' '||project||' '||coalesce(paired_token_symbol,'unknown')||':'||main_token_symbol||' '||fee|| '('||cast(pool as varchar)||')' as pool_name, + pool, + blockchain, + project, + fee, + time, + main_token, + main_token_symbol, + paired_token, + paired_token_symbol, + main_token_reserve, + paired_token_reserve, + main_token_usd_price, + paired_token_usd_price, + trading_volume +from all_metrics + diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/base/lido_liquidity_base_pancakeswap_v3_pools.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/base/lido_liquidity_base_pancakeswap_v3_pools.sql new file mode 100644 index 00000000000..729355b2bbd --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/base/lido_liquidity_base_pancakeswap_v3_pools.sql @@ -0,0 +1,263 @@ +{{ config( + schema='lido_liquidity_base', + alias = 'pancakeswap_v3_pools', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool', 'time'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.time')], + post_hook='{{ expose_spells(blockchains = \'["base"]\', + spell_type = "project", + spell_name = "lido_liquidity", + contributors = \'["pipistrella"]\') }}' + ) +}} + +{% set project_start_date = '2024-03-13' %} + +with + +pools as ( +select pool as address, 'base' as blockchain, 'pancakeswap' as project, max(cast(fee as double))/10000 as fee +from {{ source('pancakeswap_v3_base','PancakeV3Factory_evt_PoolCreated')}} +where token0 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 or token1 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 +group by 1,2,3 +) + +, tokens as ( +select distinct token as address +from ( +select token1 as token +from {{ source('pancakeswap_v3_base','PancakeV3Factory_evt_PoolCreated')}} +where token0 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 +union +select token0 +from {{ source('pancakeswap_v3_base','PancakeV3Factory_evt_PoolCreated')}} +where token1 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 +union +select 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 +) t +) + +, tokens_prices_daily AS ( + SELECT distinct + DATE_TRUNC('day', minute) AS time, + contract_address as token, + decimals, + symbol, + avg(price) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and date_trunc('day', minute) < current_date + and blockchain = 'base' + and contract_address in (select address from tokens) + group by 1,2,3,4 + union all + SELECT distinct + DATE_TRUNC('day', minute), + contract_address as token, + decimals, + symbol, + last_value(price) over (partition by DATE_TRUNC('day', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} + WHERE date_trunc('day', minute) = current_date + and blockchain = 'base' + and contract_address in (select address from tokens) +) + +, tokens_prices_hourly AS ( + select time, + lead(time,1, DATE_TRUNC('hour', now() + interval '1' hour)) over (partition by token order by time) as next_time, + token, price, decimals, symbol + from ( + SELECT distinct + DATE_TRUNC('hour', minute) time, + contract_address as token, + decimals, + symbol, + last_value(price) over (partition by DATE_TRUNC('hour', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and blockchain = 'base' + and contract_address in (select address from tokens) +) p +) + + +, swap_events as ( + select + date_trunc('day', sw.evt_block_time) as time, + sw.contract_address as pool, + cr.token0, cr.token1, + sum(cast(amount0 as DOUBLE)) as amount0, + sum(cast(amount1 as DOUBLE)) as amount1 + + from {{ source('pancakeswap_v3_base', 'PancakeV3Pool_evt_Swap') }} sw + left join {{ source('pancakeswap_v3_base', 'PancakeV3Factory_evt_PoolCreated') }} cr on sw.contract_address = cr.pool + join pools on sw.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + group by 1,2,3,4 +) + +, mint_events as ( + select + date_trunc('day', mt.evt_block_time) as time, + mt.contract_address as pool, + cr.token0, cr.token1, + sum(cast(amount0 as DOUBLE)) as amount0, + sum(cast(amount1 as DOUBLE)) as amount1 + from {{ source('pancakeswap_v3_base', 'PancakeV3Pool_evt_Mint') }} mt + left join {{ source('pancakeswap_v3_base', 'PancakeV3Factory_evt_PoolCreated') }} cr on mt.contract_address = cr.pool + join pools on mt.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', mt.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('mt.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + +, burn_events as ( + select + date_trunc('day', bn.evt_block_time) as time, + bn.contract_address as pool, + cr.token0, cr.token1, + (-1)*sum(cast(amount0 as DOUBLE)) as amount0, + (-1)*sum(cast(amount1 as DOUBLE)) as amount1 + from {{ source('pancakeswap_v3_base', 'PancakeV3Pool_evt_Burn') }} bn + left join {{ source('pancakeswap_v3_base', 'PancakeV3Factory_evt_PoolCreated') }} cr on bn.contract_address = cr.pool + join pools on bn.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', bn.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('bn.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + + , collect_events AS ( + SELECT + date_trunc('day', c.evt_block_time) as time, + c.contract_address AS pool, + cr.token0, + cr.token1, + (-1) * CAST(amount0 AS DOUBLE) AS amount0, + (-1) * CAST(amount1 AS DOUBLE) AS amount1, + c.evt_tx_hash + FROM + {{source('pancakeswap_v3_base','PancakeV3Pool_evt_Collect')}} AS c + LEFT JOIN {{source('pancakeswap_v3_base','PancakeV3Factory_evt_PoolCreated')}} AS cr ON c.contract_address = cr.pool + join pools on c.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', c.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('c.evt_block_time') }} + {% endif %} + + ) + + +, daily_delta_balance as ( + select time, pool, token0, token1, sum(coalesce(amount0, 0)) as amount0, sum(coalesce(amount1, 0)) as amount1 + from ( + select time, pool, token0, token1, amount0, amount1 + from swap_events + union all + select time, pool, token0, token1, amount0, amount1 + from mint_events + union all + select time, pool, token0, token1, amount0, amount1 + from collect_events + ) balance + group by 1,2,3,4 +) + +, pool_liquidity as ( + select time, + pool, + token0, + token1, + sum(amount0) as amount0, + sum(amount1) as amount1 + from daily_delta_balance + group by 1,2,3,4 +) + + +, swap_events_hourly as ( + select hour, pool, token0, token1, sum(amount0) as amount0, sum(amount1) as amount1 from ( + select + date_trunc('hour', sw.evt_block_time) as hour, + sw.contract_address as pool, + cr.token0, cr.token1, + coalesce(sum(cast(abs(amount0) as DOUBLE)),0) as amount0, + coalesce(sum(cast(abs(amount1) as DOUBLE)),0) as amount1 + + from {{source('pancakeswap_v3_base','PancakeV3Pool_evt_Swap')}} sw + left join {{source('pancakeswap_v3_base','PancakeV3Factory_evt_PoolCreated')}} cr on sw.contract_address = cr.pool + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + and sw.contract_address in (select address from pools) + group by 1,2,3,4 + + ) a group by 1,2,3,4 +) + +, trading_volume_hourly as ( + select hour as time, pool, token0, amount0, p.price, coalesce(p.price*amount0/power(10, p.decimals),0) as volume + from swap_events_hourly s + left join tokens t on s.token0 = t.address + left join tokens_prices_hourly p on s.hour >= p.time and s.hour < p.next_time and s.token0 = p.token + +) + +, trading_volume as ( +select distinct date_trunc('day', time) as time, pool, sum(volume) as volume +from trading_volume_hourly +group by 1,2 +) + +, all_metrics as ( +select l.pool, pools.blockchain, pools.project, pools.fee, cast(l.time as date) as time, + case when token0 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then token0 else token1 end main_token, + case when token0 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then p0.symbol else p1.symbol end main_token_symbol, + case when token0 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then token1 else token0 end paired_token, + case when token0 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then p1.symbol else p0.symbol end paired_token_symbol, + case when token0 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then amount0/power(10, p0.decimals) else amount1/power(10, p1.decimals) end main_token_reserve, + case when token0 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then amount1/power(10, p1.decimals) else amount0/power(10, p0.decimals) end paired_token_reserve, + case when token0 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then p0.price else p1.price end as main_token_usd_price, + case when token0 = 0xc1CBa3fCea344f92D9239c08C0568f6F2F0ee452 then p1.price else p0.price end as paired_token_usd_price, + volume as trading_volume +from pool_liquidity l +left join pools on l.pool = pools.address +left join tokens t0 on l.token0 = t0.address +left join tokens t1 on l.token1 = t1.address +left join tokens_prices_daily p0 on l.time = p0.time and l.token0 = p0.token +left join tokens_prices_daily p1 on l.time = p1.time and l.token1 = p1.token +left join trading_volume tv on l.time = tv.time and l.pool = tv.pool +) + + + +select blockchain||' '||project||' '||COALESCE(paired_token_symbol, 'unknown')||':'||main_token_symbol||' '||format('%,.3f',round(coalesce(fee,0),4)) as pool_name,* +from all_metrics + diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_pancakeswap_v3_pools.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_pancakeswap_v3_pools.sql new file mode 100644 index 00000000000..e4be4ac2fc0 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_pancakeswap_v3_pools.sql @@ -0,0 +1,263 @@ +{{ config( + schema='lido_liquidity_bnb', + alias = 'pancakeswap_v3_pools', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool', 'time'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.time')], + post_hook='{{ expose_spells(blockchains = \'["bnb"]\', + spell_type = "project", + spell_name = "lido_liquidity", + contributors = \'["pipistrella"]\') }}' + ) +}} + +{% set project_start_date = '2024-08-14' %} + +with + +pools as ( +select pool as address, 'bnb' as blockchain, 'pancakeswap' as project, max(cast(fee as double))/10000 as fee +from {{ source('pancakeswap_v3_bnb','PancakeV3Factory_evt_PoolCreated')}} +where token0 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C or token1 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C +group by 1,2,3 +) + +, tokens as ( +select distinct token as address +from ( +select token1 as token +from {{ source('pancakeswap_v3_bnb','PancakeV3Factory_evt_PoolCreated')}} +where token0 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C +union +select token0 +from {{ source('pancakeswap_v3_bnb','PancakeV3Factory_evt_PoolCreated')}} +where token1 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C +union +select 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C +) t +) + +, tokens_prices_daily AS ( + SELECT distinct + DATE_TRUNC('day', minute) AS time, + contract_address as token, + decimals, + symbol, + avg(price) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and date_trunc('day', minute) < current_date + and blockchain = 'bnb' + and contract_address in (select address from tokens) + group by 1,2,3,4 + union all + SELECT distinct + DATE_TRUNC('day', minute), + contract_address as token, + decimals, + symbol, + last_value(price) over (partition by DATE_TRUNC('day', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} + WHERE date_trunc('day', minute) = current_date + and blockchain = 'bnb' + and contract_address in (select address from tokens) +) + +, tokens_prices_hourly AS ( + select time, + lead(time,1, DATE_TRUNC('hour', now() + interval '1' hour)) over (partition by token order by time) as next_time, + token, price, decimals, symbol + from ( + SELECT distinct + DATE_TRUNC('hour', minute) time, + contract_address as token, + decimals, + symbol, + last_value(price) over (partition by DATE_TRUNC('hour', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and blockchain = 'bnb' + and contract_address in (select address from tokens) +) p +) + + +, swap_events as ( + select + date_trunc('day', sw.evt_block_time) as time, + sw.contract_address as pool, + cr.token0, cr.token1, + sum(cast(amount0 as DOUBLE)) as amount0, + sum(cast(amount1 as DOUBLE)) as amount1 + + from {{ source('pancakeswap_v3_bnb', 'PancakeV3Pool_evt_Swap') }} sw + left join {{ source('pancakeswap_v3_bnb', 'PancakeV3Factory_evt_PoolCreated') }} cr on sw.contract_address = cr.pool + join pools on sw.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + group by 1,2,3,4 +) + +, mint_events as ( + select + date_trunc('day', mt.evt_block_time) as time, + mt.contract_address as pool, + cr.token0, cr.token1, + sum(cast(amount0 as DOUBLE)) as amount0, + sum(cast(amount1 as DOUBLE)) as amount1 + from {{ source('pancakeswap_v3_bnb', 'PancakeV3Pool_evt_Mint') }} mt + left join {{ source('pancakeswap_v3_bnb', 'PancakeV3Factory_evt_PoolCreated') }} cr on mt.contract_address = cr.pool + join pools on mt.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', mt.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('mt.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + +, burn_events as ( + select + date_trunc('day', bn.evt_block_time) as time, + bn.contract_address as pool, + cr.token0, cr.token1, + (-1)*sum(cast(amount0 as DOUBLE)) as amount0, + (-1)*sum(cast(amount1 as DOUBLE)) as amount1 + from {{ source('pancakeswap_v3_bnb', 'PancakeV3Pool_evt_Burn') }} bn + left join {{ source('pancakeswap_v3_bnb', 'PancakeV3Factory_evt_PoolCreated') }} cr on bn.contract_address = cr.pool + join pools on bn.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', bn.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('bn.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + + , collect_events AS ( + SELECT + date_trunc('day', c.evt_block_time) as time, + c.contract_address AS pool, + cr.token0, + cr.token1, + (-1) * CAST(amount0 AS DOUBLE) AS amount0, + (-1) * CAST(amount1 AS DOUBLE) AS amount1, + c.evt_tx_hash + FROM + {{source('pancakeswap_v3_bnb','PancakeV3Pool_evt_Collect')}} AS c + LEFT JOIN {{source('pancakeswap_v3_bnb','PancakeV3Factory_evt_PoolCreated')}} AS cr ON c.contract_address = cr.pool + join pools on c.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', c.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('c.evt_block_time') }} + {% endif %} + + ) + + +, daily_delta_balance as ( + select time, pool, token0, token1, sum(coalesce(amount0, 0)) as amount0, sum(coalesce(amount1, 0)) as amount1 + from ( + select time, pool, token0, token1, amount0, amount1 + from swap_events + union all + select time, pool, token0, token1, amount0, amount1 + from mint_events + union all + select time, pool, token0, token1, amount0, amount1 + from collect_events + ) balance + group by 1,2,3,4 +) + +, pool_liquidity as ( + select time, + pool, + token0, + token1, + sum(amount0) as amount0, + sum(amount1) as amount1 + from daily_delta_balance + group by 1,2,3,4 +) + + +, swap_events_hourly as ( + select hour, pool, token0, token1, sum(amount0) as amount0, sum(amount1) as amount1 from ( + select + date_trunc('hour', sw.evt_block_time) as hour, + sw.contract_address as pool, + cr.token0, cr.token1, + coalesce(sum(cast(abs(amount0) as DOUBLE)),0) as amount0, + coalesce(sum(cast(abs(amount1) as DOUBLE)),0) as amount1 + + from {{source('pancakeswap_v3_bnb','PancakeV3Pool_evt_Swap')}} sw + left join {{source('pancakeswap_v3_bnb','PancakeV3Factory_evt_PoolCreated')}} cr on sw.contract_address = cr.pool + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + and sw.contract_address in (select address from pools) + group by 1,2,3,4 + + ) a group by 1,2,3,4 +) + +, trading_volume_hourly as ( + select hour as time, pool, token0, amount0, p.price, coalesce(p.price*amount0/power(10, p.decimals),0) as volume + from swap_events_hourly s + left join tokens t on s.token0 = t.address + left join tokens_prices_hourly p on s.hour >= p.time and s.hour < p.next_time and s.token0 = p.token + +) + +, trading_volume as ( +select distinct date_trunc('day', time) as time, pool, sum(volume) as volume +from trading_volume_hourly +group by 1,2 +) + +, all_metrics as ( +select l.pool, pools.blockchain, pools.project, pools.fee, cast(l.time as date) as time, + case when token0 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then token0 else token1 end main_token, + case when token0 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then p0.symbol else p1.symbol end main_token_symbol, + case when token0 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then token1 else token0 end paired_token, + case when token0 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then p1.symbol else p0.symbol end paired_token_symbol, + case when token0 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then amount0/power(10, p0.decimals) else amount1/power(10, p1.decimals) end main_token_reserve, + case when token0 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then amount1/power(10, p1.decimals) else amount0/power(10, p0.decimals) end paired_token_reserve, + case when token0 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then p0.price else p1.price end as main_token_usd_price, + case when token0 = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then p1.price else p0.price end as paired_token_usd_price, + volume as trading_volume +from pool_liquidity l +left join pools on l.pool = pools.address +left join tokens t0 on l.token0 = t0.address +left join tokens t1 on l.token1 = t1.address +left join tokens_prices_daily p0 on l.time = p0.time and l.token0 = p0.token +left join tokens_prices_daily p1 on l.time = p1.time and l.token1 = p1.token +left join trading_volume tv on l.time = tv.time and l.pool = tv.pool +) + + + +select blockchain||' '||project||' '||COALESCE(paired_token_symbol, 'unknown')||':'||main_token_symbol||' '||format('%,.3f',round(coalesce(fee,0),4)) as pool_name,* +from all_metrics + diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_schema.yml b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_schema.yml new file mode 100644 index 00000000000..495e2002435 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_schema.yml @@ -0,0 +1,64 @@ +version: 2 + +models: + - name: lido_liquidity_bnb_pancakeswap_v3_pools + meta: + blockchain: bnb + project: lido + contributors: pipistrella + config: + tags: ['bnb','lido','liquidity'] + description: + Lido wstETH liquidity pools on Pancake v3 BNB Chain + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool + - blockchain + - time + columns: + - &pool_name + name: pool_name + description: "Liquidity pool's name consisting of the its blockchain, DEX project, symbols of tokens and fee value" + - &pool + name: pool + description: "Liquidity pool's address" + - &blockchain + name: blockchain + description: "Blockchain which the DEX is deployed" + - &project + name: project + description: "Project name of the DEX" + - &fee + name: fee + description: "Liquidity pool's trading fee" + - &time + name: time + description: "UTC event block date truncated to the day mark" + - &main_token + name: main_token + description: "Main token's address" + - &main_token_symbol + name: main_token_symbol + description: "Token symbol for main pool's token" + - &paired_token + name: paired_token + description: "Paired token's address" + - &paired_token_symbol + name: paired_token_symbol + description: "Token symbol for paired pool's token" + - &main_token_reserve + name: main_token_reserve + description: "Liquidity reserve of the main token in the pool" + - &paired_token_reserve + name: paired_token_reserve + description: "Liquidity reserve of the paired token in the pool" + - &main_token_usd_price + name: main_token_usd_price + description: "Price of the main token in the pool in USD" + - &paired_token_usd_price + name: paired_token_usd_price + description: "Price of the paired token in the pool in USD" + - &trading_volume + name: trading_volume + description: "USD value of the trade" \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_thena_pools.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_thena_pools.sql new file mode 100644 index 00000000000..a861d12f4df --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/bnb/lido_liquidity_bnb_thena_pools.sql @@ -0,0 +1,242 @@ +{{ config( + schema='lido_liquidity_bnb', + alias = 'thena_pools', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool', 'time'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.time')], + post_hook='{{ expose_spells(blockchains = \'["bnb"]\', + spell_type = "project", + spell_name = "lido_liquidity", + contributors = \'["pipistrella"]\') }}' + ) +}} + +{% set project_start_date = '2024-08-10' %} + +with + +pools as ( +select output_pool as address, 'bnb' as blockchain, 'thena' as project +from {{ source('thena_fi_bnb','PairFactory_CL_call_createPool')}} +where tokenA = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C or tokenB = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C +group by 1,2,3 +) + +, tokens as ( +select distinct token as address +from ( +select tokenB as token +from {{ source('thena_fi_bnb','PairFactory_CL_call_createPool')}} +where tokenA = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C +union +select tokenA +from {{ source('thena_fi_bnb','PairFactory_CL_call_createPool')}} +where tokenB = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C +union +select 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C +) t +) + +, tokens_prices_daily AS ( + SELECT distinct + DATE_TRUNC('day', minute) AS time, + contract_address as token, + decimals, + symbol, + avg(price) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and date_trunc('day', minute) < current_date + and blockchain = 'bnb' + and contract_address in (select address from tokens) + group by 1,2,3,4 + union all + SELECT distinct + DATE_TRUNC('day', minute), + contract_address as token, + decimals, + symbol, + last_value(price) over (partition by DATE_TRUNC('day', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} + WHERE date_trunc('day', minute) = current_date + and blockchain = 'bnb' + and contract_address in (select address from tokens) +) + +, tokens_prices_hourly AS ( + select time, + lead(time,1, DATE_TRUNC('hour', now() + interval '1' hour)) over (partition by token order by time) as next_time, + token, price, decimals, symbol + from ( + SELECT distinct + DATE_TRUNC('hour', minute) time, + contract_address as token, + decimals, + symbol, + last_value(price) over (partition by DATE_TRUNC('hour', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and blockchain = 'bnb' + and contract_address in (select address from tokens) +) p +) + + +, swap_events as ( + select + date_trunc('day', sw.evt_block_time) as time, + sw.contract_address as pool, + cr.tokenA, cr.tokenB, + sum(cast(amount0 as DOUBLE)) as amount0, + sum(cast(amount1 as DOUBLE)) as amount1 + + from {{ source('thena_bnb', 'AlgebraPool_evt_Swap') }} sw + left join {{ source('thena_fi_bnb', 'PairFactory_CL_call_createPool') }} cr on sw.contract_address = cr.output_pool + join pools on sw.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + group by 1,2,3,4 +) + +, mint_events as ( + select + date_trunc('day', mt.evt_block_time) as time, + mt.contract_address as pool, + cr.tokenA, cr.tokenB, + sum(cast(amount0 as DOUBLE)) as amount0, + sum(cast(amount1 as DOUBLE)) as amount1 + from {{ source('thena_bnb', 'AlgebraPool_evt_Mint') }} mt + left join {{ source('thena_fi_bnb', 'PairFactory_CL_call_createPool') }} cr on mt.contract_address = cr.output_pool + join pools on mt.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', mt.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('mt.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + +, burn_events as ( + select + date_trunc('day', bn.evt_block_time) as time, + bn.contract_address as pool, + cr.tokenA, cr.tokenB, + (-1)*sum(cast(amount0 as DOUBLE)) as amount0, + (-1)*sum(cast(amount1 as DOUBLE)) as amount1 + from {{ source('thena_bnb', 'AlgebraPool_evt_Burn') }} bn + left join {{ source('thena_fi_bnb', 'PairFactory_CL_call_createPool') }} cr on bn.contract_address = cr.output_pool + join pools on bn.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', bn.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('bn.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + + +, daily_delta_balance as ( + select time, pool, tokenA, tokenB, sum(coalesce(amount0, 0)) as amount0, sum(coalesce(amount1, 0)) as amount1 + from ( + select time, pool, tokenA, tokenB, amount0, amount1 + from swap_events + union all + select time, pool, tokenA, tokenB, amount0, amount1 + from mint_events + union all + select time, pool, tokenA, tokenB, amount0, amount1 + from burn_events + ) balance + group by 1,2,3,4 +) + +, pool_liquidity as ( + select time, + pool, + tokenA, + tokenB, + sum(amount0) as amount0, + sum(amount1) as amount1 + from daily_delta_balance + group by 1,2,3,4 +) + + +, swap_events_hourly as ( + select hour, pool, tokenA, tokenB, sum(amount0) as amount0, sum(amount1) as amount1 from ( + select + date_trunc('hour', sw.evt_block_time) as hour, + sw.contract_address as pool, + cr.tokenA, cr.tokenB, + coalesce(sum(cast(abs(amount0) as DOUBLE)),0) as amount0, + coalesce(sum(cast(abs(amount1) as DOUBLE)),0) as amount1 + + from {{ source('thena_bnb', 'AlgebraPool_evt_Swap') }} sw + left join {{source('thena_fi_bnb','PairFactory_CL_call_createPool')}} cr on sw.contract_address = cr.output_pool + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + and sw.contract_address in (select address from pools) + group by 1,2,3,4 + + ) a group by 1,2,3,4 +) + +, trading_volume_hourly as ( + select hour as time, pool, tokenA, amount0, p.price, coalesce(p.price*amount0/power(10, p.decimals),0) as volume + from swap_events_hourly s + left join tokens t on s.tokenA = t.address + left join tokens_prices_hourly p on s.hour >= p.time and s.hour < p.next_time and s.tokenA = p.token + +) + +, trading_volume as ( +select distinct date_trunc('day', time) as time, pool, sum(volume) as volume +from trading_volume_hourly +group by 1,2 +) + +, all_metrics as ( +select l.pool, pools.blockchain, pools.project, cast(l.time as date) as time, + case when tokenA = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then tokenA else tokenB end main_token, + case when tokenA = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then p0.symbol else p1.symbol end main_token_symbol, + case when tokenA = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then tokenB else tokenA end paired_token, + case when tokenA = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then p1.symbol else p0.symbol end paired_token_symbol, + case when tokenA = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then amount0/power(10, p0.decimals) else amount1/power(10, p1.decimals) end main_token_reserve, + case when tokenA = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then amount1/power(10, p1.decimals) else amount0/power(10, p0.decimals) end paired_token_reserve, + case when tokenA = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then p0.price else p1.price end as main_token_usd_price, + case when tokenA = 0x26c5e01524d2E6280A48F2c50fF6De7e52E9611C then p1.price else p0.price end as paired_token_usd_price, + volume as trading_volume +from pool_liquidity l +left join pools on l.pool = pools.address +left join tokens t0 on l.tokenA = t0.address +left join tokens t1 on l.tokenB = t1.address +left join tokens_prices_daily p0 on l.time = p0.time and l.tokenA = p0.token +left join tokens_prices_daily p1 on l.time = p1.time and l.tokenB = p1.token +left join trading_volume tv on l.time = tv.time and l.pool = tv.pool +) + + + +select blockchain||' '||project||' '||COALESCE(paired_token_symbol, 'unknown')||':'||main_token_symbol as pool_name,* +from all_metrics + diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/ethereum/lido_liquidity_ethereum_balancer_pools.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/ethereum/lido_liquidity_ethereum_balancer_pools.sql index 8aec58d6c63..7e146f4eb83 100644 --- a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/ethereum/lido_liquidity_ethereum_balancer_pools.sql +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/ethereum/lido_liquidity_ethereum_balancer_pools.sql @@ -83,7 +83,11 @@ values (0x5F1F4E50BA51D723F12385A8A9606AFC3A0555F5000200000000000000000465, 0x5F1F4E50BA51D723F12385A8A9606AFC3A0555F5), (0x25ACCB7943FD73DDA5E23BA6329085A3C24BFB6A000200000000000000000387, 0x25ACCB7943FD73DDA5E23BA6329085A3C24BFB6A), (0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd0000000000000000000005c2, 0x93d199263632a4ef4bb438f1feb99e57b4b5f0bd), -(0x54ca50ee86616379420cc56718e12566aa75abbe000200000000000000000610, 0x54ca50ee86616379420cc56718e12566aa75abbe) +(0x54ca50ee86616379420cc56718e12566aa75abbe000200000000000000000610, 0x54ca50ee86616379420cc56718e12566aa75abbe), +(0x3de27efa2f1aa663ae5d458857e731c129069f29000200000000000000000588, 0x3de27efa2f1aa663ae5d458857e731c129069f29), +(0x63e0d47a6964ad1565345da9bfa66659f4983f02000000000000000000000681, 0x63e0d47a6964ad1565345da9bfa66659f4983f02), +(0xb91159aa527d4769cb9faf3e4adb760c7e8c8ea700000000000000000000067c, 0xb91159aa527d4769cb9faf3e4adb760c7e8c8ea7) + ) diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/ethereum/lido_liquidity_ethereum_curve_wsteth_pufeth_pool.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/ethereum/lido_liquidity_ethereum_curve_wsteth_pufeth_pool.sql new file mode 100644 index 00000000000..c0f0c8454dc --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/ethereum/lido_liquidity_ethereum_curve_wsteth_pufeth_pool.sql @@ -0,0 +1,236 @@ +{{ config( + schema='lido_liquidity_ethereum', + alias = 'curve_wsteth_pufeth_pool', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool', 'time'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.time')], + post_hook='{{ expose_spells(blockchains = \'["ethereum"]\', + spell_type = "project", + spell_name = "lido_liquidity", + contributors = \'["pipistrella"]\') }}' + ) +}} + +{% set project_start_date = '2024-03-23' %} + + + +with + +wsteth_in as ( +select + DATE_TRUNC('day', evt_block_time) as time, + sum(cast(value as double))/1e18 as wsteth_in +from {{source('erc20_ethereum','evt_Transfer')}} t +{% if not is_incremental() %} + WHERE DATE_TRUNC('day', evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE DATE_TRUNC('day', evt_block_time) >= DATE_TRUNC('day', NOW() - INTERVAL '1' day) + {% endif %} + and contract_address = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0 + and to = 0xeeda34a377dd0ca676b9511ee1324974fa8d980d +group by 1 +) + +, wsteth_out as ( +select + DATE_TRUNC('day', evt_block_time) as time, + -sum(cast(value as double))/1e18 as wsteth_out +from {{source('erc20_ethereum','evt_Transfer')}} t +{% if not is_incremental() %} + WHERE DATE_TRUNC('day', evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE DATE_TRUNC('day', evt_block_time) >= DATE_TRUNC('day', NOW() - INTERVAL '1' day) + {% endif %} + and contract_address = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0 + and "from" = 0xeeda34a377dd0ca676b9511ee1324974fa8d980d + +group by 1 +) + +, wsteth_daily_balances as ( +select time, sum(wsteth_in) wsteth_balance from ( +select * from wsteth_in +union all +select * from wsteth_out +) group by 1 +) + +, wsteth_balances as ( +select time, + sum(wsteth_balance) as wsteth +from wsteth_daily_balances b +group by 1 +order by 1 +) + + +, pufeth_in as ( +select + DATE_TRUNC('day', evt_block_time) as time, + sum(cast(value as double))/1e18 as pufeth_in +from {{source('erc20_ethereum','evt_Transfer')}} t + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + and contract_address = 0xD9A442856C234a39a81a089C06451EBAa4306a72 + and to = 0xeeda34a377dd0ca676b9511ee1324974fa8d980d + group by 1 +) + +, pufeth_out as ( +select + DATE_TRUNC('day', evt_block_time) as time, + -sum(cast(value as double))/1e18 as pufeth_out +from {{source('erc20_ethereum','evt_Transfer')}} t + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + and contract_address = 0xD9A442856C234a39a81a089C06451EBAa4306a72 + and "from" = 0xeeda34a377dd0ca676b9511ee1324974fa8d980d + group by 1 +) + +, pufeth_daily_balances as ( +select time, sum(pufeth_in) as pufeth_balance from ( +select * from pufeth_in +union all +select * from pufeth_out +) group by 1 +) + +, pufeth_balances as ( +select time, sum(pufeth_balance) pufeth +from pufeth_daily_balances +group by 1 +order by 1 +) + + +, pufeth_prices_daily AS ( + SELECT distinct + DATE_TRUNC('day', minute) AS time, + avg(price) AS price + FROM {{source('prices','usd')}} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and date_trunc('day', minute) < current_date + and blockchain = 'ethereum' + and contract_address = 0xD9A442856C234a39a81a089C06451EBAa4306a72 + group by 1 + union all + SELECT distinct + DATE_TRUNC('day', minute), + last_value(price) over (partition by DATE_TRUNC('day', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{source('prices','usd')}} + WHERE date_trunc('day', minute) = current_date + and blockchain = 'ethereum' + and contract_address = 0xD9A442856C234a39a81a089C06451EBAa4306a72 + + +) + +, wsteth_prices_hourly AS ( + select time + , lead(time,1, DATE_TRUNC('hour', now() + interval '1' hour)) over (order by time) as next_time + , price + from ( + SELECT distinct + DATE_TRUNC('hour', minute) time + , last_value(price) over (partition by DATE_TRUNC('hour', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{source('prices','usd')}} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and blockchain = 'ethereum' + and contract_address = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0 + +)) + +, wsteth_prices_daily AS ( + SELECT distinct + DATE_TRUNC('day', minute) AS time, + avg(price) AS price + FROM {{source('prices','usd')}} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and date_trunc('day', minute) < current_date + and blockchain = 'ethereum' + and contract_address = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0 + group by 1 + union all + SELECT distinct + DATE_TRUNC('day', minute), + last_value(price) over (partition by DATE_TRUNC('day', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{source('prices','usd')}} + WHERE date_trunc('day', minute) = current_date + and blockchain = 'ethereum' + and contract_address = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0 + +) + +, token_exchange_hourly as( + select date_trunc('hour', evt_block_time) as time + , sum(case when cast(sold_id as int) = int '0' then cast(tokens_sold as double) else cast(tokens_bought as double) end) as eth_amount_raw + from {{source('puffer_ethereum','CurveStableSwapNG_evt_TokenExchange')}} c + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('evt_block_time') }} + {% endif %} + group by 1 + +) + +, trading_volume_hourly as ( + select t.time + , t.eth_amount_raw * wp.price as volume_raw + from token_exchange_hourly t + left join wsteth_prices_hourly wp on t.time = wp.time + order by 1 +) + +, trading_volume as ( + select distinct date_trunc('day', time) as time + , sum(volume_raw)/1e18 as volume + from trading_volume_hourly + GROUP by 1 +) + +select 'ethereum curve pufETH:wstETH 0.04' as pool_name, + 0xeeda34a377dd0ca676b9511ee1324974fa8d980d as pool, + 'ethereum' as blockchain, + 'curve' as project, + 0.02 as fee, + cast(b.time as date) as time, + 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0 as main_token, + 'wstETH' as main_token_symbol, + 0xD9A442856C234a39a81a089C06451EBAa4306a72 as paired_token, + 'pufETH' as paired_token_symbol, + wsteth as main_token_reserve, + coalesce(pufeth.pufeth, 0) as paired_token_reserve, + coalesce(wstethp.price, 0)as main_token_usd_price, + pufethp.price as paired_token_usd_price, + v.volume as trading_volume +from wsteth_balances b +left join pufeth_balances pufeth on b.time = pufeth.time +left join wsteth_prices_daily wstethp on b.time = wstethp.time +left join pufeth_prices_daily pufethp on b.time = pufethp.time +left join trading_volume v on b.time = v.time + +order by 1 + diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/linea/lido_liquidity_linea_lynex_pools.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/linea/lido_liquidity_linea_lynex_pools.sql new file mode 100644 index 00000000000..bf1d7f9c951 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/linea/lido_liquidity_linea_lynex_pools.sql @@ -0,0 +1,275 @@ +{{ config( + schema='lido_liquidity_linea', + alias = 'lynex_pools', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool', 'time'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.time')], + post_hook='{{ expose_spells(blockchains = \'["linea"]\', + spell_type = "project", + spell_name = "lido_liquidity", + contributors = \'["pipistrella"]\') }}' + ) +}} + +{% set project_start_date = '2024-03-23' %} + +with pools as ( +select pool AS address, + 'linea' AS blockchain, + 'lynex' AS project, + * +from {{source('lynex_linea','AlgebraFactory_evt_Pool')}} +where (token0 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F + OR token1 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F) +) + +, tokens as ( + select distinct token + from ( + select token0 as token + from {{source('lynex_linea','AlgebraFactory_evt_Pool')}} + where token1 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F + union all + select token1 + from {{source('lynex_linea','AlgebraFactory_evt_Pool')}} + where token0 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F + union all + select 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F + ) t + ) + + , tokens_prices_daily as ( +select distinct + DATE_TRUNC('day', minute) AS time, + contract_address AS token, + symbol, + decimals, + AVG(price) AS price +FROM {{source('prices','usd')}} p +{% if not is_incremental() %} +WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' +{% else %} +WHERE {{incremental_predicate('p.minute')}} +{% endif %} + and date_trunc('day', minute) < current_date + and blockchain = 'linea' + and contract_address IN (select token from tokens) +group by 1,2,3,4 +union all +select distinct + DATE_TRUNC('day', minute), + contract_address AS token, + symbol, + decimals, + LAST_VALUE(price) OVER (PARTITION BY DATE_TRUNC('day', minute),contract_address ORDER BY minute NULLS FIRST range BETWEEN UNBOUNDED preceding AND UNBOUNDED following) AS price + FROM {{source('prices','usd')}} p + WHERE + DATE_TRUNC('day', minute) = current_date + and blockchain = 'linea' + and contract_address IN (select token from tokens) + ) + + , wsteth_prices_hourly AS ( + SELECT distinct + DATE_TRUNC('hour', minute) time, + contract_address as token, + symbol, + decimals, + last_value(price) over (partition by DATE_TRUNC('hour', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{incremental_predicate('p.minute')}} + {% endif %} + and blockchain = 'linea' and contract_address = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F + + +) + +, wsteth_prices_hourly_with_lead AS ( +select time, + lead(time, 1, date_trunc('hour', now() + interval '1' hour)) over (order by time) as next_time, + price +from wsteth_prices_hourly +) + +, mint_events AS ( + select DATE_TRUNC('day', m.evt_block_time) AS time, + m.contract_address AS pool, + cr.token0, + cr.token1, + SUM(CAST(amount0 AS DOUBLE)) AS amount0, + SUM(CAST(amount1 AS DOUBLE)) AS amount1 + from {{source('lynex_linea','AlgebraPool_evt_Mint')}} m + left join {{source('lynex_linea','AlgebraFactory_evt_Pool')}} cr on m.contract_address = cr.pool + join pools on m.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', m.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{incremental_predicate('m.evt_block_time')}} + {% endif %} + group by 1,2,3,4 + ) + + , burn_events as ( + select DATE_TRUNC('day', b.evt_block_time) AS time, + b.contract_address AS pool, + cr.token0, + cr.token1, + (-1)*SUM(CAST(amount0 AS DOUBLE)) AS amount0, + (-1)*SUM(CAST(amount1 AS DOUBLE)) AS amount1 + from {{source('lynex_linea','AlgebraPool_evt_Burn')}} b + left join {{source('lynex_linea','AlgebraFactory_evt_Pool')}} cr on b.contract_address = cr.pool + join pools on b.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', b.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{incremental_predicate('b.evt_block_time')}} + {% endif %} + group by 1,2,3,4 + + ) + +, swap_events as ( + select DATE_TRUNC('day', s.evt_block_time) AS time, + s.contract_address AS pool, + cr.token0, + cr.token1, + SUM(CAST(amount0 AS DOUBLE)) AS amount0, + SUM(CAST(amount1 AS DOUBLE)) AS amount1 + from {{source('lynex_linea','AlgebraPool_evt_Swap')}} s + left join {{source('lynex_linea','AlgebraFactory_evt_Pool')}} cr on s.contract_address = cr.pool + join pools on s.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', s.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{incremental_predicate('s.evt_block_time')}} + {% endif %} + group by 1,2,3,4 + +) + + , daily_delta_balance AS ( + +select time, pool, token0, token1, sum(amount0) as amount0, sum(amount1) as amount1 +from ( +select time, pool,token0, token1, amount0, amount1 +from mint_events + +union all + +select time, pool,token0, token1, amount0, amount1 +from swap_events + +union all + +select time, pool,token0, token1, amount0, amount1 +from burn_events + +) group by 1,2,3,4 +) + +, daily_delta_balance_with_lead AS ( +select time, pool, token0, token1, amount0, amount1, +lead(time, 1, now()) over (partition by pool order by time) as next_time +from daily_delta_balance +) + + +, pool_liquidity as ( +SELECT b.time, + b.pool, + token0, + token1, + SUM(amount0) AS amount0, + SUM(amount1) AS amount1 +FROM daily_delta_balance_with_lead b +GROUP BY 1,2,3,4 +) + +, swap_events_hourly as ( + select DATE_TRUNC('hour', s.evt_block_time) AS time, + s.contract_address AS pool, + sum(case when cr.token0 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F then CAST(amount0 AS DOUBLE) + else CAST(amount1 AS DOUBLE) end) as wsteth_amount + from {{source('lynex_linea','AlgebraPool_evt_Swap')}} s + left join {{source('lynex_linea','AlgebraFactory_evt_Pool')}} cr on s.contract_address = cr.pool + join pools on s.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', s.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{incremental_predicate('s.evt_block_time')}} + {% endif %} +group by 1,2 +) + +, trading_volume_hourly AS ( + SELECT + s.time, + pool, + wsteth_amount, + p.price, + COALESCE((p.price * wsteth_amount) / CAST(POWER(10, 18) AS DOUBLE), 0) AS volume + FROM + swap_events_hourly AS s + LEFT JOIN wsteth_prices_hourly_with_lead AS p ON s.time >= p.time + AND s.time < p.next_time + ) + +, trading_volume AS ( + SELECT DISTINCT + DATE_TRUNC('day', time) AS time, + pool, + SUM(volume) AS volume + FROM trading_volume_hourly + GROUP BY 1, 2 + ) + +, all_metrics AS ( + SELECT + l.pool, + pools.blockchain, + pools.project, + cast(l.time as date) as time, + CASE WHEN l.token0 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F THEN l.token0 ELSE l.token1 END AS main_token, + CASE WHEN l.token0 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F THEN p0.symbol ELSE p1.symbol END AS main_token_symbol, + CASE WHEN l.token0 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F THEN l.token1 ELSE l.token0 END AS paired_token, + CASE WHEN l.token0 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F THEN p1.symbol ELSE p0.symbol END AS paired_token_symbol, + CASE WHEN l.token0 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F THEN amount0/CAST(POWER(10,p0.decimals) as double) ELSE amount1/CAST(POWER(10,p1.decimals) as double) END AS main_token_reserve, + CASE WHEN l.token0 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F THEN amount1/CAST(POWER(10, p1.decimals) as double) ELSE amount0/CAST(POWER(10, p0.decimals) as double) END AS paired_token_reserve, + CASE WHEN l.token0 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F THEN p0.price ELSE p1.price END AS main_token_usd_price, + CASE WHEN l.token0 = 0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F THEN p1.price ELSE p0.price END AS paired_token_usd_price, + coalesce(volume,0) AS trading_volume + FROM + pool_liquidity AS l + LEFT JOIN pools ON l.pool = pools.address + LEFT JOIN tokens AS t0 ON l.token0 = t0.token + LEFT JOIN tokens AS t1 ON l.token1 = t1.token + LEFT JOIN tokens_prices_daily AS p0 ON l.time = p0.time + AND l.token0 = p0.token + LEFT JOIN tokens_prices_daily AS p1 ON l.time = p1.time + AND l.token1 = p1.token + LEFT JOIN trading_volume AS tv ON l.time = tv.time + AND l.pool = tv.pool + ) + + +SELECT + blockchain || ' ' || project || ' ' || COALESCE(paired_token_symbol, 'unknown') || ':' || main_token_symbol AS pool_name, + pool, + blockchain, + project, + time, + main_token, + main_token_symbol, + paired_token, + paired_token_symbol, + main_token_reserve, + paired_token_reserve, + main_token_usd_price, + paired_token_usd_price, + trading_volume +from all_metrics \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/scroll/lido_liquidity_scroll_maverick_pools.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/scroll/lido_liquidity_scroll_maverick_pools.sql new file mode 100644 index 00000000000..9b032594cce --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/scroll/lido_liquidity_scroll_maverick_pools.sql @@ -0,0 +1,254 @@ +{{ config( + schema='lido_liquidity_scroll', + alias = 'maverick_pools', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool', 'time'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.time')], + post_hook='{{ expose_spells(blockchains = \'["scroll"]\', + spell_type = "project", + spell_name = "lido_liquidity", + contributors = \'["pipistrella"]\') }}' + ) +}} + +{% set project_start_date = '2024-07-29' %} + +with + +pools as ( +select poolAddress, tokenA, tokenB, cast(feeAIn as double)/1e16 as fee +from {{source('maverick_v2_scroll','V2Factory_evt_PoolCreated')}} +where tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 + or tokenB = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 +) + + +, tokens as ( +select distinct token as address +from ( +select tokenA as token +from {{source('maverick_v2_scroll','V2Factory_evt_PoolCreated')}} +where tokenB = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 +union +select tokenB +from {{source('maverick_v2_scroll','V2Factory_evt_PoolCreated')}} +where tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 +union +select 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 +) t +) + +, tokens_prices_daily AS ( + SELECT distinct + DATE_TRUNC('day', minute) AS time, + contract_address as token, + symbol, + decimals, + avg(price) AS price + FROM {{source('prices','usd')}} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and date_trunc('day', minute) < current_date + and blockchain = 'scroll' + and contract_address in (select address from tokens) + group by 1,2,3,4 + union all + SELECT distinct + DATE_TRUNC('day', minute), + contract_address as token, + symbol, + decimals, + last_value(price) over (partition by DATE_TRUNC('day', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{source('prices','usd')}} + WHERE date_trunc('day', minute) = current_date + and blockchain = 'scroll' + and contract_address in (select address from tokens) +) + +, wsteth_prices_hourly as ( + select time, lead(time,1, DATE_TRUNC('hour', now() + interval '1' hour)) over (order by time) as next_time, price + from ( + SELECT distinct + DATE_TRUNC('hour', minute) time, + last_value(price) over (partition by DATE_TRUNC('hour', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{source('prices','usd')}} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and blockchain = 'scroll' + and contract_address = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 + ) p +) + +, swap_events as ( + select + date_trunc('day', sw.evt_block_time) as time, + sw.contract_address as pool, + cr.tokenA, cr.tokenB, + sum(case when json_extract_scalar(params, '$.tokenAIn') = 'true' then cast(amountIn as double) else (-1)*cast(amountOut as double) end) as amountA, + sum(case when json_extract_scalar(params, '$.tokenAIn') = 'true' then (-1)*cast(amountOut as double) else cast(amountIn as double) end) as amountB + from {{source('maverick_v2_scroll','V2Pool_evt_PoolSwap')}} sw + left join {{source('maverick_v2_scroll','V2Factory_evt_PoolCreated')}} cr on sw.contract_address = cr.poolAddress + join pools on sw.contract_address = pools.poolAddress + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + group by 1,2,3,4 +) + +, addliquidity_events as ( + select date_trunc('day', a.evt_block_time) as time, + a.contract_address as pool, + cr.tokenA, cr.tokenB, + sum(cast(tokenAAmount as double)) as amountA, + sum(cast(tokenBAmount as double)) as amountB +from {{source('maverick_v2_scroll','V2Pool_evt_PoolAddLiquidity')}} a +left join {{source('maverick_v2_scroll','V2Factory_evt_PoolCreated')}} cr on a.contract_address = cr.poolAddress +join pools on a.contract_address = pools.poolAddress + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', a.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('a.evt_block_time') }} + {% endif %} +group by 1,2,3,4 +) + +, removeliquidity_events as ( +select date_trunc('day', a.evt_block_time) as time, + a.contract_address as pool, + cr.tokenA, cr.tokenB, + (-1)*sum(cast(tokenAOut as double)) as amountA, + (-1)*sum(cast(tokenBOut as double)) as amountB +from {{source('maverick_v2_scroll','V2Pool_evt_PoolRemoveLiquidity')}} a +left join {{source('maverick_v2_scroll','V2Factory_evt_PoolCreated')}} cr on a.contract_address = cr.poolAddress +join pools on a.contract_address = pools.poolAddress + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', a.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('a.evt_block_time') }} + {% endif %} +group by 1,2,3,4 +) + +, daily_delta_balance AS ( + +select time, pool, tokenA, tokenB, sum(amountA) as amountA, sum(amountB) as amountB +from ( +select time, pool,tokenA, tokenB, amountA, amountB +from swap_events + +union all + +select time, pool,tokenA, tokenB, amountA, amountB +from addliquidity_events + +union all + +select time, pool,tokenA, tokenB, amountA, amountB +from removeliquidity_events + +) group by 1,2,3,4 +) + + +, pool_liquidity as ( +SELECT time, pools.fee, + pool, + b.tokenA, + b.tokenB, + coalesce((SUM(amountA)),0) AS amountA, + coalesce((SUM(amountB)),0) AS amountB +FROM daily_delta_balance b +left join pools on b.pool = pools.poolAddress +GROUP BY 1,2,3,4,5 +) + + + +, wsteth_traded_hourly as ( + select + date_trunc('hour', sw.evt_block_time) as time, + sw.contract_address as pool, + cr.tokenA, cr.tokenB, + sum(case when (cr.tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 and json_extract_scalar(params, '$.tokenAIn') = 'true') then amountIn + when (cr.tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 and json_extract_scalar(params, '$.tokenAIn') = 'false') then amountOut + when (cr.tokenA != 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 and json_extract_scalar(params, '$.tokenAIn') = 'true') then amountOut + when (cr.tokenA != 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 and json_extract_scalar(params, '$.tokenAIn') = 'false') then amountIn + end) as amount + from {{source('maverick_v2_scroll','V2Pool_evt_PoolSwap')}} sw + left join {{source('maverick_v2_scroll','V2Factory_evt_PoolCreated')}} cr on sw.contract_address = cr.poolAddress + join pools on sw.contract_address = pools.poolAddress + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + +, trading_volume_hourly as ( +select t.time, pool, t.amount*wp.price as volume_raw +from wsteth_traded_hourly t +left join wsteth_prices_hourly wp on date_trunc('hour',t.time) >= wp.time and date_trunc('hour',t.time) < wp.next_time +order by 1,2 +) + +, trading_volume as ( + select distinct date_trunc('day', time) as time + , pool + , sum(volume_raw)/1e18 as volume + from trading_volume_hourly + GROUP by 1,2 +) + +, all_metrics as ( +select + o.pool, + 'scroll' as blockchain, + 'maverick' as project, + format('%,.3f',round(coalesce(fee,0),4)) as fee, + cast(o.time as date) time, + case when o.tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 then o.tokenA else o.tokenB end as main_token, + case when o.tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 then pA.symbol else pB.symbol end as main_token_symbol, + case when o.tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 then o.tokenB else o.tokenA end as paired_token, + case when o.tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 then pB.symbol else pA.symbol end as paired_token_symbol, + case when o.tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 then amountA/power(10,pA.decimals) else amountB/power(10,pB.decimals) end as main_token_reserve, + case when o.tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 then amountB/power(10,pB.decimals) else amountA/power(10,pA.decimals) end as paired_token_reserve, + case when o.tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 then pA.price else pB.price end as main_token_usd_price, + case when o.tokenA = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 then pB.price else pA.price end as paired_token_usd_price, + coalesce(t.volume,0) as trading_volume +from pool_liquidity o +left join tokens_prices_daily pA on o.time = pA.time and o.tokenA = pA.token +left join tokens_prices_daily pB on o.time = pB.time and o.tokenB = pB.token +left join trading_volume t on o.time = t.time and o.pool = t.pool +) + + +select blockchain||' '||project||' '||coalesce(paired_token_symbol,'unknown')||':'||main_token_symbol||' '||fee|| '('||cast(pool as varchar)||')' as pool_name, + pool, + blockchain, + project, + fee, + time, + main_token, + main_token_symbol, + paired_token, + paired_token_symbol, + main_token_reserve, + paired_token_reserve, + main_token_usd_price, + paired_token_usd_price, + trading_volume +from all_metrics + diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/scroll/lido_liquidity_scroll_nuri_pools.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/scroll/lido_liquidity_scroll_nuri_pools.sql new file mode 100644 index 00000000000..da3e364afd4 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/scroll/lido_liquidity_scroll_nuri_pools.sql @@ -0,0 +1,276 @@ +{{ config( + schema='lido_liquidity_scroll', + alias = 'nuri_pools', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool', 'time'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.time')], + post_hook='{{ expose_spells(blockchains = \'["scroll"]\', + spell_type = "project", + spell_name = "lido_liquidity", + contributors = \'["pipistrella"]\') }}' + ) +}} + +{% set project_start_date = '2024-05-15' %} + +with pools as ( +select pool AS address, + 'scroll' AS blockchain, + 'nuri' AS project, + * +from {{source('nuri_scroll','ClPoolFactory_evt_PoolCreated')}} +where (token0 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 + OR token1 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32) +) + +, tokens as ( + select distinct token + from ( + select token0 as token + from {{source('nuri_scroll','ClPoolFactory_evt_PoolCreated')}} + where token1 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 + union all + select token1 + from {{source('nuri_scroll','ClPoolFactory_evt_PoolCreated')}} + where token0 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 + union all + select 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 + ) t + ) + + , tokens_prices_daily as ( +select distinct + DATE_TRUNC('day', minute) AS time, + contract_address AS token, + symbol, + decimals, + AVG(price) AS price +FROM {{source('prices','usd')}} p +{% if not is_incremental() %} +WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' +{% else %} +WHERE {{ incremental_predicate('p.minute') }} +{% endif %} + +and date_trunc('day', minute) < current_date +and blockchain = 'scroll' +and contract_address IN (select token from tokens) +group by 1,2,3,4 +union all +select distinct + DATE_TRUNC('day', minute), + contract_address AS token, + symbol, + decimals, + LAST_VALUE(price) OVER (PARTITION BY DATE_TRUNC('day', minute),contract_address ORDER BY minute NULLS FIRST range BETWEEN UNBOUNDED preceding AND UNBOUNDED following) AS price + FROM + {{source('prices','usd')}} + WHERE + DATE_TRUNC('day', minute) = current_date + and blockchain = 'scroll' + and contract_address IN (select token from tokens) + ) + + , wsteth_prices_hourly AS ( + SELECT distinct + DATE_TRUNC('hour', minute) time, + contract_address as token, + symbol, + decimals, + last_value(price) over (partition by DATE_TRUNC('hour', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and blockchain = 'scroll' and contract_address = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 + +) + +, wsteth_prices_hourly_with_lead AS ( +select time, + lead(time, 1, date_trunc('hour', now() + interval '1' hour)) over (order by time) as next_time, + price +from wsteth_prices_hourly +) + +, mint_events AS ( + select DATE_TRUNC('day', m.evt_block_time) AS time, + m.contract_address AS pool, + cr.token0, + cr.token1, + SUM(CAST(amount0 AS DOUBLE)) AS amount0, + SUM(CAST(amount1 AS DOUBLE)) AS amount1 + from {{source('nuri_scroll','ClPool_evt_Mint')}} m + left join {{source('nuri_scroll','ClPoolFactory_evt_PoolCreated')}} cr on m.contract_address = cr.pool + join pools on m.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', m.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('m.evt_block_time') }} + {% endif %} + group by 1,2,3,4 + ) + + , collect_events as ( + select DATE_TRUNC('day', b.evt_block_time) AS time, + b.contract_address AS pool, + cr.token0, + cr.token1, + (-1)*SUM(CAST(amount0 AS DOUBLE)) AS amount0, + (-1)*SUM(CAST(amount1 AS DOUBLE)) AS amount1 + from {{source('nuri_scroll','ClPool_evt_Collect')}} b + left join {{source('nuri_scroll','ClPoolFactory_evt_PoolCreated')}} cr on b.contract_address = cr.pool + join pools on b.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', b.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('b.evt_block_time') }} + {% endif %} + group by 1,2,3,4 + + ) + +, swap_events as ( + select DATE_TRUNC('day', s.evt_block_time) AS time, + s.contract_address AS pool, + cr.token0, + cr.token1, + SUM(CAST(amount0 AS DOUBLE)) AS amount0, + SUM(CAST(amount1 AS DOUBLE)) AS amount1 + from {{source('nuri_scroll','ClPool_evt_Swap')}} s + left join {{source('nuri_scroll','ClPoolFactory_evt_PoolCreated')}} cr on s.contract_address = cr.pool + join pools on s.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', s.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('s.evt_block_time') }} + {% endif %} + group by 1,2,3,4 + +) + + , daily_delta_balance AS ( + +select time, pool, token0, token1, sum(amount0) as amount0, sum(amount1) as amount1 +from ( +select time, pool,token0, token1, amount0, amount1 +from mint_events + +union all + +select time, pool,token0, token1, amount0, amount1 +from swap_events + +union all + +select time, pool,token0, token1, amount0, amount1 +from collect_events + +) group by 1,2,3,4 +) + +, daily_delta_balance_with_lead AS ( +select time, pool, token0, token1, amount0, amount1, +lead(time, 1, now()) over (partition by pool order by time) as next_time +from daily_delta_balance +) + + +, pool_liquidity as ( +SELECT b.time, + b.pool, + token0, + token1, + SUM(amount0) AS amount0, + SUM(amount1) AS amount1 +FROM daily_delta_balance_with_lead b +GROUP BY 1,2,3,4 +) + +, swap_events_hourly as ( + select DATE_TRUNC('hour', s.evt_block_time) AS time, + s.contract_address AS pool, + sum(case when cr.token0 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 then CAST(amount0 AS DOUBLE) + else CAST(amount1 AS DOUBLE) end) as wsteth_amount + from {{source('nuri_scroll','ClPool_evt_Swap')}} s + left join {{source('nuri_scroll','ClPoolFactory_evt_PoolCreated')}} cr on s.contract_address = cr.pool + join pools on s.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', s.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('s.evt_block_time') }} + {% endif %} + +group by 1,2 +) + +, trading_volume_hourly AS ( + SELECT + s.time, + pool, + wsteth_amount, + p.price, + COALESCE((p.price * wsteth_amount) / CAST(POWER(10, 18) AS DOUBLE), 0) AS volume + FROM + swap_events_hourly AS s + LEFT JOIN wsteth_prices_hourly_with_lead AS p ON s.time >= p.time + AND s.time < p.next_time + ) + +, trading_volume AS ( + SELECT DISTINCT + DATE_TRUNC('day', time) AS time, + pool, + SUM(volume) AS volume + FROM trading_volume_hourly + GROUP BY 1, 2 + ) + +, all_metrics AS ( + SELECT + l.pool, + pools.blockchain, + pools.project, + cast(l.time as date) as time, + CASE WHEN l.token0 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 THEN l.token0 ELSE l.token1 END AS main_token, + CASE WHEN l.token0 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 THEN p0.symbol ELSE p1.symbol END AS main_token_symbol, + CASE WHEN l.token0 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 THEN l.token1 ELSE l.token0 END AS paired_token, + CASE WHEN l.token0 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 THEN p1.symbol ELSE p0.symbol END AS paired_token_symbol, + CASE WHEN l.token0 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 THEN amount0/CAST(POWER(10,p0.decimals) as double) ELSE amount1/CAST(POWER(10,p1.decimals) as double) END AS main_token_reserve, + CASE WHEN l.token0 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 THEN amount1/CAST(POWER(10, p1.decimals) as double) ELSE amount0/CAST(POWER(10, p0.decimals) as double) END AS paired_token_reserve, + CASE WHEN l.token0 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 THEN p0.price ELSE p1.price END AS main_token_usd_price, + CASE WHEN l.token0 = 0xf610A9dfB7C89644979b4A0f27063E9e7d7Cda32 THEN p1.price ELSE p0.price END AS paired_token_usd_price, + coalesce(volume,0) AS trading_volume + FROM + pool_liquidity AS l + LEFT JOIN pools ON l.pool = pools.address + LEFT JOIN tokens AS t0 ON l.token0 = t0.token + LEFT JOIN tokens AS t1 ON l.token1 = t1.token + LEFT JOIN tokens_prices_daily AS p0 ON l.time = p0.time + AND l.token0 = p0.token + LEFT JOIN tokens_prices_daily AS p1 ON l.time = p1.time + AND l.token1 = p1.token + LEFT JOIN trading_volume AS tv ON l.time = tv.time + AND l.pool = tv.pool + ) + + +select blockchain||' '||project||' '||coalesce(paired_token_symbol,'unknown')||':'||main_token_symbol as pool_name, + pool, + blockchain, + project, + time, + main_token, + main_token_symbol, + paired_token, + paired_token_symbol, + main_token_reserve, + paired_token_reserve, + main_token_usd_price, + paired_token_usd_price, + trading_volume +from all_metrics \ No newline at end of file diff --git a/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/zksync/lido_liquidity_zksync_pancakeswap_v3_pools.sql b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/zksync/lido_liquidity_zksync_pancakeswap_v3_pools.sql new file mode 100644 index 00000000000..7dd8cde215b --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/models/_project/lido/liquidity/zksync/lido_liquidity_zksync_pancakeswap_v3_pools.sql @@ -0,0 +1,263 @@ +{{ config( + schema='lido_liquidity_zksync', + alias = 'pancakeswap_v3_pools', + materialized = 'incremental', + file_format = 'delta', + incremental_strategy = 'merge', + unique_key = ['pool', 'time'], + incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.time')], + post_hook='{{ expose_spells(blockchains = \'["zksync"]\', + spell_type = "project", + spell_name = "lido_liquidity", + contributors = \'["pipistrella"]\') }}' + ) +}} + +{% set project_start_date = '2024-01-17' %} + +with + +pools as ( +select pool as address, 'zksync' as blockchain, 'pancakeswap' as project, max(cast(fee as double))/10000 as fee +from {{ source('pancakeswap_v3_zksync','PancakeV3Factory_evt_PoolCreated')}} +where token0 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 or token1 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 +group by 1,2,3 +) + +, tokens as ( +select distinct token as address +from ( +select token1 as token +from {{ source('pancakeswap_v3_zksync','PancakeV3Factory_evt_PoolCreated')}} +where token0 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 +union +select token0 +from {{ source('pancakeswap_v3_zksync','PancakeV3Factory_evt_PoolCreated')}} +where token1 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 +union +select 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 +) t +) + +, tokens_prices_daily AS ( + SELECT distinct + DATE_TRUNC('day', minute) AS time, + contract_address as token, + decimals, + symbol, + avg(price) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and date_trunc('day', minute) < current_date + and blockchain = 'zksync' + and contract_address in (select address from tokens) + group by 1,2,3,4 + union all + SELECT distinct + DATE_TRUNC('day', minute), + contract_address as token, + decimals, + symbol, + last_value(price) over (partition by DATE_TRUNC('day', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} + WHERE date_trunc('day', minute) = current_date + and blockchain = 'zksync' + and contract_address in (select address from tokens) +) + +, tokens_prices_hourly AS ( + select time, + lead(time,1, DATE_TRUNC('hour', now() + interval '1' hour)) over (partition by token order by time) as next_time, + token, price, decimals, symbol + from ( + SELECT distinct + DATE_TRUNC('hour', minute) time, + contract_address as token, + decimals, + symbol, + last_value(price) over (partition by DATE_TRUNC('hour', minute), contract_address ORDER BY minute range between unbounded preceding AND unbounded following) AS price + FROM {{ source('prices', 'usd') }} p + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', p.minute) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('p.minute') }} + {% endif %} + and blockchain = 'zksync' + and contract_address in (select address from tokens) +) p +) + + +, swap_events as ( + select + date_trunc('day', sw.evt_block_time) as time, + sw.contract_address as pool, + cr.token0, cr.token1, + sum(cast(amount0 as DOUBLE)) as amount0, + sum(cast(amount1 as DOUBLE)) as amount1 + + from {{ source('pancakeswap_v3_zksync', 'PancakeV3Pool_evt_Swap') }} sw + left join {{ source('pancakeswap_v3_zksync', 'PancakeV3Factory_evt_PoolCreated') }} cr on sw.contract_address = cr.pool + join pools on sw.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + group by 1,2,3,4 +) + +, mint_events as ( + select + date_trunc('day', mt.evt_block_time) as time, + mt.contract_address as pool, + cr.token0, cr.token1, + sum(cast(amount0 as DOUBLE)) as amount0, + sum(cast(amount1 as DOUBLE)) as amount1 + from {{ source('pancakeswap_v3_zksync', 'PancakeV3Pool_evt_Mint') }} mt + left join {{ source('pancakeswap_v3_zksync', 'PancakeV3Factory_evt_PoolCreated') }} cr on mt.contract_address = cr.pool + join pools on mt.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', mt.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('mt.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + +, burn_events as ( + select + date_trunc('day', bn.evt_block_time) as time, + bn.contract_address as pool, + cr.token0, cr.token1, + (-1)*sum(cast(amount0 as DOUBLE)) as amount0, + (-1)*sum(cast(amount1 as DOUBLE)) as amount1 + from {{ source('pancakeswap_v3_zksync', 'PancakeV3Pool_evt_Burn') }} bn + left join {{ source('pancakeswap_v3_zksync', 'PancakeV3Factory_evt_PoolCreated') }} cr on bn.contract_address = cr.pool + join pools on bn.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', bn.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('bn.evt_block_time') }} + {% endif %} + + group by 1,2,3,4 + +) + + , collect_events AS ( + SELECT + date_trunc('day', c.evt_block_time) as time, + c.contract_address AS pool, + cr.token0, + cr.token1, + (-1) * CAST(amount0 AS DOUBLE) AS amount0, + (-1) * CAST(amount1 AS DOUBLE) AS amount1, + c.evt_tx_hash + FROM + {{source('pancakeswap_v3_zksync','PancakeV3Pool_evt_Collect')}} AS c + LEFT JOIN {{source('pancakeswap_v3_zksync','PancakeV3Factory_evt_PoolCreated')}} AS cr ON c.contract_address = cr.pool + join pools on c.contract_address = pools.address + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', c.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('c.evt_block_time') }} + {% endif %} + + ) + + +, daily_delta_balance as ( + select time, pool, token0, token1, sum(coalesce(amount0, 0)) as amount0, sum(coalesce(amount1, 0)) as amount1 + from ( + select time, pool, token0, token1, amount0, amount1 + from swap_events + union all + select time, pool, token0, token1, amount0, amount1 + from mint_events + union all + select time, pool, token0, token1, amount0, amount1 + from collect_events + ) balance + group by 1,2,3,4 +) + +, pool_liquidity as ( + select time, + pool, + token0, + token1, + sum(amount0) as amount0, + sum(amount1) as amount1 + from daily_delta_balance + group by 1,2,3,4 +) + + +, swap_events_hourly as ( + select hour, pool, token0, token1, sum(amount0) as amount0, sum(amount1) as amount1 from ( + select + date_trunc('hour', sw.evt_block_time) as hour, + sw.contract_address as pool, + cr.token0, cr.token1, + coalesce(sum(cast(abs(amount0) as DOUBLE)),0) as amount0, + coalesce(sum(cast(abs(amount1) as DOUBLE)),0) as amount1 + + from {{source('pancakeswap_v3_zksync','PancakeV3Pool_evt_Swap')}} sw + left join {{source('pancakeswap_v3_zksync','PancakeV3Factory_evt_PoolCreated')}} cr on sw.contract_address = cr.pool + {% if not is_incremental() %} + WHERE DATE_TRUNC('day', sw.evt_block_time) >= DATE '{{ project_start_date }}' + {% else %} + WHERE {{ incremental_predicate('sw.evt_block_time') }} + {% endif %} + and sw.contract_address in (select address from pools) + group by 1,2,3,4 + + ) a group by 1,2,3,4 +) + +, trading_volume_hourly as ( + select hour as time, pool, token0, amount0, p.price, coalesce(p.price*amount0/power(10, p.decimals),0) as volume + from swap_events_hourly s + left join tokens t on s.token0 = t.address + left join tokens_prices_hourly p on s.hour >= p.time and s.hour < p.next_time and s.token0 = p.token + +) + +, trading_volume as ( +select distinct date_trunc('day', time) as time, pool, sum(volume) as volume +from trading_volume_hourly +group by 1,2 +) + +, all_metrics as ( +select l.pool, pools.blockchain, pools.project, pools.fee, cast(l.time as date) as time, + case when token0 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 then token0 else token1 end main_token, + case when token0 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 then p0.symbol else p1.symbol end main_token_symbol, + case when token0 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 then token1 else token0 end paired_token, + case when token0 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 then p1.symbol else p0.symbol end paired_token_symbol, + case when token0 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 then amount0/power(10, p0.decimals) else amount1/power(10, p1.decimals) end main_token_reserve, + case when token0 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 then amount1/power(10, p1.decimals) else amount0/power(10, p0.decimals) end paired_token_reserve, + case when token0 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 then p0.price else p1.price end as main_token_usd_price, + case when token0 = 0x703b52F2b28fEbcB60E1372858AF5b18849FE867 then p1.price else p0.price end as paired_token_usd_price, + volume as trading_volume +from pool_liquidity l +left join pools on l.pool = pools.address +left join tokens t0 on l.token0 = t0.address +left join tokens t1 on l.token1 = t1.address +left join tokens_prices_daily p0 on l.time = p0.time and l.token0 = p0.token +left join tokens_prices_daily p1 on l.time = p1.time and l.token1 = p1.token +left join trading_volume tv on l.time = tv.time and l.pool = tv.pool +) + + + +select blockchain||' '||project||' '||COALESCE(paired_token_symbol, 'unknown')||':'||main_token_symbol||' '||format('%,.3f',round(coalesce(fee,0),4)) as pool_name,* +from all_metrics + diff --git a/sources/lido/liquidity/arbitrum/lido_liquidity_arbitrum_sources.yml b/sources/lido/liquidity/arbitrum/lido_liquidity_arbitrum_sources.yml index 7a969902440..c9365926437 100644 --- a/sources/lido/liquidity/arbitrum/lido_liquidity_arbitrum_sources.yml +++ b/sources/lido/liquidity/arbitrum/lido_liquidity_arbitrum_sources.yml @@ -54,5 +54,11 @@ sources: tables: - name: RamsesV2Pool_evt_Mint - name: RamsesV2Pool_evt_Collect - + + - name: pancakeswap_v3_arbitrum + description: "Arbitrum decoded tables related to Pancake v3 DEX pools contracts" + tables: + - name: PancakeV3Pool_evt_Mint + - name: PancakeV3Pool_evt_Collect + - name: PancakeV3Pool_evt_Burn \ No newline at end of file diff --git a/sources/lido/liquidity/base/lido_liquidity_base_sources.yml b/sources/lido/liquidity/base/lido_liquidity_base_sources.yml index 1423f79a684..b78cef4c12a 100644 --- a/sources/lido/liquidity/base/lido_liquidity_base_sources.yml +++ b/sources/lido/liquidity/base/lido_liquidity_base_sources.yml @@ -32,6 +32,19 @@ sources: - name: UniswapV3Pool_evt_Collect - name: UniswapV3Pool_evt_Burn + - name: pancakeswap_v3_base + description: "Base decoded tables related to Pancake v3 contract" + tables: + - name: PancakeV3Pool_evt_Mint + - name: PancakeV3Pool_evt_Collect + - name: PancakeV3Pool_evt_Burn + + - name: maverick_v2_base + description: "Base decoded tables related to Maverick v2 contract" + tables: + - name: V2Pool_evt_PoolAddLiquidity + - name: V2Pool_evt_PoolRemoveLiquidity + diff --git a/sources/lido/liquidity/bnb/lido_liquidity_bnb_sources.yml b/sources/lido/liquidity/bnb/lido_liquidity_bnb_sources.yml new file mode 100644 index 00000000000..66c7472a5d9 --- /dev/null +++ b/sources/lido/liquidity/bnb/lido_liquidity_bnb_sources.yml @@ -0,0 +1,22 @@ +version: 2 + +sources: + - name: pancakeswap_v3_bnb + description: "BNB decoded tables related to Pancake V3 contracts" + tables: + - name: PancakeV3Pool_evt_Mint + - name: PancakeV3Pool_evt_Burn + - name: PancakeV3Pool_evt_Collect + + - name: thena_fi_bnb + description: "BNB decoded tables related to Thena DEX contracts" + tables: + - name: PairFactory_CL_call_createPool + + - name: thena_bnb + description: "BNB decoded tables related to Thena Algebra pools contracts" + tables: + - name: AlgebraPool_evt_Mint + - name: AlgebraPool_evt_Burn + + diff --git a/sources/lido/liquidity/ethereum/lido_liquidity_ethereum_sources.yml b/sources/lido/liquidity/ethereum/lido_liquidity_ethereum_sources.yml index e525e183b08..5ada5e73153 100644 --- a/sources/lido/liquidity/ethereum/lido_liquidity_ethereum_sources.yml +++ b/sources/lido/liquidity/ethereum/lido_liquidity_ethereum_sources.yml @@ -74,4 +74,10 @@ sources: - name: SolidlyV3Factory_evt_PoolCreated - name: SolidlyV3Pool_evt_Swap - name: SolidlyV3Pool_evt_Mint - - name: SolidlyV3Pool_evt_Collect \ No newline at end of file + - name: SolidlyV3Pool_evt_Collect + + - name: puffer_ethereum + description: "Ethereum decoded tables related to Curve pufETH:wstETH pool contract" + tables: + - name: CurveStableSwapNG_evt_TokenExchange + \ No newline at end of file diff --git a/sources/lido/liquidity/linea/lido_liquidity_linea_sources.yml b/sources/lido/liquidity/linea/lido_liquidity_linea_sources.yml index 6cc0828b7d1..79c8a0dff24 100644 --- a/sources/lido/liquidity/linea/lido_liquidity_linea_sources.yml +++ b/sources/lido/liquidity/linea/lido_liquidity_linea_sources.yml @@ -9,3 +9,8 @@ sources: - name: SyncSwapClassicPool_evt_Burn - name: SyncSwapClassicPool_evt_Swap + - name: lynex_linea + description: "Linea decoded tables related to Lynex contract" + tables: + - name: AlgebraPool_evt_Mint + - name: AlgebraPool_evt_Burn diff --git a/sources/lido/liquidity/scroll/lido_liquidity_scroll_sources.yml b/sources/lido/liquidity/scroll/lido_liquidity_scroll_sources.yml index 9cc0aa1b821..d84e8137ff9 100644 --- a/sources/lido/liquidity/scroll/lido_liquidity_scroll_sources.yml +++ b/sources/lido/liquidity/scroll/lido_liquidity_scroll_sources.yml @@ -12,3 +12,15 @@ sources: tables: - name: ZebraV2Pool_evt_Mint - name: ZebraV2Pool_evt_Burn + + - name: maverick_v2_scroll + description: "Scroll decoded tables related to Maveric v2 contract" + tables: + - name: V2Pool_evt_PoolAddLiquidity + - name: V2Pool_evt_PoolRemoveLiquidity + + - name: nuri_scroll + description: "Scroll decoded tables related to Nuri DEX contract" + tables: + - name: ClPool_evt_Mint + - name: ClPool_evt_Collect \ No newline at end of file diff --git a/sources/lido/liquidity/zksync/lido_liquidity_zksync_sources.yml b/sources/lido/liquidity/zksync/lido_liquidity_zksync_sources.yml index a97224dd1e8..a5837f74ec1 100644 --- a/sources/lido/liquidity/zksync/lido_liquidity_zksync_sources.yml +++ b/sources/lido/liquidity/zksync/lido_liquidity_zksync_sources.yml @@ -19,4 +19,9 @@ sources: - name: pool_call_addLiquidity - name: pool_call_removeLiquidity - + - name: pancakeswap_v3_zksync + description: "Zksync decoded tables related to Pancake V3 contracts" + tables: + - name: PancakeV3Pool_evt_Mint + - name: PancakeV3Pool_evt_Collect + - name: PancakeV3Pool_evt_Burn From d37a584cfce51e362ee58dd172071750fcd4614e Mon Sep 17 00:00:00 2001 From: hildobby Date: Wed, 2 Oct 2024 18:08:40 +0200 Subject: [PATCH 57/59] Rework `addresses_events.first_funded_by` + make a crosschain version (#6052) * rework first_funded_by + make a crosschain version * fixes * fix * fix * fix * fix * fixes * fix * fix * update seed * fix * fix * fix * fix * fix * fix * undo btc change * fix * fix * fixes * more to hourly spellbook * fix * fi * fixes * fix * fix * exclude zksync from prod * add NOW() - `3` month filter for ci tests * also filter bitcoin and solana * change downstream spells to refs * fix * remove block_time filters * cleanup files, remove dupe tests * deprecate goerli * merge crosschain spells into 1 --------- Co-authored-by: jeff-dude Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- .../addresses_events_first_funded_by.sql | 23 ------ .../addresses_events_blast_first_activity.sql | 37 --------- ...addresses_events_blast_first_funded_by.sql | 14 ---- .../blast/addresses_events_blast_schema.yml | 79 ------------------- ...addresses_events_mantle_first_activity.sql | 37 --------- ...ddresses_events_mantle_first_funded_by.sql | 14 ---- .../mantle/addresses_events_mantle_schema.yml | 79 ------------------- .../addresses_events_schema.yml | 31 -------- ...resses_events_testnets_first_funded_by.sql | 21 ----- ...events_testnets_goerli_first_funded_by.sql | 31 -------- ...ddresses_events_testnets_goerli_schema.yml | 39 --------- .../addresses_events_first_activity.sql | 0 .../addresses_events_first_funded_by.sql | 23 ++++++ .../addresses_events_first_activity.sql | 0 .../addresses_events_first_funded_by.sql | 53 ++++++++----- .../addresses_events_schema.yml | 24 ++++-- ...dresses_events_arbitrum_first_activity.sql | 0 ...resses_events_arbitrum_first_funded_by.sql | 7 +- .../addresses_events_arbitrum_schema.yml | 6 ++ ...sses_events_avalanche_c_first_activity.sql | 0 ...ses_events_avalanche_c_first_funded_by.sql | 7 +- .../addresses_events_avalanche_c_schema.yml | 2 + .../addresses_events_base_first_activity.sql | 0 .../addresses_events_base_first_funded_by.sql | 7 +- .../base/addresses_events_base_schema.yml | 6 ++ ...dresses_events_bitcoin_first_funded_by.sql | 0 .../addresses_events_bitcoin_schema.yml | 2 + .../addresses_events_bnb_first_activity.sql | 0 .../addresses_events_bnb_first_funded_by.sql | 7 +- .../bnb/addresses_events_bnb_schema.yml | 2 + .../addresses_events_celo_first_activity.sql | 0 .../addresses_events_celo_first_funded_by.sql | 7 +- .../celo/addresses_events_celo_schema.yml | 2 + ...dresses_events_ethereum_first_activity.sql | 0 ...resses_events_ethereum_first_funded_by.sql | 7 +- .../addresses_events_ethereum_schema.yml | 6 ++ ...addresses_events_fantom_first_activity.sql | 0 ...ddresses_events_fantom_first_funded_by.sql | 7 +- .../fantom/addresses_events_fantom_schema.yml | 2 + ...addresses_events_gnosis_first_activity.sql | 0 ...ddresses_events_gnosis_first_funded_by.sql | 7 +- .../gnosis/addresses_events_gnosis_schema.yml | 2 + .../addresses_events_linea_first_activity.sql | 0 ...addresses_events_linea_first_funded_by.sql | 7 +- .../linea/addresses_events_linea_schema.yml | 6 ++ ...dresses_events_optimism_first_activity.sql | 0 ...resses_events_optimism_first_funded_by.sql | 7 +- .../addresses_events_optimism_first_path.sql | 2 +- .../addresses_events_optimism_schema.yml | 6 ++ ...ddresses_events_polygon_first_activity.sql | 0 ...dresses_events_polygon_first_funded_by.sql | 7 +- .../addresses_events_polygon_schema.yml | 2 + ...addresses_events_scroll_first_activity.sql | 0 ...ddresses_events_scroll_first_funded_by.sql | 7 +- .../scroll/addresses_events_scroll_schema.yml | 8 +- ...ddresses_events_solana_first_funded_by.sql | 0 .../solana/addresses_events_solana_schema.yml | 2 + .../addresses_events_zkevm_first_activity.sql | 0 ...addresses_events_zkevm_first_funded_by.sql | 7 +- .../zkevm/addresses_events_zkevm_schema.yml | 6 ++ ...addresses_events_zksync_first_activity.sql | 0 ...ddresses_events_zksync_first_funded_by.sql | 8 +- .../zksync/addresses_events_zksync_schema.yml | 6 ++ .../addresses_events_zora_first_activity.sql | 0 .../addresses_events_zora_first_funded_by.sql | 7 +- .../zora/addresses_events_zora_schema.yml | 6 ++ .../_sector}/addresses_events/_schema.yml | 0 .../addresses_events/first_activity_seed.csv | 0 .../addresses_events/first_funded_by_seed.csv | 4 +- .../first_funded_by_seed_bitcoin.csv | 0 .../first_funded_by_seed_solana.csv | 0 .../daily_spellbook/_sources.yml | 1 + .../_subprojects_outputs/tokens/transfers.yml | 4 +- 73 files changed, 229 insertions(+), 465 deletions(-) delete mode 100644 dbt_subprojects/daily_spellbook/macros/sector/addresses_events/addresses_events_first_funded_by.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_first_activity.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_first_funded_by.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_schema.yml delete mode 100644 dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_first_activity.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_first_funded_by.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_schema.yml delete mode 100644 dbt_subprojects/daily_spellbook/models/addresses_events_testnets/addresses_events_schema.yml delete mode 100644 dbt_subprojects/daily_spellbook/models/addresses_events_testnets/addresses_events_testnets_first_funded_by.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/addresses_events_testnets/goerli/addresses_events_testnets_goerli_first_funded_by.sql delete mode 100644 dbt_subprojects/daily_spellbook/models/addresses_events_testnets/goerli/addresses_events_testnets_goerli_schema.yml rename dbt_subprojects/{daily_spellbook => hourly_spellbook}/macros/sector/addresses_events/addresses_events_first_activity.sql (100%) create mode 100644 dbt_subprojects/hourly_spellbook/macros/sector/addresses_events/addresses_events_first_funded_by.sql rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/addresses_events_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/addresses_events_first_funded_by.sql (51%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/addresses_events_schema.yml (70%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/arbitrum/addresses_events_arbitrum_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/arbitrum/addresses_events_arbitrum_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/arbitrum/addresses_events_arbitrum_schema.yml (89%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/avalanche_c/addresses_events_avalanche_c_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/avalanche_c/addresses_events_avalanche_c_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/avalanche_c/addresses_events_avalanche_c_schema.yml (96%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/base/addresses_events_base_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/base/addresses_events_base_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/base/addresses_events_base_schema.yml (89%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/bitcoin/addresses_events_bitcoin_first_funded_by.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/bitcoin/addresses_events_bitcoin_schema.yml (92%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/bnb/addresses_events_bnb_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/bnb/addresses_events_bnb_first_funded_by.sql (57%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/bnb/addresses_events_bnb_schema.yml (96%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/celo/addresses_events_celo_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/celo/addresses_events_celo_first_funded_by.sql (57%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/celo/addresses_events_celo_schema.yml (92%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/ethereum/addresses_events_ethereum_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/ethereum/addresses_events_ethereum_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/ethereum/addresses_events_ethereum_schema.yml (89%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/fantom/addresses_events_fantom_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/fantom/addresses_events_fantom_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/fantom/addresses_events_fantom_schema.yml (96%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/gnosis/addresses_events_gnosis_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/gnosis/addresses_events_gnosis_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/gnosis/addresses_events_gnosis_schema.yml (96%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/linea/addresses_events_linea_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/linea/addresses_events_linea_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/linea/addresses_events_linea_schema.yml (89%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/optimism/addresses_events_optimism_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/optimism/addresses_events_optimism_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/optimism/addresses_events_optimism_first_path.sql (98%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/optimism/addresses_events_optimism_schema.yml (92%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/polygon/addresses_events_polygon_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/polygon/addresses_events_polygon_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/polygon/addresses_events_polygon_schema.yml (96%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/scroll/addresses_events_scroll_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/scroll/addresses_events_scroll_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/scroll/addresses_events_scroll_schema.yml (88%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/solana/addresses_events_solana_first_funded_by.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/solana/addresses_events_solana_schema.yml (92%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/zkevm/addresses_events_zkevm_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/zkevm/addresses_events_zkevm_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/zkevm/addresses_events_zkevm_schema.yml (89%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/zksync/addresses_events_zksync_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/zksync/addresses_events_zksync_first_funded_by.sql (52%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/zksync/addresses_events_zksync_schema.yml (89%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/zora/addresses_events_zora_first_activity.sql (100%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/zora/addresses_events_zora_first_funded_by.sql (56%) rename dbt_subprojects/{daily_spellbook/models => hourly_spellbook/models/_sector}/addresses_events/zora/addresses_events_zora_schema.yml (89%) rename dbt_subprojects/{daily_spellbook/seeds => hourly_spellbook/seeds/_sector}/addresses_events/_schema.yml (100%) rename dbt_subprojects/{daily_spellbook/seeds => hourly_spellbook/seeds/_sector}/addresses_events/first_activity_seed.csv (100%) rename dbt_subprojects/{daily_spellbook/seeds => hourly_spellbook/seeds/_sector}/addresses_events/first_funded_by_seed.csv (91%) rename dbt_subprojects/{daily_spellbook/seeds => hourly_spellbook/seeds/_sector}/addresses_events/first_funded_by_seed_bitcoin.csv (100%) rename dbt_subprojects/{daily_spellbook/seeds => hourly_spellbook/seeds/_sector}/addresses_events/first_funded_by_seed_solana.csv (100%) diff --git a/dbt_subprojects/daily_spellbook/macros/sector/addresses_events/addresses_events_first_funded_by.sql b/dbt_subprojects/daily_spellbook/macros/sector/addresses_events/addresses_events_first_funded_by.sql deleted file mode 100644 index 5af330660da..00000000000 --- a/dbt_subprojects/daily_spellbook/macros/sector/addresses_events/addresses_events_first_funded_by.sql +++ /dev/null @@ -1,23 +0,0 @@ -{% macro addresses_events_first_funded_by(blockchain) %} - -SELECT -'{{blockchain}}' as blockchain -, et.to AS address -, MIN_BY(et."from", et.block_number) AS first_funded_by -, MIN(et.block_time) AS block_time -, MIN(et.block_number) AS block_number -, MIN_BY(et.tx_hash, et.block_number) AS tx_hash -FROM {{ source( blockchain , 'traces') }} et -{% if is_incremental() %} -LEFT JOIN {{this}} ffb ON et.to = ffb.address WHERE ffb.address IS NULL -{% else %} -WHERE 1 = 1 -{% endif %} -AND et.success -AND (et.call_type NOT IN ('delegatecall', 'callcode', 'staticcall') OR et.call_type IS NULL) -AND CAST(et.value AS double) > 0 -{% if is_incremental() %} -AND et.block_time >= date_trunc('day', now() - interval '7' day) -{% endif %} -GROUP BY et.to -{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_first_activity.sql b/dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_first_activity.sql deleted file mode 100644 index 3ea6f9919c6..00000000000 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_first_activity.sql +++ /dev/null @@ -1,37 +0,0 @@ -{{ config( - schema = 'addresses_events_blast' - , alias = 'first_activity' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'append' - , unique_key = ['address'] - ) -}} - -SELECT 'blast' AS blockchain -, et."from" AS address -, MIN_BY(et."to", et.block_number) AS first_activity_to -, MIN(et.block_time) AS first_block_time -, MIN(et.block_number) AS first_block_number -, MIN_BY(et.hash, et.block_number) AS first_tx_hash -, MIN_BY(COALESCE(sig.function, CAST((bytearray_substring(et.data, 1, 4)) as VARCHAR)), et.block_number) as first_function -, MIN_BY(et.value/1e18, et.block_number) as first_{{native_symbol}}_transferred -FROM -{{ source('blast', 'transactions') }} et -LEFT JOIN ( - SELECT - DISTINCT id, - split_part(signature,'(',1) as function - FROM - {{ source('abi', 'signatures') }} - where type = 'function_call' - AND id NOT IN (0x09779838, 0x00000000) -- for some weird reason these have duplicates functions -) sig - ON sig.id = bytearray_substring(et.data, 1, 4) -{% if is_incremental() %} -LEFT JOIN {{this}} ffb ON et."from" = ffb.address -WHERE ffb.address IS NULL -AND et.block_time >= date_trunc('day', now() - interval '7' day) -{% endif %} - -GROUP BY et."from" diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_first_funded_by.sql b/dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_first_funded_by.sql deleted file mode 100644 index 16bd0bca594..00000000000 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_first_funded_by.sql +++ /dev/null @@ -1,14 +0,0 @@ -{{ config( - schema = 'addresses_events_blast' - , alias = 'first_funded_by' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'append' - , unique_key = ['address'] - ) -}} - - -{{addresses_events_first_funded_by( - blockchain='blast' -)}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_schema.yml b/dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_schema.yml deleted file mode 100644 index 75c38b79f16..00000000000 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/blast/addresses_events_blast_schema.yml +++ /dev/null @@ -1,79 +0,0 @@ -version: 2 - -models: - - name: addresses_events_blast_first_funded_by - meta: - blockchain: blast - sector: addresses_events - project: addresses - contributors: hildobby, lgingerich - config: - tags: ['table', 'funded', 'addresses_events', 'blast'] - description: "Table showing who first funded each blast address in ETH" - tests: - - check_seed: - seed_file: ref('first_funded_by_seed') - filter: - blockchain: blast - match_columns: - - blockchain - - address - check_columns: - - first_funded_by - - block_number - - tx_hash - columns: - - name: blockchain - description: "Blockchain" - - name: address - description: "Concerned blast address" - tests: - - unique - - name: first_funded_by - description: "Which blast address first funded the address with ETH" - - name: block_time - description: "The block time on which the address was first funded with ETH" - - name: block_number - description: "The block number on which the address was first funded with ETH" - - name: tx_hash - description: "The transaction hash on which the address was first funded with ETH" - - - name: addresses_events_blast_first_activity - meta: - blockchain: blast - sector: addresses_events - project: addresses - contributors: hildobby - config: - tags: ['table', 'activity', 'addresses_events', 'blast'] - description: "Table showing first activity of each blast Mainnet address" - tests: - - check_seed: - seed_file: ref('first_activity_seed') - filter: - blockchain: blast - match_columns: - - address - check_columns: - - first_activity_to - - first_block_number - - first_tx_hash - columns: - - name: blockchain - description: "Blockchain" - - name: address - description: "Concerned blast Mainnet address" - tests: - - unique - - name: first_activity_to - description: "First transaction activity to address" - - name: first_block_time - description: "The block time on which the address made it's first activity" - - name: first_block_number - description: "The block number on which the address made it's first activity" - - name: first_tx_hash - description: "The transaction hash on which the address made it's first activity" - - name: first_function - description: "first function called by address" - - name: first_eth_transferred - description: "ETH transferred in transaction" diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_first_activity.sql b/dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_first_activity.sql deleted file mode 100644 index 34143da750f..00000000000 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_first_activity.sql +++ /dev/null @@ -1,37 +0,0 @@ -{{ config( - schema = 'addresses_events_mantle' - , alias = 'first_activity' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'append' - , unique_key = ['address'] - ) -}} - -SELECT 'mantle' AS blockchain -, et."from" AS address -, MIN_BY(et."to", et.block_number) AS first_activity_to -, MIN(et.block_time) AS first_block_time -, MIN(et.block_number) AS first_block_number -, MIN_BY(et.hash, et.block_number) AS first_tx_hash -, MIN_BY(COALESCE(sig.function, CAST((bytearray_substring(et.data, 1, 4)) as VARCHAR)), et.block_number) as first_function -, MIN_BY(et.value/1e18, et.block_number) as first_{{native_symbol}}_transferred -FROM -{{ source('mantle', 'transactions') }} et -LEFT JOIN ( - SELECT - DISTINCT id, - split_part(signature,'(',1) as function - FROM - {{ source('abi', 'signatures') }} - where type = 'function_call' - AND id NOT IN (0x09779838, 0x00000000) -- for some weird reason these have duplicates functions -) sig - ON sig.id = bytearray_substring(et.data, 1, 4) -{% if is_incremental() %} -LEFT JOIN {{this}} ffb ON et."from" = ffb.address -WHERE ffb.address IS NULL -AND et.block_time >= date_trunc('day', now() - interval '7' day) -{% endif %} - -GROUP BY et."from" diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_first_funded_by.sql b/dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_first_funded_by.sql deleted file mode 100644 index ab5d5699dd7..00000000000 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_first_funded_by.sql +++ /dev/null @@ -1,14 +0,0 @@ -{{ config( - schema = 'addresses_events_mantle' - , alias = 'first_funded_by' - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'append' - , unique_key = ['address'] - ) -}} - - -{{addresses_events_first_funded_by( - blockchain='mantle' -)}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_schema.yml b/dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_schema.yml deleted file mode 100644 index a1dbb96d762..00000000000 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/mantle/addresses_events_mantle_schema.yml +++ /dev/null @@ -1,79 +0,0 @@ -version: 2 - -models: - - name: addresses_events_mantle_first_funded_by - meta: - blockchain: mantle - sector: addresses_events - project: addresses - contributors: hildobby - config: - tags: ['table', 'funded', 'addresses_events', 'mantle'] - description: "Table showing who first funded each Linea address in ETH" - tests: - - check_seed: - seed_file: ref('first_funded_by_seed') - filter: - blockchain: mantle - match_columns: - - blockchain - - address - check_columns: - - first_funded_by - - block_number - - tx_hash - columns: - - name: blockchain - description: "Blockchain" - - name: address - description: "Concerned mantle address" - tests: - - unique - - name: first_funded_by - description: "Which mantle address first funded the address with ETH" - - name: block_time - description: "The block time on which the address was first funded with ETH" - - name: block_number - description: "The block number on which the address was first funded with ETH" - - name: tx_hash - description: "The transaction hash on which the address was first funded with ETH" - - - name: addresses_events_mantle_first_activity - meta: - blockchain: mantle - sector: addresses_events - project: addresses - contributors: hildobby - config: - tags: ['table', 'activity', 'addresses_events', 'mantle'] - description: "Table showing first activity of each mantle Mainnet address" - tests: - - check_seed: - seed_file: ref('first_activity_seed') - filter: - blockchain: mantle - match_columns: - - address - check_columns: - - first_activity_to - - first_block_number - - first_tx_hash - columns: - - name: blockchain - description: "Blockchain" - - name: address - description: "Concerned mantle Mainnet address" - tests: - - unique - - name: first_activity_to - description: "First transaction activity to address" - - name: first_block_time - description: "The block time on which the address made it's first activity" - - name: first_block_number - description: "The block number on which the address made it's first activity" - - name: first_tx_hash - description: "The transaction hash on which the address made it's first activity" - - name: first_function - description: "first function called by address" - - name: first_eth_transferred - description: "ETH transferred in transaction" diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/addresses_events_schema.yml b/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/addresses_events_schema.yml deleted file mode 100644 index 10b477b25c9..00000000000 --- a/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/addresses_events_schema.yml +++ /dev/null @@ -1,31 +0,0 @@ -version: 2 - -models: - - name: addresses_events_testnets_first_funded_by - meta: - blockchain: goerli - sector: addresses_events_testnets - project: addresses - contributors: hildobby - config: - tags: ['table', 'funded', 'addresses_events', 'testnets'] - description: "Table showing who first funded each address in its native asset on every testnet chain" - columns: - - &blockchain - name: blockchain - description: "Name of the blockchain" - - &address - name: address - description: "Concerned address" - - &first_funded_by - name: first_funded_by - description: "Which address first funded the address with the native asset on that chain" - - &block_time - name: block_time - description: "The block time on which the address was first funded with the native asset on that chain" - - &block_number - name: block_number - description: "The block number on which the address was first funded with the native asset on that chain" - - &tx_hash - name: tx_hash - description: "The transaction hash on which the address was first funded with the native asset on that chain" \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/addresses_events_testnets_first_funded_by.sql b/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/addresses_events_testnets_first_funded_by.sql deleted file mode 100644 index 2edd95c8de5..00000000000 --- a/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/addresses_events_testnets_first_funded_by.sql +++ /dev/null @@ -1,21 +0,0 @@ -{{ config -( - alias = 'first_funded_by', - schema = 'addresses_events_testnets', - post_hook='{{ expose_spells(\'["goerli"]\', - "sector", - "addresses_events_testnets", - \'["hildobby"]\') }}' -) -}} - -SELECT * -FROM ( - SELECT blockchain - , address - , first_funded_by - , block_time - , block_number - , tx_hash - FROM {{ ref('addresses_events_testnets_goerli_first_funded_by') }} -) diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/goerli/addresses_events_testnets_goerli_first_funded_by.sql b/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/goerli/addresses_events_testnets_goerli_first_funded_by.sql deleted file mode 100644 index 126e4b7ea22..00000000000 --- a/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/goerli/addresses_events_testnets_goerli_first_funded_by.sql +++ /dev/null @@ -1,31 +0,0 @@ -{{ config( - schema = 'addresses_events_testnets_goerli' - , alias = 'first_funded_by' - - , materialized = 'incremental' - , file_format = 'delta' - , incremental_strategy = 'merge' - , unique_key = ['address'] - ) -}} - -SELECT 'goerli' AS blockchain -, et.to AS address -, MIN_BY(et."from", et.block_number) AS first_funded_by -, MIN(et.block_time) AS block_time -, MIN(et.block_number) AS block_number -, MIN_BY(et.tx_hash, et.block_number) AS tx_hash -FROM {{ source('goerli', 'traces') }} et -{% if is_incremental() %} -LEFT JOIN {{this}} ffb ON et.to = ffb.address -WHERE ffb.address IS NULL -{% else %} -WHERE 1 = 1 -{% endif %} -AND et.success -AND (et.call_type NOT IN ('delegatecall', 'callcode', 'staticcall') OR et.call_type IS NULL) -AND CAST(et.value AS double) > 0 -{% if is_incremental() %} -AND et.block_time >= date_trunc('day', now() - interval '7' day) -{% endif %} -GROUP BY et.to \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/goerli/addresses_events_testnets_goerli_schema.yml b/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/goerli/addresses_events_testnets_goerli_schema.yml deleted file mode 100644 index 5a32d245636..00000000000 --- a/dbt_subprojects/daily_spellbook/models/addresses_events_testnets/goerli/addresses_events_testnets_goerli_schema.yml +++ /dev/null @@ -1,39 +0,0 @@ -version: 2 - -models: - - name: addresses_events_testnets_goerli_first_funded_by - meta: - blockchain: goerli - sector: addresses_events_testnets - project: addresses - contributors: hildobby - config: - tags: ['table', 'funded', 'addresses_events', 'goerli'] - description: "Table showing who first funded each Goerli address in ETH" - tests: - - check_seed: - seed_file: ref('first_funded_by_seed') - filter: - blockchain: goerli - match_columns: - - blockchain - - address - check_columns: - - first_funded_by - - block_number - - tx_hash - columns: - - name: blockchain - description: "Blockchain" - - name: address - description: "Concerned Goerli address" - tests: - - unique - - name: first_funded_by - description: "Which Goerli address first funded the address with ETH" - - name: block_time - description: "The block time on which the address was first funded with ETH" - - name: block_number - description: "The block number on which the address was first funded with ETH" - - name: tx_hash - description: "The transaction hash on which the address was first funded with ETH" diff --git a/dbt_subprojects/daily_spellbook/macros/sector/addresses_events/addresses_events_first_activity.sql b/dbt_subprojects/hourly_spellbook/macros/sector/addresses_events/addresses_events_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/macros/sector/addresses_events/addresses_events_first_activity.sql rename to dbt_subprojects/hourly_spellbook/macros/sector/addresses_events/addresses_events_first_activity.sql diff --git a/dbt_subprojects/hourly_spellbook/macros/sector/addresses_events/addresses_events_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/macros/sector/addresses_events/addresses_events_first_funded_by.sql new file mode 100644 index 00000000000..7a21f735e95 --- /dev/null +++ b/dbt_subprojects/hourly_spellbook/macros/sector/addresses_events/addresses_events_first_funded_by.sql @@ -0,0 +1,23 @@ +{% macro addresses_events_first_funded_by(blockchain, token_transfers) %} + + +SELECT '{{blockchain}}' as blockchain +, tt.to AS address +, MIN_BY(tt."from", (tt.block_number, tt.tx_index)) AS first_funded_by +, MIN_BY(tt.tx_from, (tt.block_number, tt.tx_index)) AS first_funding_executed_by +, MIN(tt.block_time) AS block_time +, MIN(tt.block_number) AS block_number +, MIN_BY(tt.tx_hash, (tt.block_number, tt.tx_index)) AS tx_hash +, MIN_BY(tt.tx_index, tt.block_number) AS tx_index +, MIN_BY(tt.unique_key, (tt.block_number, tt.tx_index)) AS unique_key +FROM {{token_transfers}} tt +{% if is_incremental() %} +WHERE {{ incremental_predicate('tt.block_time') }} +AND tt.token_standard = 'native' +AND tt.to NOT IN (SELECT address FROM {{this}}) +{% else %} +WHERE tt.token_standard = 'native' +{% endif %} +GROUP BY tt.to + +{% endmacro %} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/addresses_events_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/addresses_events_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/addresses_events_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/addresses_events_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/addresses_events_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/addresses_events_first_funded_by.sql similarity index 51% rename from dbt_subprojects/daily_spellbook/models/addresses_events/addresses_events_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/addresses_events_first_funded_by.sql index 9961a4d1a2e..ffd24f99e98 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/addresses_events_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/addresses_events_first_funded_by.sql @@ -2,10 +2,10 @@ ( alias = 'first_funded_by', schema = 'addresses_events', - post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "bnb", "ethereum", "fantom", "gnosis", "optimism", "polygon", "celo", "zksync", "zora", "base", "scroll", "mantle", "blast"]\', + post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "bnb", "ethereum", "fantom", "gnosis", "optimism", "polygon", "celo", "zora", "base", "scroll"]\', "sector", "addresses_events", - \'["hildobby", "Henrystats"]\') }}' + \'["hildobby"]\') }}' ) }} @@ -19,28 +19,41 @@ ref('addresses_events_arbitrum_first_funded_by') , ref('addresses_events_optimism_first_funded_by') , ref('addresses_events_polygon_first_funded_by') , ref('addresses_events_celo_first_funded_by') -, ref('addresses_events_zksync_first_funded_by') , ref('addresses_events_zora_first_funded_by') , ref('addresses_events_base_first_funded_by') , ref('addresses_events_scroll_first_funded_by') , ref('addresses_events_zkevm_first_funded_by') , ref('addresses_events_linea_first_funded_by') -, ref('addresses_events_mantle_first_funded_by') -, ref('addresses_events_blast_first_funded_by') ] %} -SELECT * -FROM ( - {% for addresses_events_model in addresses_events_models %} - SELECT blockchain - , address - , first_funded_by - , block_time - , block_number - , tx_hash - FROM {{ addresses_events_model }} - {% if not loop.last %} - UNION ALL - {% endif %} - {% endfor %} -) +WITH joined_data AS ( + SELECT * + FROM ( + {% for addresses_events_model in addresses_events_models %} + SELECT blockchain + , address + , first_funded_by + , first_funding_executed_by + , block_time + , block_number + , tx_hash + , tx_index + FROM {{ addresses_events_model }} + {% if not loop.last %} + UNION ALL + {% endif %} + {% endfor %} + ) + ) + +SELECT MIN_BY(blockchain, block_time) AS blockchain +, address +, MIN_BY(first_funded_by, block_time) AS first_funded_by +, array_distinct(array_agg(blockchain)) AS chains_funded_on +, MIN_BY(first_funding_executed_by, block_time) AS first_funding_executed_by +, MIN(block_time) AS block_time +, MIN(block_number) AS block_number +, MIN_BY(tx_hash, block_time) AS tx_hash +, MIN_BY(tx_index, block_time) AS tx_index +FROM joined_data +GROUP BY address \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/addresses_events_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/addresses_events_schema.yml similarity index 70% rename from dbt_subprojects/daily_spellbook/models/addresses_events/addresses_events_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/addresses_events_schema.yml index b17dd9faf2e..09862de49ff 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/addresses_events_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/addresses_events_schema.yml @@ -1,15 +1,20 @@ version: 2 models: + - name: addresses_events_first_funded_by meta: - blockchain: arbitrum, avalanche_c, bnb, ethereum, fantom, gnosis, optimism, polygon, celo, zksync, base, scroll, zkevm, linea + blockchain: arbitrum, avalanche_c, bnb, ethereum, fantom, gnosis, optimism, polygon, celo, base, scroll, zkevm, linea sector: addresses_events project: addresses - contributors: hildobby, Henrystats + contributors: hildobby config: - tags: ['table', 'funded', 'addresses_events', 'mainnets'] - description: "Table showing who first funded each address in its native asset on every chain" + tags: ['table', 'funded', 'addresses_events', 'mainnets', 'crosschain'] + description: "Table showing what chain an address was first funded on and its details" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - address columns: - &blockchain name: blockchain @@ -20,6 +25,12 @@ models: - &first_funded_by name: first_funded_by description: "Which address first funded the address with the native asset on that chain" + - &chains_funded_on + name: chains_funded_on + description: "Name of all the blockchains it was funded on" + - &first_funding_executed_by + name: first_funding_executed_by + description: "Which address executed the first funding tx" - &block_time name: block_time description: "The block time on which the address was first funded with the native asset on that chain" @@ -29,6 +40,9 @@ models: - &tx_hash name: tx_hash description: "The transaction hash on which the address was first funded with the native asset on that chain" + - &tx_index + name: tx_index + description: "The transaction index within its block on which the address was first funded with the native asset on that chain" - name: addresses_events_first_activity meta: @@ -56,4 +70,4 @@ models: description: "The transaction hash on which the address made it's first activity" - &first_function name: first_function - description: "first function called by address" + description: "first function called by address" \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/arbitrum/addresses_events_arbitrum_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/arbitrum/addresses_events_arbitrum_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/arbitrum/addresses_events_arbitrum_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/arbitrum/addresses_events_arbitrum_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/arbitrum/addresses_events_arbitrum_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/arbitrum/addresses_events_arbitrum_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/arbitrum/addresses_events_arbitrum_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/arbitrum/addresses_events_arbitrum_first_funded_by.sql index 4147d1f7664..640ee4503d5 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/arbitrum/addresses_events_arbitrum_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/arbitrum/addresses_events_arbitrum_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'arbitrum' %} + {{ config( - schema = 'addresses_events_arbitrum' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' @@ -11,5 +13,6 @@ {{addresses_events_first_funded_by( - blockchain='arbitrum' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/arbitrum/addresses_events_arbitrum_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/arbitrum/addresses_events_arbitrum_schema.yml similarity index 89% rename from dbt_subprojects/daily_spellbook/models/addresses_events/arbitrum/addresses_events_arbitrum_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/arbitrum/addresses_events_arbitrum_schema.yml index 50899ebe55c..4f244bcf844 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/arbitrum/addresses_events_arbitrum_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/arbitrum/addresses_events_arbitrum_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned Arbitrum address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which Arbitrum address first funded the address with ETH" - name: block_time @@ -37,6 +39,10 @@ models: description: "The block number on which the address was first funded with ETH" - name: tx_hash description: "The transaction hash on which the address was first funded with ETH" + - name: tx_index + description: "The transaction index within the block on which the address was first funded with ETH" + - name: unique_key + description: "Unique transfer identifier key" - name: addresses_events_arbitrum_first_activity meta: diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/avalanche_c/addresses_events_avalanche_c_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/avalanche_c/addresses_events_avalanche_c_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/avalanche_c/addresses_events_avalanche_c_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/avalanche_c/addresses_events_avalanche_c_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/avalanche_c/addresses_events_avalanche_c_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/avalanche_c/addresses_events_avalanche_c_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/avalanche_c/addresses_events_avalanche_c_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/avalanche_c/addresses_events_avalanche_c_first_funded_by.sql index 362929fceac..4cff982189d 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/avalanche_c/addresses_events_avalanche_c_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/avalanche_c/addresses_events_avalanche_c_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'avalanche_c' %} + {{ config( - schema = 'addresses_events_avalanche_c' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' @@ -11,5 +13,6 @@ {{addresses_events_first_funded_by( - blockchain='avalanche_c' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/avalanche_c/addresses_events_avalanche_c_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/avalanche_c/addresses_events_avalanche_c_schema.yml similarity index 96% rename from dbt_subprojects/daily_spellbook/models/addresses_events/avalanche_c/addresses_events_avalanche_c_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/avalanche_c/addresses_events_avalanche_c_schema.yml index f8c1fd7defe..675ce94fc3a 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/avalanche_c/addresses_events_avalanche_c_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/avalanche_c/addresses_events_avalanche_c_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned Avalanche address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which Avalanche address first funded the address with AVAX" - name: block_time diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/base/addresses_events_base_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/base/addresses_events_base_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/base/addresses_events_base_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/base/addresses_events_base_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/base/addresses_events_base_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/base/addresses_events_base_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/base/addresses_events_base_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/base/addresses_events_base_first_funded_by.sql index eab2fcbefb0..87f4cc81159 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/base/addresses_events_base_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/base/addresses_events_base_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'base' %} + {{ config( - schema = 'addresses_events_base' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' , file_format = 'delta' @@ -10,5 +12,6 @@ {{addresses_events_first_funded_by( - blockchain='base' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/base/addresses_events_base_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/base/addresses_events_base_schema.yml similarity index 89% rename from dbt_subprojects/daily_spellbook/models/addresses_events/base/addresses_events_base_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/base/addresses_events_base_schema.yml index 16a665547a2..916a202b41f 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/base/addresses_events_base_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/base/addresses_events_base_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned base address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which base address first funded the address with ETH" - name: block_time @@ -37,6 +39,10 @@ models: description: "The block number on which the address was first funded with ETH" - name: tx_hash description: "The transaction hash on which the address was first funded with ETH" + - name: tx_index + description: "The transaction index within the block on which the address was first funded with ETH" + - name: unique_key + description: "Unique transfer identifier key" - name: addresses_events_base_first_activity meta: diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/bitcoin/addresses_events_bitcoin_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bitcoin/addresses_events_bitcoin_first_funded_by.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/bitcoin/addresses_events_bitcoin_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bitcoin/addresses_events_bitcoin_first_funded_by.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/bitcoin/addresses_events_bitcoin_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bitcoin/addresses_events_bitcoin_schema.yml similarity index 92% rename from dbt_subprojects/daily_spellbook/models/addresses_events/bitcoin/addresses_events_bitcoin_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bitcoin/addresses_events_bitcoin_schema.yml index 64504a249c3..76daf363213 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/bitcoin/addresses_events_bitcoin_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bitcoin/addresses_events_bitcoin_schema.yml @@ -28,6 +28,8 @@ models: description: "Concerned Bitcoin address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which Bitcoin address first funded the address with BTC" - name: block_time diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/bnb/addresses_events_bnb_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bnb/addresses_events_bnb_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/bnb/addresses_events_bnb_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bnb/addresses_events_bnb_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/bnb/addresses_events_bnb_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bnb/addresses_events_bnb_first_funded_by.sql similarity index 57% rename from dbt_subprojects/daily_spellbook/models/addresses_events/bnb/addresses_events_bnb_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bnb/addresses_events_bnb_first_funded_by.sql index 9fed90aa27e..88a633488aa 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/bnb/addresses_events_bnb_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bnb/addresses_events_bnb_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'bnb' %} + {{ config( - schema = 'addresses_events_bnb' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' @@ -11,5 +13,6 @@ {{addresses_events_first_funded_by( - blockchain='bnb' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/bnb/addresses_events_bnb_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bnb/addresses_events_bnb_schema.yml similarity index 96% rename from dbt_subprojects/daily_spellbook/models/addresses_events/bnb/addresses_events_bnb_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bnb/addresses_events_bnb_schema.yml index fec63938363..08bd45d0613 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/bnb/addresses_events_bnb_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/bnb/addresses_events_bnb_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned BNB address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which BNB address first funded the address with BNB" - name: block_time diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/celo/addresses_events_celo_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/celo/addresses_events_celo_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/celo/addresses_events_celo_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/celo/addresses_events_celo_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/celo/addresses_events_celo_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/celo/addresses_events_celo_first_funded_by.sql similarity index 57% rename from dbt_subprojects/daily_spellbook/models/addresses_events/celo/addresses_events_celo_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/celo/addresses_events_celo_first_funded_by.sql index 2c95be19ccb..cd4fe6c4508 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/celo/addresses_events_celo_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/celo/addresses_events_celo_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'celo' %} + {{ config( - schema = 'addresses_events_celo' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' @@ -11,5 +13,6 @@ {{addresses_events_first_funded_by( - blockchain='celo' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/celo/addresses_events_celo_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/celo/addresses_events_celo_schema.yml similarity index 92% rename from dbt_subprojects/daily_spellbook/models/addresses_events/celo/addresses_events_celo_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/celo/addresses_events_celo_schema.yml index 4471b530e68..76103f8ff91 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/celo/addresses_events_celo_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/celo/addresses_events_celo_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned Celo address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which Celo address first funded the address with CELO" - name: block_time diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/ethereum/addresses_events_ethereum_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/ethereum/addresses_events_ethereum_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/ethereum/addresses_events_ethereum_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/ethereum/addresses_events_ethereum_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/ethereum/addresses_events_ethereum_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/ethereum/addresses_events_ethereum_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/ethereum/addresses_events_ethereum_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/ethereum/addresses_events_ethereum_first_funded_by.sql index 467c7a9d846..f4df9768ee2 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/ethereum/addresses_events_ethereum_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/ethereum/addresses_events_ethereum_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'ethereum' %} + {{ config( - schema = 'addresses_events_ethereum' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' @@ -11,5 +13,6 @@ {{addresses_events_first_funded_by( - blockchain='ethereum' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/ethereum/addresses_events_ethereum_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/ethereum/addresses_events_ethereum_schema.yml similarity index 89% rename from dbt_subprojects/daily_spellbook/models/addresses_events/ethereum/addresses_events_ethereum_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/ethereum/addresses_events_ethereum_schema.yml index 7feb4e8e3c9..20aab914fac 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/ethereum/addresses_events_ethereum_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/ethereum/addresses_events_ethereum_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned Ethereum address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which Ethereum address first funded the address with ETH" - name: block_time @@ -37,6 +39,10 @@ models: description: "The block number on which the address was first funded with ETH" - name: tx_hash description: "The transaction hash on which the address was first funded with ETH" + - name: tx_index + description: "The transaction index within the block on which the address was first funded with ETH" + - name: unique_key + description: "Unique transfer identifier key" - name: addresses_events_ethereum_first_activity meta: diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/fantom/addresses_events_fantom_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/fantom/addresses_events_fantom_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/fantom/addresses_events_fantom_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/fantom/addresses_events_fantom_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/fantom/addresses_events_fantom_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/fantom/addresses_events_fantom_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/fantom/addresses_events_fantom_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/fantom/addresses_events_fantom_first_funded_by.sql index eaa14b364e9..d3051e3ccf1 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/fantom/addresses_events_fantom_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/fantom/addresses_events_fantom_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'fantom' %} + {{ config( - schema = 'addresses_events_fantom' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' @@ -11,5 +13,6 @@ {{addresses_events_first_funded_by( - blockchain='fantom' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/fantom/addresses_events_fantom_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/fantom/addresses_events_fantom_schema.yml similarity index 96% rename from dbt_subprojects/daily_spellbook/models/addresses_events/fantom/addresses_events_fantom_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/fantom/addresses_events_fantom_schema.yml index 02c89931eb6..d7d0a5a58cd 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/fantom/addresses_events_fantom_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/fantom/addresses_events_fantom_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned Fantom address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which Fantom address first funded the address with FTM" - name: block_time diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/gnosis/addresses_events_gnosis_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/gnosis/addresses_events_gnosis_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/gnosis/addresses_events_gnosis_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/gnosis/addresses_events_gnosis_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/gnosis/addresses_events_gnosis_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/gnosis/addresses_events_gnosis_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/gnosis/addresses_events_gnosis_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/gnosis/addresses_events_gnosis_first_funded_by.sql index 1c1ad1e39b5..db8bfcaa248 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/gnosis/addresses_events_gnosis_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/gnosis/addresses_events_gnosis_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'gnosis' %} + {{ config( - schema = 'addresses_events_gnosis' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' @@ -11,5 +13,6 @@ {{addresses_events_first_funded_by( - blockchain='gnosis' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/gnosis/addresses_events_gnosis_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/gnosis/addresses_events_gnosis_schema.yml similarity index 96% rename from dbt_subprojects/daily_spellbook/models/addresses_events/gnosis/addresses_events_gnosis_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/gnosis/addresses_events_gnosis_schema.yml index b6e1214c105..2cc827fba41 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/gnosis/addresses_events_gnosis_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/gnosis/addresses_events_gnosis_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned Gnosis address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which Gnosis address first funded the address with xDAI" - name: block_time diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/linea/addresses_events_linea_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/linea/addresses_events_linea_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/linea/addresses_events_linea_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/linea/addresses_events_linea_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/linea/addresses_events_linea_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/linea/addresses_events_linea_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/linea/addresses_events_linea_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/linea/addresses_events_linea_first_funded_by.sql index da13fa6499d..caabc37629d 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/linea/addresses_events_linea_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/linea/addresses_events_linea_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'linea' %} + {{ config( - schema = 'addresses_events_linea' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' , file_format = 'delta' @@ -10,5 +12,6 @@ {{addresses_events_first_funded_by( - blockchain='linea' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/linea/addresses_events_linea_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/linea/addresses_events_linea_schema.yml similarity index 89% rename from dbt_subprojects/daily_spellbook/models/addresses_events/linea/addresses_events_linea_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/linea/addresses_events_linea_schema.yml index 9d870c858dc..d39b416c7fc 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/linea/addresses_events_linea_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/linea/addresses_events_linea_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned linea address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which linea address first funded the address with ETH" - name: block_time @@ -37,6 +39,10 @@ models: description: "The block number on which the address was first funded with ETH" - name: tx_hash description: "The transaction hash on which the address was first funded with ETH" + - name: tx_index + description: "The transaction index within the block on which the address was first funded with ETH" + - name: unique_key + description: "Unique transfer identifier key" - name: addresses_events_linea_first_activity meta: diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/optimism/addresses_events_optimism_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/optimism/addresses_events_optimism_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/optimism/addresses_events_optimism_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/optimism/addresses_events_optimism_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/optimism/addresses_events_optimism_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/optimism/addresses_events_optimism_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/optimism/addresses_events_optimism_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/optimism/addresses_events_optimism_first_funded_by.sql index aaaf8e8ccaf..4cf8e04348a 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/optimism/addresses_events_optimism_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/optimism/addresses_events_optimism_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'optimism' %} + {{ config( - schema = 'addresses_events_optimism' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' @@ -11,5 +13,6 @@ {{addresses_events_first_funded_by( - blockchain='optimism' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/optimism/addresses_events_optimism_first_path.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/optimism/addresses_events_optimism_first_path.sql similarity index 98% rename from dbt_subprojects/daily_spellbook/models/addresses_events/optimism/addresses_events_optimism_first_path.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/optimism/addresses_events_optimism_first_path.sql index c14530829ea..2e5aa11c9f0 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/optimism/addresses_events_optimism_first_path.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/optimism/addresses_events_optimism_first_path.sql @@ -150,6 +150,6 @@ LEFT JOIN ( ) sig ON sig.id = f.function LEFT JOIN -{{ ref('contracts_optimism_contract_mapping') }} cm +{{ source('contracts_optimism', 'contract_mapping') }} cm ON f.to_address = cm.contract_address GROUP BY 1, 2 diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/optimism/addresses_events_optimism_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/optimism/addresses_events_optimism_schema.yml similarity index 92% rename from dbt_subprojects/daily_spellbook/models/addresses_events/optimism/addresses_events_optimism_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/optimism/addresses_events_optimism_schema.yml index 969c7d990c8..09b728929ed 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/optimism/addresses_events_optimism_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/optimism/addresses_events_optimism_schema.yml @@ -28,6 +28,8 @@ models: description: "Concerned Optimism address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which Optimism address first funded the address with ETH" - name: block_time @@ -36,6 +38,10 @@ models: description: "The block number on which the address was first funded with ETH" - name: tx_hash description: "The transaction hash on which the address was first funded with ETH" + - name: tx_index + description: "The transaction index within the block on which the address was first funded with ETH" + - name: unique_key + description: "Unique transfer identifier key" - name: addresses_events_optimism_first_activity meta: diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/polygon/addresses_events_polygon_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/polygon/addresses_events_polygon_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/polygon/addresses_events_polygon_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/polygon/addresses_events_polygon_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/polygon/addresses_events_polygon_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/polygon/addresses_events_polygon_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/polygon/addresses_events_polygon_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/polygon/addresses_events_polygon_first_funded_by.sql index a7c40a2d41a..e3b7c8e5f0c 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/polygon/addresses_events_polygon_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/polygon/addresses_events_polygon_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'polygon' %} + {{ config( - schema = 'addresses_events_polygon' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' @@ -11,5 +13,6 @@ {{addresses_events_first_funded_by( - blockchain='polygon' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/polygon/addresses_events_polygon_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/polygon/addresses_events_polygon_schema.yml similarity index 96% rename from dbt_subprojects/daily_spellbook/models/addresses_events/polygon/addresses_events_polygon_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/polygon/addresses_events_polygon_schema.yml index 7de364f68f1..c2ecc231928 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/polygon/addresses_events_polygon_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/polygon/addresses_events_polygon_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned Polygon address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which Polygon address first funded the address with MATIC" - name: block_time diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/scroll/addresses_events_scroll_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/scroll/addresses_events_scroll_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/scroll/addresses_events_scroll_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/scroll/addresses_events_scroll_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/scroll/addresses_events_scroll_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/scroll/addresses_events_scroll_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/scroll/addresses_events_scroll_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/scroll/addresses_events_scroll_first_funded_by.sql index 942c0c2b100..9ddcb28873a 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/scroll/addresses_events_scroll_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/scroll/addresses_events_scroll_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'scroll' %} + {{ config( - schema = 'addresses_events_scroll' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' , file_format = 'delta' @@ -10,5 +12,6 @@ {{addresses_events_first_funded_by( - blockchain='scroll' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/scroll/addresses_events_scroll_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/scroll/addresses_events_scroll_schema.yml similarity index 88% rename from dbt_subprojects/daily_spellbook/models/addresses_events/scroll/addresses_events_scroll_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/scroll/addresses_events_scroll_schema.yml index 329c8d88c80..6a2ac61c815 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/scroll/addresses_events_scroll_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/scroll/addresses_events_scroll_schema.yml @@ -29,14 +29,20 @@ models: description: "Concerned scroll address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which scroll address first funded the address with ETH" - name: block_time description: "The block time on which the address was first funded with ETH" - - name: block_number + - name: block_numbers description: "The block number on which the address was first funded with ETH" - name: tx_hash description: "The transaction hash on which the address was first funded with ETH" + - name: tx_index + description: "The transaction index within the block on which the address was first funded with ETH" + - name: unique_key + description: "Unique transfer identifier key" - name: addresses_events_scroll_first_activity meta: diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/solana/addresses_events_solana_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/solana/addresses_events_solana_first_funded_by.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/solana/addresses_events_solana_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/solana/addresses_events_solana_first_funded_by.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/solana/addresses_events_solana_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/solana/addresses_events_solana_schema.yml similarity index 92% rename from dbt_subprojects/daily_spellbook/models/addresses_events/solana/addresses_events_solana_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/solana/addresses_events_solana_schema.yml index 6c7c67cd849..07d65840954 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/solana/addresses_events_solana_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/solana/addresses_events_solana_schema.yml @@ -30,6 +30,8 @@ models: description: "Concerned Solana address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which Solana address first funded the address with SOL" - name: block_time diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/zkevm/addresses_events_zkevm_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zkevm/addresses_events_zkevm_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/zkevm/addresses_events_zkevm_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zkevm/addresses_events_zkevm_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/zkevm/addresses_events_zkevm_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zkevm/addresses_events_zkevm_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/zkevm/addresses_events_zkevm_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zkevm/addresses_events_zkevm_first_funded_by.sql index d5d5f71d23c..88c0c084059 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/zkevm/addresses_events_zkevm_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zkevm/addresses_events_zkevm_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'zkevm' %} + {{ config( - schema = 'addresses_events_zkevm' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' , file_format = 'delta' @@ -10,5 +12,6 @@ {{addresses_events_first_funded_by( - blockchain='zkevm' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/zkevm/addresses_events_zkevm_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zkevm/addresses_events_zkevm_schema.yml similarity index 89% rename from dbt_subprojects/daily_spellbook/models/addresses_events/zkevm/addresses_events_zkevm_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zkevm/addresses_events_zkevm_schema.yml index 9b873a709db..6f4feeccd86 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/zkevm/addresses_events_zkevm_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zkevm/addresses_events_zkevm_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned zkevm address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which zkevm address first funded the address with ETH" - name: block_time @@ -37,6 +39,10 @@ models: description: "The block number on which the address was first funded with ETH" - name: tx_hash description: "The transaction hash on which the address was first funded with ETH" + - name: tx_index + description: "The transaction index within the block on which the address was first funded with ETH" + - name: unique_key + description: "Unique transfer identifier key" - name: addresses_events_zkevm_first_activity meta: diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/zksync/addresses_events_zksync_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zksync/addresses_events_zksync_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/zksync/addresses_events_zksync_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zksync/addresses_events_zksync_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/zksync/addresses_events_zksync_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zksync/addresses_events_zksync_first_funded_by.sql similarity index 52% rename from dbt_subprojects/daily_spellbook/models/addresses_events/zksync/addresses_events_zksync_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zksync/addresses_events_zksync_first_funded_by.sql index 20799cd881c..38f683f6389 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/zksync/addresses_events_zksync_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zksync/addresses_events_zksync_first_funded_by.sql @@ -1,5 +1,8 @@ +{% set blockchain = 'zksync' %} + {{ config( - schema = 'addresses_events_zksync' + tags = ['prod_exclude'] + , schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' , file_format = 'delta' @@ -10,5 +13,6 @@ {{addresses_events_first_funded_by( - blockchain='zksync' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/zksync/addresses_events_zksync_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zksync/addresses_events_zksync_schema.yml similarity index 89% rename from dbt_subprojects/daily_spellbook/models/addresses_events/zksync/addresses_events_zksync_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zksync/addresses_events_zksync_schema.yml index e3b5e6fd047..3a6be3c6b61 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/zksync/addresses_events_zksync_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zksync/addresses_events_zksync_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned zksync address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which zksync address first funded the address with ETH" - name: block_time @@ -37,6 +39,10 @@ models: description: "The block number on which the address was first funded with ETH" - name: tx_hash description: "The transaction hash on which the address was first funded with ETH" + - name: tx_index + description: "The transaction index within the block on which the address was first funded with ETH" + - name: unique_key + description: "Unique transfer identifier key" - name: addresses_events_zksync_first_activity meta: diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/zora/addresses_events_zora_first_activity.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zora/addresses_events_zora_first_activity.sql similarity index 100% rename from dbt_subprojects/daily_spellbook/models/addresses_events/zora/addresses_events_zora_first_activity.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zora/addresses_events_zora_first_activity.sql diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/zora/addresses_events_zora_first_funded_by.sql b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zora/addresses_events_zora_first_funded_by.sql similarity index 56% rename from dbt_subprojects/daily_spellbook/models/addresses_events/zora/addresses_events_zora_first_funded_by.sql rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zora/addresses_events_zora_first_funded_by.sql index 655ce09f3bd..314bdf0b9ee 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/zora/addresses_events_zora_first_funded_by.sql +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zora/addresses_events_zora_first_funded_by.sql @@ -1,5 +1,7 @@ +{% set blockchain = 'zora' %} + {{ config( - schema = 'addresses_events_zora' + schema = 'addresses_events_' + blockchain , alias = 'first_funded_by' , materialized = 'incremental' , file_format = 'delta' @@ -10,5 +12,6 @@ {{addresses_events_first_funded_by( - blockchain='zora' + blockchain = blockchain + , token_transfers = source('tokens_' + blockchain, 'transfers') )}} diff --git a/dbt_subprojects/daily_spellbook/models/addresses_events/zora/addresses_events_zora_schema.yml b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zora/addresses_events_zora_schema.yml similarity index 89% rename from dbt_subprojects/daily_spellbook/models/addresses_events/zora/addresses_events_zora_schema.yml rename to dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zora/addresses_events_zora_schema.yml index 56d0f31cab2..3caac08c6b4 100644 --- a/dbt_subprojects/daily_spellbook/models/addresses_events/zora/addresses_events_zora_schema.yml +++ b/dbt_subprojects/hourly_spellbook/models/_sector/addresses_events/zora/addresses_events_zora_schema.yml @@ -29,6 +29,8 @@ models: description: "Concerned zora address" tests: - unique + - name: first_funding_executed_by + description: "Which address executed the first funding tx" - name: first_funded_by description: "Which zora address first funded the address with ETH" - name: block_time @@ -37,6 +39,10 @@ models: description: "The block number on which the address was first funded with ETH" - name: tx_hash description: "The transaction hash on which the address was first funded with ETH" + - name: tx_index + description: "The transaction index within the block on which the address was first funded with ETH" + - name: unique_key + description: "Unique transfer identifier key" - name: addresses_events_zora_first_activity meta: diff --git a/dbt_subprojects/daily_spellbook/seeds/addresses_events/_schema.yml b/dbt_subprojects/hourly_spellbook/seeds/_sector/addresses_events/_schema.yml similarity index 100% rename from dbt_subprojects/daily_spellbook/seeds/addresses_events/_schema.yml rename to dbt_subprojects/hourly_spellbook/seeds/_sector/addresses_events/_schema.yml diff --git a/dbt_subprojects/daily_spellbook/seeds/addresses_events/first_activity_seed.csv b/dbt_subprojects/hourly_spellbook/seeds/_sector/addresses_events/first_activity_seed.csv similarity index 100% rename from dbt_subprojects/daily_spellbook/seeds/addresses_events/first_activity_seed.csv rename to dbt_subprojects/hourly_spellbook/seeds/_sector/addresses_events/first_activity_seed.csv diff --git a/dbt_subprojects/daily_spellbook/seeds/addresses_events/first_funded_by_seed.csv b/dbt_subprojects/hourly_spellbook/seeds/_sector/addresses_events/first_funded_by_seed.csv similarity index 91% rename from dbt_subprojects/daily_spellbook/seeds/addresses_events/first_funded_by_seed.csv rename to dbt_subprojects/hourly_spellbook/seeds/_sector/addresses_events/first_funded_by_seed.csv index 28edb9b7e3e..ea44ebdc7a0 100644 --- a/dbt_subprojects/daily_spellbook/seeds/addresses_events/first_funded_by_seed.csv +++ b/dbt_subprojects/hourly_spellbook/seeds/_sector/addresses_events/first_funded_by_seed.csv @@ -19,7 +19,7 @@ fantom,0xf4cc855ce33b9ffad5dd85799190811157a0271b,0xe2922b289bd364c8b0fe25fc5bc3 fantom,0xf4cd008d798a3b757c12ade2a16311ba5bf8a7c5,0xeabbf24d080722c86c6441faceefa4070a25af67,16865837,0x90502ef842d078af330e082b5ab257a1fbe3b5117fcd7373a15f6cf0a2b55c62 celo,0x273BFe950BDc3d16e88ba755DAD845CC77Dbf9B6,0x4F93Fa058b03953C851eFaA2e4FC5C34afDFAb84,19059311,0x1d3e9cfcc476f0f146e10e1de0f4e30a560373f2d03f2e6ebb436ad49f685b53 celo,0x7df13800cf9352513e0f64dbce2947bbd416fd8a,0xdd3826a3a3e0fff1fa3424f5fc5d4523e3256cef,21411795,0xe500f615634d56bfb24515c4d94d1388c3ae19f6a51afb3b7c4f50d3b182c65c -zksync,0x67eecbd0d594a760aa569d20c3f33592c8865d1d,0x621425a1ef6abe91058e9712575dcc4258f8d091,2219807,0x13685fb1135194c37377359ab28856f1c430c120237316189d6c8c14a283bffc -zksync,0x9d9d6e47bd5eb4f166444bb9220b2638228d06d5,0x621425a1ef6abe91058e9712575dcc4258f8d091,2269832,0xafc90f065a5ea2fa81222c1631a97f8776bdd847c0954d3e1bfa1fa5a787d8a9 +zksync,0x5dcc03586098648a92aa3862d25c66295024b049,0x888270ff52f486729ef865466340d4eac83a31d6,9872121,0xc6175daf3025aef766cf9ed0bd302e284571b4d65e0b1721d733361a63e8ddfc +zksync,0x65b7446d7be552e4a0bc72e921951000ff709c3b,0xe4edb277e41dc89ab076a1f049f4a3efa700bce8,1548262,0x63f2c92dd302f49c5e2772cc6e0d1d01ac09761ff2ce2f659ffadcb3ca0874e8 zora,0x3fab184622dc19b6109349b94811493bf2a45362,0xad031eee55f595df6dbd61e9ef3b908fad1b3671,10626,0x33f1a09bb2011aea90e56a66975d7ed3f3e20880f7f2395474f4e197cedb9e6d zora,0xf2989961bf987bdd6c86cd6b845b6faca194a8e4,0xc4da93843ca009814325aa5437412c85612d3f1f,41445,0x6eef8829fbf19a266ee42f4bf1908ea0fa570a8b5a8521830b71104164b87bba \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/seeds/addresses_events/first_funded_by_seed_bitcoin.csv b/dbt_subprojects/hourly_spellbook/seeds/_sector/addresses_events/first_funded_by_seed_bitcoin.csv similarity index 100% rename from dbt_subprojects/daily_spellbook/seeds/addresses_events/first_funded_by_seed_bitcoin.csv rename to dbt_subprojects/hourly_spellbook/seeds/_sector/addresses_events/first_funded_by_seed_bitcoin.csv diff --git a/dbt_subprojects/daily_spellbook/seeds/addresses_events/first_funded_by_seed_solana.csv b/dbt_subprojects/hourly_spellbook/seeds/_sector/addresses_events/first_funded_by_seed_solana.csv similarity index 100% rename from dbt_subprojects/daily_spellbook/seeds/addresses_events/first_funded_by_seed_solana.csv rename to dbt_subprojects/hourly_spellbook/seeds/_sector/addresses_events/first_funded_by_seed_solana.csv diff --git a/sources/_subprojects_outputs/daily_spellbook/_sources.yml b/sources/_subprojects_outputs/daily_spellbook/_sources.yml index c1521130161..aaa30c99dee 100644 --- a/sources/_subprojects_outputs/daily_spellbook/_sources.yml +++ b/sources/_subprojects_outputs/daily_spellbook/_sources.yml @@ -16,6 +16,7 @@ sources: tables: - name: disperse_contracts - name: contract_creator_project_mapping + - name: contract_mapping - name: labels tables: diff --git a/sources/_subprojects_outputs/tokens/transfers.yml b/sources/_subprojects_outputs/tokens/transfers.yml index 59fe74d7e62..e229ae82b19 100644 --- a/sources/_subprojects_outputs/tokens/transfers.yml +++ b/sources/_subprojects_outputs/tokens/transfers.yml @@ -67,4 +67,6 @@ sources: tables: - name: transfers - + - name: tokens_mantle + tables: + - name: transfers \ No newline at end of file From 389e9af8e865e5d9a399d568bbd576984d139f05 Mon Sep 17 00:00:00 2001 From: monidob <122102789+monidob@users.noreply.github.com> Date: Wed, 2 Oct 2024 19:11:27 +0300 Subject: [PATCH 58/59] Update tokens_ethereum_erc20.sql (#6865) Wrong decimals value was entered for token 0xe9689028ede16c2fdfe3d11855d28f8e3fc452a3 --- .../tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql index dc0ed2338d6..4be68ef4e22 100644 --- a/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql +++ b/dbt_subprojects/tokens/models/tokens/ethereum/tokens_ethereum_erc20.sql @@ -4628,7 +4628,7 @@ FROM (VALUES , ( 0xbbd91d5cda7085a186b1354e1b0744bb58ad7cf6, 'ZOMBIE', 9) , ( 0xdd157bd06c1840fa886da18a138c983a7d74c1d7, 'GSTOP', 18) , ( 0x525574c899a7c877a11865339e57376092168258, 'GURU', 18) - , ( 0xe9689028ede16c2fdfe3d11855d28f8e3fc452a3, 'BUBBLE', 9) + , ( 0xe9689028ede16c2fdfe3d11855d28f8e3fc452a3, 'BUBBLE', 18) , ( 0xeb9951021698b42e4399f9cbb6267aa35f82d59d, 'LIF', 18) , ( 0x707f9118e33a9b8998bea41dd0d46f38bb963fc8, 'bETH', 18) , ( 0x848107491e029afde0ac543779c7790382f15929, 'stataEthcrvUSD', 18) From bd7f463eaf294452524e9290cfd287795ddb0316 Mon Sep 17 00:00:00 2001 From: tomfutago <35136350+tomfutago@users.noreply.github.com> Date: Wed, 2 Oct 2024 19:42:18 +0100 Subject: [PATCH 59/59] Nexus Mutual - staking rewards & staked history (#6861) * refactor: staking events * fix: amend product_id to non-nullable & trigger incremental re-run * feat: add staking rewards and staked per pool & token * fix: staking deposit entensions uniqueness --- .../nexusmutual/ethereum/staking/_schema.yml | 121 +++++++++++++++++- ...exusmutual_ethereum_base_staking_pools.sql | 10 +- .../nexusmutual_ethereum_staked_per_pool.sql | 90 +++++++++++++ .../nexusmutual_ethereum_staked_per_token.sql | 98 ++++++++++++++ ...al_ethereum_staking_deposit_extensions.sql | 55 ++++---- ...utual_ethereum_staking_deposit_ordered.sql | 67 ++++++++++ .../nexusmutual_ethereum_staking_events.sql | 1 + .../nexusmutual_ethereum_staking_pools.sql | 7 +- .../nexusmutual_ethereum_staking_rewards.sql | 64 +++++++++ .../ethereum/nexusmutual_ethereum_sources.yml | 3 + 10 files changed, 482 insertions(+), 34 deletions(-) create mode 100644 dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staked_per_pool.sql create mode 100644 dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staked_per_token.sql create mode 100644 dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_ordered.sql create mode 100644 dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_rewards.sql diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/_schema.yml b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/_schema.yml index 468841a72ee..b75aa207bc6 100644 --- a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/_schema.yml +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/_schema.yml @@ -132,7 +132,7 @@ models: contributors: tomfutago config: tags: ["ethereum", "nexusmutual", "staking"] - description: "Staking pools event history for Nexus Mutual on Ethereum" + description: "Staking pools event history" tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -147,6 +147,9 @@ models: - &block_time name: block_time description: "UTC event block time" + - &block_date + name: block_date + description: "event block date" - *pool_address - &token_id name: token_id @@ -182,6 +185,42 @@ models: name: tx_hash description: "unique transaction hash value" + - name: nexusmutual_ethereum_staking_deposit_ordered + meta: + blockchain: ethereum + project: nexusmutual + contributors: tomfutago + config: + tags: ["ethereum", "nexusmutual", "staking"] + description: "Staking pools deposit ordered" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - flow_type + - block_time + - evt_index + - tx_hash + columns: + - *block_time + - *flow_type + - &stake_start_date + name: stake_start_date + - &stake_end_date + name: stake_end_date + - *pool_address + - *token_id + - *tranche_id + - *init_tranche_id + - *new_tranche_id + - *tranche_expiry_date + - *is_active + - *amount + - *topup_amount + - *user + - *evt_index + - *tx_hash + - name: deposit_rn + - name: nexusmutual_ethereum_staking_deposit_extensions meta: blockchain: ethereum @@ -189,7 +228,7 @@ models: contributors: tomfutago config: tags: ["ethereum", "nexusmutual", "staking"] - description: "Staking pools deposit extensions for Nexus Mutual on Ethereum" + description: "Staking pools deposit extensions" tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: @@ -197,16 +236,20 @@ models: - token_id - init_tranche_id - current_tranche_id + - stake_start_date + - stake_end_date columns: - *block_time + - *block_date - *pool_address - *token_id - *init_tranche_id - name: current_tranche_id description: "current staking tranche period (most recent one in the chain of extensions)" - - name: total_amount + - name: amount description: "total staking amount (initial deposit + all top-up amounts)" - - *tranche_expiry_date + - *stake_start_date + - *stake_end_date - *is_active - name: chain_level description: "chain (recursion) level" @@ -214,3 +257,73 @@ models: description: "descending row number per pool, token & tranche" - *evt_index - *tx_hash + + - name: nexusmutual_ethereum_staking_rewards + meta: + blockchain: ethereum + project: nexusmutual + contributors: tomfutago + config: + tags: ["ethereum", "nexusmutual", "staking"] + description: "Staking rewards minted at cover buy event - to be streamed over cover period" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - pool_id + - cover_id + columns: + - *block_time + - *block_date + - *pool_id + - *product_id + - name: cover_id + - name: cover_start_date + - name: cover_end_date + - name: reward_amount_expected_total + - name: reward_amount_per_second + - name: reward_amount_per_day + - *tx_hash + + - name: nexusmutual_ethereum_staked_per_pool + meta: + blockchain: ethereum + project: nexusmutual + contributors: tomfutago + config: + tags: ["ethereum", "nexusmutual", "staking"] + description: "Staking rewards minted at cover buy event - to be streamed over cover period" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + columns: + - *block_date + - *pool_id + - *pool_address + - &total_staked_nxm + name: total_staked_nxm + - name: pool_date_rn + + - name: nexusmutual_ethereum_staked_per_token + meta: + blockchain: ethereum + project: nexusmutual + contributors: tomfutago + config: + tags: ["ethereum", "nexusmutual", "staking"] + description: "Staking rewards minted at cover buy event - to be streamed over cover period" + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - pool_id + - token_id + columns: + - *block_date + - *pool_id + - *pool_address + - *token_id + - *total_staked_nxm + - name: stake_expiry_date + - name: token_date_rn diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_base_staking_pools.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_base_staking_pools.sql index 0ebf657ee4e..84423810d7a 100644 --- a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_base_staking_pools.sql +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_base_staking_pools.sql @@ -202,10 +202,16 @@ products as ( select cast(p.product_id as int) as product_id, p.product_name, - pt.product_type_id, + cast(pt.product_type_id as int) as product_type_id, pt.product_type_name as product_type from {{ ref('nexusmutual_ethereum_product_types_v2') }} pt inner join {{ ref('nexusmutual_ethereum_products_v2') }} p on pt.product_type_id = p.product_type_id + union all + select + -1 as product_id, + null as product_name, + -1 as product_type_id, + null as product_type ) select @@ -247,6 +253,6 @@ select ) as tx_hash_updated from staking_pools_created_ext sp inner join staking_pool_products_combined spc on sp.pool_id = spc.pool_id - left join products p on spc.product_id = p.product_id + inner join products p on spc.product_id = p.product_id left join staking_pool_managers spm on sp.pool_id = spm.pool_id left join staking_pool_fee_updates spf on sp.pool_address = spf.pool_address diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staked_per_pool.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staked_per_pool.sql new file mode 100644 index 00000000000..9b903a7335a --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staked_per_pool.sql @@ -0,0 +1,90 @@ +{{ + config( + schema = 'nexusmutual_ethereum', + alias = 'staked_per_pool', + materialized = 'view', + unique_key = ['block_date', 'pool_id'], + post_hook = '{{ expose_spells(blockchains = \'["ethereum"]\', + spell_type = "project", + spell_name = "nexusmutual", + contributors = \'["tomfutago"]\') }}' + ) +}} + +with + +staking_pools as ( + select distinct + sp.pool_id, + sp.pool_address, + se.first_stake_event_date + from {{ ref('nexusmutual_ethereum_staking_pools') }} sp + inner join ( + select + pool_address, + cast(min(block_time) as date) as first_stake_event_date + from {{ ref('nexusmutual_ethereum_staking_events') }} + group by 1 + ) se on sp.pool_address = se.pool_address +), + +staking_pool_day_sequence as ( + select + sp.pool_id, + sp.pool_address, + s.block_date + from staking_pools sp + cross join unnest ( + sequence( + cast(date_trunc('day', sp.first_stake_event_date) as timestamp), + cast(date_trunc('day', now()) as timestamp), + interval '1' day + ) + ) as s(block_date) +), + +staked_nxm_per_pool as ( + select + block_date, + pool_id, + pool_address, + sum(coalesce(total_amount, 0)) as total_staked_nxm, + dense_rank() over (partition by pool_id order by block_date desc) as pool_date_rn + from ( + -- deposits & deposit extensions + select + d.block_date, + d.pool_id, + d.pool_address, + sum(se.amount) as total_amount + from staking_pool_day_sequence d + left join {{ ref('nexusmutual_ethereum_staking_deposit_extensions') }} se + on d.pool_address = se.pool_address + and d.block_date >= se.stake_start_date + and d.block_date < se.stake_end_date + group by 1, 2, 3 + union all + -- withdrawals & burns + select + d.block_date, + d.pool_id, + d.pool_address, + sum(se.amount) as total_amount + from staking_pool_day_sequence d + left join {{ ref('nexusmutual_ethereum_staking_events') }} se + on d.pool_address = se.pool_address + and d.block_date >= date_trunc('day', se.block_time) + and d.block_date < coalesce(se.tranche_expiry_date, current_date) + where flow_type in ('withdraw', 'stake burn') + group by 1, 2, 3 + ) t + group by 1, 2, 3 +) + +select + block_date, + pool_id, + pool_address, + total_staked_nxm, + pool_date_rn +from staked_nxm_per_pool diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staked_per_token.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staked_per_token.sql new file mode 100644 index 00000000000..d59db6f0032 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staked_per_token.sql @@ -0,0 +1,98 @@ +{{ + config( + schema = 'nexusmutual_ethereum', + alias = 'staked_per_token', + materialized = 'view', + unique_key = ['block_date', 'pool_id', 'token_id'], + post_hook = '{{ expose_spells(blockchains = \'["ethereum"]\', + spell_type = "project", + spell_name = "nexusmutual", + contributors = \'["tomfutago"]\') }}' + ) +}} + +with + +staking_pools as ( + select distinct + sp.pool_id, + sp.pool_address, + se.first_stake_event_date + from {{ ref('nexusmutual_ethereum_staking_pools') }} sp + inner join ( + select + pool_address, + cast(min(block_time) as date) as first_stake_event_date + from {{ ref('nexusmutual_ethereum_staking_events') }} + group by 1 + ) se on sp.pool_address = se.pool_address +), + +staking_pool_day_sequence as ( + select + sp.pool_id, + sp.pool_address, + s.block_date + from staking_pools sp + cross join unnest ( + sequence( + cast(date_trunc('day', sp.first_stake_event_date) as timestamp), + cast(date_trunc('day', now()) as timestamp), + interval '1' day + ) + ) as s(block_date) +), + +staked_nxm_per_pool_n_token as ( + select + block_date, + pool_id, + pool_address, + token_id, + sum(coalesce(total_amount, 0)) as total_staked_nxm, + max(stake_expiry_date) as stake_expiry_date, + dense_rank() over (partition by pool_id, token_id order by block_date desc) as token_date_rn + from ( + -- deposits & deposit extensions + select + d.block_date, + d.pool_id, + d.pool_address, + se.token_id, + sum(se.amount) as total_amount, + max(se.stake_end_date) as stake_expiry_date + from staking_pool_day_sequence d + left join {{ ref('nexusmutual_ethereum_staking_deposit_extensions') }} se + on d.pool_address = se.pool_address + and d.block_date >= se.stake_start_date + and d.block_date < se.stake_end_date + group by 1, 2, 3, 4 + union all + -- withdrawals & burns? + select + d.block_date, + d.pool_id, + d.pool_address, + se.token_id, + sum(se.amount) as total_amount, + cast(null as date) as stake_expiry_date -- no point pulling stake_expiry_date for withdrawals + from staking_pool_day_sequence d + left join {{ ref('nexusmutual_ethereum_staking_events') }} se + on d.pool_address = se.pool_address + and d.block_date >= date_trunc('day', se.block_time) + and d.block_date < coalesce(se.tranche_expiry_date, current_date) + where flow_type in ('withdraw', 'stake burn') + group by 1, 2, 3, 4 + ) t + group by 1, 2, 3, 4 +) + +select + block_date, + pool_id, + pool_address, + token_id, + total_staked_nxm, + stake_expiry_date, + token_date_rn +from staked_nxm_per_pool_n_token diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_extensions.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_extensions.sql index 58aefb450ff..7bcd2b6ad2b 100644 --- a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_extensions.sql +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_extensions.sql @@ -3,7 +3,7 @@ schema = 'nexusmutual_ethereum', alias = 'staking_deposit_extensions', materialized = 'view', - unique_key = ['pool_address', 'token_id', 'init_tranche_id', 'current_tranche_id'], + unique_key = ['pool_address', 'token_id', 'init_tranche_id', 'current_tranche_id', 'stake_start_date', 'stake_end_date'], post_hook = '{{ expose_spells(blockchains = \'["ethereum"]\', spell_type = "project", spell_name = "nexusmutual", @@ -11,60 +11,67 @@ ) }} -with recursive deposit_chain (pool_address, token_id, tranche_id, new_tranche_id, total_amount, block_time, tranche_expiry_date, is_active, evt_index, tx_hash, chain_level) as ( +with recursive deposit_chain ( + block_time, pool_address, token_id, tranche_id, new_tranche_id, amount, stake_start_date, stake_end_date, is_active, evt_index, tx_hash, deposit_rn, chain_level +) as ( select + block_time, pool_address, token_id, - tranche_id as tranche_id, + tranche_id, tranche_id as new_tranche_id, - sum(amount) as total_amount, - max(block_time) as block_time, - max_by(tranche_expiry_date, block_time) as tranche_expiry_date, - max_by(is_active, block_time) as is_active, - max_by(evt_index, block_time) as evt_index, - max_by(tx_hash, block_time) as tx_hash, + amount, + stake_start_date, + stake_end_date, + is_active, + evt_index, + tx_hash, + deposit_rn, 1 as chain_level - from {{ ref('nexusmutual_ethereum_staking_events') }} + from {{ ref('nexusmutual_ethereum_staking_deposit_ordered') }} where flow_type = 'deposit' - group by 1,2,3,4 union all select + d.block_time, d.pool_address, d.token_id, dc.tranche_id, - d.new_tranche_id, - dc.total_amount + coalesce(d.topup_amount, 0) as total_amount, - d.block_time, - d.tranche_expiry_date, + coalesce(d.new_tranche_id, dc.tranche_id) as new_tranche_id, + dc.amount + coalesce(d.amount, d.topup_amount, 0) as amount, + d.stake_start_date, + d.stake_end_date, d.is_active, d.evt_index, d.tx_hash, + d.deposit_rn, dc.chain_level + 1 as chain_level from deposit_chain dc - inner join {{ ref('nexusmutual_ethereum_staking_events') }} d on dc.pool_address = d.pool_address - and dc.token_id = d.token_id - and dc.new_tranche_id = d.init_tranche_id - where d.flow_type = 'deposit extended' + inner join {{ ref('nexusmutual_ethereum_staking_deposit_ordered') }} d on dc.pool_address = d.pool_address and dc.token_id = d.token_id + where dc.deposit_rn = d.deposit_rn - 1 + and ((d.flow_type = 'deposit extended' and dc.new_tranche_id = d.init_tranche_id) + or (d.flow_type = 'deposit addon' and dc.new_tranche_id = d.tranche_id)) ) -select +select block_time, + date_trunc('day', block_time) as block_date, pool_address, token_id, tranche_id as init_tranche_id, new_tranche_id as current_tranche_id, - total_amount, - tranche_expiry_date, + amount, + stake_start_date, + stake_end_date, is_active, chain_level, - rn as token_tranche_rn, + token_tranche_rn, evt_index, tx_hash from ( select *, - row_number() over (partition by pool_address, token_id, tranche_id order by chain_level desc) as rn + row_number() over (partition by pool_address, token_id, tranche_id order by chain_level desc) as token_tranche_rn from deposit_chain ) t diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_ordered.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_ordered.sql new file mode 100644 index 00000000000..f5d47b559b4 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_deposit_ordered.sql @@ -0,0 +1,67 @@ +{{ + config( + schema = 'nexusmutual_ethereum', + alias = 'staking_deposit_ordered', + materialized = 'view', + unique_key = ['flow_type', 'block_time', 'evt_index', 'tx_hash'] + ) +}} + +with + +deposits as ( + select + flow_type, + block_time, + block_date, + pool_address, + token_id, + tranche_id, + init_tranche_id, + new_tranche_id, + tranche_expiry_date, + is_active, + amount, + topup_amount, + user, + evt_index, + tx_hash, + lead(block_date, 1) over (partition by pool_address, token_id order by coalesce(tranche_id, init_tranche_id), block_time) as next_block_date, + lag(flow_type, 1) over (partition by pool_address, token_id order by coalesce(tranche_id, init_tranche_id), block_time) as prev_flow_type, + lead(flow_type, 1) over (partition by pool_address, token_id order by coalesce(tranche_id, init_tranche_id), block_time) as next_flow_type, + lag(token_id, 1) over (partition by pool_address, token_id order by coalesce(tranche_id, init_tranche_id), block_time) as prev_token_id, + lag(tranche_id, 1) over (partition by pool_address, token_id order by coalesce(tranche_id, init_tranche_id), block_time) as prev_tranche_id, + lead(tranche_id, 1) over (partition by pool_address, token_id order by coalesce(tranche_id, init_tranche_id), block_time) as next_tranche_id, + row_number() over (partition by pool_address, token_id order by coalesce(tranche_id, init_tranche_id), block_time) as deposit_rn + from {{ ref('nexusmutual_ethereum_staking_events') }} + where flow_type in ('deposit', 'deposit extended') +) + +select + block_time, + case + when token_id = prev_token_id and flow_type = 'deposit' and prev_flow_type = 'deposit' and prev_tranche_id = tranche_id + then 'deposit addon' + else flow_type + end as flow_type, + block_date as stake_start_date, + case + when flow_type = 'deposit' and next_flow_type <> 'deposit extended' and next_tranche_id <> tranche_id then tranche_expiry_date + when flow_type = 'deposit extended' and next_flow_type = 'deposit' then tranche_expiry_date + when next_block_date > tranche_expiry_date then tranche_expiry_date + else coalesce(next_block_date, tranche_expiry_date) + end as stake_end_date, + pool_address, + token_id, + tranche_id, + init_tranche_id, + new_tranche_id, + tranche_expiry_date, + is_active, + amount, + topup_amount, + user, + evt_index, + tx_hash, + deposit_rn +from deposits diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_events.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_events.sql index 846f286b13c..2d4f1940f77 100644 --- a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_events.sql +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_events.sql @@ -104,6 +104,7 @@ staked_nxm_history as ( select flow_type, block_time, + date_trunc('day', block_time) as block_date, pool_address, token_id, tranche_id, diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_pools.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_pools.sql index adce06fa39c..ad21b3e3559 100644 --- a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_pools.sql +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_pools.sql @@ -38,7 +38,6 @@ select tx_hash_created, tx_hash_updated from {{ ref('nexusmutual_ethereum_base_staking_pools') }} -where true - {% if is_incremental() %} - and {{ incremental_predicate('block_time_updated') }} - {% endif %} +{% if is_incremental() %} +where {{ incremental_predicate('block_time_updated') }} +{% endif %} diff --git a/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_rewards.sql b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_rewards.sql new file mode 100644 index 00000000000..13a26d46de6 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/nexusmutual/ethereum/staking/nexusmutual_ethereum_staking_rewards.sql @@ -0,0 +1,64 @@ +{{ + config( + schema = 'nexusmutual_ethereum', + alias = 'staking_rewards', + materialized = 'view', + unique_key = ['pool_id', 'cover_id'], + post_hook = '{{ expose_spells(blockchains = \'["ethereum"]\', + spell_type = "project", + spell_name = "nexusmutual", + contributors = \'["tomfutago"]\') }}' + ) +}} + +with + +covers as ( + select + cover_id, + cover_start_date, + cover_end_date, + floor(date_diff('day', from_unixtime(0), cover_end_date) / 28) as cover_end_bucket_id, + from_unixtime(28.0 * 86400.0 * cast(floor(date_diff('day', from_unixtime(0), cover_end_time) / 28) + 1 as double)) as cover_end_bucket_expiry_date, + date_diff( + 'second', + cover_start_time, + from_unixtime(28.0 * 86400.0 * cast(floor(date_diff('day', from_unixtime(0), cover_end_time) / 28) + 1 as double)) -- cover_end_bucket_expiry_date (rathan than cover_end_time) + ) as cover_period_seconds, + staking_pool_id, + product_id, + block_number, + trace_address, + tx_hash + from {{ ref("nexusmutual_ethereum_covers_v2") }} +) + +select + mr.call_block_time as block_time, + date_trunc('day', mr.call_block_time) as block_date, + mr.poolId as pool_id, + c.product_id, + c.cover_id, + c.cover_start_date, + c.cover_end_date, + mr.amount / 1e18 as reward_amount_expected_total, + mr.amount / c.cover_period_seconds / 1e18 as reward_amount_per_second, + mr.amount / c.cover_period_seconds * 86400.0 / 1e18 as reward_amount_per_day, + mr.call_tx_hash as tx_hash +from ( + select call_block_time, call_block_number, poolId, amount, call_trace_address, call_tx_hash + from {{ source('nexusmutual_ethereum', 'TokenController_call_mintStakingPoolNXMRewards') }} + where call_success + union all + select call_block_time, call_block_number, poolId, amount, call_trace_address, call_tx_hash + from {{ source('nexusmutual_ethereum', 'TokenController2_call_mintStakingPoolNXMRewards') }} + where call_success + union all + select call_block_time, call_block_number, poolId, amount, call_trace_address, call_tx_hash + from {{ source('nexusmutual_ethereum', 'TokenController3_call_mintStakingPoolNXMRewards') }} + where call_success + ) mr + inner join covers c on mr.call_tx_hash = c.tx_hash and mr.call_block_number = c.block_number +where mr.poolId = c.staking_pool_id + and (c.trace_address is null + or slice(mr.call_trace_address, 1, cardinality(c.trace_address)) = c.trace_address) diff --git a/sources/nexusmutual/ethereum/nexusmutual_ethereum_sources.yml b/sources/nexusmutual/ethereum/nexusmutual_ethereum_sources.yml index 81a219ed106..3b555631340 100644 --- a/sources/nexusmutual/ethereum/nexusmutual_ethereum_sources.yml +++ b/sources/nexusmutual/ethereum/nexusmutual_ethereum_sources.yml @@ -15,6 +15,9 @@ sources: - name: TokenController_call_assignStakingPoolManager - name: TokenController2_call_assignStakingPoolManager - name: TokenController3_call_assignStakingPoolManager + - name: TokenController_call_mintStakingPoolNXMRewards + - name: TokenController2_call_mintStakingPoolNXMRewards + - name: TokenController3_call_mintStakingPoolNXMRewards - name: StakingProducts_evt_ProductUpdated - name: StakingPool_call_manager - name: StakingPool_evt_PoolFeeChanged