@haven-fi/solauto-sdk 1.0.237 → 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 +8 -4
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +69 -65
- 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 +98 -91
- package/src/types/solauto.ts +2 -0
- package/src/utils/generalUtils.ts +4 -4
@@ -3,6 +3,9 @@ import { SolautoClient } from "../clients/solautoClient";
|
|
3
3
|
import { ErrorsToThrow } from "../utils/generalUtils";
|
4
4
|
import { PriorityFeeSetting, TransactionItemInputs, TransactionRunType } from "../types";
|
5
5
|
import { ReferralStateManager } from "../clients";
|
6
|
+
export declare class TransactionTooLargeError extends Error {
|
7
|
+
constructor(message: string);
|
8
|
+
}
|
6
9
|
export declare class TransactionItem {
|
7
10
|
fetchTx: (attemptNum: number) => Promise<TransactionItemInputs | undefined>;
|
8
11
|
name?: string | undefined;
|
@@ -32,18 +35,19 @@ export declare class TransactionsManager {
|
|
32
35
|
private txHandler;
|
33
36
|
private statusCallback?;
|
34
37
|
private txType?;
|
35
|
-
private
|
38
|
+
private priorityFeeSetting;
|
36
39
|
private errorsToThrow?;
|
37
40
|
private retries;
|
38
41
|
private retryDelay;
|
39
42
|
private statuses;
|
40
43
|
private lookupTables;
|
41
|
-
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);
|
42
45
|
private assembleTransactionSets;
|
43
46
|
private updateStatus;
|
44
47
|
private debugAccounts;
|
45
|
-
|
46
|
-
|
48
|
+
private getUpdatedPriorityFeeSetting;
|
49
|
+
clientSend(transactions: TransactionItem[]): Promise<TransactionManagerStatuses>;
|
50
|
+
send(items: TransactionItem[], initialized?: boolean): Promise<TransactionManagerStatuses>;
|
47
51
|
private sendTransaction;
|
48
52
|
}
|
49
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,EA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C,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"}
|
@@ -3,13 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.TransactionsManager = exports.TransactionStatus = exports.TransactionItem = void 0;
|
6
|
+
exports.TransactionsManager = exports.TransactionStatus = exports.TransactionItem = exports.TransactionTooLargeError = void 0;
|
7
7
|
const bs58_1 = __importDefault(require("bs58"));
|
8
8
|
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";
|
15
|
+
class TransactionTooLargeError extends Error {
|
16
|
+
constructor(message) {
|
17
|
+
super(message);
|
18
|
+
this.name = "TransactionTooLargeError";
|
19
|
+
Object.setPrototypeOf(this, TransactionTooLargeError.prototype);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
exports.TransactionTooLargeError = TransactionTooLargeError;
|
13
23
|
class LookupTables {
|
14
24
|
constructor(defaultLuts, umi) {
|
15
25
|
this.defaultLuts = defaultLuts;
|
@@ -119,11 +129,11 @@ var TransactionStatus;
|
|
119
129
|
TransactionStatus["Failed"] = "Failed";
|
120
130
|
})(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
|
121
131
|
class TransactionsManager {
|
122
|
-
constructor(txHandler, statusCallback, txType,
|
132
|
+
constructor(txHandler, statusCallback, txType, priorityFeeSetting = types_1.PriorityFeeSetting.Min, errorsToThrow, retries = 4, retryDelay = 150) {
|
123
133
|
this.txHandler = txHandler;
|
124
134
|
this.statusCallback = statusCallback;
|
125
135
|
this.txType = txType;
|
126
|
-
this.
|
136
|
+
this.priorityFeeSetting = priorityFeeSetting;
|
127
137
|
this.errorsToThrow = errorsToThrow;
|
128
138
|
this.retries = retries;
|
129
139
|
this.retryDelay = retryDelay;
|
@@ -141,7 +151,7 @@ class TransactionsManager {
|
|
141
151
|
}
|
142
152
|
const transaction = item.tx.setAddressLookupTables(await this.lookupTables.getLutInputs(item.lookupTableAddresses));
|
143
153
|
if (!transaction.fitsInOneTransaction(this.txHandler.umi)) {
|
144
|
-
throw new
|
154
|
+
throw new TransactionTooLargeError(`Exceeds max transaction size (${transaction.getTransactionSize(this.txHandler.umi)})`);
|
145
155
|
}
|
146
156
|
else {
|
147
157
|
let newSet = new TransactionSet(this.txHandler, this.lookupTables, [
|
@@ -214,7 +224,14 @@ class TransactionsManager {
|
|
214
224
|
}
|
215
225
|
}
|
216
226
|
}
|
217
|
-
|
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) {
|
218
235
|
const items = [...transactions];
|
219
236
|
const client = this.txHandler;
|
220
237
|
const updateLookupTable = await client.updateLookupTable();
|
@@ -222,7 +239,7 @@ class TransactionsManager {
|
|
222
239
|
if (updateLookupTable &&
|
223
240
|
updateLookupTable.updateLutTx.getInstructions().length > 0 &&
|
224
241
|
updateLookupTable?.needsToBeIsolated) {
|
225
|
-
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);
|
226
243
|
}
|
227
244
|
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
228
245
|
for (const item of items) {
|
@@ -246,7 +263,7 @@ class TransactionsManager {
|
|
246
263
|
items.push(chore);
|
247
264
|
this.txHandler.log("Chores after: ", choresAfter.getInstructions().length);
|
248
265
|
}
|
249
|
-
const result = await this.send(items,
|
266
|
+
const result = await this.send(items, true).catch((e) => {
|
250
267
|
client.resetLiveTxUpdates(false);
|
251
268
|
throw e;
|
252
269
|
});
|
@@ -255,7 +272,7 @@ class TransactionsManager {
|
|
255
272
|
}
|
256
273
|
return result;
|
257
274
|
}
|
258
|
-
async send(items,
|
275
|
+
async send(items, initialized) {
|
259
276
|
this.statuses = [];
|
260
277
|
this.lookupTables.reset();
|
261
278
|
if (!initialized) {
|
@@ -268,69 +285,56 @@ class TransactionsManager {
|
|
268
285
|
for (const itemSet of itemSets) {
|
269
286
|
this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
|
270
287
|
}
|
271
|
-
if (this.
|
272
|
-
|
273
|
-
|
274
|
-
// this.updateStatus(set.name(), TransactionStatus.Processing);
|
275
|
-
// });
|
276
|
-
// await sendJitoBundledTransactions(
|
277
|
-
// this.client,
|
278
|
-
// await Promise.all(itemSets.map((x) => x.getSingleTransaction())),
|
279
|
-
// this.simulateOnly
|
280
|
-
// );
|
281
|
-
// TODO: check if successful or not
|
282
|
-
// itemSets.forEach((set) => {
|
283
|
-
// this.updateStatus(set.name(), TransactionStatus.Successful);
|
284
|
-
// });
|
288
|
+
if (this.txType === "only-simulate" && itemSets.length > 1) {
|
289
|
+
this.txHandler.log("Only simulate and more than 1 transaction. Skipping...");
|
290
|
+
return [];
|
285
291
|
}
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
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
|
-
}, this.retries, this.retryDelay, this.errorsToThrow);
|
326
|
-
}
|
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);
|
327
331
|
}
|
328
332
|
return this.statuses;
|
329
333
|
}
|
330
|
-
async sendTransaction(tx, txName, attemptNum,
|
334
|
+
async sendTransaction(tx, txName, attemptNum, priorityFeeSetting) {
|
331
335
|
this.updateStatus(txName, TransactionStatus.Processing, attemptNum);
|
332
336
|
try {
|
333
|
-
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));
|
334
338
|
this.updateStatus(txName, TransactionStatus.Successful, attemptNum, txSig ? bs58_1.default.encode(txSig) : undefined);
|
335
339
|
}
|
336
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,GAA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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,12 +17,22 @@ 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
|
|
28
|
+
export class TransactionTooLargeError extends Error {
|
29
|
+
constructor(message: string) {
|
30
|
+
super(message);
|
31
|
+
this.name = "TransactionTooLargeError";
|
32
|
+
Object.setPrototypeOf(this, TransactionTooLargeError.prototype);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
26
36
|
class LookupTables {
|
27
37
|
cache: AddressLookupTableInput[] = [];
|
28
38
|
|
@@ -196,10 +206,10 @@ export class TransactionsManager {
|
|
196
206
|
private txHandler: SolautoClient | ReferralStateManager,
|
197
207
|
private statusCallback?: (statuses: TransactionManagerStatuses) => void,
|
198
208
|
private txType?: TransactionRunType,
|
199
|
-
private
|
209
|
+
private priorityFeeSetting: PriorityFeeSetting = PriorityFeeSetting.Min,
|
200
210
|
private errorsToThrow?: ErrorsToThrow,
|
201
211
|
private retries: number = 4,
|
202
|
-
private retryDelay: number = 150
|
212
|
+
private retryDelay: number = 150
|
203
213
|
) {
|
204
214
|
this.lookupTables = new LookupTables(
|
205
215
|
this.txHandler.defaultLookupTables(),
|
@@ -225,8 +235,8 @@ export class TransactionsManager {
|
|
225
235
|
await this.lookupTables.getLutInputs(item.lookupTableAddresses)
|
226
236
|
);
|
227
237
|
if (!transaction.fitsInOneTransaction(this.txHandler.umi)) {
|
228
|
-
throw new
|
229
|
-
`
|
238
|
+
throw new TransactionTooLargeError(
|
239
|
+
`Exceeds max transaction size (${transaction.getTransactionSize(this.txHandler.umi)})`
|
230
240
|
);
|
231
241
|
} else {
|
232
242
|
let newSet = new TransactionSet(this.txHandler, this.lookupTables, [
|
@@ -313,9 +323,18 @@ export class TransactionsManager {
|
|
313
323
|
}
|
314
324
|
}
|
315
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
|
+
|
316
336
|
public async clientSend(
|
317
|
-
transactions: TransactionItem[]
|
318
|
-
prioritySetting?: PriorityFeeSetting
|
337
|
+
transactions: TransactionItem[]
|
319
338
|
): Promise<TransactionManagerStatuses> {
|
320
339
|
const items = [...transactions];
|
321
340
|
const client = this.txHandler as SolautoClient;
|
@@ -328,12 +347,12 @@ export class TransactionsManager {
|
|
328
347
|
updateLookupTable?.needsToBeIsolated
|
329
348
|
) {
|
330
349
|
await retryWithExponentialBackoff(
|
331
|
-
async (attemptNum) =>
|
350
|
+
async (attemptNum, prevError) =>
|
332
351
|
await this.sendTransaction(
|
333
352
|
updateLookupTable.updateLutTx,
|
334
353
|
updateLutTxName,
|
335
354
|
attemptNum,
|
336
|
-
|
355
|
+
this.getUpdatedPriorityFeeSetting(prevError)
|
337
356
|
),
|
338
357
|
3,
|
339
358
|
150,
|
@@ -377,7 +396,7 @@ export class TransactionsManager {
|
|
377
396
|
);
|
378
397
|
}
|
379
398
|
|
380
|
-
const result = await this.send(items,
|
399
|
+
const result = await this.send(items, true).catch((e) => {
|
381
400
|
client.resetLiveTxUpdates(false);
|
382
401
|
throw e;
|
383
402
|
});
|
@@ -391,7 +410,6 @@ export class TransactionsManager {
|
|
391
410
|
|
392
411
|
public async send(
|
393
412
|
items: TransactionItem[],
|
394
|
-
prioritySetting?: PriorityFeeSetting,
|
395
413
|
initialized?: boolean
|
396
414
|
): Promise<TransactionManagerStatuses> {
|
397
415
|
this.statuses = [];
|
@@ -409,89 +427,78 @@ export class TransactionsManager {
|
|
409
427
|
this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
|
410
428
|
}
|
411
429
|
|
412
|
-
if (this.
|
413
|
-
|
414
|
-
|
430
|
+
if (this.txType === "only-simulate" && itemSets.length > 1) {
|
431
|
+
this.txHandler.log(
|
432
|
+
"Only simulate and more than 1 transaction. Skipping..."
|
415
433
|
);
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
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
|
-
|
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
|
451
487
|
);
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
488
|
+
} else {
|
489
|
+
await this.debugAccounts(itemSet, tx);
|
490
|
+
await this.sendTransaction(
|
491
|
+
tx,
|
492
|
+
itemSet.name(),
|
493
|
+
attemptNum,
|
494
|
+
this.getUpdatedPriorityFeeSetting(prevError)
|
457
495
|
);
|
458
496
|
}
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
async (attemptNum) => {
|
465
|
-
itemSet =
|
466
|
-
i > 0 || attemptNum > 0
|
467
|
-
? await getFreshItemSet(itemSet!, attemptNum)
|
468
|
-
: itemSet;
|
469
|
-
if (!itemSet) {
|
470
|
-
return;
|
471
|
-
}
|
472
|
-
const tx = await itemSet.getSingleTransaction();
|
473
|
-
|
474
|
-
if (tx.getInstructions().length === 0) {
|
475
|
-
this.updateStatus(
|
476
|
-
itemSet.name(),
|
477
|
-
TransactionStatus.Skipped,
|
478
|
-
attemptNum
|
479
|
-
);
|
480
|
-
} else {
|
481
|
-
await this.debugAccounts(itemSet, tx);
|
482
|
-
await this.sendTransaction(
|
483
|
-
tx,
|
484
|
-
itemSet.name(),
|
485
|
-
attemptNum,
|
486
|
-
prioritySetting
|
487
|
-
);
|
488
|
-
}
|
489
|
-
},
|
490
|
-
this.retries,
|
491
|
-
this.retryDelay,
|
492
|
-
this.errorsToThrow
|
493
|
-
);
|
494
|
-
}
|
497
|
+
},
|
498
|
+
this.retries,
|
499
|
+
this.retryDelay,
|
500
|
+
this.errorsToThrow
|
501
|
+
);
|
495
502
|
}
|
496
503
|
|
497
504
|
return this.statuses;
|
@@ -501,7 +508,7 @@ export class TransactionsManager {
|
|
501
508
|
tx: TransactionBuilder,
|
502
509
|
txName: string,
|
503
510
|
attemptNum: number,
|
504
|
-
|
511
|
+
priorityFeeSetting?: PriorityFeeSetting
|
505
512
|
) {
|
506
513
|
this.updateStatus(txName, TransactionStatus.Processing, attemptNum);
|
507
514
|
try {
|
@@ -510,7 +517,7 @@ export class TransactionsManager {
|
|
510
517
|
this.txHandler.connection,
|
511
518
|
tx,
|
512
519
|
this.txType,
|
513
|
-
|
520
|
+
priorityFeeSetting,
|
514
521
|
() =>
|
515
522
|
this.updateStatus(
|
516
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 {
|