Skip to content

Commit

Permalink
An 5204/deprecate velodrome (#304)
Browse files Browse the repository at this point in the history
* migrate velodrome v1

* remove velo from frontend and docs

* undo delete on files

* delete yml, update to stale
  • Loading branch information
sam-xyz authored Oct 15, 2024
1 parent 394d866 commit f92bd60
Show file tree
Hide file tree
Showing 23 changed files with 326 additions and 638 deletions.
9 changes: 0 additions & 9 deletions models/doc_descriptions/general/__overview__.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ There is more information on how to use dbt docs in the last section of this doc
### Stats Tables (optimism.stats)
- [ez_core_metrics_hourly](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.stats__ez_core_metrics_hourly)

**Velodrome**
- [ez_claimed_rewards](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.velodrome__ez_claimed_rewards)
- [ez_lp_actions](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.velodrome__ez_lp_actions)
- [ez_pool_details](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.velodrome__ez_pool_details)
- [ez_staking_actions](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.velodrome__ez_staking_actions)
- [ez_swaps](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.velodrome__ez_swaps)
- [ez_velo_locks](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.velodrome__ez_velo_locks)
- [ez_votes](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.velodrome__ez_votes)

### NFT Tables (optimism.nft)

- [ez_nft_sales](https://flipsidecrypto.github.io/optimism-models/#!/model/model.optimism_models.nft__ez_nft_sales)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ WHERE
),
velodrome AS (
SELECT
created_block AS block_number,
created_timestamp AS block_timestamp,
created_hash AS tx_hash,
deployer_address AS contract_address,
block_number,
block_timestamp,
tx_hash,
contract_address,
pool_address,
pool_name,
NULL AS fee,
Expand All @@ -418,14 +418,14 @@ velodrome AS (
NULL AS token5,
NULL AS token6,
NULL AS token7,
token0_address AS token0,
token1_address AS token1,
token0,
token1,
'velodrome' AS platform,
'v1' AS version,
_log_id AS _id,
_inserted_timestamp
FROM
{{ ref('silver__velodrome_pool_details') }}
{{ ref('silver_dex__velodrome_v1_pools') }}

{% if is_incremental() and 'velodrome' not in var('HEAL_MODELS') %}
WHERE
Expand Down
21 changes: 9 additions & 12 deletions models/silver/defi/dex/silver_dex__complete_dex_swaps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -166,29 +166,26 @@ velodrome AS (
origin_from_address,
origin_to_address,
contract_address,
CASE
WHEN event_name IS NULL THEN 'Swap'
ELSE event_name
END AS event_name,
event_name,
amount_in_unadj,
amount_out_unadj,
token_address_in AS token_in,
token_address_out AS token_out,
sender_address AS sender,
to_address AS tx_to,
token_in,
token_out,
sender,
tx_to,
event_index,
platform,
'v1' AS version,
_log_id,
'1970-01-01' :: DATE AS _inserted_timestamp
_inserted_timestamp
FROM
{{ ref('velodrome__ez_swaps') }}
{{ ref('silver_dex__velodrome_v1_swaps') }}

{% if is_incremental() and 'velodrome' not in var('HEAL_MODELS') %}
WHERE
block_timestamp >= (
_inserted_timestamp >= (
SELECT
MAX(block_timestamp) - INTERVAL '72 hours'
MAX(_inserted_timestamp) - INTERVAL '{{ var("LOOKBACK", "4 hours") }}'
FROM
{{ this }}
)
Expand Down
124 changes: 124 additions & 0 deletions models/silver/defi/dex/velodrome/silver_dex__velodrome_v1_pools.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = 'pool_address',
cluster_by = ['block_timestamp::DATE'],
tags = ['curated']
) }}

WITH pool_creation AS (

SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
contract_address,
regexp_substr_all(SUBSTR(DATA, 3), '.{64}') AS segmented,
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS token0,
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS token1,
IFF(utils.udf_hex_to_int(segmented [0] :: STRING) = 0, FALSE, TRUE) AS stable,
'0x' || SUBSTR(
segmented [1] :: STRING,
25,
40
) AS pool_address,
utils.udf_hex_to_int(
segmented [2] :: STRING
) AS pool_id,
_log_id,
_inserted_timestamp
FROM
{{ ref('silver__logs') }}
WHERE
block_timestamp :: DATE >= '2022-06-01'
AND topics [0] :: STRING = '0xc4805696c66d7cf352fc1d6bb633ad5ee82f6cb577c453024b6e0eb8306c6fc9' -- pair created
AND contract_address = '0x25cbddb98b35ab1ff77413456b31ec81a6b6b746' --velo pair factory
AND tx_status = 'SUCCESS'

{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}

qualify(ROW_NUMBER() over (PARTITION BY pool_address
ORDER BY
_inserted_timestamp DESC)) = 1
),
build_request AS (
SELECT
pool_address,
block_number,
'0x06fdde03' AS function_sig,
-- name
utils.udf_json_rpc_call(
'eth_call',
[{'to': pool_address, 'from': null, 'data': function_sig}, utils.udf_int_to_hex(block_number)],
concat_ws(
'-',
contract_address,
function_sig,
block_number
)
) AS rpc_request
FROM
pool_creation
),
requests AS (
SELECT
*,
live.udf_api(
'POST',
CONCAT(
'{service}',
'/',
'{Authentication}'
),{},
rpc_request,
'Vault/prod/optimism/quicknode/mainnet'
) AS read_output,
read_output :data :result AS results
FROM
build_request
),
results_decoded AS (
SELECT
pool_address,
regexp_substr_all(SUBSTR(results, 3), '.{64}') AS segmented_data,
utils.udf_hex_to_int(
segmented_data [0] :: STRING
) / 32 AS offset,
utils.udf_hex_to_int(
segmented_data [offset] :: STRING
) * 2 AS string_length,
utils.udf_hex_to_string(
SUBSTR(
segmented_data [offset + 1 ] :: STRING,
1,
string_length
)
) AS pool_name
FROM
requests
)
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
contract_address,
token0,
token1,
stable,
pool_address,
pool_name,
pool_id,
_log_id,
_inserted_timestamp
FROM
pool_creation
LEFT JOIN results_decoded USING (pool_address)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2
models:
- name: silver_dex__velodrome_v1_pools

columns:
- name: POOL_ADDRESS
tests:
- not_null
- name: TOKEN0
tests:
- not_null
- name: TOKEN1
tests:
- not_null
- name: _INSERTED_TIMESTAMP
tests:
- dbt_expectations.expect_column_values_to_be_in_type_list:
column_type_list:
- TIMESTAMP_LTZ
- TIMESTAMP_NTZ
124 changes: 124 additions & 0 deletions models/silver/defi/dex/velodrome/silver_dex__velodrome_v1_swaps.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = 'block_number',
cluster_by = ['block_timestamp::DATE'],
tags = ['curated','reorg']
) }}

