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

Refactor amount_usd calculation in paraswap.trades #6216

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ models:
- &token_sold_amount_raw
name: token_sold_amount_raw
description: "Raw value of the token sold at time of execution in the original currency"
- &amount_usd
name: amount_usd
description: "USD value of the trade at time of execution"
- &token_bought_address
name: token_bought_address
description: "Contract address of the token bought"
Expand Down Expand Up @@ -134,7 +131,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down Expand Up @@ -173,7 +169,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{ config(
schema='paraswap_arbitrum',
alias = 'trades',

alias = 'trades'
)
}}

Expand All @@ -28,7 +27,6 @@ FROM (
token_sold_amount,
token_bought_amount_raw,
token_sold_amount_raw,
amount_usd,
token_bought_address,
token_sold_address,
taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
incremental_strategy = 'merge',
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
unique_key = ['block_date', 'blockchain', 'project', 'version', 'tx_hash', 'evt_index', 'trace_address'],
post_hook='{{ expose_spells(\'["arbitrum"]\',
"project",
"paraswap_v5",
\'["springzh"]\') }}'
post_hook='{{ expose_spells(blockchains = \'["arbitrum"]\',
spell_type = "project",
spell_name = "paraswap_v5",
contributors = \'["springzhang"]\') }}'
)
}}

Expand Down Expand Up @@ -72,11 +72,6 @@ SELECT 'arbitrum' AS blockchain,
d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount,
d.token_bought_amount_raw,
d.token_sold_amount_raw,
coalesce(
d.amount_usd
,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price
,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price
) AS amount_usd,
d.token_bought_address,
d.token_sold_address,
coalesce(d.taker, tx."from") AS taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
incremental_strategy = 'merge',
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
unique_key = ['block_date', 'blockchain', 'project', 'version', 'tx_hash', 'evt_index', 'trace_address'],
post_hook='{{ expose_spells(\'["arbitrum"]\',
"project",
"paraswap_v6",
\'["springzh"]\') }}'
post_hook='{{ expose_spells(blockchains = \'["arbitrum"]\',
spell_type ="project",
spell_name = "paraswap_v6",
contributors = \'["springzhang"]\') }}'
)
}}

Expand Down Expand Up @@ -64,11 +64,6 @@ method,
d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount,
d.token_bought_amount_raw,
d.token_sold_amount_raw,
coalesce(
d.amount_usd
,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price
,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price
) AS amount_usd,
d.token_bought_address,
d.token_sold_address,
coalesce(d.taker, tx."from") AS taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ models:
- &token_sold_amount_raw
name: token_sold_amount_raw
description: "Raw value of the token sold at time of execution in the original currency"
- &amount_usd
name: amount_usd
description: "USD value of the trade at time of execution"
- &token_bought_address
name: token_bought_address
description: "Contract address of the token bought"
Expand Down Expand Up @@ -134,7 +131,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down Expand Up @@ -172,7 +168,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ FROM (
token_sold_amount,
token_bought_amount_raw,
token_sold_amount_raw,
amount_usd,
token_bought_address,
token_sold_address,
taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ SELECT
dexs.token_sold_amount_raw / power(10, erc20b.decimals) AS token_sold_amount,
dexs.token_bought_amount_raw,
dexs.token_sold_amount_raw,
coalesce(
dexs.amount_usd
,(dexs.token_bought_amount_raw / power(10, erc20a.decimals)) * coalesce(p_bought.price, p_prev1.price, p_next1.price)
,(dexs.token_sold_amount_raw / power(10, erc20b.decimals)) * coalesce(p_sold.price, p_prev2.price, p_next2.price)
) AS amount_usd,
dexs.token_bought_address,
dexs.token_sold_address,
coalesce(dexs.taker, tx."from") AS taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ models:
- &token_sold_amount_raw
name: token_sold_amount_raw
description: "Raw value of the token sold at time of execution in the original currency"
- &amount_usd
name: amount_usd
description: "USD value of the trade at time of execution"
- &token_bought_address
name: token_bought_address
description: "Contract address of the token bought"
Expand Down Expand Up @@ -119,7 +116,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down Expand Up @@ -168,7 +164,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{ config(
alias = 'trades',
schema = 'paraswap_base'

)
}}

