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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

PatelPrinci
Copy link
Contributor

Thank you for contributing to Spellbook 🪄

Please open the PR in draft and mark as ready when you want to request a review.

Description:

[...]


quick links for more information:

@github-actions github-actions bot marked this pull request as draft January 7, 2025 06:21
@github-actions github-actions bot added WIP work in progress dbt: hourly covers the hourly dbt subproject labels Jan 7, 2025
@PatelPrinci PatelPrinci marked this pull request as ready for review January 7, 2025 06:31
@github-actions github-actions bot added ready-for-review this PR development is complete, please review and removed WIP work in progress labels Jan 7, 2025
@0xRobin 0xRobin requested review from Hosuke and 0xRobin January 7, 2025 08:32
Comment on lines 71 to 93
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 CONCAT ('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'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there no way of getting these productId <> token symbols from onchain data?
If not I would make a separate model containing the static mapping and then join it in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there no way of getting these productId <> token symbols from onchain data? If not I would make a separate model containing the static mapping and then join it in here.

No, the productId and token symbols are not coming from on-chain data. They are part of a static mapping defined within the protocol's architecture, which cannot be queried directly on-chain.

I agree with your suggestion—it makes sense to create a separate model containing this static mapping and join it here for better maintainability and clarity. This will also simplify any future updates if new mappings are introduced.

Copy link
Collaborator

@Hosuke Hosuke left a comment

Choose a reason for hiding this comment

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

Comment on lines 10 to 13
post_hook='{{ expose_spells(\'["optimism"]\',
"project",
"pika",
\'["msilb7", "drethereum", "rplust","princi"]\') }}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can apply the new post_hook format here.
i.e.

post_hook='{{ expose_spells(blockchains = \'["fantom", "optimism"]\',

,'4' AS version
FROM {{ source('pika_protocol_v4_optimism', 'PikaPerpV4_evt_NewPosition') }}
{% if is_incremental() %}
WHERE evt_block_time >= DATE_TRUNC('DAY', NOW() - INTERVAL '7' Day)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can use incremental_predicate for incremental filters:

Suggested change
WHERE evt_block_time >= DATE_TRUNC('DAY', NOW() - INTERVAL '7' Day)
WHERE {{incremental_predicate('evt_block_time')}}

,'4' AS version
FROM {{ source('pika_protocol_v4_optimism', 'PikaPerpV4_evt_ClosePosition') }}
{% if is_incremental() %}
WHERE evt_block_time >= DATE_TRUNC('DAY', NOW() - INTERVAL '7' Day)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above.

AND tx.block_time >= DATE '{{project_start_date}}'
{% endif %}
{% if is_incremental() %}
AND tx.block_time >= DATE_TRUNC('DAY', NOW() - INTERVAL '7' Day)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above.

@Hosuke Hosuke added in review Assignee is currently reviewing the PR and removed ready-for-review this PR development is complete, please review labels Jan 7, 2025
@Hosuke
Copy link
Collaborator

Hosuke commented Jan 10, 2025

Please apply the incremental_predicate in incremental filters.

AND tx.block_time >= DATE '{{project_start_date}}'
{% endif %}
{% if is_incremental() %}
AND tx.block_time >= DATE_TRUNC('DAY', NOW() - INTERVAL '7' Day)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please fix the incremental filter.

Comment on lines 9 to 10
unique_key = ['block_date', 'blockchain', 'project', 'version', 'tx_hash', 'evt_index'],
post_hook='{{ expose_spells(blockchains = \'["optimism"]\',
Copy link
Collaborator

@Hosuke Hosuke Jan 18, 2025

Choose a reason for hiding this comment

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

Please be consistent in tab or space in all PRs. We prefer spaces.

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 CONCAT ('product_id_', CAST(productId as VARCHAR))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe

Suggested change
ELSE CONCAT ('product_id_', CAST(productId as VARCHAR))
'product_id_' || productId

Comment on lines 183 to 184
data_tests:
- dbt_utils.unique_combination_of_columns:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
data_tests:
- dbt_utils.unique_combination_of_columns:
data_tests:
- check_perpetuals_seed:
blockchain: optimism
project: Pika
version: 4
- dbt_utils.unique_combination_of_columns:

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_' || productId
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ELSE 'product_id_' || productId
ELSE 'product_id_' || CAST(productId AS VARCHAR)

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_' || productId
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ELSE 'product_id_' || productId
ELSE 'product_id_' || CAST(productId AS VARCHAR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dbt: hourly covers the hourly dbt subproject in review Assignee is currently reviewing the PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants