-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Synthetixio/apr-calculation
APR calculation
- Loading branch information
Showing
8 changed files
with
145 additions
and
134 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
55 changes: 14 additions & 41 deletions
55
transformers/synthetix/models/marts/perp/fct_perp_pnl.sql
This file contains 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 |
---|---|---|
@@ -1,52 +1,25 @@ | ||
WITH market_updated AS ( | ||
SELECT | ||
DISTINCT block_number, | ||
LAST_VALUE((reported_debt + token_amount) / 1e18) over ( | ||
PARTITION BY block_number | ||
DISTINCT id, | ||
ts, | ||
market_id, | ||
LAST_VALUE((-1 * net_issuance) - (reported_debt + token_amount)) over ( | ||
PARTITION BY ts, | ||
market_id | ||
ORDER BY | ||
id | ||
) AS reported_debt | ||
) AS market_pnl | ||
FROM | ||
{{ ref('core_market_updated') }} | ||
{{ ref('fct_core_market_updated') }} | ||
WHERE | ||
market_id = 2 | ||
), | ||
net_transfers AS ( | ||
SELECT | ||
DISTINCT block_timestamp, | ||
block_number, | ||
LAST_VALUE(net_transfers) over ( | ||
PARTITION BY block_number | ||
ORDER BY | ||
id | ||
) AS net_transfers | ||
FROM | ||
( | ||
SELECT | ||
id, | ||
block_timestamp, | ||
block_number, | ||
SUM( | ||
amount_delta / 1e18 | ||
) over ( | ||
ORDER BY | ||
id | ||
) AS net_transfers | ||
FROM | ||
{{ ref('perp_collateral_modified') }} | ||
) modified | ||
) | ||
SELECT | ||
nt.block_timestamp AS ts, | ||
nt.block_number, | ||
2 AS market_id, | ||
nt.net_transfers, | ||
mu.reported_debt, | ||
mu.reported_debt - nt.net_transfers AS trader_pnl, | ||
nt.net_transfers - mu.reported_debt AS market_pnl | ||
id, | ||
ts, | ||
market_id, | ||
market_pnl | ||
FROM | ||
net_transfers nt | ||
JOIN market_updated mu | ||
ON nt.block_number = mu.block_number | ||
market_updated | ||
ORDER BY | ||
nt.block_number | ||
id |
This file contains 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,11 @@ | ||
SELECT | ||
id, | ||
"timestamp" AS ts, | ||
CAST( | ||
"number" AS INTEGER | ||
) AS block_number | ||
FROM | ||
{{ source( | ||
'raw_' ~ target.name, | ||
'block' | ||
) }} |
This file contains 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
This file contains 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,10 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: block | ||
description: "Block numbers and timestamps" | ||
columns: | ||
- name: id | ||
tests: | ||
- unique | ||
- not_null |
Oops, something went wrong.