@haven-fi/solauto-sdk 1.0.832 → 1.0.833

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,6 +60,7 @@ export declare class TransactionsManager<T extends TxHandler> {
60
60
  private shouldProceedToSend;
61
61
  private refreshItemSets;
62
62
  private processTransactionsAtomically;
63
+ private processTransactionSetsSequentially;
63
64
  private sendJitoBundle;
64
65
  private processTransactionSet;
65
66
  protected sendTransaction(tx: TransactionBuilder, name: string, attemptNum: number, priorityFeeSetting?: PriorityFeeSetting, txRunType?: TransactionRunType): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/manager/transactionsManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAElB,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAIL,aAAa,EAKd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAEL,YAAY,EACZ,eAAe,EAEhB,MAAM,UAAU,CAAC;AAGlB,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAED,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,UAAU,eAAe;IACzB,MAAM,WAAW;CAClB;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,0BAA0B,GAAG,wBAAwB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AAC,YAAY;YAiCN,aAAa;IAwB3B,SAAS,CAAC,4BAA4B,CACpC,SAAS,EAAE,KAAK,GAAG,SAAS,EAC5B,UAAU,EAAE,MAAM;IAcpB,OAAO,CAAC,mBAAmB;IAkBd,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;IAoCtC,OAAO,CAAC,mBAAmB;YA0Bb,eAAe;YAkDf,6BAA6B;YAyC7B,cAAc;YA0Ed,qBAAqB;cAuDnB,eAAe,CAC7B,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,kBAAkB,CAAC,EAAE,kBAAkB,EACvC,SAAS,CAAC,EAAE,kBAAkB;IAqChC,OAAO,CAAC,gBAAgB;CAuCzB"}
1
+ {"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/manager/transactionsManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAElB,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAIL,aAAa,EAKd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAEL,YAAY,EACZ,eAAe,EAEhB,MAAM,UAAU,CAAC;AAGlB,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAED,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,UAAU,eAAe;IACzB,MAAM,WAAW;CAClB;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,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e,CAAC,EAAE,eAAe,CAAC;gBAEhC,IAAI,EAAE,uBAAuB,CAAC,CAAC,CAAC;YAoB9B,uBAAuB;IAwDrC,OAAO,CAAC,YAAY;YAiCN,aAAa;IAwB3B,SAAS,CAAC,4BAA4B,CACpC,SAAS,EAAE,KAAK,GAAG,SAAS,EAC5B,UAAU,EAAE,MAAM;IAcpB,OAAO,CAAC,mBAAmB;IAkBd,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;IAgCtC,OAAO,CAAC,mBAAmB;YA0Bb,eAAe;YAkDf,6BAA6B;YA8D7B,kCAAkC;YAUlC,cAAc;YA0Ed,qBAAqB;cAuDnB,eAAe,CAC7B,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,kBAAkB,CAAC,EAAE,kBAAkB,EACvC,SAAS,CAAC,EAAE,kBAAkB;IAqChC,OAAO,CAAC,gBAAgB;CAuCzB"}
@@ -161,11 +161,7 @@ class TransactionsManager {
161
161
  await this.processTransactionsAtomically(itemSets);
162
162
  }
163
163
  else {
164
- let currentIndex = 0;
165
- while (currentIndex < itemSets.length) {
166
- await this.processTransactionSet(itemSets, currentIndex);
167
- currentIndex++;
168
- }
164
+ await this.processTransactionSetsSequentially(itemSets);
169
165
  }
170
166
  return this.statuses;
171
167
  }
@@ -215,27 +211,49 @@ class TransactionsManager {
215
211
  return newItemSets;
216
212
  }
