@haven-fi/solauto-sdk 1.0.239 → 1.0.240

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.
@@ -46,8 +46,11 @@ export declare class TransactionsManager {
46
46
  private updateStatus;
47
47
  private debugAccounts;
48
48
  private getUpdatedPriorityFeeSetting;
49
+ private updateStatusForSets;
49
50
  clientSend(transactions: TransactionItem[]): Promise<TransactionManagerStatuses>;
50
51
  send(items: TransactionItem[], initialized?: boolean): Promise<TransactionManagerStatuses>;
52
+ private processTransactionSet;
53
+ private refreshItemSet;
51
54
  private sendTransaction;
52
55
  }
53
56
  //# 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,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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AO,CAAC,0BAA0B,CAAC;YA6FxB,eAAe;CAkD9B"}
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;IAUpC,OAAO,CAAC,mBAAmB;IAMd,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;YA6BxB,qBAAqB;YAiDrB,cAAc;YAqBd,eAAe;CAkD9B"}
@@ -231,6 +231,11 @@ class TransactionsManager {
231
231
  }
232
232
  return this.priorityFeeSetting;
233
233
  }
234
+ updateStatusForSets(itemSets) {
235
+ itemSets.forEach((itemSet) => {
236
+ this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
237
+ });
238
+ }
234
239
  async clientSend(transactions) {
235
240
  const items = [...transactions];
236
241
  const client = this.txHandler;
@@ -281,56 +286,54 @@ class TransactionsManager {
281
286
  }
282
287
  }
283
288
  const itemSets = await this.assembleTransactionSets(items);
284
- const statusesStartIdx = this.statuses.length;
285
- for (const itemSet of itemSets) {
286
- this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
287
- }
289
+ this.updateStatusForSets(itemSets);
288
290
  if (this.txType === "only-simulate" && itemSets.length > 1) {
289
291
  this.txHandler.log("Only simulate and more than 1 transaction. Skipping...");
290
292
  return [];
291
293
  }
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);
294
+ let currentIndex = 0;
295
+ while (currentIndex < itemSets.length) {
296
+ await this.processTransactionSet(itemSets, currentIndex);
297
+ currentIndex++;
331
298
  }
332
299
  return this.statuses;
333
300
  }
