Skip to content

Commit

Permalink
[Ready For Review] init Balancer CoWSwap AMM spells (duneanalytics#6384)
Browse files Browse the repository at this point in the history
* init bcowamm trades spell

* update sources

* again

* fix column

* again

* fix unique key

* also update schema

* add new spells

* rename field

* fix schems

* remove file

* again

* from source to ref

* fix typo

* rename fields

* again

* small improvements

* rename columns in tests

* rerun

* rerun

* fix silly error

* remove null lines

* push fix for trades

* fix labels

* again

* join ethereum.transactions

* fix typo

* add more fields on join

* rerun

* another typo

* round of improvements + cross chain spells

* add new files

* fix typo

* attempt rerun

* resolve conflicts

* rename schemas

* x typo

* add blockchain to trades

* add pool_type and pool_symbol to trades

* add swap_fee calc

* fix join

* add pool_type column to labels

* simplify labels

* move to daily_spellbook

* fix source files

* move files into new directory structure

* final formats, remove post hooks

---------

Co-authored-by: jeff-dude <[email protected]>
  • Loading branch information
viniabussafi and jeff-dude committed Jul 26, 2024
1 parent 65a1893 commit 10d6086
Show file tree
Hide file tree
Showing 13 changed files with 848 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
version: 2

models:
- name: balancer_cowswap_amm_trades
meta:
blockchain: ethereum
sector: trades
project: balancer_cowswap_amm
contributors: viniabussafi
config:
tags: ['balancer', 'cowswap', 'ethereum', 'amm', 'trades']
description: "Trades on Balancer CoWSwap AMM pools"
columns:
- &blockchain
name: blockchain
description: "Blockchain"
- &project
name: project
description: "Project name (balancer)"
- &version
name: version
description: "Version of the project"
- &block_month
name: block_month
description: "Block month in UTC"
- &block_date
name: block_date
description: "Block date in UTC"
- &block_time
name: block_time
description: 'Block time in UTC'
- &block_number
name: block_number
description: 'Block number'
- &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"
- &maker
name: maker
description: "Address of trader who sold a token"
- &project_contract_address
name: project_contract_address
description: "Pool address"
- &tx_hash
name: tx_hash
description: "Tx. 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'
- name: pool_type
- name: pool_symbol
- name: swap_fee

- name: balancer_cowswap_amm_balances
meta:
blockchain: ethereum
project: balancer_cowswap_amm
contributors: viniabussafi
config:
tags: ['ethereum', 'balancer', 'balances']
description: >
ERC20 token rolling sum balances on Balancer, an automated portfolio manager and trading platform.
columns:
- &day
name: day
description: "UTC event block time truncated to the day mark"
tests:
- not_null
- &pool_address
name: pool_address
description: "Balancer CoWSwap AMM pool contract address"
- &token_address
name: token_address
description: "Token contract address"
- &token_balance_raw
name: token_balance_raw
description: "Balance of a token"

- name: labels_balancer_cowswap_amm_pools
meta:
blockchain: ethereum
sector: labels
project: balancer_cowswap_amm
contributors: viniabussafi
config:
tags: ['labels', 'ethereum', 'balancer', 'pools']
description: "Balancer CoWSwap AMM liquidity pools created on Ethereum."
columns:
- *blockchain
- &address
name: address
description: "Address of liquidity pool"
- &name
name: name
description: "Label name of pool containing the token symbols and their respective weights (if applicable)"
- &category
name: category
description: "Label category"
- &contributor
name: contributor
description: "Wizard(s) contributing to labels"
- &source
name: source
description: "How were labels generated (could be static or query)"
- &created_at
name: created_at
description: "When were labels created"
- &updated_at
name: updated_at
description: "When were labels updated for the last time"
- &model_name
name: model_name
description: "Name of the label model sourced from"
- &label_type
name: label_type
description: "Type of label (see labels overall readme)"

- name: balancer_cowswap_amm_liquidity
meta:
blockchain: ethereum
project: balancer_cowswap_amm
contributors: viniabussafi
config:
tags: ['ethereum', 'balancer', 'pools', 'liquidity']
description: >
Balancer CoWSwap AMM pools liquidity by token in Ethereum.
columns:
- *day
- name: pool_id
- *pool_address
- name: pool_symbol
- *version
- *blockchain
- name: pool_type
- *token_address
- &token_symbol
name: token_symbol
description: "Token symbol"
- *token_balance_raw
- &token_balance
name: token_balance
description: "Balance of the token in the pool"
- &protocol_liquidity_usd
name: protocol_liquidity_usd
description: "Protocol liquidity in USD"
- &protocol_liquidity_eth
name: protocol_liquidity_eth
description: "Protocol liquidity in ETH"
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{
config(
schema = 'balancer_cowswap_amm',
alias = 'balances',
materialized = 'view'
)
}}


{% set b_cow_amm_models = [
ref('balancer_cowswap_amm_ethereum_balances')
] %}

SELECT *
FROM (
{% for model in b_cow_amm_models %}
SELECT
day,
pool_address,
token_address,
token_balance_raw
FROM {{ model }}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{
config(
schema='balancer_cowswap_amm',
alias = 'liquidity',
materialized = 'view'
)
}}

{% set b_cow_amm_models = [
ref('balancer_cowswap_amm_ethereum_liquidity')
] %}

SELECT *
FROM (
{% for model in b_cow_amm_models %}
SELECT
day,
pool_id,
pool_address,
pool_symbol,
version,
blockchain,
pool_type,
token_address,
token_symbol,
token_balance_raw,
token_balance,
protocol_liquidity_usd,
protocol_liquidity_eth
FROM {{ model }}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{
config(
schema = 'balancer_cowswap_amm',
alias = 'trades',
materialized = 'view'
)
}}

{% set b_cow_amm_models = [
ref('balancer_cowswap_amm_ethereum_trades')
] %}

SELECT *
FROM (
{% for model in b_cow_amm_models %}
SELECT
blockchain
, project
, version
, block_month
, block_date
, block_time
, block_number
, 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
, tx_hash
, tx_from
, tx_to
, evt_index
, pool_type
, pool_symbol
FROM {{ model }}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
)
Loading

0 comments on commit 10d6086

Please sign in to comment.