FIELD_STATISTIC_INSTRUCTION

Aggregate instructions through basic statistics on instruction fields.

Overview

This method allows you to aggregate instructions through basic statistics and an optional robust filter object. There are many types of filters you can apply and you can find information regarding those in the Filters section of the docs. The endpoint example here shows off one of the many filters.

Statistic

The "statistic" field in the post body is based on the following type and can adapt to the kind of query you wish to perform

type FieldStatistic = 'avg' | 'sum' | 'std' | 'min' | 'max' | { percentile: number }

Filters

As mentioned above, the api definition here illustrates one of Carpool's many filter types. The filter object is optional here, but all queries that accept a filter object in the POST body can make use of any of the potential filters. Please see the Instruction Filters section of the documentation to better understand how they are implemented for instruction queries.

👓pageInstruction Filters

Example - Basic

Program - Candy Machine

Description - Return the average of the numeric value found at argument data.creators.percentageShare

Javascript

var myHeaders = new Headers();
myHeaders.append("x-api-key", "<API_KEY>");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "type": "FIELD_STATISTIC_INSTRUCTION",
  "query": {
    "programId": "CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR",
    "path": "data.creators.percentageShare",
    "statistic": "avg"
  }
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://mainnet.carpool.dev/query/solana", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

cURL

curl --location 'https://mainnet.carpool.dev/query/solana' \
--header 'x-api-key: <API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
    "type": "FIELD_STATISTIC_INSTRUCTION",
    "query": {
        "programId": "CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR",
        "path": "data.creators.percentageShare",
        "statistic": "avg"
    }
}'

Example - Advanced

Program - Candy Machine

Description - Find the minimum numeric value found at argument data.creators.percentageShare. Filter for only initializeV2 instructions within a set time range.

Javascript

var myHeaders = new Headers();
myHeaders.append("x-api-key", "<API_KEY>");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "type": "FIELD_STATISTIC_INSTRUCTION",
  "query": {
    "programId": "CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR",
    "path": "data.creators.percentageShare",
    "statistic": "min",
    "filter": {
      "type": "INSTRUCTION_NAME",
      "instructionName": "initializeV2"
    },
    "timeRange": {
      "before": "2023-07-12T22:53:09+0000",
      "after": "2023-07-11T22:53:09+0000"
    }
  }
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://mainnet.carpool.dev/query/solana", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

cURL

curl --location 'https://mainnet.carpool.dev/query/solana' \
--header 'x-api-key: <API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
    "type": "FIELD_STATISTIC_INSTRUCTION",
    "query": {
        "programId": "CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR",
        "path": "data.creators.percentageShare",
        "statistic": "min",
        "filter": {
            "type": "INSTRUCTION_NAME",
            "instructionName": "initializeV2"
        },
        "timeRange": {
            "before": "2023-07-12T22:53:09+0000",
            "after": "2023-07-11T22:53:09+0000"
        }
    }
}'

Last updated