Skip to content

Commit

Permalink
Add bridges of LiFi across chains
Browse files Browse the repository at this point in the history
  • Loading branch information
lequangphu committed Nov 23, 2024
1 parent db1fe05 commit 85a0295
Show file tree
Hide file tree
Showing 10 changed files with 454 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
67 changes: 67 additions & 0 deletions dbt_subprojects/daily_spellbook/models/_projects/lifi/schema.yml
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 85a0295

Please sign in to comment.