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

Pika Protocol v4 added for optimism #7427

Merged
merged 24 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4aa160b
Pika Protocol v4 added for optimism
PatelPrinci Jan 7, 2025
bfbcd20
Merge branch 'main' into pika-protocol-v4-optimism
PatelPrinci Jan 7, 2025
2a2f5a9
changed post_hook format and replaced the incremental_predicate for i…
PatelPrinci Jan 7, 2025
5baece0
Applied the new post_hook in the config and changed the incremental_p…
PatelPrinci Jan 7, 2025
5733c18
Seed File Data added for V4
PatelPrinci Jan 7, 2025
53390ef
Fixed valid DATE literal issue
PatelPrinci Jan 7, 2025
aef0807
Fixing evt block time time column issue
PatelPrinci Jan 7, 2025
93150e6
adding previous version of incremental filter
PatelPrinci Jan 7, 2025
f5acf5b
adding previous version of incremental filter
PatelPrinci Jan 7, 2025
758fb23
Merge branch 'main' into pika-protocol-v4-optimism
PatelPrinci Jan 8, 2025
d4f8a83
nothing changed
PatelPrinci Jan 8, 2025
6fee002
Merge branch 'main' into pika-protocol-v4-optimism
PatelPrinci Jan 10, 2025
cd8eab6
added incremental predicate
PatelPrinci Jan 16, 2025
7908520
added incremental filters
PatelPrinci Jan 16, 2025
9f7007c
removed unwanted character
PatelPrinci Jan 16, 2025
7377220
added incremental filter in last
PatelPrinci Jan 18, 2025
d5e6af4
Merge branch 'main' into pika-protocol-v4-optimism
PatelPrinci Jan 18, 2025
6169aec
fix space indentication error
PatelPrinci Jan 18, 2025
39a9598
fix space indentication error
PatelPrinci Jan 18, 2025
1c59300
fix product id issue
PatelPrinci Jan 18, 2025
79f5b12
added cast to else part of product id case
PatelPrinci Jan 20, 2025
a9aa419
changed unique keys to simplify
PatelPrinci Jan 23, 2025
e73ce23
changed the contributors name
PatelPrinci Jan 23, 2025
215893c
Merge branch 'main' into pika-protocol-v4-optimism
PatelPrinci Jan 23, 2025
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
Expand Up @@ -4,14 +4,15 @@
post_hook='{{ expose_spells(\'["optimism"]\',
"project",
"pika",
\'["msilb7", "drethereum", "rplust"]\') }}'
\'["msilb7", "drethereum", "rplust", "princi"]\') }}'
)
}}

{% set pika_optimism_perpetual_trade_models = [
ref('pika_v1_optimism_perpetual_trades')
, ref('pika_v2_optimism_perpetual_trades')
, ref('pika_v3_optimism_perpetual_trades')
, ref('pika_v4_optimism_perpetual_trades')
] %}

SELECT *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ models:
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_date
- blockchain
- project
- version
- tx_hash
- evt_index
columns:
Expand Down Expand Up @@ -169,6 +165,51 @@ models:
- *tx_to
- *evt_index
- *block_month

- name: pika_v4_optimism_perpetual_trades
meta:
blockchain: optimism
sector: perpetual
project: pika_v4
contributors: princi
config:
tags: ['optimism', 'pika, pika_v4', 'perpetuals', 'perps']
description: >
Pika_v3 perpetuals trades/swaps on Optimism
data_tests:
- check_perpetuals_seed:
blockchain: optimism
project: Pika
version: 4
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_date
- blockchain
- project
- version
- tx_hash
- evt_index
Comment on lines +184 to +191
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match the simplified unique_key:

Suggested change
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_date
- blockchain
- project
- version
- tx_hash
- evt_index
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index

columns:
- *blockchain
- *block_time
- *virtual_asset
- *underlying_asset
- *market
- *market_address
- *volume_usd
- *fee_usd
- *margin_usd
- *trade
- *project
- *version
- *frontend
- *trader
- *volume_raw
- *tx_hash
- *tx_from
- *tx_to
- *evt_index
- *block_month

- name: pika_optimism_perpetual_trades
meta:
Expand Down
Hosuke marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{{ config(
schema = 'pika_v4_optimism',
alias = 'perpetual_trades',
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['tx_hash', 'evt_index'],
post_hook='{{ expose_spells(blockchains = \'["optimism"]\',
spell_type = "project",
spell_name = "pika",
contributors = \'["principatel"]\') }}'
)}}

