max accounts error margin fcn (#905)

* add error for max accounts limit

* fix
This commit is contained in:
Adrian Brzeziński 2024-03-05 16:56:35 +01:00 committed by GitHub
parent 8aff0fb8c5
commit 1a6a544ecd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 1 deletions

View File

@ -226,9 +226,26 @@ export class MangoClient {
ixs: TransactionInstruction[],
opts: SendTransactionOpts = {},
): Promise<MangoSignatureStatus> {
const alts =
opts?.alts && opts?.alts?.length
? opts.alts
: group.addressLookupTablesList;
const uniqueAccountsCount = [
...new Set([
...ixs.flatMap((x) => x.keys.map((x) => x.pubkey.toBase58())),
...ixs.flatMap((x) => x.programId.toBase58()),
...alts.map((x) => x.key.toBase58()),
]),
].length;
if (uniqueAccountsCount > 64) {
throw new Error(`Max accounts limit exceeded`);
}
return await this.sendAndConfirmTransaction(ixs, {
alts: group.addressLookupTablesList,
...opts,
alts: alts,
});
}