Skip to content

Commit 5afc44b

Browse files
add batching for getMultipleAccoutnsInfo (#276)
1 parent 3fb3977 commit 5afc44b

File tree

9 files changed

+38
-9
lines changed

9 files changed

+38
-9
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"packages": [
33
"packages/*"
44
],
5-
"version": "7.4.15",
5+
"version": "7.4.16",
66
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
77
}

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/common",
3-
"version": "7.4.15",
3+
"version": "7.4.16",
44
"description": "Common utilities and types used by streamflow packages.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"main": "./dist/esm/index.js",

packages/common/solana/utils.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
RpcResponseAndContext,
2424
SimulatedTransactionResponse,
2525
SendTransactionError,
26+
AccountInfo,
2627
} from "@solana/web3.js";
2728
import bs58 from "bs58";
2829
import PQueue from "p-queue";
@@ -581,3 +582,30 @@ export async function getMintAndProgram(
581582
tokenProgramId: programId!,
582583
};
583584
}
585+
586+
/**
587+
* Split fetching of Multiple Accounts Info into batches of 100
588+
* as the maximum number of accounts that can be fetched in a single call is 100
589+
*
590+
* @param connection Connection to use
591+
* @param pubKeys Array of public keys to fetch account info for
592+
* @param commitment Desired level of commitment for querying the state
593+
*
594+
* @return Array of AccountInfo objects
595+
*/
596+
export async function getMultipleAccountsInfoBatched(
597+
connection: Connection,
598+
pubKeys: PublicKey[],
599+
commitment?: Commitment,
600+
): Promise<(AccountInfo<Buffer> | null)[]> {
601+
const batchSize = 99;
602+
const batches: Promise<(AccountInfo<Buffer> | null)[]>[] = [];
603+
604+
for (let i = 0; i < pubKeys.length; i += batchSize) {
605+
const batch = pubKeys.slice(i, i + batchSize);
606+
batches.push(connection.getMultipleAccountsInfo(batch, commitment));
607+
}
608+
609+
const results = await Promise.all(batches);
610+
return results.flat();
611+
}

packages/distributor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/distributor",
3-
"version": "7.4.15",
3+
"version": "7.4.16",
44
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"main": "dist/esm/index.js",

packages/eslint-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/eslint-config",
3-
"version": "7.4.15",
3+
"version": "7.4.16",
44
"license": "ISC",
55
"main": "index.js",
66
"files": [

packages/launchpad/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/launchpad",
3-
"version": "7.4.15",
3+
"version": "7.4.16",
44
"description": "JavaScript SDK to interact with Streamflow Launchpad protocol.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"main": "dist/esm/index.js",

packages/staking/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/staking",
3-
"version": "7.4.15",
3+
"version": "7.4.16",
44
"description": "JavaScript SDK to interact with Streamflow Staking protocol.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"main": "dist/esm/index.js",

packages/stream/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/stream",
3-
"version": "7.4.15",
3+
"version": "7.4.16",
44
"description": "JavaScript SDK to interact with Streamflow protocol.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"main": "./dist/esm/index.js",

packages/stream/solana/StreamClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
buildSendThrottler,
3434
IProgramAccount,
3535
ThrottleParams,
36+
getMultipleAccountsInfoBatched,
3637
} from "@streamflow/common/solana";
3738
import * as borsh from "borsh";
3839
import { Program } from "@coral-xyz/anchor";
@@ -1360,7 +1361,7 @@ export class SolanaStreamClient extends BaseStreamClient {
13601361
},
13611362
]);
13621363
const streamPubKeys = alignedOutgoingProgramAccounts.map((account) => account.account.stream);
1363-
const streamAccounts = await this.connection.getMultipleAccountsInfo(streamPubKeys, TX_FINALITY_CONFIRMED);
1364+
const streamAccounts = await getMultipleAccountsInfoBatched(this.connection, streamPubKeys, TX_FINALITY_CONFIRMED);
13641365
streamAccounts.forEach((account, index) => {
13651366
if (account) {
13661367
const alignedData = alignedOutgoingProgramAccounts[index].account;
@@ -1379,7 +1380,7 @@ export class SolanaStreamClient extends BaseStreamClient {
13791380
const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) =>
13801381
deriveContractPDA(this.alignedProxyProgram.programId, new PublicKey(streamPubKey)),
13811382
);
1382-
const alignedProxyAccounts = await this.connection.getMultipleAccountsInfo(alignedProxyPDAs);
1383+
const alignedProxyAccounts = await getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
13831384
alignedProxyAccounts.forEach((account, index) => {
13841385
if (account && account.data.length === ALIGNED_METADATA_ACC_SIZE) {
13851386
const alignedData = streamRecord[alignedStreamsPubKeys[index]];

0 commit comments

Comments
 (0)