Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[swell] - add base (not the chain) swell rsweth withdrawals tables #7179

Merged
merged 14 commits into from
Nov 28, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
version: 2

models:
- name: swell_rsweth_ethereum_withdrawals
meta:
blockchain: ethereum
project: swell
contributors: maybeYonas

config:
tags: ['swell', 'restaking', 'lrt', 'withdrawals']
description: "rswETH withdrawals"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- token_id
- check_seed:
seed_file: ref('swell_rsweth_ethereum_withdrawals_seed')
match_columns:
- token_id
check_columns:
- request_tx_hash
- request_block_number
- request_index
- owner
- rswETH_amount
- rswETH_request_rate
- processed_tx_hash
- processed_block_number
- processed_index
- rswETH_processed_rate
- claim_tx_hash
- claim_block_number
- claim_index
- ETH_amount

columns:
- &request_block_time
name: request_block_time
description: "timestamp at withdrawal request"
- &request_tx_hash
name: request_tx_hash
description: "hash of tx at withdrawal request"
- &request_block_number
name: request_block_number
description: "block at withdrawal request"
- &request_index
name: request_index
description: "event index at at withdrawal request"
- &token_id
name: token_id
description: "unique id of withdrawal"
- &owner
name: owner
description: "owner of withdrawn eth"
- &rswETH_amount
name: rswETH_amount
description: "amount of rsweth burned"
- &rswETH_request_rate
name: rswETH_request_rate
description: "rsweth to eth rate at withdrawal request"
- &processed_block_time
name: processed_block_time
description: "timestamp at withdrawal ready for completion"
- &processed_tx_hash
name: processed_tx_hash
description: "hash of tx at withdrawal ready for completion"
- &processed_block_number
name: processed_block_number
description: "block at withdrawal ready for completion"
- &processed_index
name: processed_index
description: "event index at at withdrawal ready for completion"
- &rswETH_processed_rate
name: rswETH_processed_rate
description: "rsweth to eth rate at withdrawal completion"
- &claim_block_time
name: claim_block_time
description: "timestamp at withdrawal claimed"
- &claim_tx_hash
name: claim_tx_hash
description: "hash of tx at withdrawal claimed"
- &claim_block_number
name: claim_block_number
description: "block at withdrawal claimed"
- &claim_index
name: claim_index
description: "event index at at withdrawal claimed"
- &ETH_amount
name: ETH_amount
description: "eth amount claimed by user"
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{{ config(
schema = 'swell_rsweth_ethereum',
alias = 'withdrawals',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['token_id'],
post_hook='{{ expose_spells(\'["ethereum"]\',
"project",
"swell",
\'["maybeYonas"]\') }}'
)
}}

{% set incremental %}
where evt_block_time >= (
select min(request_block_time)
from {{ this }}
where claim_block_time is null
)
{% endset %}

with
rsweth_decoded_withdrawal_requests as (
select
evt_block_time, evt_tx_hash, evt_block_number, evt_index,
lastTokenIdProcessed,
owner,
tokenId,
amount,
timestamp,
rateWhenCreated
from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawRequestCreated')}}
-- from swell_v3_ethereum.RswEXIT_evt_WithdrawRequestCreated
{% if is_incremental() %}
{{incremental}}
{% endif %}
),
rsweth_decoded_withdrawal_claimed as (
select
evt_block_time, evt_tx_hash, evt_block_number, evt_index,
owner,
tokenId,
exitClaimedETH
from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawalClaimed')}}
-- from swell_v3_ethereum.RswEXIT_evt_WithdrawalClaimed
{% if is_incremental() %}
{{incremental}}
{% endif %}

),
rsweth_decoded_withdrawal_processed as (
select
evt_block_time, evt_tx_hash, evt_block_number, evt_index,
fromTokenId,
toTokenId,
processedRate,
processedExitingETH,
processedExitedETH
from {{source ('swell_v3_ethereum', 'RswEXIT_evt_WithdrawalsProcessed')}}
-- from swell_v3_ethereum.RswEXIT_evt_WithdrawalsProcessed
{% if is_incremental() %}
{{incremental}}
{% endif %}
)

select
r.evt_block_time as request_block_time,
r.evt_tx_hash as request_tx_hash,
r.evt_block_number as request_block_number,
r.evt_index as request_index,
r.tokenId as token_id,
r.owner as owner,
r.amount/1e18 as rswETH_amount,
r.rateWhenCreated/1e18 as rswETH_request_rate,

p.evt_block_time as processed_block_time,
p.evt_tx_hash as processed_tx_hash,
p.evt_block_number as processed_block_number,
p.evt_index as processed_index,
p.processedRate/1e18 as rswETH_processed_rate,

c.evt_block_time as claim_block_time,
c.evt_tx_hash as claim_tx_hash,
c.evt_block_number as claim_block_number,
c.evt_index as claim_index,
c.exitClaimedETH/1e18 as ETH_amount
from rsweth_decoded_withdrawal_requests r
left join rsweth_decoded_withdrawal_processed p
on r.tokenId >= p.fromTokenId
and r.tokenId <= p.toTokenId
left join rsweth_decoded_withdrawal_claimed c
on r.tokenId = c.tokenId
order by 1 desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 2

