preprended instruction change (#703)

* fix

* fix
This commit is contained in:
Adrian Brzeziński 2023-09-04 18:06:37 +02:00 committed by GitHub
parent 0a2bf3abd5
commit 79ea2bc7df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 49 deletions

View File

@ -95,6 +95,7 @@ export type MangoClientOptions = {
prioritizationFee?: number;
txConfirmationCommitment?: Commitment;
openbookFeesToDao?: boolean;
prependedGlobalAdditionalInstructions?: TransactionInstruction[];
};
export class MangoClient {
@ -103,15 +104,6 @@ export class MangoClient {
private prioritizationFee: number;
private txConfirmationCommitment: Commitment;
private openbookFeesToDao: boolean;
/**
* @param tempAdditionalInstructions - Instructions to be appended ixes of to the next sendAndConfirmTransaction call.
* Cleared automatically after the sendAndConfirmTransaction call is executed.
*/
private tempAdditionalInstructions: TransactionInstruction[] = [];
/**
* @param prependedGlobalAdditionalInstructions - Instructions to be prepended (unshift) to ixes inside any sendAndConfirmTransaction call.
* They remain effective until cleared with clearPrependedGlobalAdditionalInstructions.
*/
private prependedGlobalAdditionalInstructions: TransactionInstruction[] = [];
constructor(
@ -124,6 +116,8 @@ export class MangoClient {
this.prioritizationFee = opts?.prioritizationFee || 0;
this.postSendTxCallback = opts?.postSendTxCallback;
this.openbookFeesToDao = opts?.openbookFeesToDao ?? true;
this.prependedGlobalAdditionalInstructions =
opts.prependedGlobalAdditionalInstructions ?? [];
this.txConfirmationCommitment =
opts?.txConfirmationCommitment ??
(program.provider as AnchorProvider).opts.commitment ??
@ -141,52 +135,14 @@ export class MangoClient {
return (this.program.provider as AnchorProvider).wallet.publicKey;
}
public clearTempAdditionalInstructions(): void {
this.tempAdditionalInstructions = [];
}
public addTempAdditionalInstructions(ixs: TransactionInstruction[]): void {
this.tempAdditionalInstructions = [
...this.tempAdditionalInstructions,
...ixs,
];
}
public clearPrependedGlobalAdditionalInstructions(): void {
this.prependedGlobalAdditionalInstructions = [];
}
public addPrependedGlobalAdditionalInstructions(
ixs: TransactionInstruction[],
): void {
this.prependedGlobalAdditionalInstructions = [
...this.prependedGlobalAdditionalInstructions,
...ixs,
];
}
/// Transactions
public async sendAndConfirmTransaction(
ixs: TransactionInstruction[],
opts: any = {},
): Promise<MangoSignatureStatus> {
return await this.sendTransactionWithClearTempAdditionalInstructions(
ixs,
opts,
);
}
public async sendTransactionWithClearTempAdditionalInstructions(
ixs: TransactionInstruction[],
opts: any = {},
): Promise<MangoSignatureStatus> {
const status = await sendTransaction(
this.program.provider as AnchorProvider,
[
...this.prependedGlobalAdditionalInstructions,
...ixs,
...this.tempAdditionalInstructions,
],
[...this.prependedGlobalAdditionalInstructions, ...ixs],
opts.alts ?? [],
{
postSendTxCallback: this.postSendTxCallback,
@ -195,7 +151,6 @@ export class MangoClient {
...opts,
},
);
this.clearTempAdditionalInstructions();
return status;
}