Skip to content

Commit

Permalink
Add zksync to airdrops sector (duneanalytics#6456)
Browse files Browse the repository at this point in the history
* add zksync to airdrops sector

* add source

* fix column

* round amounts

* Update dbt_subprojects/daily_spellbook/models/_sector/airdrops/zksync/projects/zksync_zksync_airdrop_claims.sql

Co-authored-by: jeff-dude <[email protected]>

* Update dbt_subprojects/daily_spellbook/models/_sector/airdrops/zksync/projects/zksync_zksync_airdrop_claims.sql

Co-authored-by: jeff-dude <[email protected]>

* Update dbt_subprojects/daily_spellbook/models/_sector/airdrops/zksync/airdrop_zksync_claims.sql

Co-authored-by: jeff-dude <[email protected]>

---------

Co-authored-by: jeff-dude <[email protected]>
  • Loading branch information
lgingerich and jeff-dude authored Aug 7, 2024
1 parent 4b55c68 commit 94c1da5
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['blockchain', 'tx_hash', 'evt_index', 'recipient'],
post_hook='{{ expose_spells(\'["ethereum", "optimism", "arbitrum", "avalanche_c", "bnb", "gnosis"]\',
post_hook='{{ expose_spells(\'["ethereum", "optimism", "arbitrum", "avalanche_c", "bnb", "gnosis", "zksync"]\',
"sector",
"airdrop",
\'["hildobby"]\') }}'
\'["hildobby", "lgingerich"]\') }}'
)
}}

Expand All @@ -20,6 +20,7 @@
, ref('airdrop_avalanche_c_claims')
, ref('airdrop_bnb_claims')
, ref('airdrop_gnosis_claims')
, ref('airdrop_zksync_claims')
] %}


Expand All @@ -43,11 +44,10 @@ FROM (
, evt_index
FROM {{ airdrop_claims_model }}
{% if is_incremental() %}
WHERE block_time >= date_trunc('day', now() - interval '7' Day)
WHERE {{incremental_predicate('block_time')}}
{% endif %}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
)

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
tags = [ 'static'],
schema='airdrop',
alias = 'info',
post_hook='{{ expose_spells(\'["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum"]\',
post_hook='{{ expose_spells(\'["ethereum", "bnb", "avalanche_c", "gnosis", "optimism", "arbitrum", "lgingerich"]\',
"sector",
"dex",
\'["hildobby"]\') }}')
"airdrop",
\'["hildobby", "lgingerich"]\') }}')
}}

SELECT project, name, eligible_addresses, airdropped_total, circulating_supply_on_drop, max_supply, token_issued_by_protocol, x_username, CAST(airdrop_start AS TIMESTAMP) AS airdrop_start, CAST(airdrop_end AS TIMESTAMP) AS airdrop_end
Expand Down Expand Up @@ -60,5 +60,5 @@ FROM (VALUES
, ('jupiter', 'Jupiter', 957935, 2700000000, NULL, NULL, TRUE, 'JupiterExchange', '2024-01-01 00:00', NULL)
, ('aptos', 'Aptos', 124828, 450000000, NULL, NULL, TRUE, 'Aptos', '2022-10-01 00:00', NULL)
, ('jito', 'Jito', 13133, 439000000, NULL, NULL, TRUE, 'jito_sol', '2023-12-01 00:00', NULL)

) AS temp_table (project, name, eligible_addresses, circulating_supply_on_drop, max_supply, airdropped_total, token_issued_by_protocol, x_username, airdrop_start, airdrop_end)
, ('zksync', 'ZKsync Era', 693268, 3675000000, 3675000000, 21000000000, TRUE, 'zksync', '2024-06-17 06:45', NULL)
) AS temp_table (project, name, eligible_addresses, circulating_supply_on_drop, max_supply, airdropped_total, token_issued_by_protocol, x_username, airdrop_start, airdrop_end)
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ version: 2
models:
- name: airdrop_claims
meta:
blockchain: ethereum, optimism, arbitrum, avalanche_c, bnb, gnosis
blockchain: ethereum, optimism, arbitrum, avalanche_c, bnb, gnosis, zksync
sector: airdrop
project: addresses
contributors: hildobby
contributors: hildobby, lgingerich
config:
tags: ['table', 'airdrop', 'ethereum', 'optimism', 'arbitrum', 'avalanche_c', 'bnb', 'gnosis', 'claim']
tags: ['table', 'airdrop', 'ethereum', 'optimism', 'arbitrum', 'avalanche_c', 'bnb', 'gnosis', 'zksync', 'claim']
description: "List of claim transactions for all airdrops"
tests:
- dbt_utils.unique_combination_of_columns:
Expand Down Expand Up @@ -67,11 +67,11 @@ models:

- name: airdrop_info
meta:
blockchain: ethereum, bnb, avalanche_c, gnosis, optimism, arbitrum
sector: dex
contributors: hildobby
blockchain: ethereum, bnb, avalanche_c, gnosis, optimism, arbitrum, zksync
sector: airdrop
contributors: hildobby, lgingerich
config:
tags: ['airdrop', 'ethereum', 'bnb', 'avalanche_c', 'gnosis', 'optimism', 'arbitrum', 'info']
tags: ['airdrop', 'ethereum', 'bnb', 'avalanche_c', 'gnosis', 'optimism', 'arbitrum', 'zksync', 'info']
description: >
Airdrop info
tests:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: 2

