Macros: Utility: Ranges And Sequences - FlipsideCrypto/fsc-evm GitHub Wiki

The following macros are intended to be used to create and maintain various models. These macros can be accessed via version >=v1.0.0 of the fsc-evm package. Please see the fsc-evm installation instructions in the README for more details on how to access and utilize this macro effectively.

These Range and Sequence macros are intended to be used to as support for Streamline, Observability or other models, and contain standardized SQL logic with flexible parameters.


number_sequence

Usage

This macro generates a sequence of numbers from 0 to max_num - 1. It uses the ROW_NUMBER() function to create a unique identifier for each row in the generated sequence, which can be useful for creating block ranges for reference in downstream models. The max number of rows is often related to the total amount of potential blocks for a given blockchain and time period.

fsc_evm.number_sequence

Parameters

Note: Parameters with default values must be ordered after non-default parameters.

Parameter Type Default Description
max_num Integer 1,000,000,000 The maximum number for the sequence.

Example:

{{ fsc_evm.number_sequence(max_num=500000) }}

block_sequence

Usage

This macro retrieves block numbers and their hexadecimal representations from the silver__number_sequence table. It filters the results based on the current block number obtained from the streamline__get_chainhead reference, ensuring that only relevant blocks are included in the output. This is typically used to reference a spine of block numbers in the Realtime and History Requests models.

fsc_evm.block_sequence

Parameters

Note: Parameters with default values must be ordered after non-default parameters.

Parameter Type Default Description
min_block Integer 0 The desired starting block. This is used to stand up new chains, primarily

Example:

{{ fsc_evm.block_sequence(min_block=18000000) }}

block_ranges

Usage

This macro retrieves block numbers and categorizes them into ranges based on their last digits. It includes various cases to identify blocks that end in 0, 25, 50, 75, and other significant values, providing a structured view of block distribution. It also includes timestamps for further analysis. This is often used with Contract Reads models to limit calls to only occur on certain blocks.

fsc_evm.block_ranges

Parameters

Note: Parameters with default values must be ordered after non-default parameters.

This macro does not have any parameters.

Example:

{{ fsc_evm.block_ranges() }}