seeds:
- name: swell_rsweth_ethereum_withdrawals_seed
config:
column_types:
request_block_time: timestamp
request_tx_hash: varbinary
request_block_number: bigint
request_index: integer
token_id: integer
owner: varbinary
rswETH_amount: double
rswETH_request_rate: double
processed_block_time: timestamp
processed_tx_hash: varbinary
processed_block_number: bigint
processed_index: integer
rswETH_processed_rate: double
claim_block_time: timestamp
claim_tx_hash: varbinary
claim_block_number: bigint
claim_index: integer
ETH_amount: double
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
request_block_time,request_tx_hash,request_block_number,request_index,token_id,owner,rswETH_amount,rswETH_request_rate,processed_block_time,processed_tx_hash,processed_block_number,processed_index,rswETH_processed_rate,claim_block_time,claim_tx_hash,claim_block_number,claim_index,ETH_amount
2024-11-12 06:57:47.000 UTC,0x978742baca60c9f02eec6f8328ee77abb85716eb111d340497315f077f049388,21169958,227,3007,0xc77c6375e9fd581701425a6fb70bf371fb1cba28,500.00,1.023476642102901592,2024-11-21 01:09:47.000 UTC,0x9a0ac005f69cd7df2f10134ae5004a666c0ceb1baf034fdb41460439f02b684d,21232733,167,1.024494608040389206,2024-11-22 02:55:11.000 UTC,0x0fd5c4551eda43ad93f6833e0f5463afac8e88d30e3263cabcf4da9477b81fbf,21240420,274,511.738321051450796
2024-11-12 06:56:47.000 UTC,0xd0a7cd3f2f67cca12f2fe22ef7a5f0df922c1716d2f894a8c20406fdf01fd9dd,21169953,461,3006,0xc77c6375e9fd581701425a6fb70bf371fb1cba28,500.00,1.023476642102901592,2024-11-21 01:09:47.000 UTC,0x9a0ac005f69cd7df2f10134ae5004a666c0ceb1baf034fdb41460439f02b684d,21232733,167,1.024494608040389206,2024-11-22 02:54:35.000 UTC,0xf4aa4a769d39d6aadc54591eca47f59e688487580ef55f5bf4b21880bce16d3e,21240417,322,511.738321051450796
70 changes: 70 additions & 0 deletions sources/swell/rsweth/ethereum/swell_rsweth_ethereum_sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
version: 2

sources:
- name: swell_v3_ethereum
description: "swell decoded tables of ethereum contract"
tables:
- name: RswEXIT_evt_WithdrawRequestCreated
description: 'decoded table on `WithdrawRequestCreated` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064`. event emitted when a user initiates a new withdrawal request'
columns:
- &rswexit_contract_address
name: contract_address
description: 'RswExit contract address'
- &evt_tx_hash
name: evt_tx_hash
description: 'transaction hash of event'
- &evt_index
name: evt_index
description: 'index of event within block'
- &evt_block_time
name: evt_block_time
description: 'timestamp of blocktime in UTC'
- &evt_block_number
name: evt_block_number
description: 'block number containing transaction'
- name: lastTokenIdProcessed
description: 'last processed withdrawal'
- &rswexit_owner
name: owner
description: 'owner of rsweth burned'
- &rswexit_tokenid
name: tokenId
description: 'unique id for withdrawal processing'
- name: amount
description: 'amount of rsweth burned'
- name: timestamp
description: 'timestamp of withdrawal request'
- name: rateWhenCreated
description: 'rsweth-eth rate at withdrawal request'

- name: RswEXIT_evt_WithdrawalsProcessed
description: 'decoded table on `WithdrawalsProcessed` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064`. event emitted when the protocol processes the withdrawal from beaconchain and make it available for user to claim'
columns:
- *rswexit_contract_address
- *evt_tx_hash
- *evt_index
- *evt_block_time
- *evt_block_number
- name: fromTokenId
description: 'first token_id of withdrawals processed in this batch'
- name: toTokenId
description: 'last token_id of withdrawals processed in this batch'
- name: processedRate
description: 'rsweth-eth rate at which withdrawal is processed'
- name: processedExitingETH
description: 'amount of eth exiting in current batch'
- name: processedExitedETH
description: 'amount of eth exited'

- name: RswEXIT_evt_WithdrawalClaimed
description: 'decoded table on `WithdrawalClaimed` event emitted from RswEXIT contract `0x58749C46Ffe97e4d79508a2C781C440f4756f064`. event emitted when a user claims the ETH withdrawn'
columns:
- *rswexit_contract_address
- *evt_tx_hash
- *evt_index
- *evt_block_time
- *evt_block_number
- *rswexit_owner
- *rswexit_tokenid
- name: exitClaimedETH
description: 'amout of eth claimed'