diff --git a/README.md b/README.md index dca43ef..a297482 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,29 @@ dbt run-operation create_udfs --var 'UPDATE_UDFS_AND_SPS": True' --args 'drop_:f dbt run-operation create_udfs --var 'UPDATE_UDFS_AND_SPS": True' --args 'drop_:true' ``` +## Adding Release Versions + +1. Make the necessary changes to your code in your dbt package repository (e.g., fsc-utils). +2. Commit your changes with `git add .` and `git commit -m "Your commit message"`. +3. Tag your commit with a version number using `git tag -a v1.1.0 -m "version 1.1.0"`. +4. Push your commits to the remote repository with `git push origin ...`. +5. Push your tags to the remote repository with `git push origin --tags`. +6. In the packages.yml file of your other dbt project, specify the new version of the package with: +``` +packages: + - git: "https://github.com/FlipsideCrypto/fsc-utils.git" + revision: "v1.1.0" +``` +7. Run dbt deps in the other dbt project to pull the specific version of the package or follow the steps on `adding the dbt package` below. + +Regarding Semantic Versioning; +1. Semantic versioning is a versioning scheme for software that aims to convey meaning about the underlying changes with each new release. +2. It's typically formatted as MAJOR.MINOR.PATCH (e.g. v1.2.3), where: +- MAJOR version (first number) should increment when there are potential breaking or incompatible changes. +- MINOR version (second number) should increment when functionality or features are added in a backwards-compatible manner. +- PATCH version (third number) should increment when bug fixes are made without adding new features. +3. Semantic versioning helps package users understand the degree of changes in a new release, and decide when to adopt new versions. With dbt packages, when you tag a release with a semantic version, users can specify the exact version they want to use in their projects. + ## Adding the `fsc_utils` dbt package The `fsc_utils` dbt package is a centralized repository consisting of various dbt macros and snowflake functions that can be utilized across other repos. diff --git a/macros/streamline/configs.yaml.sql b/macros/streamline/configs.yaml.sql index 01c9eb5..0f82e7d 100644 --- a/macros/streamline/configs.yaml.sql +++ b/macros/streamline/configs.yaml.sql @@ -95,6 +95,28 @@ sql: | {{ fsc_utils.sql_udf_json_rpc_call(False) }} +- name: {{ schema }}.udf_evm_text_signature + signature: + - [abi, VARIANT] + return_type: TEXT + options: | + LANGUAGE PYTHON + RUNTIME_VERSION = '3.8' + HANDLER = 'get_simplified_signature' + sql: | + {{ fsc_utils.create_udf_evm_text_signature() | indent(4) }} + +- name: {{ schema }}.udf_keccak256 + signature: + - [event_name, VARCHAR(255)] + return_type: TEXT + options: | + LANGUAGE PYTHON + RUNTIME_VERSION = '3.8' + PACKAGES = ('pycryptodome==3.15.0') + HANDLER = 'udf_encode' + sql: | + {{ fsc_utils.create_udf_keccak256() | indent(4) }} {% endmacro %} diff --git a/macros/streamline/functions.py.sql b/macros/streamline/functions.py.sql index 7f3acbc..b095f3a 100644 --- a/macros/streamline/functions.py.sql +++ b/macros/streamline/functions.py.sql @@ -39,4 +39,38 @@ def hex_to_int(encoding, hex) -> str: return str(value) else: return str(int(hex, 16)) +{% endmacro %} + +{% macro create_udf_keccak256() %} +from Crypto.Hash import keccak + +def udf_encode(event_name): + keccak_hash = keccak.new(digest_bits=256) + keccak_hash.update(event_name.encode('utf-8')) + return '0x' + keccak_hash.hexdigest() +{% endmacro %} + +{% macro create_udf_evm_text_signature() %} + +def get_simplified_signature(abi): + def generate_signature(inputs): + signature_parts = [] + for input_data in inputs: + if 'components' in input_data: + component_signature_parts = [] + components = input_data['components'] + component_signature_parts.extend(generate_signature(components)) + component_signature_parts[-1] = component_signature_parts[-1].rstrip(",") + if input_data['type'].endswith('[]'): + signature_parts.append("(" + "".join(component_signature_parts) + ")[],") + else: + signature_parts.append("(" + "".join(component_signature_parts) + "),") + else: + signature_parts.append(input_data['type'].replace('enum ', '').replace(' payable', '') + ",") + return signature_parts + + signature_parts = [abi['name'] + "("] + signature_parts.extend(generate_signature(abi['inputs'])) + signature_parts[-1] = signature_parts[-1].rstrip(",") + ")" + return "".join(signature_parts) {% endmacro %} \ No newline at end of file