Skip to content

Commit

Permalink
Merge pull request #97 from Synthetixio/transformers/fix-blocks-join
Browse files Browse the repository at this point in the history
Transfomer - Fix JOIN in core vault views
  • Loading branch information
Tburm authored Aug 13, 2024
2 parents 4565c4d + fc962f4 commit 91c3bb0
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 237 deletions.
2 changes: 1 addition & 1 deletion transformers/synthetix/.sqlfluff
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[sqlfluff]
dialect = postgres
templater = jinja
ignore = templating
runaway_limit = 10
max_line_length = 80
indent_unit = space
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
{{
config(
materialized='table'
)
}}

WITH base AS (
SELECT
with base as (
select
block_number,
contract_address,
chain_id,
pool_id,
collateral_type,
CAST(
amount AS numeric
) AS amount,
CAST(
"value" AS numeric
) AS collateral_value
FROM
cast(
amount as numeric
) as amount,
cast(
value as numeric
) as collateral_value
from
{{ source(
'raw_arbitrum_mainnet',
"core_get_vault_collateral"
) }}
WHERE
amount IS NOT NULL
where
amount is not null
)
SELECT
blocks.ts,
base.block_number,

select
to_timestamp(blocks.timestamp) as ts,
cast(
blocks.block_number as integer
) as block_number,
base.contract_address,
CAST(
base.pool_id AS INTEGER
) AS pool_id,
CAST(
base.collateral_type AS VARCHAR
) AS collateral_type,
{{ convert_wei('base.amount') }} AS amount,
{{ convert_wei('base.collateral_value') }} AS collateral_value
FROM
cast(
base.pool_id as integer
) as pool_id,
cast(
base.collateral_type as varchar
) as collateral_type,
{{ convert_wei('base.amount') }} as amount,
{{ convert_wei('base.collateral_value') }} as collateral_value
from
base
JOIN {{ ref('blocks_arbitrum_mainnet') }} AS blocks
ON base.block_number = blocks.block_number
inner join {{ source('raw_arbitrum_mainnet', 'blocks_parquet') }} as blocks
on base.block_number = blocks.block_number
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
{{
config(
materialized='table'
)
}}

WITH base AS (
SELECT
with base as (
select
block_number,
contract_address,
chain_id,
pool_id,
collateral_type,
CAST(
value_1 AS numeric
) AS debt
FROM
cast(
value_1 as numeric
) as debt
from
{{ source(
'raw_arbitrum_mainnet',
"core_get_vault_debt"
) }}
WHERE
value_1 IS NOT NULL
where
value_1 is not null
)
SELECT
blocks.ts,
base.block_number,

select
to_timestamp(blocks.timestamp) as ts,
cast(
blocks.block_number as integer
) as block_number,
base.contract_address,
CAST(
base.pool_id AS INTEGER
) AS pool_id,
CAST(
base.collateral_type AS VARCHAR
) AS collateral_type,
{{ convert_wei('base.debt') }} AS debt
FROM
cast(
base.pool_id as integer
) as pool_id,
cast(
base.collateral_type as varchar
) as collateral_type,
{{ convert_wei('base.debt') }} as debt
from
base
JOIN {{ ref('blocks_arbitrum_mainnet') }} AS blocks
ON base.block_number = blocks.block_number
inner join {{ source('raw_arbitrum_mainnet', 'blocks_parquet') }} as blocks
on base.block_number = blocks.block_number
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
{{
config(
materialized='table'
)
}}

WITH base AS (
SELECT
with base as (
select
block_number,
contract_address,
chain_id,
pool_id,
collateral_type,
CAST(
amount AS numeric
) AS amount,
CAST(
"value" AS numeric
) AS collateral_value
FROM
cast(
amount as numeric
) as amount,
cast(
value as numeric
) as collateral_value
from
{{ source(
'raw_arbitrum_sepolia',
"core_get_vault_collateral"
) }}
WHERE
amount IS NOT NULL
where
amount is not null
)
SELECT
blocks.ts,
base.block_number,

select
to_timestamp(blocks.timestamp) as ts,
cast(
blocks.block_number as integer
) as block_number,
base.contract_address,
CAST(
base.pool_id AS INTEGER
) AS pool_id,
CAST(
base.collateral_type AS VARCHAR
) AS collateral_type,
{{ convert_wei('base.amount') }} AS amount,
{{ convert_wei('base.collateral_value') }} AS collateral_value
FROM
cast(
base.pool_id as integer
) as pool_id,
cast(
base.collateral_type as varchar
) as collateral_type,
{{ convert_wei('base.amount') }} as amount,
{{ convert_wei('base.collateral_value') }} as collateral_value
from
base
JOIN {{ ref('blocks_arbitrum_sepolia') }} AS blocks
ON base.block_number = blocks.block_number
inner join {{ source('raw_arbitrum_sepolia', 'blocks_parquet') }} as blocks
on base.block_number = blocks.block_number
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
{{
config(
materialized='table'
)
}}

WITH base AS (
SELECT
with base as (
select
block_number,
contract_address,
chain_id,
pool_id,
collateral_type,
CAST(
value_1 AS numeric
) AS debt
FROM
cast(
value_1 as numeric
) as debt
from
{{ source(
'raw_arbitrum_sepolia',
"core_get_vault_debt"
) }}
WHERE
value_1 IS NOT NULL
where
value_1 is not null
)
SELECT
blocks.ts,
base.block_number,

select
to_timestamp(blocks.timestamp) as ts,
cast(
blocks.block_number as integer
) as block_number,
base.contract_address,
CAST(
base.pool_id AS INTEGER
) AS pool_id,
CAST(
base.collateral_type AS VARCHAR
) AS collateral_type,
{{ convert_wei('base.debt') }} AS debt
FROM
cast(
base.pool_id as integer
) as pool_id,
cast(
base.collateral_type as varchar
) as collateral_type,
{{ convert_wei('base.debt') }} as debt
from
base
JOIN {{ ref('blocks_arbitrum_sepolia') }} AS blocks
ON base.block_number = blocks.block_number
inner join {{ source('raw_arbitrum_sepolia', 'blocks_parquet') }} as blocks
on base.block_number = blocks.block_number
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
{{
config(
materialized='table'
)
}}


WITH base AS (
SELECT
with base as (
select
block_number,
contract_address,
chain_id,
pool_id,
collateral_type,
CAST(
amount AS numeric
) AS amount,
CAST(
"value" AS numeric
) AS collateral_value
FROM
cast(
amount as numeric
) as amount,
cast(
value as numeric
) as collateral_value
from
{{ source(
'raw_base_mainnet',
"core_get_vault_collateral"
) }}
WHERE
amount IS NOT NULL
where
amount is not null
)
SELECT
blocks.ts,
base.block_number,

select
to_timestamp(blocks.timestamp) as ts,
cast(
blocks.block_number as integer
) as block_number,
base.contract_address,
CAST(
base.pool_id AS INTEGER
) AS pool_id,
CAST(
base.collateral_type AS VARCHAR
) AS collateral_type,
{{ convert_wei('base.amount') }} AS amount,
{{ convert_wei('base.collateral_value') }} AS collateral_value
FROM
cast(
base.pool_id as integer
) as pool_id,
cast(
base.collateral_type as varchar
) as collateral_type,
{{ convert_wei('base.amount') }} as amount,
{{ convert_wei('base.collateral_value') }} as collateral_value
from
base
JOIN {{ ref('blocks_base_mainnet') }} AS blocks
ON base.block_number = blocks.block_number
inner join {{ source('raw_base_mainnet', 'blocks_parquet') }} as blocks
on base.block_number = blocks.block_number
Loading

0 comments on commit 91c3bb0

Please sign in to comment.