mirror of
https://github.com/FlipsideCrypto/flow-models.git
synced 2026-02-06 07:56:48 +00:00
An 2434/swap labels (#86)
* need to match poolid to contract * pier swap pool labels * metapier labels test & docs * swaps labels core view * doc comment
This commit is contained in:
parent
232d2f61a0
commit
06643d4fd9
42
models/core/core__dim_swap_pool_labels.sql
Normal file
42
models/core/core__dim_swap_pool_labels.sql
Normal file
@ -0,0 +1,42 @@
|
||||
{{ config (
|
||||
materialized = 'view'
|
||||
) }}
|
||||
|
||||
WITH pairs AS (
|
||||
|
||||
SELECT
|
||||
swap_contract,
|
||||
deployment_timestamp,
|
||||
token0_contract,
|
||||
token1_contract,
|
||||
pool_id,
|
||||
vault_address
|
||||
FROM
|
||||
{{ ref('silver__labels_pools') }}
|
||||
),
|
||||
metapier AS (
|
||||
SELECT
|
||||
swap_contract,
|
||||
deployment_timestamp,
|
||||
token0_contract,
|
||||
token1_contract,
|
||||
pool_id,
|
||||
vault_address
|
||||
FROM
|
||||
{{ ref('silver__labels_pools_metapier') }}
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
pairs
|
||||
UNION
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
metapier
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
FINAL
|
||||
28
models/core/core__dim_swap_pool_labels.yml
Normal file
28
models/core/core__dim_swap_pool_labels.yml
Normal file
@ -0,0 +1,28 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: core__dim_swap_pool_labels
|
||||
description: |-
|
||||
This table takes swap pool/pair creation events and models out the relevant info, such as contracts for the token pairs, when it was deployed, and the address of the vault where tokens seem to be held.
|
||||
|
||||
columns:
|
||||
- name: tx_id
|
||||
description: "{{ doc('tx_id') }}"
|
||||
|
||||
- name: deployment_timestamp
|
||||
description: "{{ doc('deployment_timestamp') }}"
|
||||
|
||||
- name: token0_contract
|
||||
description: "{{ doc('token0_contract') }}"
|
||||
|
||||
- name: token1_contract
|
||||
description: "{{ doc('token1_contract') }}"
|
||||
|
||||
- name: pool_id
|
||||
description: "{{ doc('pool_id') }}"
|
||||
|
||||
- name: vault_address
|
||||
description: "{{ doc('vault_address') }}"
|
||||
|
||||
- name: swap_contract
|
||||
description: "{{ doc('swap_contract') }}"
|
||||
5
models/descriptions/pool_id.md
Normal file
5
models/descriptions/pool_id.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs pool_id %}
|
||||
|
||||
The ID of the swap pool, as designated by the DEX on contract creation.
|
||||
|
||||
{% enddocs %}
|
||||
@ -1,5 +1,6 @@
|
||||
{% docs swap_contract %}
|
||||
|
||||
The smart contract address of the DEX swap pool.
|
||||
Note for metapier swaps in the labels table - they all appear to use the same master contract `A.609e10301860b683.PierPair` so the `pool_id` is essential to differentiating what pool is used in the swap route.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/token0_contract.md
Normal file
5
models/descriptions/token0_contract.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs token0_contract %}
|
||||
|
||||
The contract for token0 in the swap pair. Positioning is determined by the order this token occurs in the Swap Contract creation transaction.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/token1_contract.md
Normal file
5
models/descriptions/token1_contract.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs token1_contract %}
|
||||
|
||||
The contract for token1 in the swap pair. Positioning is determined by the order this token occurs in the Swap Contract creation transaction.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/vault_address.md
Normal file
5
models/descriptions/vault_address.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs vault_address %}
|
||||
|
||||
The account address that holds tokens on behalf of the swap contract.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/silver/deployment_timestamp.md
Normal file
5
models/silver/deployment_timestamp.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs deployment_timestamp %}
|
||||
|
||||
The block timestamp from the deployment transaction.
|
||||
|
||||
{% enddocs %}
|
||||
65
models/silver/silver__labels_pools.sql
Normal file
65
models/silver/silver__labels_pools.sql
Normal file
@ -0,0 +1,65 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
unique_key = 'tx_id',
|
||||
incremental_strategy = 'delete+insert'
|
||||
) }}
|
||||
|
||||
WITH events AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__events_final') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
pair_labels AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__contract_labels') }}
|
||||
WHERE
|
||||
contract_name ILIKE '%swappair%'
|
||||
),
|
||||
pair_creation AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
block_timestamp,
|
||||
event_contract,
|
||||
event_data :numPairs :: NUMBER AS pair_number,
|
||||
event_data :pairAddress :: STRING AS account_address,
|
||||
event_data :token0Key :: STRING AS token0_contract,
|
||||
event_data :token1Key :: STRING AS token1_contract,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
events
|
||||
WHERE
|
||||
event_type = 'PairCreated'
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
block_timestamp AS deployment_timestamp,
|
||||
pair_number as pool_id,
|
||||
p.account_address as vault_address,
|
||||
token0_contract,
|
||||
token1_contract,
|
||||
l.event_contract AS swap_contract,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
pair_creation p
|
||||
LEFT JOIN pair_labels l USING (account_address)
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
FINAL
|
||||
50
models/silver/silver__labels_pools.yml
Normal file
50
models/silver/silver__labels_pools.yml
Normal file
@ -0,0 +1,50 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: silver__labels_pools
|
||||
description: |-
|
||||
Looks for new PairCreated events from the Swap pair factory and records info.
|
||||
|
||||
columns:
|
||||
- name: tx_id
|
||||
description: "{{ doc('tx_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- unique
|
||||
|
||||
- name: deployment_timestamp
|
||||
description: "{{ doc('deployment_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: token0_contract
|
||||
description: "{{ doc('token0_contract') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: token1_contract
|
||||
description: "{{ doc('token1_contract') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: pool_id
|
||||
description: "{{ doc('pool_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- unique
|
||||
|
||||
- name: vault_address
|
||||
description: "{{ doc('vault_address') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- unique
|
||||
|
||||
- name: swap_contract
|
||||
description: "{{ doc('swap_contract') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: _inserted_timestamp
|
||||
description: "{{ doc('_inserted_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
119
models/silver/silver__labels_pools_metapier.sql
Normal file
119
models/silver/silver__labels_pools_metapier.sql
Normal file
@ -0,0 +1,119 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
cluster_by = ['_inserted_timestamp::DATE'],
|
||||
unique_key = 'tx_id',
|
||||
incremental_strategy = 'delete+insert'
|
||||
) }}
|
||||
|
||||
WITH events AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__events_final') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
pierpools AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
block_timestamp,
|
||||
event_contract,
|
||||
event_type,
|
||||
event_data :poolId :: STRING AS pool_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
events
|
||||
WHERE
|
||||
event_contract = 'A.609e10301860b683.PierSwapFactory'
|
||||
AND event_type = 'NewPoolCreated'
|
||||
),
|
||||
pier_events AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
events
|
||||
WHERE
|
||||
tx_id IN (
|
||||
SELECT
|
||||
DISTINCT tx_id
|
||||
FROM
|
||||
pierpools
|
||||
)
|
||||
),
|
||||
token_withdraws AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
block_timestamp,
|
||||
event_contract,
|
||||
event_index,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
pier_events
|
||||
WHERE
|
||||
event_type = 'TokensWithdrawn'
|
||||
AND event_data :amount :: DOUBLE = 0
|
||||
),
|
||||
pairs AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
block_timestamp AS deployment_timestamp,
|
||||
event_contract AS token0_contract,
|
||||
LAG(event_contract) over (
|
||||
PARTITION BY tx_id
|
||||
ORDER BY
|
||||
event_index
|
||||
) AS token1_contract,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
token_withdraws
|
||||
),
|
||||
escrow AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
event_data :address :: STRING AS vault_address
|
||||
FROM
|
||||
pier_events
|
||||
WHERE
|
||||
event_contract = 'flow'
|
||||
AND event_type = 'AccountCreated'
|
||||
),
|
||||
pool_addr AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
event_contract AS swap_contract
|
||||
FROM
|
||||
pier_events
|
||||
WHERE
|
||||
event_type = 'Mint'
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
C.tx_id,
|
||||
C.deployment_timestamp,
|
||||
C.token0_contract,
|
||||
C.token1_contract,
|
||||
p.pool_id,
|
||||
e.vault_address,
|
||||
pa.swap_contract,
|
||||
C._inserted_timestamp
|
||||
FROM
|
||||
pairs C
|
||||
LEFT JOIN pierpools p USING (tx_id)
|
||||
LEFT JOIN escrow e USING (tx_id)
|
||||
LEFT JOIN pool_addr pa USING (tx_id)
|
||||
WHERE
|
||||
token1_contract IS NOT NULL
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
FINAL
|
||||
50
models/silver/silver__labels_pools_metapier.yml
Normal file
50
models/silver/silver__labels_pools_metapier.yml
Normal file
@ -0,0 +1,50 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: silver__labels_pools_metapier
|
||||
description: |-
|
||||
Looks for new PoolCreated events from the Metapier factory and recordes info.
|
||||
|
||||
columns:
|
||||
- name: tx_id
|
||||
description: "{{ doc('tx_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- unique
|
||||
|
||||
- name: deployment_timestamp
|
||||
description: "{{ doc('deployment_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: token0_contract
|
||||
description: "{{ doc('token0_contract') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: token1_contract
|
||||
description: "{{ doc('token1_contract') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: pool_id
|
||||
description: "{{ doc('pool_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- unique
|
||||
|
||||
- name: vault_address
|
||||
description: "{{ doc('vault_address') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- unique
|
||||
|
||||
- name: swap_contract
|
||||
description: "{{ doc('swap_contract') }}"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: _inserted_timestamp
|
||||
description: "{{ doc('_inserted_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
Loading…
Reference in New Issue
Block a user