Package Logo
orca_whirlpool_substream
orca_whirlpool_substream@v0.1.0
Total Downloads
3
Published
2 weeks ago
Network
solana solana
Publisher
User Avatar kmchmk

Readme

Orca-Whirlpool Substream

This substream processes Orca Whirlpool transactions on the Solana blockchain, extracting and organizing data related to liquidity pools, swaps, deposits, and withdrawals.

Overview

The Orca-Whirlpool substream is designed to:

  1. Map and process Orca Whirlpool transactions
  2. Extract data for pools, deposits, withdrawals, and swaps
  3. Store and update cumulative statistics
  4. Generate entity changes for downstream consumers (e.g., Graph Protocol) to enable efficient data querying and analysis

Usage

Refer to the Repository README for instructions on how to build and run the substream.

Key Components

Modules

  1. map_block: Processes raw Solana blocks to extract Orca Whirlpool events
  2. map_pools: Extracts and processes pool-related data
  3. map_deposits: Processes deposit (increase liquidity) events
  4. map_withdraws: Processes withdrawal (decrease liquidity) events
  5. map_swaps: Processes swap events
  6. graph_out: Generates entity changes for the Graph protocol

Instructions

The substream handles various Orca Whirlpool instructions, including:

  • Initialize Pool (V1 and V2)
  • Increase Liquidity (V1 and V2)
  • Decrease Liquidity (V1 and V2)
  • Swap (V1 and V2)
  • Two Hop Swap (V1 and V2)

Data Structures

The main data structures are defined in the output.proto file.

Stores

The substream uses several stores to maintain state:

  • store_pools: Stores pool data
  • store_deposits: Stores deposit data
  • store_withdraws: Stores withdrawal data
  • store_swaps: Stores swap data
  • store_unique_users: Tracks unique users
  • store_cumulative_users: Maintains cumulative user count
  • store_total_pool_count: Tracks total pool count
  • store_pool_balances: Stores pool token balances
  • store_pool_liquidity: Tracks pool liquidity

Adding Support for New Instructions

To add support for new Orca Whirlpool instructions:

  1. Update the src/pb/orca.whirlpool.v1.rs file to include the new instruction definition.
  2. Modify the map_block function in src/lib.rs to handle the new instruction type.
  3. Create a new mapping function in the appropriate module (e.g., map_pools.rs, map_deposits.rs, etc.) to process the new instruction data.
  4. Update the relevant stores to accommodate any new data fields.
  5. Modify the graph_out module to include the new data in the entity changes if necessary.

Graph

graph TD;
  map_block[map: map_block];
  solana:blocks_without_votes --> map_block;
  map_pools[map: map_pools];
  map_block --> map_pools;
  store_pools[store: store_pools];
  map_pools --> store_pools;
  map_deposits[map: map_deposits];
  map_block --> map_deposits;
  store_pools --> map_deposits;
  store_deposits[store: store_deposits];
  map_block --> store_deposits;
  map_withdraws[map: map_withdraws];
  map_block --> map_withdraws;
  store_pools --> map_withdraws;
  store_withdraws[store: store_withdraws];
  map_block --> store_withdraws;
  map_swaps[map: map_swaps];
  map_block --> map_swaps;
  store_pools --> map_swaps;
  store_swaps[store: store_swaps];
  map_swaps --> store_swaps;
  store_unique_users[store: store_unique_users];
  map_block --> store_unique_users;
  store_cumulative_users[store: store_cumulative_users];
  store_unique_users -- deltas --> store_cumulative_users;
  store_total_pool_count[store: store_total_pool_count];
  store_pools -- deltas --> store_total_pool_count;
  store_pool_balances[store: store_pool_balances];
  map_deposits --> store_pool_balances;
  map_withdraws --> store_pool_balances;
  map_swaps --> store_pool_balances;
  store_pool_liquidity[store: store_pool_liquidity];
  map_deposits --> store_pool_liquidity;
  map_withdraws --> store_pool_liquidity;
  graph_out[map: graph_out];
  sf.substreams.v1.Clock[source: sf.substreams.v1.Clock] --> graph_out;
  map_pools --> graph_out;
  store_pools --> graph_out;
  store_cumulative_users -- deltas --> graph_out;
  store_total_pool_count -- deltas --> graph_out;
  store_pool_balances -- deltas --> graph_out;
  store_pool_liquidity -- deltas --> graph_out;
  solana:blocks_without_votes[map: solana:blocks_without_votes];
  sf.solana.type.v1.Block[source: sf.solana.type.v1.Block] --> solana:blocks_without_votes;
  solana:blocks_without_votes --> solana:program_ids_without_votes;
  solana:filtered_transactions_without_votes[map: solana:filtered_transactions_without_votes];
  solana:filtered_transactions_without_votes:params[params] --> solana:filtered_transactions_without_votes;
  solana:blocks_without_votes --> solana:filtered_transactions_without_votes;

