-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Lyra V1 on Optimism #7569
Open
PatelPrinci
wants to merge
7
commits into
duneanalytics:main
Choose a base branch
from
Lampros-Tech:optimism-lyra
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+234
−0
Open
Lyra V1 on Optimism #7569
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4702e97
last head commit
PatelPrinci c08c21c
lyra on optimism
PatelPrinci 7968174
Merge branch 'main' into optimism-lyra
PatelPrinci 1179b03
solved the syntax error
PatelPrinci 8eff0f5
solved syntax error
PatelPrinci 1546b6b
Merge branch 'main' into optimism-lyra
PatelPrinci 4e2f045
Merge branch 'main' into optimism-lyra
PatelPrinci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...ourly_spellbook/models/_sector/perpetual/projects/lyra/lyra_optimism_perpetual_trades.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{{ config( | ||
schema = 'lyra_perpetual_trades', | ||
alias = 'perpetual_trades', | ||
post_hook='{{ expose_spells(blockchains = \'["optimism"]\', | ||
spell_type = "project", | ||
spell_name = "lyra", | ||
contributors = \'["princi"]\') }}' | ||
) | ||
}} | ||
|
||
{% set lyra_optimism_perpetual_trade_models = [ | ||
ref('lyra_v1_optimism_perpetual_trades') | ||
] %} | ||
|
||
SELECT * | ||
FROM | ||
( | ||
{% for lyra_perpetual_trades in lyra_optimism_perpetual_trade_models %} | ||
SELECT | ||
blockchain | ||
,block_date | ||
,block_month | ||
,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 | ||
FROM {{ lyra_perpetual_trades }} | ||
{% if not loop.last %} | ||
UNION ALL | ||
{% endif %} | ||
{% endfor %} | ||
) |
84 changes: 84 additions & 0 deletions
84
dbt_subprojects/hourly_spellbook/models/_sector/perpetual/projects/lyra/lyra_schema.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: lyra_v1_optimism_perpetual_trades | ||
meta: | ||
blockchain: optimism | ||
sector: perpetual | ||
contributors: princi | ||
config: | ||
tags: ['optimism', 'perpetuals', 'perps', 'lyra'] | ||
description: | ||
Perpetual swaps/trades table on lyra protocol across blockchains | ||
data_tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- tx_hash | ||
- evt_index | ||
columns: | ||
- &blockchain | ||
name: blockchain | ||
description: "Blockchain where the perpetuals market is deployed" | ||
- &block_date | ||
name: block_date | ||
description: "Date of the transaction" | ||
- &block_time | ||
name: block_time | ||
description: "Time of the transaction" | ||
- &virtual_asset | ||
name: virtual_asset | ||
description: "How the protocol represents the underlying asset" | ||
- &underlying_asset | ||
name: underlying_asset | ||
description: "The real underlying asset that is represented in the swap" | ||
- &market | ||
name: market | ||
description: "The futures market involved in the transaction" | ||
- &market_address | ||
name: market_address | ||
description: "Contract address of the market" | ||
data_tests: | ||
- 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" | ||
- &fee_usd | ||
name: fee_usd | ||
description: "The fees charged to the user for the swap in USD" | ||
- &margin_usd | ||
name: margin_usd | ||
description: "The amount of collateral/margin used in a trade in USD" | ||
- &trade | ||
name: trade | ||
description: "Indicates the trade's direction whether a short, long, of if a position is being closed" | ||
- &project | ||
name: project | ||
description: "The underlying protocol/project where the swap took place" | ||
- &version | ||
name: version | ||
description: "The version of the protocol/project" | ||
- &frontend | ||
name: frontend | ||
description: "The frontend protocol/project where the specific swap was executed; built on top of the 'project' and defaults to the 'project' if no other frontend is specified" | ||
- &trader | ||
name: trader | ||
description: "The address which made the swap in the protocol" | ||
- &volume_raw | ||
name: volume_raw | ||
description: "The size of the position in raw form" | ||
- &tx_hash | ||
name: tx_hash | ||
description: "The hash of the transactions" | ||
- &tx_from | ||
name: tx_from | ||
description: "The address that originated the transaction; based on the optimism.transactions table" | ||
- &tx_to | ||
name: tx_to | ||
description: "The address receiving the transaction; based on the optimism.transactions table" | ||
- &evt_index | ||
name: evt_index | ||
description: "Event index number" | ||
- &block_month | ||
name: block_month | ||
description: "Month of the transaction" |
92 changes: 92 additions & 0 deletions
92
...ly_spellbook/models/_sector/perpetual/projects/lyra/lyra_v1_optimism_perpetual_trades.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{{ config( | ||
alias = 'perpetual_trades', | ||
schema = 'lyra_v1_optimism', | ||
partition_by = ['block_month'], | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
unique_key = ['tx_hash', 'evt_index'] | ||
)}} | ||
|
||
{% set project_start_date = '2023-01-01' %} | ||
|
||
WITH perp_events as ( | ||
-- Open Position events | ||
SELECT | ||
evt_block_time as block_time, | ||
evt_block_number as block_number, | ||
'open_position' as trade_data, | ||
listingId as product_id, | ||
trader, | ||
contract_address as market_address, | ||
evt_index, | ||
evt_tx_hash as tx_hash, | ||
CAST(totalCost AS DOUBLE) as fee_usd, | ||
CAST(amount AS DOUBLE) as volume_usd, | ||
tradeType | ||
FROM {{ source('lyra_v1_optimism', 'OptionMarket_evt_PositionOpened') }} | ||
{% if is_incremental() %} | ||
WHERE {{ incremental_predicate('evt_block_time') }} | ||
{% else %} | ||
WHERE evt_block_time >= DATE '{{ project_start_date }}' | ||
{% endif %} | ||
|
||
UNION ALL | ||
|
||
-- Close Position events | ||
SELECT | ||
evt_block_time as block_time, | ||
evt_block_number as block_number, | ||
'close_position' as trade_data, | ||
listingId as product_id, | ||
trader, | ||
contract_address as market_address, | ||
evt_index, | ||
evt_tx_hash as tx_hash, | ||
CAST(totalCost AS DOUBLE) as fee_usd, | ||
CAST(amount AS DOUBLE) as volume_usd, | ||
tradeType | ||
FROM {{ source('lyra_v1_optimism', 'OptionMarket_evt_PositionClosed') }} | ||
{% if is_incremental() %} | ||
WHERE {{ incremental_predicate('evt_block_time') }} | ||
{% else %} | ||
WHERE evt_block_time >= DATE '{{ project_start_date }}' | ||
{% endif %} | ||
) | ||
|
||
SELECT | ||
'optimism' as blockchain, | ||
'lyra' as project, | ||
'1' as version, | ||
'lyra' as frontend, | ||
CAST(date_trunc('day', pe.block_time) as date) as block_date, | ||
CAST(date_trunc('month', pe.block_time) as date) as block_month, | ||
pe.block_time, | ||
CAST(NULL AS VARCHAR) as virtual_asset, | ||
CAST(NULL AS VARCHAR) as underlying_asset, | ||
CAST(NULL AS VARCHAR) as market, | ||
pe.market_address, | ||
pe.volume_usd, | ||
pe.fee_usd, | ||
CAST(NULL AS DOUBLE) as margin_usd, | ||
CASE | ||
WHEN pe.trade_data = 'open_position' THEN 'open' | ||
WHEN pe.trade_data = 'close_position' THEN 'close' | ||
END as trade, | ||
pe.trader, | ||
pe.tradeType, | ||
CAST(NULL AS UINT256) as volume_raw, | ||
pe.tx_hash, | ||
txns."to" as tx_to, | ||
txns."from" as tx_from, | ||
pe.evt_index, | ||
CAST(NULL AS DOUBLE) as pnl | ||
FROM perp_events pe | ||
INNER JOIN {{ source('optimism', 'transactions') }} txns | ||
ON pe.tx_hash = txns.hash | ||
AND pe.block_number = txns.block_number | ||
{% if is_incremental() %} | ||
AND {{ incremental_predicate('txns.block_time') }} | ||
{% else %} | ||
AND txns.block_time >= DATE '{{ project_start_date }}' | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: lyra_v1_optimism | ||
description: > | ||
Decoded event tables for Perpetual trades on Lyra protocol | ||
tables: | ||
- name: OptionMarket_evt_PositionOpened | ||
|
||
- name: OptionMarket_evt_PositionClosed |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz fix here