Skip to content

Commit

Permalink
AN-5054/native-null-value (#164)
Browse files Browse the repository at this point in the history
* native

* docs
  • Loading branch information
drethereum authored Aug 26, 2024
1 parent ea60de0 commit 1dd6eb3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
@@ -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 %}
24 changes: 15 additions & 9 deletions models/gold/defi/defi__ez_dex_swaps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,26 @@ 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 <> '0xe91d153e0b41518a2ce8dd3d7944fa863463a97d'
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
) AS amount_in_usd,
amount_out_unadj,
amount_out,
ROUND(
amount_out_unadj,
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 <> '0xe91d153e0b41518a2ce8dd3d7944fa863463a97d'
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
Expand Down

0 comments on commit 1dd6eb3

Please sign in to comment.