Documentation

Modules

Maps icon
Maps

map
map_block

a169ccda53ca7c3b31d2c345cc884034ae13b23c
map map_block (
solana:blocks_without_votessf.solana.type.v1.Block
)  -> messari.orca_whirlpool.v1.Events
substreams gui orca-whirlpool-substream@v0.1.0 map_block

map
map_pools

8a87b1820a607ac54daf0217624c5b01fc030df8
substreams gui orca-whirlpool-substream@v0.1.0 map_pools

map
map_deposits

bf84d4dfa49a5554d78859956f7ed1b5247eddf4
substreams gui orca-whirlpool-substream@v0.1.0 map_deposits

map
map_withdraws

f88753a2e6b4fec230f67234ac684edda0740378
substreams gui orca-whirlpool-substream@v0.1.0 map_withdraws

map
map_swaps

5823201b16b920948dd1f0896e934109c1c2ec9c
substreams gui orca-whirlpool-substream@v0.1.0 map_swaps

map
graph_out

19cf897609ceef242a5d2a1b409aa1a8aeb31edf
substreams gui orca-whirlpool-substream@v0.1.0 graph_out

map
solana:blocks_without_votes

0be93a73c65aa8ec2de4b1a47209edeea493ff29
map solana:blocks_without_votes (
)  -> sf.solana.type.v1.Block

blocks_without_votes allows you to consume a full Solana Block without Vote instructions (Vote111111111111111111111111111111111111111). If you consume it on HISTORICAL data (+1000 blocks from HEAD), you will be reading from the StreamingFast cache, thus saving costs on the amount of TB read.

substreams gui orca-whirlpool-substream@v0.1.0 solana:blocks_without_votes
Stores icon
Stores

store
store_pools

94aead22d89c8b448623b2370577f53dcbc38281
substreams gui orca-whirlpool-substream@v0.1.0 store_pools

store
store_deposits

87ef279948e3dc51263fd5cefe1e788605607d32
substreams gui orca-whirlpool-substream@v0.1.0 store_deposits

store
store_withdraws

e128ed1689b6c45db0514300e55ec91a0b00f74e
substreams gui orca-whirlpool-substream@v0.1.0 store_withdraws

store
store_swaps

f73832ddad7aedc64bd08a386137f384f03eb161
substreams gui orca-whirlpool-substream@v0.1.0 store_swaps

store
store_unique_users

ebb36d0415ca64100952558f029c7059b3e834d7
store <set_if_not_exists,bigint> store_unique_users (
)
substreams gui orca-whirlpool-substream@v0.1.0 store_unique_users

store
store_cumulative_users

b7e00cad6b99fc8b48d73b7de79698a50fcbc6af
store <add,int64> store_cumulative_users (
store_unique_usersDELTAS<set_if_not_exists,bigint>
)
substreams gui orca-whirlpool-substream@v0.1.0 store_cumulative_users

store
store_total_pool_count

c4a1bb31fcd9dc27993a07dd4748c12ee7eef18e
store <add,int64> store_total_pool_count (
)
substreams gui orca-whirlpool-substream@v0.1.0 store_total_pool_count

store
store_pool_balances

2b413438b4a4ab48326d8fd3cd25d0f15073bf25
substreams gui orca-whirlpool-substream@v0.1.0 store_pool_balances

store
store_pool_liquidity

750e06673b6ddf0f8a6ca11e0415e910b209dba6
substreams gui orca-whirlpool-substream@v0.1.0 store_pool_liquidity

store
store_activity_counts

920f0fab930a17eb1d02557de6047ba368cf4cf9
substreams gui orca-whirlpool-substream@v0.1.0 store_activity_counts

store
store_volume_by_token_amount

5d7f5a641c29f0bb31519b6c4ba9557abd38a36b
store <add,bigint> store_volume_by_token_amount (
)
substreams gui orca-whirlpool-substream@v0.1.0 store_volume_by_token_amount
Block Indexes icon
Block Indexes

blockIndex
solana:program_ids_without_votes

811466d12743a8b02be8ba6649cfa9a24aa1af62
blockIndex solana:program_ids_without_votes (
)  -> sf.substreams.index.v1.Keys

program_ids_without_votes creates a cache to efficiently retrieve instructions based on the program ID. For example, the following sets keys for the Token program:

  • program:TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
substreams gui orca-whirlpool-substream@v0.1.0 solana:program_ids_without_votes
Protobuf

Protobuf Docs Explorer

sol.instructions.v1
sol.transactions.v1
messari.orca_whirlpool.v1
sf.solana.type.v1