Skip to content

Conversation

@pauldragonfly
Copy link
Contributor

No description provided.

@pauldragonfly pauldragonfly force-pushed the paul/DX-191_fix_fetch_positions_for_owner branch from 6ba9f21 to 0454f07 Compare March 5, 2025 16:25
Copy link
Member

@wjthieme wjthieme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add this for the ts sdk?

@@ -0,0 +1,5 @@
---
"@orca-so/whirlpools-rust": patch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need a changeset for the TS sdk

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

) -> Result<Vec<Option<Account>>, Box<dyn std::error::Error>> {
let mut results = vec![];

for chunk in pubkeys.chunks(chunk_size.unwrap_or(DEFAULT_CHUNK_SIZE)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Clamp the chunk_size to (0, MAX_CHUNK_SIZE)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An iterator over a slice in (non-overlapping) chunks (chunk_size elements at a time), starting at the beginning of the slice.
When the slice len is not evenly divided by the chunk size, the last slice of the iteration will be the remainder.

Clamp is necessary here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything less than 1 and more than 100 is invalid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

const chunkSize = 100;

let promises = [];
for (let i = 0; i < positionAddresses.length; i += chunkSize) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if you can make this a separate function as well (like in rust). Something like:

export async function fetchMultipleAccountsBatched<T extends object>(
  rpc: Rpc<GetMultipleAccountsApi>,
  addresses: Address[],
  decoder: (account: MaybeEncodedAccount) => MaybeAccount<T>,
): Promise<MaybeAccount<T>[]> {
  const numChunks = Math.ceil(addresses.length / MAX_CHUNK_SIZE);
  const chunks = [...Array(numChunks).keys()].map((i) =>
    addresses.slice(i * MAX_CHUNK_SIZE, (i + 1) * MAX_CHUNK_SIZE),
  );

  const results: MaybeAccount<T>[] = [];
  for (const chunk of chunks) {
    const chunkResult = await fetchEncodedAccounts(rpc, chunk);
    chunkResult.forEach((account, i) => {
      const data = decoder(account);
      results.push(data);
    });
  }
  return results;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@wjthieme wjthieme merged commit 1e939cb into main Mar 21, 2025
7 checks passed
@wjthieme wjthieme deleted the paul/DX-191_fix_fetch_positions_for_owner branch March 21, 2025 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants