Skip to content

Commit

Permalink
Add helper to split out ATAIXs (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhly authored Mar 29, 2022
1 parent 0d8c7c3 commit 565f429
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/solana-contrib/src/transaction/TransactionEnvelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,30 @@ export class TransactionEnvelope {
return new TransactionEnvelope(this.provider, instructions, this.signers);
}

/**
* Split out ATA instructions to a separate transaction envelope.
*/
splitATAIXs(): {
ataIXs: TransactionEnvelope;
tx: TransactionEnvelope;
} {
const ataIXs = new TransactionEnvelope(this.provider, [], this.signers);
const newTx = new TransactionEnvelope(this.provider, [], this.signers);

for (const ix of this.instructions) {
if (ix.programId.equals(ASSOCIATED_TOKEN_PROGRAM_ID)) {
ataIXs.instructions.push(ix);
} else {
newTx.instructions.push(ix);
}
}

return {
ataIXs: ataIXs.dedupeATAIXs(),
tx: newTx,
};
}

/**
* Get an instruction from the transaction envelope by index.
*/
Expand Down

0 comments on commit 565f429

Please sign in to comment.