-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* migrate velodrome v1 * remove velo from frontend and docs * undo delete on files * delete yml, update to stale
- Loading branch information
Showing
23 changed files
with
326 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
models/silver/defi/dex/velodrome/silver_dex__velodrome_v1_pools.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
20 changes: 20 additions & 0 deletions
20
models/silver/defi/dex/velodrome/silver_dex__velodrome_v1_pools.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
124
models/silver/defi/dex/velodrome/silver_dex__velodrome_v1_swaps.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.