From cd6bcfbeccfd429d82a323ef1670e90d56ae7ae0 Mon Sep 17 00:00:00 2001 From: drethereum <71602799+drethereum@users.noreply.github.com> Date: Mon, 26 Aug 2024 14:12:20 -0600 Subject: [PATCH] AN-5054/native-null-value (#196) * native * docs --- .../eth_dex_swaps_amount_in_usd.md | 2 +- .../eth_dex_swaps_amount_out_usd.md | 2 +- models/gold/defi/defi__ez_dex_swaps.sql | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/models/doc_descriptions/dex - (imported from layer 1)/eth_dex_swaps_amount_in_usd.md b/models/doc_descriptions/dex - (imported from layer 1)/eth_dex_swaps_amount_in_usd.md index 4633819..bfa46fd 100644 --- a/models/doc_descriptions/dex - (imported from layer 1)/eth_dex_swaps_amount_in_usd.md +++ b/models/doc_descriptions/dex - (imported from layer 1)/eth_dex_swaps_amount_in_usd.md @@ -1,5 +1,5 @@ {% docs eth_dex_swaps_amount_in_usd %} -The amount of tokens put into the swap converted to USD using the price of the token. +The value of the swapped tokens in USD at the time of the transaction, where available. If there is a variance of 75% or greater in USD swap values or one side of the swap's USD value is NULL, then both amount_in_usd and amount_out_usd will be set to NULL. This avoids falsely overstating USD swap volumes for low-liquidity token pairings or incorrectly reported prices. To get USD values in these scenarios anyway, please re-join the `price.ez_prices_hourly` table. Note, this logic does not apply for the chain's Native asset. {% enddocs %} \ No newline at end of file diff --git a/models/doc_descriptions/dex - (imported from layer 1)/eth_dex_swaps_amount_out_usd.md b/models/doc_descriptions/dex - (imported from layer 1)/eth_dex_swaps_amount_out_usd.md index 32e5470..3b52837 100644 --- a/models/doc_descriptions/dex - (imported from layer 1)/eth_dex_swaps_amount_out_usd.md +++ b/models/doc_descriptions/dex - (imported from layer 1)/eth_dex_swaps_amount_out_usd.md @@ -1,5 +1,5 @@ {% docs eth_dex_swaps_amount_out_usd %} -The amount of tokens taken out of or received from the swap converted to USD using the price of the token. +The value of the swapped tokens in USD at the time of the transaction, where available. If there is a variance of 75% or greater in USD swap values or one side of the swap's USD value is NULL, then both amount_in_usd and amount_out_usd will be set to NULL. This avoids falsely overstating USD swap volumes for low-liquidity token pairings or incorrectly reported prices. To get USD values in these scenarios anyway, please re-join the `price.ez_prices_hourly` table. Note, this logic does not apply for the chain's Native asset. {% enddocs %} \ No newline at end of file diff --git a/models/gold/defi/defi__ez_dex_swaps.sql b/models/gold/defi/defi__ez_dex_swaps.sql index 976df15..e029219 100644 --- a/models/gold/defi/defi__ez_dex_swaps.sql +++ b/models/gold/defi/defi__ez_dex_swaps.sql @@ -21,9 +21,12 @@ SELECT amount_in, ROUND( CASE - WHEN amount_out_usd IS NULL - OR ABS((amount_in_usd - amount_out_usd) / NULLIF(amount_out_usd, 0)) > 0.75 - OR ABS((amount_in_usd - amount_out_usd) / NULLIF(amount_in_usd, 0)) > 0.75 THEN NULL + WHEN token_in <> '0x4200000000000000000000000000000000000006' + AND ( + amount_out_usd IS NULL + OR ABS((amount_in_usd - amount_out_usd) / NULLIF(amount_out_usd, 0)) > 0.75 + OR ABS((amount_in_usd - amount_out_usd) / NULLIF(amount_in_usd, 0)) > 0.75 + ) THEN NULL ELSE amount_in_usd END, 2 @@ -32,9 +35,12 @@ SELECT amount_out, ROUND( CASE - WHEN amount_in_usd IS NULL - OR ABS((amount_out_usd - amount_in_usd) / NULLIF(amount_in_usd, 0)) > 0.75 - OR ABS((amount_out_usd - amount_in_usd) / NULLIF(amount_out_usd, 0)) > 0.75 THEN NULL + WHEN token_out <> '0x4200000000000000000000000000000000000006' + AND ( + amount_in_usd IS NULL + OR ABS((amount_out_usd - amount_in_usd) / NULLIF(amount_in_usd, 0)) > 0.75 + OR ABS((amount_out_usd - amount_in_usd) / NULLIF(amount_out_usd, 0)) > 0.75 + ) THEN NULL ELSE amount_out_usd END, 2