Skip to content

enoldev/substreams-pump-fun-account-changes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pump Fun: Reading Account Changes Data

Substreams offers two Solana endpoints: - Standard Block: index transactions and instructions. - Account Changes: index historical account changes.

In this example, you will be able to index data from BondingCurve Anchor accounts in the Pump.Fun platform. Therefore, you will be using the Account Changes endpoint.

To get standard Block data, use this Substreams.

Quickstart

  1. Build the Substreams
substreams build
  1. Run the Substreams:
substreams gui ./substreams.yaml map_my_data --start-block=333000025 -e accounts.mainnet.sol.streamingfast.io:443 --stop-block=+10

In the previous command, you are running the Substreams against the accounts.mainnet.sol.streamingfast.io:443 (account changes) endpoint.

Understading the Substreams

The Substreams Manifest (substreams.yaml)

...

imports:
  solana: https://spkg.io/v1/packages/solana_accounts_foundational/v0.1.1 # 1.

...

modules:
 - name: filtered_accounts # 2.
   use: solana:filtered_accounts

 - name: map_my_data # 3.
   kind: map
   inputs:
   - map: filtered_accounts
   output:
    type: proto:mydata.v1.MyData

params:
  filtered_accounts: account:EA8ALG67fSLWDJwUmDyj38x45UkmG4pPYDNmfWbE6NMA # 4.
  1. Import the Solana Accounts foundational modules. These modules allow you to get filtered Solana accounts. The modules are imported with the solana alias (solana: ...).
  2. Define a new module filtered_accounts, which uses the filtered_accounts module from the Solana Accounts foundational modules previously imported. This modules expects one or several modules to be filtered as input.
  3. Define a new module, map_my_data, which receives the filtered accounts as input, and outputs a MyData object (defined in the proto/mydata.proto file). Here, you will make the decoding of the Pump Fun accounts.
  4. The parameters passed to the filtered_accounts module. In this case, it is the address of a Pump Fun Bonding Curve account.

The Substreams Code (src/lib.rs)

#[substreams::handlers::map]
fn map_my_data(accounts: FilteredAccounts) -> mydata::MyData {
    let mut bonding_curve_list: Vec<BondingCurve> = Vec::new(); // 1.

    accounts.accounts.iter().for_each(|account| { // 2.
        let slice_u8: &[u8] = &account.data[..];
        if &slice_u8[0..8] == idl::idl::program::accounts::BondingCurve::DISCRIMINATOR { // 3.
            if let Ok(acct) =
                idl::idl::program::accounts::BondingCurve::deserialize(&mut &slice_u8[8..]) // 4.
            {
                bonding_curve_list.push(
                    BondingCurve {
                        virtual_token_reserves: acct.virtual_token_reserves,
                        virtual_sol_reserves: acct.virtual_sol_reserves,
                        real_token_reserves: acct.real_token_reserves,
                        real_sol_reserves: acct.real_sol_reserves,
                        token_total_supply: acct.token_total_supply,
                        complete: acct.complete
                    })
            }
        }
    });

    MyData {
        bonding_curve_list
    }
}
  1. Initialize the output array of BondingCurve Protobuf objects, defined in proto/mydata.proto.
  2. Iterate over the filtered account. In this example, we will only get changes related to the EA8ALG67fSLWDJwUmDyj38x45UkmG4pPYDNmfWbE6NMA account, which is a BondigCurve account.
  3. Every account change contains a data field, which is the raw data written in the blockchain. The first 8 bytes are used as discriminator (i.e. the identifier of the account).
  4. If the account data matches the discriminator, it is deserialized.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages