-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* event and registration tables * add columns, adjust signers * cast as string
- Loading branch information
1 parent
2bb7776
commit 2b4f8e1
Showing
4 changed files
with
295 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
-- depends_on: {{ ref('silver__decoded_instructions_combined') }} | ||
{{ config( | ||
materialized = 'incremental', | ||
unique_key = ['service_event_logs_id'], | ||
incremental_predicates = ["dynamic_range_predicate", "block_timestamp::date"], | ||
merge_exclude_columns = ["inserted_timestamp"], | ||
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'], | ||
tags = ['scheduled_non_core'] | ||
) }} | ||
|
||
{% if execute %} | ||
{% set base_query %} | ||
CREATE | ||
OR REPLACE temporary TABLE silver.service_event_logs__intermediate_tmp AS | ||
|
||
SELECT | ||
* | ||
FROM | ||
{{ ref('silver__decoded_instructions_combined') }} | ||
WHERE | ||
program_id = 'SMPLecH534NA9acpos4G6x7uf3LWbCAwZQE9e8ZekMu' | ||
|
||
{% if is_incremental() %} | ||
AND _inserted_timestamp >= ( | ||
SELECT | ||
MAX(_inserted_timestamp) - INTERVAL '1 hour' | ||
FROM | ||
{{ this }} | ||
) | ||
{% else %} | ||
AND _inserted_timestamp :: DATE >= '2024-06-21' | ||
AND block_timestamp :: DATE >= '2023-07-07' | ||
{% endif %} | ||
|
||
{% endset %} | ||
{% do run_query(base_query) %} | ||
{% set between_stmts = fsc_utils.dynamic_range_predicate( | ||
"silver.service_event_logs__intermediate_tmp", | ||
"block_timestamp::date" | ||
) %} | ||
{% endif %} | ||
|
||
WITH base AS ( | ||
SELECT | ||
* | ||
FROM | ||
silver.service_event_logs__intermediate_tmp | ||
), | ||
multisigs AS ( | ||
SELECT | ||
multisig_address | ||
FROM | ||
{{ ref('silver_olas__service_registrations') }} | ||
), | ||
olas_decoded AS ( | ||
SELECT | ||
block_timestamp, | ||
block_id, | ||
tx_id, | ||
INDEX, | ||
inner_index, | ||
signers, | ||
succeeded, | ||
program_id, | ||
silver.udf_get_account_pubkey_by_name( | ||
'multisig', | ||
decoded_instruction :accounts | ||
) AS multisig_address, | ||
event_type, | ||
_inserted_timestamp | ||
FROM | ||
base | ||
WHERE | ||
multisig_address IN ( | ||
SELECT | ||
multisig_address | ||
FROM | ||
multisigs | ||
) | ||
), | ||
base_events AS ( | ||
SELECT | ||
A.* | ||
FROM | ||
{{ ref('silver__events') }} A | ||
INNER JOIN ( | ||
SELECT | ||
DISTINCT tx_id, | ||
block_timestamp :: DATE AS block_date | ||
FROM | ||
olas_decoded | ||
) d | ||
ON d.block_date = A.block_timestamp :: DATE | ||
AND d.tx_id = A.tx_id | ||
WHERE | ||
program_id = 'SMPLecH534NA9acpos4G6x7uf3LWbCAwZQE9e8ZekMu' | ||
AND {{ between_stmts }} | ||
) | ||
SELECT | ||
A.block_timestamp, | ||
A.block_id, | ||
A.tx_id, | ||
A.index, | ||
A.inner_index, | ||
A.signers [0] :: STRING AS signer, | ||
A.succeeded, | ||
A.program_id, | ||
A.multisig_address, | ||
A.event_type, | ||
c.service_id, | ||
-- b.instruction, | ||
-- b.inner_instruction, | ||
b.instruction :data :: STRING AS DATA, | ||
A._inserted_timestamp, | ||
{{ dbt_utils.generate_surrogate_key(['a.tx_id','a.index','a.inner_index']) }} AS service_event_logs_id, | ||
SYSDATE() AS inserted_timestamp, | ||
SYSDATE() AS modified_timestamp, | ||
'{{ invocation_id }}' AS invocation_id | ||
FROM | ||
olas_decoded A | ||
LEFT JOIN base_events b | ||
ON A.tx_id = b.tx_id | ||
AND A.index = b.index | ||
LEFT JOIN {{ ref('silver_olas__service_registrations') }} c | ||
ON a.multisig_address = c.multisig_address |
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,22 @@ | ||
version: 2 | ||
models: | ||
- name: silver_olas__service_event_logs | ||
tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- TX_ID | ||
- INDEX | ||
- INNER_INDEX | ||
columns: | ||
- name: BLOCK_ID | ||
tests: | ||
- not_null | ||
- name: BLOCK_TIMESTAMP | ||
tests: | ||
- not_null | ||
- name: TX_ID | ||
tests: | ||
- not_null | ||
- name: MULTISIG_ADDRESS | ||
tests: | ||
- not_null |
121 changes: 121 additions & 0 deletions
121
models/silver/olas/silver_olas__service_registrations.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,121 @@ | ||
-- depends_on: {{ ref('silver__decoded_instructions_combined') }} | ||
{{ config( | ||
materialized = 'incremental', | ||
unique_key = ['service_registrations_id'], | ||
incremental_predicates = ["dynamic_range_predicate", "block_timestamp::date"], | ||
merge_exclude_columns = ["inserted_timestamp"], | ||
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'], | ||
tags = ['scheduled_non_core'] | ||
) }} | ||
|
||
{% if execute %} | ||
{% set base_query %} | ||
CREATE | ||
OR REPLACE temporary TABLE silver.service_registrations__intermediate_tmp AS | ||
|
||
SELECT | ||
* | ||
FROM | ||
{{ ref('silver__decoded_instructions_combined') }} | ||
WHERE | ||
program_id = 'AU428Z7KbjRMjhmqWmQwUta2AvydbpfEZNBh8dStHTDi' | ||
|
||
{% if is_incremental() %} | ||
AND _inserted_timestamp >= ( | ||
SELECT | ||
MAX(_inserted_timestamp) - INTERVAL '1 hour' | ||
FROM | ||
{{ this }} | ||
) | ||
{% else %} | ||
AND _inserted_timestamp :: DATE >= '2024-06-21' | ||
{% endif %} | ||
|
||
{% endset %} | ||
{% do run_query(base_query) %} | ||
{% set between_stmts = fsc_utils.dynamic_range_predicate( | ||
"silver.service_registrations__intermediate_tmp", | ||
"block_timestamp::date" | ||
) %} | ||
{% endif %} | ||
|
||
WITH base AS ( | ||
SELECT | ||
* | ||
FROM | ||
silver.service_registrations__intermediate_tmp | ||
), | ||
create_events AS ( | ||
SELECT | ||
block_timestamp, | ||
block_id, | ||
tx_id, | ||
INDEX, | ||
signers[0]::string as signers, | ||
succeeded, | ||
program_id, | ||
event_type, | ||
decoded_instruction :args :agentids AS agent_ids_dict, | ||
decoded_instruction :args :serviceowner :: STRING AS owner_address, | ||
_inserted_timestamp | ||
FROM | ||
base | ||
WHERE | ||
event_type = 'create' | ||
), | ||
agent_ids AS ( | ||
SELECT | ||
tx_id, | ||
ARRAY_AGG( | ||
VALUE :: STRING | ||
) AS agent_ids | ||
FROM | ||
create_events, | ||
LATERAL FLATTEN( | ||
input => agent_ids_dict | ||
) | ||
GROUP BY | ||
tx_id | ||
), | ||
deploy_events AS ( | ||
SELECT | ||
block_timestamp, | ||
block_id, | ||
tx_id, | ||
INDEX, | ||
signers, | ||
succeeded, | ||
program_id, | ||
decoded_instruction :args :multisig :: STRING AS multisig_address, | ||
decoded_instruction :args :serviceid :: INT AS service_id, | ||
decoded_instruction :accounts[1]:pubkey :: STRING AS owner_address, | ||
_inserted_timestamp | ||
FROM | ||
base | ||
WHERE | ||
event_type = 'deploy' | ||
) | ||
SELECT | ||
A.block_timestamp, | ||
A.block_id, | ||
A.tx_id, | ||
A.index, | ||
A.signers, | ||
A.succeeded, | ||
A.program_id, | ||
A.owner_address, | ||
a.event_type, | ||
b.agent_ids, | ||
C.multisig_address, | ||
C.service_id, | ||
A._inserted_timestamp, | ||
{{ dbt_utils.generate_surrogate_key(['a.tx_id','a.index']) }} AS service_registrations_id, | ||
SYSDATE() AS inserted_timestamp, | ||
SYSDATE() AS modified_timestamp, | ||
'{{ invocation_id }}' AS invocation_id | ||
FROM | ||
create_events A | ||
LEFT JOIN agent_ids b | ||
ON A.tx_id = b.tx_id | ||
LEFT JOIN deploy_events C | ||
ON A.owner_address = C.owner_address |
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,27 @@ | ||
version: 2 | ||
models: | ||
- name: silver_olas__service_registrations | ||
tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- TX_ID | ||
- INDEX | ||
columns: | ||
- name: BLOCK_ID | ||
tests: | ||
- not_null | ||
- name: BLOCK_TIMESTAMP | ||
tests: | ||
- not_null | ||
- name: TX_ID | ||
tests: | ||
- not_null | ||
- name: OWNER_ADDRESS | ||
tests: | ||
- not_null | ||
- name: MULTISIG_ADDRESS | ||
tests: | ||
- not_null | ||
- name: SERVICE_ID | ||
tests: | ||
- not_null |