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

Add TLX trades with prices and volume #149

Merged
merged 11 commits into from
Dec 6, 2024
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
10 changes: 3 additions & 7 deletions transformers/synthetix/macros/get_tlx_event_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@
)
SELECT
*,
REGEXP_SUBSTR(
"_dbt_source_relation",
'lt_([^_]+)_event',
1,
1,
'i',
1
substring(
"_dbt_source_relation"
FROM 'lt_([^_]+_[^_]+)_event_[^_]+$'
) AS token
FROM
raw_data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
with trades as (

select
a.id,
a.block_number,
a.ts,
a.transaction_hash,
a.contract,
a.event_name,
a.account,
a.token,
a.leverage,
upper(substring(a.token from '([^_]+)')) as market,
a.leveraged_token_amount,
a.base_asset_amount,
abs(a.leveraged_token_amount) as nominal_volume,
abs(a.leveraged_token_amount) * a.leverage as notional_volume
from (

select
id,
block_number,
block_timestamp as ts,
transaction_hash,
contract,
event_name,
account,
token,
cast(
regexp_replace(token, '.*_(long|short)', '') as int
) as leverage,
{{ convert_wei('leveraged_token_amount') }}
as leveraged_token_amount,
{{ convert_wei('base_asset_amount') }} as base_asset_amount
from {{ ref('tlx_lt_minted_optimism_mainnet') }}
union all
select
id,
block_number,
block_timestamp as ts,
transaction_hash,
contract,
event_name,
account,
token,
cast(
regexp_replace(token, '.*_(long|short)', '') as int
) as leverage,
{{ convert_wei('leveraged_token_amount') }}
* -1 as leveraged_token_amount,
{{ convert_wei('base_asset_amount') }} * -1 as base_asset_amount
from {{ ref('tlx_lt_redeemed_optimism_mainnet') }}
) as a
),

prices as (
select distinct
market,
block_number,
last(price)
over (partition by market, block_number order by id)
as price
from {{ ref('fct_v2_trades_optimism_mainnet') }}
)

select
trades.*,
prices.price
from trades
left join prices
on
trades.market = prices.market
and trades.block_number = prices.block_number
42 changes: 42 additions & 0 deletions transformers/synthetix/models/marts/optimism/mainnet/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,45 @@ models:
data_type: numeric
- name: net_transfers
data_type: numeric
- name: lt_trades_optimism_mainnet
columns:
- name: id
data_type: character varying
- name: block_number
data_type: integer
- name: ts
data_type: timestamp with time zone
- name: transaction_hash
data_type: text
- name: contract
data_type: text
- name: event_name
data_type: text
- name: account
data_type: text
- name: token
data_type: text
- name: leverage
data_type: numeric
- name: market
data_type: text
- name: leveraged_token_amount
data_type: numeric
- name: base_asset_amount
data_type: numeric
- name: price
data_type: numeric
- name: nominal_volume
data_type: numeric
tests:
- not_null
- dbt_utils.accepted_range:
min_value: 0
inclusive: true
- name: notional_volume
data_type: numeric
tests:
- not_null
- dbt_utils.accepted_range:
min_value: 0
inclusive: true
8 changes: 8 additions & 0 deletions transformers/synthetix/models/raw/optimism/mainnet/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ models:
data_type: integer
- name: contract
data_type: text
- name: token
data_type: text
tests:
- not_null
- name: event_name
data_type: text
- name: account
Expand All @@ -171,6 +175,10 @@ models:
data_type: integer
- name: contract
data_type: text
- name: token
data_type: text
tests:
- not_null
- name: event_name
data_type: text
- name: account
Expand Down
Loading