@haven-fi/solauto-sdk 1.0.238 → 1.0.239
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/transactions/transactionsManager.d.ts +5 -4
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +60 -64
- package/dist/types/solauto.d.ts +1 -0
- package/dist/types/solauto.d.ts.map +1 -1
- package/dist/types/solauto.js +2 -1
- package/dist/utils/generalUtils.d.ts +1 -1
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +3 -3
- package/package.json +1 -1
- package/src/transactions/transactionsManager.ts +89 -90
- package/src/types/solauto.ts +2 -0
- package/src/utils/generalUtils.ts +4 -4
@@ -35,18 +35,19 @@ export declare class TransactionsManager {
|
|
35
35
|
private txHandler;
|
36
36
|
private statusCallback?;
|
37
37
|
private txType?;
|
38
|
-
private
|
38
|
+
private priorityFeeSetting;
|
39
39
|
private errorsToThrow?;
|
40
40
|
private retries;
|
41
41
|
private retryDelay;
|
42
42
|
private statuses;
|
43
43
|
private lookupTables;
|
44
|
-
constructor(txHandler: SolautoClient | ReferralStateManager, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, txType?: TransactionRunType | undefined,
|
44
|
+
constructor(txHandler: SolautoClient | ReferralStateManager, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, txType?: TransactionRunType | undefined, priorityFeeSetting?: PriorityFeeSetting, errorsToThrow?: ErrorsToThrow | undefined, retries?: number, retryDelay?: number);
|
45
45
|
private assembleTransactionSets;
|
46
46
|
private updateStatus;
|
47
47
|
private debugAccounts;
|
48
|
-
|
49
|
-
|
48
|
+
private getUpdatedPriorityFeeSetting;
|
49
|
+
clientSend(transactions: TransactionItem[]): Promise<TransactionManagerStatuses>;
|
50
|
+
send(items: TransactionItem[], initialized?: boolean): Promise<TransactionManagerStatuses>;
|
50
51
|
private sendTransaction;
|
51
52
|
}
|
52
53
|
//# sourceMappingURL=transactionsManager.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,
|
1
|
+
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,EAElB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAI7D,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAqCD,qBAAa,eAAe;IAKjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IAPtB,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;gBAGf,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,EACxC,IAAI,CAAC,EAAE,MAAM,YAAA;IAGhB,UAAU;IAIV,OAAO,CAAC,UAAU,EAAE,MAAM;IAMhC,cAAc,IAAI,MAAM,EAAE;CAY3B;AAgFD,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,UAAU,eAAe;IACzB,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,0BAA0B,GAAG;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,EAAE,CAAC;AAEJ,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,MAAM,CAAC;IACf,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,UAAU;IAVpB,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,kBAAkB,GAAE,kBAA2C,EAC/D,aAAa,CAAC,EAAE,aAAa,YAAA,EAC7B,OAAO,GAAE,MAAU,EACnB,UAAU,GAAE,MAAY;YAQpB,uBAAuB;IAwCrC,OAAO,CAAC,YAAY;YA8CN,aAAa;IAoB3B,OAAO,CAAC,4BAA4B;IAUvB,UAAU,CACrB,YAAY,EAAE,eAAe,EAAE,GAC9B,OAAO,CAAC,0BAA0B,CAAC;IAyEzB,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,EACxB,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,0BAA0B,CAAC;YA6FxB,eAAe;CAkD9B"}
|
@@ -9,11 +9,13 @@ const umi_1 = require("@metaplex-foundation/umi");
|
|
9
9
|
const solanaUtils_1 = require("../utils/solanaUtils");
|
10
10
|
const generalUtils_1 = require("../utils/generalUtils");
|
11
11
|
const transactionUtils_1 = require("./transactionUtils");
|
12
|
+
const types_1 = require("../types");
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
12
14
|
// import { sendJitoBundledTransactions } from "../utils/jitoUtils";
|
13
15
|
class TransactionTooLargeError extends Error {
|
14
16
|
constructor(message) {
|
15
17
|
super(message);
|
16
|
-
this.name =
|
18
|
+
this.name = "TransactionTooLargeError";
|
17
19
|
Object.setPrototypeOf(this, TransactionTooLargeError.prototype);
|
18
20
|
}
|
19
21
|
}
|
@@ -127,11 +129,11 @@ var TransactionStatus;
|
|
127
129
|
TransactionStatus["Failed"] = "Failed";
|
128
130
|
})(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
|
129
131
|
class TransactionsManager {
|
130
|
-
constructor(txHandler, statusCallback, txType,
|
132
|
+
constructor(txHandler, statusCallback, txType, priorityFeeSetting = types_1.PriorityFeeSetting.Min, errorsToThrow, retries = 4, retryDelay = 150) {
|
131
133
|
this.txHandler = txHandler;
|
132
134
|
this.statusCallback = statusCallback;
|
133
135
|
this.txType = txType;
|
134
|
-
this.
|
136
|
+
this.priorityFeeSetting = priorityFeeSetting;
|
135
137
|
this.errorsToThrow = errorsToThrow;
|
136
138
|
this.retries = retries;
|
137
139
|
this.retryDelay = retryDelay;
|
@@ -222,7 +224,14 @@ class TransactionsManager {
|
|
222
224
|
}
|
223
225
|
}
|
224
226
|
}
|
225
|
-
|
227
|
+
getUpdatedPriorityFeeSetting(prevError) {
|
228
|
+
if (prevError instanceof web3_js_1.TransactionExpiredBlockheightExceededError) {
|
229
|
+
const currIdx = types_1.priorityFeeSettingValues.indexOf(this.priorityFeeSetting);
|
230
|
+
return types_1.priorityFeeSettingValues[Math.min(types_1.priorityFeeSettingValues.length - 1, currIdx + 1)];
|
231
|
+
}
|
232
|
+
return this.priorityFeeSetting;
|
233
|
+
}
|
234
|
+
async clientSend(transactions) {
|
226
235
|
const items = [...transactions];
|
227
236
|
const client = this.txHandler;
|
228
237
|
const updateLookupTable = await client.updateLookupTable();
|
@@ -230,7 +239,7 @@ class TransactionsManager {
|
|
230
239
|
if (updateLookupTable &&
|
231
240
|
updateLookupTable.updateLutTx.getInstructions().length > 0 &&
|
232
241
|
updateLookupTable?.needsToBeIsolated) {
|
233
|
-
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => await this.sendTransaction(updateLookupTable.updateLutTx, updateLutTxName, attemptNum,
|
242
|
+
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => await this.sendTransaction(updateLookupTable.updateLutTx, updateLutTxName, attemptNum, this.getUpdatedPriorityFeeSetting(prevError)), 3, 150, this.errorsToThrow);
|
234
243
|
}
|
235
244
|
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
236
245
|
for (const item of items) {
|
@@ -254,7 +263,7 @@ class TransactionsManager {
|
|
254
263
|
items.push(chore);
|
255
264
|
this.txHandler.log("Chores after: ", choresAfter.getInstructions().length);
|
256
265
|
}
|
257
|
-
const result = await this.send(items,
|
266
|
+
const result = await this.send(items, true).catch((e) => {
|
258
267
|
client.resetLiveTxUpdates(false);
|
259
268
|
throw e;
|
260
269
|
});
|
@@ -263,7 +272,7 @@ class TransactionsManager {
|
|
263
272
|
}
|
264
273
|
return result;
|
265
274
|
}
|
266
|
-
async send(items,
|
275
|
+
async send(items, initialized) {
|
267
276
|
this.statuses = [];
|
268
277
|
this.lookupTables.reset();
|
269
278
|
if (!initialized) {
|
@@ -276,69 +285,56 @@ class TransactionsManager {
|
|
276
285
|
for (const itemSet of itemSets) {
|
277
286
|
this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
|
278
287
|
}
|
279
|
-
if (this.
|
280
|
-
|
281
|
-
|
282
|
-
// this.updateStatus(set.name(), TransactionStatus.Processing);
|
283
|
-
// });
|
284
|
-
// await sendJitoBundledTransactions(
|
285
|
-
// this.client,
|
286
|
-
// await Promise.all(itemSets.map((x) => x.getSingleTransaction())),
|
287
|
-
// this.simulateOnly
|
288
|
-
// );
|
289
|
-
// TODO: check if successful or not
|
290
|
-
// itemSets.forEach((set) => {
|
291
|
-
// this.updateStatus(set.name(), TransactionStatus.Successful);
|
292
|
-
// });
|
288
|
+
if (this.txType === "only-simulate" && itemSets.length > 1) {
|
289
|
+
this.txHandler.log("Only simulate and more than 1 transaction. Skipping...");
|
290
|
+
return [];
|
293
291
|
}
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
}, this.retries, this.retryDelay, this.errorsToThrow);
|
334
|
-
}
|
292
|
+
for (let i = 0; i < itemSets.length; i++) {
|
293
|
+
const getFreshItemSet = async (itemSet, attemptNum) => {
|
294
|
+
await itemSet.refetchAll(attemptNum);
|
295
|
+
const newItemSets = await this.assembleTransactionSets([
|
296
|
+
...itemSet.items,
|
297
|
+
...itemSets
|
298
|
+
.slice(i + 1)
|
299
|
+
.map((x) => x.items)
|
300
|
+
.flat(),
|
301
|
+
]);
|
302
|
+
if (newItemSets.length > 1) {
|
303
|
+
this.statuses.splice(statusesStartIdx + i, itemSets.length - i, ...newItemSets.map((x) => ({
|
304
|
+
name: x.name(),
|
305
|
+
status: TransactionStatus.Queued,
|
306
|
+
attemptNum: 0,
|
307
|
+
})));
|
308
|
+
this.txHandler.log(this.statuses);
|
309
|
+
itemSets.splice(i + 1, itemSets.length - i - 1, ...newItemSets.slice(1));
|
310
|
+
}
|
311
|
+
return newItemSets.length > 0 ? newItemSets[0] : undefined;
|
312
|
+
};
|
313
|
+
let itemSet = itemSets[i];
|
314
|
+
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => {
|
315
|
+
itemSet =
|
316
|
+
i > 0 || attemptNum > 0
|
317
|
+
? await getFreshItemSet(itemSet, attemptNum)
|
318
|
+
: itemSet;
|
319
|
+
if (!itemSet) {
|
320
|
+
return;
|
321
|
+
}
|
322
|
+
const tx = await itemSet.getSingleTransaction();
|
323
|
+
if (tx.getInstructions().length === 0) {
|
324
|
+
this.updateStatus(itemSet.name(), TransactionStatus.Skipped, attemptNum);
|
325
|
+
}
|
326
|
+
else {
|
327
|
+
await this.debugAccounts(itemSet, tx);
|
328
|
+
await this.sendTransaction(tx, itemSet.name(), attemptNum, this.getUpdatedPriorityFeeSetting(prevError));
|
329
|
+
}
|
330
|
+
}, this.retries, this.retryDelay, this.errorsToThrow);
|
335
331
|
}
|
336
332
|
return this.statuses;
|
337
333
|
}
|
338
|
-
async sendTransaction(tx, txName, attemptNum,
|
334
|
+
async sendTransaction(tx, txName, attemptNum, priorityFeeSetting) {
|
339
335
|
this.updateStatus(txName, TransactionStatus.Processing, attemptNum);
|
340
336
|
try {
|
341
|
-
const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, this.txType,
|
337
|
+
const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, this.txType, priorityFeeSetting, () => this.updateStatus(txName, TransactionStatus.Processing, attemptNum, undefined, true));
|
342
338
|
this.updateStatus(txName, TransactionStatus.Successful, attemptNum, txSig ? bs58_1.default.encode(txSig) : undefined);
|
343
339
|
}
|
344
340
|
catch (e) {
|
package/dist/types/solauto.d.ts
CHANGED
@@ -18,6 +18,7 @@ export declare enum PriorityFeeSetting {
|
|
18
18
|
Default = "Medium",
|
19
19
|
High = "High"
|
20
20
|
}
|
21
|
+
export declare const priorityFeeSettingValues: PriorityFeeSetting[];
|
21
22
|
export type RebalanceAction = "boost" | "repay" | "dca";
|
22
23
|
export type TransactionRunType = "skip-simulation" | "only-simulate" | "normal";
|
23
24
|
export interface TransactionItemInputs {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,oBAAY,kBAAkB;IAC5B,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,OAAO,WAAW;IAClB,IAAI,SAAS;CACd;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;AAExD,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG,eAAe,GAAG,QAAQ,CAAC;AAEhF,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;CACjC"}
|
1
|
+
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,oBAAY,kBAAkB;IAC5B,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,OAAO,WAAW;IAClB,IAAI,SAAS;CACd;AAED,eAAO,MAAM,wBAAwB,EAAwC,kBAAkB,EAAE,CAAC;AAElG,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;AAExD,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG,eAAe,GAAG,QAAQ,CAAC;AAEhF,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;CACjC"}
|
package/dist/types/solauto.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.PriorityFeeSetting = void 0;
|
3
|
+
exports.priorityFeeSettingValues = exports.PriorityFeeSetting = void 0;
|
4
4
|
var PriorityFeeSetting;
|
5
5
|
(function (PriorityFeeSetting) {
|
6
6
|
PriorityFeeSetting["None"] = "None";
|
@@ -9,3 +9,4 @@ var PriorityFeeSetting;
|
|
9
9
|
PriorityFeeSetting["Default"] = "Medium";
|
10
10
|
PriorityFeeSetting["High"] = "High";
|
11
11
|
})(PriorityFeeSetting || (exports.PriorityFeeSetting = PriorityFeeSetting = {}));
|
12
|
+
exports.priorityFeeSettingValues = Object.values(PriorityFeeSetting);
|
@@ -10,5 +10,5 @@ export declare function arraysAreEqual(arrayA: number[], arrayB: number[]): bool
|
|
10
10
|
export declare function fetchTokenPrices(mints: PublicKey[]): Promise<number[]>;
|
11
11
|
export declare function safeGetPrice(mint: PublicKey | UmiPublicKey | undefined): number | undefined;
|
12
12
|
export type ErrorsToThrow = Array<new (...args: any[]) => Error>;
|
13
|
-
export declare function retryWithExponentialBackoff<T>(fn: (attemptNum: number) => Promise<T>, retries?: number, delay?: number, errorsToThrow?: ErrorsToThrow): Promise<T>;
|
13
|
+
export declare function retryWithExponentialBackoff<T>(fn: (attemptNum: number, prevErr?: Error) => Promise<T>, retries?: number, delay?: number, errorsToThrow?: ErrorsToThrow): Promise<T>;
|
14
14
|
//# sourceMappingURL=generalUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,eAAe,EAEf,GAAG,EACH,SAAS,IAAI,YAAY,EAC1B,MAAM,0BAA0B,CAAC;AAKlC,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAI/C;AACD,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,SAAS,GACZ,OAAO,CAAC,OAAO,CAAC,CAKlB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEnE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAU1E;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAsD5E;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB;AAED,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC,CAAC;AAEjE,wBAAgB,2BAA2B,CAAC,CAAC,EAC3C,EAAE,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,eAAe,EAEf,GAAG,EACH,SAAS,IAAI,YAAY,EAC1B,MAAM,0BAA0B,CAAC;AAKlC,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAI/C;AACD,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,SAAS,GACZ,OAAO,CAAC,OAAO,CAAC,CAKlB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEnE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAU1E;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAsD5E;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB;AAED,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC,CAAC;AAEjE,wBAAgB,2BAA2B,CAAC,CAAC,EAC3C,EAAE,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,EACvD,OAAO,GAAE,MAAU,EACnB,KAAK,GAAE,MAAY,EACnB,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,CAAC,CAAC,CA8BZ"}
|
@@ -97,8 +97,8 @@ function safeGetPrice(mint) {
|
|
97
97
|
}
|
98
98
|
function retryWithExponentialBackoff(fn, retries = 5, delay = 150, errorsToThrow) {
|
99
99
|
return new Promise((resolve, reject) => {
|
100
|
-
const attempt = (attemptNum) => {
|
101
|
-
fn(attemptNum)
|
100
|
+
const attempt = (attemptNum, prevErr) => {
|
101
|
+
fn(attemptNum, prevErr)
|
102
102
|
.then(resolve)
|
103
103
|
.catch((error) => {
|
104
104
|
attemptNum++;
|
@@ -111,7 +111,7 @@ function retryWithExponentialBackoff(fn, retries = 5, delay = 150, errorsToThrow
|
|
111
111
|
consoleLog(error);
|
112
112
|
setTimeout(() => {
|
113
113
|
consoleLog("Retrying...");
|
114
|
-
return attempt(attemptNum);
|
114
|
+
return attempt(attemptNum, error);
|
115
115
|
}, delay);
|
116
116
|
delay *= 2;
|
117
117
|
}
|
package/package.json
CHANGED
@@ -17,16 +17,18 @@ import {
|
|
17
17
|
import { getErrorInfo, getTransactionChores } from "./transactionUtils";
|
18
18
|
import {
|
19
19
|
PriorityFeeSetting,
|
20
|
+
priorityFeeSettingValues,
|
20
21
|
TransactionItemInputs,
|
21
22
|
TransactionRunType,
|
22
23
|
} from "../types";
|
23
24
|
import { ReferralStateManager, TxHandler } from "../clients";
|
25
|
+
import { TransactionExpiredBlockheightExceededError } from "@solana/web3.js";
|
24
26
|
// import { sendJitoBundledTransactions } from "../utils/jitoUtils";
|
25
27
|
|
26
28
|
export class TransactionTooLargeError extends Error {
|
27
29
|
constructor(message: string) {
|
28
30
|
super(message);
|
29
|
-
this.name =
|
31
|
+
this.name = "TransactionTooLargeError";
|
30
32
|
Object.setPrototypeOf(this, TransactionTooLargeError.prototype);
|
31
33
|
}
|
32
34
|
}
|
@@ -204,10 +206,10 @@ export class TransactionsManager {
|
|
204
206
|
private txHandler: SolautoClient | ReferralStateManager,
|
205
207
|
private statusCallback?: (statuses: TransactionManagerStatuses) => void,
|
206
208
|
private txType?: TransactionRunType,
|
207
|
-
private
|
209
|
+
private priorityFeeSetting: PriorityFeeSetting = PriorityFeeSetting.Min,
|
208
210
|
private errorsToThrow?: ErrorsToThrow,
|
209
211
|
private retries: number = 4,
|
210
|
-
private retryDelay: number = 150
|
212
|
+
private retryDelay: number = 150
|
211
213
|
) {
|
212
214
|
this.lookupTables = new LookupTables(
|
213
215
|
this.txHandler.defaultLookupTables(),
|
@@ -321,9 +323,18 @@ export class TransactionsManager {
|
|
321
323
|
}
|
322
324
|
}
|
323
325
|
|
326
|
+
private getUpdatedPriorityFeeSetting(prevError?: Error) {
|
327
|
+
if (prevError instanceof TransactionExpiredBlockheightExceededError) {
|
328
|
+
const currIdx = priorityFeeSettingValues.indexOf(this.priorityFeeSetting);
|
329
|
+
return priorityFeeSettingValues[
|
330
|
+
Math.min(priorityFeeSettingValues.length - 1, currIdx + 1)
|
331
|
+
];
|
332
|
+
}
|
333
|
+
return this.priorityFeeSetting;
|
334
|
+
}
|
335
|
+
|
324
336
|
public async clientSend(
|
325
|
-
transactions: TransactionItem[]
|
326
|
-
prioritySetting?: PriorityFeeSetting
|
337
|
+
transactions: TransactionItem[]
|
327
338
|
): Promise<TransactionManagerStatuses> {
|
328
339
|
const items = [...transactions];
|
329
340
|
const client = this.txHandler as SolautoClient;
|
@@ -336,12 +347,12 @@ export class TransactionsManager {
|
|
336
347
|
updateLookupTable?.needsToBeIsolated
|
337
348
|
) {
|
338
349
|
await retryWithExponentialBackoff(
|
339
|
-
async (attemptNum) =>
|
350
|
+
async (attemptNum, prevError) =>
|
340
351
|
await this.sendTransaction(
|
341
352
|
updateLookupTable.updateLutTx,
|
342
353
|
updateLutTxName,
|
343
354
|
attemptNum,
|
344
|
-
|
355
|
+
this.getUpdatedPriorityFeeSetting(prevError)
|
345
356
|
),
|
346
357
|
3,
|
347
358
|
150,
|
@@ -385,7 +396,7 @@ export class TransactionsManager {
|
|
385
396
|
);
|
386
397
|
}
|
387
398
|
|
388
|
-
const result = await this.send(items,
|
399
|
+
const result = await this.send(items, true).catch((e) => {
|
389
400
|
client.resetLiveTxUpdates(false);
|
390
401
|
throw e;
|
391
402
|
});
|
@@ -399,7 +410,6 @@ export class TransactionsManager {
|
|
399
410
|
|
400
411
|
public async send(
|
401
412
|
items: TransactionItem[],
|
402
|
-
prioritySetting?: PriorityFeeSetting,
|
403
413
|
initialized?: boolean
|
404
414
|
): Promise<TransactionManagerStatuses> {
|
405
415
|
this.statuses = [];
|
@@ -417,89 +427,78 @@ export class TransactionsManager {
|
|
417
427
|
this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
|
418
428
|
}
|
419
429
|
|
420
|
-
if (this.
|
421
|
-
|
422
|
-
|
430
|
+
if (this.txType === "only-simulate" && itemSets.length > 1) {
|
431
|
+
this.txHandler.log(
|
432
|
+
"Only simulate and more than 1 transaction. Skipping..."
|
423
433
|
);
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
...
|
445
|
-
|
446
|
-
.
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
434
|
+
return [];
|
435
|
+
}
|
436
|
+
|
437
|
+
for (let i = 0; i < itemSets.length; i++) {
|
438
|
+
const getFreshItemSet = async (
|
439
|
+
itemSet: TransactionSet,
|
440
|
+
attemptNum: number
|
441
|
+
) => {
|
442
|
+
await itemSet.refetchAll(attemptNum);
|
443
|
+
const newItemSets = await this.assembleTransactionSets([
|
444
|
+
...itemSet.items,
|
445
|
+
...itemSets
|
446
|
+
.slice(i + 1)
|
447
|
+
.map((x) => x.items)
|
448
|
+
.flat(),
|
449
|
+
]);
|
450
|
+
if (newItemSets.length > 1) {
|
451
|
+
this.statuses.splice(
|
452
|
+
statusesStartIdx + i,
|
453
|
+
itemSets.length - i,
|
454
|
+
...newItemSets.map((x) => ({
|
455
|
+
name: x.name(),
|
456
|
+
status: TransactionStatus.Queued,
|
457
|
+
attemptNum: 0,
|
458
|
+
}))
|
459
|
+
);
|
460
|
+
this.txHandler.log(this.statuses);
|
461
|
+
itemSets.splice(
|
462
|
+
i + 1,
|
463
|
+
itemSets.length - i - 1,
|
464
|
+
...newItemSets.slice(1)
|
465
|
+
);
|
466
|
+
}
|
467
|
+
return newItemSets.length > 0 ? newItemSets[0] : undefined;
|
468
|
+
};
|
469
|
+
|
470
|
+
let itemSet: TransactionSet | undefined = itemSets[i];
|
471
|
+
await retryWithExponentialBackoff(
|
472
|
+
async (attemptNum, prevError) => {
|
473
|
+
itemSet =
|
474
|
+
i > 0 || attemptNum > 0
|
475
|
+
? await getFreshItemSet(itemSet!, attemptNum)
|
476
|
+
: itemSet;
|
477
|
+
if (!itemSet) {
|
478
|
+
return;
|
479
|
+
}
|
480
|
+
const tx = await itemSet.getSingleTransaction();
|
481
|
+
|
482
|
+
if (tx.getInstructions().length === 0) {
|
483
|
+
this.updateStatus(
|
484
|
+
itemSet.name(),
|
485
|
+
TransactionStatus.Skipped,
|
486
|
+
attemptNum
|
459
487
|
);
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
488
|
+
} else {
|
489
|
+
await this.debugAccounts(itemSet, tx);
|
490
|
+
await this.sendTransaction(
|
491
|
+
tx,
|
492
|
+
itemSet.name(),
|
493
|
+
attemptNum,
|
494
|
+
this.getUpdatedPriorityFeeSetting(prevError)
|
465
495
|
);
|
466
496
|
}
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
async (attemptNum) => {
|
473
|
-
itemSet =
|
474
|
-
i > 0 || attemptNum > 0
|
475
|
-
? await getFreshItemSet(itemSet!, attemptNum)
|
476
|
-
: itemSet;
|
477
|
-
if (!itemSet) {
|
478
|
-
return;
|
479
|
-
}
|
480
|
-
const tx = await itemSet.getSingleTransaction();
|
481
|
-
|
482
|
-
if (tx.getInstructions().length === 0) {
|
483
|
-
this.updateStatus(
|
484
|
-
itemSet.name(),
|
485
|
-
TransactionStatus.Skipped,
|
486
|
-
attemptNum
|
487
|
-
);
|
488
|
-
} else {
|
489
|
-
await this.debugAccounts(itemSet, tx);
|
490
|
-
await this.sendTransaction(
|
491
|
-
tx,
|
492
|
-
itemSet.name(),
|
493
|
-
attemptNum,
|
494
|
-
prioritySetting
|
495
|
-
);
|
496
|
-
}
|
497
|
-
},
|
498
|
-
this.retries,
|
499
|
-
this.retryDelay,
|
500
|
-
this.errorsToThrow
|
501
|
-
);
|
502
|
-
}
|
497
|
+
},
|
498
|
+
this.retries,
|
499
|
+
this.retryDelay,
|
500
|
+
this.errorsToThrow
|
501
|
+
);
|
503
502
|
}
|
504
503
|
|
505
504
|
return this.statuses;
|
@@ -509,7 +508,7 @@ export class TransactionsManager {
|
|
509
508
|
tx: TransactionBuilder,
|
510
509
|
txName: string,
|
511
510
|
attemptNum: number,
|
512
|
-
|
511
|
+
priorityFeeSetting?: PriorityFeeSetting
|
513
512
|
) {
|
514
513
|
this.updateStatus(txName, TransactionStatus.Processing, attemptNum);
|
515
514
|
try {
|
@@ -518,7 +517,7 @@ export class TransactionsManager {
|
|
518
517
|
this.txHandler.connection,
|
519
518
|
tx,
|
520
519
|
this.txType,
|
521
|
-
|
520
|
+
priorityFeeSetting,
|
522
521
|
() =>
|
523
522
|
this.updateStatus(
|
524
523
|
txName,
|
package/src/types/solauto.ts
CHANGED
@@ -21,6 +21,8 @@ export enum PriorityFeeSetting {
|
|
21
21
|
High = "High",
|
22
22
|
}
|
23
23
|
|
24
|
+
export const priorityFeeSettingValues = Object.values(PriorityFeeSetting) as PriorityFeeSetting[];
|
25
|
+
|
24
26
|
export type RebalanceAction = "boost" | "repay" | "dca";
|
25
27
|
|
26
28
|
export type TransactionRunType = "skip-simulation" | "only-simulate" | "normal";
|
@@ -125,14 +125,14 @@ export function safeGetPrice(
|
|
125
125
|
export type ErrorsToThrow = Array<new (...args: any[]) => Error>;
|
126
126
|
|
127
127
|
export function retryWithExponentialBackoff<T>(
|
128
|
-
fn: (attemptNum: number) => Promise<T>,
|
128
|
+
fn: (attemptNum: number, prevErr?: Error) => Promise<T>,
|
129
129
|
retries: number = 5,
|
130
130
|
delay: number = 150,
|
131
131
|
errorsToThrow?: ErrorsToThrow
|
132
132
|
): Promise<T> {
|
133
133
|
return new Promise((resolve, reject) => {
|
134
|
-
const attempt = (attemptNum: number) => {
|
135
|
-
fn(attemptNum)
|
134
|
+
const attempt = (attemptNum: number, prevErr?: Error) => {
|
135
|
+
fn(attemptNum, prevErr)
|
136
136
|
.then(resolve)
|
137
137
|
.catch((error: Error) => {
|
138
138
|
attemptNum++;
|
@@ -149,7 +149,7 @@ export function retryWithExponentialBackoff<T>(
|
|
149
149
|
consoleLog(error);
|
150
150
|
setTimeout(() => {
|
151
151
|
consoleLog("Retrying...");
|
152
|
-
return attempt(attemptNum);
|
152
|
+
return attempt(attemptNum, error);
|
153
153
|
}, delay);
|
154
154
|
delay *= 2;
|
155
155
|
} else {
|