Skip to content

Commit

Permalink
add Avalanche-C models to Gyroscope (duneanalytics#6804)
Browse files Browse the repository at this point in the history
* fix typo

* add Avalanche-C models to Gyroscope

* again

* update cross-chain trades model

* update contributors
  • Loading branch information
viniabussafi authored Sep 23, 2024
1 parent 9484d1b commit 7f6532b
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
version: 2

models:

- name: gyroscope_avalanche_c_trades

meta:

blockchain: avalanche_c
project: gyroscope
contributors: viniabussafi

config:

tags: ["avalanche_c", "gyroscope", "trades"]

description: trades on gyroscope E-CLP pools on avalanche_c
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_time
- blockchain
- tx_hash
- evt_index
columns:
- &blockchain
name: blockchain
description: "blockchain name(avalanche_c)"
- &project
name: project
description: "gyroscope as project"
- &block_date
name: block_date
description: "UTC event block date"
- &block_month
name: block_month
description: "UTC event block month"
- &block_time
name: block_time
description: "UTC event block time"
- &token_bought_symbol
name: token_bought_symbol
description: "Token symbol for token bought in the trade"
- &token_sold_symbol
name: token_sold_symbol
description: "Token symbol for token sold in the trade"
- &token_pair
name: token_pair
description: "Token symbol pair for each token involved in the trade"
- &token_bought_amount
name: token_bought_amount
description: "Value of the token bought at time of execution in the original currency"
- &token_sold_amount
name: token_sold_amount
description: "Value of the token sold at time of execution in the original currency"
- &token_bought_amount_raw
name: token_bought_amount_raw
description: "Raw value of the token bought at time of execution in the original currency"
- &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"
- &token_sold_address
name: token_sold_address
description: "Contract address of the token sold"
- &taker
name: taker
description: "Address of trader who purchased a token"
- &project_contract_address
name: project_contract_address
description: "Ethereum address for the liquidity pool used in transaction"
- &pool_id
name: pool_id
description: "Unique encoded identifier that refers to each pool"
- &swap_fee
name: swap_fee
description: 'Swap fee'
- &tx_hash
name: tx_hash
description: "Transaction hash"
- &tx_from
name: tx_from
description: "transaction.from"
- &tx_to
name: tx_to
description: "transaction.to"
- &evt_index
name: evt_index
description: "Event index"
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{ config(
schema = 'gyroscope_avalanche_c',
alias = 'trades',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_time', 'blockchain', 'tx_hash', 'evt_index'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
)
}}

with E_CLPs AS (
SELECT
x.pool
, y.min_block_time
FROM {{ source('gyroscope_avalanche_c','GyroECLPPoolFactory_evt_PoolCreated') }} x
LEFT JOIN (
SELECT min(evt_block_time) AS min_block_time
FROM {{ source('gyroscope_avalanche_c','GyroECLPPoolFactory_evt_PoolCreated') }}
) y
on x.pool is not null
)

SELECT
blockchain,
'gyroscope' AS project,
block_date,
block_month,
block_time,
token_bought_symbol,
token_sold_symbol,
token_pair,
token_bought_amount,
token_sold_amount,
token_bought_amount_raw,
token_sold_amount_raw,
amount_usd,
token_bought_address,
token_sold_address,
taker,
maker,
project_contract_address,
pool_id,
swap_fee,
tx_hash,
tx_from,
tx_to,
evt_index
FROM {{ source('balancer_v2_avalanche_c', 'trades') }} x
inner join E_CLPs y
on x.block_time >= y.min_block_time
and x.project_contract_address = y.pool
{% if is_incremental() %}
WHERE
{{incremental_predicate('x.block_time')}}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ models:

meta:

blockchain: ethereum, arbitrum, optimism, polygon
blockchain: ethereum, arbitrum, optimism, polygon, avalanche_c
project: gyroscope
contributors: fmarrr
contributors: fmarrr, viniabussafi

config:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
schema = 'gyroscope',
alias = 'trades',
materialized = 'view',
post_hook='{{ expose_spells(\'["arbitrum", "ethereum","optimism", "polygon"]\',
post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "ethereum","optimism", "polygon"]\',
"project",
"gyroscope",
\'["fmarrr"]\') }}'
\'["fmarrr", "viniabussafi"]\') }}'
)
}}

{% set gyroscope_models = [
ref('gyroscope_arbitrum_trades'),
ref('gyroscope_avalanche_c_trades'),
ref('gyroscope_ethereum_trades'),
ref('gyroscope_optimism_trades'),
ref('gyroscope_polygon_trades')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ WITH pools AS (
CROSS JOIN UNNEST(
CAST(json_extract(settingsParams, '$.tokens') AS ARRAY(VARCHAR))
) AS t (tokens)

UNION ALL

SELECT
c.poolId AS pool_id,
t.tokens AS token_address,
0 AS normalized_weight,
cc.symbol,
'ECLP' AS pool_type
FROM {{ source('balancer_v2_avalanche_c', 'Vault_evt_PoolRegistered') }} c
INNER JOIN {{ source('gyroscope_avalanche_c', 'GyroECLPPoolFactory_call_create') }} cc
ON c.evt_tx_hash = cc.call_tx_hash
AND bytearray_substring(c.poolId, 1, 20) = cc.output_0
CROSS JOIN UNNEST(cc.tokens) AS t(tokens)
),

settings AS (
Expand All @@ -129,7 +143,7 @@ settings AS (
SELECT
'avalanche_c' AS blockchain,
bytearray_substring(pool_id, 1, 20) AS address,
CASE WHEN pool_type IN ('stable', 'linear', 'LBP', 'FX', 'managed')
CASE WHEN pool_type IN ('stable', 'linear', 'LBP', 'FX', 'managed', 'ECLP')
THEN lower(pool_symbol)
ELSE lower(concat(array_join(array_agg(token_symbol ORDER BY token_symbol), '/'), ' ',
array_join(array_agg(cast(norm_weight AS varchar) ORDER BY token_symbol), '/')))
Expand Down
23 changes: 23 additions & 0 deletions sources/gyroscope/avalanche_c/gyroscope_avalanche_c_sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2

sources:
- name: gyroscope_avalanche_c
description: >
Decoded tables related to gyroscope E-CLP pools on avalanche_c.
tables:
- name: GyroECLPPoolFactory_evt_PoolCreated
description: >
Decoded table of gyroscope pool created
columns:
- name: contract_address
description: 'creator address'
- name: evt_tx_hash
description: 'Primary key of the transaction'
- name: evt_index
description: 'Index value of the transaction'
- name: evt_block_time
description: 'Timestamp for block event time in UTC'
- name: evt_block_number
description: 'Block number which processed the unique transaction hash'
- name: pool
description: 'created ECLP pool address'
Original file line number Diff line number Diff line change
Expand Up @@ -1870,4 +1870,31 @@ sources:
- *swapFeePercentage
- *rateProviders
- *symbol
- *tokens
- *tokens

- name: gyroscope_avalanche_c
tables:
- name: GyroECLPPoolFactory_call_create
description: >
Decoded table of registered pools on the Gyroscope ECLP contract.
columns:
- *call_block_number
- *call_block_time
- *call_success
- *call_trace_address
- *call_tx_hash
- name: capManager
- name: capParams
- name: contract_address
description: "Address of the ECLP Pool contract"
- name: derivedECLPParams
- name: eclpParams
- name: name
- *output_0
- *owner
- name: pauseManager
- name: pauseParams
- *swapFeePercentage
- *rateProviders
- *symbol
- *tokens

0 comments on commit 7f6532b

Please sign in to comment.