301
+ async processTransactionSet(itemSets, currentIndex) {
302
+ let itemSet = itemSets[currentIndex];
303
+ await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => {
304
+ if (currentIndex > 0 || attemptNum > 0) {
305
+ itemSet = await this.refreshItemSet(itemSets, currentIndex, attemptNum);
306
+ }
307
+ if (!itemSet)
308
+ return;
309
+ const tx = await itemSet.getSingleTransaction();
310
+ if (tx.getInstructions().length === 0) {
311
+ this.updateStatus(itemSet.name(), TransactionStatus.Skipped, attemptNum);
312
+ }
313
+ else {
314
+ await this.debugAccounts(itemSet, tx);
315
+ await this.sendTransaction(tx, itemSet.name(), attemptNum, this.getUpdatedPriorityFeeSetting(prevError));
316
+ }
317
+ }, this.retries, this.retryDelay, this.errorsToThrow).catch((e) => {
318
+ if (itemSet) {
319
+ this.updateStatus(itemSet.name(), TransactionStatus.Failed, this.retries);
320
+ }
321
+ throw e;
322
+ });
323
+ }
324
+ async refreshItemSet(itemSets, currentIndex, attemptNum) {
325
+ const itemSet = itemSets[currentIndex];
326
+ await itemSet.refetchAll(attemptNum);
327
+ const newItemSets = await this.assembleTransactionSets([
328
+ ...itemSet.items,
329
+ ...itemSets.slice(currentIndex + 1).flatMap((set) => set.items),
330
+ ]);
331
+ if (newItemSets.length > 1) {
332
+ itemSets.splice(currentIndex + 1, itemSets.length - currentIndex - 1, ...newItemSets.slice(1));
333
+ this.updateStatusForSets(newItemSets.slice(1));
334
+ }
335
+ return newItemSets[0];
336
+ }
334
337
  async sendTransaction(tx, txName, attemptNum, priorityFeeSetting) {
335
338
  this.updateStatus(txName, TransactionStatus.Processing, attemptNum);
336
339
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.239",
3
+ "version": "1.0.240",
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",
@@ -333,6 +333,12 @@ export class TransactionsManager {
333
333
  return this.priorityFeeSetting;
334
334
  }
335
335
 
336
+ private updateStatusForSets(itemSets: TransactionSet[]) {
337
+ itemSets.forEach((itemSet) => {
338
+ this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
339
+ });
340
+ }
341
+
336
342
  public async clientSend(
337
343
  transactions: TransactionItem[]
338
344
  ): Promise<TransactionManagerStatuses> {
@@ -422,10 +428,7 @@ export class TransactionsManager {
422
428
  }
423
429
 
424
430
  const itemSets = await this.assembleTransactionSets(items);
425
- const statusesStartIdx = this.statuses.length;
426
- for (const itemSet of itemSets) {
427
- this.updateStatus(itemSet.name(), TransactionStatus.Queued, 0);
428
- }
431
+ this.updateStatusForSets(itemSets);
429
432
 
430
433
  if (this.txType === "only-simulate" && itemSets.length > 1) {
431
434
  this.txHandler.log(
@@ -434,74 +437,83 @@ export class TransactionsManager {
434
437
  return [];
435
438
  }
436
439
 
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
- }))
440
+ let currentIndex = 0;
441
+ while (currentIndex < itemSets.length) {
442
+ await this.processTransactionSet(itemSets, currentIndex);
443
+ currentIndex++;
444
+ }
445
+
446
+ return this.statuses;
447
+ }
448
+
449
+ private async processTransactionSet(
450
+ itemSets: TransactionSet[],
451
+ currentIndex: number
452
+ ) {
453
+ let itemSet: TransactionSet | undefined = itemSets[currentIndex];
454
+
455
+ await retryWithExponentialBackoff(
456
+ async (attemptNum, prevError) => {
457
+ if (currentIndex > 0 || attemptNum > 0) {
458
+ itemSet = await this.refreshItemSet(
459
+ itemSets,
460
+ currentIndex,
461
+ attemptNum
459
462
  );
460
- this.txHandler.log(this.statuses);
461
- itemSets.splice(
462
- i + 1,
463
- itemSets.length - i - 1,
464
- ...newItemSets.slice(1)
463
+ }
464
+ if (!itemSet) return;
465
+
466
+ const tx = await itemSet.getSingleTransaction();
467
+ if (tx.getInstructions().length === 0) {
468
+ this.updateStatus(
469
+ itemSet.name(),
470
+ TransactionStatus.Skipped,
471
+ attemptNum
472
+ );
473
+ } else {
474
+ await this.debugAccounts(itemSet, tx);
475
+ await this.sendTransaction(
476
+ tx,
477
+ itemSet.name(),
478
+ attemptNum,
479
+ this.getUpdatedPriorityFeeSetting(prevError)
465
480
  );
466
481
  }
467
- return newItemSets.length > 0 ? newItemSets[0] : undefined;
468
- };
482
+ },
483
+ this.retries,
484
+ this.retryDelay,
485
+ this.errorsToThrow
486
+ ).catch((e) => {
487
+ if (itemSet) {
488
+ this.updateStatus(
489
+ itemSet.name(),
490
+ TransactionStatus.Failed,
491
+ this.retries,
492
+ );
493
+ }
494
+ throw e;
495
+ });
496
+ }
469
497
 
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
487
- );
488
- } else {
489
- await this.debugAccounts(itemSet, tx);
490
- await this.sendTransaction(
491
- tx,
492
- itemSet.name(),
493
- attemptNum,
494
- this.getUpdatedPriorityFeeSetting(prevError)
495
- );
496
- }
497
- },
498
- this.retries,
499
- this.retryDelay,
500
- this.errorsToThrow
501
- );
498
+ private async refreshItemSet(
499
+ itemSets: TransactionSet[],
500
+ currentIndex: number,
501
+ attemptNum: number
502
+ ): Promise<TransactionSet | undefined> {
503
+ const itemSet = itemSets[currentIndex];
504
+ await itemSet.refetchAll(attemptNum);
505
+
506
+ const newItemSets = await this.assembleTransactionSets([
507
+ ...itemSet.items,
508
+ ...itemSets.slice(currentIndex + 1).flatMap((set) => set.items),
509
+ ]);
510
+
511
+ if (newItemSets.length > 1) {
512
+ itemSets.splice(currentIndex + 1, itemSets.length - currentIndex - 1, ...newItemSets.slice(1));
513
+ this.updateStatusForSets(newItemSets.slice(1));
502
514
  }
503
-
504
- return this.statuses;
515
+
516
+ return newItemSets[0];
505
517
  }
