-
Notifications
You must be signed in to change notification settings - Fork 6
Transformers - Add Underlying Yields per Account models #206
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...thetix/models/marts/base/mainnet/core/fct_core_account_underlying_yields_base_mainnet.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| {{ | ||
| config( | ||
| materialized='table', | ||
| indexes=[ | ||
| {'columns': ['account_id'], 'type': 'hash'} | ||
| ] | ||
| ) | ||
| }} | ||
|
|
||
| with recursive yield_tokens as ( | ||
| select distinct collateral_type | ||
| from {{ ref('fct_token_yields_base_mainnet') }} | ||
| ), | ||
|
|
||
| delegations as ( | ||
| select | ||
| block_timestamp, | ||
| account_id, | ||
| pool_id, | ||
| collateral_type, | ||
| {{ convert_wei('amount') }} as amount | ||
| from | ||
| {{ ref('core_delegation_updated_base_mainnet') }} | ||
| where lower(collateral_type) in (select lower(collateral_type) from yield_tokens) | ||
| ), | ||
|
|
||
| hourly_delegation as ( | ||
| select | ||
| date_trunc('hour', block_timestamp) as block_timestamp, | ||
| account_id, | ||
| pool_id, | ||
| collateral_type, | ||
| last(amount) over ( | ||
| partition by account_id, pool_id, collateral_type, date_trunc('hour', block_timestamp) | ||
| order by block_timestamp | ||
| rows between unbounded preceding and unbounded following | ||
| ) as amount | ||
| from delegations | ||
| order by block_timestamp asc | ||
| ), | ||
|
|
||
| account_bounds AS ( | ||
| select | ||
| account_id, | ||
| pool_id, | ||
| collateral_type, | ||
| min(block_timestamp) as min_time, | ||
| max(block_timestamp) as max_time | ||
| from hourly_delegation | ||
| group by account_id, pool_id, collateral_type | ||
| ), | ||
|
|
||
| hourly_series AS ( | ||
| select | ||
| ab.account_id, | ||
| ab.pool_id, | ||
| ab.collateral_type, | ||
| ab.min_time as series_time | ||
| from account_bounds ab | ||
|
|
||
| union all | ||
|
|
||
| select | ||
| hs.account_id, | ||
| hs.pool_id, | ||
| hs.collateral_type, | ||
| hs.series_time + INTERVAL '1 hour' as series_time | ||
| from hourly_series hs | ||
| join account_bounds ab on hs.account_id = ab.account_id | ||
| where hs.series_time < ab.max_time | ||
| ), | ||
|
|
||
| last_known_values AS ( | ||
| select | ||
| hs.account_id, | ||
| hs.pool_id, | ||
| hs.collateral_type, | ||
| hs.series_time, | ||
| ( | ||
| select t.amount | ||
| from hourly_delegation as t | ||
| where t.account_id = hs.account_id | ||
| and t.block_timestamp <= hs.series_time | ||
| order by t.block_timestamp desc | ||
| limit 1 | ||
| ) as amount | ||
| from hourly_series hs | ||
| ), | ||
|
|
||
| final_result as ( | ||
| select | ||
| last_known_values.account_id, | ||
| last_known_values.pool_id, | ||
| last_known_values.collateral_type, | ||
| last_known_values.series_time as block_timestamp, | ||
| last_known_values.amount, | ||
| token_yields.hourly_exchange_rate_pnl | ||
| from last_known_values | ||
| left join {{ ref('fct_token_yields_base_mainnet') }} as token_yields | ||
| on last_known_values.series_time = token_yields.ts | ||
| and last_known_values.pool_id = token_yields.pool_id | ||
| and lower(last_known_values.collateral_type) = lower(token_yields.collateral_type) | ||
| ) | ||
|
|
||
| select | ||
| account_id, | ||
| pool_id, | ||
| collateral_type, | ||
| coalesce(sum(amount * hourly_exchange_rate_pnl), 0) as yield_usd | ||
| from final_result | ||
| group by account_id, pool_id, collateral_type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...ynthetix/models/marts/eth/mainnet/core/fct_core_account_underlying_yields_eth_mainnet.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| {{ | ||
| config( | ||
| materialized='table', | ||
| indexes=[ | ||
| {'columns': ['account_id'], 'type': 'hash'} | ||
| ] | ||
| ) | ||
| }} | ||
|
|
||
| with recursive yield_tokens as ( | ||
| select distinct collateral_type | ||
| from {{ ref('fct_token_yields_eth_mainnet') }} | ||
| ), | ||
|
|
||
| delegations as ( | ||
| select | ||
| block_timestamp, | ||
| account_id, | ||
| pool_id, | ||
| collateral_type, | ||
| {{ convert_wei('amount') }} as amount | ||
| from | ||
| {{ ref('core_delegation_updated_eth_mainnet') }} | ||
| where lower(collateral_type) in (select lower(collateral_type) from yield_tokens) | ||
| ), | ||
|
|
||
| hourly_delegation as ( | ||
| select | ||
| date_trunc('hour', block_timestamp) as block_timestamp, | ||
| account_id, | ||
| pool_id, | ||
| collateral_type, | ||
| last(amount) over ( | ||
| partition by account_id, pool_id, collateral_type, date_trunc('hour', block_timestamp) | ||
| order by block_timestamp | ||
| rows between unbounded preceding and unbounded following | ||
| ) as amount | ||
| from delegations | ||
| order by block_timestamp asc | ||
| ), | ||
|
|
||
| account_bounds AS ( | ||
| select | ||
| account_id, | ||
| pool_id, | ||
| collateral_type, | ||
| min(block_timestamp) as min_time, | ||
| max(block_timestamp) as max_time | ||
| from hourly_delegation | ||
| group by account_id, pool_id, collateral_type | ||
| ), | ||
|
|
||
| hourly_series AS ( | ||
| select | ||
| ab.account_id, | ||
| ab.pool_id, | ||
| ab.collateral_type, | ||
| ab.min_time as series_time | ||
| from account_bounds ab | ||
|
|
||
| union all | ||
|
|
||
| select | ||
| hs.account_id, | ||
| hs.pool_id, | ||
| hs.collateral_type, | ||
| hs.series_time + INTERVAL '1 hour' as series_time | ||
| from hourly_series hs | ||
| join account_bounds ab on hs.account_id = ab.account_id | ||
| where hs.series_time < ab.max_time | ||
| ), | ||
|
|
||
| last_known_values AS ( | ||
| select | ||
| hs.account_id, | ||
| hs.pool_id, | ||
| hs.collateral_type, | ||
| hs.series_time, | ||
| ( | ||
| select t.amount | ||
| from hourly_delegation as t | ||
| where t.account_id = hs.account_id | ||
| and t.block_timestamp <= hs.series_time | ||
| order by t.block_timestamp desc | ||
| limit 1 | ||
| ) as amount | ||
| from hourly_series hs | ||
| ), | ||
|
|
||
| final_result as ( | ||
| select | ||
| last_known_values.account_id, | ||
| last_known_values.pool_id, | ||
| last_known_values.collateral_type, | ||
| last_known_values.series_time as block_timestamp, | ||
| last_known_values.amount, | ||
| token_yields.hourly_exchange_rate_pnl | ||
| from last_known_values | ||
| left join {{ ref('fct_token_yields_eth_mainnet') }} as token_yields | ||
| on last_known_values.series_time = token_yields.ts | ||
| and last_known_values.pool_id = token_yields.pool_id | ||
| and lower(last_known_values.collateral_type) = lower(token_yields.collateral_type) | ||
| ) | ||
|
|
||
| select | ||
| account_id, | ||
| pool_id, | ||
| collateral_type, | ||
| coalesce(sum(amount * hourly_exchange_rate_pnl), 0) as yield_usd | ||
| from final_result | ||
| group by account_id, pool_id, collateral_type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
transformers/synthetix/seeds/tokens/arbitrum_mainnet_tokens.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we drop arbitrum? or do we keep it for the vibes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, I will remove it, we will soon be deprecating arbitrum from remaining dashboards too.