@haven-fi/solauto-sdk 1.0.140 → 1.0.142
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,uBAAu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vB,OAAO,CAAC,MAAM,CAAC;IACf,OAAO,CAAC,YAAY,CAAC;IACrB,OAAO,CAAC,aAAa,CAAC;IARxB,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,YAAY,CAAe;gBAGzB,SAAS,EAAE,aAAa,GAAG,oBAAoB,EAC/C,cAAc,CAAC,GAAE,CAAC,QAAQ,EAAE,0BAA0B,KAAK,IAAI,aAAA,EAC/D,MAAM,CAAC,EAAE,kBAAkB,YAAA,EAC3B,YAAY,CAAC,EAAE,OAAO,YAAA,EACtB,aAAa,CAAC,EAAE,aAAa,YAAA;YAQzB,uBAAuB;IAwCrC,YAAY,CACV,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,MAAM;IAoBV,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;IAgGhC,IAAI,CACR,KAAK,EAAE,eAAe,EAAE,EACxB,eAAe,CAAC,EAAE,kBAAkB,EACpC,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,0BAA0B,CAAC;CAiIvC"}
|
@@ -27,7 +27,7 @@ class LookupTables {
|
|
27
27
|
return this.cache;
|
28
28
|
}
|
29
29
|
reset() {
|
30
|
-
this.cache = this.cache.filter(x => this.defaultLuts.includes(x.publicKey.toString()));
|
30
|
+
this.cache = this.cache.filter((x) => this.defaultLuts.includes(x.publicKey.toString()));
|
31
31
|
}
|
32
32
|
}
|
33
33
|
class TransactionItem {
|
@@ -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
|
-
|
203
|
-
|
204
|
-
|
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,21 @@ 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
|
-
|
305
|
-
|
314
|
+
try {
|
315
|
+
const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, this.txType, attemptNum, prioritySetting);
|
316
|
+
this.updateStatus(itemSet.name(), TransactionStatus.Successful, attemptNum, txSig ? bs58_1.default.encode(txSig) : undefined);
|
317
|
+
}
|
318
|
+
catch (e) {
|
319
|
+
this.updateStatus(itemSet.name(), TransactionStatus.Failed, attemptNum);
|
320
|
+
throw e;
|
321
|
+
}
|
306
322
|
}
|
307
323
|
}, 4, 150, this.errorsToThrow);
|
308
324
|
}
|
package/package.json
CHANGED
@@ -48,7 +48,9 @@ class LookupTables {
|
|
48
48
|
}
|
49
49
|
|
50
50
|
reset() {
|
51
|
-
this.cache = this.cache.filter(x =>
|
51
|
+
this.cache = this.cache.filter((x) =>
|
52
|
+
this.defaultLuts.includes(x.publicKey.toString())
|
53
|
+
);
|
52
54
|
}
|
53
55
|
}
|
54
56
|
|
@@ -172,12 +174,14 @@ export enum TransactionStatus {
|
|
172
174
|
Processing = "Processing",
|
173
175
|
Queued = "Queued",
|
174
176
|
Successful = "Successful",
|
177
|
+
Failed = "Failed",
|
175
178
|
}
|
176
179
|
|
177
180
|
export type TransactionManagerStatuses = {
|
178
181
|
name: string;
|
179
182
|
status: TransactionStatus;
|
180
183
|
txSig?: string;
|
184
|
+
attemptNum: number;
|
181
185
|
}[];
|
182
186
|
|
183
187
|
export class TransactionsManager {
|
@@ -237,16 +241,23 @@ export class TransactionsManager {
|
|
237
241
|
return transactionSets;
|
238
242
|
}
|
239
243
|
|
240
|
-
updateStatus(
|
244
|
+
updateStatus(
|
245
|
+
name: string,
|
246
|
+
status: TransactionStatus,
|
247
|
+
attemptNum: number,
|
248
|
+
txSig?: string
|
249
|
+
) {
|
241
250
|
if (!this.statuses.filter((x) => x.name === name)) {
|
242
|
-
this.statuses.push({ name, status, txSig });
|
251
|
+
this.statuses.push({ name, status, txSig, attemptNum });
|
243
252
|
} else {
|
244
|
-
const idx = this.statuses.findIndex(
|
253
|
+
const idx = this.statuses.findIndex(
|
254
|
+
(x) => x.name === name && x.attemptNum === attemptNum
|
255
|
+
);
|
245
256
|
if (idx !== -1) {
|
246
257
|
this.statuses[idx].status = status;
|
247
258
|
this.statuses[idx].txSig = txSig;
|
248
259
|
} else {
|
249
|
-
this.statuses.push({ name, status, txSig });
|
260
|
+
this.statuses.push({ name, status, txSig, attemptNum });
|
250
261
|
}
|
251
262
|
}
|
252
263
|
this.txHandler.log(`${name} is ${status.toString().toLowerCase()}`);
|
@@ -288,22 +299,41 @@ export class TransactionsManager {
|
|
288
299
|
updateLookupTable.updateLutTx.getInstructions().length > 0 &&
|
289
300
|
updateLookupTable?.needsToBeIsolated
|
290
301
|
) {
|
291
|
-
this.updateStatus(updateLutTxName, TransactionStatus.Processing);
|
292
302
|
await retryWithExponentialBackoff(
|
293
|
-
async (attemptNum) =>
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
303
|
+
async (attemptNum) => {
|
304
|
+
this.updateStatus(
|
305
|
+
updateLutTxName,
|
306
|
+
TransactionStatus.Processing,
|
307
|
+
attemptNum
|
308
|
+
);
|
309
|
+
try {
|
310
|
+
const txSig = await sendSingleOptimizedTransaction(
|
311
|
+
this.txHandler.umi,
|
312
|
+
this.txHandler.connection,
|
313
|
+
updateLookupTable.updateLutTx,
|
314
|
+
this.txType,
|
315
|
+
attemptNum,
|
316
|
+
prioritySetting
|
317
|
+
);
|
318
|
+
this.updateStatus(
|
319
|
+
updateLutTxName,
|
320
|
+
TransactionStatus.Successful,
|
321
|
+
attemptNum,
|
322
|
+
txSig ? bs58.encode(txSig) : undefined
|
323
|
+
);
|
324
|
+
} catch (e) {
|
325
|
+
this.updateStatus(
|
326
|
+
updateLutTxName,
|
327
|
+
TransactionStatus.Failed,
|
328
|
+
attemptNum
|
329
|
+
);
|
330
|
+
throw e;
|
331
|
+
}
|
332
|
+
},
|
302
333
|
3,
|
303
334
|
150,
|
304
335
|
this.errorsToThrow
|
305
336
|
);
|
306
|
-
this.updateStatus(updateLutTxName, TransactionStatus.Successful);
|
307
337
|
}
|
308
338
|
|
309
339
|
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
@@ -359,7 +389,7 @@ export class TransactionsManager {
|
|
359
389
|
prioritySetting?: PriorityFeeSetting,
|
360
390
|
initialized?: boolean
|
361
391
|
): Promise<TransactionManagerStatuses> {
|
362
|
-
this.statuses = []
|
392
|
+
this.statuses = [];
|
363
393
|
this.lookupTables.reset();
|
364
394
|
|
365
395
|
if (!initialized) {
|
@@ -371,7 +401,7 @@ export class TransactionsManager {
|
|
371
401
|
const itemSets = await this.assembleTransactionSets(items);
|
372
402
|
const statusesStartIdx = this.statuses.length;
|
373
403
|
for (const itemSet of itemSets) {
|
374
|
-
this.updateStatus(itemSet.name(), TransactionStatus.Queued);
|
404
|
+
this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
|
375
405
|
}
|
376
406
|
|
377
407
|
if (this.mustBeAtomic && itemSets.length > 1) {
|
@@ -411,6 +441,7 @@ export class TransactionsManager {
|
|
411
441
|
...newItemSets.map((x) => ({
|
412
442
|
name: x.name(),
|
413
443
|
status: TransactionStatus.Queued,
|
444
|
+
attemptNum: 0,
|
414
445
|
}))
|
415
446
|
);
|
416
447
|
this.txHandler.log(this.statuses);
|
@@ -436,27 +467,45 @@ export class TransactionsManager {
|
|
436
467
|
const tx = await itemSet.getSingleTransaction();
|
437
468
|
|
438
469
|
if (tx.getInstructions().length === 0) {
|
439
|
-
this.updateStatus(
|
470
|
+
this.updateStatus(
|
471
|
+
itemSet.name(),
|
472
|
+
TransactionStatus.Skipped,
|
473
|
+
attemptNum
|
474
|
+
);
|
440
475
|
} else {
|
441
|
-
this.updateStatus(
|
476
|
+
this.updateStatus(
|
477
|
+
itemSet.name(),
|
478
|
+
TransactionStatus.Processing,
|
479
|
+
attemptNum
|
480
|
+
);
|
442
481
|
|
443
482
|
if (this.txHandler.localTest) {
|
444
483
|
await this.debugAccounts(itemSet, tx);
|
445
484
|
}
|
446
485
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
486
|
+
try {
|
487
|
+
const txSig = await sendSingleOptimizedTransaction(
|
488
|
+
this.txHandler.umi,
|
489
|
+
this.txHandler.connection,
|
490
|
+
tx,
|
491
|
+
this.txType,
|
492
|
+
attemptNum,
|
493
|
+
prioritySetting
|
494
|
+
);
|
495
|
+
this.updateStatus(
|
496
|
+
itemSet.name(),
|
497
|
+
TransactionStatus.Successful,
|
498
|
+
attemptNum,
|
499
|
+
txSig ? bs58.encode(txSig) : undefined
|
500
|
+
);
|
501
|
+
} catch (e) {
|
502
|
+
this.updateStatus(
|
503
|
+
itemSet.name(),
|
504
|
+
TransactionStatus.Failed,
|
505
|
+
attemptNum
|
506
|
+
);
|
507
|
+
throw e;
|
508
|
+
}
|
460
509
|
}
|
461
510
|
},
|
462
511
|
4,
|