Batch transactions (#619)

This commit is contained in:
guibescos 2023-02-21 11:55:44 -06:00 committed by GitHub
parent b34ec4e882
commit 20b18e291d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 9 deletions

View File

@ -20,6 +20,7 @@ import { ExecutePostedVaa } from "./governance_payload/ExecutePostedVaa";
import { OPS_KEY } from "./multisig"; import { OPS_KEY } from "./multisig";
export const MAX_EXECUTOR_PAYLOAD_SIZE = PACKET_DATA_SIZE - 687; // Bigger payloads won't fit in one addInstruction call when adding to the proposal export const MAX_EXECUTOR_PAYLOAD_SIZE = PACKET_DATA_SIZE - 687; // Bigger payloads won't fit in one addInstruction call when adding to the proposal
export const SIZE_OF_SIGNED_BATCH = 30;
type SquadInstruction = { type SquadInstruction = {
instruction: TransactionInstruction; instruction: TransactionInstruction;
@ -111,15 +112,18 @@ export async function proposeInstructions(
ixToSend.push(await squad.buildApproveTransaction(vault, newProposalAddress)); ixToSend.push(await squad.buildApproveTransaction(vault, newProposalAddress));
const txToSend = batchIntoTransactions(ixToSend); const txToSend = batchIntoTransactions(ixToSend);
await new AnchorProvider(
squad.connection, for (let i = 0; i < txToSend.length; i += SIZE_OF_SIGNED_BATCH) {
squad.wallet, await new AnchorProvider(
AnchorProvider.defaultOptions() squad.connection,
).sendAll( squad.wallet,
txToSend.map((tx) => { AnchorProvider.defaultOptions()
return { tx, signers: [] }; ).sendAll(
}) txToSend.slice(i, i + SIZE_OF_SIGNED_BATCH).map((tx) => {
); return { tx, signers: [] };
})
);
}
return newProposalAddress; return newProposalAddress;
} }