@haven-fi/solauto-sdk 1.0.140 → 1.0.141

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,12 +43,14 @@ export declare enum TransactionStatus {
43
43
  Skipped = "Skipped",
44
44
  Processing = "Processing",
45
45
  Queued = "Queued",
46
- Successful = "Successful"
46
+ Successful = "Successful",
47
+ Failed = "Failed"
47
48
  }
48
49
  export type TransactionManagerStatuses = {
49
50
  name: string;
50
51
  status: TransactionStatus;
51
52
  txSig?: string;
53
+ attemptNum: number;
52
54
  }[];
53
55
  export declare class TransactionsManager {
54
56
  private txHandler;
@@ -60,7 +62,7 @@ export declare class TransactionsManager {
60
62
  private lookupTables;
61
63
  constructor(txHandler: SolautoClient | ReferralStateManager, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, txType?: TransactionRunType | undefined, mustBeAtomic?: boolean | undefined, errorsToThrow?: ErrorsToThrow | undefined);
62
64
  private assembleTransactionSets;
63
- updateStatus(name: string, status: TransactionStatus, txSig?: string): void;
65
+ updateStatus(name: string, status: TransactionStatus, attemptNum: number, txSig?: string): void;
64
66
  debugAccounts(itemSet: TransactionSet, tx: TransactionBuilder): Promise<void>;
65
67
  clientSend(transactions: TransactionItem[], prioritySetting?: PriorityFeeSetting): Promise<TransactionManagerStatuses>;
66
68
  send(items: TransactionItem[], prioritySetting?: PriorityFeeSetting, initialized?: boolean): Promise<TransactionManagerStatuses>;
@@ -1 +1 @@
1
- {"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EAEvB,kBAAkB,EAClB,GAAG,EACJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,SAA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,EAAE,MAAM,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;IAiBlF,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,kBAAkB;IAoB7D,UAAU,CACd,YAAY,EAAE,eAAe,EAAE,EAC/B,eAAe,CAAC,EAAE,kBAAkB,GACnC,OAAO,CAAC,0BAA0B,CAAC;IAmFhC,IAAI,CACR,KAAK,EAAE,eAAe,EAAE,EACxB,eAAe,CAAC,EAAE,kBAAkB,EACpC,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,0BAA0B,CAAC;CAgHvC"}
@@ -116,6 +116,7 @@ var TransactionStatus;
116
116
  TransactionStatus["Processing"] = "Processing";
117
117
  TransactionStatus["Queued"] = "Queued";
118
118
  TransactionStatus["Successful"] = "Successful";
119
+ TransactionStatus["Failed"] = "Failed";
119
120
  })(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
120
121
  class TransactionsManager {
121
122
  constructor(txHandler, statusCallback, txType, mustBeAtomic, errorsToThrow) {
@@ -158,18 +159,18 @@ class TransactionsManager {
158
159
  }
159
160
  return transactionSets;
160
161
  }
161
- updateStatus(name, status, txSig) {
162
+ updateStatus(name, status, attemptNum, txSig) {
162
163
  if (!this.statuses.filter((x) => x.name === name)) {
163
- this.statuses.push({ name, status, txSig });
164
+ this.statuses.push({ name, status, txSig, attemptNum });
164
165
  }
165
166
  else {
166
- const idx = this.statuses.findIndex((x) => x.name === name);
167
+ const idx = this.statuses.findIndex((x) => x.name === name && x.attemptNum === attemptNum);
167
168
  if (idx !== -1) {
168
169
  this.statuses[idx].status = status;
169
170
  this.statuses[idx].txSig = txSig;
170
171
  }
171
172
  else {
172
- this.statuses.push({ name, status, txSig });
173
+ this.statuses.push({ name, status, txSig, attemptNum });
173
174
  }
174
175
  }
175
176
  this.txHandler.log(`${name} is ${status.toString().toLowerCase()}`);
@@ -199,9 +200,17 @@ class TransactionsManager {
199
200
  if (updateLookupTable &&
200
201
  updateLookupTable.updateLutTx.getInstructions().length > 0 &&
201
202
  updateLookupTable?.needsToBeIsolated) {
202
- this.updateStatus(updateLutTxName, TransactionStatus.Processing);
203
- await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, updateLookupTable.updateLutTx, this.txType, attemptNum, prioritySetting), 3, 150, this.errorsToThrow);
204
- this.updateStatus(updateLutTxName, TransactionStatus.Successful);
203
+ await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => {
204
+ this.updateStatus(updateLutTxName, TransactionStatus.Processing, attemptNum);
205
+ try {
206
+ const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, updateLookupTable.updateLutTx, this.txType, attemptNum, prioritySetting);
207
+ this.updateStatus(updateLutTxName, TransactionStatus.Successful, attemptNum, txSig ? bs58_1.default.encode(txSig) : undefined);
208
+ }
209
+ catch (e) {
210
+ this.updateStatus(updateLutTxName, TransactionStatus.Failed, attemptNum);
211
+ throw e;
212
+ }
213
+ }, 3, 150, this.errorsToThrow);
205
214
  }
206
215
  this.lookupTables.defaultLuts = client.defaultLookupTables();
207
216
  for (const item of items) {
@@ -245,7 +254,7 @@ class TransactionsManager {
245
254
  const itemSets = await this.assembleTransactionSets(items);
246
255
  const statusesStartIdx = this.statuses.length;
247
256
  for (const itemSet of itemSets) {
248
- this.updateStatus(itemSet.name(), TransactionStatus.Queued);
257
+ this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
249
258
  }
250
259
  if (this.mustBeAtomic && itemSets.length > 1) {
251
260
  throw new Error(`${itemSets.length} transactions required but jito bundles are not currently supported`);
@@ -277,6 +286,7 @@ class TransactionsManager {
277
286
  this.statuses.splice(statusesStartIdx + i, itemSets.length - i, ...newItemSets.map((x) => ({
278
287
  name: x.name(),
279
288
  status: TransactionStatus.Queued,
289
+ attemptNum: 0.
280
290
  })));
281
291
  this.txHandler.log(this.statuses);
282
292
  itemSets.splice(i + 1, itemSets.length - i - 1, ...newItemSets.slice(1));
@@ -294,15 +304,15 @@ class TransactionsManager {
294
304
  }
295
305
  const tx = await itemSet.getSingleTransaction();
296
306
  if (tx.getInstructions().length === 0) {
297
- this.updateStatus(itemSet.name(), TransactionStatus.Skipped);
307
+ this.updateStatus(itemSet.name(), TransactionStatus.Skipped, attemptNum);
298
308
  }
299
309
  else {
300
- this.updateStatus(itemSet.name(), TransactionStatus.Processing);
310
+ this.updateStatus(itemSet.name(), TransactionStatus.Processing, attemptNum);
301
311
  if (this.txHandler.localTest) {
302
312
  await this.debugAccounts(itemSet, tx);
303
313
  }
304
314
  const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, this.txType, attemptNum, prioritySetting);
305
- this.updateStatus(itemSet.name(), TransactionStatus.Successful, txSig ? bs58_1.default.encode(txSig) : undefined);
315
+ this.updateStatus(itemSet.name(), TransactionStatus.Successful, attemptNum, txSig ? bs58_1.default.encode(txSig) : undefined);
306
316
  }
307
317
  }, 4, 150, this.errorsToThrow);
308
318
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.140",
3
+ "version": "1.0.141",
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",
@@ -172,12 +172,14 @@ export enum TransactionStatus {
172
172
  Processing = "Processing",
173
173
  Queued = "Queued",
174
174
  Successful = "Successful",
175
+ Failed = "Failed",
175
176
  }
176
177
 
177
178
  export type TransactionManagerStatuses = {
178
179
  name: string;
179
180
  status: TransactionStatus;
180
181
  txSig?: string;
182
+ attemptNum: number;
181
183
  }[];
182
184
 
183
185
  export class TransactionsManager {
@@ -237,16 +239,16 @@ export class TransactionsManager {
237
239
  return transactionSets;
238
240
  }
239
241
 
240
- updateStatus(name: string, status: TransactionStatus, txSig?: string) {
242
+ updateStatus(name: string, status: TransactionStatus, attemptNum: number, txSig?: string) {
241
243
  if (!this.statuses.filter((x) => x.name === name)) {
242
- this.statuses.push({ name, status, txSig });
244
+ this.statuses.push({ name, status, txSig, attemptNum });
243
245
  } else {
244
- const idx = this.statuses.findIndex((x) => x.name === name);
246
+ const idx = this.statuses.findIndex((x) => x.name === name && x.attemptNum === attemptNum);
245
247
  if (idx !== -1) {
246
248
  this.statuses[idx].status = status;
247
249
  this.statuses[idx].txSig = txSig;
248
250
  } else {
249
- this.statuses.push({ name, status, txSig });
251
+ this.statuses.push({ name, status, txSig, attemptNum });
250
252
  }
251
253
  }
252
254
  this.txHandler.log(`${name} is ${status.toString().toLowerCase()}`);
@@ -288,22 +290,28 @@ export class TransactionsManager {
288
290
  updateLookupTable.updateLutTx.getInstructions().length > 0 &&
289
291
  updateLookupTable?.needsToBeIsolated
290
292
  ) {
291
- this.updateStatus(updateLutTxName, TransactionStatus.Processing);
292
293
  await retryWithExponentialBackoff(
293
- async (attemptNum) =>
294
- await sendSingleOptimizedTransaction(
295
- this.txHandler.umi,
296
- this.txHandler.connection,
297
- updateLookupTable.updateLutTx,
298
- this.txType,
299
- attemptNum,
300
- prioritySetting
301
- ),
294
+ async (attemptNum) => {
295
+ this.updateStatus(updateLutTxName, TransactionStatus.Processing, attemptNum);
296
+ try {
297
+ const txSig = await sendSingleOptimizedTransaction(
298
+ this.txHandler.umi,
299
+ this.txHandler.connection,
300
+ updateLookupTable.updateLutTx,
301
+ this.txType,
302
+ attemptNum,
303
+ prioritySetting
304
+ );
305
+ this.updateStatus(updateLutTxName, TransactionStatus.Successful, attemptNum, txSig ? bs58.encode(txSig) : undefined);
306
+ } catch (e) {
307
+ this.updateStatus(updateLutTxName, TransactionStatus.Failed, attemptNum);
308
+ throw e;
309
+ }
310
+ },
302
311
  3,
303
312
  150,
304
313
  this.errorsToThrow
305
314
  );
306
- this.updateStatus(updateLutTxName, TransactionStatus.Successful);
307
315
  }
308
316
 
309
317
  this.lookupTables.defaultLuts = client.defaultLookupTables();
@@ -371,7 +379,7 @@ export class TransactionsManager {
371
379
  const itemSets = await this.assembleTransactionSets(items);
372
380
  const statusesStartIdx = this.statuses.length;
373
381
  for (const itemSet of itemSets) {
374
- this.updateStatus(itemSet.name(), TransactionStatus.Queued);
382
+ this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
375
383
  }
376
384
 
377
385
  if (this.mustBeAtomic && itemSets.length > 1) {
@@ -411,6 +419,7 @@ export class TransactionsManager {
411
419
  ...newItemSets.map((x) => ({
412
420
  name: x.name(),
413
421
  status: TransactionStatus.Queued,
422
+ attemptNum: 0.
414
423
  }))
415
424
  );
416
425
  this.txHandler.log(this.statuses);
@@ -436,9 +445,9 @@ export class TransactionsManager {
436
445
  const tx = await itemSet.getSingleTransaction();
437
446
 
438
447
  if (tx.getInstructions().length === 0) {
439
- this.updateStatus(itemSet.name(), TransactionStatus.Skipped);
448
+ this.updateStatus(itemSet.name(), TransactionStatus.Skipped, attemptNum);
440
449
  } else {
441
- this.updateStatus(itemSet.name(), TransactionStatus.Processing);
450
+ this.updateStatus(itemSet.name(), TransactionStatus.Processing, attemptNum);
442
451
 
443
452
  if (this.txHandler.localTest) {
444
453
  await this.debugAccounts(itemSet, tx);
@@ -455,7 +464,8 @@ export class TransactionsManager {
455
464
  this.updateStatus(
456
465
  itemSet.name(),
457
466
  TransactionStatus.Successful,
458
- txSig ? bs58.encode(txSig) : undefined
467
+ attemptNum,
468
+ txSig ? bs58.encode(txSig) : undefined,
459
469
  );
460
470
  }
461
471
  },