{% set project_start_date = '2021-11-22' %}

WITH positions AS (
SELECT
positionId
,user AS user
,productId
,CAST(isLong AS VARCHAR) AS isLong
,price
,oraclePrice
,margin
,leverage
,fee
,contract_address
,evt_tx_hash
,evt_index
,evt_block_time
,evt_block_number
,'4' AS version
FROM {{ source('pika_protocol_v4_optimism', 'PikaPerpV4_evt_NewPosition') }}
{% if is_incremental() %}
WHERE {{incremental_predicate('evt_block_time')}}
{% endif %}

UNION ALL
--closing positions
SELECT
positionId
,user
,productId
,'close' AS action
,price
,entryPrice
,margin
,leverage
,fee
,contract_address
,evt_tx_hash
,evt_index
,evt_block_time
,evt_block_number
,'4' AS version
FROM {{ source('pika_protocol_v4_optimism', 'PikaPerpV4_evt_ClosePosition') }}
{% if is_incremental() %}
WHERE {{incremental_predicate('evt_block_time')}}
{% endif %}
),

perps AS (
SELECT
evt_block_time AS block_time
,evt_block_number AS block_number

,CASE
WHEN productId = UINT256 '1' OR productId = UINT256 '16' THEN 'ETH'
WHEN productId = UINT256 '2' OR productId = UINT256 '17' THEN 'BTC'
WHEN productId = UINT256 '3' OR productId = UINT256 '18' THEN 'LINK'
WHEN productId = UINT256 '4' OR productId = UINT256 '19' THEN 'SNX'
WHEN productId = UINT256 '5' OR productId = UINT256 '20' THEN 'SOL'
WHEN productId = UINT256 '6' OR productId = UINT256 '21' THEN 'AVAX'
WHEN productId = UINT256 '7' OR productId = UINT256 '22' THEN 'MATIC'
WHEN productId = UINT256 '8' THEN 'LUNA'
WHEN productId = UINT256 '9' OR productId = UINT256 '23' THEN 'AAVE'
WHEN productId = UINT256 '10' OR productId = UINT256 '24' THEN 'APE'
WHEN productId = UINT256 '11' OR productId = UINT256 '25' THEN 'AXS'
WHEN productId = UINT256 '12' OR productId = UINT256 '26' THEN 'UNI'
ELSE 'product_id_' || CAST(productId AS VARCHAR)
END AS virtual_asset
,CASE
WHEN productId = UINT256 '1' OR productId = UINT256 '16' THEN 'ETH'
WHEN productId = UINT256 '2' OR productId = UINT256 '17' THEN 'BTC'
WHEN productId = UINT256 '3' OR productId = UINT256 '18' THEN 'LINK'
WHEN productId = UINT256 '4' OR productId = UINT256 '19' THEN 'SNX'
WHEN productId = UINT256 '5' OR productId = UINT256 '20' THEN 'SOL'
WHEN productId = UINT256 '6' OR productId = UINT256 '21' THEN 'AVAX'
WHEN productId = UINT256 '7' OR productId = UINT256 '22' THEN 'MATIC'
WHEN productId = UINT256 '8' THEN 'LUNA'
WHEN productId = UINT256 '9' OR productId = UINT256 '23' THEN 'AAVE'
WHEN productId = UINT256 '10' OR productId = UINT256 '24' THEN 'APE'
WHEN productId = UINT256 '11' OR productId = UINT256 '25' THEN 'AXS'
WHEN productId = UINT256 '12' OR productId = UINT256 '26' THEN 'UNI'
ELSE 'product_id_' || CAST(productId AS VARCHAR)
END AS underlying_asset
,CASE
WHEN productId = UINT256 '1' OR productId = UINT256 '16' THEN 'ETH'
WHEN productId = UINT256 '2' OR productId = UINT256 '17' THEN 'BTC'
WHEN productId = UINT256 '3' OR productId = UINT256 '18' THEN 'LINK'
WHEN productId = UINT256 '4' OR productId = UINT256 '19' THEN 'SNX'
WHEN productId = UINT256 '5' OR productId = UINT256 '20' THEN 'SOL'
WHEN productId = UINT256 '6' OR productId = UINT256 '21' THEN 'AVAX'
WHEN productId = UINT256 '7' OR productId = UINT256 '22' THEN 'MATIC'
WHEN productId = UINT256 '8' THEN 'LUNA-USD'
WHEN productId = UINT256 '9' OR productId = UINT256 '23' THEN 'AAVE'
WHEN productId = UINT256 '10' OR productId = UINT256 '24' THEN 'APE'
WHEN productId = UINT256 '11' OR productId = UINT256 '25' THEN 'AXS'
WHEN productId = UINT256 '12' OR productId = UINT256 '26' THEN 'UNI'
ELSE 'product_id_' || CAST(productId AS VARCHAR)
END AS market

,contract_address AS market_address
,(margin/1e8) * (leverage/1e8) AS volume_usd
,fee/1e8 AS fee_usd
,margin/1e8 AS margin_usd

,CASE
WHEN isLong = 'true' THEN 'long'
WHEN isLong = 'false' THEN 'short'
ELSE CAST(isLong as VARCHAR)
END AS trade

,'Pika' AS project
,version
,'Pika' AS frontend
,user AS trader
,margin * leverage AS volume_raw
,evt_tx_hash AS tx_hash
,evt_index
FROM positions
)

