@haven-fi/solauto-sdk 1.0.232 → 1.0.234

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.
Files changed (31) hide show
  1. package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
  2. package/dist/clients/solautoMarginfiClient.js +4 -5
  3. package/dist/constants/solautoConstants.d.ts +1 -0
  4. package/dist/constants/solautoConstants.d.ts.map +1 -1
  5. package/dist/constants/solautoConstants.js +2 -1
  6. package/dist/transactions/transactionUtils.d.ts +1 -1
  7. package/dist/transactions/transactionUtils.d.ts.map +1 -1
  8. package/dist/transactions/transactionUtils.js +25 -6
  9. package/dist/transactions/transactionsManager.d.ts +2 -1
  10. package/dist/transactions/transactionsManager.d.ts.map +1 -1
  11. package/dist/transactions/transactionsManager.js +6 -4
  12. package/dist/utils/accountUtils.d.ts +1 -1
  13. package/dist/utils/accountUtils.d.ts.map +1 -1
  14. package/dist/utils/accountUtils.js +2 -2
  15. package/dist/utils/numberUtils.js +1 -1
  16. package/dist/utils/solanaUtils.d.ts +1 -1
  17. package/dist/utils/solanaUtils.d.ts.map +1 -1
  18. package/dist/utils/solanaUtils.js +73 -14
  19. package/dist/utils/solauto/rebalanceUtils.d.ts +1 -0
  20. package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
  21. package/dist/utils/solauto/rebalanceUtils.js +1 -0
  22. package/package.json +1 -1
  23. package/src/clients/solautoMarginfiClient.ts +7 -6
  24. package/src/constants/solautoConstants.ts +1 -0
  25. package/src/transactions/transactionUtils.ts +46 -13
  26. package/src/transactions/transactionsManager.ts +11 -9
  27. package/src/utils/accountUtils.ts +2 -2
  28. package/src/utils/numberUtils.ts +1 -1
  29. package/src/utils/solanaUtils.ts +106 -26
  30. package/src/utils/solauto/rebalanceUtils.ts +4 -1
  31. package/tests/transactions/solautoMarginfi.ts +1 -9
@@ -1 +1 @@
1
- {"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../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AS/C,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA6C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA0D5C,SAAS,CACP,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;IAgFrB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAoFlE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CA8ClE"}
@@ -442,11 +442,10 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
442
442
  if (state) {
443
443
  return state;
444
444
  }
