mirror of
https://github.com/FlipsideCrypto/sei-models.git
synced 2026-02-06 09:22:03 +00:00
AN-6482/sei-evm-dex (#119)
* temp dex * remove order book dex oxium and update vars * is verified in prices * gold models * tags and remove legacy models * heal wf * remove file * revert * remove event name * remove so
This commit is contained in:
parent
9ca750f964
commit
741dd7e0aa
53
.github/workflows/dbt_run_heal_models.yml
vendored
Normal file
53
.github/workflows/dbt_run_heal_models.yml
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
name: dbt_run_heal_models
|
||||
run-name: dbt_run_heal_models
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
# At 12:10 UTC on Sunday
|
||||
- cron: '10 12 * * 0'
|
||||
|
||||
env:
|
||||
USE_VARS: "${{ vars.USE_VARS }}"
|
||||
DBT_PROFILES_DIR: "${{ vars.DBT_PROFILES_DIR }}"
|
||||
DBT_VERSION: "${{ vars.DBT_VERSION }}"
|
||||
ACCOUNT: "${{ vars.ACCOUNT }}"
|
||||
ROLE: "${{ vars.ROLE }}"
|
||||
USER: "${{ vars.USER }}"
|
||||
PASSWORD: "${{ secrets.PASSWORD }}"
|
||||
REGION: "${{ vars.REGION }}"
|
||||
DATABASE: "${{ vars.DATABASE }}"
|
||||
WAREHOUSE: "${{ vars.WAREHOUSE }}"
|
||||
SCHEMA: "${{ vars.SCHEMA }}"
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}
|
||||
|
||||
jobs:
|
||||
run_dbt_jobs:
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: workflow_prod
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "${{ vars.PYTHON_VERSION }}"
|
||||
cache: "pip"
|
||||
|
||||
- name: install dependencies
|
||||
run: |
|
||||
pip install -r requirements.txt
|
||||
dbt deps
|
||||
- name: Run DBT Jobs
|
||||
run: |
|
||||
dbt run -m "sei_models,tag:heal" --vars '{"HEAL_MODEL":True}'
|
||||
|
||||
notify-failure:
|
||||
needs: [run_dbt_jobs]
|
||||
if: failure()
|
||||
uses: ./.github/workflows/slack_notify.yml
|
||||
secrets:
|
||||
EVM_SLACK_WEBHOOK_URL: ${{ secrets.EVM_SLACK_WEBHOOK_URL }}
|
||||
2
.github/workflows/dbt_test_evm_recent.yml
vendored
2
.github/workflows/dbt_test_evm_recent.yml
vendored
@ -45,7 +45,7 @@ jobs:
|
||||
dbt deps
|
||||
- name: Run DBT Jobs
|
||||
run: |
|
||||
dbt test -m models/bronze/core "sei_models,tag:recent_evm_test"
|
||||
dbt test -m models/bronze/core "sei_models,tag:recent_evm_test" "sei_models,tag:curated"
|
||||
|
||||
notify-failure:
|
||||
needs: [run_dbt_jobs]
|
||||
|
||||
@ -48,6 +48,7 @@ vars:
|
||||
UPDATE_UDFS_AND_SPS: False
|
||||
WAIT: 0
|
||||
START_GHA_TASKS: False
|
||||
HEAL_MODEL: False
|
||||
HEAL_MODELS: []
|
||||
TEST_DAYS_THRESHOLD: 7
|
||||
|
||||
|
||||
@ -12,6 +12,8 @@ SELECT
|
||||
blockchain_name,
|
||||
blockchain_id,
|
||||
is_deprecated,
|
||||
is_verified,
|
||||
is_verified_modified_timestamp,
|
||||
provider,
|
||||
source,
|
||||
_inserted_timestamp,
|
||||
|
||||
@ -15,6 +15,7 @@ SELECT
|
||||
blockchain_id,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
is_verified,
|
||||
provider,
|
||||
source,
|
||||
_inserted_timestamp,
|
||||
|
||||
@ -140,4 +140,12 @@ Lowest price of the recorded hour in USD
|
||||
|
||||
Closing price of the recorded hour in USD
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_prices_is_verified %}
|
||||
|
||||
Boolean indicating Flipside team verification of the asset. TRUE for manually verified assets with validated metadata.
|
||||
|
||||
Example: true
|
||||
|
||||
{% enddocs %}
|
||||
467
models/evm/descriptions/defi/ez_dex_swaps.md
Normal file
467
models/evm/descriptions/defi/ez_dex_swaps.md
Normal file
@ -0,0 +1,467 @@
|
||||
{% docs ez_dex_swaps_table_doc %}
|
||||
|
||||
## What
|
||||
|
||||
This table provides a comprehensive view of token swap events across major decentralized exchanges (DEXs) on EVM blockchains. It standardizes swap data from different DEX protocols into a unified format, enabling cross-DEX analysis and DeFi trading insights.
|
||||
|
||||
## Key Use Cases
|
||||
|
||||
- Analyzing DEX trading volumes and market share
|
||||
- Tracking token pair liquidity and trading activity
|
||||
- Detecting arbitrage opportunities across protocols
|
||||
- Monitoring whale trades and unusual swap patterns
|
||||
- Calculating slippage and price impact of trades
|
||||
|
||||
## Important Relationships
|
||||
|
||||
- **Join with dim_dex_liquidity_pools**: Get pool metadata and token details
|
||||
- **Join with fact_event_logs**: Access raw swap events
|
||||
- **Join with ez_prices_hourly**: Verify token prices
|
||||
|
||||
## Commonly-used Fields
|
||||
|
||||
- `platform`: DEX protocol (uniswap_v2, curve, etc.)
|
||||
- `sender`: Address initiating the swap
|
||||
- `token_in`/`token_out`: Token addresses being swapped
|
||||
- `amount_in`/`amount_out`: Decimal-adjusted swap amounts
|
||||
- `amount_in_usd`/`amount_out_usd`: USD values at swap time
|
||||
- `pool_address`: Liquidity pool where swap occurred
|
||||
|
||||
## Sample queries
|
||||
|
||||
```sql
|
||||
-- Daily swap volume by DEX platform
|
||||
SELECT
|
||||
DATE_TRUNC('day', block_timestamp) AS date,
|
||||
platform,
|
||||
COUNT(*) AS swap_count,
|
||||
COUNT(DISTINCT sender) AS unique_traders,
|
||||
COUNT(DISTINCT pool_address) AS active_pools,
|
||||
SUM(amount_in_usd) AS total_volume_usd,
|
||||
AVG(amount_in_usd) AS avg_swap_size_usd,
|
||||
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY amount_in_usd) AS median_swap_usd
|
||||
FROM <blockchain_name>.defi.ez_dex_swaps
|
||||
WHERE block_timestamp >= CURRENT_DATE - 30
|
||||
AND amount_in_usd IS NOT NULL
|
||||
AND amount_in_usd > 0
|
||||
GROUP BY 1, 2
|
||||
ORDER BY 1 DESC, 6 DESC;
|
||||
|
||||
-- Most active trading pairs
|
||||
WITH pair_volume AS (
|
||||
SELECT
|
||||
LEAST(token_in, token_out) AS token_a,
|
||||
GREATEST(token_in, token_out) AS token_b,
|
||||
LEAST(symbol_in, symbol_out) AS symbol_a,
|
||||
GREATEST(symbol_in, symbol_out) AS symbol_b,
|
||||
COUNT(*) AS swap_count,
|
||||
SUM(amount_in_usd) AS volume_usd,
|
||||
COUNT(DISTINCT sender) AS unique_traders,
|
||||
COUNT(DISTINCT DATE(block_timestamp)) AS active_days
|
||||
FROM <blockchain_name>.defi.ez_dex_swaps
|
||||
WHERE block_timestamp >= CURRENT_DATE - 7
|
||||
AND amount_in_usd IS NOT NULL
|
||||
GROUP BY 1, 2, 3, 4
|
||||
)
|
||||
SELECT
|
||||
symbol_a || '/' || symbol_b AS pair,
|
||||
swap_count,
|
||||
volume_usd,
|
||||
unique_traders,
|
||||
active_days,
|
||||
volume_usd / swap_count AS avg_swap_size
|
||||
FROM pair_volume
|
||||
WHERE volume_usd > 100000
|
||||
ORDER BY volume_usd DESC
|
||||
LIMIT 50;
|
||||
|
||||
-- Price discrepancies across DEXs for same token pairs
|
||||
WITH recent_swaps AS (
|
||||
SELECT
|
||||
block_timestamp,
|
||||
platform,
|
||||
token_in,
|
||||
token_out,
|
||||
symbol_in,
|
||||
symbol_out,
|
||||
amount_in,
|
||||
amount_out,
|
||||
amount_in_usd / NULLIF(amount_in, 0) AS price_in_usd,
|
||||
amount_out_usd / NULLIF(amount_out, 0) AS price_out_usd,
|
||||
-- Calculate implied exchange rate
|
||||
amount_out / NULLIF(amount_in, 0) AS exchange_rate
|
||||
FROM <blockchain_name>.defi.ez_dex_swaps
|
||||
WHERE block_timestamp >= CURRENT_TIMESTAMP - INTERVAL '1 hour'
|
||||
AND amount_in > 0
|
||||
AND amount_out > 0
|
||||
AND amount_in_usd IS NOT NULL
|
||||
),
|
||||
price_comparison AS (
|
||||
SELECT
|
||||
DATE_TRUNC('minute', block_timestamp) AS minute,
|
||||
token_in,
|
||||
token_out,
|
||||
symbol_in || '->' || symbol_out AS pair,
|
||||
platform,
|
||||
AVG(exchange_rate) AS avg_rate,
|
||||
COUNT(*) AS swap_count
|
||||
FROM recent_swaps
|
||||
GROUP BY 1, 2, 3, 4, 5
|
||||
)
|
||||
SELECT
|
||||
p1.minute,
|
||||
p1.pair,
|
||||
p1.platform AS platform_1,
|
||||
p2.platform AS platform_2,
|
||||
p1.avg_rate AS rate_1,
|
||||
p2.avg_rate AS rate_2,
|
||||
ABS(p1.avg_rate - p2.avg_rate) / LEAST(p1.avg_rate, p2.avg_rate) * 100 AS price_diff_pct
|
||||
FROM price_comparison p1
|
||||
JOIN price_comparison p2
|
||||
ON p1.minute = p2.minute
|
||||
AND p1.token_in = p2.token_in
|
||||
AND p1.token_out = p2.token_out
|
||||
AND p1.platform < p2.platform
|
||||
WHERE price_diff_pct > 1 -- More than 1% difference
|
||||
ORDER BY p1.minute DESC, price_diff_pct DESC;
|
||||
|
||||
-- Large swaps by size and impact
|
||||
SELECT
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
platform,
|
||||
sender,
|
||||
symbol_in || ' -> ' || symbol_out AS swap_pair,
|
||||
amount_in,
|
||||
amount_in_usd,
|
||||
amount_out,
|
||||
amount_out_usd,
|
||||
ABS(amount_in_usd - amount_out_usd) / NULLIF(amount_in_usd, 0) * 100 AS slippage_pct
|
||||
FROM <blockchain_name>.defi.ez_dex_swaps
|
||||
WHERE block_timestamp >= CURRENT_DATE - 1
|
||||
AND amount_in_usd > 100000 -- Swaps over $100k
|
||||
ORDER BY amount_in_usd DESC
|
||||
LIMIT 100;
|
||||
|
||||
-- Platform market share by volume
|
||||
WITH platform_stats AS (
|
||||
SELECT
|
||||
platform,
|
||||
SUM(amount_in_usd) AS total_volume,
|
||||
COUNT(*) AS total_swaps,
|
||||
COUNT(DISTINCT sender) AS unique_users,
|
||||
COUNT(DISTINCT pool_address) AS unique_pools
|
||||
FROM <blockchain_name>.defi.ez_dex_swaps
|
||||
WHERE block_timestamp >= CURRENT_DATE - 7
|
||||
AND amount_in_usd IS NOT NULL
|
||||
GROUP BY 1
|
||||
)
|
||||
SELECT
|
||||
platform,
|
||||
total_volume,
|
||||
ROUND(100.0 * total_volume / SUM(total_volume) OVER (), 2) AS market_share_pct,
|
||||
total_swaps,
|
||||
unique_users,
|
||||
unique_pools,
|
||||
total_volume / NULLIF(total_swaps, 0) AS avg_swap_size
|
||||
FROM platform_stats
|
||||
ORDER BY total_volume DESC;
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs dim_dex_lp_table_doc %}
|
||||
|
||||
## What
|
||||
|
||||
This dimensional table contains comprehensive metadata for all DEX liquidity pools across supported protocols. It provides essential information about pool composition, token pairs, and configuration needed for analyzing liquidity provision and pool performance.
|
||||
|
||||
## Key Use Cases
|
||||
|
||||
- Finding all pools containing specific tokens
|
||||
- Tracking new pool deployments
|
||||
- Analyzing pool configurations and fee structures
|
||||
- Identifying trading pairs across different protocols
|
||||
- Monitoring factory contract deployments
|
||||
|
||||
## Important Relationships
|
||||
|
||||
- **Join with ez_dex_swaps**: Use `pool_address` to get swap activity
|
||||
- **Join with dim_contracts**: Use token addresses for additional metadata
|
||||
- **Self-join**: Find all pools with common tokens
|
||||
|
||||
## Commonly-used Fields
|
||||
|
||||
- `pool_address`: Unique identifier for the liquidity pool
|
||||
- `platform`: DEX protocol (uniswap_v3, curve, etc.)
|
||||
- `pool_name`: Human-readable pool identifier
|
||||
- `tokens`: JSON with token0 and token1 addresses
|
||||
- `symbols`: JSON with token0 and token1 symbols
|
||||
- `creation_time`: When pool was deployed
|
||||
|
||||
## Sample queries
|
||||
|
||||
```sql
|
||||
-- Find all pools containing USDC
|
||||
SELECT
|
||||
pool_address,
|
||||
pool_name,
|
||||
platform,
|
||||
creation_time,
|
||||
CASE
|
||||
WHEN tokens:token0::string = LOWER('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48') THEN
|
||||
symbols:token1::string
|
||||
ELSE
|
||||
symbols:token0::string
|
||||
END AS paired_token
|
||||
FROM <blockchain_name>.defi.dim_dex_liquidity_pools
|
||||
WHERE LOWER('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48') IN (
|
||||
tokens:token0::string,
|
||||
tokens:token1::string
|
||||
)
|
||||
ORDER BY creation_time DESC;
|
||||
|
||||
-- Recently created liquidity pools
|
||||
SELECT
|
||||
platform,
|
||||
pool_address,
|
||||
pool_name,
|
||||
creation_time,
|
||||
creation_tx,
|
||||
symbols:token0::string || '/' || symbols:token1::string AS pair,
|
||||
factory_address
|
||||
FROM <blockchain_name>.defi.dim_dex_liquidity_pools
|
||||
WHERE creation_time >= CURRENT_DATE - 7
|
||||
ORDER BY creation_time DESC
|
||||
LIMIT 100;
|
||||
|
||||
-- Extract token information from JSON fields
|
||||
SELECT
|
||||
pool_address,
|
||||
tokens:token0::string AS token0_address,
|
||||
tokens:token1::string AS token1_address,
|
||||
symbols:token0::string AS token0_symbol,
|
||||
symbols:token1::string AS token1_symbol,
|
||||
decimals:token0::integer AS token0_decimals,
|
||||
decimals:token1::integer AS token1_decimals
|
||||
FROM <blockchain_name>.defi.dim_dex_liquidity_pools
|
||||
WHERE platform = 'uniswap_v3';
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_amount_in %}
|
||||
|
||||
The decimal-adjusted quantity of tokens provided by the trader in the swap.
|
||||
|
||||
Example: 1000.5
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_amount_in_usd %}
|
||||
|
||||
USD value of tokens provided in the swap at time of transaction.
|
||||
|
||||
Example: 1500.75
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_amount_out %}
|
||||
|
||||
The decimal-adjusted quantity of tokens received by the trader from the swap.
|
||||
|
||||
Example: 0.65
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_sender %}
|
||||
|
||||
The address that initiated the swap transaction.
|
||||
|
||||
Example: '0x7a250d5630b4cf539739df2c5dacb4c659f2488d'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_to %}
|
||||
|
||||
The recipient address of the swapped tokens.
|
||||
|
||||
Example: '0x1234567890123456789012345678901234567890'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_platform %}
|
||||
|
||||
The DEX protocol where the swap occurred.
|
||||
|
||||
Example: 'uniswap_v3'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_pool_address %}
|
||||
|
||||
The liquidity pool contract address where the swap executed.
|
||||
|
||||
Example: '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_amount_in_unadj %}
|
||||
|
||||
The raw, non-decimal adjusted amount of tokens provided in the swap.
|
||||
|
||||
Example: 1000500000
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_amount_out_unadj %}
|
||||
|
||||
The raw, non-decimal adjusted amount of tokens received from the swap.
|
||||
|
||||
Example: 650000000000000000
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_amount_out_usd %}
|
||||
|
||||
USD value of tokens received from the swap at time of transaction.
|
||||
|
||||
Example: 1498.25
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_symbol_in %}
|
||||
|
||||
The ticker symbol of the token being sold/swapped from.
|
||||
|
||||
Example: 'USDC'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_symbol_out %}
|
||||
|
||||
The ticker symbol of the token being bought/received.
|
||||
|
||||
Example: 'WETH'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_token_in %}
|
||||
|
||||
The contract address of the token being sold in the swap.
|
||||
|
||||
Example: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_token_out %}
|
||||
|
||||
The contract address of the token being received from the swap.
|
||||
|
||||
Example: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_creation_block %}
|
||||
|
||||
The block number when the liquidity pool was first created.
|
||||
|
||||
Example: 12369739
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_creation_time %}
|
||||
|
||||
The timestamp when the liquidity pool was deployed.
|
||||
|
||||
Example: '2021-05-05 12:34:56.000'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_creation_tx %}
|
||||
|
||||
The transaction hash that deployed this liquidity pool.
|
||||
|
||||
Example: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_factory_address %}
|
||||
|
||||
The factory contract that deployed this liquidity pool.
|
||||
|
||||
Example: '0x1f98431c8ad98523631ae4a59f267346ea31f984'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_pool_name %}
|
||||
|
||||
Human-readable name for the liquidity pool.
|
||||
|
||||
Example: 'WETH/USDC 0.05%'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_decimals %}
|
||||
|
||||
JSON object containing decimal places for each token in the pool.
|
||||
|
||||
Example: {"token0": 18, "token1": 6}
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_symbols %}
|
||||
|
||||
JSON object containing token symbols for the pool pair.
|
||||
|
||||
Example: {"token0": "WETH", "token1": "USDC"}
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_tokens %}
|
||||
|
||||
JSON object containing token contract addresses in the pool.
|
||||
|
||||
Example: {"token0": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "token1": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"}
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_token_in_is_verified %}
|
||||
|
||||
Whether the token in the swap is verified.
|
||||
|
||||
Example: true
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_token_out_is_verified %}
|
||||
|
||||
Whether the token out of the swap is verified.
|
||||
|
||||
Example: true
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_protocol_version %}
|
||||
|
||||
The version of the protocol used for the swap.
|
||||
|
||||
Example: 'v3'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_protocol %}
|
||||
|
||||
The protocol used for the swap. This is the clean name of the protocol, not the platform, without the version.
|
||||
|
||||
Example: 'uniswap'
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs ez_dex_swaps_contract_address %}
|
||||
|
||||
The contract address of the swap. This is the address of the contract that executed the swap, often a pool contract.
|
||||
|
||||
Example: '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8'
|
||||
|
||||
{% enddocs %}
|
||||
399
models/evm/descriptions/general/general.md
Normal file
399
models/evm/descriptions/general/general.md
Normal file
@ -0,0 +1,399 @@
|
||||
{% docs general_block_number %}
|
||||
|
||||
Sequential counter representing the position of a block in the blockchain since genesis (block 0).
|
||||
|
||||
**Key Facts**:
|
||||
- Immutable once finalized
|
||||
- Primary ordering mechanism for blockchain data
|
||||
- Increments by 1 for each new block
|
||||
- Used as a proxy for time in many analyses
|
||||
|
||||
**Usage in Queries**:
|
||||
```sql
|
||||
-- Recent data
|
||||
WHERE block_number >= (SELECT MAX(block_number) - 1000 FROM fact_blocks)
|
||||
|
||||
-- Historical analysis
|
||||
WHERE block_number BETWEEN 15000000 AND 16000000
|
||||
|
||||
-- Join across tables
|
||||
JOIN <blockchain_name>.core.fact_event_logs USING (block_number)
|
||||
```
|
||||
|
||||
**Important**: Block numbers are chain-specific. Block 15000000 on Ethereum ≠ block 15000000 on Polygon.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_tx_hash %}
|
||||
|
||||
Unique 66-character identifier for the transaction.
|
||||
|
||||
**Format**: 0x + 64 hexadecimal characters
|
||||
|
||||
**Usage**:
|
||||
- Primary key for transaction lookups
|
||||
- Join key for traces, logs, and token transfers
|
||||
- Immutable once confirmed
|
||||
|
||||
**Example**: `0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060`
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_block_timestamp %}
|
||||
|
||||
UTC timestamp when the block was produced by validators/miners.
|
||||
|
||||
**Format**: TIMESTAMP_NTZ (no timezone)
|
||||
**Precision**: Second-level accuracy
|
||||
**Reliability**:
|
||||
- Set by block producer
|
||||
- Can have minor variations (±15 seconds)
|
||||
- Always increasing (newer blocks = later timestamps)
|
||||
|
||||
**Best Practices**:
|
||||
```sql
|
||||
-- Time-based filtering (most efficient)
|
||||
WHERE block_timestamp >= DATEADD('day', -7, CURRENT_TIMESTAMP)
|
||||
|
||||
-- Hourly aggregations
|
||||
DATE_TRUNC('hour', block_timestamp) AS hour
|
||||
|
||||
-- UTC date extraction
|
||||
DATE(block_timestamp) AS block_date
|
||||
```
|
||||
|
||||
**Note**: Use for time-series analysis, but be aware that block production rates vary by chain.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_from_address %}
|
||||
|
||||
The externally-owned account (EOA) or contract address that initiated the transaction.
|
||||
|
||||
**Key Points**:
|
||||
- Always 42 characters (0x + 40 hex chars)
|
||||
- Lowercase normalized in all tables
|
||||
- Cannot be NULL for valid transactions
|
||||
- For contract creation: sender of creation transaction
|
||||
|
||||
**Common Patterns**:
|
||||
- EOA → EOA: Simple transfer
|
||||
- EOA → Contract: User interaction
|
||||
- Contract → Contract: Internal calls (see fact_traces)
|
||||
- Known addresses: Exchange hot wallets, protocol deployers
|
||||
|
||||
**Query Examples**:
|
||||
```sql
|
||||
-- User activity analysis
|
||||
SELECT from_address, COUNT(*) as tx_count
|
||||
FROM <blockchain_name>.core.fact_transactions
|
||||
WHERE block_timestamp >= CURRENT_DATE - 30
|
||||
GROUP BY 1
|
||||
ORDER BY 2 DESC;
|
||||
|
||||
-- New user detection
|
||||
SELECT DISTINCT from_address
|
||||
FROM <blockchain_name>.core.fact_transactions t1
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM <blockchain_name>.core.fact_transactions t2
|
||||
WHERE t2.from_address = t1.from_address
|
||||
AND t2.block_number < t1.block_number
|
||||
);
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_to_address %}
|
||||
|
||||
The destination address for the transaction - either an EOA or contract address.
|
||||
|
||||
**Special Cases**:
|
||||
- NULL: Contract creation transaction
|
||||
- Contract address: Interacting with smart contract
|
||||
- EOA address: Simple transfer or receiving funds
|
||||
|
||||
**Important Patterns**:
|
||||
```sql
|
||||
-- Contract deployments
|
||||
WHERE to_address IS NULL
|
||||
|
||||
-- Popular contracts
|
||||
SELECT to_address, COUNT(*) as interactions
|
||||
FROM <blockchain_name>.core.fact_transactions
|
||||
WHERE to_address IS NOT NULL
|
||||
GROUP BY 1
|
||||
ORDER BY 2 DESC;
|
||||
|
||||
-- Direct transfers only
|
||||
WHERE to_address NOT IN (SELECT address FROM dim_contracts)
|
||||
```
|
||||
|
||||
**Note**: For token transfers, this is the token contract, not the recipient. See ez_token_transfers tables for recipient.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_pk %}
|
||||
|
||||
Primary key - unique identifier for each row ensuring data integrity.
|
||||
|
||||
**Format**: Usually VARCHAR containing composite key generated using MD5 hash of the relevant columns.
|
||||
**Example**: MD5(block_number, tx_hash, trace_index)
|
||||
|
||||
**Usage**:
|
||||
- Deduplication in incremental loads
|
||||
- Join operations for data quality checks
|
||||
- Troubleshooting specific records
|
||||
|
||||
**Important**: Implementation varies by table - check table-specific documentation.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_inserted_timestamp %}
|
||||
|
||||
UTC timestamp when the record was first added to the Flipside database.
|
||||
|
||||
**Format**: TIMESTAMP_NTZ
|
||||
|
||||
**Use Cases**:
|
||||
- Data freshness monitoring
|
||||
- Incremental processing markers
|
||||
- Debugging data pipeline issues
|
||||
- SLA tracking
|
||||
|
||||
**Query Example**:
|
||||
```sql
|
||||
-- Check data latency
|
||||
SELECT
|
||||
DATE_TRUNC('hour', block_timestamp) as block_hour,
|
||||
DATE_TRUNC('hour', inserted_timestamp) as insert_hour,
|
||||
AVG(TIMESTAMPDIFF('minute', block_timestamp, inserted_timestamp)) as avg_latency_minutes
|
||||
FROM <blockchain_name>.core.fact_transactions
|
||||
WHERE block_timestamp >= CURRENT_DATE - 1
|
||||
GROUP BY 1, 2;
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_modified_timestamp %}
|
||||
|
||||
UTC timestamp of the most recent update to this record.
|
||||
|
||||
**Format**: TIMESTAMP_NTZ
|
||||
|
||||
**Triggers for Updates**:
|
||||
- Data corrections
|
||||
- Enrichment additions
|
||||
- Reprocessing for accuracy
|
||||
- Schema migrations
|
||||
|
||||
**Monitoring Usage**:
|
||||
```sql
|
||||
-- Recently modified records
|
||||
SELECT *
|
||||
FROM <blockchain_name>.core.fact_transactions
|
||||
WHERE modified_timestamp > inserted_timestamp
|
||||
AND modified_timestamp >= CURRENT_DATE - 1;
|
||||
|
||||
-- Data quality tracking
|
||||
SELECT
|
||||
DATE(modified_timestamp) as mod_date,
|
||||
COUNT(*) as records_updated,
|
||||
COUNT(DISTINCT block_number) as blocks_affected
|
||||
FROM <blockchain_name>.core.fact_transactions
|
||||
WHERE modified_timestamp > inserted_timestamp
|
||||
GROUP BY 1
|
||||
ORDER BY 1 DESC;
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_value_precise_raw %}
|
||||
|
||||
String representation of numeric values preserving exact precision without any adjustments.
|
||||
|
||||
**Format**: VARCHAR containing numeric string
|
||||
**Purpose**: Prevents floating-point precision loss due to snowflake limitations
|
||||
**Contains**: Raw blockchain values (usually in smallest unit)
|
||||
|
||||
**Example Values**:
|
||||
- "1000000000000000000" = 1 ETH in Wei
|
||||
- "50000000" = 50 USDC (6 decimals)
|
||||
|
||||
**Usage**:
|
||||
```sql
|
||||
-- Exact value comparisons
|
||||
WHERE value_precise_raw = '1000000000000000000'
|
||||
|
||||
-- Conversion with precision
|
||||
CAST(value_precise_raw AS NUMERIC(38,0)) / POW(10, 18) AS value_decimal
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_value_precise %}
|
||||
|
||||
String representation of numeric values adjusted for human readability while maintaining precision.
|
||||
|
||||
**Format**: VARCHAR containing decimal string
|
||||
**Adjustments**: Converted from smallest unit to standard unit
|
||||
**Purpose**: Human-readable values without precision loss
|
||||
|
||||
**Example Values**:
|
||||
- "1.0" = 1 ETH (converted from Wei)
|
||||
- "50.0" = 50 USDC (converted from 6 decimal places)
|
||||
|
||||
**Best Practices**:
|
||||
```sql
|
||||
-- Safe numeric operations
|
||||
CAST(value_precise AS NUMERIC(38,18))
|
||||
|
||||
-- Filtering large values
|
||||
WHERE CAST(value_precise AS NUMERIC(38,18)) > 1000
|
||||
|
||||
-- Aggregations
|
||||
SUM(CAST(value_precise AS NUMERIC(38,18))) AS total_value
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_value_hex %}
|
||||
|
||||
Hexadecimal representation of transaction values as provided by the blockchain RPC.
|
||||
|
||||
**Format**: 0x-prefixed hex string
|
||||
**Example**: "0xde0b6b3a7640000" = 1 ETH in Wei
|
||||
|
||||
**Use Cases**:
|
||||
- Debugging RPC responses
|
||||
- Verifying data transformations
|
||||
- Handling special encoding cases
|
||||
|
||||
**Conversion Example**:
|
||||
- Hex to decimal (conceptual - use built-in conversions)
|
||||
- 0xde0b6b3a7640000 = 1000000000000000000 Wei = 1 ETH
|
||||
|
||||
**Note**: Most queries should use value or value_precise fields instead.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_origin_function_signature %}
|
||||
|
||||
Function signature (first 4 bytes) of the called method.
|
||||
|
||||
**Format**: 0x + 8 hex characters
|
||||
|
||||
**Common Signatures**:
|
||||
- 0xa9059cbb: transfer(address,uint256)
|
||||
- 0x095ea7b3: approve(address,uint256)
|
||||
- 0x23b872dd: transferFrom(address,address,uint256)
|
||||
|
||||
**Note**: NULL for simple transfers or invalid calls
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_tx_position %}
|
||||
|
||||
Zero-indexed position of transaction within its block.
|
||||
|
||||
**Insights**:
|
||||
- Position 0: First transaction in block
|
||||
- MEV bots often target early positions
|
||||
- Bundle transactions appear consecutively
|
||||
- Useful for analyzing transaction ordering
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_value %}
|
||||
|
||||
Amount of native tokens transferred, in token units (not Wei).
|
||||
|
||||
**Key Points**:
|
||||
- 0 for most contract interactions
|
||||
- >0 for native token transfers or payable functions
|
||||
- Already converted from Wei (divided by 1e18)
|
||||
- Use value_precise for exact amounts
|
||||
|
||||
**Example Query**:
|
||||
```sql
|
||||
-- Daily native token transfer volume
|
||||
SELECT
|
||||
DATE_TRUNC('day', block_timestamp) AS day,
|
||||
SUM(value) AS total_transferred,
|
||||
COUNT(*) AS transfer_count
|
||||
FROM <blockchain_name>.core.fact_transactions
|
||||
WHERE value > 0 AND tx_succeeded
|
||||
GROUP BY 1;
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_tx_succeeded %}
|
||||
|
||||
Boolean indicator of transaction success.
|
||||
|
||||
**Values**:
|
||||
- TRUE: Transaction executed successfully
|
||||
- FALSE: Transaction failed/reverted
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_event_index %}
|
||||
|
||||
Zero-based sequential position of the event within a transaction's execution.
|
||||
|
||||
**Key Facts**:
|
||||
- Starts at 0 for first event
|
||||
- Increments across all contracts in transaction
|
||||
- Preserves execution order
|
||||
- Essential for deterministic event ordering
|
||||
|
||||
**Usage Example**:
|
||||
```sql
|
||||
-- Trace event execution flow
|
||||
SELECT
|
||||
event_index,
|
||||
contract_address,
|
||||
topic_0,
|
||||
SUBSTRING(data, 1, 10) AS data_preview
|
||||
FROM <blockchain_name>.core.fact_event_logs
|
||||
WHERE tx_hash = '0xabc...'
|
||||
ORDER BY event_index;
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_contract_address %}
|
||||
|
||||
Smart contract address that emitted this event or received the transaction.
|
||||
|
||||
**Key Points**:
|
||||
- Always the immediate event emitter for logs
|
||||
- May differ from transaction to_address
|
||||
- Lowercase normalized format
|
||||
- Never NULL for valid events
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs general_event_name %}
|
||||
|
||||
The event name as defined in the contract's ABI.
|
||||
|
||||
**Format**: PascalCase event identifier
|
||||
**Examples**:
|
||||
- `Transfer` - Token transfers
|
||||
- `Swap` - DEX trades
|
||||
- `OwnershipTransferred` - Admin changes
|
||||
- `Approval` - Token approvals
|
||||
|
||||
**Usage Pattern**:
|
||||
|
||||
```sql
|
||||
-- Find all event types for a contract
|
||||
SELECT DISTINCT event_name, COUNT(*) as occurrences
|
||||
FROM ez_decoded_event_logs
|
||||
WHERE contract_address = LOWER('0x...')
|
||||
GROUP BY 1
|
||||
ORDER BY 2 DESC;
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
@ -1,56 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'pool_address',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH created_pools AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
decoded_log :token0 :: STRING AS token0,
|
||||
decoded_log :token1 :: STRING AS token1,
|
||||
decoded_log :pair :: STRING AS pool_address,
|
||||
decoded_log :length :: INT AS pool_id
|
||||
FROM
|
||||
{{ ref ('core_evm__ez_decoded_event_logs') }}
|
||||
WHERE
|
||||
tx_succeeded
|
||||
AND contract_address = LOWER('0x71f6b49ae1558357bbb5a6074f1143c46cbca03d') --DragonswapFactory
|
||||
AND event_name = 'PairCreated'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '5 minutes'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
token0,
|
||||
token1,
|
||||
pool_address,
|
||||
pool_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['pool_address']
|
||||
) }} AS dragonswap_pools_v1_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
created_pools qualify(ROW_NUMBER() over (PARTITION BY pool_address
|
||||
ORDER BY
|
||||
block_timestamp DESC)) = 1
|
||||
@ -1,61 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'pool_address',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH created_pools AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1,
|
||||
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS pool_address,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
)
|
||||
) AS pool_id,
|
||||
FROM
|
||||
{{ ref ('core_evm__fact_event_logs') }}
|
||||
WHERE
|
||||
tx_status = 'SUCCESS'
|
||||
AND contract_address = LOWER('0x179d9a5592bc77050796f7be28058c51ca575df4') --DragonswapFactoryV2
|
||||
AND topics [0] :: STRING = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '5 minutes'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
token0,
|
||||
token1,
|
||||
pool_address,
|
||||
pool_id,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['pool_address']
|
||||
) }} AS dragonswap_pools_v2_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
created_pools qualify(ROW_NUMBER() over (PARTITION BY pool_address
|
||||
ORDER BY
|
||||
block_timestamp DESC)) = 1
|
||||
@ -1,62 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
tx_to,
|
||||
sender,
|
||||
ABS(amount_in_unadj) AS amount_in_unadj,
|
||||
ABS(amount_out_unadj) AS amount_out_unadj,
|
||||
token_in,
|
||||
token_out,
|
||||
dragonswap_swaps_decoded_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_invocation_id
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_swaps_decoded') }}
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
tx_to,
|
||||
sender,
|
||||
CASE
|
||||
WHEN amount0_unadj < 0 THEN amount1_unadj
|
||||
ELSE amount0_unadj
|
||||
END AS amount_in_unadj,
|
||||
CASE
|
||||
WHEN amount0_unadj < 0 THEN ABS(amount0_unadj)
|
||||
ELSE ABS(amount1_unadj)
|
||||
END AS amount_out_unadj,
|
||||
CASE
|
||||
WHEN amount0_unadj < 0 THEN token1
|
||||
ELSE token0
|
||||
END AS token_in,
|
||||
CASE
|
||||
WHEN amount0_unadj < 0 THEN token0
|
||||
ELSE token1
|
||||
END AS token_out,
|
||||
dragonswap_swaps_undecoded_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_invocation_id
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_swaps_undecoded') }}
|
||||
@ -1,38 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_evm_dex__dragonswap_swaps_combined
|
||||
description: Records of swaps that occurred on the dragonswap platform
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 1
|
||||
- name: tx_hash
|
||||
|
||||
- name: event_index
|
||||
|
||||
- name: event_name
|
||||
|
||||
- name: origin_function_signature
|
||||
|
||||
- name: origin_from_address
|
||||
|
||||
- name: origin_to_address
|
||||
|
||||
- name: contract_address
|
||||
|
||||
- name: tx_to
|
||||
|
||||
- name: sender
|
||||
|
||||
- name: amount_in_unadj
|
||||
|
||||
- name: amount_out_unadj
|
||||
|
||||
- name: token_in
|
||||
|
||||
- name: token_out
|
||||
|
||||
@ -1,113 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'dragonswap_swaps_decoded_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH pools AS (
|
||||
|
||||
SELECT
|
||||
pool_address,
|
||||
token0,
|
||||
token1
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_pools_v1') }}
|
||||
UNION ALL
|
||||
SELECT
|
||||
pool_address,
|
||||
token0,
|
||||
token1
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_pools_v2') }}
|
||||
),
|
||||
swaps_base AS (
|
||||
SELECT
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.tx_hash,
|
||||
l.event_index,
|
||||
l.event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
decoded_log: amount0In :: bigint AS amount0In,
|
||||
decoded_log: amount1In :: bigint AS amount1In,
|
||||
decoded_log: amount0Out :: bigint AS amount0Out,
|
||||
decoded_log: amount1Out :: bigint AS amount1Out,
|
||||
decoded_log :sender :: STRING AS sender,
|
||||
decoded_log :to :: STRING AS tx_to,
|
||||
token0,
|
||||
token1
|
||||
FROM
|
||||
{{ ref('core_evm__ez_decoded_event_logs') }}
|
||||
l
|
||||
INNER JOIN pools p
|
||||
ON p.pool_address = l.contract_address
|
||||
WHERE
|
||||
event_name = 'Swap'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '5 minutes'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
sender,
|
||||
tx_to,
|
||||
amount0In,
|
||||
amount1In,
|
||||
amount0Out,
|
||||
amount1Out,
|
||||
token0,
|
||||
token1,
|
||||
CASE
|
||||
WHEN amount0In <> 0
|
||||
AND amount1In <> 0
|
||||
AND amount0Out <> 0 THEN amount1In
|
||||
WHEN amount0In <> 0 THEN amount0In
|
||||
WHEN amount1In <> 0 THEN amount1In
|
||||
END AS amount_in_unadj,
|
||||
CASE
|
||||
WHEN amount0Out <> 0 THEN amount0Out
|
||||
WHEN amount1Out <> 0 THEN amount1Out
|
||||
END AS amount_out_unadj,
|
||||
CASE
|
||||
WHEN amount0In <> 0
|
||||
AND amount1In <> 0
|
||||
AND amount0Out <> 0 THEN token1
|
||||
WHEN amount0In <> 0 THEN token0
|
||||
WHEN amount1In <> 0 THEN token1
|
||||
END AS token_in,
|
||||
CASE
|
||||
WHEN amount0Out <> 0 THEN token0
|
||||
WHEN amount1Out <> 0 THEN token1
|
||||
END AS token_out,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS dragonswap_swaps_decoded_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
swaps_base
|
||||
WHERE
|
||||
token_in <> token_out
|
||||
@ -1,96 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'dragonswap_swaps_undecoded_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH pools AS (
|
||||
|
||||
SELECT
|
||||
pool_address,
|
||||
token0,
|
||||
token1
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_pools_v1') }}
|
||||
UNION ALL
|
||||
SELECT
|
||||
pool_address,
|
||||
token0,
|
||||
token1
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_pools_v2') }}
|
||||
),
|
||||
swaps_base AS (
|
||||
SELECT
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.tx_hash,
|
||||
l.event_index,
|
||||
NULL AS event_name,
|
||||
l.origin_function_signature,
|
||||
l.origin_from_address,
|
||||
l.origin_to_address,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data [0] :: STRING
|
||||
) :: FLOAT AS amount0_unadj,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data [1] :: STRING
|
||||
) :: FLOAT AS amount1_unadj,
|
||||
token0,
|
||||
token1,
|
||||
pool_address
|
||||
FROM
|
||||
{{ ref('core_evm__fact_event_logs') }}
|
||||
l
|
||||
INNER JOIN pools p
|
||||
ON p.pool_address = l.contract_address
|
||||
WHERE
|
||||
l.block_timestamp :: DATE >= '2024-01-01'
|
||||
AND topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
modified_timestamp
|
||||
) - INTERVAL '5 minutes'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
pool_address,
|
||||
tx_to,
|
||||
sender,
|
||||
token0,
|
||||
token1,
|
||||
amount0_unadj,
|
||||
amount1_unadj,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS dragonswap_swaps_undecoded_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
swaps_base
|
||||
@ -0,0 +1,284 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'pool_address',
|
||||
tags = ['silver_dex','defi','dex','curated']
|
||||
) }}
|
||||
|
||||
WITH contract_mapping AS (
|
||||
SELECT * FROM VALUES
|
||||
('0xfb43069f6d0473b85686a85f4ce4fc1fd8f00875', 'jellyswap', 'v1', 'balancer_pool_created')
|
||||
AS t(contract_address, protocol, version, type) --based on Balancer protocol models
|
||||
),
|
||||
pools_registered AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
tx_hash,
|
||||
l.contract_address,
|
||||
topics [1] :: STRING AS pool_id,
|
||||
SUBSTR(
|
||||
topics [1] :: STRING,
|
||||
1,
|
||||
42
|
||||
) AS pool_address,
|
||||
m.protocol,
|
||||
m.version,
|
||||
m.type,
|
||||
CONCAT(m.protocol, '-', m.version) AS platform,
|
||||
'PoolRegistered' AS event_name,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp,
|
||||
ROW_NUMBER() over (
|
||||
ORDER BY
|
||||
pool_address
|
||||
) AS row_num
|
||||
FROM
|
||||
{{ ref('core_evm__fact_event_logs') }}
|
||||
l
|
||||
INNER JOIN contract_mapping m
|
||||
ON l.contract_address = m.contract_address
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x3c13bc30b8e878c53fd2a36b679409c073afd75950be43d8858768e956fbc20e' --PoolRegistered
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 days'
|
||||
{% endif %}
|
||||
),
|
||||
tokens_registered AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
tx_hash,
|
||||
l.contract_address,
|
||||
decoded_log :poolId :: STRING AS pool_id,
|
||||
decoded_log :tokens AS tokens,
|
||||
tokens [0] :: STRING AS token0,
|
||||
tokens [1] :: STRING AS token1,
|
||||
tokens [2] :: STRING AS token2,
|
||||
tokens [3] :: STRING AS token3,
|
||||
tokens [4] :: STRING AS token4,
|
||||
tokens [5] :: STRING AS token5,
|
||||
tokens [6] :: STRING AS token6,
|
||||
tokens [7] :: STRING AS token7,
|
||||
decoded_log :assetManagers AS asset_managers,
|
||||
m.protocol,
|
||||
m.version,
|
||||
m.type,
|
||||
CONCAT(m.protocol, '-', m.version) AS platform,
|
||||
event_name,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core_evm__ez_decoded_event_logs') }}
|
||||
l
|
||||
INNER JOIN contract_mapping m
|
||||
ON l.contract_address = m.contract_address
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xf5847d3f2197b16cdcd2098ec95d0905cd1abdaf415f07bb7cef2bba8ac5dec4' --TokensRegistered
|
||||
AND tx_hash IN (
|
||||
SELECT
|
||||
tx_hash
|
||||
FROM
|
||||
pools_registered
|
||||
)
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 days'
|
||||
{% endif %}
|
||||
),
|
||||
function_sigs AS (
|
||||
SELECT
|
||||
'0x06fdde03' AS function_sig,
|
||||
'name' AS function_name
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x95d89b41' AS function_sig,
|
||||
'symbol' AS function_name
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x313ce567' AS function_sig,
|
||||
'decimals' AS function_name
|
||||
),
|
||||
inputs_pools AS (
|
||||
SELECT
|
||||
pool_address,
|
||||
block_number,
|
||||
function_sig
|
||||
FROM
|
||||
pools_registered
|
||||
JOIN function_sigs
|
||||
ON 1 = 1
|
||||
),
|
||||
build_rpc_requests AS (
|
||||
SELECT
|
||||
pool_address,
|
||||
block_number,
|
||||
function_sig,
|
||||
RPAD(
|
||||
function_sig,
|
||||
64,
|
||||
'0'
|
||||
) AS input,
|
||||
utils.udf_json_rpc_call(
|
||||
'eth_call',
|
||||
[{'to': pool_address, 'from': null, 'data': input}, utils.udf_int_to_hex(block_number)],
|
||||
concat_ws(
|
||||
'-',
|
||||
pool_address,
|
||||
input,
|
||||
block_number
|
||||
)
|
||||
) AS rpc_request,
|
||||
row_num,
|
||||
CEIL(
|
||||
row_num / 250
|
||||
) AS batch_no
|
||||
FROM
|
||||
inputs_pools
|
||||
LEFT JOIN pools_registered USING(pool_address)
|
||||
),
|
||||
pool_token_reads AS ({% for item in range(20) %}
|
||||
(
|
||||
SELECT
|
||||
live.udf_api('POST','{Service}/{Authentication}',{}, batch_rpc_request, 'Vault/prod/sei/quicknode/mainnet') AS read_output, SYSDATE() AS _inserted_timestamp
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
ARRAY_AGG(rpc_request) batch_rpc_request
|
||||
FROM
|
||||
build_rpc_requests
|
||||
WHERE
|
||||
batch_no = {{ item }} + 1
|
||||
AND batch_no IN (
|
||||
SELECT
|
||||
DISTINCT batch_no
|
||||
FROM
|
||||
build_rpc_requests))) {% if not loop.last %}
|
||||
UNION ALL
|
||||
{% endif %}
|
||||
{% endfor %}),
|
||||
reads_adjusted AS (
|
||||
SELECT
|
||||
VALUE :id :: STRING AS read_id,
|
||||
VALUE :result :: STRING AS read_result,
|
||||
SPLIT(
|
||||
read_id,
|
||||
'-'
|
||||
) AS read_id_object,
|
||||
read_id_object [0] :: STRING AS pool_address,
|
||||
LEFT(
|
||||
read_id_object [1] :: STRING,
|
||||
10
|
||||
) AS function_sig,
|
||||
read_id_object [2] :: STRING AS block_number,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
pool_token_reads,
|
||||
LATERAL FLATTEN(
|
||||
input => read_output :data
|
||||
)
|
||||
),
|
||||
pool_details AS (
|
||||
SELECT
|
||||
pool_address,
|
||||
function_sig,
|
||||
function_name,
|
||||
read_result,
|
||||
regexp_substr_all(SUBSTR(read_result, 3, len(read_result)), '.{64}') AS segmented_output,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
reads_adjusted
|
||||
LEFT JOIN function_sigs USING(function_sig)
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
pool_address,
|
||||
MIN(
|
||||
CASE
|
||||
WHEN function_name = 'symbol' THEN utils.udf_hex_to_string(
|
||||
segmented_output [2] :: STRING
|
||||
)
|
||||
END
|
||||
) AS pool_symbol,
|
||||
MIN(
|
||||
CASE
|
||||
WHEN function_name = 'name' THEN utils.udf_hex_to_string(
|
||||
segmented_output [2] :: STRING
|
||||
)
|
||||
END
|
||||
) AS pool_name,
|
||||
MIN(
|
||||
CASE
|
||||
WHEN read_result :: STRING = '0x' THEN NULL
|
||||
ELSE utils.udf_hex_to_int(LEFT(read_result :: STRING, 66))
|
||||
END
|
||||
) :: INTEGER AS pool_decimals,
|
||||
MAX(_inserted_timestamp) AS _inserted_timestamp
|
||||
FROM
|
||||
pool_details
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
SELECT
|
||||
p.block_number,
|
||||
p.block_timestamp,
|
||||
p.event_index,
|
||||
COALESCE(p.event_name,t.event_name) AS event_name,
|
||||
p.tx_hash,
|
||||
p.contract_address,
|
||||
p.pool_id,
|
||||
f.pool_address,
|
||||
f.pool_symbol,
|
||||
f.pool_name,
|
||||
f.pool_decimals,
|
||||
t.token0,
|
||||
t.token1,
|
||||
t.token2,
|
||||
t.token3,
|
||||
t.token4,
|
||||
t.token5,
|
||||
t.token6,
|
||||
t.token7,
|
||||
t.asset_managers,
|
||||
COALESCE(p.platform,t.platform) AS platform,
|
||||
COALESCE(p.protocol,t.protocol) AS protocol,
|
||||
COALESCE(p.version,t.version) AS version,
|
||||
COALESCE(p.type,t.type) AS type,
|
||||
p._log_id,
|
||||
f._inserted_timestamp
|
||||
FROM
|
||||
FINAL f
|
||||
LEFT JOIN pools_registered p
|
||||
ON f.pool_address = p.pool_address
|
||||
LEFT JOIN tokens_registered t
|
||||
ON p.pool_id = t.pool_id
|
||||
WHERE
|
||||
t.token0 IS NOT NULL qualify(ROW_NUMBER() over(PARTITION BY f.pool_address
|
||||
ORDER BY
|
||||
f._inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,8 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_dex__jellyswap_pools
|
||||
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- POOL_ADDRESS
|
||||
@ -0,0 +1,107 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'block_number',
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver_dex','defi','dex','curated']
|
||||
) }}
|
||||
|
||||
WITH pool_name AS (
|
||||
|
||||
SELECT
|
||||
CASE
|
||||
WHEN p.pool_name IS NULL THEN p.pool_symbol
|
||||
ELSE p.pool_name
|
||||
END AS pool_name,
|
||||
pool_address,
|
||||
contract_address,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type
|
||||
FROM
|
||||
{{ ref('silver_dex__jellyswap_pools') }} p
|
||||
),
|
||||
swaps_base AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
'Swap' AS event_name,
|
||||
event_index,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
)
|
||||
) AS amount_in_unadj,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
)
|
||||
) AS amount_out_unadj,
|
||||
topics [1] :: STRING AS pool_id,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token_in,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS token_out,
|
||||
SUBSTR(
|
||||
topics [1] :: STRING,
|
||||
1,
|
||||
42
|
||||
) AS pool_address,
|
||||
origin_from_address AS sender,
|
||||
origin_from_address AS tx_to,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core_evm__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (SELECT DISTINCT contract_address FROM pool_name)
|
||||
AND topics [0] :: STRING = '0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0a8dd37b1840b9e0b207b'
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 days'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
event_index,
|
||||
amount_in_unadj,
|
||||
amount_out_unadj,
|
||||
token_in,
|
||||
token_out,
|
||||
sender,
|
||||
tx_to,
|
||||
pool_id,
|
||||
s.pool_address AS contract_address,
|
||||
pool_name,
|
||||
event_name,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
swaps_base s
|
||||
INNER JOIN pool_name pn
|
||||
ON pn.pool_address = s.pool_address
|
||||
@ -1,55 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'jellyswap_pools_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
created_pools AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
topics[1]::STRING as pool_id,
|
||||
SUBSTR(topics[1]::STRING, 1, 42) as pool_address,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver_evm__logs') }}
|
||||
WHERE
|
||||
topics[0]::STRING = '0x3c13bc30b8e878c53fd2a36b679409c073afd75950be43d8858768e956fbc20e' -- PoolRegistered
|
||||
AND contract_address = '0xfb43069f6d0473b85686a85f4ce4fc1fd8f00875' -- Vault contract
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '5 minutes' AS max_inserted_timestamp
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
pool_id,
|
||||
pool_address,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['pool_address']
|
||||
) }} AS jellyswap_pools_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM created_pools
|
||||
QUALIFY ROW_NUMBER() OVER (
|
||||
PARTITION BY pool_address
|
||||
ORDER BY block_timestamp DESC
|
||||
) = 1
|
||||
@ -1,32 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_evm_dex__jellyswap_pools
|
||||
description: Records of pools created on the jellyswap platform.
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
|
||||
- name: tx_hash
|
||||
|
||||
- name: event_index
|
||||
|
||||
- name: contract_address
|
||||
|
||||
- name: pool_id
|
||||
|
||||
- name: pool_address
|
||||
|
||||
- name: jellyswap_pools_id
|
||||
description: Unique identifier for the pool
|
||||
tests:
|
||||
- unique:
|
||||
where: modified_timestamp > current_date -3
|
||||
- not_null:
|
||||
where: modified_timestamp > current_date -3
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,73 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'jellyswap_swaps_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH swaps_base AS (
|
||||
SELECT
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.tx_hash,
|
||||
l.event_index,
|
||||
'Swap' AS event_name,
|
||||
l.origin_function_signature,
|
||||
l.origin_from_address,
|
||||
l.origin_to_address,
|
||||
l.contract_address,
|
||||
topics[1]::STRING as pool_id,
|
||||
p.pool_address,
|
||||
CONCAT('0x', SUBSTR(topics[2]::STRING, 27, 40)) as token_in,
|
||||
CONCAT('0x', SUBSTR(topics[3]::STRING, 27, 40)) as token_out,
|
||||
regexp_substr_all(SUBSTR(data, 3, len(data)), '.{64}') AS segmented_data,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data[0]::STRING
|
||||
) as amount_in_raw,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data[1]::STRING
|
||||
) as amount_out_raw,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_evm__logs') }} l
|
||||
JOIN
|
||||
{{ ref('silver_evm_dex__jellyswap_pools') }} p
|
||||
ON l.topics[1]::STRING = p.pool_id
|
||||
WHERE
|
||||
topics[0]::STRING = '0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0a8dd37b1840b9e0b207b' -- Swap event
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT MAX(modified_timestamp) - INTERVAL '5 minutes'
|
||||
FROM {{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
pool_address,
|
||||
pool_id,
|
||||
token_in,
|
||||
token_out,
|
||||
amount_in_raw as amount_in_unadj,
|
||||
amount_out_raw as amount_out_unadj,
|
||||
{{ dbt_utils.generate_surrogate_key(['tx_hash', 'event_index']) }} AS jellyswap_swaps_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
swaps_base
|
||||
@ -1,45 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_evm_dex__jellyswap_swaps
|
||||
description: Records of swaps that occurred on the jellyswap platform
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 1
|
||||
|
||||
- name: tx_hash
|
||||
|
||||
- name: event_index
|
||||
|
||||
- name: event_name
|
||||
|
||||
- name: origin_function_signature
|
||||
|
||||
- name: origin_from_address
|
||||
|
||||
- name: origin_to_address
|
||||
|
||||
- name: contract_address
|
||||
|
||||
- name: pool_id
|
||||
description: Identifier from Jellyswap for the pool in which the swap occurred
|
||||
|
||||
- name: amount_in_unadj
|
||||
|
||||
- name: amount_out_unadj
|
||||
|
||||
- name: token_in
|
||||
|
||||
- name: token_out
|
||||
|
||||
- name: jellyswap_swaps_id
|
||||
description: Unique identifier for the swap
|
||||
tests:
|
||||
- unique:
|
||||
where: modified_timestamp > current_date -3
|
||||
- not_null:
|
||||
where: modified_timestamp > current_date -3
|
||||
@ -0,0 +1,84 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'pool_address',
|
||||
tags = ['silver_dex','defi','dex','curated']
|
||||
) }}
|
||||
|
||||
WITH contract_mapping AS (
|
||||
SELECT * FROM VALUES
|
||||
('0x595a6b190ba0163eac1da988955563635ab3aa60', 'uniswap', 'v2', 'uni_v2_pair_created'),
|
||||
('0x4b4746216214f9e972c5d35d3fe88e6ec4c28a6b', 'donkeswap', 'v2', 'uni_v2_pair_created'),
|
||||
('0x5d370a6189f89603fab67e9c68383e63f7b6a262', 'dragonswap', 'v1', 'uni_v2_pair_created'),
|
||||
('0x71b27deea549cf3e9293544b2af7a193a34be29a', 'dragonswap', 'v1', 'uni_v2_pair_created')
|
||||
AS t(contract_address, protocol, version, type)
|
||||
),
|
||||
pools AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1,
|
||||
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS pool_address,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INT AS pool_id,
|
||||
m.protocol,
|
||||
m.version,
|
||||
m.type,
|
||||
CONCAT(
|
||||
m.protocol,
|
||||
'-',
|
||||
m.version
|
||||
) AS platform,
|
||||
'PairCreated' AS event_name,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('core_evm__fact_event_logs') }}
|
||||
l
|
||||
INNER JOIN contract_mapping m
|
||||
ON l.contract_address = m.contract_address
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9' --PairCreated
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 days'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_index,
|
||||
event_name,
|
||||
token0,
|
||||
token1,
|
||||
pool_address,
|
||||
pool_id,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_log_id,
|
||||
modified_timestamp
|
||||
FROM
|
||||
pools qualify(ROW_NUMBER() over (PARTITION BY pool_address
|
||||
ORDER BY
|
||||
modified_timestamp DESC)) = 1
|
||||
@ -0,0 +1,142 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'pool_address',
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver_dex','defi','dex','curated']
|
||||
) }}
|
||||
|
||||
WITH contract_mapping AS (
|
||||
SELECT * FROM VALUES
|
||||
('0x3976ccb6603f4af4f1f21ac1ac993e3776b8d590', 'uniswap', 'v3', 'uni_v3_pool_created'),
|
||||
('0x385488ffbff2265dac31d38497b616fa6cc81231', 'uniswap', 'v3', 'uni_v3_pool_created'),
|
||||
('0x75fc67473a91335b5b8f8821277262a13b38c9b3', 'uniswap', 'v3', 'uni_v3_pool_created'),
|
||||
('0x23f1822ede8b1fa63c1652c2212a74481a6e6130', 'uniswap', 'v3', 'uni_v3_pool_created'),
|
||||
('0x179d9a5592bc77050796f7be28058c51ca575df4', 'dragonswap', 'v2', 'uni_v3_pool_created'),
|
||||
('0x0bcea088e977a03113a880cf7c5b6165d8304b16', 'dragonswap', 'v2', 'uni_v3_pool_created'),
|
||||
('0x0596a0469d5452f876523487251bdde73d4b2597', 'xei', 'v3', 'uni_v3_pool_created'),
|
||||
('0xdde4ff846706236eaae4367fff233c0e35a0613f', 'yeiswap', 'v1', 'uni_v3_pool_created'),
|
||||
('0xa51136931fdd3875902618bf6b3abe38ab2d703b', 'sailor', 'v1', 'uni_v3_pool_created'),
|
||||
('0x0a6816112d8fd84ae2111ab23a7e524865d923c5', 'sailor', 'v1', 'uni_v3_pool_created')
|
||||
AS t(contract_address, protocol, version, type)
|
||||
),
|
||||
pools AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
LOWER(CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40))) AS token0_address,
|
||||
LOWER(CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))) AS token1_address,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
topics [3] :: STRING
|
||||
)
|
||||
) AS fee,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data [0] :: STRING
|
||||
)
|
||||
) AS tick_spacing,
|
||||
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 25, 40)) AS pool_address,
|
||||
m.protocol,
|
||||
m.version,
|
||||
m.type,
|
||||
CONCAT(
|
||||
m.protocol,
|
||||
'-',
|
||||
m.version
|
||||
) AS platform,
|
||||
'PoolCreated' AS event_name,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('core_evm__fact_event_logs') }}
|
||||
l
|
||||
INNER JOIN contract_mapping m
|
||||
ON l.contract_address = m.contract_address
|
||||
WHERE
|
||||
topics [0] = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' --PoolCreated
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 days'
|
||||
{% endif %}
|
||||
),
|
||||
initial_info AS (
|
||||
SELECT
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [0] :: STRING)) :: FLOAT AS init_sqrtPriceX96,
|
||||
utils.udf_hex_to_int('s2c', CONCAT('0x', segmented_data [1] :: STRING)) :: FLOAT AS init_tick,
|
||||
pow(
|
||||
1.0001,
|
||||
init_tick
|
||||
) AS init_price_1_0_unadj,
|
||||
CONCAT(
|
||||
tx_hash :: STRING,
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('core_evm__fact_event_logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95' --Initialize
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 days'
|
||||
{% endif %}
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
p.contract_address,
|
||||
token0_address,
|
||||
token1_address,
|
||||
fee :: INTEGER AS fee,
|
||||
(
|
||||
fee / 10000
|
||||
) :: FLOAT AS fee_percent,
|
||||
tick_spacing,
|
||||
pool_address,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
p._log_id,
|
||||
p.modified_timestamp
|
||||
FROM
|
||||
pools p
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY pool_address
|
||||
ORDER BY
|
||||
modified_timestamp DESC)) = 1
|
||||
@ -0,0 +1,125 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'block_number',
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver_dex','defi','dex','curated']
|
||||
) }}
|
||||
|
||||
WITH swaps AS (
|
||||
|
||||
SELECT
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.tx_hash,
|
||||
l.event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER
|
||||
) AS amount0In,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER
|
||||
) AS amount1In,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER
|
||||
) AS amount0Out,
|
||||
TRY_TO_NUMBER(
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [3] :: STRING
|
||||
) :: INTEGER
|
||||
) AS amount1Out,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS tx_to,
|
||||
p.token0,
|
||||
p.token1,
|
||||
p.platform,
|
||||
p.protocol,
|
||||
p.version,
|
||||
p.type,
|
||||
'Swap' AS event_name,
|
||||
CONCAT(
|
||||
l.tx_hash :: STRING,
|
||||
'-',
|
||||
l.event_index :: STRING
|
||||
) AS _log_id,
|
||||
l.modified_timestamp
|
||||
FROM
|
||||
{{ ref('core_evm__fact_event_logs') }}
|
||||
l
|
||||
INNER JOIN {{ ref('silver_dex__paircreated_evt_v2_pools') }}
|
||||
p
|
||||
ON p.pool_address = l.contract_address
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822' --Swap
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 days'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
contract_address,
|
||||
sender,
|
||||
tx_to,
|
||||
amount0In,
|
||||
amount1In,
|
||||
amount0Out,
|
||||
amount1Out,
|
||||
token0,
|
||||
token1,
|
||||
CASE
|
||||
WHEN amount0In <> 0
|
||||
AND amount1In <> 0
|
||||
AND amount0Out <> 0 THEN amount1In
|
||||
WHEN amount0In <> 0 THEN amount0In
|
||||
WHEN amount1In <> 0 THEN amount1In
|
||||
END AS amount_in_unadj,
|
||||
CASE
|
||||
WHEN amount0Out <> 0 THEN amount0Out
|
||||
WHEN amount1Out <> 0 THEN amount1Out
|
||||
END AS amount_out_unadj,
|
||||
CASE
|
||||
WHEN amount0In <> 0
|
||||
AND amount1In <> 0
|
||||
AND amount0Out <> 0 THEN token1
|
||||
WHEN amount0In <> 0 THEN token0
|
||||
WHEN amount1In <> 0 THEN token1
|
||||
END AS token_in,
|
||||
CASE
|
||||
WHEN amount0Out <> 0 THEN token0
|
||||
WHEN amount1Out <> 0 THEN token1
|
||||
END AS token_out,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_log_id,
|
||||
modified_timestamp
|
||||
FROM
|
||||
swaps
|
||||
WHERE
|
||||
token_in <> token_out
|
||||
@ -0,0 +1,125 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = 'block_number',
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['silver_dex','defi','dex','curated']
|
||||
) }}
|
||||
|
||||
WITH swaps AS (
|
||||
|
||||
SELECT
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.tx_hash,
|
||||
l.event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS sender,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS recipient,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data [0] :: STRING
|
||||
) :: FLOAT AS amount0_unadj,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data [1] :: STRING
|
||||
) :: FLOAT AS amount1_unadj,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data [2] :: STRING
|
||||
) :: FLOAT AS sqrtPriceX96,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data [3] :: STRING
|
||||
) :: FLOAT AS liquidity,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
segmented_data [4] :: STRING
|
||||
) :: FLOAT AS tick,
|
||||
token0_address,
|
||||
token1_address,
|
||||
pool_address,
|
||||
tick_spacing,
|
||||
fee,
|
||||
p.platform,
|
||||
p.protocol,
|
||||
p.version,
|
||||
p.type,
|
||||
'Swap' AS event_name,
|
||||
CONCAT(
|
||||
l.tx_hash :: STRING,
|
||||
'-',
|
||||
l.event_index :: STRING
|
||||
) AS _log_id,
|
||||
l.modified_timestamp
|
||||
FROM
|
||||
{{ ref('core_evm__fact_event_logs') }}
|
||||
l
|
||||
INNER JOIN {{ ref('silver_dex__poolcreated_evt_v3_pools') }}
|
||||
p
|
||||
ON p.pool_address = l.contract_address
|
||||
WHERE
|
||||
topics [0] :: STRING = '0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67' --Swap
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 days'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
pool_address,
|
||||
recipient,
|
||||
sender,
|
||||
fee,
|
||||
tick,
|
||||
tick_spacing,
|
||||
liquidity,
|
||||
token0_address,
|
||||
token1_address,
|
||||
amount0_unadj,
|
||||
amount1_unadj,
|
||||
CASE
|
||||
WHEN amount0_unadj > 0 THEN ABS(amount0_unadj)
|
||||
ELSE ABS(amount1_unadj)
|
||||
END AS amount_in_unadj,
|
||||
CASE
|
||||
WHEN amount0_unadj < 0 THEN ABS(amount0_unadj)
|
||||
ELSE ABS(amount1_unadj)
|
||||
END AS amount_out_unadj,
|
||||
CASE
|
||||
WHEN amount0_unadj > 0 THEN token0_address
|
||||
ELSE token1_address
|
||||
END AS token_in,
|
||||
CASE
|
||||
WHEN amount0_unadj < 0 THEN token0_address
|
||||
ELSE token1_address
|
||||
END AS token_out,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_log_id,
|
||||
modified_timestamp
|
||||
FROM
|
||||
swaps qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
modified_timestamp DESC)) = 1
|
||||
@ -1,54 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'sailorswap_pools_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH pools_created AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '[a-f0-9]{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics[1] :: STRING, 27, 40)) AS token0,
|
||||
CONCAT('0x', SUBSTR(topics[2] :: STRING, 27, 40)) AS token1,
|
||||
CONCAT('0x', SUBSTR(segmented_data[1] :: STRING, 25, 40)) AS pool_address,
|
||||
FROM
|
||||
{{ ref('silver_evm__logs') }}
|
||||
WHERE
|
||||
contract_address = LOWER('0xA51136931fdd3875902618bF6B3abe38Ab2D703b') -- SailorSwapFactory
|
||||
AND topics[0] :: STRING = '0x783cca1c0412dd0d695e784568c96da2e9c22ff989357a2e8b1d9b2b4e6b7118' -- PairCreated
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '5 minutes'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
token0,
|
||||
token1,
|
||||
pool_address,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['pool_address']
|
||||
) }} AS sailorswap_pools_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
pools_created qualify(ROW_NUMBER() over (PARTITION BY pool_address
|
||||
ORDER BY
|
||||
block_timestamp DESC)) = 1
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_evm_dex__sailorswap_pools
|
||||
description: Records of pools created on the sailorswap platform.
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
|
||||
- name: tx_hash
|
||||
|
||||
- name: event_index
|
||||
|
||||
- name: contract_address
|
||||
|
||||
- name: token0
|
||||
|
||||
- name: token1
|
||||
|
||||
- name: pool_id
|
||||
|
||||
- name: pool_address
|
||||
|
||||
- name: sailorswap_pools_id
|
||||
description: Unique identifier for the pool
|
||||
tests:
|
||||
- unique:
|
||||
where: modified_timestamp > current_date -3
|
||||
- not_null:
|
||||
where: modified_timestamp > current_date -3
|
||||
@ -1,80 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'sailorswap_swaps_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
WITH pools AS (
|
||||
SELECT
|
||||
pool_address,
|
||||
token0,
|
||||
token1
|
||||
FROM {{ ref('silver_evm_dex__sailorswap_pools') }}
|
||||
),
|
||||
swaps_base AS (
|
||||
SELECT
|
||||
l.block_number,
|
||||
l.block_timestamp,
|
||||
l.tx_hash,
|
||||
l.event_index,
|
||||
'Swap' AS event_name,
|
||||
l.origin_function_signature,
|
||||
l.origin_from_address,
|
||||
l.origin_to_address,
|
||||
l.contract_address,
|
||||
CONCAT('0x', SUBSTR(topics[1] :: STRING, 27, 40)) AS sender,
|
||||
CONCAT('0x', SUBSTR(topics[2] :: STRING, 27, 40)) AS tx_to,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}')[0] :: STRING
|
||||
) :: FLOAT AS amount0,
|
||||
utils.udf_hex_to_int(
|
||||
's2c',
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}')[1] :: STRING
|
||||
) :: FLOAT AS amount1,
|
||||
p.token0,
|
||||
p.token1,
|
||||
CASE WHEN p.pool_address IS NULL THEN TRUE ELSE FALSE END AS is_missing_pool
|
||||
FROM {{ ref('silver_evm__logs') }} l
|
||||
JOIN pools p
|
||||
ON LOWER(p.pool_address) = LOWER(l.contract_address)
|
||||
WHERE
|
||||
topics[0] :: STRING = '0x19b47279256b2a23a1665c810c8d55a1758940ee09377d4f8d26497a3577dc83'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '5 minutes'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address AS pool_address,
|
||||
sender,
|
||||
tx_to,
|
||||
token0,
|
||||
token1,
|
||||
amount0,
|
||||
amount1,
|
||||
is_missing_pool,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash', 'event_index']
|
||||
) }} AS sailorswap_swaps_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM swaps_base
|
||||
@ -1,45 +0,0 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_evm_dex__sailorswap_swaps
|
||||
description: Records of swaps that occurred on the sailorswap platform
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 1
|
||||
|
||||
- name: tx_hash
|
||||
|
||||
- name: event_index
|
||||
|
||||
- name: event_name
|
||||
|
||||
- name: origin_function_signature
|
||||
|
||||
- name: origin_from_address
|
||||
|
||||
- name: origin_to_address
|
||||
|
||||
- name: contract_address
|
||||
|
||||
- name: pool_id
|
||||
description: Identifier from sailorswap for the pool in which the swap occurred
|
||||
|
||||
- name: amount_in_unadj
|
||||
|
||||
- name: amount_out_unadj
|
||||
|
||||
- name: token_in
|
||||
|
||||
- name: token_out
|
||||
|
||||
- name: sailorswap_swaps_id
|
||||
description: Unique identifier for the swap
|
||||
tests:
|
||||
- unique:
|
||||
where: modified_timestamp > current_date -3
|
||||
- not_null:
|
||||
where: modified_timestamp > current_date -3
|
||||
@ -0,0 +1,952 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform','version'],
|
||||
cluster_by = ['block_timestamp::DATE','platform'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash)",
|
||||
tags = ['silver_dex','defi','dex','curated','heal','complete','lp']
|
||||
) }}
|
||||
|
||||
WITH contracts AS (
|
||||
|
||||
SELECT
|
||||
address AS contract_address,
|
||||
symbol AS token_symbol,
|
||||
decimals AS token_decimals,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core_evm__dim_contracts') }}
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x0000000000000000000000000000000000000000' AS contract_address,
|
||||
'SEI' AS token_symbol,
|
||||
decimals AS token_decimals,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core_evm__dim_contracts') }}
|
||||
WHERE
|
||||
address = '0xe30fedd158a2e3b13e9badaeabafc5516e95e8c7'
|
||||
),
|
||||
jellyswap AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
pool_address,
|
||||
'0x' AS pool_id,
|
||||
pool_name,
|
||||
NULL AS fee,
|
||||
NULL AS tick_spacing,
|
||||
token0,
|
||||
token1,
|
||||
token2,
|
||||
token3,
|
||||
token4,
|
||||
token5,
|
||||
token6,
|
||||
token7,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_log_id AS _id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_dex__jellyswap_pools') }}
|
||||
|
||||
{% if is_incremental() and 'jellyswap' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
poolcreated_evt_v3 AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
pool_address,
|
||||
'0x' AS pool_id,
|
||||
NULL AS pool_name,
|
||||
fee,
|
||||
tick_spacing,
|
||||
token0_address AS token0,
|
||||
token1_address AS token1,
|
||||
NULL AS token2,
|
||||
NULL AS token3,
|
||||
NULL AS token4,
|
||||
NULL AS token5,
|
||||
NULL AS token6,
|
||||
NULL AS token7,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_log_id AS _id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_dex__poolcreated_evt_v3_pools') }}
|
||||
|
||||
{% if is_incremental() and 'poolcreated_evt_v3' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
paircreated_evt_v2 AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
pool_address,
|
||||
'0x' AS pool_id,
|
||||
NULL AS pool_name,
|
||||
NULL AS fee,
|
||||
NULL AS tick_spacing,
|
||||
token0,
|
||||
token1,
|
||||
NULL AS token2,
|
||||
NULL AS token3,
|
||||
NULL AS token4,
|
||||
NULL AS token5,
|
||||
NULL AS token6,
|
||||
NULL AS token7,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_log_id AS _id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_dex__paircreated_evt_v2_pools') }}
|
||||
|
||||
{% if is_incremental() and 'paircreated_evt_v2' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
all_pools AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
poolcreated_evt_v3
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
paircreated_evt_v2
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
jellyswap
|
||||
),
|
||||
complete_lps AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
p.contract_address,
|
||||
pool_address,
|
||||
pool_id,
|
||||
CASE
|
||||
WHEN platform NOT IN ('uniswap-v4')
|
||||
AND pool_name IS NOT NULL THEN pool_name
|
||||
WHEN pool_name IS NULL
|
||||
AND platform IN (
|
||||
'dragonswap-v2',
|
||||
'uniswap-v3'
|
||||
) THEN CONCAT(
|
||||
COALESCE(
|
||||
c0.token_symbol,
|
||||
CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42))
|
||||
),
|
||||
'-',
|
||||
COALESCE(
|
||||
c1.token_symbol,
|
||||
CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42))
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
fee,
|
||||
0
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
tick_spacing,
|
||||
0
|
||||
),
|
||||
CASE
|
||||
WHEN platform = 'uniswap-v3' THEN ' UNI-V3 LP'
|
||||
WHEN platform = 'dragonswap-v2' THEN ' DRAGON-V2 LP'
|
||||
END
|
||||
)
|
||||
WHEN pool_name IS NULL
|
||||
AND platform IN (
|
||||
'jellyswap-v1'
|
||||
) THEN CONCAT(
|
||||
COALESCE(c0.token_symbol, SUBSTRING(token0, 1, 5) || '...' || SUBSTRING(token0, 39, 42)),
|
||||
CASE
|
||||
WHEN token1 IS NOT NULL THEN '-' || COALESCE(c1.token_symbol, SUBSTRING(token1, 1, 5) || '...' || SUBSTRING(token1, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token2 IS NOT NULL THEN '-' || COALESCE(c2.token_symbol, SUBSTRING(token2, 1, 5) || '...' || SUBSTRING(token2, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token3 IS NOT NULL THEN '-' || COALESCE(c3.token_symbol, SUBSTRING(token3, 1, 5) || '...' || SUBSTRING(token3, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token4 IS NOT NULL THEN '-' || COALESCE(c4.token_symbol, SUBSTRING(token4, 1, 5) || '...' || SUBSTRING(token4, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token5 IS NOT NULL THEN '-' || COALESCE(c5.token_symbol, SUBSTRING(token5, 1, 5) || '...' || SUBSTRING(token5, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token6 IS NOT NULL THEN '-' || COALESCE(c6.token_symbol, SUBSTRING(token6, 1, 5) || '...' || SUBSTRING(token6, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token7 IS NOT NULL THEN '-' || COALESCE(c7.token_symbol, SUBSTRING(token7, 1, 5) || '...' || SUBSTRING(token7, 39, 42))
|
||||
ELSE ''
|
||||
END
|
||||
)
|
||||
WHEN platform = 'uniswap-v4' THEN CONCAT(
|
||||
COALESCE(
|
||||
c0.token_symbol,
|
||||
CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42))
|
||||
),
|
||||
'-',
|
||||
COALESCE(
|
||||
c1.token_symbol,
|
||||
CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42))
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
fee,
|
||||
0
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
tick_spacing,
|
||||
0
|
||||
),
|
||||
' ',
|
||||
CASE
|
||||
WHEN REGEXP_LIKE(RIGHT(pool_name, 42), '0x[0-9a-fA-F]+$') THEN RIGHT(
|
||||
pool_name,
|
||||
42
|
||||
)
|
||||
ELSE ''
|
||||
END,
|
||||
' UNI-V4 LP'
|
||||
)
|
||||
ELSE CONCAT(
|
||||
COALESCE(
|
||||
c0.token_symbol,
|
||||
CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42))
|
||||
),
|
||||
'-',
|
||||
COALESCE(
|
||||
c1.token_symbol,
|
||||
CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42))
|
||||
)
|
||||
)
|
||||
END AS pool_name,
|
||||
fee,
|
||||
tick_spacing,
|
||||
token0,
|
||||
token1,
|
||||
token2,
|
||||
token3,
|
||||
token4,
|
||||
token5,
|
||||
token6,
|
||||
token7,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
token0,
|
||||
'token1',
|
||||
token1,
|
||||
'token2',
|
||||
token2,
|
||||
'token3',
|
||||
token3,
|
||||
'token4',
|
||||
token4,
|
||||
'token5',
|
||||
token5,
|
||||
'token6',
|
||||
token6,
|
||||
'token7',
|
||||
token7
|
||||
) AS tokens,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
c0.token_symbol,
|
||||
'token1',
|
||||
c1.token_symbol,
|
||||
'token2',
|
||||
c2.token_symbol,
|
||||
'token3',
|
||||
c3.token_symbol,
|
||||
'token4',
|
||||
c4.token_symbol,
|
||||
'token5',
|
||||
c5.token_symbol,
|
||||
'token6',
|
||||
c6.token_symbol,
|
||||
'token7',
|
||||
c7.token_symbol
|
||||
) AS symbols,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
c0.token_decimals,
|
||||
'token1',
|
||||
c1.token_decimals,
|
||||
'token2',
|
||||
c2.token_decimals,
|
||||
'token3',
|
||||
c3.token_decimals,
|
||||
'token4',
|
||||
c4.token_decimals,
|
||||
'token5',
|
||||
c5.token_decimals,
|
||||
'token6',
|
||||
c6.token_decimals,
|
||||
'token7',
|
||||
c7.token_decimals
|
||||
) AS decimals,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_id,
|
||||
p._inserted_timestamp
|
||||
FROM
|
||||
all_pools p
|
||||
LEFT JOIN contracts c0
|
||||
ON c0.contract_address = p.token0
|
||||
LEFT JOIN contracts c1
|
||||
ON c1.contract_address = p.token1
|
||||
LEFT JOIN contracts c2
|
||||
ON c2.contract_address = p.token2
|
||||
LEFT JOIN contracts c3
|
||||
ON c3.contract_address = p.token3
|
||||
LEFT JOIN contracts c4
|
||||
ON c4.contract_address = p.token4
|
||||
LEFT JOIN contracts c5
|
||||
ON c5.contract_address = p.token5
|
||||
LEFT JOIN contracts c6
|
||||
ON c6.contract_address = p.token6
|
||||
LEFT JOIN contracts c7
|
||||
ON c7.contract_address = p.token7
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
t0.contract_address,
|
||||
pool_address,
|
||||
pool_id,
|
||||
CASE
|
||||
WHEN platform NOT IN ('uniswap-v4')
|
||||
AND pool_name IS NOT NULL THEN pool_name
|
||||
WHEN pool_name IS NULL
|
||||
AND platform IN (
|
||||
'dragonswap-v2',
|
||||
'uniswap-v3'
|
||||
) THEN CONCAT(
|
||||
COALESCE(
|
||||
c0.token_symbol,
|
||||
CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42))
|
||||
),
|
||||
'-',
|
||||
COALESCE(
|
||||
c1.token_symbol,
|
||||
CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42))
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
fee,
|
||||
0
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
tick_spacing,
|
||||
0
|
||||
),
|
||||
CASE
|
||||
WHEN platform = 'uniswap-v3' THEN ' UNI-V3 LP'
|
||||
WHEN platform = 'dragonswap-v2' THEN ' DRAGON-V2 LP'
|
||||
END
|
||||
)
|
||||
WHEN pool_name IS NULL
|
||||
AND platform IN (
|
||||
'jellyswap-v1'
|
||||
) THEN CONCAT(
|
||||
COALESCE(c0.token_symbol, SUBSTRING(token0, 1, 5) || '...' || SUBSTRING(token0, 39, 42)),
|
||||
CASE
|
||||
WHEN token1 IS NOT NULL THEN '-' || COALESCE(c1.token_symbol, SUBSTRING(token1, 1, 5) || '...' || SUBSTRING(token1, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token2 IS NOT NULL THEN '-' || COALESCE(c2.token_symbol, SUBSTRING(token2, 1, 5) || '...' || SUBSTRING(token2, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token3 IS NOT NULL THEN '-' || COALESCE(c3.token_symbol, SUBSTRING(token3, 1, 5) || '...' || SUBSTRING(token3, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token4 IS NOT NULL THEN '-' || COALESCE(c4.token_symbol, SUBSTRING(token4, 1, 5) || '...' || SUBSTRING(token4, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token5 IS NOT NULL THEN '-' || COALESCE(c5.token_symbol, SUBSTRING(token5, 1, 5) || '...' || SUBSTRING(token5, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token6 IS NOT NULL THEN '-' || COALESCE(c6.token_symbol, SUBSTRING(token6, 1, 5) || '...' || SUBSTRING(token6, 39, 42))
|
||||
ELSE ''
|
||||
END,
|
||||
CASE
|
||||
WHEN token7 IS NOT NULL THEN '-' || COALESCE(c7.token_symbol, SUBSTRING(token7, 1, 5) || '...' || SUBSTRING(token7, 39, 42))
|
||||
ELSE ''
|
||||
END
|
||||
)
|
||||
WHEN platform = 'uniswap-v4' THEN CONCAT(
|
||||
COALESCE(
|
||||
c0.token_symbol,
|
||||
CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42))
|
||||
),
|
||||
'-',
|
||||
COALESCE(
|
||||
c1.token_symbol,
|
||||
CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42))
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
fee,
|
||||
0
|
||||
),
|
||||
' ',
|
||||
COALESCE(
|
||||
tick_spacing,
|
||||
0
|
||||
),
|
||||
' ',
|
||||
CASE
|
||||
WHEN REGEXP_LIKE(SUBSTR(pool_name, len(pool_name) - 51, 42), '0x[0-9a-fA-F]+$') THEN SUBSTR(pool_name, len(pool_name) - 51, 42)
|
||||
ELSE ''END,
|
||||
' UNI-V4 LP'
|
||||
)
|
||||
ELSE CONCAT(
|
||||
COALESCE(
|
||||
c0.token_symbol,
|
||||
CONCAT(SUBSTRING(token0, 1, 5), '...', SUBSTRING(token0, 39, 42))
|
||||
),
|
||||
'-',
|
||||
COALESCE(
|
||||
c1.token_symbol,
|
||||
CONCAT(SUBSTRING(token1, 1, 5), '...', SUBSTRING(token1, 39, 42))
|
||||
)
|
||||
)
|
||||
END AS pool_name_heal,
|
||||
fee,
|
||||
tick_spacing,
|
||||
token0,
|
||||
token1,
|
||||
token2,
|
||||
token3,
|
||||
token4,
|
||||
token5,
|
||||
token6,
|
||||
token7,
|
||||
tokens,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
c0.token_symbol,
|
||||
'token1',
|
||||
c1.token_symbol,
|
||||
'token2',
|
||||
c2.token_symbol,
|
||||
'token3',
|
||||
c3.token_symbol,
|
||||
'token4',
|
||||
c4.token_symbol,
|
||||
'token5',
|
||||
c5.token_symbol,
|
||||
'token6',
|
||||
c6.token_symbol,
|
||||
'token7',
|
||||
c7.token_symbol
|
||||
) AS symbols_heal,
|
||||
OBJECT_CONSTRUCT(
|
||||
'token0',
|
||||
c0.token_decimals,
|
||||
'token1',
|
||||
c1.token_decimals,
|
||||
'token2',
|
||||
c2.token_decimals,
|
||||
'token3',
|
||||
c3.token_decimals,
|
||||
'token4',
|
||||
c4.token_decimals,
|
||||
'token5',
|
||||
c5.token_decimals,
|
||||
'token6',
|
||||
c6.token_decimals,
|
||||
'token7',
|
||||
c7.token_decimals
|
||||
) AS decimals_heal,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_id,
|
||||
t0._inserted_timestamp
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN contracts c0
|
||||
ON c0.contract_address = t0.token0
|
||||
LEFT JOIN contracts c1
|
||||
ON c1.contract_address = t0.token1
|
||||
LEFT JOIN contracts c2
|
||||
ON c2.contract_address = t0.token2
|
||||
LEFT JOIN contracts c3
|
||||
ON c3.contract_address = t0.token3
|
||||
LEFT JOIN contracts c4
|
||||
ON c4.contract_address = t0.token4
|
||||
LEFT JOIN contracts c5
|
||||
ON c5.contract_address = t0.token5
|
||||
LEFT JOIN contracts c6
|
||||
ON c6.contract_address = t0.token6
|
||||
LEFT JOIN contracts c7
|
||||
ON c7.contract_address = t0.token7
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform,
|
||||
'-',
|
||||
t1.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.decimals :token0 :: INT IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
contracts C
|
||||
WHERE
|
||||
C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND C.token_decimals IS NOT NULL
|
||||
AND C.contract_address = t1.tokens :token0 :: STRING)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t2.block_number,
|
||||
'-',
|
||||
t2.platform,
|
||||
'-',
|
||||
t2.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t2
|
||||
WHERE
|
||||
t2.decimals :token1 :: INT IS NULL
|
||||
AND t2._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
contracts C
|
||||
WHERE
|
||||
C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND C.token_decimals IS NOT NULL
|
||||
AND C.contract_address = t2.tokens :token1 :: STRING)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t3.block_number,
|
||||
'-',
|
||||
t3.platform,
|
||||
'-',
|
||||
t3.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t3
|
||||
WHERE
|
||||
t3.decimals :token2 :: INT IS NULL
|
||||
AND t3._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
contracts C
|
||||
WHERE
|
||||
C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND C.token_decimals IS NOT NULL
|
||||
AND C.contract_address = t3.tokens :token2 :: STRING)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t4.block_number,
|
||||
'-',
|
||||
t4.platform,
|
||||
'-',
|
||||
t4.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t4
|
||||
WHERE
|
||||
t4.decimals :token3 :: INT IS NULL
|
||||
AND t4._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
contracts C
|
||||
WHERE
|
||||
C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND C.token_decimals IS NOT NULL
|
||||
AND C.contract_address = t4.tokens :token3 :: STRING)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t5.block_number,
|
||||
'-',
|
||||
t5.platform,
|
||||
'-',
|
||||
t5.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t5
|
||||
WHERE
|
||||
t5.decimals :token4 :: INT IS NULL
|
||||
AND t5._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
contracts C
|
||||
WHERE
|
||||
C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND C.token_decimals IS NOT NULL
|
||||
AND C.contract_address = t5.tokens :token4 :: STRING)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t6.block_number,
|
||||
'-',
|
||||
t6.platform,
|
||||
'-',
|
||||
t6.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t6
|
||||
WHERE
|
||||
t6.decimals :token5 :: INT IS NULL
|
||||
AND t6._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
contracts C
|
||||
WHERE
|
||||
C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND C.token_decimals IS NOT NULL
|
||||
AND C.contract_address = t6.tokens :token5 :: STRING)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t7.block_number,
|
||||
'-',
|
||||
t7.platform,
|
||||
'-',
|
||||
t7.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t7
|
||||
WHERE
|
||||
t7.decimals :token6 :: INT IS NULL
|
||||
AND t7._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
contracts C
|
||||
WHERE
|
||||
C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND C.token_decimals IS NOT NULL
|
||||
AND C.contract_address = t7.tokens :token6 :: STRING)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t8.block_number,
|
||||
'-',
|
||||
t8.platform,
|
||||
'-',
|
||||
t8.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t8
|
||||
WHERE
|
||||
t8.decimals :token7 :: INT IS NULL
|
||||
AND t8._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
contracts C
|
||||
WHERE
|
||||
C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND C.token_decimals IS NOT NULL
|
||||
AND C.contract_address = t8.tokens :token7 :: STRING)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_lps
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
pool_address,
|
||||
pool_id,
|
||||
pool_name_heal AS pool_name,
|
||||
fee,
|
||||
tick_spacing,
|
||||
token0,
|
||||
token1,
|
||||
token2,
|
||||
token3,
|
||||
token4,
|
||||
token5,
|
||||
token6,
|
||||
token7,
|
||||
tokens,
|
||||
symbols_heal AS symbols,
|
||||
decimals_heal AS decimals,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
contract_address,
|
||||
pool_address,
|
||||
pool_id,
|
||||
pool_name,
|
||||
tokens,
|
||||
symbols,
|
||||
decimals,
|
||||
fee,
|
||||
tick_spacing,
|
||||
token0,
|
||||
token1,
|
||||
token2,
|
||||
token3,
|
||||
token4,
|
||||
token5,
|
||||
token6,
|
||||
token7,
|
||||
_id,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['pool_address', 'pool_id']
|
||||
) }} AS complete_dex_liquidity_pools_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL
|
||||
@ -0,0 +1,46 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_dex__complete_dex_liquidity_pools
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _ID
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: CONTRACT_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: POOL_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: VERSION
|
||||
tests:
|
||||
- not_null
|
||||
- name: TYPE
|
||||
tests:
|
||||
- not_null
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 30
|
||||
699
models/evm/silver/defi/dex/silver_dex__complete_dex_swaps.sql
Normal file
699
models/evm/silver/defi/dex/silver_dex__complete_dex_swaps.sql
Normal file
@ -0,0 +1,699 @@
|
||||
-- depends_on: {{ ref('price__ez_asset_metadata') }}
|
||||
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform','version'],
|
||||
cluster_by = ['block_timestamp::DATE','platform'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash, origin_function_signature, origin_from_address, origin_to_address, sender, tx_to, token_in, token_out, symbol_in, symbol_out)",
|
||||
tags = ['silver_dex','defi','dex','curated','heal','complete','swap']
|
||||
) }}
|
||||
|
||||
WITH contracts AS (
|
||||
|
||||
SELECT
|
||||
address AS contract_address,
|
||||
symbol AS token_symbol,
|
||||
decimals AS token_decimals,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core_evm__dim_contracts') }}
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x0000000000000000000000000000000000000000' AS contract_address,
|
||||
'SEI' AS token_symbol,
|
||||
decimals AS token_decimals,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core_evm__dim_contracts') }}
|
||||
WHERE
|
||||
address = '0xe30fedd158a2e3b13e9badaeabafc5516e95e8c7'
|
||||
),
|
||||
prices AS (
|
||||
SELECT
|
||||
token_address,
|
||||
price,
|
||||
HOUR,
|
||||
is_verified,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x0000000000000000000000000000000000000000' AS token_address,
|
||||
price,
|
||||
HOUR,
|
||||
is_verified,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
WHERE
|
||||
token_address = '0xe30fedd158a2e3b13e9badaeabafc5516e95e8c7'
|
||||
),
|
||||
swap_evt_v3 AS (
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
pool_address AS contract_address,
|
||||
'0x' AS pool_id,
|
||||
event_name,
|
||||
amount_in_unadj,
|
||||
amount_out_unadj,
|
||||
token_in,
|
||||
token_out,
|
||||
sender,
|
||||
recipient AS tx_to,
|
||||
event_index,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_log_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_dex__swap_evt_v3_swaps') }}
|
||||
|
||||
{% if is_incremental() and 'swap_evt_v3' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
swap_evt_v2 AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
'0x' AS pool_id,
|
||||
event_name,
|
||||
amount_in_unadj,
|
||||
amount_out_unadj,
|
||||
token_in,
|
||||
token_out,
|
||||
sender,
|
||||
tx_to,
|
||||
event_index,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_log_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_dex__swap_evt_v2_swaps') }}
|
||||
|
||||
{% if is_incremental() and 'swap_evt_v2' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
jellyswap AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
'0x' AS pool_id,
|
||||
event_name,
|
||||
amount_in_unadj,
|
||||
amount_out_unadj,
|
||||
token_in,
|
||||
token_out,
|
||||
sender,
|
||||
tx_to,
|
||||
event_index,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver_dex__jellyswap_swaps') }}
|
||||
|
||||
{% if is_incremental() and 'jellyswap' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
all_dex AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
jellyswap
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
swap_evt_v3
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
swap_evt_v2
|
||||
),
|
||||
complete_dex_swaps AS (
|
||||
SELECT
|
||||
s.block_number,
|
||||
s.block_timestamp,
|
||||
s.tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
s.contract_address,
|
||||
s.pool_id,
|
||||
event_name,
|
||||
token_in,
|
||||
p1.is_verified AS token_in_is_verified,
|
||||
c1.token_decimals AS decimals_in,
|
||||
c1.token_symbol AS symbol_in,
|
||||
amount_in_unadj,
|
||||
CASE
|
||||
WHEN decimals_in IS NULL THEN amount_in_unadj
|
||||
ELSE (amount_in_unadj / pow(10, decimals_in))
|
||||
END AS amount_in,
|
||||
CASE
|
||||
WHEN decimals_in IS NOT NULL THEN amount_in * p1.price
|
||||
ELSE NULL
|
||||
END AS amount_in_usd,
|
||||
token_out,
|
||||
p2.is_verified AS token_out_is_verified,
|
||||
c2.token_decimals AS decimals_out,
|
||||
c2.token_symbol AS symbol_out,
|
||||
amount_out_unadj,
|
||||
CASE
|
||||
WHEN decimals_out IS NULL THEN amount_out_unadj
|
||||
ELSE (amount_out_unadj / pow(10, decimals_out))
|
||||
END AS amount_out,
|
||||
CASE
|
||||
WHEN decimals_out IS NOT NULL THEN amount_out * p2.price
|
||||
ELSE NULL
|
||||
END AS amount_out_usd,
|
||||
CASE
|
||||
WHEN lp.pool_name IS NULL THEN CONCAT(
|
||||
LEAST(
|
||||
COALESCE(
|
||||
symbol_in,
|
||||
CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))
|
||||
),
|
||||
COALESCE(
|
||||
symbol_out,
|
||||
CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42))
|
||||
)
|
||||
),
|
||||
'-',
|
||||
GREATEST(
|
||||
COALESCE(
|
||||
symbol_in,
|
||||
CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))
|
||||
),
|
||||
COALESCE(
|
||||
symbol_out,
|
||||
CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42))
|
||||
)
|
||||
)
|
||||
)
|
||||
ELSE lp.pool_name
|
||||
END AS pool_name,
|
||||
sender,
|
||||
tx_to,
|
||||
event_index,
|
||||
s.platform,
|
||||
s.protocol,
|
||||
s.version,
|
||||
s.type,
|
||||
s._log_id,
|
||||
s._inserted_timestamp
|
||||
FROM
|
||||
all_dex s
|
||||
LEFT JOIN contracts
|
||||
c1
|
||||
ON s.token_in = c1.contract_address
|
||||
LEFT JOIN contracts
|
||||
c2
|
||||
ON s.token_out = c2.contract_address
|
||||
LEFT JOIN prices
|
||||
p1
|
||||
ON s.token_in = p1.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p1.hour
|
||||
LEFT JOIN prices
|
||||
p2
|
||||
ON s.token_out = p2.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p2.hour
|
||||
LEFT JOIN {{ ref('silver_dex__complete_dex_liquidity_pools') }}
|
||||
lp
|
||||
ON s.contract_address = lp.pool_address
|
||||
AND s.pool_id = lp.pool_id
|
||||
),
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
heal_model AS (
|
||||
SELECT
|
||||
t0.block_number,
|
||||
t0.block_timestamp,
|
||||
t0.tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
t0.contract_address,
|
||||
t0.pool_id,
|
||||
event_name,
|
||||
token_in,
|
||||
p1.is_verified AS token_in_is_verified,
|
||||
c1.token_decimals AS decimals_in,
|
||||
c1.token_symbol AS symbol_in,
|
||||
amount_in_unadj,
|
||||
CASE
|
||||
WHEN c1.token_decimals IS NULL THEN amount_in_unadj
|
||||
ELSE (amount_in_unadj / pow(10, c1.token_decimals))
|
||||
END AS amount_in_heal,
|
||||
CASE
|
||||
WHEN c1.token_decimals IS NOT NULL THEN amount_in_heal * p1.price
|
||||
ELSE NULL
|
||||
END AS amount_in_usd_heal,
|
||||
token_out,
|
||||
p2.is_verified AS token_out_is_verified,
|
||||
c2.token_decimals AS decimals_out,
|
||||
c2.token_symbol AS symbol_out,
|
||||
amount_out_unadj,
|
||||
CASE
|
||||
WHEN c2.token_decimals IS NULL THEN amount_out_unadj
|
||||
ELSE (amount_out_unadj / pow(10, c2.token_decimals))
|
||||
END AS amount_out_heal,
|
||||
CASE
|
||||
WHEN c2.token_decimals IS NOT NULL THEN amount_out_heal * p2.price
|
||||
ELSE NULL
|
||||
END AS amount_out_usd_heal,
|
||||
CASE
|
||||
WHEN lp.pool_name IS NULL THEN CONCAT(
|
||||
LEAST(
|
||||
COALESCE(
|
||||
c1.token_symbol,
|
||||
CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))
|
||||
),
|
||||
COALESCE(
|
||||
c2.token_symbol,
|
||||
CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42))
|
||||
)
|
||||
),
|
||||
'-',
|
||||
GREATEST(
|
||||
COALESCE(
|
||||
c1.token_symbol,
|
||||
CONCAT(SUBSTRING(token_in, 1, 5), '...', SUBSTRING(token_in, 39, 42))
|
||||
),
|
||||
COALESCE(
|
||||
c2.token_symbol,
|
||||
CONCAT(SUBSTRING(token_out, 1, 5), '...', SUBSTRING(token_out, 39, 42))
|
||||
)
|
||||
)
|
||||
)
|
||||
ELSE lp.pool_name
|
||||
END AS pool_name_heal,
|
||||
sender,
|
||||
tx_to,
|
||||
event_index,
|
||||
t0.platform,
|
||||
t0.protocol,
|
||||
t0.version,
|
||||
t0.type,
|
||||
t0._log_id,
|
||||
t0._inserted_timestamp
|
||||
FROM
|
||||
{{ this }}
|
||||
t0
|
||||
LEFT JOIN contracts
|
||||
c1
|
||||
ON t0.token_in = c1.contract_address
|
||||
LEFT JOIN contracts
|
||||
c2
|
||||
ON t0.token_out = c2.contract_address
|
||||
LEFT JOIN prices
|
||||
p1
|
||||
ON t0.token_in = p1.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p1.hour
|
||||
LEFT JOIN prices
|
||||
p2
|
||||
ON t0.token_out = p2.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p2.hour
|
||||
LEFT JOIN {{ ref('silver_dex__complete_dex_liquidity_pools') }}
|
||||
lp
|
||||
ON t0.contract_address = lp.pool_address
|
||||
AND t0.pool_id = lp.pool_id
|
||||
WHERE
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t1.block_number,
|
||||
'-',
|
||||
t1.platform,
|
||||
'-',
|
||||
t1.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t1
|
||||
WHERE
|
||||
t1.decimals_in IS NULL
|
||||
AND t1._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
contracts C
|
||||
WHERE
|
||||
C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND C.token_decimals IS NOT NULL
|
||||
AND C.contract_address = t1.token_in)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t2.block_number,
|
||||
'-',
|
||||
t2.platform,
|
||||
'-',
|
||||
t2.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t2
|
||||
WHERE
|
||||
t2.decimals_out IS NULL
|
||||
AND t2._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
contracts C
|
||||
WHERE
|
||||
C._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND C.token_decimals IS NOT NULL
|
||||
AND C.contract_address = t2.token_out)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t3.block_number,
|
||||
'-',
|
||||
t3.platform,
|
||||
'-',
|
||||
t3.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t3
|
||||
WHERE
|
||||
t3.amount_in_usd IS NULL
|
||||
AND t3._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
prices
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t3.token_in
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t3.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
SELECT
|
||||
CONCAT(
|
||||
t4.block_number,
|
||||
'-',
|
||||
t4.platform,
|
||||
'-',
|
||||
t4.version
|
||||
)
|
||||
FROM
|
||||
{{ this }}
|
||||
t4
|
||||
WHERE
|
||||
t4.amount_out_usd IS NULL
|
||||
AND t4._inserted_timestamp < (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND EXISTS (
|
||||
SELECT
|
||||
1
|
||||
FROM
|
||||
prices
|
||||
p
|
||||
WHERE
|
||||
p._inserted_timestamp > DATEADD('DAY', -14, SYSDATE())
|
||||
AND p.price IS NOT NULL
|
||||
AND p.token_address = t4.token_out
|
||||
AND p.hour = DATE_TRUNC(
|
||||
'hour',
|
||||
t4.block_timestamp
|
||||
)
|
||||
)
|
||||
GROUP BY
|
||||
1
|
||||
)
|
||||
OR
|
||||
CONCAT(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
select concat(
|
||||
t5.block_number,
|
||||
'-',
|
||||
t5.platform,
|
||||
'-',
|
||||
t5.version
|
||||
)
|
||||
from {{ this }} t5
|
||||
where t5.token_in in (
|
||||
select token_address
|
||||
from {{ ref('price__ez_asset_metadata') }}
|
||||
where ifnull(is_verified_modified_timestamp, '1970-01-01' :: TIMESTAMP) > dateadd('day', -10, SYSDATE())
|
||||
)
|
||||
)
|
||||
OR concat(
|
||||
t0.block_number,
|
||||
'-',
|
||||
t0.platform,
|
||||
'-',
|
||||
t0.version
|
||||
) IN (
|
||||
select concat(
|
||||
t6.block_number,
|
||||
'-',
|
||||
t6.platform,
|
||||
'-',
|
||||
t6.version
|
||||
)
|
||||
from {{ this }} t6
|
||||
where t6.token_out in (
|
||||
select token_address
|
||||
from {{ ref('price__ez_asset_metadata') }}
|
||||
where ifnull(is_verified_modified_timestamp, '1970-01-01' :: TIMESTAMP) > dateadd('day', -10, SYSDATE())
|
||||
)
|
||||
)
|
||||
),
|
||||
{% endif %}
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
complete_dex_swaps
|
||||
|
||||
{% if is_incremental() and var(
|
||||
'HEAL_MODEL'
|
||||
) %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
pool_id,
|
||||
event_name,
|
||||
token_in,
|
||||
token_in_is_verified,
|
||||
decimals_in,
|
||||
symbol_in,
|
||||
amount_in_unadj,
|
||||
amount_in_heal AS amount_in,
|
||||
amount_in_usd_heal AS amount_in_usd,
|
||||
token_out,
|
||||
token_out_is_verified,
|
||||
decimals_out,
|
||||
symbol_out,
|
||||
amount_out_unadj,
|
||||
amount_out_heal AS amount_out,
|
||||
amount_out_usd_heal AS amount_out_usd,
|
||||
pool_name_heal AS pool_name,
|
||||
sender,
|
||||
tx_to,
|
||||
event_index,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
heal_model
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
pool_name,
|
||||
pool_id,
|
||||
event_name,
|
||||
amount_in_unadj,
|
||||
amount_in,
|
||||
amount_in_usd,
|
||||
amount_out_unadj,
|
||||
amount_out,
|
||||
amount_out_usd,
|
||||
sender,
|
||||
tx_to,
|
||||
event_index,
|
||||
platform,
|
||||
protocol,
|
||||
version,
|
||||
type,
|
||||
token_in,
|
||||
IFNULL(
|
||||
token_in_is_verified,
|
||||
FALSE
|
||||
) AS token_in_is_verified,
|
||||
token_out,
|
||||
IFNULL(
|
||||
token_out_is_verified,
|
||||
FALSE
|
||||
) AS token_out_is_verified,
|
||||
symbol_in,
|
||||
symbol_out,
|
||||
decimals_in,
|
||||
decimals_out,
|
||||
_log_id,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_dex_swaps_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify (ROW_NUMBER() over (PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,66 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver_dex__complete_dex_swaps
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- _LOG_ID
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: CONTRACT_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: AMOUNT_IN
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_OUT
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_IN
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: TOKEN_OUT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: SENDER
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: TX_TO
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: VERSION
|
||||
tests:
|
||||
- not_null
|
||||
- name: TYPE
|
||||
tests:
|
||||
- not_null
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 3
|
||||
@ -1,308 +0,0 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'merge',
|
||||
unique_key = 'swaps_combined_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['modified_timestamp::DATE'],
|
||||
tags = ['noncore']
|
||||
) }}
|
||||
|
||||
{% if execute %}
|
||||
|
||||
{% if is_incremental() %}
|
||||
-- get the max modified_timestamp from the target table
|
||||
{% set max_m_query %}
|
||||
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '{{ var("LOOKBACK", "30 minutes") }}' AS modified_timestamp
|
||||
FROM
|
||||
{{ this }}
|
||||
|
||||
{% endset %}
|
||||
{% set max_mod_timestamp = run_query(max_m_query).columns [0].values() [0] %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
WITH inc AS (
|
||||
SELECT
|
||||
'dragonswap' AS platform,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
tx_to,
|
||||
sender,
|
||||
amount_in_unadj,
|
||||
amount_out_unadj,
|
||||
token_in,
|
||||
token_out,
|
||||
dragonswap_swaps_decoded_id AS uk
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__dragonswap_swaps_combined') }}
|
||||
|
||||
{% if is_incremental() and 'dragonswap' not in var('HEAL_MODELS') %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_mod_timestamp }}'
|
||||
{% endif %}
|
||||
|
||||
qualify ROW_NUMBER() over (
|
||||
PARTITION BY tx_hash,
|
||||
event_index
|
||||
ORDER BY
|
||||
modified_timestamp DESC
|
||||
) = 1
|
||||
-- add other dexes
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
'jellyswap' AS platform,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
pool_address AS contract_address,
|
||||
null AS tx_to,
|
||||
null AS sender,
|
||||
amount_in_unadj,
|
||||
amount_out_unadj,
|
||||
token_in,
|
||||
token_out,
|
||||
jellyswap_swaps_id AS uk
|
||||
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__jellyswap_swaps') }}
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
'sailorswap' AS platform,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_name,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
pool_address AS contract_address,
|
||||
tx_to,
|
||||
sender,
|
||||
ABS(amount0) AS amount_in_unadj,
|
||||
ABS(amount1) AS amount_out_unadj,
|
||||
token0 AS token_in,
|
||||
token1 AS token_out,
|
||||
sailorswap_swaps_id AS uk
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__sailorswap_swaps') }}
|
||||
)
|
||||
|
||||
{% if is_incremental() %},
|
||||
mod_price AS (
|
||||
SELECT
|
||||
token_address,
|
||||
HOUR,
|
||||
price
|
||||
FROM
|
||||
{{ ref('price__ez_prices_hourly') }}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_mod_timestamp }}'
|
||||
),
|
||||
mod_decimal AS (
|
||||
SELECT
|
||||
contract_address,
|
||||
token_decimals,
|
||||
token_symbol
|
||||
FROM
|
||||
{{ ref('silver_evm__contracts') }}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_mod_timestamp }}'
|
||||
),
|
||||
mod_map AS (
|
||||
SELECT
|
||||
evm_address,
|
||||
sei_address
|
||||
FROM
|
||||
{{ ref('core__dim_address_mapping') }}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_mod_timestamp }}'
|
||||
)
|
||||
{% endif %},
|
||||
fin AS (
|
||||
SELECT
|
||||
A.block_number AS block_id,
|
||||
A.block_timestamp,
|
||||
A.tx_hash AS tx_id,
|
||||
'evm' AS originated_from,
|
||||
A.platform,
|
||||
d.sei_address AS swapper,
|
||||
A.origin_from_address,
|
||||
A.contract_address AS pool_address,
|
||||
A.amount_in_unadj,
|
||||
CASE
|
||||
WHEN c_in.token_decimals IS NOT NULL THEN (amount_in_unadj / pow(10, c_in.token_decimals))
|
||||
END AS amount_in,
|
||||
CASE
|
||||
WHEN c_in.token_decimals IS NOT NULL THEN amount_in * b_in.price
|
||||
END AS amount_in_usd,
|
||||
A.amount_out_unadj,
|
||||
CASE
|
||||
WHEN c_out.token_decimals IS NOT NULL THEN (amount_out_unadj / pow(10, c_out.token_decimals))
|
||||
END AS amount_out,
|
||||
CASE
|
||||
WHEN c_out.token_decimals IS NOT NULL THEN amount_out * b_out.price
|
||||
END AS amount_out_usd,
|
||||
A.token_in,
|
||||
c_in.token_symbol AS symbol_in,
|
||||
A.token_out,
|
||||
c_out.token_symbol AS symbol_out,
|
||||
A.origin_function_signature,
|
||||
A.event_index AS INDEX,
|
||||
A.origin_to_address,
|
||||
A.sender,
|
||||
A.tx_to,
|
||||
A.event_name,
|
||||
uk AS swaps_combined_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
inc A
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
b_in
|
||||
ON A.token_in = b_in.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
A.block_timestamp
|
||||
) = b_in.hour
|
||||
LEFT JOIN {{ ref('price__ez_prices_hourly') }}
|
||||
b_out
|
||||
ON A.token_out = b_out.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
A.block_timestamp
|
||||
) = b_out.hour
|
||||
LEFT JOIN {{ ref('silver_evm__contracts') }}
|
||||
c_in
|
||||
ON A.token_in = c_in.contract_address
|
||||
LEFT JOIN {{ ref('silver_evm__contracts') }}
|
||||
c_out
|
||||
ON A.token_out = c_out.contract_address
|
||||
LEFT JOIN {{ ref('core__dim_address_mapping') }}
|
||||
d
|
||||
ON A.origin_from_address = d.evm_address
|
||||
|
||||
{% if is_incremental() %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
A.block_id,
|
||||
A.block_timestamp,
|
||||
A.tx_id,
|
||||
A.originated_from,
|
||||
A.platform,
|
||||
COALESCE(
|
||||
A.swapper,
|
||||
d.sei_address
|
||||
) AS swapper,
|
||||
A.origin_from_address,
|
||||
A.pool_address,
|
||||
A.amount_in_unadj,
|
||||
COALESCE(
|
||||
A.amount_in,
|
||||
CASE
|
||||
WHEN c_in.token_decimals IS NOT NULL THEN (A.amount_in_unadj / pow(10, c_in.token_decimals))
|
||||
END
|
||||
) AS amount_in,
|
||||
COALESCE(
|
||||
A.amount_in_usd,
|
||||
CASE
|
||||
WHEN c_in.token_decimals IS NOT NULL THEN (A.amount_in_unadj / pow(10, c_in.token_decimals)) * b_in.price
|
||||
END
|
||||
) AS amount_in_usd,
|
||||
A.amount_out_unadj,
|
||||
COALESCE(
|
||||
A.amount_out,
|
||||
CASE
|
||||
WHEN c_out.token_decimals IS NOT NULL THEN (A.amount_out_unadj / pow(10, c_in.token_decimals))
|
||||
END
|
||||
) AS amount_out,
|
||||
COALESCE(
|
||||
A.amount_out_usd,
|
||||
CASE
|
||||
WHEN c_out.token_decimals IS NOT NULL THEN (A.amount_out_unadj / pow(10, c_in.token_decimals)) * b_out.price
|
||||
END
|
||||
) AS amount_out_usd,
|
||||
A.token_in,
|
||||
COALESCE(
|
||||
A.symbol_in,
|
||||
c_in.token_symbol
|
||||
) AS symbol_in,
|
||||
A.token_out,
|
||||
COALESCE(
|
||||
A.symbol_out,
|
||||
c_out.token_symbol
|
||||
) AS symbol_out,
|
||||
A.origin_function_signature,
|
||||
A.index,
|
||||
A.origin_to_address,
|
||||
A.sender,
|
||||
A.tx_to,
|
||||
A.event_name,
|
||||
A.swaps_combined_id,
|
||||
A.inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
{{ this }} A
|
||||
LEFT JOIN mod_price b_in
|
||||
ON A.token_in = b_in.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
A.block_timestamp
|
||||
) = b_in.hour
|
||||
LEFT JOIN mod_price b_out
|
||||
ON A.token_out = b_out.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
A.block_timestamp
|
||||
) = b_out.hour
|
||||
LEFT JOIN mod_decimal c_in
|
||||
ON A.token_in = c_in.contract_address
|
||||
LEFT JOIN mod_decimal c_out
|
||||
ON A.token_out = c_out.contract_address
|
||||
LEFT JOIN mod_map d
|
||||
ON A.origin_from_address = d.evm_address
|
||||
WHERE
|
||||
(
|
||||
A.amount_in IS NULL
|
||||
OR A.amount_in_usd IS NULL
|
||||
OR A.amount_out IS NULL
|
||||
OR A.amount_out_usd IS NULL
|
||||
OR A.symbol_in IS NULL
|
||||
OR A.symbol_out IS NULL
|
||||
OR A.swapper IS NULL
|
||||
)
|
||||
AND (
|
||||
b_in.price IS NOT NULL
|
||||
OR b_out.price IS NOT NULL
|
||||
OR c_in.token_decimals IS NOT NULL
|
||||
OR c_out.token_decimals IS NOT NULL
|
||||
OR d.sei_address IS NOT NULL
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
fin qualify(ROW_NUMBER() over (PARTITION BY swaps_combined_id
|
||||
ORDER BY
|
||||
inserted_timestamp DESC) = 1)
|
||||
27
models/gold/defi/defi__dim_dex_liquidity_pools.sql
Normal file
27
models/gold/defi/defi__dim_dex_liquidity_pools.sql
Normal file
@ -0,0 +1,27 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'DEX, LIQUIDITY, POOLS, LP, SWAPS',
|
||||
} } },
|
||||
tags = ['gold','defi','dex','curated']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number AS creation_block,
|
||||
block_timestamp AS creation_time,
|
||||
tx_hash AS creation_tx,
|
||||
platform,
|
||||
protocol,
|
||||
version AS protocol_version,
|
||||
contract_address AS factory_address,
|
||||
pool_address,
|
||||
pool_name,
|
||||
tokens,
|
||||
symbols,
|
||||
decimals,
|
||||
complete_dex_liquidity_pools_id AS dim_dex_liquidity_pools_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver_dex__complete_dex_liquidity_pools') }}
|
||||
32
models/gold/defi/defi__dim_dex_liquidity_pools.yml
Normal file
32
models/gold/defi/defi__dim_dex_liquidity_pools.yml
Normal file
@ -0,0 +1,32 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__dim_dex_liquidity_pools
|
||||
description: '{{ doc("dim_dex_lp_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: CREATION_BLOCK
|
||||
description: '{{ doc("ez_dex_swaps_creation_block") }}'
|
||||
- name: CREATION_TIME
|
||||
description: '{{ doc("ez_dex_swaps_creation_time") }}'
|
||||
- name: CREATION_TX
|
||||
description: '{{ doc("ez_dex_swaps_creation_tx") }}'
|
||||
- name: FACTORY_ADDRESS
|
||||
description: '{{ doc("ez_dex_swaps_factory_address") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("ez_dex_swaps_platform") }}'
|
||||
- name: POOL_ADDRESS
|
||||
description: '{{ doc("ez_dex_swaps_pool_address") }}'
|
||||
- name: POOL_NAME
|
||||
description: '{{ doc("ez_dex_swaps_pool_name") }}'
|
||||
- name: TOKENS
|
||||
description: '{{ doc("ez_dex_swaps_tokens") }}'
|
||||
- name: SYMBOLS
|
||||
description: '{{ doc("ez_dex_swaps_symbols") }}'
|
||||
- name: DECIMALS
|
||||
description: '{{ doc("ez_dex_swaps_decimals") }}'
|
||||
- name: DIM_DEX_LIQUIDITY_POOLS_ID
|
||||
description: '{{ doc("general_pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("general_inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("general_modified_timestamp") }}'
|
||||
@ -1,93 +1,66 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = 'ez_dex_swaps_id',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['block_timestamp::DATE','originated_from','platform'],
|
||||
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_id,origin_from_address,swapper,token_in,token_out,symbol_in,symbol_out);",
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'SWAPS' }} },
|
||||
tags = ['noncore','recent_test']
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'DEX, SWAPS' } } },
|
||||
tags = ['gold','defi','dex','curated','ez']
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_id,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
originated_from,
|
||||
platform,
|
||||
swapper,
|
||||
tx_hash,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
pool_address,
|
||||
origin_to_address,
|
||||
contract_address,
|
||||
pool_name,
|
||||
event_name,
|
||||
amount_in_unadj,
|
||||
amount_in,
|
||||
amount_in_usd,
|
||||
ROUND(
|
||||
CASE
|
||||
WHEN (token_in <> '0xe30fedd158a2e3b13e9badaeabafc5516e95e8c7'
|
||||
OR NOT token_in_is_verified)
|
||||
AND (
|
||||
amount_out_usd IS NULL
|
||||
OR ABS((amount_in_usd - amount_out_usd) / NULLIF(amount_out_usd, 0)) > 0.75
|
||||
OR ABS((amount_in_usd - amount_out_usd) / NULLIF(amount_in_usd, 0)) > 0.75
|
||||
) THEN NULL
|
||||
ELSE amount_in_usd
|
||||
END,
|
||||
2
|
||||
) AS amount_in_usd,
|
||||
amount_out_unadj,
|
||||
amount_out,
|
||||
amount_out_usd,
|
||||
token_in,
|
||||
symbol_in,
|
||||
token_out,
|
||||
symbol_out,
|
||||
origin_function_signature,
|
||||
INDEX,
|
||||
origin_to_address,
|
||||
ROUND(
|
||||
CASE
|
||||
WHEN (token_out <> '0xe30fedd158a2e3b13e9badaeabafc5516e95e8c7'
|
||||
OR NOT token_out_is_verified)
|
||||
AND (
|
||||
amount_in_usd IS NULL
|
||||
OR ABS((amount_out_usd - amount_in_usd) / NULLIF(amount_in_usd, 0)) > 0.75
|
||||
OR ABS((amount_out_usd - amount_in_usd) / NULLIF(amount_out_usd, 0)) > 0.75
|
||||
) THEN NULL
|
||||
ELSE amount_out_usd
|
||||
END,
|
||||
2
|
||||
) AS amount_out_usd,
|
||||
sender,
|
||||
tx_to,
|
||||
event_name,
|
||||
swaps_combined_id AS ez_dex_swaps_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
{{ ref('silver_evm_dex__swaps_combined') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '{{ var("LOOKBACK", "30 minutes") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_id,
|
||||
block_timestamp,
|
||||
tx_id,
|
||||
originated_from,
|
||||
event_index,
|
||||
platform,
|
||||
swapper,
|
||||
origin_from_address,
|
||||
pool_address,
|
||||
amount_in_unadj,
|
||||
amount_in,
|
||||
amount_in_usd,
|
||||
amount_out_unadj,
|
||||
amount_out,
|
||||
amount_out_usd,
|
||||
protocol,
|
||||
version AS protocol_version,
|
||||
token_in,
|
||||
symbol_in,
|
||||
token_in_is_verified,
|
||||
token_out,
|
||||
token_out_is_verified,
|
||||
symbol_in,
|
||||
symbol_out,
|
||||
origin_function_signature,
|
||||
INDEX,
|
||||
origin_to_address,
|
||||
sender,
|
||||
tx_to,
|
||||
event_name,
|
||||
swaps_combined_id AS ez_dex_swaps_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
_log_id,
|
||||
complete_dex_swaps_id AS ez_dex_swaps_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__dex_swaps_combined') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(modified_timestamp) - INTERVAL '{{ var("LOOKBACK", "30 minutes") }}'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
{{ ref('silver_dex__complete_dex_swaps') }}
|
||||
|
||||
@ -1,107 +1,65 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_dex_swaps
|
||||
description: Records swap transactions on Sei (both native sei and evm protocols) for Astroport, Fuzio, Seaswap, and Dragonswap
|
||||
description: '{{ doc("ez_dex_swaps_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id') }}"
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("general_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: block_timestamp > current_date() - {{ var('test_days_threshold', 7) }} or block_timestamp is null
|
||||
- name: TX_ID
|
||||
description: This will be either the native sei tx_id or the evm tx_hash. Swaps that are initiated on and native sei protocol will have a tx_id that can be find in CORE.FAC_TRANSACTIONS. Swaps that are initiated on an evm protocol will have a tx_id that is the tx_hash of the evm transaction that can be found in CORE_EVM.FACT_TRANSACTIONS.
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: originated_from
|
||||
description: The evm from address of this transaction.
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
description: '{{ doc("general_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("general_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("ez_dex_swaps_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("general_event_name") }}'
|
||||
- name: AMOUNT_IN
|
||||
description: '{{ doc("ez_dex_swaps_amount_in") }}'
|
||||
- name: AMOUNT_OUT
|
||||
description: '{{ doc("ez_dex_swaps_amount_out") }}'
|
||||
- name: AMOUNT_IN_USD
|
||||
description: '{{ doc("ez_dex_swaps_amount_in_usd") }}'
|
||||
- name: AMOUNT_OUT_USD
|
||||
description: '{{ doc("ez_dex_swaps_amount_out_usd") }}'
|
||||
- name: TOKEN_IN
|
||||
description: '{{ doc("ez_dex_swaps_token_in") }}'
|
||||
- name: TOKEN_IN_IS_VERIFIED
|
||||
description: '{{ doc("ez_dex_swaps_token_in_is_verified") }}'
|
||||
- name: TOKEN_OUT
|
||||
description: '{{ doc("ez_dex_swaps_token_out") }}'
|
||||
- name: TOKEN_OUT_IS_VERIFIED
|
||||
description: '{{ doc("ez_dex_swaps_token_out_is_verified") }}'
|
||||
- name: SYMBOL_IN
|
||||
description: '{{ doc("ez_dex_swaps_symbol_in") }}'
|
||||
- name: SYMBOL_OUT
|
||||
description: '{{ doc("ez_dex_swaps_symbol_out") }}'
|
||||
- name: SENDER
|
||||
description: '{{ doc("ez_dex_swaps_sender") }}'
|
||||
- name: TX_TO
|
||||
description: '{{ doc("ez_dex_swaps_to") }}'
|
||||
- name: PLATFORM
|
||||
description: The platform that the swap was initiated on. This will be either astroport, fuzio, seaswap, or dragonswap.
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: SWAPPER
|
||||
description: "{{ doc('swapper') }}"
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: originated_from = 'sei' and block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: origin_from_address
|
||||
description: "{{doc('sei_origin_from')}}"
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: originated_from = 'evm' and block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: pool_address
|
||||
description: The contract address for the liquidity pool.
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: amount_in_unadj
|
||||
description: The non-decimal adjusted amount of tokens put into the swap.
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: amount_in
|
||||
description: The amount of tokens put into the swap. This will be null if we do not have the decimal adjustment for the token.
|
||||
- name: amount_in_usd
|
||||
description: The amount of tokens put into the swap converted to USD using the price of the token. This will be null if we do not have the decimal adjustment or price for the token.
|
||||
- name: amount_out_unadj
|
||||
description: The non-decimal adjusted amount of tokens taken out of or received from the swap. This will be null if we do not have the decimal adjustment for the token.
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: amount_out
|
||||
description: The amount of tokens taken out or received from the swap. This will be null if we do not have the decimal adjustment for the token.
|
||||
- name: amount_out_usd
|
||||
description: The amount of tokens taken out or received from the swap converted to USD using the price of the token. This will be null if we do not have the decimal adjustment or price for the token.
|
||||
- name: token_in
|
||||
description: The address of the token sent for swap.
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: symbol_in
|
||||
description: The symbol of the token sent for swap.
|
||||
- name: token_out
|
||||
description: The address of the token being swapped to.
|
||||
- name: symbol_out
|
||||
description: The symbol of the token being swapped to.
|
||||
- name: origin_function_signature
|
||||
description: "{{doc('sei_tx_origin_sig')}}"
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: originated_from = 'evm' and block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: INDEX
|
||||
description: This is the event_index for evm transactions or the msg_index for native sei transactions. This is used to uniquely identify the action within the transaction.
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: origin_to_address
|
||||
description: "{{doc('sei_eth_origin_to')}} Note: this will only be populated for evm transactions."
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: originated_from = 'evm' and block_timestamp > current_date() - {{ var('test_days_threshold', 7) }}
|
||||
- name: sender
|
||||
description: "The Router is the Sender in the swap function. Note: this will only be populated for evm transactions."
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: originated_from = 'evm' and block_timestamp > current_date() - {{ var('test_days_threshold', 7) }} and platform <> 'jellyswap'
|
||||
- name: tx_to
|
||||
description: 'The tx_to is the address who receives the swapped token. This corresponds to the "to" field in the swap function. Note: this will only be populated for evm transactions.'
|
||||
data_tests:
|
||||
- not_null:
|
||||
where: originated_from = 'evm' and block_timestamp > current_date() - {{ var('test_days_threshold', 7) }} and platform <> 'jellyswap'
|
||||
- name: event_name
|
||||
description: The decoded event name for a given event.
|
||||
description: '{{ doc("ez_dex_swaps_platform") }}'
|
||||
- name: PROTOCOL
|
||||
description: '{{ doc("ez_dex_swaps_protocol") }}'
|
||||
- name: PROTOCOL_VERSION
|
||||
description: '{{ doc("ez_dex_swaps_protocol_version") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("general_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("general_origin_function_signature") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("general_from_address") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("general_to_address") }}'
|
||||
- name: AMOUNT_IN_UNADJ
|
||||
description: '{{ doc("ez_dex_swaps_amount_in_unadj") }}'
|
||||
- name: AMOUNT_OUT_UNADJ
|
||||
description: '{{ doc("ez_dex_swaps_amount_out_unadj") }}'
|
||||
- name: EZ_DEX_SWAPS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
description: '{{ doc("general_pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
description: '{{ doc("general_inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
description: '{{ doc("general_modified_timestamp") }}'
|
||||
|
||||
|
||||
@ -16,6 +16,8 @@ WITH base AS (
|
||||
blockchain,
|
||||
FALSE AS is_native,
|
||||
is_deprecated,
|
||||
is_verified,
|
||||
is_verified_modified_timestamp,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
complete_token_asset_metadata_id AS ez_asset_metadata_id
|
||||
@ -51,6 +53,8 @@ SELECT
|
||||
blockchain,
|
||||
TRUE AS is_native,
|
||||
is_deprecated,
|
||||
TRUE AS is_verified,
|
||||
NULL AS is_verified_modified_timestamp,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
complete_native_asset_metadata_id AS ez_asset_metadata_id
|
||||
@ -94,6 +98,8 @@ SELECT
|
||||
blockchain,
|
||||
is_native,
|
||||
is_deprecated,
|
||||
is_verified,
|
||||
is_verified_modified_timestamp,
|
||||
A.inserted_timestamp,
|
||||
A.modified_timestamp,
|
||||
ez_asset_metadata_id
|
||||
|
||||
@ -30,6 +30,8 @@ models:
|
||||
description: '{{ doc("prices_is_native") }}'
|
||||
- name: IS_DEPRECATED
|
||||
description: '{{ doc("prices_is_deprecated") }}'
|
||||
- name: IS_VERIFIED
|
||||
description: '{{ doc("ez_prices_is_verified") }}'
|
||||
- name: EZ_ASSET_METADATA_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
|
||||
@ -17,6 +17,7 @@ WITH base AS (
|
||||
FALSE AS is_native,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
is_verified,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
complete_token_prices_id AS ez_prices_hourly_id
|
||||
@ -47,6 +48,7 @@ SELECT
|
||||
TRUE AS is_native,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
TRUE AS is_verified,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
complete_native_prices_id AS ez_prices_hourly_id
|
||||
@ -80,6 +82,7 @@ SELECT
|
||||
A.is_native,
|
||||
A.is_imputed,
|
||||
A.is_deprecated,
|
||||
A.is_verified,
|
||||
A.inserted_timestamp,
|
||||
A.modified_timestamp,
|
||||
A.ez_prices_hourly_id
|
||||
|
||||
@ -39,6 +39,8 @@ models:
|
||||
description: '{{ doc("prices_is_deprecated") }}'
|
||||
tests:
|
||||
- not_null
|
||||
- name: IS_VERIFIED
|
||||
description: '{{ doc("ez_prices_is_verified") }}'
|
||||
- name: EZ_PRICES_HOURLY_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
|
||||
@ -14,6 +14,8 @@ SELECT
|
||||
blockchain_name,
|
||||
blockchain_id,
|
||||
is_deprecated,
|
||||
is_verified,
|
||||
is_verified_modified_timestamp,
|
||||
provider,
|
||||
source,
|
||||
_inserted_timestamp,
|
||||
|
||||
@ -17,6 +17,7 @@ SELECT
|
||||
blockchain_id,
|
||||
is_imputed,
|
||||
is_deprecated,
|
||||
is_verified,
|
||||
provider,
|
||||
source,
|
||||
_inserted_timestamp,
|
||||
|
||||
@ -6,7 +6,7 @@ packages:
|
||||
- git: https://github.com/FlipsideCrypto/fsc-utils.git
|
||||
revision: eb33ac727af26ebc8a8cc9711d4a6ebc3790a107
|
||||
- package: get-select/dbt_snowflake_query_tags
|
||||
version: 2.5.0
|
||||
version: 2.5.3
|
||||
- git: https://github.com/FlipsideCrypto/fsc-evm.git
|
||||
revision: a700111699af1a355d9076dde9aa04e26efb0617
|
||||
- package: calogica/dbt_date
|
||||
|
||||
Loading…
Reference in New Issue
Block a user