From ae44ef9330af0d5e92be2b0a279886deeae30426 Mon Sep 17 00:00:00 2001 From: Troy Date: Mon, 9 Dec 2024 11:02:25 -0700 Subject: [PATCH] add rebalanced model --- .../lt_rebalanced_optimism_mainnet.sql | 13 ++++++++++ .../tlx_lt_rebalanced_optimism_mainnet.sql | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 transformers/synthetix/models/marts/optimism/mainnet/lt_rebalanced_optimism_mainnet.sql create mode 100644 transformers/synthetix/models/raw/optimism/mainnet/tlx_lt_rebalanced_optimism_mainnet.sql diff --git a/transformers/synthetix/models/marts/optimism/mainnet/lt_rebalanced_optimism_mainnet.sql b/transformers/synthetix/models/marts/optimism/mainnet/lt_rebalanced_optimism_mainnet.sql new file mode 100644 index 00000000..28181b0b --- /dev/null +++ b/transformers/synthetix/models/marts/optimism/mainnet/lt_rebalanced_optimism_mainnet.sql @@ -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') }} diff --git a/transformers/synthetix/models/raw/optimism/mainnet/tlx_lt_rebalanced_optimism_mainnet.sql b/transformers/synthetix/models/raw/optimism/mainnet/tlx_lt_rebalanced_optimism_mainnet.sql new file mode 100644 index 00000000..7b7dca4f --- /dev/null +++ b/transformers/synthetix/models/raw/optimism/mainnet/tlx_lt_rebalanced_optimism_mainnet.sql @@ -0,0 +1,25 @@ +{{ 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(block_number), 0) as b + from {{ this }} + ) + {% else %} + true + {% endif %} +order by + id