Skip to content

Conversation

@outsider-analytics
Copy link

@outsider-analytics outsider-analytics commented Apr 20, 2023

These were modified to allow for integration with the decode_projects.sql file the dbt project decoding contracts.
Please feel free to rebuke any and all aspects of files or this pull request, as I am truly a rookie :)

This function takes a dune_name and abi string and returns an array of each function in the abi.  I use it within a decode contracts dbt model which creates a the information needed to create decoded views of contracts for dune compatibility.
Differences are:
1. Adds the dune name
2. Maps the ABI types to BQ types
3. If there is no name for the inputs or outputs, the name is "input_number" or "output_number"
This function takes a dune_name and abi string and returns an array of each event in the abi.  I use it within a decode contracts dbt model which creates a the information needed to create decoded views of contracts for dune compatibility.
Differences are:
1. Adds the dune name
2. Maps the ABI types to BQ types
3. If there is no name for the inputs, the name is "input_number"
"uint16[]": "INT64",
"uint8[]": "INT64",
"uint64[]": "INT64",
"uint128[]": "INT64",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above int64 please use string to avoid precision loss

"uint16[]": "INT64",
"uint8[]": "INT64",
"uint64[]": "INT64",
"uint128[]": "INT64",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above int64 please use string to avoid precision loss

@@ -0,0 +1,81 @@
CREATE OR REPLACE FUNCTION `blocktrekker.udfs.PARSE_ABI_EVENTS`(abi STRING, dune_name STRING) RETURNS ARRAY<STRUCT<name STRING, anonymous BOOL, hash_id STRING, inputs STRING, types STRING>> LANGUAGE js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factor out blocktrekker.udfs

to $UDF_PROJECT.$UDF_DATASET

using DECLARE.

Rename dune_name to contract_prefix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge this file with the base file from which it is cloned


abi.forEach(function(x){
tuple = [];
tuple['name'] = dune_name + "_evt_" + x.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guard against dune_name is null with a default value

if (y.type in typeMap) {
pair.type = typeMap[y.type];
} else {
if (y.type.slice(0, 4).toLowerCase() === "uint") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to throw an error on unknown types

if (y.type.slice(0, 4).toLowerCase() === "uint") {
pair.type = "BIGNUMERIC";
} else {
pair.type = "STRING";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise. Throw.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge into base file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants