@haven-fi/solauto-sdk 1.0.744 → 1.0.745

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,11 +60,12 @@ export declare class TransactionsManager<T extends TxHandler> {
60
60
  send(items: TransactionItem[]): Promise<TransactionManagerStatuses>;
61
61
  private shouldProceedToSend;
62
62
  private getTrueAttemptNum;
63
- private sendJitoBundle;
63
+ private refreshItemSets;
64
64
  private processTransactionsAtomically;
65
+ private sendJitoBundle;
65
66
  private processTransactionSet;
66
- private refreshItemSets;
67
67
  protected sendTransaction(tx: TransactionBuilder, name: string, attemptNum: number, priorityFeeSetting?: PriorityFeeSetting, txRunType?: TransactionRunType): Promise<void>;
68
+ private captureErrorInfo;
68
69
  }
69
70
  export {};
70
71
  //# sourceMappingURL=transactionsManager.d.ts.map
@@ -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,EAEL,aAAa,EAId,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAkB,MAAM,UAAU,CAAC;AAEzE,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,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AE,MAAM,CAAC;IAC7B,SAAS,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC;IAE5C,kBAAkB,SAAmB;gBAEzB,IAAI,EAAE,uBAAuB,CAAC,CAAC,CAAC;YAoB9B,uBAAuB;IA0CrC,OAAO,CAAC,YAAY;YA+BN,aAAa;IAoB3B,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;IAiCtC,OAAO,CAAC,mBAAmB;IAuB3B,OAAO,CAAC,iBAAiB;YAWX,cAAc;YA8Gd,6BAA6B;YA6C7B,qBAAqB;YAwDrB,eAAe;cAkDb,eAAe,CAC7B,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,kBAAkB,CAAC,EAAE,kBAAkB,EACvC,SAAS,CAAC,EAAE,kBAAkB;CAgEjC"}
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,EAEL,aAAa,EAId,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAkB,MAAM,UAAU,CAAC;AAEzE,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,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E,YAAY,CAAC;IACrC,SAAS,CAAC,eAAe,EAAE,MAAM,CAAC;IAClC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,eAAe,CAAC,EAAE,eAAe,CAAC;IAE5C,kBAAkB,SAAmB;gBAEzB,IAAI,EAAE,uBAAuB,CAAC,CAAC,CAAC;YAoB9B,uBAAuB;IA0CrC,OAAO,CAAC,YAAY;YA+BN,aAAa;IAoB3B,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;IA0B3B,OAAO,CAAC,iBAAiB;YAWX,eAAe;YAkDf,6BAA6B;YA6C7B,cAAc;YA0Ed,qBAAqB;cAwDnB,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;CAqCzB"}
@@ -126,10 +126,10 @@ class TransactionsManager {
126
126
  }
127
127
  return this.priorityFeeSetting;
128
128
  }
