diff --git a/dbt_subprojects/daily_spellbook/models/_projects/lifi/LiFiDiamond_v2_evt_LiFiTransferStarted.sql b/dbt_subprojects/daily_spellbook/models/_projects/lifi/LiFiDiamond_v2_evt_LiFiTransferStarted.sql new file mode 100644 index 00000000000..a56bb63b80f --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/lifi/LiFiDiamond_v2_evt_LiFiTransferStarted.sql @@ -0,0 +1,65 @@ +{{ + config( + schema = 'lifi', + alias = 'transfers', + materialized = 'incremental', + unique_key = ['evt_block_time', 'evt_tx_hash', 'evt_index'] + ) +}} + +{% set chains = [ + 'ethereum', + 'arbitrum', + 'avalanche', + 'bnb', + 'fantom', + 'gnosis', + 'zksync' +] %} + +with chain_transfers as ( + {% for chain in chains %} + select + contract_address, + evt_tx_hash, + evt_index, + evt_block_time, + evt_block_number, + transactionId, + bridge, + integrator, + referrer, + sendingAssetId, + receiver, + minAmount, + destinationChainId, + source_chain, + sender + from {{ ref('lifi_' ~ chain ~ '_transfers') }} + {% if is_incremental() %} + where evt_block_time >= date_trunc('day', now() - interval '7' day) + {% endif %} + + {% if not loop.last %} + union all + {% endif %} + {% endfor %} +) + +select + contract_address, + evt_tx_hash, + evt_index, + evt_block_time, + evt_block_number, + transactionId, + bridge, + integrator, + referrer, + sendingAssetId, + receiver, + minAmount, + destinationChainId, + source_chain, + sender +from chain_transfers \ No newline at end of file diff --git a/dbt_subprojects/daily_spellbook/models/_projects/lifi/arbitrum/lifi_arbitrum_transfers.sql b/dbt_subprojects/daily_spellbook/models/_projects/lifi/arbitrum/lifi_arbitrum_transfers.sql new file mode 100644 index 00000000000..661b8ef25b3 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/lifi/arbitrum/lifi_arbitrum_transfers.sql @@ -0,0 +1,38 @@ +{{ config( + schema = 'lifi_arbitrum', + alias = 'transfers', + materialized = 'view' + ) +}} + +with source_data as ( + select + contract_address, + evt_tx_hash, + evt_index, + evt_block_time, + evt_block_number, + json_extract_scalar(bridgeData, '$.transactionId') as transactionId, + json_extract_scalar(bridgeData, '$.bridge') as bridge, + json_extract_scalar(bridgeData, '$.integrator') as integrator, + json_extract_scalar(bridgeData, '$.referrer') as referrer, + json_extract_scalar(bridgeData, '$.sendingAssetId') as sendingAssetId, + json_extract_scalar(bridgeData, '$.receiver') as receiver, + json_extract_scalar(bridgeData, '$.minAmount') as minAmount, + json_extract_scalar(bridgeData, '$.destinationChainId') as destinationChainId, + 'arbitrum' as source_chain + from {{ source('lifi_arbitrum', 'LiFiDiamond_v2_evt_LiFiTransferStarted') }} +), +transactions as ( + select + "from" as sender, + hash as tx_hash + from {{ source('arbitrum', 'transactions') }} +) + +select + s.*, + t.sender +from source_data s +inner join transactions t + on s.evt_tx_hash = t.tx_hash diff --git a/dbt_subprojects/daily_spellbook/models/_projects/lifi/avalanche/lifi_avalanche_transfers.sql b/dbt_subprojects/daily_spellbook/models/_projects/lifi/avalanche/lifi_avalanche_transfers.sql new file mode 100644 index 00000000000..87e7b397c96 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/lifi/avalanche/lifi_avalanche_transfers.sql @@ -0,0 +1,38 @@ +{{ config( + schema = 'lifi_avalanche', + alias = 'transfers', + materialized = 'view' + ) +}} + +with source_data as ( + select + contract_address, + evt_tx_hash, + evt_index, + evt_block_time, + evt_block_number, + json_extract_scalar(bridgeData, '$.transactionId') as transactionId, + json_extract_scalar(bridgeData, '$.bridge') as bridge, + json_extract_scalar(bridgeData, '$.integrator') as integrator, + json_extract_scalar(bridgeData, '$.referrer') as referrer, + json_extract_scalar(bridgeData, '$.sendingAssetId') as sendingAssetId, + json_extract_scalar(bridgeData, '$.receiver') as receiver, + json_extract_scalar(bridgeData, '$.minAmount') as minAmount, + json_extract_scalar(bridgeData, '$.destinationChainId') as destinationChainId, + 'avalanche' as source_chain + from {{ source('lifi_avalanche', 'LiFiDiamond_v2_evt_LiFiTransferStarted') }} +), +transactions as ( + select + "from" as sender, + hash as tx_hash + from {{ source('avalanche_c', 'transactions') }} +) + +select + s.*, + t.sender +from source_data s +inner join transactions t + on s.evt_tx_hash = t.tx_hash diff --git a/dbt_subprojects/daily_spellbook/models/_projects/lifi/bnb/lifi_bnb_transfers.sql b/dbt_subprojects/daily_spellbook/models/_projects/lifi/bnb/lifi_bnb_transfers.sql new file mode 100644 index 00000000000..af8ca6eb0b8 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/lifi/bnb/lifi_bnb_transfers.sql @@ -0,0 +1,38 @@ +{{ config( + schema = 'lifi_bnb', + alias = 'transfers', + materialized = 'view' + ) +}} + +with source_data as ( + select + contract_address, + evt_tx_hash, + evt_index, + evt_block_time, + evt_block_number, + json_extract_scalar(bridgeData, '$.transactionId') as transactionId, + json_extract_scalar(bridgeData, '$.bridge') as bridge, + json_extract_scalar(bridgeData, '$.integrator') as integrator, + json_extract_scalar(bridgeData, '$.referrer') as referrer, + json_extract_scalar(bridgeData, '$.sendingAssetId') as sendingAssetId, + json_extract_scalar(bridgeData, '$.receiver') as receiver, + json_extract_scalar(bridgeData, '$.minAmount') as minAmount, + json_extract_scalar(bridgeData, '$.destinationChainId') as destinationChainId, + 'bnb' as source_chain + from {{ source('lifi_bnb', 'LiFiDiamond_v2_evt_LiFiTransferStarted') }} +), +transactions as ( + select + "from" as sender, + hash as tx_hash + from {{ source('bnb', 'transactions') }} +) + +select + s.*, + t.sender +from source_data s +inner join transactions t + on s.evt_tx_hash = t.tx_hash diff --git a/dbt_subprojects/daily_spellbook/models/_projects/lifi/ethereum/lifi_ethereum_transfers.sql b/dbt_subprojects/daily_spellbook/models/_projects/lifi/ethereum/lifi_ethereum_transfers.sql new file mode 100644 index 00000000000..a1c36d2da7d --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/lifi/ethereum/lifi_ethereum_transfers.sql @@ -0,0 +1,38 @@ +{{ config( + schema = 'lifi_ethereum', + alias = 'transfers', + materialized = 'view' + ) +}} + +with source_data as ( + select + contract_address, + evt_tx_hash, + evt_index, + evt_block_time, + evt_block_number, + json_extract_scalar(bridgeData, '$.transactionId') as transactionId, + json_extract_scalar(bridgeData, '$.bridge') as bridge, + json_extract_scalar(bridgeData, '$.integrator') as integrator, + json_extract_scalar(bridgeData, '$.referrer') as referrer, + json_extract_scalar(bridgeData, '$.sendingAssetId') as sendingAssetId, + json_extract_scalar(bridgeData, '$.receiver') as receiver, + json_extract_scalar(bridgeData, '$.minAmount') as minAmount, + json_extract_scalar(bridgeData, '$.destinationChainId') as destinationChainId, + 'ethereum' as source_chain + from {{ source('lifi_ethereum', 'LiFiDiamond_v2_evt_LiFiTransferStarted') }} +), +transactions as ( + select + "from" as sender, + hash as tx_hash + from {{ source('ethereum', 'transactions') }} +) + +select + s.*, + t.sender +from source_data s +inner join transactions t + on s.evt_tx_hash = t.tx_hash diff --git a/dbt_subprojects/daily_spellbook/models/_projects/lifi/fantom/lifi_fantom_transfers.sql b/dbt_subprojects/daily_spellbook/models/_projects/lifi/fantom/lifi_fantom_transfers.sql new file mode 100644 index 00000000000..31fe5c038f2 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/lifi/fantom/lifi_fantom_transfers.sql @@ -0,0 +1,38 @@ +{{ config( + schema = 'lifi_fantom', + alias = 'transfers', + materialized = 'view' + ) +}} + +with source_data as ( + select + contract_address, + evt_tx_hash, + evt_index, + evt_block_time, + evt_block_number, + json_extract_scalar(bridgeData, '$.transactionId') as transactionId, + json_extract_scalar(bridgeData, '$.bridge') as bridge, + json_extract_scalar(bridgeData, '$.integrator') as integrator, + json_extract_scalar(bridgeData, '$.referrer') as referrer, + json_extract_scalar(bridgeData, '$.sendingAssetId') as sendingAssetId, + json_extract_scalar(bridgeData, '$.receiver') as receiver, + json_extract_scalar(bridgeData, '$.minAmount') as minAmount, + json_extract_scalar(bridgeData, '$.destinationChainId') as destinationChainId, + 'fantom' as source_chain + from {{ source('lifi_fantom', 'LiFiDiamond_v2_evt_LiFiTransferStarted') }} +), +transactions as ( + select + "from" as sender, + hash as tx_hash + from {{ source('fantom', 'transactions') }} +) + +select + s.*, + t.sender +from source_data s +inner join transactions t + on s.evt_tx_hash = t.tx_hash diff --git a/dbt_subprojects/daily_spellbook/models/_projects/lifi/gnosis/lifi_gnosis_transfers.sql b/dbt_subprojects/daily_spellbook/models/_projects/lifi/gnosis/lifi_gnosis_transfers.sql new file mode 100644 index 00000000000..4b1748fe7bb --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/lifi/gnosis/lifi_gnosis_transfers.sql @@ -0,0 +1,38 @@ +{{ config( + schema = 'lifi_gnosis', + alias = 'transfers', + materialized = 'view' + ) +}} + +with source_data as ( + select + contract_address, + evt_tx_hash, + evt_index, + evt_block_time, + evt_block_number, + json_extract_scalar(bridgeData, '$.transactionId') as transactionId, + json_extract_scalar(bridgeData, '$.bridge') as bridge, + json_extract_scalar(bridgeData, '$.integrator') as integrator, + json_extract_scalar(bridgeData, '$.referrer') as referrer, + json_extract_scalar(bridgeData, '$.sendingAssetId') as sendingAssetId, + json_extract_scalar(bridgeData, '$.receiver') as receiver, + json_extract_scalar(bridgeData, '$.minAmount') as minAmount, + json_extract_scalar(bridgeData, '$.destinationChainId') as destinationChainId, + 'gnosis' as source_chain + from {{ source('lifi_gnosis', 'LiFiDiamond_v2_evt_LiFiTransferStarted') }} +), +transactions as ( + select + "from" as sender, + hash as tx_hash + from {{ source('gnosis', 'transactions') }} +) + +select + s.*, + t.sender +from source_data s +inner join transactions t + on s.evt_tx_hash = t.tx_hash diff --git a/dbt_subprojects/daily_spellbook/models/_projects/lifi/schema.yml b/dbt_subprojects/daily_spellbook/models/_projects/lifi/schema.yml new file mode 100644 index 00000000000..0e5386681d6 --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/lifi/schema.yml @@ -0,0 +1,67 @@ +version: 2 + +models: + - name: lifi_ethereum_transfers + description: "Ethereum LiFi transfer events" + columns: &common_columns + - name: contract_address + description: "Contract address of the LiFi Diamond" + - name: evt_tx_hash + description: "Transaction hash" + tests: + - unique: + where: "evt_index IS NOT NULL" + - name: evt_index + description: "Event index in the transaction" + - name: evt_block_time + description: "Block timestamp of the event" + - name: evt_block_number + description: "Block number of the event" + - name: transactionId + description: "Unique identifier for the transfer transaction" + - name: bridge + description: "Bridge protocol used" + - name: integrator + description: "Integration partner" + - name: referrer + description: "Referrer address" + - name: sendingAssetId + description: "Source token address" + - name: receiver + description: "Recipient address" + - name: minAmount + description: "Minimum amount to be received" + - name: destinationChainId + description: "Target chain ID for the transfer" + - name: source_chain + description: "Source blockchain" + - name: sender + description: "Address that initiated the transaction" + + - name: lifi_arbitrum_transfers + description: "Arbitrum LiFi transfer events" + columns: *common_columns + + - name: lifi_avalanche_transfers + description: "Avalanche LiFi transfer events" + columns: *common_columns + + - name: lifi_bnb_transfers + description: "BNB Chain LiFi transfer events" + columns: *common_columns + + - name: lifi_fantom_transfers + description: "Fantom LiFi transfer events" + columns: *common_columns + + - name: lifi_gnosis_transfers + description: "Gnosis Chain LiFi transfer events" + columns: *common_columns + + - name: lifi_zksync_transfers + description: "zkSync LiFi transfer events" + columns: *common_columns + + - name: LiFiDiamond_v2_evt_LiFiTransferStarted + description: "Combined LiFi transfer events across all supported chains" + columns: *common_columns diff --git a/dbt_subprojects/daily_spellbook/models/_projects/lifi/zksync/lifi_zksync_transfers.sql b/dbt_subprojects/daily_spellbook/models/_projects/lifi/zksync/lifi_zksync_transfers.sql new file mode 100644 index 00000000000..ed2514140ee --- /dev/null +++ b/dbt_subprojects/daily_spellbook/models/_projects/lifi/zksync/lifi_zksync_transfers.sql @@ -0,0 +1,38 @@ +{{ config( + schema = 'lifi_zksync', + alias = 'transfers', + materialized = 'view' + ) +}} + +with source_data as ( + select + contract_address, + evt_tx_hash, + evt_index, + evt_block_time, + evt_block_number, + json_extract_scalar(bridgeData, '$.transactionId') as transactionId, + json_extract_scalar(bridgeData, '$.bridge') as bridge, + json_extract_scalar(bridgeData, '$.integrator') as integrator, + json_extract_scalar(bridgeData, '$.referrer') as referrer, + json_extract_scalar(bridgeData, '$.sendingAssetId') as sendingAssetId, + json_extract_scalar(bridgeData, '$.receiver') as receiver, + json_extract_scalar(bridgeData, '$.minAmount') as minAmount, + json_extract_scalar(bridgeData, '$.destinationChainId') as destinationChainId, + 'zksync' as source_chain + from {{ source('lifi_zksync', 'LiFiDiamond_v2_evt_LiFiTransferStarted') }} +), +transactions as ( + select + "from" as sender, + hash as tx_hash + from {{ source('zksync', 'transactions') }} +) + +select + s.*, + t.sender +from source_data s +inner join transactions t + on s.evt_tx_hash = t.tx_hash diff --git a/sources/lifi/sources.yml b/sources/lifi/sources.yml new file mode 100644 index 00000000000..87486c607d9 --- /dev/null +++ b/sources/lifi/sources.yml @@ -0,0 +1,56 @@ +version: 2 + +sources: + - name: lifi_ethereum + description: "Ethereum LiFi events" + tables: + - name: LiFiDiamond_v2_evt_LiFiTransferStarted + columns: &common_columns + - name: contract_address + description: "Contract address of the LiFi Diamond" + - name: evt_tx_hash + description: "Transaction hash of the event" + - name: evt_index + description: "Event index in the transaction" + - name: evt_block_time + description: "Timestamp of the block when the event was emitted" + - name: evt_block_number + description: "Block number when the event was emitted" + - name: bridgeData + description: "JSON data containing bridge transfer information including transactionId, bridge, integrator, referrer, sendingAssetId, receiver, minAmount, and destinationChainId" + + - name: lifi_arbitrum + description: "Arbitrum LiFi events" + tables: + - name: LiFiDiamond_v2_evt_LiFiTransferStarted + columns: *common_columns + + - name: lifi_avalanche_c + description: "Avalanche C-Chain LiFi events" + tables: + - name: LiFiDiamond_v2_evt_LiFiTransferStarted + columns: *common_columns + + - name: lifi_bnb + description: "BNB Chain LiFi events" + tables: + - name: LiFiDiamond_v2_evt_LiFiTransferStarted + columns: *common_columns + + - name: lifi_fantom + description: "Fantom LiFi events" + tables: + - name: LiFiDiamond_v2_evt_LiFiTransferStarted + columns: *common_columns + + - name: lifi_gnosis + description: "Gnosis Chain LiFi events" + tables: + - name: LiFiDiamond_v2_evt_LiFiTransferStarted + columns: *common_columns + + - name: lifi_zksync + description: "zkSync LiFi events" + tables: + - name: LiFiDiamond_v2_evt_LiFiTransferStarted + columns: *common_columns