Stream 318/an 3432/stream 324/evm highl level abstractions (#24)

* - create place holder configs for high level evm abstractions

* - rename udf_config

* - fixed macro bug

* - add generic rpc_call

* - add generic evm rpc udf

* - add generic evm rpc udf

* - more DRY primitives

* WIP

* - add example udft

* - readme.MD

* - updated comments on evm primitives

* - add model to store signatures for UI

* evm abstractions

* use schema

* Squashed commit of the following:

commit df57d3309394d13407d5f4f7a1c27ab4e51ccb4e
Author: Julius Remigio <14811322+juls858@users.noreply.github.com>
Date:   Thu Jun 15 12:31:00 2023 -0700

     - remove unneeded model

* - refactor pimitives to use schema with network name

* schema fix and polygon

* - added udf_rpc to live schema
- prefixed primitives with udf_

* use crosschain table

* use sources for crosschain

* support all chains

* add network

* updated comments

* all chains

* remove map

* reorg

* remove optimism from map

* Update utils.sql

Return null instead of empty json object

* add error column

* Revert "add error column"

This reverts commit 49bc7239a43afaa9974abc2ab9408310c0757aa1.

* Revert "Update utils.sql"

This reverts commit 1edbeef5eebea6a5bffe3fc599afd2289864b359.

* Update utils.sql

Return null instead of empty json object

* Revert "Update utils.sql"

This reverts commit e4c29b093235cf9a36ca34e1000d1ad1c1a7beb6.

---------

Co-authored-by: Julius Remigio <14811322+juls858@users.noreply.github.com>
This commit is contained in:
Austin 2023-06-27 11:55:30 -07:00 committed by GitHub
parent 8add7be491
commit 040b3fdf9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1937 additions and 70 deletions

View File

@ -51,7 +51,7 @@
# Live Functions
## Limits and Best Practices
- The `udf_api` function is very powerful, but it is also very easy to abuse. Please be mindful of the following limits and best practices when using this function.
- The `udf_api` function is very powerful, but it is also very easy to abuse. Please be mindful of the following limits and best practices when using this function.
- We reserve the right to disable the `udf_api` function for particular users, or as a whole, if we see it being abused.
- Most APIs have rate limits. Please be mindful of these limits and do not abuse them.
- Most of the limits you will encounter using this function will be on the API side. Please be sure to thoroughly read an API's documentation before using it.
@ -60,12 +60,12 @@
- API request (per row) response size limit: 6MB
- API request timeout (per row) limit: 30 seconds
- Data app query timeout limit: 15 minutes
- Batching is supported for JSON RPC requests.
- Batching is supported for JSON RPC requests.
- Again, this is very easy to abuse. Be mindful of the API's rate limits when using this functionality.
- It is strongly recommended that you start small and test your queries before requesting large amounts of data.
- Response data is not cached.
- Response data is not cached.
- This means that if you run the same query twice, that API will be called twice. A future enhancement may address this need, but for now, please be mindful of this limitation.
- Many APIs require authentication.
- Many APIs require authentication.
- Please see the [secret registration section](#registering-secrets) below for more information on how to register secrets for use with the `udf_api` function.
- Technically, you can pass secrets into the `udf_api` function directly, but this is not recommended.
- If you do pass your secrets without following the steps in the [secret registration section](#registering-secrets), your secrets will be visible in Flipside's internal query history.
@ -100,7 +100,7 @@ livequery.live.udf_api(
### Approved APIs
| API Name | API Docs | Authentication Required |
| --------------------- | -------------------------------------------------------------------------------------- | ----------------------- |
| QuickNode | [Docs](https://www.quicknode.com/docs) | Yes |
@ -220,7 +220,7 @@ SELECT
}
) as response
)
select
select
value:id::string as address,
value:name::string as name,
value:totalLiquidity::int as totalLiquidity
@ -265,7 +265,7 @@ FROM
```sql
-- you can use this function to retrieve data from IPFS. You can find the hash in the URL within several places onchain, including evm logs and traces.
SELECT
SELECT
livequery.live.udf_api('https://ipfs.io/ipfs/QmTFX3TopS8JsgpfBLKGDnTiaWrRcfStDWDQaREzD36sWW') AS response;
```
</details>
@ -276,7 +276,7 @@ FROM
Utility functions are designed to make your life easier when interacting with blockchain data.
## udf_hex_to_int
This function converts a hex string to an integer.
This function converts a hex string to an integer.
### Syntax
```sql
@ -317,7 +317,7 @@ livequery.utils.udf_hex_to_int(
---
## udf_hex_to_string
## udf_hex_to_string
This function converts a hex string to a string of human readable characters. It will handle obscure characters like emojis and special characters.
@ -336,7 +336,7 @@ livequery.utils.udf_hex_to_string(
<summary>Convert Hex to Text</summary>
```sql
select
select
livequery.utils.udf_hex_to_string('466C69707369646520726F636B73') as text1
```
</details>
@ -411,7 +411,7 @@ To register a secret, follow these steps:
1. Visit [Ephit](https://science.flipsidecrypto.xyz/ephit) to obtain an Ephemeral query that will securely link your API Endpoint to Flipside's backend. This will allow you to refer to the URL securely in our application without referencing it or exposing keys directly.
2. Fill out the form and click ***Submit this Credential***
3. Paste the provided query into [Flipside](https://flipside.new) and query your node directly in the app with your submitted Credential (`{my_key}`)
Registering a secret from Quicknode to query nodes directly in Flipside:
1. Sign up for a free [Quicknode API Account](https://www.quicknode.com/core-api)
@ -469,7 +469,7 @@ When False, none of the on-run-start macros are executed on model run
Default values are False
* Usage:
dbt run --var '{"UPDATE_UDFS_AND_SPS":True}' -m ...
`dbt run --var '{"UPDATE_UDFS_AND_SPS":True}' -m ...`
Dropping and creating udfs can also be done without running a model:

View File

@ -1,4 +1,4 @@
{%- set udfs = fromyaml(udf_configs()) -%}
{%- set udfs = fromyaml(config_core_udfs()) -%}
{%- for udf in udfs -%}
{{- create_or_drop_function_from_config(udf, drop_=True) -}}
{{- create_or_drop_function_from_config(udf, drop_=False) -}}

View File

@ -1 +1,3 @@
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "ethereum", None, drop_) -}}
{{crud_udfs_in_schema(config_evm_high_level_abstractions, 'ethereum', 'mainnet', false)}}
{# {{- crud_udfs_in_schema(config_evm_rpc_primitives, "ethereum", None, False) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "ethereum", None, true) -}} #}

View File

@ -7,12 +7,57 @@
CREATE SCHEMA IF NOT EXISTS _utils;
CREATE SCHEMA IF NOT EXISTS _live;
CREATE SCHEMA IF NOT EXISTS live;
{%- set udfs = fromyaml(udf_configs()) -%}
{%- set udfs = fromyaml(config_core_udfs()) -%}
{%- for udf in udfs -%}
{{- create_or_drop_function_from_config(udf, drop_=drop_) -}}
{% endfor %}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "ethereum", None, drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "arbitrum_nova", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "arbitrum_one", "goerli", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "arbitrum_one", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "avalanche_c", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "avalanche_c", "testnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "base", "goerli", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "bsc", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "bsc", "testnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "celo", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "ethereum", "goerli", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "ethereum", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "ethereum", "sepolia", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "fantom", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "gnosis", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "harmony", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "harmony", "testnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "optimism", "goerli", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "optimism", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "polygon", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "polygon", "testnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "polygon_zkevm", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_rpc_primitives, "polygon_zkevm", "testnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "arbitrum_nova", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "arbitrum_one", "goerli", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "arbitrum_one", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "avalanche_c", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "avalanche_c", "testnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "base", "goerli", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "bsc", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "bsc", "testnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "celo", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "ethereum", "goerli", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "ethereum", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "ethereum", "sepolia", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "fantom", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "gnosis", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "harmony", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "harmony", "testnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "optimism", "goerli", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "optimism", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "polygon", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "polygon", "testnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "polygon_zkevm", "mainnet", drop_) -}}
{{- crud_udfs_in_schema(config_evm_high_level_abstractions, "polygon_zkevm", "testnet", drop_) -}}
{% endset %}
{% do run_query(sql) %}
{% endif %}

View File

@ -1,4 +1,4 @@
{% macro udf_configs() %}
{% macro config_core_udfs() %}
{#
UTILITY SCHEMA
@ -329,5 +329,20 @@
secret_name
)
- name: live.udf_rpc
signature:
- [blockchain, STRING]
- [network, STRING]
- [method, STRING]
- [parameters, VARIANT]
return_type: VARIANT
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Executes an JSON RPC call on a blockchain.$$
sql: |
{{ sql_live_rpc_call("method", "parameters", "blockchain", "network") | indent(4) -}}
{% endmacro %}

View File

@ -0,0 +1,365 @@
{% macro config_evm_high_level_abstractions(blockchain, network) -%}
{#
This macro is used to generate the high level abstractions for an EVM
blockchain.
#}
{% set schema = blockchain ~ "_" ~ network %}
- name: {{ schema -}}.latest_native_balance
signature:
- [wallet, STRING, The address to get the balance of at the latest block]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, symbol STRING, raw_balance STRING, balance FLOAT)"
- |
The table has the following columns:
* `blockchain` - The blockchain
* `network` - The network
* `wallet_address` - The wallet address
* `symbol` - The symbol of the native asset
* `raw_balance` - The unadjusted native asset balance
* `balance` - The adjusted native asset balance
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the native asset balance at the latest block for a given address.$$
sql: |
{{ evm_latest_native_balance_string(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_native_balance
signature:
- [wallets, ARRAY, An array of addresses string to get the balance of at the latest block]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, symbol STRING, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the native asset balances at the latest block for given addresses.$$
sql: |
{{ evm_latest_native_balance_array(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_token_balance
signature:
- [wallet, STRING, The address to get the balance of at the latest block]
- [token, STRING, The address of the token to get the balance of]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, token_address STRING, symbol STRING, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the token balance at the latest block for a given address and token address. Supports ERC20 and ERC721 tokens.$$
sql: |
{{ evm_latest_token_balance_ss(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_token_balance
signature:
- [wallet, STRING, The address to get the balance of at the latest block]
- [tokens, ARRAY, An array of address strings of the tokens to get the balance of]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, token_address STRING, symbol STRING, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the token balances at the latest block for a given address and multiple token addresses. Supports ERC20 and ERC721 tokens.$$
sql: |
{{ evm_latest_token_balance_sa(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_token_balance
signature:
- [wallets, ARRAY, An array of addresses string to get the balance of at the latest block]
- [token, STRING, The address of the token to get the balance of]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, token_address STRING, symbol STRING, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the token balances at the latest block for multiple addresses and a single token address. Supports ERC20 and ERC721 tokens.$$
sql: |
{{ evm_latest_token_balance_as(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_token_balance
signature:
- [wallets, ARRAY, An array of addresses string to get the balance of at the latest block]
- [tokens, ARRAY, An array of address strings of the tokens to get the balance of]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, token_address STRING, symbol STRING, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the token balances at the latest block for multiple addresses and multiple token addresses. Supports ERC20 and ERC721 tokens.$$
sql: |
{{ evm_latest_token_balance_aa(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.historical_token_balance
signature:
- [wallet, STRING, The address to get the balance of at the input block]
- [token, STRING, The address of the token to get the balance of]
- [block_number, INTEGER, The block number to get the balance at]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, token_address STRING, symbol STRING, block_number INTEGER, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the token balance for a given address and token address at a specific block. Supports ERC20 and ERC721 tokens.$$
sql: |
{{ evm_historical_token_balance_ssi(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.historical_token_balance
signature:
- [wallet, STRING, The address to get the balance of at the input block]
- [token, STRING, The address of the token to get the balance of]
- [block_numbers, ARRAY, The block numbers to get the balance at]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, token_address STRING, symbol STRING, block_number INTEGER, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the token balances for a given address and token address at multiple specific blocks. Supports ERC20 and ERC721 tokens.$$
sql: |
{{ evm_historical_token_balance_ssa(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.historical_token_balance
signature:
- [wallets, ARRAY, The addresses to get the balance of at the input block]
- [token, STRING, The address of the token to get the balance of]
- [block_number, INTEGER, The block number to get the balance at]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, token_address STRING, symbol STRING, block_number INTEGER, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the token balances for multiple addresses and a given token addresses at a specific block. Supports ERC20 and ERC721 tokens.$$
sql: |
{{ evm_historical_token_balance_asi(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.historical_token_balance
signature:
- [wallet, STRING, The address to get the balance of at the input block]
- [tokens, ARRAY, An array of address strings of the tokens to get the balance of]
- [block_number, INTEGER, The block number to get the balance at]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, token_address STRING, symbol STRING, block_number INTEGER, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the token balances for a given address and multiple token addresses at a specific block. Supports ERC20 and ERC721 tokens.$$
sql: |
{{ evm_historical_token_balance_sai(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.historical_token_balance
signature:
- [wallet, STRING, The address to get the balance of at the input block]
- [tokens, ARRAY, An array of address strings of the tokens to get the balance of]
- [block_numbers, ARRAY, The block numbers to get the balance at]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, token_address STRING, symbol STRING, block_number INTEGER, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the token balances for a given address and multiple token addresses at multiple specific blocks. Supports ERC20 and ERC721 tokens.$$
sql: |
{{ evm_historical_token_balance_saa(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.historical_token_balance
signature:
- [wallets, ARRAY, An array of address strings to get the balance of at the input block]
- [tokens, ARRAY, An array of address strings of the tokens to get the balance of]
- [block_number, INTEGER, The block number to get the balance at]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, token_address STRING, symbol STRING, block_number INTEGER, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the token balances for multiple addresses and multiple token addresses at a specific block. Supports ERC20 and ERC721 tokens.$$
sql: |
{{ evm_historical_token_balance_aai(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.historical_token_balance
signature:
- [wallets, ARRAY, An array of address strings to get the balance of at the input block]
- [tokens, ARRAY, An array of address strings of the tokens to get the balance of]
- [block_numbers, ARRAY, The block numbers to get the balance at]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, token_address STRING, symbol STRING, block_number INTEGER, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the token balances for multiple addresses and multiple token addresses at multiple specific blocks. Supports ERC20 and ERC721 tokens.$$
sql: |
{{ evm_historical_token_balance_aaa(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.historical_native_balance
signature:
- [wallet, STRING, The address to get the balance of at the input block]
- [block_number, INTEGER, The block number to get the balance at]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, symbol STRING, block_number INTEGER, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the native asset balance for a given address at a specific block.$$
sql: |
{{ evm_historical_native_balance_si(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.historical_native_balance
signature:
- [wallet, STRING, The address to get the balance of at the input block]
- [block_numbers, ARRAY, The block numbers to get the balance at]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, symbol STRING, block_number INTEGER, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the native asset balances for a given address at multiple specific blocks.$$
sql: |
{{ evm_historical_native_balance_sa(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.historical_native_balance
signature:
- [wallets, ARRAY, An array of address strings to get the balance of at the input block]
- [block_number, INTEGER, The block number to get the balance at]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, symbol STRING, block_number INTEGER, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the native asset balances for multiple addresses at a specific block.$$
sql: |
{{ evm_historical_native_balance_ai(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.historical_native_balance
signature:
- [wallets, ARRAY, An array of address strings to get the balance of at the input block]
- [block_numbers, ARRAY, The block numbers to get the balance at]
return_type:
- "TABLE(blockchain STRING, network STRING, wallet_address STRING, symbol STRING, block_number INTEGER, raw_balance STRING, balance FLOAT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the native asset balances for multiple addresses at multiple specific blocks.$$
sql: |
{{ evm_historical_native_balance_aa(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_contract_events
signature:
- [address, STRING, The address of the contract to get the events of]
return_type:
- "TABLE(blockchain STRING, network STRING, tx_hash STRING, block_number INTEGER, event_index INTEGER, contract_address STRING, event_topics ARRAY, event_data STRING)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the latest events emitted by a contract in the last 100 blocks.$$
sql: |
{{ evm_latest_contract_events_s(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_contract_events
signature:
- [address, STRING, The address of the contract to get the events of]
- [lookback, INTEGER, The number of blocks to look back. Please note there are RPC limitations on this method.]
return_type:
- "TABLE(blockchain STRING, network STRING, tx_hash STRING, block_number INTEGER, event_index INTEGER, contract_address STRING, event_topics ARRAY, event_data STRING)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the latest events emitted by a contract within the last `lookback` blocks. *Please note there are RPC limitations on this method.*$$
sql: |
{{ evm_latest_contract_events_si(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_contract_events
signature:
- [addresses, ARRAY, The addresses of the contracts to get the events of]
return_type:
- "TABLE(blockchain STRING, network STRING, tx_hash STRING, block_number INTEGER, event_index INTEGER, contract_address STRING, event_topics ARRAY, event_data STRING)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the latest events emitted by multiple contracts in the last 100 blocks.$$
sql: |
{{ evm_latest_contract_events_a(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_contract_events
signature:
- [addresses, ARRAY, The addresses of the contracts to get the events of]
- [lookback, INTEGER, The number of blocks to look back. Please note there are RPC limitations on this method.]
return_type:
- "TABLE(blockchain STRING, network STRING, tx_hash STRING, block_number INTEGER, event_index INTEGER, contract_address STRING, event_topics ARRAY, event_data STRING)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the latest events emitted by multiple contracts within the last `lookback` blocks. *Please note there are RPC limitations on this method.*$$
sql: |
{{ evm_latest_contract_events_ai(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_contract_events_decoded
signature:
- [address, STRING, The address of the contract to get the decoded events of]
return_type:
- "TABLE(blockchain STRING, network STRING, tx_hash STRING, block_number INTEGER, event_index INTEGER, event_name STRING, contract_address STRING, event_topics ARRAY, event_data STRING, decoded_data OBJECT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$RReturns the latest decoded events emitted by a contract in the last 100 blocks. Submit missing ABIs [here](https://science.flipsidecrypto.xyz/abi-requestor/).$$
sql: |
{{ evm_latest_contract_events_decoded_s(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_contract_events_decoded
signature:
- [addresses, ARRAY, The addresses of the contracts to get the decoded events of]
return_type:
- "TABLE(blockchain STRING, network STRING, tx_hash STRING, block_number INTEGER, event_index INTEGER, event_name STRING, contract_address STRING, event_topics ARRAY, event_data STRING, decoded_data OBJECT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the latest decoded events emitted by multiple contracts in the last 100 blocks. Submit missing ABIs [here](https://science.flipsidecrypto.xyz/abi-requestor/).$$
sql: |
{{ evm_latest_contract_events_decoded_a(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_contract_events_decoded
signature:
- [address, STRING, The address of the contract to get the decoded events of]
- [lookback, INTEGER, The number of blocks to look back. Please note there are RPC limitations on this method.]
return_type:
- "TABLE(blockchain STRING, network STRING, tx_hash STRING, block_number INTEGER, event_index INTEGER, event_name STRING, contract_address STRING, event_topics ARRAY, event_data STRING, decoded_data OBJECT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the latest decoded events emitted by a contract within the last `lookback` blocks. Submit missing ABIs [here](https://science.flipsidecrypto.xyz/abi-requestor/). *Please note there are RPC limitations on this method.*$$
sql: |
{{ evm_latest_contract_events_decoded_si(schema, blockchain, network) | indent(4) -}}
- name: {{ schema -}}.latest_contract_events_decoded
signature:
- [addresses, ARRAY, The addresses of the contracts to get the decoded events of]
- [lookback, INTEGER, The number of blocks to look back. Please note there are RPC limitations on this method.]
return_type:
- "TABLE(blockchain STRING, network STRING, tx_hash STRING, block_number INTEGER, event_index INTEGER, event_name STRING, contract_address STRING, event_topics ARRAY, event_data STRING, decoded_data OBJECT)"
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the latest decoded events emitted by multiple contracts within the last `lookback` blocks. Submit missing ABIs [here](https://science.flipsidecrypto.xyz/abi-requestor/). *Please note there are RPC limitations on this method.* $$
sql: |
{{ evm_latest_contract_events_decoded_ai(schema, blockchain, network) | indent(4) -}}
{%- endmacro -%}

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,29 @@
{%- macro config_evm_rpc_primitives(schema, blockchain) -%}
{%- macro config_evm_rpc_primitives(blockchain, network) -%}
{#-
Generates a set of UDFs that call the Ethereum JSON RPC API
- eth_call
- eth_getLogs
- eth_getBalance
- rpc: Executes an RPC call on the {{ blockchain }} blockchain
- eth_call: Executes a new message call immediately without creating a transaction on the block chain
- eth_getLogs: Returns an array of all logs matching filter with given address
- eth_getBalance: Returns the balance of the account of given address
-#}
- name: {{ schema -}}.rpc_eth_call
{% set schema = blockchain ~ "_" ~ network -%}
- name: {{ schema -}}.udf_rpc
signature:
- [method, STRING, RPC method to call]
- [parameters, VARIANT, Parameters to pass to the RPC method]
return_type: [VARIANT, The return value of the RPC method]
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Executes an RPC call on the {{ blockchain }} blockchain.$$
sql: |
SELECT live.udf_rpc('{{ blockchain }}', '{{ network }}', method, parameters)
- name: {{ schema -}}.udf_rpc_eth_call
signature:
- [transaction, OBJECT, The transaction object]
- [block_or_tag, STRING, The block number or tag to execute the call on]
@ -18,22 +34,9 @@
VOLATILE
COMMENT = $$Executes a new message call immediately without creating a transaction on the block chain.$$
sql: |
{{ sql_live_rpc_call('eth_call', "[transaction, block_or_tag]", blockchain, "'mainnet'") | indent(4) -}}
- name: {{ schema -}}.rpc_eth_call
signature:
- [transaction, OBJECT, The transaction object]
- [block_or_tag, STRING, The block number or tag to execute the call on]
- [network, STRING, The network to execute the call on]
return_type: [VARIANT, The return value of the executed contract code]
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Executes a new message call immediately without creating a transaction on the block chain.$$
sql: |
{{ sql_live_rpc_call('eth_call', '[transaction, block_or_tag]', blockchain, 'network') | indent(4) -}}
SELECT {{ schema -}}.udf_rpc('eth_call', [transaction, block_or_tag])
- name: {{ schema -}}.rpc_eth_get_logs
- name: {{ schema -}}.udf_rpc_eth_get_logs
signature:
- [filter, OBJECT, The filter object]
return_type: [VARIANT, An array of all logs matching filter with given address]
@ -43,21 +46,9 @@
VOLATILE
COMMENT = $$Returns an array of all logs matching filter with given address.$$
sql: |
{{ sql_live_rpc_call('eth_getLogs', '[filter]', blockchain, "'mainnet'") | indent(4) -}}
- name: {{ schema -}}.rpc_eth_get_logs
signature:
- [filter, OBJECT, The filter object]
- [network, STRING, The network to execute the call on]
return_type: [VARIANT, An array of all logs matching filter with given address]
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns an array of all logs matching filter with given address.$$
sql: |
{{ sql_live_rpc_call('eth_getLogs', '[filter]', blockchain, 'network') | indent(4) -}}
SELECT {{ schema -}}.udf_rpc('eth_getLogs', [filter])
- name: {{ schema -}}.rpc_eth_get_balance
- name: {{ schema -}}.udf_rpc_eth_get_balance
signature:
- [address, STRING, The address to get the balance of]
- [block_or_tag, STRING, The block number or tag to execute the call on]
@ -68,18 +59,6 @@
VOLATILE
COMMENT = $$Returns the balance of the account of given address.$$
sql: |
{{ sql_live_rpc_call('eth_getBalance', '[address, block_or_tag]', blockchain, "'mainnet'") | indent(4) -}}
- name: {{ schema -}}.rpc_eth_get_balance
signature:
- [address, STRING, The address to get the balance of]
- [block_or_tag, STRING, The block number or tag to execute the call on]
- [network, STRING, The network to execute the call on]
return_type: [VARIANT, The balance of the account of given address]
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
VOLATILE
COMMENT = $$Returns the balance of the account of given address.$$
sql: |
{{ sql_live_rpc_call('eth_getBalance', '[address, block_or_tag]', blockchain, 'network') | indent(4) -}}
{% endmacro -%}
SELECT {{ schema -}}.udf_rpc('eth_getBalance', [address, block_or_tag])
{%- endmacro -%}

View File

@ -14,11 +14,11 @@
SELECT
live.udf_api(
'{endpoint}'
,utils.udf_json_rpc_call('{{ method }}', {{ params }})
,concat_ws('/', 'integration', _utils.udf_provider(), '{{ blockchain }}', {{ network }})
,utils.udf_json_rpc_call({{ method }}, {{ params }})
,concat_ws('/', 'integration', _utils.udf_provider(), {{ blockchain }}, {{ network }})
)::VARIANT:data AS data
)
SELECT
COALESCE(data:result, {'error':data:error})
FROM result
{%- endmacro -%}
{% endmacro -%}

View File

@ -0,0 +1,22 @@
{{ config(
materialized = 'view'
) }}
SELECT
parent_contract_address,
event_name,
event_signature,
abi,
start_block,
end_block,
CASE
blockchain
WHEN 'avalanche' THEN 'avalanche_c'
WHEN 'arbitrum' THEN 'arbitrum_one'
ELSE blockchain
END AS blockchain
FROM
{{ source(
'crosschain',
'dim_evm_event_abis'
) }}

View File

@ -0,0 +1,19 @@
{{ config(
materialized = 'view'
) }}
SELECT
address,
symbol,
decimals,
CASE
blockchain
WHEN 'avalanche' THEN 'avalanche_c'
WHEN 'arbitrum' THEN 'arbitrum_one'
ELSE blockchain
END AS blockchain
FROM
{{ source(
'crosschain',
'dim_contracts'
) }}

View File

@ -5,4 +5,6 @@ sources:
database: "{{ 'crosschain' if target.database == 'LIVEQUERY' else 'crosschain_dev' }}"
schema: core
tables:
- name: dim_date_hours
- name: dim_date_hours
- name: dim_contracts
- name: dim_evm_event_abis