WITH pools AS (

SELECT
pool_address AS contract_address,
pool_name,
token0,
token1
FROM
{{ ref('silver_dex__velodrome_v1_pools') }}
),
base AS (
SELECT
block_number,
block_timestamp,
tx_hash,
event_index,
origin_function_signature,
origin_from_address,
origin_to_address,
contract_address,
pool_name,
regexp_substr_all(SUBSTR(DATA, 3), '.{64}') AS segmented,
'0x' || SUBSTR(
topics [1] :: STRING,
27,
40
) AS sender,
'0x' || SUBSTR(
topics [2] :: STRING,
27,
40
) AS tx_to,
utils.udf_hex_to_int(
segmented [0] :: STRING
) :: INT AS amount0In,
utils.udf_hex_to_int(
segmented [1] :: STRING
) :: INT AS amount1In,
utils.udf_hex_to_int(
segmented [2] :: STRING
) :: INT AS amount0Out,
utils.udf_hex_to_int(
segmented [3] :: STRING
) :: INT AS amount1Out,
token0,
token1,
_log_id,
_inserted_timestamp
FROM
{{ ref('silver__logs') }}
INNER JOIN pools USING (contract_address)
WHERE
block_timestamp :: DATE >= '2022-06-01'
AND topics [0] :: STRING IN (
'0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822'
)
AND tx_status = 'SUCCESS'
AND event_removed = 'false'

{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp) - INTERVAL '12 hours'
FROM
{{ this }}
)
{% endif %}
)
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
pool_name,
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,
'Swap' AS event_name,
'velodrome' AS platform,
_log_id,
_inserted_timestamp
FROM
base
WHERE
token_in <> token_out
Loading

0 comments on commit f92bd60

Please sign in to comment.