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

Perpetuals Migration - #3 - Migrate Perpetual Protocol - Ready for review #4032

Merged
merged 6 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{ config(
tags=['dunesql'],
alias = alias('perpetual_trades'),
post_hook='{{ expose_spells(\'["optimism"]\',
"project",
Expand All @@ -17,6 +18,7 @@ FROM (
SELECT
blockchain
,block_date
,block_month
,block_time
,virtual_asset
,underlying_asset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ models:
name: market_address
description: "Contract address of the market"
tests:
- perpetual_trades_market_address_legacy:
perpetual_trades_seed_legacy: ref('perpetual_trades_seed_legacy')
- perpetual_trades_market_address:
perpetual_trades_seed: ref('perpetual_trades_seed')
- &volume_usd
name: volume_usd
description: "The size of the position taken for the swap in USD; already in absolute value and decimal normalized"
Expand Down Expand Up @@ -84,6 +84,9 @@ models:
- &evt_index
name: evt_index
description: "Event index number"
- &block_month
name: block_month
description: "Month of the transaction"

- name: perpetual_protocol_optimism_perpetual_trades
meta:
Expand Down Expand Up @@ -115,4 +118,5 @@ models:
- *tx_hash
- *tx_from
- *tx_to
- *evt_index
- *evt_index
- *block_month
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{ config(
tags=['dunesql'],
schema = 'perpetual_protocol_v2_optimism',
alias = alias('perpetual_trades'),
partition_by = ['block_date'],
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
Expand Down Expand Up @@ -43,21 +44,22 @@ WITH perps AS (
ON p.evt_tx_hash = co.call_tx_hash
AND co.call_success = true
{% if is_incremental() %}
AND co.call_block_time >= DATE_TRUNC("DAY", NOW() - INTERVAL '1 WEEK')
AND co.call_block_time >= DATE_TRUNC('DAY', NOW() - INTERVAL '7' Day)
{% endif %}
LEFT JOIN {{ source('perp_v2_optimism', 'MarketRegistry_evt_PoolAdded') }} AS pp
ON p.baseToken = pp.baseToken
{% if is_incremental() %}
WHERE p.evt_block_time >= DATE_TRUNC("DAY", NOW() - INTERVAL '1 WEEK')
WHERE p.evt_block_time >= DATE_TRUNC('DAY', NOW() - INTERVAL '7' Day)
{% endif %}
GROUP BY 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15
)

SELECT
'optimism' AS blockchain
,TRY_CAST(date_trunc('DAY', perps.block_time) AS date) AS block_date
,CAST(date_trunc('DAY', perps.block_time) AS date) AS block_date
,CAST(date_trunc('MONTH', perps.block_time) AS date) AS block_month
,perps.block_time
,COALESCE(e.symbol, CAST(perps.baseToken AS STRING)) AS virtual_asset
,COALESCE(e.symbol, CAST(perps.baseToken AS VARCHAR)) AS virtual_asset
,SUBSTRING(e.symbol, 2) AS underlying_asset
,CONCAT(e.symbol, '-', 'USD') AS market
,perps.market_address
Expand All @@ -71,8 +73,8 @@ SELECT
,perps.trader
,perps.volume_raw
,perps.tx_hash
,tx.from AS tx_from
,tx.to AS tx_to
,tx."from" AS tx_from
,tx."to" AS tx_to
,perps.evt_index
FROM perps
LEFT JOIN {{ ref('tokens_erc20') }} AS e
Expand All @@ -82,8 +84,8 @@ INNER JOIN {{ source('optimism', 'transactions') }} AS tx
ON perps.tx_hash = tx.hash
AND perps.block_number = tx.block_number
{% if not is_incremental() %}
AND tx.block_time >= '{{project_start_date}}'
AND tx.block_time >= DATE '{{project_start_date}}'
{% endif %}
{% if is_incremental() %}
AND tx.block_time >= DATE_TRUNC("DAY", NOW() - INTERVAL '1 WEEK')
AND tx.block_time >= DATE_TRUNC('DAY', NOW() - INTERVAL '7' Day)
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{ config(
tags=['dunesql'],
alias = alias('perpetual_trades'),
post_hook='{{ expose_spells(\'["optimism"]\',
"project",
Expand All @@ -17,6 +18,7 @@ FROM (
SELECT
blockchain
,block_date
,block_month
,block_time
,virtual_asset
,underlying_asset
Expand Down
5 changes: 4 additions & 1 deletion models/perpetual_protocol/perpetual_protocol_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ models:
description: "The address receiving the transaction; based on the optimism.transactions table"
- &evt_index
name: evt_index
description: "Event index number"
description: "Event index number"
- &block_month
name: block_month
description: "Month of the transaction"
2 changes: 1 addition & 1 deletion seeds/perpetual/trades/perpetual_trades_seed.csv
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ avalanche_c,2023-01-27,,,0x3cf47469298b1630c192b2c8d3ffa087abcac8b2,open-long,em
avalanche_c,2023-01-26,AVAX,AVAX,0x4e3535964cb5612a466d8bb25362d485452efcef,open-short,hubble_exchange,1,0x3f187beac116995fa84a8185fd5c220c9c0dd6b1b7af737ab83065ae3da81329
avalanche_c,2023-01-18,AVAX,AVAX,0x4e3535964cb5612a466d8bb25362d485452efcef,close-short,hubble_exchange,1,0x984182f9e697acc213bcaf6c87858ebe7e0cbeb99019a73b5100e0ec837e7e96
optimism,2023-02-26,DYDX,sDYDXPERP,0x139f94e4f0e1101c1464a321cba815c34d58b5d9,long,Synthetix,2,0xa9900b71d779aec64fc08fb96a770677e4b6402cc67ec5ab96e08baf25731b93
optimism,2023-02-26,ETH,sETHPERP,0x2b3bb4c683bfc5239b029131eef3b1d214478d93,short,Synthetix,2,0x67d7039204428c2c66e058c81fe6632261df3aba0ba04b82442ff2a62a6abbd9
optimism,2023-02-26,ETH,sETHPERP,0x2b3bb4c683bfc5239b029131eef3b1d214478d93,short,Synthetix,2,0x67d7039204428c2c66e058c81fe6632261df3aba0ba04b82442ff2a62a6abbd9