506
518
 
507
519
  private async sendTransaction(
@@ -14,9 +14,10 @@ import {
14
14
  toBaseUnit,
15
15
  } from "../../src/utils/numberUtils";
16
16
  import { NATIVE_MINT } from "@solana/spl-token";
17
- import { fetchTokenPrices } from "../../src/utils/generalUtils";
17
+ import { consoleLog, fetchTokenPrices } from "../../src/utils/generalUtils";
18
18
  import {
19
19
  TransactionItem,
20
+ TransactionManagerStatuses,
20
21
  TransactionsManager,
21
22
  } from "../../src/transactions/transactionsManager";
22
23
  import { PublicKey } from "@solana/web3.js";
@@ -29,8 +30,7 @@ describe("Solauto Marginfi tests", async () => {
29
30
  // const signer = setupTest("solauto-manager");
30
31
 
31
32
  const payForTransactions = false;
32
- const useJitoBundle = false;
33
- const positionId = 1;
33
+ const positionId = 2;
34
34
 
35
35
  it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
36
36
  const client = new SolautoMarginfiClient(
@@ -49,8 +49,8 @@ describe("Solauto Marginfi tests", async () => {
49
49
  // marginfiAccount: new PublicKey(
50
50
  // "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
51
51
  // ),
52
- // supplyMint: NATIVE_MINT,
53
- // debtMint: new PublicKey(USDC),
52
+ supplyMint: NATIVE_MINT,
53
+ debtMint: new PublicKey(USDC),
54
54
  });
55
55
 
56
56
  const transactionItems: TransactionItem[] = [];
@@ -78,7 +78,7 @@ describe("Solauto Marginfi tests", async () => {
78
78
  // // const [supplyPrice] = await fetchTokenPrices([supply]);
79
79
  // return {
80
80
  // tx: client.protocolInteraction(
81
- // solautoAction("Deposit", [toBaseUnit(9, supplyDecimals)])
81
+ // solautoAction("Deposit", [toBaseUnit(0.5, supplyDecimals)])
82
82
  // ),
83
83
  // };
84
84
  // }, "deposit")
@@ -117,6 +117,14 @@ describe("Solauto Marginfi tests", async () => {
117
117
  )
118
118
  );
119
119
 
120
+ // transactionItems.push(
121
+ // new TransactionItem(
122
+ // async (attemptNum) =>
123
+ // await buildSolautoRebalanceTransaction(client, 0, attemptNum),
124
+ // "rebalance"
125
+ // )
126
+ // );
127
+
120
128
  // transactionItems.push(
121
129
  // new TransactionItem(
122
130
  // async () => ({
@@ -137,11 +145,15 @@ describe("Solauto Marginfi tests", async () => {
137
145
  // )
138
146
  // );
139
147
 
140
- await new TransactionsManager(
148
+ const statuses = await new TransactionsManager(
141
149
  client,
142
- undefined,
150
+ (statuses: TransactionManagerStatuses) => {
151
+ console.log(statuses);
152
+ },
143
153
  !payForTransactions ? "only-simulate" : "normal",
144
- useJitoBundle
145
- ).clientSend(transactionItems, PriorityFeeSetting.Min);
154
+ PriorityFeeSetting.Low
155
+ ).clientSend(transactionItems);
156
+
157
+ // console.log(statuses);
146
158
  });
147
159
  });