-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from Synthetixio/tlx-rebalanced
TLX: add rebalanced model
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
transformers/synthetix/models/marts/optimism/mainnet/lt_rebalanced_optimism_mainnet.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,13 @@ | ||
select | ||
id, | ||
block_number, | ||
block_timestamp as ts, | ||
transaction_hash, | ||
contract, | ||
event_name, | ||
token, | ||
cast( | ||
regexp_replace(token, '.*_(long|short)', '') as int | ||
) as leverage, | ||
{{ convert_wei('current_leverage') }} as current_leverage | ||
from {{ ref('tlx_lt_rebalanced_optimism_mainnet') }} |
24 changes: 24 additions & 0 deletions
24
transformers/synthetix/models/raw/optimism/mainnet/tlx_lt_rebalanced_optimism_mainnet.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,24 @@ | ||
{{ config( | ||
materialized = 'incremental', | ||
unique_key = 'id', | ||
post_hook = [ "create index if not exists idx_id on {{ this }} (id)", "create index if not exists idx_block_number on {{ this }} (block_number)", "create index if not exists idx_block_timestamp on {{ this }} (block_timestamp)", "create index if not exists idx_token on {{ this }} (token)", "create index if not exists idx_contract on {{ this }} (contract)" ] | ||
) }} | ||
|
||
with events as ( | ||
{{ get_tlx_event_data('optimism', 'mainnet', 'rebalanced') }} -- noqa | ||
) | ||
|
||
select * -- noqa: ST06 | ||
from | ||
events | ||
where | ||
{% if is_incremental() %} | ||
block_number > ( | ||
select coalesce(max(t.block_number), 0) as b | ||
from {{ this }} as t | ||
) | ||
{% else %} | ||
true | ||
{% endif %} | ||
order by | ||
id |