SELECT
'optimism' AS blockchain
,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
,perps.virtual_asset
,perps.underlying_asset
,perps.market
,perps.market_address
,perps.volume_usd
,perps.fee_usd
,perps.margin_usd
,perps.trade
,perps.project
,perps.version
,perps.frontend
,perps.trader
,CAST(perps.volume_raw as UINT256) as volume_raw
,perps.tx_hash
,tx."from" AS tx_from
,tx."to" AS tx_to
,perps.evt_index
FROM perps
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 >= DATE '{{project_start_date}}'
{% endif %}
{% if is_incremental() %}
AND {{incremental_predicate('tx.block_time')}}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ optimism,2022-08-31,MATIC,MATIC-USD,0xd5a8f233cbddb40368d55c3320644fb36e597002,s
optimism,2022-08-31,MATIC,MATIC-USD,0xd5a8f233cbddb40368d55c3320644fb36e597002,short,Pika,3,0xd50c2884035201c4e5643d1c4c4cd65e6c3dcbb9e0f3bee741d07a5e02eb3a9d
optimism,2022-03-09,LINK,LINK-USD,0x365324e5045df8c886ebe6ad5449f5ceb5881a40,close,Pika,1,0x0d3906c14ebfc0b6da28e46699d54f7ba3ebdeaba0be90ddae8dfc5e0245adbc
optimism,2022-01-13,BTC,BTC-USD,0x365324e5045df8c886ebe6ad5449f5ceb5881a40,long,Pika,1,0x60eb7268d68583307e262f39296acd179b84de52661036369ae5c95d8231a198
optimism,2023-10-12,BTC,BTC,0x9b86b2be8edb2958089e522fe0eb7dd5935975ab,close,Pika,4,0xf0196ed2f3d1f65d78eab4d811b346ca29f392821241ffd522ee840a3f40f166
optimism,2023-10-12,BTC,BTC,0x9b86b2be8edb2958089e522fe0eb7dd5935975ab,long,Pika,4,0x325c7e6b0fdd55a793f1572e7e103098cbb159bb5d2c42fc9501cbd968852718
avalanche_c,2023-01-18,WAVAX,WAVAX,0x9ab2de34a33fb459b538c43f251eb825645e8595,open-long,gmx,1,0xfaef719c389269fd6a337f198432a5aa7e980fd9794a51bff163ca5fe66915b4
avalanche_c,2023-01-18,USDC,BTC.b-USDC,0x9ab2de34a33fb459b538c43f251eb825645e8595,open-short,gmx,1,0x0d0fe971ac1fc3fdee9f45477e263b44041d533461a790c69f3fba4de1ee4d58
arbitrum,2023-01-18,USDC,WBTC-USDC,0x489ee077994b6658eafa855c308275ead8097c4a,open-short,gmx,1,0x7451f1514a48d026d7065736539c521cdb7190d9eef6aacc27eebbe4b7387d47
Expand Down
8 changes: 8 additions & 0 deletions sources/pika/optimism/pika_optimism_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ sources:
- name: PikaPerpV3_evt_NewPosition
description: "Details the new positions opened"
- name: PikaPerpV3_evt_ClosePosition
description: "Details the swaps to close existing positions"

- name: pika_protocol_v4_optimism
description: Optimism decoded tables related to Pika Protocol v4
tables:
- name: PikaPerpV4_evt_NewPosition
description: "Details the new positions opened"
- name: PikaPerpV4_evt_ClosePosition
description: "Details the swaps to close existing positions"
Loading