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

AN-5188/parse fee from logs #356

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion models/gold/defi/defi__ez_dex_swaps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ WITH dex_swaps AS (
block_id,
block_timestamp,
receiver_id,
predecessor_id,
signer_id,
swap_index,
amount_out_raw,
Expand All @@ -21,6 +22,8 @@ WITH dex_swaps AS (
token_in,
swap_input_data,
LOG,
total_fee,
admin_fee,
dex_swaps_v2_id AS ez_dex_swaps_id,
inserted_timestamp,
modified_timestamp
Expand Down Expand Up @@ -58,7 +61,7 @@ FINAL AS (
s.block_timestamp,
s.receiver_id AS platform,
s.swap_input_data :pool_id :: INT AS pool_id,
s.signer_id AS trader,
s.predecessor_id AS trader,
s.swap_index,
s.amount_out_raw,
s.amount_out_raw / pow(
Expand All @@ -78,6 +81,8 @@ FINAL AS (
l2.symbol AS symbol_in,
s.swap_input_data,
s.log,
s.total_fee,
s.admin_fee,
s.ez_dex_swaps_id,
s.inserted_timestamp,
s.modified_timestamp
Expand Down
3 changes: 3 additions & 0 deletions models/gold/defi/defi__fact_dex_swaps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SELECT
block_id,
block_timestamp,
receiver_id,
predecessor_id,
signer_id,
swap_index,
amount_out_raw,
Expand All @@ -19,6 +20,8 @@ SELECT
token_in,
swap_input_data,
LOG,
total_fee,
admin_fee,
dex_swaps_v2_id AS fact_dex_swaps_id,
inserted_timestamp,
modified_timestamp
Expand Down
69 changes: 42 additions & 27 deletions models/silver/curated/defi/silver__dex_swaps_v2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ WITH swap_logs AS (
block_id,
block_timestamp,
receiver_id,
predecessor_id,
signer_id,
log_index,
clean_log,
Expand All @@ -29,25 +30,26 @@ WITH swap_logs AS (
receipt_succeeded
AND clean_log LIKE 'Swapped%'
AND receiver_id NOT LIKE '%dragon_bot.near'

{% if var("MANUAL_FIX") %}
AND {{ partition_load_manual('no_buffer') }}
{% else %}
{% if is_incremental() %}
AND _modified_timestamp >= (
SELECT
MAX(_modified_timestamp)
FROM
{{ this }}
)
{% endif %}
{% endif %}

{% if is_incremental() %}
AND _modified_timestamp >= (
SELECT
MAX(_modified_timestamp)
FROM
{{ this }}
)
{% endif %}
{% endif %}
),
receipts AS (
SELECT
receipt_object_id,
receipt_actions,
receiver_id,
receipt_actions :predecessor_id :: STRING AS predecessor_id,
signer_id,
_partition_by_block_number,
_inserted_timestamp,
Expand All @@ -64,15 +66,16 @@ receipts AS (
{% if var("MANUAL_FIX") %}
AND {{ partition_load_manual('no_buffer') }}
{% else %}
{% if is_incremental() %}
AND _modified_timestamp >= (
SELECT
MAX(_modified_timestamp)
FROM
{{ this }}
)
{% endif %}
{% endif %}

{% if is_incremental() %}
AND _modified_timestamp >= (
SELECT
MAX(_modified_timestamp)
FROM
{{ this }}
)
{% endif %}
{% endif %}
),
swap_outcome AS (
SELECT
Expand All @@ -81,30 +84,34 @@ swap_outcome AS (
block_id,
block_timestamp,
receiver_id,
predecessor_id,
signer_id,
ROW_NUMBER() over (
PARTITION BY receipt_object_id
ORDER BY
log_index ASC
) - 1 AS swap_index,
COALESCE(SPLIT(clean_log, ',') [0], clean_log) AS LOG,
clean_log AS LOG,
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 get delete this. It;s not been used

COALESCE(SPLIT(clean_log, ',') [0], clean_log) AS primary_log,
REGEXP_SUBSTR(SPLIT(clean_log, ', ') [1], 'total fee ([0-9]+)', 1, 1, 'e', 1) AS total_fee,
REGEXP_SUBSTR(SPLIT(clean_log, ', ') [2], 'admin fee ([0-9]+)', 1, 1, 'e', 1) AS admin_fee,
REGEXP_REPLACE(
LOG,
primary_log,
'.*Swapped (\\d+) (.*) for (\\d+) (.*)',
'\\1'
) :: INT AS amount_in_raw,
REGEXP_REPLACE(
LOG,
primary_log,
'.*Swapped \\d+ (\\S+) for (\\d+) (.*)',
'\\1'
) :: STRING AS token_in,
REGEXP_REPLACE(
LOG,
primary_log,
'.*Swapped \\d+ \\S+ for (\\d+) (.*)',
'\\1'
) :: INT AS amount_out_raw,
REGEXP_REPLACE(
LOG,
primary_log,
'.*Swapped \\d+ \\S+ for \\d+ (.*)',
'\\1'
) :: STRING AS token_out,
Expand All @@ -120,10 +127,14 @@ parse_actions AS (
o.receipt_object_id,
block_id,
block_timestamp,
receiver_id,
signer_id,
o.receiver_id,
o.predecessor_id,
o.signer_id,
swap_index,
LOG,
primary_log,
total_fee,
admin_fee,
amount_out_raw,
token_out,
amount_in_raw,
Expand Down Expand Up @@ -152,7 +163,7 @@ parse_actions AS (
-- for multi-swaps, there is (often) one action with an array of input dicts that correspond with the swap index
decoded_action :msg,
-- Swap must be capitalized! Autoformat may change to "swap"
decoded_action :operation: Swap,
decoded_action :operation :Swap,
decoded_action
)
) :actions [swap_index],
Expand All @@ -178,6 +189,7 @@ FINAL AS (
block_id,
block_timestamp,
receiver_id,
predecessor_id,
signer_id,
swap_index,
amount_out_raw,
Expand All @@ -186,6 +198,9 @@ FINAL AS (
token_in,
swap_input_data,
LOG,
primary_log,
total_fee,
admin_fee,
_partition_by_block_number,
_inserted_timestamp,
_modified_timestamp
Expand Down
Loading