129
- updateStatusForSets(itemSets, args, txSigs, reset) {
130
- itemSets.forEach((itemSet, i) => {
129
+ updateStatusForSets(txNames, args, txSigs, reset) {
130
+ txNames.forEach((name, i) => {
131
131
  this.updateStatus({
132
- name: itemSet.name(),
132
+ name,
133
133
  txSig: txSigs && txSigs.length > i ? txSigs[i] : undefined,
134
134
  ...args,
135
135
  }, reset);
@@ -147,7 +147,7 @@ class TransactionsManager {
147
147
  this.txHandler.log("Transaction items:", items.length);
148
148
  return await this.assembleTransactionSets(items);
149
149
  }, this.totalRetries);
150
- this.updateStatusForSets(itemSets, {
150
+ this.updateStatusForSets(itemSets.map((x) => x.name()), {
151
151
  status: TransactionStatus.Queued,
152
152
  attemptNum: 0,
153
153
  });
@@ -165,14 +165,14 @@ class TransactionsManager {
165
165
  return this.statuses;
166
166
  }
167
167
  shouldProceedToSend(itemSets, attemptNum) {
168
- if (!itemSets) {
168
+ if (itemSets.length === 0) {
169
169
  return false;
170
170
  }
171
171
  const newItemSetNames = itemSets.flatMap((x) => x.items.map((y) => y.name ?? ""));
172
172
  if (newItemSetNames.length === 1 &&
173
173
  newItemSetNames[0] === this.updateOracleTxName) {
174
174
  (0, utils_1.consoleLog)("Skipping unnecessary oracle update");
175
- this.updateStatusForSets(itemSets, {
175
+ this.updateStatusForSets(itemSets.map((x) => x.name()), {
176
176
  status: TransactionStatus.Skipped,
177
177
  attemptNum,
178
178
  });
@@ -187,71 +187,34 @@ class TransactionsManager {
187
187
  ?.length;
188
188
  return attemptNum;
189
189
  }
190
- async sendJitoBundle(itemSets, attemptNum) {
191
- let transactions = [];
192
- try {
193
- for (const set of itemSets) {
194
- transactions.push(await set.getSingleTransaction());
195
- }
196
- transactions = transactions.filter((x) => x.getInstructions().length > 0);
197
- if (transactions.length === 0) {
198
- this.updateStatusForSets(itemSets, {
199
- status: TransactionStatus.Skipped,
200
- attemptNum,
201
- });
202
- return;
203
- }
204
- this.updateStatusForSets(itemSets, {
205
- status: TransactionStatus.Processing,
206
- attemptNum,
207
- }, undefined, true);
190
+ async refreshItemSets(itemSets, attemptNum, prevError, currentIndex) {
191
+ if (currentIndex !== undefined) {
192
+ const itemSet = itemSets[currentIndex];
193
+ await itemSet.reset();
194
+ await itemSet.refetchAll(attemptNum, prevError);
195
+ }
196
+ else {
197
+ await Promise.all(itemSets.map((itemSet) => itemSet.reset()));
208
198
  for (const itemSet of itemSets) {
209
- await this.debugAccounts(itemSet, await itemSet.getSingleTransaction());
210
- }
211
- let txSigs;
212
- let error;
213
- try {
214
- txSigs = await (0, utils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.connection, this.txHandler.signer, this.txHandler.otherSigners, transactions, this.txRunType, this.priorityFeeSetting, () => this.updateStatusForSets(itemSets, {
215
- status: TransactionStatus.Processing,
216
- attemptNum,
217
- simulationSuccessful: true,
218
- }), this.abortController);
219
- }
220
- catch (e) {
221
- error = e;
222
- }
223
- if (error ||
224
- (this.txRunType !== "only-simulate" &&
225
- (!Boolean(txSigs) || txSigs?.length === 0) &&
226
- !this.abortController?.signal.aborted)) {
227
- this.updateStatusForSets(itemSets, {
228
- status: TransactionStatus.Failed,
229
- attemptNum,
230
- moreInfo: error?.message,
231
- }, txSigs);
232
- throw error ? error : new Error("Unknown error");
199
+ await itemSet.refetchAll(attemptNum, prevError);
233
200
  }
234
- this.updateStatusForSets(itemSets, { status: TransactionStatus.Successful, attemptNum }, txSigs);
235
201
  }
236
- catch (e) {
237
- this.txHandler.log("Capturing error info...");
238
- const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, transactions, e, itemSets.filter((x) => this.statuses.find((y) => x.name() === y.name && y.attemptNum === attemptNum)?.simulationSuccessful).length === itemSets.length, this.priorityFeeSetting);
239
- const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
240
- const errorInfo = errorDetails.errorName || errorDetails.errorInfo
241
- ? errorString
242
- : e.message;
243
- this.updateStatusForSets(itemSets, {
244
- status: errorDetails.canBeIgnored
245
- ? TransactionStatus.Skipped
246
- : TransactionStatus.Failed,
247
- attemptNum,
248
- moreInfo: errorInfo,
249
- });
250
- (0, utils_1.consoleLog)(errorString);
251
- if (!errorDetails.canBeIgnored) {
252
- throw new Error(errorInfo);
253
- }
202
+ const newItemSets = await this.assembleTransactionSets(currentIndex !== undefined
203
+ ? [
204
+ ...itemSets[currentIndex].items,
205
+ ...itemSets.slice(currentIndex + 1).flatMap((set) => set.items),
206
+ ]
207
+ : itemSets.flatMap((set) => set.items));
208
+ if (currentIndex !== undefined && newItemSets.length > 1) {
209
+ itemSets.splice(currentIndex, itemSets.length - currentIndex, ...newItemSets);
210
+ const startOfQueuedStatuses = this.statuses.findIndex((x) => x.status === TransactionStatus.Queued);
211
+ this.statuses.splice(startOfQueuedStatuses, this.statuses.length - startOfQueuedStatuses, ...newItemSets.map((x, i) => ({
212
+ name: x.name(),
213
+ attemptNum: i === 0 ? attemptNum : 0,
214
+ status: i === 0 ? TransactionStatus.Processing : TransactionStatus.Queued,
215
+ })));
254
216
  }
217
+ return newItemSets;
255
218
  }
256
219
  async processTransactionsAtomically(itemSets) {
257
220
  await (0, utils_1.retryWithExponentialBackoff)(async (retryNum, prevError) => {
@@ -277,6 +240,48 @@ class TransactionsManager {
277
240
  await this.sendJitoBundle(itemSets, attemptNum);
278
241
  }, this.totalRetries, this.retryDelay, this.errorsToThrow);
279
242
  }
243
+ async sendJitoBundle(itemSets, attemptNum) {
244
+ let transactions = [];
245
+ let txNames = [];
246
+ try {
247
+ for (const set of itemSets) {
248
+ transactions.push(await set.getSingleTransaction());
249
+ }
250
+ transactions = transactions.filter((x) => x.getInstructions().length > 0);
251
+ txNames = itemSets.map((x) => x.name());
252
+ if (transactions.length === 0) {
253
+ this.updateStatusForSets(txNames, {
254
+ status: TransactionStatus.Skipped,
255
+ attemptNum,
256
+ });
257
+ return;
258
+ }
259
+ this.updateStatusForSets(txNames, {
260
+ status: TransactionStatus.Processing,
261
+ attemptNum,
262
+ }, undefined, true);
263
+ for (const itemSet of itemSets) {
264
+ await this.debugAccounts(itemSet, await itemSet.getSingleTransaction());
265
+ }
266
+ const txSigs = await (0, utils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.connection, this.txHandler.signer, this.txHandler.otherSigners, transactions, this.txRunType, this.priorityFeeSetting, () => this.updateStatusForSets(txNames, {
267
+ status: TransactionStatus.Processing,
268
+ attemptNum,
269
+ simulationSuccessful: true,
270
+ }), this.abortController);
271
+ if (this.txRunType !== "only-simulate" &&
272
+ (!Boolean(txSigs) || txSigs?.length === 0) &&
273
+ !this.abortController?.signal.aborted) {
274
+ this.updateStatusForSets(txNames, {
275
+ status: TransactionStatus.Failed,
276
+ attemptNum,
277
+ }, txSigs);
278
+ }
279
+ this.updateStatusForSets(txNames, { status: TransactionStatus.Successful, attemptNum }, txSigs);
280
+ }
281
+ catch (e) {
282
+ this.captureErrorInfo(transactions, txNames, attemptNum, e);
283
+ }
284
+ }
280
285
  async processTransactionSet(itemSets, currentIndex) {
281
286
  let itemSet = itemSets[currentIndex];
282
287
  await (0, utils_1.retryWithExponentialBackoff)(async (retryNum, prevError) => {
@@ -308,35 +313,6 @@ class TransactionsManager {
308
313
  }
309
314
  }, this.totalRetries, this.retryDelay, this.errorsToThrow);
310
315
  }
311
- async refreshItemSets(itemSets, attemptNum, prevError, currentIndex) {
312
- if (currentIndex !== undefined) {
313
- const itemSet = itemSets[currentIndex];
314
- await itemSet.reset();
315
- await itemSet.refetchAll(attemptNum, prevError);
316
- }
317
- else {
318
- await Promise.all(itemSets.map((itemSet) => itemSet.reset()));
319
- for (const itemSet of itemSets) {
320
- await itemSet.refetchAll(attemptNum, prevError);
321
- }
322
- }
323
- const newItemSets = await this.assembleTransactionSets(currentIndex !== undefined
324
- ? [
325
- ...itemSets[currentIndex].items,
326
- ...itemSets.slice(currentIndex + 1).flatMap((set) => set.items),
327
- ]
328
- : itemSets.flatMap((set) => set.items));
329
- if (currentIndex !== undefined && newItemSets.length > 1) {
330
- itemSets.splice(currentIndex, itemSets.length - currentIndex, ...newItemSets);
331
- const startOfQueuedStatuses = this.statuses.findIndex((x) => x.status === TransactionStatus.Queued);
332
- this.statuses.splice(startOfQueuedStatuses, this.statuses.length - startOfQueuedStatuses, ...newItemSets.map((x, i) => ({
333
- name: x.name(),
334
- attemptNum: i === 0 ? attemptNum : 0,
335
- status: i === 0 ? TransactionStatus.Processing : TransactionStatus.Queued,
336
- })));
337
- }
338
- return newItemSets;
339
- }
340
316
  async sendTransaction(tx, name, attemptNum, priorityFeeSetting, txRunType) {
341
317
  this.updateStatus({
342
318
  name,
@@ -358,24 +334,27 @@ class TransactionsManager {
358
334
  });
359
335
  }
360
336
  catch (e) {
361
- this.txHandler.log("Capturing error info...");
362
- const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, [tx], e, this.statuses.find((x) => x.name === name && x.attemptNum === attemptNum)?.simulationSuccessful, priorityFeeSetting);
363
- const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
364
- const errorInfo = errorDetails.errorName || errorDetails.errorInfo
365
- ? errorString
366
- : e.message;
367
- this.updateStatus({
368
- name,
369
- status: errorDetails.canBeIgnored
370
- ? TransactionStatus.Skipped
371
- : TransactionStatus.Failed,
372
- attemptNum,
373
- moreInfo: errorInfo,
374
- });
375
- (0, utils_1.consoleLog)(errorString);
376
- if (!errorDetails.canBeIgnored) {
377
- throw new Error(errorInfo);
378
- }
337
+ this.captureErrorInfo([tx], [name], attemptNum, e);
338
+ }
339
+ }
340
+ captureErrorInfo(transactions, txNames, attemptNum, error) {
341
+ this.txHandler.log("Capturing error info...");
342
+ const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, transactions, error, txNames.filter((x) => this.statuses.find((y) => x === y.name && y.attemptNum === attemptNum)
343
+ ?.simulationSuccessful).length === txNames.length, this.priorityFeeSetting);
344
+ const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
345
+ const errorInfo = errorDetails.errorName || errorDetails.errorInfo
346
+ ? errorString
347
+ : error.message;
348
+ this.updateStatusForSets(txNames, {
349
+ status: errorDetails.canBeIgnored
350
+ ? TransactionStatus.Skipped
351
+ : TransactionStatus.Failed,
352
+ attemptNum,
353
+ moreInfo: errorInfo,
354
+ });
355
+ (0, utils_1.consoleLog)(errorString);
356
+ if (!errorDetails.canBeIgnored) {
357
+ throw new Error(errorInfo);
379
358
  }
380
359
  }
381
360
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.744",
3
+ "version": "1.0.745",
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",
@@ -207,15 +207,15 @@ export class TransactionsManager<T extends TxHandler> {
207
207
  }
208
208
 
209
209
  private updateStatusForSets(
210
- itemSets: TransactionSet[],
210
+ txNames: string[],
211
211
  args: Omit<TransactionManagerStatus, "name">,
212
212
  txSigs?: string[],
213
213
  reset?: boolean
214
214
  ) {
215
- itemSets.forEach((itemSet, i) => {
215
+ txNames.forEach((name, i) => {
216
216
  this.updateStatus(
217
217
  {
218
- name: itemSet.name(),
218
+ name,
219
219
  txSig: txSigs && txSigs.length > i ? txSigs[i] : undefined,
220
220
  ...args,
221
221
  },
@@ -240,10 +240,13 @@ export class TransactionsManager<T extends TxHandler> {
240
240
  return await this.assembleTransactionSets(items);
241
241
  }, this.totalRetries);
242
242
 
243
- this.updateStatusForSets(itemSets, {
244
- status: TransactionStatus.Queued,
245
- attemptNum: 0,
246
- });
243
+ this.updateStatusForSets(
244
+ itemSets.map((x) => x.name()),
245
+ {
246
+ status: TransactionStatus.Queued,
247
+ attemptNum: 0,
248
+ }
249
+ );
247
250
  this.txHandler.log("Initial item sets:", itemSets.length);
248
251
 
249
252
  if (this.atomically) {
@@ -260,7 +263,7 @@ export class TransactionsManager<T extends TxHandler> {
260
263
  }
261
264
 
262
265
  private shouldProceedToSend(itemSets: TransactionSet[], attemptNum: number) {
263
- if (!itemSets) {
266
+ if (itemSets.length === 0) {
264
267
  return false;
265
268
  }
266
269
 
@@ -272,10 +275,13 @@ export class TransactionsManager<T extends TxHandler> {
272
275
  newItemSetNames[0] === this.updateOracleTxName
273
276
  ) {
274
277
  consoleLog("Skipping unnecessary oracle update");
275
- this.updateStatusForSets(itemSets, {
276
- status: TransactionStatus.Skipped,
277
- attemptNum,
278
- });
278
+ this.updateStatusForSets(
279
+ itemSets.map((x) => x.name()),
280
+ {
281
+ status: TransactionStatus.Skipped,
282
+ attemptNum,
283
+ }
284
+ );
279
285
  return false;
280
286
  }
281
287
 
@@ -293,114 +299,54 @@ export class TransactionsManager<T extends TxHandler> {
293
299
  return attemptNum;
294
300
  }
295
301
 
296
- private async sendJitoBundle(itemSets: TransactionSet[], attemptNum: number) {
297
- let transactions: TransactionBuilder[] = [];
298
-
299
- try {
300
- for (const set of itemSets) {
301
- transactions.push(await set.getSingleTransaction());
302
- }
303
- transactions = transactions.filter((x) => x.getInstructions().length > 0);
304
- if (transactions.length === 0) {
305
- this.updateStatusForSets(itemSets, {
306
- status: TransactionStatus.Skipped,
307
- attemptNum,
308
- });
309
- return;
310
- }
311
-
312
- this.updateStatusForSets(
313
- itemSets,
314
- {
315
- status: TransactionStatus.Processing,
316
- attemptNum,
317
- },
318
- undefined,
319
- true
320
- );
302
+ private async refreshItemSets(
303
+ itemSets: TransactionSet[],
304
+ attemptNum: number,
305
+ prevError?: Error,
306
+ currentIndex?: number
307
+ ): Promise<TransactionSet[] | undefined> {
308
+ if (currentIndex !== undefined) {
309
+ const itemSet = itemSets[currentIndex];
310
+ await itemSet.reset();
311
+ await itemSet.refetchAll(attemptNum, prevError);
312
+ } else {
313
+ await Promise.all(itemSets.map((itemSet) => itemSet.reset()));
321
314
  for (const itemSet of itemSets) {
322
- await this.debugAccounts(itemSet, await itemSet.getSingleTransaction());
323
- }
324
-
325
- let txSigs: string[] | undefined;
326
- let error: Error | undefined;
327
- try {
328
- txSigs = await sendJitoBundledTransactions(
329
- this.txHandler.umi,
330
- this.txHandler.connection,
331
- this.txHandler.signer,
332
- this.txHandler.otherSigners,
333
- transactions,
334
- this.txRunType,
335
- this.priorityFeeSetting,
336
- () =>
337
- this.updateStatusForSets(itemSets, {
338
- status: TransactionStatus.Processing,
339
- attemptNum,
340
- simulationSuccessful: true,
341
- }),
342
- this.abortController
343
- );
344
- } catch (e: any) {
345
- error = e as Error;
315
+ await itemSet.refetchAll(attemptNum, prevError);
346
316
  }
317
+ }
347
318
 
348
- if (
349
- error ||
350
- (this.txRunType !== "only-simulate" &&
351
- (!Boolean(txSigs) || txSigs?.length === 0) &&
352
- !this.abortController?.signal.aborted)
353
- ) {
354
- this.updateStatusForSets(
355
- itemSets,
356
- {
357
- status: TransactionStatus.Failed,
358
- attemptNum,
359
- moreInfo: error?.message,
360
- },
361
- txSigs
362
- );
363
- throw error ? error : new Error("Unknown error");
364
- }
319
+ const newItemSets = await this.assembleTransactionSets(
320
+ currentIndex !== undefined
321
+ ? [
322
+ ...itemSets[currentIndex].items,
323
+ ...itemSets.slice(currentIndex + 1).flatMap((set) => set.items),
324
+ ]
325
+ : itemSets.flatMap((set) => set.items)
326
+ );
365
327
 
366
- this.updateStatusForSets(
367
- itemSets,
368
- { status: TransactionStatus.Successful, attemptNum },
369
- txSigs
328
+ if (currentIndex !== undefined && newItemSets.length > 1) {
329
+ itemSets.splice(
330
+ currentIndex,
331
+ itemSets.length - currentIndex,
332
+ ...newItemSets
370
333
  );
371
- } catch (e: any) {
372
- this.txHandler.log("Capturing error info...");
373
- const errorDetails = getErrorInfo(
374
- this.txHandler.umi,
375
- transactions,
376
- e,
377
- itemSets.filter(
378
- (x) =>
379
- this.statuses.find(
380
- (y) => x.name() === y.name && y.attemptNum === attemptNum
381
- )?.simulationSuccessful
382
- ).length === itemSets.length,
383
- this.priorityFeeSetting
334
+ const startOfQueuedStatuses = this.statuses.findIndex(
335
+ (x) => x.status === TransactionStatus.Queued
336
+ );
337
+ this.statuses.splice(
338
+ startOfQueuedStatuses,
339
+ this.statuses.length - startOfQueuedStatuses,
340
+ ...newItemSets.map((x, i) => ({
341
+ name: x.name(),
342
+ attemptNum: i === 0 ? attemptNum : 0,
343
+ status:
344
+ i === 0 ? TransactionStatus.Processing : TransactionStatus.Queued,
345
+ }))
384
346
  );
385
-
386
- const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
387
- const errorInfo =
388
- errorDetails.errorName || errorDetails.errorInfo
389
- ? errorString
390
- : e.message;
391
- this.updateStatusForSets(itemSets, {
392
- status: errorDetails.canBeIgnored
393
- ? TransactionStatus.Skipped
394
- : TransactionStatus.Failed,
395
- attemptNum,
396
- moreInfo: errorInfo,
397
- });
398
- consoleLog(errorString);
399
-
400
- if (!errorDetails.canBeIgnored) {
401
- throw new Error(errorInfo);
402
- }
403
347
  }
348
+
349
+ return newItemSets;
404
350
  }
405
351
 
406
352
  private async processTransactionsAtomically(itemSets: TransactionSet[]) {
@@ -448,6 +394,80 @@ export class TransactionsManager<T extends TxHandler> {
448
394
  );
449
395
  }
450
396
 
397
+ private async sendJitoBundle(itemSets: TransactionSet[], attemptNum: number) {
398
+ let transactions: TransactionBuilder[] = [];
399
+ let txNames: string[] = [];
400
+
401
+ try {
402
+ for (const set of itemSets) {
403
+ transactions.push(await set.getSingleTransaction());
404
+ }
405
+ transactions = transactions.filter((x) => x.getInstructions().length > 0);
406
+
407
+ txNames = itemSets.map((x) => x.name());
408
+ if (transactions.length === 0) {
409
+ this.updateStatusForSets(txNames, {
410
+ status: TransactionStatus.Skipped,
411
+ attemptNum,
412
+ });
413
+ return;
414
+ }
415
+
416
+ this.updateStatusForSets(
417
+ txNames,
418
+ {
419
+ status: TransactionStatus.Processing,
420
+ attemptNum,
421
+ },
422
+ undefined,
423
+ true
424
+ );
425
+ for (const itemSet of itemSets) {
426
+ await this.debugAccounts(itemSet, await itemSet.getSingleTransaction());
427
+ }
428
+
429
+ const txSigs = await sendJitoBundledTransactions(
430
+ this.txHandler.umi,
431
+ this.txHandler.connection,
432
+ this.txHandler.signer,
433
+ this.txHandler.otherSigners,
434
+ transactions,
435
+ this.txRunType,
436
+ this.priorityFeeSetting,
437
+ () =>
438
+ this.updateStatusForSets(txNames, {
439
+ status: TransactionStatus.Processing,
440
+ attemptNum,
441
+ simulationSuccessful: true,
442
+ }),
443
+ this.abortController
444
+ );
445
+
446
+ if (
447
+ this.txRunType !== "only-simulate" &&
448
+ (!Boolean(txSigs) || txSigs?.length === 0) &&
449
+ !this.abortController?.signal.aborted
450
+ ) {
451
+ this.updateStatusForSets(
452
+ txNames,
453
+ {
454
+ status: TransactionStatus.Failed,
455
+ attemptNum,
456
+ },
457
+ txSigs
458
+ );
459
+ }
460
+
461
+ this.updateStatusForSets(
462
+ txNames,
463
+ { status: TransactionStatus.Successful, attemptNum },
464
+ txSigs
465
+ );
466
+ } catch (e: any) {
467
+ this.captureErrorInfo(transactions, txNames, attemptNum, e);
468
+ }
469
+ }
470
+
451
471
  private async processTransactionSet(
452
472
  itemSets: TransactionSet[],
453
473
  currentIndex: number
@@ -504,56 +524,6 @@ export class TransactionsManager<T extends TxHandler> {
504
524
  );
505
525
  }
506
526
 
507
- private async refreshItemSets(
508
- itemSets: TransactionSet[],
509
- attemptNum: number,
510
- prevError?: Error,
511
- currentIndex?: number
512
- ): Promise<TransactionSet[] | undefined> {
513
- if (currentIndex !== undefined) {
514
- const itemSet = itemSets[currentIndex];
515
- await itemSet.reset();
516
- await itemSet.refetchAll(attemptNum, prevError);
517
- } else {
518
- await Promise.all(itemSets.map((itemSet) => itemSet.reset()));
519
- for (const itemSet of itemSets) {
520
- await itemSet.refetchAll(attemptNum, prevError);
521
- }
522
- }
523
-
524
- const newItemSets = await this.assembleTransactionSets(
525
- currentIndex !== undefined
526
- ? [
527
- ...itemSets[currentIndex].items,
528
- ...itemSets.slice(currentIndex + 1).flatMap((set) => set.items),
529
- ]
530
- : itemSets.flatMap((set) => set.items)
531
- );
532
-
533
- if (currentIndex !== undefined && newItemSets.length > 1) {
534
- itemSets.splice(
535
- currentIndex,
536
- itemSets.length - currentIndex,
537
- ...newItemSets
538
- );
539
- const startOfQueuedStatuses = this.statuses.findIndex(
540
- (x) => x.status === TransactionStatus.Queued
541
- );
542
- this.statuses.splice(
543
- startOfQueuedStatuses,
544
- this.statuses.length - startOfQueuedStatuses,
545
- ...newItemSets.map((x, i) => ({
546
- name: x.name(),
547
- attemptNum: i === 0 ? attemptNum : 0,
548
- status:
549
- i === 0 ? TransactionStatus.Processing : TransactionStatus.Queued,
550
- }))
551
- );
552
- }
553
-
554
- return newItemSets;
555
- }
556
-
557
527
  protected async sendTransaction(
558
528
  tx: TransactionBuilder,
559
529
  name: string,
@@ -592,35 +562,45 @@ export class TransactionsManager<T extends TxHandler> {
592
562
  txSig: txSig ? bs58.encode(txSig) : undefined,
593
563
  });
594
564
  } catch (e: any) {
595
- this.txHandler.log("Capturing error info...");
596
- const errorDetails = getErrorInfo(
597
- this.txHandler.umi,
598
- [tx],
599
- e,
600
- this.statuses.find(
601
- (x) => x.name === name && x.attemptNum === attemptNum
602
- )?.simulationSuccessful,
603
- priorityFeeSetting
604
- );
565
+ this.captureErrorInfo([tx], [name], attemptNum, e);
566
+ }
567
+ }
605
568
 
606
- const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
607
- const errorInfo =
608
- errorDetails.errorName || errorDetails.errorInfo
609
- ? errorString
610
- : e.message;
611
- this.updateStatus({
612
- name,
613
- status: errorDetails.canBeIgnored
614
- ? TransactionStatus.Skipped
615
- : TransactionStatus.Failed,
616
- attemptNum,
617
- moreInfo: errorInfo,
618
- });
619
- consoleLog(errorString);
569
+ private captureErrorInfo(
570
+ transactions: TransactionBuilder[],
571
+ txNames: string[],
572
+ attemptNum: number,
573
+ error: any
574
+ ) {
575
+ this.txHandler.log("Capturing error info...");
576
+ const errorDetails = getErrorInfo(
577
+ this.txHandler.umi,
578
+ transactions,
579
+ error,
580
+ txNames.filter(
581
+ (x) =>
582
+ this.statuses.find((y) => x === y.name && y.attemptNum === attemptNum)
583
+ ?.simulationSuccessful
584
+ ).length === txNames.length,
585
+ this.priorityFeeSetting
586
+ );
620
587
 
621
- if (!errorDetails.canBeIgnored) {
622
- throw new Error(errorInfo);
623
- }
588
+ const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
589
+ const errorInfo =
590
+ errorDetails.errorName || errorDetails.errorInfo
591
+ ? errorString
592
+ : error.message;
593
+ this.updateStatusForSets(txNames, {
594
+ status: errorDetails.canBeIgnored
595
+ ? TransactionStatus.Skipped
596
+ : TransactionStatus.Failed,
597
+ attemptNum,
598
+ moreInfo: errorInfo,
599
+ });
600
+ consoleLog(errorString);
601
+
602
+ if (!errorDetails.canBeIgnored) {
603
+ throw new Error(errorInfo);
624
604
  }
625
605
  }
626
606
  }