445
- const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, { pk: this.marginfiAccountPk }, this.marginfiGroup, !this.selfManaged && this.solautoPositionData === null
446
- ? { mint: this.supplyMint }
447
- : undefined, !this.selfManaged && this.solautoPositionData === null
448
- ? { mint: this.debtMint }
449
- : undefined, this.livePositionUpdates);
445
+ const useDesignatedMint = !this.selfManaged &&
446
+ (this.solautoPositionData === null ||
447
+ !(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey).equals(this.authority));
448
+ const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, { pk: this.marginfiAccountPk }, this.marginfiGroup, useDesignatedMint ? { mint: this.supplyMint } : undefined, useDesignatedMint ? { mint: this.debtMint } : undefined, this.livePositionUpdates);
450
449
  if (freshState) {
451
450
  this.log("Fresh state", freshState);
452
451
  const supplyPrice = (0, generalUtils_1.safeGetPrice)(freshState?.supply.mint);
@@ -5,6 +5,7 @@ export declare const BASIS_POINTS = 10000;
5
5
  export declare const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
6
6
  export declare const MIN_REPAY_GAP_BPS = 50;
7
7
  export declare const MIN_BOOST_GAP_BPS = 50;
8
+ export declare const MIN_USD_SUPPORTED_POSITION = 500;
8
9
  export declare const PRICES: {
9
10
  [key: string]: {
10
11
  price: number;
@@ -1 +1 @@
1
- {"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AASzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,CAAC;AAE7E,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,UAYR,CAAC"}
1
+ {"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AASzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAE9C,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,CAAC;AAE7E,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,UAYR,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.PRICES = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.BASIS_POINTS = exports.SOLAUTO_TEST_PROGRAM = exports.SOLAUTO_PROD_PROGRAM = void 0;
3
+ exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.PRICES = exports.MIN_USD_SUPPORTED_POSITION = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.BASIS_POINTS = exports.SOLAUTO_TEST_PROGRAM = exports.SOLAUTO_PROD_PROGRAM = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  const spl_token_1 = require("@solana/spl-token");
6
6
  // import { JitoRpcConnection } from "jito-ts";
@@ -13,6 +13,7 @@ exports.BASIS_POINTS = 10000;
13
13
  exports.MIN_POSITION_STATE_FRESHNESS_SECS = 5;
14
14
  exports.MIN_REPAY_GAP_BPS = 50;
15
15
  exports.MIN_BOOST_GAP_BPS = 50;
16
+ exports.MIN_USD_SUPPORTED_POSITION = 500;
16
17
  exports.PRICES = {};
17
18
  exports.SOLAUTO_LUT = "9D4xwZwDf46n9ft5gQxZzq3rBbdRXsXojKQLZbBdskPY";
18
19
  exports.STANDARD_LUT_ACCOUNTS = [
@@ -10,7 +10,7 @@ export declare function buildSolautoRebalanceTransaction(client: SolautoClient,
10
10
  export declare function convertReferralFeesToDestination(referralManager: ReferralStateManager, tokenAccount: PublicKey, destinationMint: PublicKey): Promise<TransactionItemInputs | undefined>;
11
11
  export declare function getErrorInfo(umi: Umi, tx: TransactionBuilder, error: any): {
12
12
  errorName: string | undefined;
13
- errorInfo: undefined;
13
+ errorInfo: string | undefined;
14
14
  canBeIgnored: boolean;
15
15
  };
16
16
  //# sourceMappingURL=transactionUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAmBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAwCzD,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAO7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAqLjD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAkH7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,8BAA8B,CAAC,MAAM,EAAE,aAAa,oBA2CzE;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAA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CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsC5C;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EAuDxE"}
@@ -186,7 +186,8 @@ function transactionChoresAfter(client, solautoActions, cancellingDcaIn) {
186
186
  }
187
187
  function getRebalanceInstructions(umi, tx) {
188
188
  return tx.getInstructions().filter((x) => {
189
- if (x.programId.toString() === umi.programs.get("solauto").publicKey.toString()) {
189
+ if (x.programId.toString() ===
190
+ umi.programs.get("solauto").publicKey.toString()) {
190
191
  try {
191
192
  const serializer = (0, generated_1.getMarginfiRebalanceInstructionDataSerializer)();
192
193
  const discriminator = serializer.serialize({
@@ -207,7 +208,8 @@ function getRebalanceInstructions(umi, tx) {
207
208
  function getSolautoActions(umi, tx) {
208
209
  let solautoActions = [];
209
210
  tx.getInstructions().forEach((x) => {
210
- if (x.programId.toString() === umi.programs.get("solauto").publicKey.toString()) {
211
+ if (x.programId.toString() ===
212
+ umi.programs.get("solauto").publicKey.toString()) {
211
213
  try {
212
214
  const serializer = (0, generated_1.getMarginfiProtocolInteractionInstructionDataSerializer)();
213
215
  const discriminator = serializer.serialize({
@@ -362,6 +364,11 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
362
364
  }
363
365
  const values = (0, rebalanceUtils_1.getRebalanceValues)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(), (0, generalUtils_1.currentUnixSeconds)(), (0, generalUtils_1.safeGetPrice)(client.supplyMint), (0, generalUtils_1.safeGetPrice)(client.debtMint), targetLiqUtilizationRateBps);
364
366
  client.log("Rebalance values: ", values);
367
+ if (targetLiqUtilizationRateBps === undefined &&
368
+ (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState?.netWorth.baseAmountUsdValue ?? BigInt(0), constants_1.USD_DECIMALS) < constants_1.MIN_USD_SUPPORTED_POSITION &&
369
+ values.feesUsd < 0.5) {
370
+ return undefined;
371
+ }
365
372
  const swapDetails = (0, rebalanceUtils_1.getJupSwapRebalanceDetails)(client, values, targetLiqUtilizationRateBps, attemptNum);
366
373
  const { jupQuote, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails, attemptNum);
367
374
  const flashLoan = (0, rebalanceUtils_1.getFlashLoanDetails)(client, values, jupQuote);
@@ -438,23 +445,35 @@ function getErrorInfo(umi, tx, error) {
438
445
  if (typeof error === "object" && error["InstructionError"]) {
439
446
  const err = error["InstructionError"];
440
447
  const errIx = tx.getInstructions()[Math.max(0, err[0] - 2)];
441
- const errCode = err[1]["Custom"];
442
- if (errIx.programId.toString() === umi.programs.get("solauto").publicKey.toString()) {
448
+ const errCode = typeof err[1] === "object" ? err[1]["Custom"] : undefined;
449
+ const errName = errCode === undefined ? err[1] : undefined;
450
+ let programName = "";
451
+ if (errIx.programId.toString() ===
452
+ umi.programs.get("solauto").publicKey.toString()) {
443
453
  programError = (0, generated_1.getSolautoErrorFromCode)(errCode, (0, generated_1.createSolautoProgram)());
454
+ programName = "Haven";
444
455
  if (programError?.name ===
445
456
  new generated_1.InvalidRebalanceConditionError((0, generated_1.createSolautoProgram)()).name) {
446
457
  canBeIgnored = true;
447
458
  }
448
459
  }
449
460
  else if (errIx.programId === marginfi_sdk_1.MARGINFI_PROGRAM_ID) {
461
+ programName = "Marginfi";
450
462
  programError = (0, marginfi_sdk_1.getMarginfiErrorFromName)(errCode, (0, marginfi_sdk_1.createMarginfiProgram)());
451
463
  }
452
464
  else if (errIx.programId === jupiter_sdk_1.JUPITER_PROGRAM_ID) {
465
+ programName = "Jupiter";
453
466
  programError = (0, jupiter_sdk_1.getJupiterErrorFromName)(errCode, (0, jupiter_sdk_1.createJupiterProgram)());
454
467
  }
468
+ if (errName && errCode === undefined) {
469
+ errorName = `${programName ?? "Program"} error`;
470
+ errorInfo = errName;
471
+ }
472
+ }
473
+ if (programError) {
474
+ errorName = programError?.name;
475
+ errorInfo = programError?.message;
455
476
  }
456
- errorName = programError?.name;
457
- errorName = programError?.message;
458
477
  }
459
478
  catch { }
460
479
  return {
@@ -36,9 +36,10 @@ export declare class TransactionsManager {
36
36
  private errorsToThrow?;
37
37
  private retries;
38
38
  private retryDelay;
39
+ private confirmTimeout;
39
40
  private statuses;
40
41
  private lookupTables;
41
- constructor(txHandler: SolautoClient | ReferralStateManager, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, txType?: TransactionRunType | undefined, mustBeAtomic?: boolean | undefined, errorsToThrow?: ErrorsToThrow | undefined, retries?: number, retryDelay?: number);
42
+ constructor(txHandler: SolautoClient | ReferralStateManager, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, txType?: TransactionRunType | undefined, mustBeAtomic?: boolean | undefined, errorsToThrow?: ErrorsToThrow | undefined, retries?: number, retryDelay?: number, confirmTimeout?: number);
42
43
  private assembleTransactionSets;
43
44
  private updateStatus;
44
45
  private debugAccounts;
@@ -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,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAwC7D,qBAAa,eAAe;IAKjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IAPtB,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OAAO,CAAC,YAAY;YA8CN,aAAa;IAoBd,UAAU,CACrB,YAAY,EAAE,eAAe,EAAE,EAC/B,eAAe,CAAC,EAAE,kBAAkB,GACnC,OAAO,CAAC,0BAA0B,CAAC;IAyEzB,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,EACxB,eAAe,CAAC,EAAE,kBAAkB,EACpC,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,0BAA0B,CAAC;YAwGxB,eAAe;CAoD9B"}
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,EAClB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAsC7D,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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
120
  })(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
121
121
  class TransactionsManager {
122
- constructor(txHandler, statusCallback, txType, mustBeAtomic, errorsToThrow, retries = 4, retryDelay = 150) {
122
+ constructor(txHandler, statusCallback, txType, mustBeAtomic, errorsToThrow, retries = 4, retryDelay = 150, confirmTimeout = 10000) {
123
123
  this.txHandler = txHandler;
124
124
  this.statusCallback = statusCallback;
125
125
  this.txType = txType;
@@ -127,6 +127,7 @@ class TransactionsManager {
127
127
  this.errorsToThrow = errorsToThrow;
128
128
  this.retries = retries;
129
129
  this.retryDelay = retryDelay;
130
+ this.confirmTimeout = confirmTimeout;
130
131
  this.statuses = [];
131
132
  this.lookupTables = new LookupTables(this.txHandler.defaultLookupTables(), this.txHandler.umi);
132
133
  }
@@ -330,15 +331,16 @@ class TransactionsManager {
330
331
  async sendTransaction(tx, txName, attemptNum, prioritySetting) {
331
332
  this.updateStatus(txName, TransactionStatus.Processing, attemptNum);
332
333
  try {
333
- const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, this.txType, attemptNum, prioritySetting, () => this.updateStatus(txName, TransactionStatus.Processing, attemptNum, undefined, true));
334
+ const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, this.txType, this.confirmTimeout, prioritySetting, () => this.updateStatus(txName, TransactionStatus.Processing, attemptNum, undefined, true));
334
335
  this.updateStatus(txName, TransactionStatus.Successful, attemptNum, txSig ? bs58_1.default.encode(txSig) : undefined);
335
336
  }
336
337
  catch (e) {
337
338
  const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, tx, e);
339
+ const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo ?? "unknown"}`;
338
340
  this.updateStatus(txName, errorDetails.canBeIgnored
339
341
  ? TransactionStatus.Skipped
340
- : TransactionStatus.Failed, attemptNum, undefined, undefined, errorDetails.errorInfo ?? errorDetails.errorName ?? "Unknown error");
341
- this.txHandler.log(`${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo ?? "unknown"}`);
342
+ : TransactionStatus.Failed, attemptNum, undefined, undefined, errorString);
343
+ this.txHandler.log(errorString);
342
344
  if (!errorDetails.canBeIgnored) {
343
345
  throw e;
344
346
  }
@@ -5,7 +5,7 @@ export declare function bufferFromU64(num: bigint): Buffer;
5
5
  export declare function getTokenAccount(wallet: PublicKey, tokenMint: PublicKey): PublicKey;
6
6
  export declare function getTokenAccounts(wallet: PublicKey, tokenMints: PublicKey[]): PublicKey[];
7
7
  export declare function getTokenAccountData(umi: Umi, tokenAccount: PublicKey): Promise<import("@solana/spl-token").RawAccount | undefined>;
8
- export declare function getSolautoPositionAccount(signer: PublicKey, positionId: number, programId: PublicKey): PublicKey;
8
+ export declare function getSolautoPositionAccount(authority: PublicKey, positionId: number, programId: PublicKey): PublicKey;
9
9
  export declare function getReferralState(authority: PublicKey, programId: PublicKey): PublicKey;
10
10
  export declare function getMarginfiAccountPDA(solautoPositionAccount: PublicKey, marginfiAccountSeedIdx: bigint, programId: PublicKey): PublicKey;
11
11
  //# sourceMappingURL=accountUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accountUtils.d.ts","sourceRoot":"","sources":["../../src/utils/accountUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,CAMlF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG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AS,aAarB"}
@@ -36,8 +36,8 @@ async function getTokenAccountData(umi, tokenAccount) {
36
36
  return undefined;
37
37
  }
38
38
  }
39
- function getSolautoPositionAccount(signer, positionId, programId) {
40
- const [positionAccount, _] = web3_js_1.PublicKey.findProgramAddressSync([bufferFromU8(positionId), signer.toBuffer()], programId);
39
+ function getSolautoPositionAccount(authority, positionId, programId) {
40
+ const [positionAccount, _] = web3_js_1.PublicKey.findProgramAddressSync([bufferFromU8(positionId), authority.toBuffer()], programId);
41
41
  return positionAccount;
42
42
  }
43
43
  function getReferralState(authority, programId) {
@@ -16,7 +16,7 @@ exports.maxBoostToBps = maxBoostToBps;
16
16
  const constants_1 = require("../constants");
17
17
  const generated_1 = require("../generated");
18
18
  function getLiqUtilzationRateBps(supplyUsd, debtUsd, liqThresholdBps) {
19
- if (supplyUsd === 0) {
19
+ if (supplyUsd === 0 || debtUsd === 0) {
20
20
  return 0;
21
21
  }
22
22
  return toBps(debtUsd / (supplyUsd * fromBps(liqThresholdBps)));
@@ -14,5 +14,5 @@ export declare function splTokenTransferUmiIx(signer: Signer, fromTa: PublicKey,
14
14
  export declare function getAddressLookupInputs(umi: Umi, lookupTableAddresses: string[]): Promise<AddressLookupTableInput[]>;
15
15
  export declare function assembleFinalTransaction(signer: Signer, tx: TransactionBuilder, computeUnitPrice: number, computeUnitLimit?: number): TransactionBuilder;
16
16
  export declare function getComputeUnitPriceEstimate(umi: Umi, tx: TransactionBuilder, prioritySetting: PriorityFeeSetting): Promise<number | undefined>;
17
- export declare function sendSingleOptimizedTransaction(umi: Umi, connection: Connection, tx: TransactionBuilder, txType?: TransactionRunType, attemptNum?: number, prioritySetting?: PriorityFeeSetting, onAwaitingSign?: () => void): Promise<Uint8Array | undefined>;
17
+ export declare function sendSingleOptimizedTransaction(umi: Umi, connection: Connection, tx: TransactionBuilder, txType?: TransactionRunType, confirmTimeout?: number, prioritySetting?: PriorityFeeSetting, onAwaitingSign?: () => void): Promise<Uint8Array | undefined>;
18
18
  //# sourceMappingURL=solanaUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,GAAG,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAGL,UAAU,EACV,SAAS,EAIT,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAYzB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAIlE,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,UAErD;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,MAAM,UAE3D;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAgC,GAC1C,CAAC,UAAU,EAAE,GAAG,CAAC,CAQnB;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,sBAAsB,GACzB,kBAAkB,CAMpB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,GACtB,kBAAkB,CAOpB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,kBAAkB,CAOpB;AAED,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,GACd,kBAAkB,CAUpB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,SAAS,EACtB,QAAQ,EAAE,MAAM,GACf,kBAAkB,CASpB;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,SAAS,EACvB,SAAS,EAAE,SAAS,GACnB,kBAAkB,CAKpB;AAED,wBAAgB,qBAAqB,CACn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AAG,EACR,EAAE,EAAE,kBAAkB,EACtB,eAAe,EAAE,kBAAkB,GAClC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAsB7B;AAqED,wBAAsB,8BAA8B,CAClD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,kBAAkB,EACtB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,cAAc,GAAE,MAAc,EAC9B,eAAe,GAAE,kBAA+C,EAChE,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAyEjC"}
@@ -164,7 +164,59 @@ async function getComputeUnitPriceEstimate(umi, tx, prioritySetting) {
164
164
  }
165
165
  return feeEstimate;
166
166
  }
167
- async function sendSingleOptimizedTransaction(umi, connection, tx, txType, attemptNum, prioritySetting = types_1.PriorityFeeSetting.Default, onAwaitingSign) {
167
+ async function spamSendTransactionUntilConfirmed(connection, transaction, blockhash, confirmTimeout = 10000, spamInterval = 1000) {
168
+ let spamAttempts = 0;
169
+ let confirmed = false;
170
+ let transactionSignature = null;
171
+ return new Promise((resolve, reject) => {
172
+ const spamSend = async () => {
173
+ if (confirmed) {
174
+ return;
175
+ }
176
+ try {
177
+ const txSignature = await connection.sendRawTransaction(Buffer.from(transaction.serialize()), { skipPreflight: true, maxRetries: 0 });
178
+ transactionSignature = txSignature;
179
+ (0, generalUtils_1.consoleLog)(`Transaction sent`);
180
+ }
181
+ catch (error) {
182
+ (0, generalUtils_1.consoleLog)("Error sending transaction:", error);
183
+ }
184
+ spamAttempts++;
185
+ if (!confirmed) {
186
+ setTimeout(spamSend, spamInterval);
187
+ }
188
+ };
189
+ const confirmTransaction = async () => {
190
+ if (transactionSignature) {
191
+ try {
192
+ const { value } = await connection.confirmTransaction({
193
+ ...blockhash,
194
+ signature: transactionSignature,
195
+ });
196
+ if (value.err) {
197
+ reject(value.err);
198
+ }
199
+ confirmed = true;
200
+ resolve(transactionSignature);
201
+ }
202
+ catch (error) {
203
+ (0, generalUtils_1.consoleLog)("Error during confirmation:", error);
204
+ }
205
+ }
206
+ if (!confirmed) {
207
+ setTimeout(confirmTransaction, 1000);
208
+ }
209
+ };
210
+ spamSend();
211
+ confirmTransaction();
212
+ setTimeout(() => {
213
+ if (!confirmed) {
214
+ reject(new Error("Failed to confirm transaction within timeout"));
215
+ }
216
+ }, confirmTimeout);
217
+ });
218
+ }
219
+ async function sendSingleOptimizedTransaction(umi, connection, tx, txType, confirmTimeout = 10000, prioritySetting = types_1.PriorityFeeSetting.Default, onAwaitingSign) {
168
220
  (0, generalUtils_1.consoleLog)("Sending single optimized transaction...");
169
221
  (0, generalUtils_1.consoleLog)("Instructions: ", tx.getInstructions().length);
170
222
  (0, generalUtils_1.consoleLog)("Serialized transaction size: ", tx.getTransactionSize(umi));
@@ -177,26 +229,33 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, txType, attem
177
229
  if (txType !== "skip-simulation") {
178
230
  // TODO: we should only retry simulation if it's not a solauto error
179
231
  const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(connection, (0, umi_web3js_adapters_1.toWeb3JsTransaction)(await (await assembleFinalTransaction(umi.identity, tx, cuPrice, 1400000).setLatestBlockhash(umi)).build(umi))), 3);
232
+ simulationResult.value.err;
180
233
  computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.05);
181
234
  (0, generalUtils_1.consoleLog)("Compute unit limit: ", computeUnitLimit);
182
235
  }
183
236
  if (txType !== "only-simulate") {
184
237
  onAwaitingSign?.();
185
- const result = await assembleFinalTransaction(umi.identity, tx, cuPrice, computeUnitLimit).sendAndConfirm(umi, {
186
- send: {
187
- skipPreflight: true,
188
- commitment: "confirmed",
189
- maxRetries: 0
190
- },
191
- confirm: { commitment: "confirmed" },
192
- });
193
- const txSig = bs58_1.default.encode(result.signature);
238
+ // const result = await assembleFinalTransaction(
239
+ // umi.identity,
240
+ // tx,
241
+ // cuPrice,
242
+ // computeUnitLimit
243
+ // ).sendAndConfirm(umi, {
244
+ // send: {
245
+ // skipPreflight: true,
246
+ // commitment: "confirmed",
247
+ // maxRetries: 0
248
+ // },
249
+ // confirm: { commitment: "confirmed" },
250
+ // });
251
+ const blockhash = await connection.getLatestBlockhash("confirmed");
252
+ const signedTx = await assembleFinalTransaction(umi.identity, tx, cuPrice, computeUnitLimit)
253
+ .setBlockhash(blockhash)
254
+ .buildAndSign(umi);
255
+ const txSig = await spamSendTransactionUntilConfirmed(connection, (0, umi_web3js_adapters_1.toWeb3JsTransaction)(signedTx), blockhash, confirmTimeout);
194
256
  (0, generalUtils_1.consoleLog)(`Transaction signature: ${txSig}`);
195
257
  (0, generalUtils_1.consoleLog)(`https://solscan.io/tx/${txSig}`);
196
- if (result.result.value.err !== null) {
197
- throw new Error(result.result.value.err.toString());
198
- }
199
- return result.signature;
258
+ return bs58_1.default.decode(txSig);
200
259
  }
201
260
  return undefined;
202
261
  }
@@ -12,6 +12,7 @@ export interface RebalanceValues {
12
12
  dcaTokenType?: TokenType;
13
13
  rebalanceAction: RebalanceAction;
14
14
  rebalanceDirection: RebalanceDirection;
15
+ feesUsd: number;
15
16
  }
16
17
  export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined, currentUnixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): RebalanceValues;
17
18
  export interface FlashLoanDetails {
@@ -1 +1 @@
1
- {"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa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Action: (amountToDcaIn ?? 0) > 0 ? "dca" : rebalanceDirection === generated_1.RebalanceDirection.Boost ? "boost" : "repay",
100
100
  rebalanceDirection,
101
+ feesUsd: debtAdjustmentUsd * (0, numberUtils_1.fromBps)(adjustmentFeeBps)
101
102
  };
102
103
  }
103
104
  function getFlashLoanDetails(client, values, jupQuote) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.232",
3
+ "version": "1.0.234",
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",
@@ -670,16 +670,17 @@ export class SolautoMarginfiClient extends SolautoClient {
670
670
  return state;
671
671
  }
672
672
 
673
+ const useDesignatedMint =
674
+ !this.selfManaged &&
675
+ (this.solautoPositionData === null ||
676
+ !toWeb3JsPublicKey(this.signer.publicKey).equals(this.authority));
677
+
673
678
  const freshState = await getMarginfiAccountPositionState(
674
679
  this.umi,
675
680
  { pk: this.marginfiAccountPk },
676
681
  this.marginfiGroup,
677
- !this.selfManaged && this.solautoPositionData === null
678
- ? { mint: this.supplyMint }
679
- : undefined,
680
- !this.selfManaged && this.solautoPositionData === null
681
- ? { mint: this.debtMint }
682
- : undefined,
682
+ useDesignatedMint ? { mint: this.supplyMint } : undefined,
683
+ useDesignatedMint ? { mint: this.debtMint } : undefined,
683
684
  this.livePositionUpdates
684
685
  );
685
686
 
@@ -27,6 +27,7 @@ export const BASIS_POINTS = 10000;
27
27
  export const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
28
28
  export const MIN_REPAY_GAP_BPS = 50;
29
29
  export const MIN_BOOST_GAP_BPS = 50;
30
+ export const MIN_USD_SUPPORTED_POSITION = 500;
30
31
 
31
32
  export const PRICES: { [key: string]: { price: number; time: number } } = {};
32
33
 
@@ -46,6 +46,7 @@ import {
46
46
  } from "../utils/generalUtils";
47
47
  import { SolautoMarginfiClient } from "../clients/solautoMarginfiClient";
48
48
  import {
49
+ fromBaseUnit,
49
50
  getMaxLiqUtilizationRateBps,
50
51
  uint8ArrayToBigInt,
51
52
  } from "../utils/numberUtils";
@@ -53,10 +54,7 @@ import {
53
54
  eligibleForRebalance,
54
55
  positionStateWithLatestPrices,
55
56
  } from "../utils/solauto/generalUtils";
56
- import {
57
- getTokenAccount,
58
- getTokenAccountData,
59
- } from "../utils/accountUtils";
57
+ import { getTokenAccount, getTokenAccountData } from "../utils/accountUtils";
60
58
  import {
61
59
  createMarginfiProgram,
62
60
  getLendingAccountBorrowInstructionDataSerializer,
@@ -72,7 +70,7 @@ import {
72
70
  getJupiterErrorFromName,
73
71
  JUPITER_PROGRAM_ID,
74
72
  } from "../jupiter-sdk";
75
- import { PRICES } from "../constants";
73
+ import { MIN_USD_SUPPORTED_POSITION, PRICES, USD_DECIMALS } from "../constants";
76
74
  import { TransactionItemInputs } from "../types";
77
75
 
78
76
  interface wSolTokenUsage {
@@ -400,9 +398,15 @@ function transactionChoresAfter(
400
398
  return chores;
401
399
  }
402
400
 
403
- function getRebalanceInstructions(umi: Umi, tx: TransactionBuilder): Instruction[] {
401
+ function getRebalanceInstructions(
402
+ umi: Umi,
403
+ tx: TransactionBuilder
404
+ ): Instruction[] {
404
405
  return tx.getInstructions().filter((x) => {
405
- if (x.programId.toString() === umi.programs.get("solauto").publicKey.toString()) {
406
+ if (
407
+ x.programId.toString() ===
408
+ umi.programs.get("solauto").publicKey.toString()
409
+ ) {
406
410
  try {
407
411
  const serializer = getMarginfiRebalanceInstructionDataSerializer();
408
412
  const discriminator = serializer.serialize({
@@ -424,7 +428,10 @@ function getSolautoActions(umi: Umi, tx: TransactionBuilder): SolautoAction[] {
424
428
  let solautoActions: SolautoAction[] = [];
425
429
 
426
430
  tx.getInstructions().forEach((x) => {
427
- if (x.programId.toString() === umi.programs.get("solauto").publicKey.toString()) {
431
+ if (
432
+ x.programId.toString() ===
433
+ umi.programs.get("solauto").publicKey.toString()
434
+ ) {
428
435
  try {
429
436
  const serializer =
430
437
  getMarginfiProtocolInteractionInstructionDataSerializer();
@@ -658,6 +665,17 @@ export async function buildSolautoRebalanceTransaction(
658
665
  );
659
666
  client.log("Rebalance values: ", values);
660
667
 
668
+ if (
669
+ targetLiqUtilizationRateBps === undefined &&
670
+ fromBaseUnit(
671
+ client.solautoPositionState?.netWorth.baseAmountUsdValue ?? BigInt(0),
672
+ USD_DECIMALS
673
+ ) < MIN_USD_SUPPORTED_POSITION &&
674
+ values.feesUsd < 0.5
675
+ ) {
676
+ return undefined;
677
+ }
678
+
661
679
  const swapDetails = getJupSwapRebalanceDetails(
662
680
  client,
663
681
  values,
@@ -805,10 +823,16 @@ export function getErrorInfo(umi: Umi, tx: TransactionBuilder, error: any) {
805
823
  if (typeof error === "object" && (error as any)["InstructionError"]) {
806
824
  const err = (error as any)["InstructionError"];
807
825
  const errIx = tx.getInstructions()[Math.max(0, err[0] - 2)];
808
- const errCode = err[1]["Custom"];
809
-
810
- if (errIx.programId.toString() === umi.programs.get("solauto").publicKey.toString()) {
826
+ const errCode = typeof err[1] === "object" ? err[1]["Custom"] : undefined;
827
+ const errName = errCode === undefined ? (err[1] as string) : undefined;
828
+ let programName = "";
829
+
830
+ if (
831
+ errIx.programId.toString() ===
832
+ umi.programs.get("solauto").publicKey.toString()
833
+ ) {
811
834
  programError = getSolautoErrorFromCode(errCode, createSolautoProgram());
835
+ programName = "Haven";
812
836
  if (
813
837
  programError?.name ===
814
838
  new InvalidRebalanceConditionError(createSolautoProgram()).name
@@ -816,17 +840,26 @@ export function getErrorInfo(umi: Umi, tx: TransactionBuilder, error: any) {
816
840
  canBeIgnored = true;
817
841
  }
818
842
  } else if (errIx.programId === MARGINFI_PROGRAM_ID) {
843
+ programName = "Marginfi";
819
844
  programError = getMarginfiErrorFromName(
820
845
  errCode,
821
846
  createMarginfiProgram()
822
847
  );
823
848
  } else if (errIx.programId === JUPITER_PROGRAM_ID) {
849
+ programName = "Jupiter";
824
850
  programError = getJupiterErrorFromName(errCode, createJupiterProgram());
825
851
  }
852
+
853
+ if (errName && errCode === undefined) {
854
+ errorName = `${programName ?? "Program"} error`;
855
+ errorInfo = errName;
856
+ }
826
857
  }
827
858
 
828
- errorName = programError?.name;
829
- errorName = programError?.message;
859
+ if (programError) {
860
+ errorName = programError?.name;
861
+ errorInfo = programError?.message;
862
+ }
830
863
  } catch {}
831
864
 
832
865
  return {
@@ -15,7 +15,11 @@ import {
15
15
  retryWithExponentialBackoff,
16
16
  } from "../utils/generalUtils";
17
17
  import { getErrorInfo, getTransactionChores } from "./transactionUtils";
18
- import { PriorityFeeSetting, TransactionItemInputs, TransactionRunType } from "../types";
18
+ import {
19
+ PriorityFeeSetting,
20
+ TransactionItemInputs,
21
+ TransactionRunType,
22
+ } from "../types";
19
23
  import { ReferralStateManager, TxHandler } from "../clients";
20
24
  // import { sendJitoBundledTransactions } from "../utils/jitoUtils";
21
25
 
@@ -54,8 +58,6 @@ class LookupTables {
54
58
  }
55
59
  }
56
60
 
57
-
58
-
59
61
  export class TransactionItem {
60
62
  lookupTableAddresses!: string[];
61
63
  tx?: TransactionBuilder;
@@ -197,7 +199,8 @@ export class TransactionsManager {
197
199
  private mustBeAtomic?: boolean,
198
200
  private errorsToThrow?: ErrorsToThrow,
199
201
  private retries: number = 4,
200
- private retryDelay: number = 150
202
+ private retryDelay: number = 150,
203
+ private confirmTimeout: number = 10000
201
204
  ) {
202
205
  this.lookupTables = new LookupTables(
203
206
  this.txHandler.defaultLookupTables(),
@@ -508,7 +511,7 @@ export class TransactionsManager {
508
511
  this.txHandler.connection,
509
512
  tx,
510
513
  this.txType,
511
- attemptNum,
514
+ this.confirmTimeout,
512
515
  prioritySetting,
513
516
  () =>
514
517
  this.updateStatus(
@@ -528,6 +531,7 @@ export class TransactionsManager {
528
531
  } catch (e: any) {
529
532
  const errorDetails = getErrorInfo(this.txHandler.umi, tx, e);
530
533
 
534
+ const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo ?? "unknown"}`;
531
535
  this.updateStatus(
532
536
  txName,
533
537
  errorDetails.canBeIgnored
@@ -536,11 +540,9 @@ export class TransactionsManager {
536
540
  attemptNum,
537
541
  undefined,
538
542
  undefined,
539
- errorDetails.errorInfo ?? errorDetails.errorName ?? "Unknown error"
540
- );
541
- this.txHandler.log(
542
- `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo ?? "unknown"}`
543
+ errorString
543
544
  );
545
+ this.txHandler.log(errorString);
544
546
 
545
547
  if (!errorDetails.canBeIgnored) {
546
548
  throw e;
@@ -36,12 +36,12 @@ export async function getTokenAccountData(umi: Umi, tokenAccount: PublicKey) {
36
36
  }
37
37
 
38
38
  export function getSolautoPositionAccount(
39
- signer: PublicKey,
39
+ authority: PublicKey,
40
40
  positionId: number,
41
41
  programId: PublicKey
42
42
  ) {
43
43
  const [positionAccount, _] = PublicKey.findProgramAddressSync(
44
- [bufferFromU8(positionId), signer.toBuffer()],
44
+ [bufferFromU8(positionId), authority.toBuffer()],
45
45
  programId
46
46
  );
47
47
 
@@ -6,7 +6,7 @@ export function getLiqUtilzationRateBps(
6
6
  debtUsd: number,
7
7
  liqThresholdBps: number
8
8
  ): number {
9
- if (supplyUsd === 0) {
9
+ if (supplyUsd === 0 || debtUsd === 0) {
10
10
  return 0;
11
11
  }
12
12
 
@@ -16,12 +16,15 @@ import {
16
16
  import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
17
17
  import {
18
18
  AddressLookupTableAccount,
19
+ Blockhash,
20
+ BlockhashWithExpiryBlockHeight,
19
21
  ComputeBudgetProgram,
20
22
  Connection,
21
23
  PublicKey,
22
24
  RpcResponseAndContext,
23
25
  SimulatedTransactionResponse,
24
26
  SystemProgram,
27
+ Transaction,
25
28
  TransactionInstruction,
26
29
  VersionedTransaction,
27
30
  } from "@solana/web3.js";
@@ -31,7 +34,11 @@ import {
31
34
  createTransferInstruction,
32
35
  } from "@solana/spl-token";
33
36
  import { getTokenAccount } from "./accountUtils";
34
- import { arraysAreEqual, consoleLog, retryWithExponentialBackoff } from "./generalUtils";
37
+ import {
38
+ arraysAreEqual,
39
+ consoleLog,
40
+ retryWithExponentialBackoff,
41
+ } from "./generalUtils";
35
42
  import {
36
43
  getLendingAccountEndFlashloanInstructionDataSerializer,
37
44
  getLendingAccountStartFlashloanInstructionDataSerializer,
@@ -50,7 +57,7 @@ export function buildIronforgeApiUrl(ironforgeApiKey: string) {
50
57
 
51
58
  export function getSolanaRpcConnection(
52
59
  rpcUrl: string,
53
- programId: PublicKey = SOLAUTO_PROD_PROGRAM,
60
+ programId: PublicKey = SOLAUTO_PROD_PROGRAM
54
61
  ): [Connection, Umi] {
55
62
  const connection = new Connection(rpcUrl, "confirmed");
56
63
  const umi = createUmi(connection).use({
@@ -285,12 +292,79 @@ export async function getComputeUnitPriceEstimate(
285
292
  return feeEstimate;
286
293
  }
287
294
 
295
+ async function spamSendTransactionUntilConfirmed(
296
+ connection: Connection,
297
+ transaction: Transaction | VersionedTransaction,
298
+ blockhash: BlockhashWithExpiryBlockHeight,
299
+ confirmTimeout: number = 10000,
300
+ spamInterval: number = 1000
301
+ ): Promise<string> {
302
+ let spamAttempts = 0;
303
+ let confirmed = false;
304
+ let transactionSignature: string | null = null;
305
+
306
+ return new Promise<string>((resolve, reject) => {
307
+ const spamSend = async () => {
308
+ if (confirmed) {
309
+ return;
310
+ }
311
+
312
+ try {
313
+ const txSignature = await connection.sendRawTransaction(
314
+ Buffer.from(transaction.serialize()),
315
+ { skipPreflight: true, maxRetries: 0 }
316
+ );
317
+ transactionSignature = txSignature;
318
+ consoleLog(`Transaction sent`);
319
+ } catch (error) {
320
+ consoleLog("Error sending transaction:", error);
321
+ }
322
+
323
+ spamAttempts++;
324
+ if (!confirmed) {
325
+ setTimeout(spamSend, spamInterval);
326
+ }
327
+ };
328
+
329
+ const confirmTransaction = async () => {
330
+ if (transactionSignature) {
331
+ try {
332
+ const { value } = await connection.confirmTransaction({
333
+ ...blockhash,
334
+ signature: transactionSignature,
335
+ });
336
+ if (value.err) {
337
+ reject(value.err);
338
+ }
339
+ confirmed = true;
340
+ resolve(transactionSignature);
341
+ } catch (error) {
342
+ consoleLog("Error during confirmation:", error);
343
+ }
344
+ }
345
+
346
+ if (!confirmed) {
347
+ setTimeout(confirmTransaction, 1000);
348
+ }
349
+ };
350
+
351
+ spamSend();
352
+ confirmTransaction();
353
+
354
+ setTimeout(() => {
355
+ if (!confirmed) {
356
+ reject(new Error("Failed to confirm transaction within timeout"));
357
+ }
358
+ }, confirmTimeout);
359
+ });
360
+ }
361
+
288
362
  export async function sendSingleOptimizedTransaction(
289
363
  umi: Umi,
290
364
  connection: Connection,
291
365
  tx: TransactionBuilder,
292
366
  txType?: TransactionRunType,
293
- attemptNum?: number,
367
+ confirmTimeout: number = 10000,
294
368
  prioritySetting: PriorityFeeSetting = PriorityFeeSetting.Default,
295
369
  onAwaitingSign?: () => void
296
370
  ): Promise<Uint8Array | undefined> {
@@ -298,11 +372,7 @@ export async function sendSingleOptimizedTransaction(
298
372
  consoleLog("Instructions: ", tx.getInstructions().length);
299
373
  consoleLog("Serialized transaction size: ", tx.getTransactionSize(umi));
300
374
 
301
- let cuPrice = await getComputeUnitPriceEstimate(
302
- umi,
303
- tx,
304
- prioritySetting
305
- );
375
+ let cuPrice = await getComputeUnitPriceEstimate(umi, tx, prioritySetting);
306
376
  if (!cuPrice) {
307
377
  cuPrice = 1000000;
308
378
  }
@@ -328,35 +398,45 @@ export async function sendSingleOptimizedTransaction(
328
398
  ),
329
399
  3
330
400
  );
331
-
332
- computeUnitLimit = Math.round(
333
- simulationResult.value.unitsConsumed! * 1.05
334
- );
401
+ simulationResult.value.err;
402
+ computeUnitLimit = Math.round(simulationResult.value.unitsConsumed! * 1.05);
335
403
  consoleLog("Compute unit limit: ", computeUnitLimit);
336
404
  }
337
405
 
338
406
  if (txType !== "only-simulate") {
339
407
  onAwaitingSign?.();
340
- const result = await assembleFinalTransaction(
408
+ // const result = await assembleFinalTransaction(
409
+ // umi.identity,
410
+ // tx,
411
+ // cuPrice,
412
+ // computeUnitLimit
413
+ // ).sendAndConfirm(umi, {
414
+ // send: {
415
+ // skipPreflight: true,
416
+ // commitment: "confirmed",
417
+ // maxRetries: 0
418
+ // },
419
+ // confirm: { commitment: "confirmed" },
420
+ // });
421
+ const blockhash = await connection.getLatestBlockhash("confirmed");
422
+ const signedTx = await assembleFinalTransaction(
341
423
  umi.identity,
342
424
  tx,
343
425
  cuPrice,
344
426
  computeUnitLimit
345
- ).sendAndConfirm(umi, {
346
- send: {
347
- skipPreflight: true,
348
- commitment: "confirmed",
349
- maxRetries: 0
350
- },
351
- confirm: { commitment: "confirmed" },
352
- });
353
- const txSig = bs58.encode(result.signature);
427
+ )
428
+ .setBlockhash(blockhash)
429
+ .buildAndSign(umi);
430
+ const txSig = await spamSendTransactionUntilConfirmed(
431
+ connection,
432
+ toWeb3JsTransaction(signedTx),
433
+ blockhash,
434
+ confirmTimeout
435
+ );
436
+
354
437
  consoleLog(`Transaction signature: ${txSig}`);
355
438
  consoleLog(`https://solscan.io/tx/${txSig}`);
356
- if (result.result.value.err !== null) {
357
- throw new Error(result.result.value.err.toString());
358
- }
359
- return result.signature;
439
+ return bs58.decode(txSig);
360
440
  }
361
441
 
362
442
  return undefined;
@@ -19,6 +19,7 @@ import { JupSwapDetails } from "../jupiterUtils";
19
19
  import { currentUnixSeconds, safeGetPrice } from "../generalUtils";
20
20
  import {
21
21
  fromBaseUnit,
22
+ fromBps,
22
23
  getDebtAdjustmentUsd,
23
24
  getLiqUtilzationRateBps,
24
25
  getMaxLiqUtilizationRateBps,
@@ -164,7 +165,8 @@ export interface RebalanceValues {
164
165
  amountUsdToDcaIn: number;
165
166
  dcaTokenType?: TokenType;
166
167
  rebalanceAction: RebalanceAction;
167
- rebalanceDirection: RebalanceDirection
168
+ rebalanceDirection: RebalanceDirection;
169
+ feesUsd: number;
168
170
  }
169
171
 
170
172
  export function getRebalanceValues(
@@ -222,6 +224,7 @@ export function getRebalanceValues(
222
224
  rebalanceAction:
223
225
  (amountToDcaIn ?? 0) > 0 ? "dca" : rebalanceDirection === RebalanceDirection.Boost ? "boost" : "repay",
224
226
  rebalanceDirection,
227
+ feesUsd: debtAdjustmentUsd * fromBps(adjustmentFeeBps)
225
228
  };
226
229
  }
227
230
 
@@ -36,7 +36,6 @@ describe("Solauto Marginfi tests", async () => {
36
36
  const client = new SolautoMarginfiClient(
37
37
  buildHeliusApiUrl(process.env.HELIUS_API_KEY!),
38
38
  true,
39
- SOLAUTO_TEST_PROGRAM
40
39
  );
41
40
 
42
41
  const supply = NATIVE_MINT;
@@ -129,18 +128,11 @@ describe("Solauto Marginfi tests", async () => {
129
128
  transactionItems.push(
130
129
  new TransactionItem(
131
130
  async (attemptNum) =>
132
- await buildSolautoRebalanceTransaction(client, 7000, attemptNum),
131
+ await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
133
132
  "rebalance"
134
133
  )
135
134
  );
136
135
 
137
- // transactionItems.push(
138
- // new TransactionItem(
139
- // async (attemptNum) => await buildSolautoRebalanceTransaction(client, 0),
140
- // "repay all debt"
141
- // )
142
- // );
143
-
144
136
  // transactionItems.push(
145
137
  // new TransactionItem(
146
138
  // async () => ({