Skip to content

Commit

Permalink
Merge branch 'main' into dex-trades-beta-dunesql
Browse files Browse the repository at this point in the history
  • Loading branch information
aalan3 authored Aug 19, 2023
2 parents 0557181 + 5f58228 commit bd42df1
Show file tree
Hide file tree
Showing 222 changed files with 4,599 additions and 2,309 deletions.
4 changes: 4 additions & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,10 @@ models:
+schema: layerzero_polygon
bnb:
+schema: layerzero_bnb
celo:
+schema: layerzero_celo
base:
+schema: layerzero_base

onepunchswap:
+schema: onepunchswap
Expand Down
1 change: 1 addition & 0 deletions models/apeswap/apeswap_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ FROM (
blockchain,
project,
version,
block_month,
block_date,
block_time,
token_bought_symbol,
Expand Down
3 changes: 3 additions & 0 deletions models/apeswap/apeswap_trades_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ models:
- &version
name: version
description: "Version of the contract built and deployed by the DEX project"
- &block_month
name: block_month
description: "UTC event block month of each DEX trade"
- &block_date
name: block_date
description: "UTC event block date of each DEX trade"
Expand Down
48 changes: 13 additions & 35 deletions models/balancer/arbitrum/balancer_arbitrum_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ models:
meta:
blockchain: arbitrum
project: balancer_v2
contributors: jacektrocinski
contributors: jacektrocinski, thetroyharris
config:
tags: ['arbitrum', 'balancer', 'pools_fees']
description: >
Expand All @@ -17,6 +17,7 @@ models:
- tx_hash
- index
columns:
- name: blockchain
- &contract_address
name: contract_address
description: 'Arbitrum address for the liquidity pool used in transaction'
Expand Down Expand Up @@ -57,9 +58,9 @@ models:
meta:
blockchain: arbitrum
project: balancer_v2
contributors: victorstefenon
contributors: victorstefenon, thetroyharris
config:
tags: ['arbitrum', 'bpt', 'prices']
tags: ['arbitrum', 'bpt', 'transfers']
description: >
Balancer Pool Token (BPT) transfer logs on Balancer, an automated portfolio manager and trading platform, on Arbitrum.
tests:
Expand All @@ -68,54 +69,35 @@ models:
- evt_tx_hash
- evt_index
- block_date
- check_seed_legacy:
seed_file: ref('balancer_transfers_bpt_seed')
filter:
blockchain: arbitrum
match_columns:
- evt_tx_hash
- evt_index
- block_date
check_columns:
- contract_address
- evt_block_number
- from
- to
columns:
- &blockchain
name: blockchain
description: "Blockchain"
- *contract_address
- &block_date
name: block_date
description: "UTC event block date of each DEX trade"
- &block_month
name: block_month
description: "UTC event block month of each DEX trade"
- &evt_tx_hash
name: evt_tx_hash
description: 'Transaction hash of transfer event'
tests:
- not_null
- &evt_index
name: evt_index
description: 'Event index'
tests:
- not_null
- &evt_block_time
name: evt_block_time
description: 'Block time of transfer event'
tests:
- not_null
- &evt_block_number
name: evt_block_number
description: 'Block number of transfer event'
tests:
- not_null
- &from
name: from
description: 'Address of BPT provider of transfer event'
tests:
- not_null
- &to
name: to
description: 'Address of BPT receiver of transfer event'
tests:
- not_null
- &value
name: value
description: 'Amount of BPT transferred in transfer event'
Expand Down Expand Up @@ -185,9 +167,7 @@ models:
project: balancer
version: 2
columns:
- &blockchain
name: blockchain
description: "Blockchain"
- *blockchain
- &project
name: project
description: "Project name (balancer)"
Expand Down Expand Up @@ -246,7 +226,6 @@ models:
name: trace_address
description: ""
- *evt_index


- name: balancer_v2_arbitrum_liquidity
meta:
Expand Down Expand Up @@ -279,7 +258,7 @@ models:
- name: protocol_liquidity_usd
description: 'Liquidity of the token in the pool in USD, except BPTs'
- name: pool_liquidity_usd
description: 'Liquidity of the token in the pool in USD, including BPTs'
description: 'Liquidity of the token in the pool in USD, including BPTs'

- name: balancer_v2_arbitrum_flashloans
meta:
Expand Down Expand Up @@ -312,7 +291,6 @@ models:
- name: recipient
- name: contract_address


- name: balancer_v2_arbitrum_bpt_prices
meta:
blockchain: arbitrum
Expand All @@ -339,7 +317,7 @@ models:
- &median_price
name: median_price
description: 'BPT median price'

- name: balancer_v2_arbitrum_trades
meta:
blockchain: arbitrum
Expand Down
21 changes: 12 additions & 9 deletions models/balancer/arbitrum/balancer_v2_arbitrum_pools_fees.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{
config(
schema = 'balancer_v2_arbitrum',
tags = ['dunesql'],
alias = alias('pools_fees'),
materialized = 'incremental',
file_format = 'delta',
Expand All @@ -9,36 +10,38 @@
post_hook='{{ expose_spells(\'["arbitrum"]\',
"project",
"balancer_v2",
\'["metacrypto", "jacektrocinski"]\') }}'
\'["metacrypto", "jacektrocinski", "thetroyharris"]\') }}'
}}

{% set event_signature = '0xa9ba3ffe0b6c366b81232caab38605a0699ad5398d6cce76f91ee809e322dafc' %}
{% set project_start_date = '2021-08-26' %}

WITH registered_pools AS (
SELECT DISTINCT
`poolAddress` AS pool_address
SELECT
DISTINCT poolAddress AS pool_address
FROM
{{ source ('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }}
{% if is_incremental() %}
WHERE evt_block_time >= DATE_TRUNC('day', NOW() - interval '7' day)
{% endif %}
)
SELECT
'arbitrum' AS blockchain,
logs.contract_address,
logs.tx_hash,
logs.tx_index,
logs.index,
logs.block_time,
logs.block_number,
bytea2numeric_v3 (SUBSTRING(logs.data FROM 32 FOR 64)) * 1 AS swap_fee_percentage
CAST(bytearray_to_uint256(bytearray_ltrim(logs.data)) AS DOUBLE) AS swap_fee_percentage
FROM
{{ source ('arbitrum', 'logs') }}
INNER JOIN registered_pools ON registered_pools.pool_address = logs.contract_address
WHERE logs.topic1 = '{{ event_signature }}'
WHERE logs.topic0 = {{ event_signature }}
{% if not is_incremental() %}
AND logs.block_time >= '{{ project_start_date }}'
AND logs.block_time >= TIMESTAMP '{{ project_start_date }}'
{% endif %}
{% if is_incremental() %}
AND logs.block_time >= DATE_TRUNC('day', NOW() - interval '1 week')
AND logs.block_time >= DATE_TRUNC('day', NOW() - interval '7' day)
{% endif %}
;

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{
config(
tags=['legacy'],

schema = 'balancer_v2_arbitrum',
alias = alias('pools_fees', legacy_model=True),
materialized = 'incremental',
Expand All @@ -25,6 +25,7 @@ WITH registered_pools AS (
{{ source ('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }}
)
SELECT
'arbitrum' AS blockchain,
logs.contract_address,
logs.tx_hash,
logs.tx_index,
Expand All @@ -43,4 +44,3 @@ WHERE logs.topic1 = '{{ event_signature }}'
AND logs.block_time >= DATE_TRUNC('day', NOW() - interval '1 week')
{% endif %}
;

23 changes: 13 additions & 10 deletions models/balancer/arbitrum/balancer_v2_arbitrum_transfers_bpt.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{{
config(
schema='balancer_v2_arbitrum',
schema = 'balancer_v2_arbitrum',
tags = ['dunesql'],
alias = alias('transfers_bpt'),
partition_by = ['block_date'],
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['block_date', 'evt_tx_hash', 'evt_index'],
post_hook='{{ expose_spells(\'["arbitrum"]\',
"project",
"balancer_v2",
\'["stefenon"]\') }}'
\'["stefenon", "thetroyharris"]\') }}'
)
}}

Expand All @@ -23,27 +24,29 @@ WITH registered_pools AS (
FROM
{{ source('balancer_v2_arbitrum', 'Vault_evt_PoolRegistered') }}
{% if is_incremental() %}
WHERE evt_block_time >= DATE_TRUNC('day', NOW() - interval '1 week')
WHERE evt_block_time >= DATE_TRUNC('day', NOW() - interval '7' day)
{% endif %}
)

SELECT DISTINCT * FROM (
SELECT
'arbitrum' AS blockchain,
logs.contract_address,
logs.tx_hash AS evt_tx_hash,
logs.index AS evt_index,
logs.block_time AS evt_block_time,
TRY_CAST(date_trunc('DAY', logs.block_time) AS date) AS block_date,
TRY_CAST(date_trunc('MONTH', logs.block_time) AS date) AS block_month,
logs.block_number AS evt_block_number,
CONCAT('0x', SUBSTRING(logs.topic2, 27, 40)) AS from,
CONCAT('0x', SUBSTRING(logs.topic3, 27, 40)) AS to,
bytea2numeric(SUBSTRING(logs.data, 32, 64)) AS value
bytearray_substring(topic1, 13) AS "from",
bytearray_substring(topic2, 13) AS to,
bytearray_to_uint256(logs.data) AS value
FROM {{ source('arbitrum', 'logs') }} logs
INNER JOIN registered_pools p ON p.pool_address = logs.contract_address
WHERE logs.topic1 = '{{ event_signature }}'
WHERE logs.topic0 = {{ event_signature }}
{% if not is_incremental() %}
AND logs.block_time >= '{{ project_start_date }}'
AND logs.block_time >= TIMESTAMP '{{ project_start_date }}'
{% endif %}
{% if is_incremental() %}
AND logs.block_time >= DATE_TRUNC('day', NOW() - interval '1 week')
AND logs.block_time >= DATE_TRUNC('day', NOW() - interval '7' day)
{% endif %} ) transfers
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

schema='balancer_v2_arbitrum',
alias = alias('transfers_bpt', legacy_model=True),
partition_by = ['block_date'],
partition_by = ['block_month'],
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
Expand All @@ -31,11 +31,13 @@ WITH registered_pools AS (

SELECT DISTINCT * FROM (
SELECT
'arbitrum' AS blockchain,
logs.contract_address,
logs.tx_hash AS evt_tx_hash,
logs.index AS evt_index,
logs.block_time AS evt_block_time,
TRY_CAST(date_trunc('DAY', logs.block_time) AS date) AS block_date,
TRY_CAST(date_trunc('MONTH', logs.block_time) AS date) AS block_month,
logs.block_number AS evt_block_number,
CONCAT('0x', SUBSTRING(logs.topic2, 27, 40)) AS from,
CONCAT('0x', SUBSTRING(logs.topic3, 27, 40)) AS to,
Expand Down
Loading

0 comments on commit bd42df1

Please sign in to comment.