models:
- name: airdrop_zksync_claims
meta:
blockchain: zksync
sector: airdrop
contributors: lgingerich
config:
tags: ['airdrop', 'zksync', 'claim']
description: "List of airdrop claim transactions on ZKsync Era"
columns:
- &blockchain
name: blockchain
description: "Blockchain"
- &block_time
name: block_time
description: "Block time of transaction"
- &block_number
name: block_number
description: "Block number of transaction"
- &project
name: project
description: "Project name"
- &airdrop_number
name: airdrop_number
description: "Airdrop identifier number"
- &recipient
name: recipient
description: "Airdrop recipient"
- &contract_address
name: contract_address
description: "Contract addressed used"
- &tx_hash
name: tx_hash
description: "Transaction hash"
- &amount_raw
name: amount_raw
description: "Raw amount of tokens"
- &amount_original
name: amount_original
description: "Original amount of tokens"
- &amount_usd
name: amount_usd
description: "USD value of tokens"
- &token_address
name: token_address
description: "Token address"
- &token_symbol
name: token_symbol
description: "Token symbol"
- &evt_index
name: evt_index
description: "Event index"
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{ config(
schema = 'airdrop_zksync',
alias = 'claims'
)
}}


{% set airdrop_claims_models = [
ref('zksync_zksync_airdrop_claims')
] %}


SELECT *
FROM (
{% for airdrop_claims_model in airdrop_claims_models %}
SELECT
blockchain
, block_time
, block_number
, project
, airdrop_number
, recipient
, contract_address
, tx_hash
, amount_raw
, amount_original
, amount_usd
, token_address
, token_symbol
, evt_index
FROM {{ airdrop_claims_model }}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: 2

models:
- name: zksync_zksync_airdrop_claims
meta:
blockchain: zksync
sector: airdrop
project: zksync
contributors: lgingerich
config:
tags: ['table', 'airdrop', 'zksync', 'claim']
description: "List of claim transactions for the $ZK airdrop"
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- recipient
- evt_index
columns:
- &blockchain
name: blockchain
description: "Blockchain"
- &block_time
name: block_time
description: "Block time of transaction"
- &block_number
name: block_number
description: "Block number of transaction"
- &project
name: project
description: "Project name"
- &airdrop_number
name: airdrop_number
description: "Airdrop identifier number"
- &recipient
name: recipient
description: "Airdrop recipient"
- &contract_address
name: contract_address
description: "Contract addressed used"
- &tx_hash
name: tx_hash
description: "Transaction hash"
- &amount_raw
name: amount_raw
description: "Raw amount of tokens"
- &amount_original
name: amount_original
description: "Original amount of tokens"
- &amount_usd
name: amount_usd
description: "USD value of tokens"
- &token_address
name: token_address
description: "Token address"
- &token_symbol
name: token_symbol
description: "Token symbol"
- &evt_index
name: evt_index
description: "Event index"
- &block_month
name: block_month
description: "Block month"
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{
config(

schema = 'zksync_zksync',
alias = 'airdrop_claims',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['recipient', 'tx_hash', 'evt_index']
)
}}

{% set token_address = '0x5A7d6b2F92C77FAD6CCaBd7EE0624E64907Eaf3E' %} -- ZK token

WITH early_price AS (
SELECT
MIN(minute) AS minute
, MIN_BY(price, minute) AS price
FROM {{ source('prices', 'usd') }}
WHERE blockchain = 'zksync'
AND contract_address = {{token_address}}
)

SELECT
'zksync' AS blockchain
, t.evt_block_time AS block_time
, t.evt_block_number AS block_number
, 'zksync' AS project
, 1 AS airdrop_number
, t.account AS recipient
, t.contract_address
, t.evt_tx_hash AS tx_hash
, t.amount as amount_raw
, ROUND(CAST(t.amount/POWER(10, 18) AS double), 0) AS amount_original
, CASE
WHEN t.evt_block_time >= (SELECT minute FROM early_price) THEN CAST(pu.price*t.amount/POWER(10, 18) AS double)
ELSE CAST((SELECT price FROM early_price)*t.amount/POWER(10, 18) AS double)
END AS amount_usd
, {{token_address}} AS token_address
, 'ZK' AS token_symbol
, t.evt_index
FROM {{ source('zksync_era_zksync', 'ZkMerkleDistributor_evt_Claimed') }} t
LEFT JOIN {{ source('prices','usd_forward_fill') }} pu ON pu.blockchain = 'zksync'
AND pu.contract_address = {{token_address}}
AND pu.minute = date_trunc('minute', t.evt_block_time)
{% if is_incremental() %}
AND {{incremental_predicate('pu.minute')}}
WHERE {{incremental_predicate('t.evt_block_time')}}
{% endif %}
9 changes: 9 additions & 0 deletions sources/zksync/zksync_zksync_sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2

sources:
- name: zksync_era_zksync
description: >
ZKsync contracts on ZKsync Era
tables:
- name: ZkMerkleDistributor_evt_Claimed
loaded_at_field: evt_block_time

0 comments on commit 94c1da5

Please sign in to comment.