217
213
  async processTransactionsAtomically(itemSets) {
218
- await (0, utils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => {
219
- if (prevError &&
220
- this.statuses.filter((x) => x.simulationSuccessful).length >
221
- this.signableRetries) {
222
- throw prevError;
223
- }
224
- this.priorityFeeSetting = this.getUpdatedPriorityFeeSetting(prevError, attemptNum);
225
- if (attemptNum > 0) {
226
- const refreshedSets = await this.refreshItemSets(itemSets, attemptNum, prevError);
227
- if (!refreshedSets || !refreshedSets.length) {
228
- return;
214
+ let bundleSendAttempted = false;
215
+ try {
216
+ await (0, utils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => {
217
+ if (prevError &&
218
+ this.statuses.filter((x) => x.simulationSuccessful).length >
219
+ this.signableRetries) {
220
+ throw prevError;
221
+ }
222
+ this.priorityFeeSetting = this.getUpdatedPriorityFeeSetting(prevError, attemptNum);
223
+ if (attemptNum > 0) {
224
+ const refreshedSets = await this.refreshItemSets(itemSets, attemptNum, prevError);
225
+ if (!refreshedSets || !refreshedSets.length) {
226
+ return;
227
+ }
228
+ else {
229
+ itemSets = refreshedSets;
230
+ }
229
231
  }
230
- else {
231
- itemSets = refreshedSets;
232
+ if (!this.shouldProceedToSend(itemSets, attemptNum)) {
233
+ return;
232
234
  }
235
+ bundleSendAttempted = true;
236
+ await this.sendJitoBundle(itemSets, attemptNum);
237
+ }, this.totalRetries, this.retryDelay, this.errorsToThrow);
238
+ }
239
+ catch (error) {
240
+ const explicitlyNonRetryable = this.errorsToThrow?.some((errorType) => error instanceof errorType);
241
+ if (!bundleSendAttempted ||
242
+ itemSets.length <= 1 ||
243
+ explicitlyNonRetryable ||
244
+ this.abortController?.signal.aborted) {
245
+ throw error;
233
246
  }
234
- if (!this.shouldProceedToSend(itemSets, attemptNum)) {
235
- return;
236
- }
237
- await this.sendJitoBundle(itemSets, attemptNum);
238
- }, this.totalRetries, this.retryDelay, this.errorsToThrow);
247
+ (0, utils_1.consoleLog)("Jito bundle failed after all retries; retrying one transaction at a time");
248
+ await this.processTransactionSetsSequentially(itemSets);
249
+ }
250
+ }
251
+ async processTransactionSetsSequentially(itemSets) {
252
+ let currentIndex = 0;
253
+ while (currentIndex < itemSets.length) {
254
+ await this.processTransactionSet(itemSets, currentIndex);
255
+ currentIndex++;
256
+ }
239
257
  }
240
258
  async sendJitoBundle(itemSets, attemptNum) {
241
259
  let transactions = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.832",
3
+ "version": "1.0.833",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Typescript SDK for the Solauto program on the Solana blockchain",
@@ -279,11 +279,7 @@ export class TransactionsManager<T extends TxHandler> {
279
279
  if (this.atomically) {
280
280
  await this.processTransactionsAtomically(itemSets);
281
281
  } else {
282
- let currentIndex = 0;
283
- while (currentIndex < itemSets.length) {
284
- await this.processTransactionSet(itemSets, currentIndex);
285
- currentIndex++;
286
- }
282
+ await this.processTransactionSetsSequentially(itemSets);
287
283
  }
288
284
 
289
285
  return this.statuses;
@@ -366,44 +362,75 @@ export class TransactionsManager<T extends TxHandler> {
366
362
  }
367
363
 
368
364
  private async processTransactionsAtomically(itemSets: TransactionSet[]) {
369
- await retryWithExponentialBackoff(
370
- async (attemptNum, prevError) => {
371
- if (
372
- prevError &&
373
- this.statuses.filter((x) => x.simulationSuccessful).length >
374
- this.signableRetries
375
- ) {
376
- throw prevError;
377
- }
378
-
379
- this.priorityFeeSetting = this.getUpdatedPriorityFeeSetting(
380
- prevError,
381
- attemptNum
382
- );
365
+ let bundleSendAttempted = false;
366
+ try {
367
+ await retryWithExponentialBackoff(
368
+ async (attemptNum, prevError) => {
369
+ if (
370
+ prevError &&
371
+ this.statuses.filter((x) => x.simulationSuccessful).length >
372
+ this.signableRetries
373
+ ) {
374
+ throw prevError;
375
+ }
383
376
 
384
- if (attemptNum > 0) {
385
- const refreshedSets = await this.refreshItemSets(
386
- itemSets,
387
- attemptNum,
388
- prevError
377
+ this.priorityFeeSetting = this.getUpdatedPriorityFeeSetting(
378
+ prevError,
379
+ attemptNum
389
380
  );
390
- if (!refreshedSets || !refreshedSets.length) {
381
+
382
+ if (attemptNum > 0) {
383
+ const refreshedSets = await this.refreshItemSets(
384
+ itemSets,
385
+ attemptNum,
386
+ prevError
387
+ );
388
+ if (!refreshedSets || !refreshedSets.length) {
389
+ return;
390
+ } else {
391
+ itemSets = refreshedSets;
392
+ }
393
+ }
394
+
395
+ if (!this.shouldProceedToSend(itemSets, attemptNum)) {
391
396
  return;
392
- } else {
393
- itemSets = refreshedSets;
394
397
  }
395
- }
396
398
 
397
- if (!this.shouldProceedToSend(itemSets, attemptNum)) {
398
- return;
399
- }
399
+ bundleSendAttempted = true;
400
+ await this.sendJitoBundle(itemSets, attemptNum);
401
+ },
402
+ this.totalRetries,
403
+ this.retryDelay,
404
+ this.errorsToThrow
405
+ );
406
+ } catch (error: any) {
407
+ const explicitlyNonRetryable = this.errorsToThrow?.some(
408
+ (errorType) => error instanceof errorType
409
+ );
410
+ if (
411
+ !bundleSendAttempted ||
412
+ itemSets.length <= 1 ||
413
+ explicitlyNonRetryable ||
414
+ this.abortController?.signal.aborted
415
+ ) {
416
+ throw error;
417
+ }
400
418
 
401
- await this.sendJitoBundle(itemSets, attemptNum);
402
- },
403
- this.totalRetries,
404
- this.retryDelay,
405
- this.errorsToThrow
406
- );
419
+ consoleLog(
420
+ "Jito bundle failed after all retries; retrying one transaction at a time"
421
+ );
422
+ await this.processTransactionSetsSequentially(itemSets);
423
+ }
424
+ }
425
+
426
+ private async processTransactionSetsSequentially(
427
+ itemSets: TransactionSet[]
428
+ ) {
429
+ let currentIndex = 0;
430
+ while (currentIndex < itemSets.length) {
431
+ await this.processTransactionSet(itemSets, currentIndex);
432
+ currentIndex++;
433
+ }
407
434
  }
408
435
 
409
436
  private async sendJitoBundle(itemSets: TransactionSet[], attemptNum: number) {
@@ -0,0 +1,69 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import { TransactionsManager } from "../../src";
4
+
5
+ function createManager(abortController?: AbortController) {
6
+ return new TransactionsManager({
7
+ txHandler: {
8
+ defaultLookupTables: () => [],
9
+ umi: {},
10
+ } as any,
11
+ retryConfig: { totalRetries: 1, retryDelay: 0 },
12
+ abortController,
13
+ }) as any;
14
+ }
15
+
16
+ describe("TransactionsManager bundle fallback", () => {
17
+ it("retries a failed multi-transaction bundle sequentially", async () => {
18
+ const manager = createManager();
19
+ const calls: string[] = [];
20
+ const itemSets = [{}, {}, {}] as any[];
21
+
22
+ manager.shouldProceedToSend = () => true;
23
+ manager.sendJitoBundle = async () => {
24
+ calls.push("bundle");
25
+ throw new Error("bundle failed");
26
+ };
27
+ manager.processTransactionSet = async (
28
+ receivedSets: any[],
29
+ currentIndex: number
30
+ ) => {
31
+ expect(receivedSets).to.equal(itemSets);
32
+ calls.push(`single:${currentIndex}`);
33
+ };
34
+
35
+ await manager.processTransactionsAtomically(itemSets);
36
+
37
+ expect(calls).to.deep.equal([
38
+ "bundle",
39
+ "single:0",
40
+ "single:1",
41
+ "single:2",
42
+ ]);
43
+ });
44
+
45
+ it("does not fall back after the request is aborted", async () => {
46
+ const abortController = new AbortController();
47
+ const manager = createManager(abortController);
48
+ let sequentialAttempts = 0;
49
+
50
+ manager.shouldProceedToSend = () => true;
51
+ manager.sendJitoBundle = async () => {
52
+ abortController.abort();
53
+ throw new Error("bundle aborted");
54
+ };
55
+ manager.processTransactionSet = async () => {
56
+ sequentialAttempts++;
57
+ };
58
+
59
+ let thrownError: Error | undefined;
60
+ try {
61
+ await manager.processTransactionsAtomically([{}, {}]);
62
+ } catch (error: any) {
63
+ thrownError = error;
64
+ }
65
+
66
+ expect(thrownError?.message).to.equal("bundle aborted");
67
+ expect(sequentialAttempts).to.equal(0);
68
+ });
69
+ });