Expand All @@ -28,7 +27,6 @@ FROM (
token_sold_amount,
token_bought_amount_raw,
token_sold_amount_raw,
amount_usd,
token_bought_address,
token_sold_address,
taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ SELECT 'base' AS blockchain,
d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount,
d.token_bought_amount_raw,
d.token_sold_amount_raw,
coalesce(
d.amount_usd
,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price
,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price
) AS amount_usd,
d.token_bought_address,
d.token_sold_address,
coalesce(d.taker, tx."from") AS taker,
Expand All @@ -95,21 +90,3 @@ LEFT JOIN {{ source('tokens', 'erc20') }} e1 ON e1.contract_address = d.token_bo
AND e1.blockchain = 'base'
LEFT JOIN {{ source('tokens', 'erc20') }} e2 on e2.contract_address = d.token_sold_address
AND e2.blockchain = 'base'
LEFT JOIN {{ source('prices', 'usd') }} p1 ON p1.minute = date_trunc('minute', d.block_time)
AND p1.contract_address = d.token_bought_address
AND p1.blockchain = 'base'
{% if not is_incremental() %}
AND p1.minute >= TIMESTAMP '{{project_start_date}}'
{% endif %}
{% if is_incremental() %}
AND {{incremental_predicate('p1.minute')}}
{% endif %}
LEFT JOIN {{ source('prices', 'usd') }} p2 ON p2.minute = date_trunc('minute', d.block_time)
AND p2.contract_address = d.token_sold_address
AND p2.blockchain = 'base'
{% if not is_incremental() %}
AND p2.minute >= TIMESTAMP '{{project_start_date}}'
{% endif %}
{% if is_incremental() %}
AND {{incremental_predicate('p2.minute')}}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ method,
d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount,
d.token_bought_amount_raw,
d.token_sold_amount_raw,
coalesce(
d.amount_usd
,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price
,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price
) AS amount_usd,
d.token_bought_address,
d.token_sold_address,
coalesce(d.taker, tx."from") AS taker,
Expand Down
6 changes: 0 additions & 6 deletions dbt_subprojects/dex/models/_projects/paraswap/bnb/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ models:
- &token_sold_amount_raw
name: token_sold_amount_raw
description: "Raw value of the token sold at time of execution in the original currency"
- &amount_usd
name: amount_usd
description: "USD value of the trade at time of execution"
- &token_bought_address
name: token_bought_address
description: "Contract address of the token bought"
Expand Down Expand Up @@ -133,7 +130,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down Expand Up @@ -183,7 +179,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down Expand Up @@ -221,7 +216,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{ config(
schema='paraswap_bnb',
alias = 'trades',

alias = 'trades'
)
}}

Expand Down Expand Up @@ -29,7 +28,6 @@ FROM (
token_sold_amount,
token_bought_amount_raw,
token_sold_amount_raw,
amount_usd,
token_bought_address,
token_sold_address,
taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ SELECT 'bnb' AS blockchain,
d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount,
d.token_bought_amount_raw,
d.token_sold_amount_raw,
coalesce(
d.amount_usd
,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price
,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price
) AS amount_usd,
d.token_bought_address,
d.token_sold_address,
coalesce(d.taker, tx."from") AS taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ SELECT 'bnb' AS blockchain,
d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount,
d.token_bought_amount_raw,
d.token_sold_amount_raw,
coalesce(
d.amount_usd
,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price
,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price
) AS amount_usd,
d.token_bought_address,
d.token_sold_address,
coalesce(d.taker, tx."from") AS taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ method,
d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount,
d.token_bought_amount_raw,
d.token_sold_amount_raw,
coalesce(
d.amount_usd
,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price
,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price
) AS amount_usd,
d.token_bought_address,
d.token_sold_address,
coalesce(d.taker, tx."from") AS taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ models:
- &token_sold_amount_raw
name: token_sold_amount_raw
description: "Raw value of the token sold at time of execution in the original currency"
- &amount_usd
name: amount_usd
description: "USD value of tokens"
- &token_bought_address
name: token_bought_address
description: "Contract address of the token bought"
Expand Down Expand Up @@ -133,7 +130,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down Expand Up @@ -183,7 +179,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down Expand Up @@ -222,7 +217,6 @@ models:
- *token_sold_amount
- *token_bought_amount_raw
- *token_sold_amount_raw
- *amount_usd
- *token_bought_address
- *token_sold_address
- *taker
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{ config(
schema='paraswap_ethereum',
alias = 'trades',

)
}}

Expand Down Expand Up @@ -29,7 +28,6 @@ FROM (
token_sold_amount,
token_bought_amount_raw,
token_sold_amount_raw,
amount_usd,
token_bought_address,
token_sold_address,
taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,6 @@ SELECT 'ethereum' AS blockchain,
d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount,
d.token_bought_amount_raw,
d.token_sold_amount_raw,
coalesce(
d.amount_usd
,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price
,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price
) AS amount_usd,
d.token_bought_address,
d.token_sold_address,
coalesce(d.taker, tx."from") AS taker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,6 @@ SELECT 'ethereum' AS blockchain,
d.token_sold_amount_raw / power(10, e2.decimals) AS token_sold_amount,
d.token_bought_amount_raw,
d.token_sold_amount_raw,
coalesce(
d.amount_usd
,(d.token_bought_amount_raw / power(10, p1.decimals)) * p1.price
,(d.token_sold_amount_raw / power(10, p2.decimals)) * p2.price
) AS amount_usd,
d.token_bought_address,
d.token_sold_address,
coalesce(d.taker, tx."from") AS taker,
Expand Down
Loading
Loading