@haven-fi/solauto-sdk 1.0.244 → 1.0.245
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.
- package/dist/clients/solautoClient.d.ts +3 -2
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +14 -11
- package/dist/transactions/transactionsManager.d.ts +3 -1
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +31 -12
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +25 -17
- package/src/transactions/transactionsManager.ts +47 -26
@@ -42,8 +42,9 @@ export declare abstract class SolautoClient extends ReferralStateManager {
|
|
42
42
|
lutAccountsToAdd(): PublicKey[];
|
43
43
|
fetchExistingAuthorityLutAccounts(): Promise<PublicKey[]>;
|
44
44
|
updateLookupTable(): Promise<{
|
45
|
-
|
46
|
-
|
45
|
+
tx: TransactionBuilder;
|
46
|
+
new: boolean;
|
47
|
+
accountsToAdd: PublicKey[];
|
47
48
|
} | undefined>;
|
48
49
|
solautoPositionSettings(): SolautoSettingsParameters | undefined;
|
49
50
|
solautoPositionActiveDca(): DCASettings | undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAEhC,sBAAsB,EAKvB,MAAM,cAAc,CAAC;AAUtB,OAAO,EACL,gBAAgB,EAChB,eAAe,EAChB,MAAM,iCAAiC,CAAC;AAMzC,OAAO,EAAE,mBAAmB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AgB,CAAC,IAAI,EAAE,sBAAsB,GAAG,kBAAkB;IAwDlE,eAAe,IAAI,kBAAkB;IAYrC,WAAW,IAAI,kBAAkB;IAgCjC,QAAQ,CAAC,OAAO,IAAI,kBAAkB;IAEtC,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAuFhE,QAAQ,CAAC,WAAW,CAClB,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IAErB,QAAQ,CAAC,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAE3E,QAAQ,CAAC,SAAS,CAChB,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,eAAe,EAAE,eAAe,EAChC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAalE"}
|
@@ -145,18 +145,21 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
145
145
|
const accountsToAdd = this.lutAccountsToAdd().filter((x) => !existingLutAccounts
|
146
146
|
.map((x) => x.toString().toLowerCase())
|
147
147
|
.includes(x.toString().toLowerCase()));
|
148
|
-
if (accountsToAdd.length
|
149
|
-
|
150
|
-
payer: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey),
|
151
|
-
authority: this.authority,
|
152
|
-
lookupTable: this.authorityLutAddress,
|
153
|
-
addresses: accountsToAdd,
|
154
|
-
})));
|
155
|
-
}
|
156
|
-
if (tx.getInstructions().length > 0) {
|
157
|
-
this.log("Updating authority lookup table...");
|
148
|
+
if (accountsToAdd.length === 0) {
|
149
|
+
return undefined;
|
158
150
|
}
|
159
|
-
|
151
|
+
tx = tx.add((0, solanaUtils_1.getWrappedInstruction)(this.signer, web3_js_1.AddressLookupTableProgram.extendLookupTable({
|
152
|
+
payer: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey),
|
153
|
+
authority: this.authority,
|
154
|
+
lookupTable: this.authorityLutAddress,
|
155
|
+
addresses: accountsToAdd,
|
156
|
+
})));
|
157
|
+
this.log("Requires authority LUT update...");
|
158
|
+
return {
|
159
|
+
tx,
|
160
|
+
new: existingLutAccounts.length === 0,
|
161
|
+
accountsToAdd,
|
162
|
+
};
|
160
163
|
}
|
161
164
|
solautoPositionSettings() {
|
162
165
|
return (this.livePositionUpdates.settings ??
|
@@ -11,6 +11,7 @@ export declare class TransactionItem {
|
|
11
11
|
name?: string | undefined;
|
12
12
|
lookupTableAddresses: string[];
|
13
13
|
tx?: TransactionBuilder;
|
14
|
+
initialized: boolean;
|
14
15
|
constructor(fetchTx: (attemptNum: number) => Promise<TransactionItemInputs | undefined>, name?: string | undefined);
|
15
16
|
initialize(): Promise<void>;
|
16
17
|
refetch(attemptNum: number): Promise<void>;
|
@@ -47,8 +48,9 @@ export declare class TransactionsManager {
|
|
47
48
|
private debugAccounts;
|
48
49
|
private getUpdatedPriorityFeeSetting;
|
49
50
|
private updateStatusForSets;
|
51
|
+
private updateLut;
|
50
52
|
clientSend(transactions: TransactionItem[]): Promise<TransactionManagerStatuses>;
|
51
|
-
send(items: TransactionItem[]
|
53
|
+
send(items: TransactionItem[]): Promise<TransactionManagerStatuses>;
|
52
54
|
private processTransactionSet;
|
53
55
|
private refreshItemSet;
|
54
56
|
private sendTransaction;
|
@@ -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,EAElB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;
|
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;AAK7D,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAqCD,qBAAa,eAAe;IAMjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IARtB,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACjB,WAAW,EAAE,OAAO,CAAS;gBAG3B,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,EACxC,IAAI,CAAC,EAAE,MAAM,YAAA;IAGhB,UAAU;IAKV,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;IAUpC,OAAO,CAAC,mBAAmB;YAMb,SAAS;IAgBV,UAAU,CACrB,YAAY,EAAE,eAAe,EAAE,GAC9B,OAAO,CAAC,0BAA0B,CAAC;IA4EzB,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YA6BxB,qBAAqB;YAiDrB,cAAc;YAyBd,eAAe;CAkD9B"}
|
@@ -11,6 +11,7 @@ const generalUtils_1 = require("../utils/generalUtils");
|
|
11
11
|
const transactionUtils_1 = require("./transactionUtils");
|
12
12
|
const types_1 = require("../types");
|
13
13
|
const web3_js_1 = require("@solana/web3.js");
|
14
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
14
15
|
// import { sendJitoBundledTransactions } from "../utils/jitoUtils";
|
15
16
|
class TransactionTooLargeError extends Error {
|
16
17
|
constructor(message) {
|
@@ -44,9 +45,11 @@ class TransactionItem {
|
|
44
45
|
constructor(fetchTx, name) {
|
45
46
|
this.fetchTx = fetchTx;
|
46
47
|
this.name = name;
|
48
|
+
this.initialized = false;
|
47
49
|
}
|
48
50
|
async initialize() {
|
49
51
|
await this.refetch(0);
|
52
|
+
this.initialized = true;
|
50
53
|
}
|
51
54
|
async refetch(attemptNum) {
|
52
55
|
const resp = await this.fetchTx(attemptNum);
|
@@ -236,25 +239,41 @@ class TransactionsManager {
|
|
236
239
|
this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
|
237
240
|
});
|
238
241
|
}
|
242
|
+
async updateLut(tx) {
|
243
|
+
const updateLutTxName = "create lookup table";
|
244
|
+
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => await this.sendTransaction(tx, updateLutTxName, attemptNum, this.getUpdatedPriorityFeeSetting(prevError)), 3, 150, this.errorsToThrow);
|
245
|
+
}
|
239
246
|
async clientSend(transactions) {
|
240
247
|
const items = [...transactions];
|
241
248
|
const client = this.txHandler;
|
242
249
|
const updateLookupTable = await client.updateLookupTable();
|
243
|
-
|
244
|
-
if (updateLookupTable &&
|
245
|
-
|
246
|
-
|
247
|
-
|
250
|
+
let isolatedLutTx = updateLookupTable?.new;
|
251
|
+
if (updateLookupTable && !isolatedLutTx) {
|
252
|
+
for (const item of items) {
|
253
|
+
await item.initialize();
|
254
|
+
}
|
255
|
+
const txAccounts = items.flatMap((x) => x.tx.getInstructions().flatMap((x) => x.keys.flatMap((x) => x.pubkey)));
|
256
|
+
const newAccountsUsage = txAccounts.reduce((count, item) => {
|
257
|
+
return updateLookupTable.accountsToAdd.find((x) => x.equals((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(item)))
|
258
|
+
? count + 1
|
259
|
+
: count;
|
260
|
+
}, 0);
|
261
|
+
isolatedLutTx = newAccountsUsage > 1;
|
262
|
+
}
|
263
|
+
if (updateLookupTable && isolatedLutTx) {
|
264
|
+
await this.updateLut(updateLookupTable.tx);
|
248
265
|
}
|
249
266
|
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
250
|
-
|
251
|
-
|
267
|
+
if (!items[0].initialized || (updateLookupTable && isolatedLutTx)) {
|
268
|
+
for (const item of items) {
|
269
|
+
await item.initialize();
|
270
|
+
}
|
252
271
|
}
|
253
272
|
const [choresBefore, choresAfter] = await (0, transactionUtils_1.getTransactionChores)(client, (0, umi_1.transactionBuilder)().add(items
|
254
273
|
.filter((x) => x.tx && x.tx.getInstructions().length > 0)
|
255
274
|
.map((x) => x.tx)));
|
256
|
-
if (updateLookupTable && !
|
257
|
-
choresBefore.prepend(updateLookupTable.
|
275
|
+
if (updateLookupTable && !isolatedLutTx) {
|
276
|
+
choresBefore.prepend(updateLookupTable.tx);
|
258
277
|
}
|
259
278
|
if (choresBefore.getInstructions().length > 0) {
|
260
279
|
const chore = new TransactionItem(async () => ({ tx: choresBefore }));
|
@@ -268,7 +287,7 @@ class TransactionsManager {
|
|
268
287
|
items.push(chore);
|
269
288
|
this.txHandler.log("Chores after: ", choresAfter.getInstructions().length);
|
270
289
|
}
|
271
|
-
const result = await this.send(items
|
290
|
+
const result = await this.send(items).catch((e) => {
|
272
291
|
client.resetLiveTxUpdates(false);
|
273
292
|
throw e;
|
274
293
|
});
|
@@ -277,10 +296,10 @@ class TransactionsManager {
|
|
277
296
|
}
|
278
297
|
return result;
|
279
298
|
}
|
280
|
-
async send(items
|
299
|
+
async send(items) {
|
281
300
|
this.statuses = [];
|
282
301
|
this.lookupTables.reset();
|
283
|
-
if (!initialized) {
|
302
|
+
if (!items[0].initialized) {
|
284
303
|
for (const item of items) {
|
285
304
|
await item.initialize();
|
286
305
|
}
|
package/package.json
CHANGED
@@ -247,7 +247,12 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
247
247
|
}
|
248
248
|
|
249
249
|
async updateLookupTable(): Promise<
|
250
|
-
|
250
|
+
| {
|
251
|
+
tx: TransactionBuilder;
|
252
|
+
new: boolean;
|
253
|
+
accountsToAdd: PublicKey[];
|
254
|
+
}
|
255
|
+
| undefined
|
251
256
|
> {
|
252
257
|
const existingLutAccounts = await this.fetchExistingAuthorityLutAccounts();
|
253
258
|
if (
|
@@ -279,25 +284,28 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
279
284
|
.map((x) => x.toString().toLowerCase())
|
280
285
|
.includes(x.toString().toLowerCase())
|
281
286
|
);
|
282
|
-
if (accountsToAdd.length
|
283
|
-
|
284
|
-
getWrappedInstruction(
|
285
|
-
this.signer,
|
286
|
-
AddressLookupTableProgram.extendLookupTable({
|
287
|
-
payer: toWeb3JsPublicKey(this.signer.publicKey),
|
288
|
-
authority: this.authority,
|
289
|
-
lookupTable: this.authorityLutAddress,
|
290
|
-
addresses: accountsToAdd,
|
291
|
-
})
|
292
|
-
)
|
293
|
-
);
|
287
|
+
if (accountsToAdd.length === 0) {
|
288
|
+
return undefined;
|
294
289
|
}
|
295
290
|
|
296
|
-
|
297
|
-
|
298
|
-
|
291
|
+
tx = tx.add(
|
292
|
+
getWrappedInstruction(
|
293
|
+
this.signer,
|
294
|
+
AddressLookupTableProgram.extendLookupTable({
|
295
|
+
payer: toWeb3JsPublicKey(this.signer.publicKey),
|
296
|
+
authority: this.authority,
|
297
|
+
lookupTable: this.authorityLutAddress,
|
298
|
+
addresses: accountsToAdd,
|
299
|
+
})
|
300
|
+
)
|
301
|
+
);
|
299
302
|
|
300
|
-
|
303
|
+
this.log("Requires authority LUT update...");
|
304
|
+
return {
|
305
|
+
tx,
|
306
|
+
new: existingLutAccounts.length === 0,
|
307
|
+
accountsToAdd,
|
308
|
+
};
|
301
309
|
}
|
302
310
|
|
303
311
|
solautoPositionSettings(): SolautoSettingsParameters | undefined {
|
@@ -23,6 +23,7 @@ import {
|
|
23
23
|
} from "../types";
|
24
24
|
import { ReferralStateManager, TxHandler } from "../clients";
|
25
25
|
import { TransactionExpiredBlockheightExceededError } from "@solana/web3.js";
|
26
|
+
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
26
27
|
// import { sendJitoBundledTransactions } from "../utils/jitoUtils";
|
27
28
|
|
28
29
|
export class TransactionTooLargeError extends Error {
|
@@ -71,6 +72,7 @@ class LookupTables {
|
|
71
72
|
export class TransactionItem {
|
72
73
|
lookupTableAddresses!: string[];
|
73
74
|
tx?: TransactionBuilder;
|
75
|
+
public initialized: boolean = false;
|
74
76
|
|
75
77
|
constructor(
|
76
78
|
public fetchTx: (
|
@@ -81,6 +83,7 @@ export class TransactionItem {
|
|
81
83
|
|
82
84
|
async initialize() {
|
83
85
|
await this.refetch(0);
|
86
|
+
this.initialized = true;
|
84
87
|
}
|
85
88
|
|
86
89
|
async refetch(attemptNum: number) {
|
@@ -339,6 +342,22 @@ export class TransactionsManager {
|
|
339
342
|
});
|
340
343
|
}
|
341
344
|
|
345
|
+
private async updateLut(tx: TransactionBuilder) {
|
346
|
+
const updateLutTxName = "create lookup table";
|
347
|
+
await retryWithExponentialBackoff(
|
348
|
+
async (attemptNum, prevError) =>
|
349
|
+
await this.sendTransaction(
|
350
|
+
tx,
|
351
|
+
updateLutTxName,
|
352
|
+
attemptNum,
|
353
|
+
this.getUpdatedPriorityFeeSetting(prevError)
|
354
|
+
),
|
355
|
+
3,
|
356
|
+
150,
|
357
|
+
this.errorsToThrow
|
358
|
+
);
|
359
|
+
}
|
360
|
+
|
342
361
|
public async clientSend(
|
343
362
|
transactions: TransactionItem[]
|
344
363
|
): Promise<TransactionManagerStatuses> {
|
@@ -346,30 +365,33 @@ export class TransactionsManager {
|
|
346
365
|
const client = this.txHandler as SolautoClient;
|
347
366
|
|
348
367
|
const updateLookupTable = await client.updateLookupTable();
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
await this.sendTransaction(
|
358
|
-
updateLookupTable.updateLutTx,
|
359
|
-
updateLutTxName,
|
360
|
-
attemptNum,
|
361
|
-
this.getUpdatedPriorityFeeSetting(prevError)
|
362
|
-
),
|
363
|
-
3,
|
364
|
-
150,
|
365
|
-
this.errorsToThrow
|
368
|
+
|
369
|
+
let isolatedLutTx = updateLookupTable?.new;
|
370
|
+
if (updateLookupTable && !isolatedLutTx) {
|
371
|
+
for (const item of items) {
|
372
|
+
await item.initialize();
|
373
|
+
}
|
374
|
+
const txAccounts = items.flatMap((x) =>
|
375
|
+
x.tx!.getInstructions().flatMap((x) => x.keys.flatMap((x) => x.pubkey))
|
366
376
|
);
|
377
|
+
const newAccountsUsage = txAccounts.reduce((count, item) => {
|
378
|
+
return updateLookupTable.accountsToAdd.find((x) =>
|
379
|
+
x.equals(toWeb3JsPublicKey(item))
|
380
|
+
)
|
381
|
+
? count + 1
|
382
|
+
: count;
|
383
|
+
}, 0);
|
384
|
+
isolatedLutTx = newAccountsUsage > 1;
|
385
|
+
}
|
386
|
+
if (updateLookupTable && isolatedLutTx) {
|
387
|
+
await this.updateLut(updateLookupTable.tx);
|
367
388
|
}
|
368
|
-
|
369
389
|
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
370
390
|
|
371
|
-
|
372
|
-
|
391
|
+
if (!items[0].initialized || (updateLookupTable && isolatedLutTx)) {
|
392
|
+
for (const item of items) {
|
393
|
+
await item.initialize();
|
394
|
+
}
|
373
395
|
}
|
374
396
|
|
375
397
|
const [choresBefore, choresAfter] = await getTransactionChores(
|
@@ -380,8 +402,8 @@ export class TransactionsManager {
|
|
380
402
|
.map((x) => x.tx!)
|
381
403
|
)
|
382
404
|
);
|
383
|
-
if (updateLookupTable && !
|
384
|
-
choresBefore.prepend(updateLookupTable.
|
405
|
+
if (updateLookupTable && !isolatedLutTx) {
|
406
|
+
choresBefore.prepend(updateLookupTable.tx);
|
385
407
|
}
|
386
408
|
if (choresBefore.getInstructions().length > 0) {
|
387
409
|
const chore = new TransactionItem(async () => ({ tx: choresBefore }));
|
@@ -402,7 +424,7 @@ export class TransactionsManager {
|
|
402
424
|
);
|
403
425
|
}
|
404
426
|
|
405
|
-
const result = await this.send(items
|
427
|
+
const result = await this.send(items).catch((e) => {
|
406
428
|
client.resetLiveTxUpdates(false);
|
407
429
|
throw e;
|
408
430
|
});
|
@@ -415,13 +437,12 @@ export class TransactionsManager {
|
|
415
437
|
}
|
416
438
|
|
417
439
|
public async send(
|
418
|
-
items: TransactionItem[]
|
419
|
-
initialized?: boolean
|
440
|
+
items: TransactionItem[]
|
420
441
|
): Promise<TransactionManagerStatuses> {
|
421
442
|
this.statuses = [];
|
422
443
|
this.lookupTables.reset();
|
423
444
|
|
424
|
-
if (!initialized) {
|
445
|
+
if (!items[0].initialized) {
|
425
446
|
for (const item of items) {
|
426
447
|
await item.initialize();
|
427
448
|
}
|