From cb62763033fd5a55cc2487d5b504f2c034c47d9f Mon Sep 17 00:00:00 2001 From: drethereum <71602799+drethereum@users.noreply.github.com> Date: Mon, 26 Aug 2024 14:39:26 -0600 Subject: [PATCH] AN-5053/new-staking-contract (#165) * new staking contracts * checkpoint and evicted tables --- .../olas/silver_olas__service_checkpoint.sql | 13 +- .../olas/silver_olas__service_staking.sql | 284 +++++++++--------- .../olas/silver_olas__services_evicted.sql | 13 +- 3 files changed, 168 insertions(+), 142 deletions(-) diff --git a/models/silver/protocols/olas/silver_olas__service_checkpoint.sql b/models/silver/protocols/olas/silver_olas__service_checkpoint.sql index 4b83f9c8..d2e9e9cb 100644 --- a/models/silver/protocols/olas/silver_olas__service_checkpoint.sql +++ b/models/silver/protocols/olas/silver_olas__service_checkpoint.sql @@ -28,6 +28,9 @@ WITH decoded_evt AS ( WHEN contract_address = '0x43fb32f25dce34eb76c78c7a42c8f40f84bcd237' THEN 'Coastal' WHEN contract_address = '0x2ef503950be67a98746f484da0bbada339df3326' THEN 'Alpine' WHEN contract_address = '0x5add592ce0a1b5dcecebb5dcac086cd9f9e3ea5c' THEN 'Everest' + WHEN contract_address = '0x5344b7dd311e5d3dddd46a4f71481bd7b05aaa3e' THEN 'Quickstart Beta - Expert' + WHEN contract_address = '0x389b46c259631acd6a69bde8b6cee218230bae8c' THEN 'Quickstart Beta - Hobbyist' + WHEN contract_address = '0xef44fb0842ddef59d37f85d61a1ef492bba6135d' THEN 'Pearl Beta' END AS program_name, _log_id, _inserted_timestamp @@ -36,12 +39,18 @@ WITH decoded_evt AS ( WHERE contract_address IN ( '0xee9f19b5df06c7e8bfc7b28745dcf944c504198a', - -- StakingProxy (Alpha) + --StakingProxy (Alpha) '0x43fb32f25dce34eb76c78c7a42c8f40f84bcd237', --ServiceStakingTokenMechUsage (Coastal) '0x2ef503950be67a98746f484da0bbada339df3326', --ServiceStakingTokenMechUsage (Alpine) - '0x5add592ce0a1b5dcecebb5dcac086cd9f9e3ea5c' --ServiceStakingTokenMechUsage (Everest) + '0x5add592ce0a1b5dcecebb5dcac086cd9f9e3ea5c', + --ServiceStakingTokenMechUsage (Everest) + '0x5344b7dd311e5d3dddd46a4f71481bd7b05aaa3e', + --Quickstart Beta - Expert + '0x389b46c259631acd6a69bde8b6cee218230bae8c', + --Quickstart Beta - Hobbyist + '0xef44fb0842ddef59d37f85d61a1ef492bba6135d' --Pearl Beta ) AND topic_0 IN ( '0x48b735a18ed32318d316214e41387be29c52e29df4598f2b8e40fa843be3f940', diff --git a/models/silver/protocols/olas/silver_olas__service_staking.sql b/models/silver/protocols/olas/silver_olas__service_staking.sql index 62cccea8..aaa3a98b 100644 --- a/models/silver/protocols/olas/silver_olas__service_staking.sql +++ b/models/silver/protocols/olas/silver_olas__service_staking.sql @@ -6,7 +6,7 @@ tags = ['curated','reorg'] ) }} -WITH stake AS ( +WITH all_evt AS ( SELECT block_number, @@ -21,27 +21,16 @@ WITH stake AS ( topics [1] :: STRING AS topic_1, topics [2] :: STRING AS topic_2, topics [3] :: STRING AS topic_3, - 'ServiceStaked' AS event_name, DATA, regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, - TRY_TO_NUMBER( - utils.udf_hex_to_int( - topic_1 - ) - ) AS service_id, - CONCAT('0x', SUBSTR(topic_2, 27, 40)) AS owner_address, - CONCAT('0x', SUBSTR(topic_3, 27, 40)) AS multisig_address, - utils.udf_hex_to_int( - segmented_data [0] :: STRING - ) AS epoch, - ARRAY_CONSTRUCT( - TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [3] :: STRING)), - TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)) - ) AS nonces, CASE WHEN contract_address = '0xee9f19b5df06c7e8bfc7b28745dcf944c504198a' THEN 'Alpha' WHEN contract_address = '0x43fb32f25dce34eb76c78c7a42c8f40f84bcd237' THEN 'Coastal' WHEN contract_address = '0x2ef503950be67a98746f484da0bbada339df3326' THEN 'Alpine' + WHEN contract_address = '0x5add592ce0a1b5dcecebb5dcac086cd9f9e3ea5c' THEN 'Everest' + WHEN contract_address = '0x5344b7dd311e5d3dddd46a4f71481bd7b05aaa3e' THEN 'Quickstart Beta - Expert' + WHEN contract_address = '0x389b46c259631acd6a69bde8b6cee218230bae8c' THEN 'Quickstart Beta - Hobbyist' + WHEN contract_address = '0xef44fb0842ddef59d37f85d61a1ef492bba6135d' THEN 'Pearl Beta' END AS program_name, _log_id, _inserted_timestamp @@ -53,9 +42,27 @@ WITH stake AS ( --StakingProxy (Alpha) '0x43fb32f25dce34eb76c78c7a42c8f40f84bcd237', --ServiceStakingTokenMechUsage (Coastal) - '0x2ef503950be67a98746f484da0bbada339df3326' --ServiceStakingTokenMechUsage (Alpine) + '0x2ef503950be67a98746f484da0bbada339df3326', + --ServiceStakingTokenMechUsage (Alpine) + '0x5add592ce0a1b5dcecebb5dcac086cd9f9e3ea5c', + --ServiceStakingTokenMechUsage (Everest) + '0x5344b7dd311e5d3dddd46a4f71481bd7b05aaa3e', + --Quickstart Beta - Expert + '0x389b46c259631acd6a69bde8b6cee218230bae8c', + --Quickstart Beta - Hobbyist + '0xef44fb0842ddef59d37f85d61a1ef492bba6135d' --Pearl Beta + ) + AND topic_0 IN ( + '0xaa6b005b4958114a0c90492461c24af6525ae0178db7fbf44125ae9217c69ccb', + --ServiceStaked + '0x950733f4c0bf951b8e770f3cc619a4288e7b59b1236d59aeaf2c238488e8ae81', + --ServiceUnstaked + '0x5d43ac9b1b213902df90d405b0006308578486b6c62182c5df202ed572c844e4', + --ServiceStaked (Everest) + '0x246ee6115bfd84e00097b16569c2ff2f822026bb9595a82cd2c1e69d4b6ea50c', + --ServiceUnstaked (Everest) + '0x6d789d063e079a4c156e77a20008529fc448dca2cd7e5e7a20abf969fffb9226' --ServiceUnstaked (Beta) ) - AND topic_0 = '0xaa6b005b4958114a0c90492461c24af6525ae0178db7fbf44125ae9217c69ccb' --ServiceStaked AND tx_status = 'SUCCESS' {% if is_incremental() %} @@ -67,6 +74,56 @@ AND _inserted_timestamp >= ( ) {% endif %} ), +stake AS ( + SELECT + block_number, + block_timestamp, + tx_hash, + origin_function_signature, + origin_from_address, + origin_to_address, + contract_address, + event_index, + 'ServiceStaked' AS event_name, + segmented_data, + TRY_TO_NUMBER( + utils.udf_hex_to_int( + topic_1 + ) + ) AS service_id, + CONCAT('0x', SUBSTR(topic_2, 27, 40)) AS owner_address, + CONCAT('0x', SUBSTR(topic_3, 27, 40)) AS multisig_address, + utils.udf_hex_to_int( + segmented_data [0] :: STRING + ) AS epoch, + NULL AS reward_unadj, + NULL AS available_rewards_unadj, + NULL AS ts_start, + ARRAY_CONSTRUCT( + TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [3] :: STRING)), + TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)) + ) AS nonces, + program_name, + _log_id, + _inserted_timestamp + FROM + all_evt + WHERE + contract_address IN ( + '0xee9f19b5df06c7e8bfc7b28745dcf944c504198a', + --StakingProxy (Alpha) + '0x43fb32f25dce34eb76c78c7a42c8f40f84bcd237', + --ServiceStakingTokenMechUsage (Coastal) + '0x2ef503950be67a98746f484da0bbada339df3326', + --ServiceStakingTokenMechUsage (Alpine) + '0x5344b7dd311e5d3dddd46a4f71481bd7b05aaa3e', + --Quickstart Beta - Expert + '0x389b46c259631acd6a69bde8b6cee218230bae8c', + --Quickstart Beta - Hobbyist + '0xef44fb0842ddef59d37f85d61a1ef492bba6135d' --Pearl Beta + ) + AND topic_0 = '0xaa6b005b4958114a0c90492461c24af6525ae0178db7fbf44125ae9217c69ccb' --ServiceStaked +), stake_everest AS ( SELECT block_number, @@ -77,13 +134,8 @@ stake_everest AS ( origin_to_address, contract_address, event_index, - topics [0] :: STRING AS topic_0, - topics [1] :: STRING AS topic_1, - topics [2] :: STRING AS topic_2, - topics [3] :: STRING AS topic_3, 'ServiceStaked' AS event_name, - DATA, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, + segmented_data, TRY_TO_NUMBER( utils.udf_hex_to_int( topic_1 @@ -92,28 +144,21 @@ stake_everest AS ( CONCAT('0x', SUBSTR(topic_2, 27, 40)) AS owner_address, CONCAT('0x', SUBSTR(topic_3, 27, 40)) AS multisig_address, NULL AS epoch, + NULL AS reward_unadj, + NULL AS available_rewards_unadj, + NULL AS ts_start, ARRAY_CONSTRUCT( TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [0] :: STRING)), TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [1] :: STRING)) ) AS nonces, - 'Everest' AS program_name, + program_name, _log_id, _inserted_timestamp FROM - {{ ref('silver__logs') }} + all_evt WHERE contract_address = '0x5add592ce0a1b5dcecebb5dcac086cd9f9e3ea5c' --ServiceStakingTokenMechUsage (Everest) AND topic_0 = '0x5d43ac9b1b213902df90d405b0006308578486b6c62182c5df202ed572c844e4' --ServiceStaked - AND tx_status = 'SUCCESS' - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -{% endif %} ), unstake AS ( SELECT @@ -125,13 +170,8 @@ unstake AS ( origin_to_address, contract_address, event_index, - topics [0] :: STRING AS topic_0, - topics [1] :: STRING AS topic_1, - topics [2] :: STRING AS topic_2, - topics [3] :: STRING AS topic_3, 'ServiceUnstaked' AS event_name, - DATA, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, + segmented_data, TRY_TO_NUMBER( utils.udf_hex_to_int( topic_1 @@ -144,21 +184,18 @@ unstake AS ( ) AS epoch, utils.udf_hex_to_int( segmented_data [2] :: STRING - ) AS reward, + ) AS reward_unadj, + NULL AS available_rewards_unadj, NULL AS ts_start, ARRAY_CONSTRUCT( TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)), TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [5] :: STRING)) ) AS nonces, - CASE - WHEN contract_address = '0xee9f19b5df06c7e8bfc7b28745dcf944c504198a' THEN 'Alpha' - WHEN contract_address = '0x43fb32f25dce34eb76c78c7a42c8f40f84bcd237' THEN 'Coastal' - WHEN contract_address = '0x2ef503950be67a98746f484da0bbada339df3326' THEN 'Alpine' - END AS program_name, + program_name, _log_id, _inserted_timestamp FROM - {{ ref('silver__logs') }} + all_evt WHERE contract_address IN ( '0xee9f19b5df06c7e8bfc7b28745dcf944c504198a', @@ -168,16 +205,6 @@ unstake AS ( '0x2ef503950be67a98746f484da0bbada339df3326' --ServiceStakingTokenMechUsage (Alpine) ) AND topic_0 = '0x950733f4c0bf951b8e770f3cc619a4288e7b59b1236d59aeaf2c238488e8ae81' --ServiceUnstaked - AND tx_status = 'SUCCESS' - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -{% endif %} ), unstake_everest AS ( SELECT @@ -189,13 +216,8 @@ unstake_everest AS ( origin_to_address, contract_address, event_index, - topics [0] :: STRING AS topic_0, - topics [1] :: STRING AS topic_1, - topics [2] :: STRING AS topic_2, - topics [3] :: STRING AS topic_3, 'ServiceUnstaked' AS event_name, - DATA, - regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data, + segmented_data, TRY_TO_NUMBER( utils.udf_hex_to_int( topic_1 @@ -206,7 +228,8 @@ unstake_everest AS ( NULL AS epoch, utils.udf_hex_to_int( segmented_data [1] :: STRING - ) AS reward, + ) AS reward_unadj, + NULL AS available_rewards_unadj, utils.udf_hex_to_int( segmented_data [2] :: STRING ) AS ts_start, @@ -214,109 +237,88 @@ unstake_everest AS ( TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [4] :: STRING)), TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [5] :: STRING)) ) AS nonces, - 'Everest' AS program_name, + program_name, _log_id, _inserted_timestamp FROM - {{ ref('silver__logs') }} + all_evt WHERE contract_address = '0x5add592ce0a1b5dcecebb5dcac086cd9f9e3ea5c' --ServiceStakingTokenMechUsage (Everest) AND topic_0 = '0x246ee6115bfd84e00097b16569c2ff2f822026bb9595a82cd2c1e69d4b6ea50c' --ServiceUnstaked - AND tx_status = 'SUCCESS' - -{% if is_incremental() %} -AND _inserted_timestamp >= ( - SELECT - MAX(_inserted_timestamp) - INTERVAL '12 hours' - FROM - {{ this }} -) -{% endif %} ), -all_evt AS ( +unstake_beta AS ( SELECT block_number, block_timestamp, tx_hash, - event_index, origin_function_signature, origin_from_address, origin_to_address, contract_address, - event_name, - service_id, - owner_address, - multisig_address, - epoch, - nonces, + event_index, + 'ServiceUnstaked' AS event_name, + segmented_data, + TRY_TO_NUMBER( + utils.udf_hex_to_int( + topic_1 + ) + ) AS service_id, + CONCAT('0x', SUBSTR(topic_2, 27, 40)) AS owner_address, + CONCAT('0x', SUBSTR(topic_3, 27, 40)) AS multisig_address, + utils.udf_hex_to_int( + segmented_data [0] :: STRING + ) AS epoch, + utils.udf_hex_to_int( + segmented_data [2] :: STRING + ) AS reward_unadj, + utils.udf_hex_to_int( + segmented_data [3] :: STRING + ) AS available_rewards_unadj, + NULL AS ts_start, + ARRAY_CONSTRUCT( + TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [5] :: STRING)), + TRY_TO_NUMBER(utils.udf_hex_to_int(segmented_data [6] :: STRING)) + ) AS nonces, program_name, _log_id, _inserted_timestamp + FROM + all_evt + WHERE + contract_address IN ( + '0x5344b7dd311e5d3dddd46a4f71481bd7b05aaa3e', + --Quickstart Beta - Expert + '0x389b46c259631acd6a69bde8b6cee218230bae8c', + --Quickstart Beta - Hobbyist + '0xef44fb0842ddef59d37f85d61a1ef492bba6135d' --Pearl Beta + ) + AND topic_0 = '0x6d789d063e079a4c156e77a20008529fc448dca2cd7e5e7a20abf969fffb9226' --ServiceUnstaked +), +union_evt AS ( + SELECT + * FROM stake UNION ALL SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - service_id, - owner_address, - multisig_address, - epoch, - nonces, - program_name, - _log_id, - _inserted_timestamp + * FROM stake_everest UNION ALL SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - service_id, - owner_address, - multisig_address, - epoch, - nonces, - program_name, - _log_id, - _inserted_timestamp + * FROM unstake UNION ALL SELECT - block_number, - block_timestamp, - tx_hash, - event_index, - origin_function_signature, - origin_from_address, - origin_to_address, - contract_address, - event_name, - service_id, - owner_address, - multisig_address, - epoch, - nonces, - program_name, - _log_id, - _inserted_timestamp + * FROM unstake_everest + UNION ALL + SELECT + * + FROM + unstake_beta ) SELECT block_number, @@ -328,10 +330,16 @@ SELECT origin_to_address, contract_address, event_name, + segmented_data, service_id, owner_address, multisig_address, epoch, + reward_unadj, + (reward_unadj / pow(10, 18)) :: FLOAT AS reward_adj, + available_rewards_unadj, + (available_rewards_unadj / pow(10, 18)) :: FLOAT AS available_rewards_adj, + ts_start, nonces, program_name, _log_id, @@ -343,4 +351,4 @@ SELECT SYSDATE() AS modified_timestamp, '{{ invocation_id }}' AS _invocation_id FROM - all_evt + union_evt diff --git a/models/silver/protocols/olas/silver_olas__services_evicted.sql b/models/silver/protocols/olas/silver_olas__services_evicted.sql index d92fec03..6696b6d1 100644 --- a/models/silver/protocols/olas/silver_olas__services_evicted.sql +++ b/models/silver/protocols/olas/silver_olas__services_evicted.sql @@ -35,6 +35,9 @@ WITH decoded_evt AS ( WHEN contract_address = '0xee9f19b5df06c7e8bfc7b28745dcf944c504198a' THEN 'Alpha' WHEN contract_address = '0x43fb32f25dce34eb76c78c7a42c8f40f84bcd237' THEN 'Coastal' WHEN contract_address = '0x2ef503950be67a98746f484da0bbada339df3326' THEN 'Alpine' + WHEN contract_address = '0x5344b7dd311e5d3dddd46a4f71481bd7b05aaa3e' THEN 'Quickstart Beta - Expert' + WHEN contract_address = '0x389b46c259631acd6a69bde8b6cee218230bae8c' THEN 'Quickstart Beta - Hobbyist' + WHEN contract_address = '0xef44fb0842ddef59d37f85d61a1ef492bba6135d' THEN 'Pearl Beta' END AS program_name, _log_id, _inserted_timestamp @@ -43,10 +46,16 @@ WITH decoded_evt AS ( WHERE contract_address IN ( '0xee9f19b5df06c7e8bfc7b28745dcf944c504198a', - -- StakingProxy (Alpha) + --StakingProxy (Alpha) '0x43fb32f25dce34eb76c78c7a42c8f40f84bcd237', --ServiceStakingTokenMechUsage (Coastal) - '0x2ef503950be67a98746f484da0bbada339df3326' --ServiceStakingTokenMechUsage (Alpine) + '0x2ef503950be67a98746f484da0bbada339df3326', + --ServiceStakingTokenMechUsage (Alpine) + '0x5344b7dd311e5d3dddd46a4f71481bd7b05aaa3e', + --Quickstart Beta - Expert + '0x389b46c259631acd6a69bde8b6cee218230bae8c', + --Quickstart Beta - Hobbyist + '0xef44fb0842ddef59d37f85d61a1ef492bba6135d' --Pearl Beta ) AND topic_0 = '0xd19a3d42ed383465e4058c322d9411aeac76ddb8454d22e139fc99808bd56952' --ServicesEvicted AND tx_status = 'SUCCESS'