@haven-fi/solauto-sdk 1.0.380 → 1.0.382

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.
@@ -190,19 +190,19 @@ exports.MARGINFI_ACCOUNTS = {
190
190
  priceOracle: USDC_PRICE_ORACLE,
191
191
  },
192
192
  },
193
- // ["DESG67cExEcw7d6MmENLEzaocR8pLrhfiw9VrNtGWUKD"]: {
194
- // [tokens.HMTR]: {
195
- // bank: "Br3yzg2WSb81RaFWK9UsKtq8fD5viwooZG34mKqQWxdM",
196
- // liquidityVault: "J45Je52qv2rDBuCQWPwp3bjRhf3bGzRWhKZtGDuLooCX",
197
- // vaultAuthority: "CKDsAKjNruDSz4tmUairh8PDGD1Rqh9WMTLWERYnnZrH",
198
- // priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.HMTR.toString()],
199
- // },
200
- // [tokens.USDC]: {
201
- // bank: "9yNnhJ8c1vGbu3DMf6eeeUi6TDJ2ddGgaRA88rL2R3rP",
202
- // liquidityVault: "4U1UBjXrPrW7JuQ894JbLUBqcb5LFfK9rfkWFwT7EdQ9",
203
- // vaultAuthority: "CY74V1r48kuuHA6APD3AaU2oPV1mBqe9srikrQQSHNR6",
204
- // priceOracle: USDC_PRICE_ORACLE,
205
- // }
206
- // }
193
+ ["DESG67cExEcw7d6MmENLEzaocR8pLrhfiw9VrNtGWUKD"]: {
194
+ [tokens.HMTR]: {
195
+ bank: "Br3yzg2WSb81RaFWK9UsKtq8fD5viwooZG34mKqQWxdM",
196
+ liquidityVault: "J45Je52qv2rDBuCQWPwp3bjRhf3bGzRWhKZtGDuLooCX",
197
+ vaultAuthority: "CKDsAKjNruDSz4tmUairh8PDGD1Rqh9WMTLWERYnnZrH",
198
+ priceOracle: switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS[tokens.HMTR.toString()],
199
+ },
200
+ [tokens.USDC]: {
201
+ bank: "9yNnhJ8c1vGbu3DMf6eeeUi6TDJ2ddGgaRA88rL2R3rP",
202
+ liquidityVault: "4U1UBjXrPrW7JuQ894JbLUBqcb5LFfK9rfkWFwT7EdQ9",
203
+ vaultAuthority: "CY74V1r48kuuHA6APD3AaU2oPV1mBqe9srikrQQSHNR6",
204
+ priceOracle: USDC_PRICE_ORACLE,
205
+ }
206
+ }
207
207
  };
208
208
  exports.MARGINFI_ACCOUNTS_LOOKUP_TABLE = "GAjmWmBPcH5Gxbiykasydj6RsCEaCLyHEvK6kHdFigc6";
@@ -49,7 +49,7 @@ exports.ALL_SUPPORTED_TOKENS = [
49
49
  exports.POPCAT,
50
50
  exports.RETARDIO,
51
51
  exports.BILLY,
52
- // HMTR,
52
+ exports.HMTR,
53
53
  ];
54
54
  exports.TOKEN_INFO = {
55
55
  [web3_js_1.PublicKey.default.toString()]: {
@@ -8,10 +8,8 @@
8
8
  import { Serializer } from '@metaplex-foundation/umi/serializers';
9
9
  export declare enum OracleSetup {
10
10
  None = 0,
11
- PythLegacy = 1,
12
- SwitchboardLegacy = 2,
13
- PythPushOracle = 3,
14
- SwitchboardPull = 4
11
+ PythEma = 1,
12
+ SwitchboardV2 = 2
15
13
  }
16
14
  export type OracleSetupArgs = OracleSetup;
17
15
  export declare function getOracleSetupSerializer(): Serializer<OracleSetupArgs, OracleSetup>;
@@ -1 +1 @@
1
- {"version":3,"file":"oracleSetup.d.ts","sourceRoot":"","sources":["../../../src/marginfi-sdk/types/oracleSetup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,sCAAsC,CAAC;AAE9E,oBAAY,WAAW;IACrB,IAAI,IAAA;IACJ,UAAU,IAAA;IACV,iBAAiB,IAAA;IACjB,cAAc,IAAA;IACd,eAAe,IAAA;CAChB;AAED,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC;AAE1C,wBAAgB,wBAAwB,IAAI,UAAU,CACpD,eAAe,EACf,WAAW,CACZ,CAIA"}
1
+ {"version":3,"file":"oracleSetup.d.ts","sourceRoot":"","sources":["../../../src/marginfi-sdk/types/oracleSetup.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,sCAAsC,CAAC;AAE9E,oBAAY,WAAW;IACrB,IAAI,IAAA;IACJ,OAAO,IAAA;IACP,aAAa,IAAA;CACd;AAED,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC;AAE1C,wBAAgB,wBAAwB,IAAI,UAAU,CACpD,eAAe,EACf,WAAW,CACZ,CAIA"}
@@ -13,10 +13,8 @@ const serializers_1 = require("@metaplex-foundation/umi/serializers");
13
13
  var OracleSetup;
14
14
  (function (OracleSetup) {
15
15
  OracleSetup[OracleSetup["None"] = 0] = "None";
16
- OracleSetup[OracleSetup["PythLegacy"] = 1] = "PythLegacy";
17
- OracleSetup[OracleSetup["SwitchboardLegacy"] = 2] = "SwitchboardLegacy";
18
- OracleSetup[OracleSetup["PythPushOracle"] = 3] = "PythPushOracle";
19
- OracleSetup[OracleSetup["SwitchboardPull"] = 4] = "SwitchboardPull";
16
+ OracleSetup[OracleSetup["PythEma"] = 1] = "PythEma";
17
+ OracleSetup[OracleSetup["SwitchboardV2"] = 2] = "SwitchboardV2";
20
18
  })(OracleSetup || (exports.OracleSetup = OracleSetup = {}));
21
19
  function getOracleSetupSerializer() {
22
20
  return (0, serializers_1.scalarEnum)(OracleSetup, {
@@ -8,7 +8,7 @@ export declare function getTransactionChores(client: SolautoClient, tx: Transact
8
8
  export declare function requiresRefreshBeforeRebalance(client: SolautoClient): Promise<boolean>;
9
9
  export declare function buildSolautoRebalanceTransaction(client: SolautoClient, targetLiqUtilizationRateBps?: number, attemptNum?: number): Promise<TransactionItemInputs | undefined>;
10
10
  export declare function convertReferralFeesToDestination(referralManager: ReferralStateManager, tokenAccount: PublicKey, destinationMint: PublicKey): Promise<TransactionItemInputs | undefined>;
11
- export declare function getErrorInfo(umi: Umi, tx: TransactionBuilder, error: any, simulationSuccessful?: boolean): {
11
+ export declare function getErrorInfo(umi: Umi, txs: TransactionBuilder[], error: Error, simulationSuccessful?: boolean): {
12
12
  errorName: string | undefined;
13
13
  errorInfo: string | undefined;
14
14
  canBeIgnored: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAmBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqCzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAOlD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA2LjD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAoH7B;AA2LD,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,oBAqDzE;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CA2H5C;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsC5C;AA0BD,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,GAAG,EACV,oBAAoB,CAAC,EAAE,OAAO;;;;EAyE/B"}
1
+ {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAmBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqCzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAOlD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA4LjD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAoH7B;AA2LD,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,oBAqDzE;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CA2H5C;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsC5C;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,kBAAkB,EAAE,EACzB,KAAK,EAAE,KAAK,EACZ,oBAAoB,CAAC,EAAE,OAAO;;;;EA4F/B"}
@@ -22,6 +22,7 @@ const marginfi_sdk_1 = require("../marginfi-sdk");
22
22
  const jupiter_sdk_1 = require("../jupiter-sdk");
23
23
  const constants_1 = require("../constants");
24
24
  const utils_1 = require("../utils");
25
+ const transactions_1 = require("../types/transactions");
25
26
  function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn) {
26
27
  const supplyIsWsol = client.supplyMint.equals(spl_token_1.NATIVE_MINT);
27
28
  const debtIsWsol = client.debtMint.equals(spl_token_1.NATIVE_MINT);
@@ -439,76 +440,76 @@ async function convertReferralFeesToDestination(referralManager, tokenAccount, d
439
440
  .add(swapIx);
440
441
  return { tx, lookupTableAddresses };
441
442
  }
442
- function parseJitoErrorMessage(message) {
443
- const regex = /Error processing Instruction (\d+): custom program error: (0x[0-9A-Fa-f]+|\d+)/;
444
- const match = message.match(regex);
445
- if (match) {
446
- const instructionIndex = parseInt(match[1], 10);
447
- let errorCode;
448
- if (match[2].toLowerCase().startsWith("0x")) {
449
- errorCode = parseInt(match[2], 16);
450
- }
451
- else {
452
- errorCode = parseInt(match[2], 10);
453
- }
454
- return {
455
- instructionIndex,
456
- errorCode,
457
- };
458
- }
459
- else {
460
- return null;
461
- }
462
- }
463
- function getErrorInfo(umi, tx, error, simulationSuccessful) {
443
+ function getErrorInfo(umi, txs, error, simulationSuccessful) {
464
444
  let canBeIgnored = false;
465
445
  let errorName = undefined;
466
446
  let errorInfo = undefined;
447
+ let errTxIdx;
448
+ let errIxIdx;
449
+ let errCode;
450
+ let errName;
451
+ const computeIxs = simulationSuccessful ? 2 : 1; // sub ixs to account for computeUnitLimit and computeUnitPrice that get added
467
452
  try {
468
- let programError = null;
469
453
  if (typeof error === "object" && error["InstructionError"]) {
470
454
  const err = error["InstructionError"];
471
- const computeIxs = simulationSuccessful ? 2 : 1; // sub ixs to account for computeUnitLimit and computeUnitPrice that get added
472
- const errIxIdx = err[0] - computeIxs;
473
- (0, generalUtils_1.consoleLog)("Transaction instructions:", tx
474
- .getInstructions()
475
- .map((x) => x.programId.toString())
476
- .join(","));
477
- (0, generalUtils_1.consoleLog)("Error instruction index:", errIxIdx);
478
- const errIx = tx.getInstructions()[Math.max(0, errIxIdx)];
479
- const errCode = typeof err[1] === "object" && "Custom" in err[1]
480
- ? err[1]["Custom"]
481
- : undefined;
482
- const errName = errCode === undefined ? err[1] : undefined;
483
- let programName = "";
484
- if (errIx.programId.toString() ===
455
+ errTxIdx = 0;
456
+ errIxIdx = err[0] - computeIxs;
457
+ errCode =
458
+ typeof err[1] === "object" && "Custom" in err[1]
459
+ ? err[1]["Custom"]
460
+ : undefined;
461
+ errName = errCode === undefined ? err[1] : undefined;
462
+ }
463
+ else if (error instanceof transactions_1.BundleSimulationError) {
464
+ errTxIdx = error.details.transactionIdx;
465
+ errIxIdx = error.details.instructionIdx - computeIxs;
466
+ errCode = error.details.errorCode;
467
+ }
468
+ (0, generalUtils_1.consoleLog)("Transaction instructions:", txs.map((x) => x
469
+ .getInstructions()
470
+ .map((y) => y.programId.toString())
471
+ .join(",")));
472
+ let programError = null;
473
+ let programName = "";
474
+ const errIx = errTxIdx !== undefined && errIxIdx !== undefined
475
+ ? txs[errTxIdx].getInstructions()[Math.max(0, errIxIdx)]
476
+ : undefined;
477
+ (0, generalUtils_1.consoleLog)("Error transaction index:", errTxIdx);
478
+ (0, generalUtils_1.consoleLog)("Error instruction index:", errIxIdx);
479
+ (0, generalUtils_1.consoleLog)("Error code:", errCode);
480
+ (0, generalUtils_1.consoleLog)("Error instruction program:", errIx?.programId.toString());
481
+ const solautoError = (0, generated_1.getSolautoErrorFromCode)(errCode ?? -1, (0, generated_1.createSolautoProgram)());
482
+ const marginfiError = (0, marginfi_sdk_1.getMarginfiErrorFromCode)(errCode ?? -1, (0, marginfi_sdk_1.createMarginfiProgram)());
483
+ if (errCode &&
484
+ errIx?.programId.toString() ===
485
485
  umi.programs.get("solauto").publicKey.toString()) {
486
- programError = (0, generated_1.getSolautoErrorFromCode)(errCode, (0, generated_1.createSolautoProgram)());
487
- programName = "Haven";
488
- if (programError?.name ===
489
- new generated_1.InvalidRebalanceConditionError((0, generated_1.createSolautoProgram)()).name) {
490
- canBeIgnored = true;
491
- }
492
- }
493
- else if (errIx.programId === marginfi_sdk_1.MARGINFI_PROGRAM_ID) {
494
- programName = "Marginfi";
495
- programError = (0, marginfi_sdk_1.getMarginfiErrorFromCode)(errCode, (0, marginfi_sdk_1.createMarginfiProgram)());
496
- }
497
- else if (errIx.programId === jupiter_sdk_1.JUPITER_PROGRAM_ID) {
498
- programName = "Jupiter";
499
- programError = (0, jupiter_sdk_1.getJupiterErrorFromCode)(errCode, (0, jupiter_sdk_1.createJupiterProgram)());
500
- }
501
- if (errName && errCode === undefined) {
502
- errorName = `${programName ?? "Program"} error`;
503
- errorInfo = errName;
486
+ programError = solautoError ?? marginfiError;
487
+ programName = "Haven";
488
+ if (programError?.name ===
489
+ new generated_1.InvalidRebalanceConditionError((0, generated_1.createSolautoProgram)()).name) {
490
+ canBeIgnored = true;
504
491
  }
505
492
  }
493
+ else if (errCode && errIx?.programId === marginfi_sdk_1.MARGINFI_PROGRAM_ID) {
494
+ programName = "Marginfi";
495
+ programError = marginfiError;
496
+ }
497
+ else if (errCode && errIx?.programId === jupiter_sdk_1.JUPITER_PROGRAM_ID) {
498
+ programName = "Jupiter";
499
+ programError = (0, jupiter_sdk_1.getJupiterErrorFromCode)(errCode, (0, jupiter_sdk_1.createJupiterProgram)());
500
+ }
506
501
  if (programError) {
507
502
  errorName = programError?.name;
508
503
  errorInfo = programError?.message;
509
504
  }
505
+ else if (errName) {
506
+ errorName = `${programName ?? "Program"} error`;
507
+ errorInfo = errName;
508
+ }
509
+ }
510
+ catch (e) {
511
+ (0, generalUtils_1.consoleLog)(e);
510
512
  }
511
- catch { }
512
513
  return {
513
514
  errorName: errorName,
514
515
  errorInfo: errorInfo,
@@ -369,7 +369,7 @@ class TransactionsManager {
369
369
  this.updateStatusForSets(itemSets, TransactionStatus.Successful, attemptNum, txSigs);
370
370
  }, this.retries, this.retryDelay, this.errorsToThrow).catch((e) => {
371
371
  this.txHandler.log("Capturing error info...");
372
- const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, (0, umi_1.transactionBuilder)().add(transactions), e, itemSets.filter((x) => this.statuses.find((y) => x.name() === y.name)?.simulationSuccessful).length === itemSets.length);
372
+ const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, transactions, e, itemSets.filter((x) => this.statuses.find((y) => x.name() === y.name)?.simulationSuccessful).length === itemSets.length);
373
373
  const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
374
374
  this.updateStatusForSets(itemSets, errorDetails.canBeIgnored
375
375
  ? TransactionStatus.Skipped
@@ -427,7 +427,7 @@ class TransactionsManager {
427
427
  }
428
428
  catch (e) {
429
429
  this.txHandler.log("Capturing error info...");
430
- const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, tx, e, this.statuses.find((x) => x.name === txName)?.simulationSuccessful);
430
+ const errorDetails = (0, transactionUtils_1.getErrorInfo)(this.txHandler.umi, [tx], e, this.statuses.find((x) => x.name === txName)?.simulationSuccessful);
431
431
  const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo?.split("\n")[0] ?? "unknown"}`;
432
432
  this.updateStatus(txName, errorDetails.canBeIgnored
433
433
  ? TransactionStatus.Skipped
@@ -0,0 +1,11 @@
1
+ export interface BundleInstructionFailure {
2
+ transactionIdx: number;
3
+ instructionIdx: number;
4
+ errorCode: number;
5
+ }
6
+ export declare class BundleSimulationError extends Error {
7
+ statusCode: number;
8
+ details: BundleInstructionFailure;
9
+ constructor(message: string, statusCode: number, details: BundleInstructionFailure);
10
+ }
11
+ //# sourceMappingURL=transactions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactions.d.ts","sourceRoot":"","sources":["../../src/types/transactions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,qBAAsB,SAAQ,KAAK;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,wBAAwB,CAAC;gBAGvC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,wBAAwB;CASpC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BundleSimulationError = void 0;
4
+ class BundleSimulationError extends Error {
5
+ constructor(message, statusCode, details) {
6
+ super(message);
7
+ this.statusCode = statusCode;
8
+ this.details = details;
9
+ Object.setPrototypeOf(this, BundleSimulationError.prototype);
10
+ }
11
+ }
12
+ exports.BundleSimulationError = BundleSimulationError;
@@ -1 +1 @@
1
- {"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAIV,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEJ,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAIlE,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAa9D;AAmKD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,kBAAkB,EAAE,EACzB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAuE/B"}
1
+ {"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAIV,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEJ,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAKlE,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAa9D;AAwMD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,kBAAkB,EAAE,EACzB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAuE/B"}
@@ -13,6 +13,7 @@ const generalUtils_1 = require("./generalUtils");
13
13
  const types_1 = require("../types");
14
14
  const axios_1 = __importDefault(require("axios"));
15
15
  const bs58_1 = __importDefault(require("bs58"));
16
+ const transactions_1 = require("../types/transactions");
16
17
  async function getRandomTipAccount() {
17
18
  const tipAccounts = [
18
19
  "96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5",
@@ -30,6 +31,27 @@ async function getRandomTipAccount() {
30
31
  async function getTipInstruction(signer, tipLamports) {
31
32
  return (0, solanaUtils_1.systemTransferUmiIx)(signer, await getRandomTipAccount(), BigInt(tipLamports));
32
33
  }
34
+ function parseJitoErrorMessage(message) {
35
+ const regex = /Error processing Instruction (\d+): custom program error: (0x[0-9A-Fa-f]+|\d+)/;
36
+ const match = message.match(regex);
37
+ if (match) {
38
+ const instructionIndex = parseInt(match[1], 10);
39
+ let errorCode;
40
+ if (match[2].toLowerCase().startsWith("0x")) {
41
+ errorCode = parseInt(match[2], 16);
42
+ }
43
+ else {
44
+ errorCode = parseInt(match[2], 10);
45
+ }
46
+ return {
47
+ instructionIndex,
48
+ errorCode,
49
+ };
50
+ }
51
+ else {
52
+ return null;
53
+ }
54
+ }
33
55
  async function simulateJitoBundle(umi, txs) {
34
56
  const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
35
57
  const resp = await axios_1.default.post(umi.rpc.getEndpoint(), {
@@ -61,7 +83,18 @@ async function simulateJitoBundle(umi, txs) {
61
83
  (0, generalUtils_1.consoleLog)(y);
62
84
  });
63
85
  });
86
+ const failedTxIdx = transactionResults.length;
64
87
  const txFailure = res.summary.failed.error.TransactionFailure;
88
+ if (txFailure) {
89
+ const info = parseJitoErrorMessage(txFailure[1]);
90
+ if (info) {
91
+ throw new transactions_1.BundleSimulationError("Failed to simulate transaction", 400, {
92
+ transactionIdx: failedTxIdx,
93
+ instructionIdx: info.instructionIndex,
94
+ errorCode: info.errorCode,
95
+ });
96
+ }
97
+ }
65
98
  throw new Error(txFailure ? txFailure[1] : res.summary.failed.toString());
66
99
  }
67
100
  return res;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.380",
3
+ "version": "1.0.382",
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",
@@ -172,20 +172,20 @@ export const MARGINFI_ACCOUNTS: {
172
172
  priceOracle: USDC_PRICE_ORACLE,
173
173
  },
174
174
  },
175
- // ["DESG67cExEcw7d6MmENLEzaocR8pLrhfiw9VrNtGWUKD"]: {
176
- // [tokens.HMTR]: {
177
- // bank: "Br3yzg2WSb81RaFWK9UsKtq8fD5viwooZG34mKqQWxdM",
178
- // liquidityVault: "J45Je52qv2rDBuCQWPwp3bjRhf3bGzRWhKZtGDuLooCX",
179
- // vaultAuthority: "CKDsAKjNruDSz4tmUairh8PDGD1Rqh9WMTLWERYnnZrH",
180
- // priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.HMTR.toString()],
181
- // },
182
- // [tokens.USDC]: {
183
- // bank: "9yNnhJ8c1vGbu3DMf6eeeUi6TDJ2ddGgaRA88rL2R3rP",
184
- // liquidityVault: "4U1UBjXrPrW7JuQ894JbLUBqcb5LFfK9rfkWFwT7EdQ9",
185
- // vaultAuthority: "CY74V1r48kuuHA6APD3AaU2oPV1mBqe9srikrQQSHNR6",
186
- // priceOracle: USDC_PRICE_ORACLE,
187
- // }
188
- // }
175
+ ["DESG67cExEcw7d6MmENLEzaocR8pLrhfiw9VrNtGWUKD"]: {
176
+ [tokens.HMTR]: {
177
+ bank: "Br3yzg2WSb81RaFWK9UsKtq8fD5viwooZG34mKqQWxdM",
178
+ liquidityVault: "J45Je52qv2rDBuCQWPwp3bjRhf3bGzRWhKZtGDuLooCX",
179
+ vaultAuthority: "CKDsAKjNruDSz4tmUairh8PDGD1Rqh9WMTLWERYnnZrH",
180
+ priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.HMTR.toString()],
181
+ },
182
+ [tokens.USDC]: {
183
+ bank: "9yNnhJ8c1vGbu3DMf6eeeUi6TDJ2ddGgaRA88rL2R3rP",
184
+ liquidityVault: "4U1UBjXrPrW7JuQ894JbLUBqcb5LFfK9rfkWFwT7EdQ9",
185
+ vaultAuthority: "CY74V1r48kuuHA6APD3AaU2oPV1mBqe9srikrQQSHNR6",
186
+ priceOracle: USDC_PRICE_ORACLE,
187
+ }
188
+ }
189
189
  };
190
190
 
191
191
  export const MARGINFI_ACCOUNTS_LOOKUP_TABLE =
@@ -48,7 +48,7 @@ export const ALL_SUPPORTED_TOKENS = [
48
48
  POPCAT,
49
49
  RETARDIO,
50
50
  BILLY,
51
- // HMTR,
51
+ HMTR,
52
52
  ];
53
53
 
54
54
  interface TokenInfo {
@@ -10,10 +10,8 @@ import { Serializer, scalarEnum } from '@metaplex-foundation/umi/serializers';
10
10
 
11
11
  export enum OracleSetup {
12
12
  None,
13
- PythLegacy,
14
- SwitchboardLegacy,
15
- PythPushOracle,
16
- SwitchboardPull,
13
+ PythEma,
14
+ SwitchboardV2,
17
15
  }
18
16
 
19
17
  export type OracleSetupArgs = OracleSetup;
@@ -73,6 +73,7 @@ import {
73
73
  import { PRICES } from "../constants";
74
74
  import { TransactionItemInputs } from "../types";
75
75
  import { safeGetPrice } from "../utils";
76
+ import { BundleSimulationError } from "../types/transactions";
76
77
 
77
78
  interface wSolTokenUsage {
78
79
  wSolTokenAccount: PublicKey;
@@ -824,101 +825,96 @@ export async function convertReferralFeesToDestination(
824
825
  return { tx, lookupTableAddresses };
825
826
  }
826
827
 
827
- function parseJitoErrorMessage(message: string) {
828
- const regex =
829
- /Error processing Instruction (\d+): custom program error: (0x[0-9A-Fa-f]+|\d+)/;
830
- const match = message.match(regex);
831
-
832
- if (match) {
833
- const instructionIndex = parseInt(match[1], 10);
834
-
835
- let errorCode: number;
836
- if (match[2].toLowerCase().startsWith("0x")) {
837
- errorCode = parseInt(match[2], 16);
838
- } else {
839
- errorCode = parseInt(match[2], 10);
840
- }
841
-
842
- return {
843
- instructionIndex,
844
- errorCode,
845
- };
846
- } else {
847
- return null;
848
- }
849
- }
850
-
851
828
  export function getErrorInfo(
852
829
  umi: Umi,
853
- tx: TransactionBuilder,
854
- error: any,
830
+ txs: TransactionBuilder[],
831
+ error: Error,
855
832
  simulationSuccessful?: boolean
856
833
  ) {
857
834
  let canBeIgnored = false;
858
835
  let errorName: string | undefined = undefined;
859
836
  let errorInfo: string | undefined = undefined;
860
837
 
861
- try {
862
- let programError: ProgramError | null = null;
838
+ let errTxIdx: number | undefined;
839
+ let errIxIdx: number | undefined;
840
+ let errCode: number | undefined;
841
+ let errName: string | undefined;
863
842
 
843
+ const computeIxs = simulationSuccessful ? 2 : 1; // sub ixs to account for computeUnitLimit and computeUnitPrice that get added
844
+
845
+ try {
864
846
  if (typeof error === "object" && (error as any)["InstructionError"]) {
865
847
  const err = (error as any)["InstructionError"];
866
848
 
867
- const computeIxs = simulationSuccessful ? 2 : 1; // sub ixs to account for computeUnitLimit and computeUnitPrice that get added
868
- const errIxIdx = err[0] - computeIxs;
849
+ errTxIdx = 0;
850
+ errIxIdx = err[0] - computeIxs;
851
+ errCode =
852
+ typeof err[1] === "object" && "Custom" in err[1]
853
+ ? err[1]["Custom"]
854
+ : undefined;
855
+ errName = errCode === undefined ? (err[1] as string) : undefined;
856
+ } else if (error instanceof BundleSimulationError) {
857
+ errTxIdx = error.details.transactionIdx;
858
+ errIxIdx = error.details.instructionIdx - computeIxs;
859
+ errCode = error.details.errorCode;
860
+ }
869
861
 
870
- consoleLog(
871
- "Transaction instructions:",
872
- tx
862
+ consoleLog(
863
+ "Transaction instructions:",
864
+ txs.map((x) =>
865
+ x
873
866
  .getInstructions()
874
- .map((x) => x.programId.toString())
867
+ .map((y) => y.programId.toString())
875
868
  .join(",")
876
- );
877
- consoleLog("Error instruction index:", errIxIdx);
869
+ )
870
+ );
878
871
 
879
- const errIx = tx.getInstructions()[Math.max(0, errIxIdx)];
872
+ let programError: ProgramError | null = null;
873
+ let programName = "";
874
+ const errIx =
875
+ errTxIdx !== undefined && errIxIdx !== undefined
876
+ ? txs[errTxIdx].getInstructions()[Math.max(0, errIxIdx)]
877
+ : undefined;
880
878
 
881
- const errCode =
882
- typeof err[1] === "object" && "Custom" in err[1]
883
- ? err[1]["Custom"]
884
- : undefined;
885
- const errName = errCode === undefined ? (err[1] as string) : undefined;
886
- let programName = "";
879
+ consoleLog("Error transaction index:", errTxIdx);
880
+ consoleLog("Error instruction index:", errIxIdx);
881
+ consoleLog("Error code:", errCode);
882
+ consoleLog("Error instruction program:", errIx?.programId.toString());
887
883
 
888
- if (
889
- errIx.programId.toString() ===
884
+ const solautoError = getSolautoErrorFromCode(errCode ?? -1, createSolautoProgram());
885
+ const marginfiError = getMarginfiErrorFromCode(errCode ?? -1, createMarginfiProgram());
886
+
887
+ if (
888
+ errCode &&
889
+ errIx?.programId.toString() ===
890
890
  umi.programs.get("solauto").publicKey.toString()
891
+ ) {
892
+ programError = solautoError ?? marginfiError;
893
+ programName = "Haven";
894
+ if (
895
+ programError?.name ===
896
+ new InvalidRebalanceConditionError(createSolautoProgram()).name
891
897
  ) {
892
- programError = getSolautoErrorFromCode(errCode, createSolautoProgram());
893
- programName = "Haven";
894
- if (
895
- programError?.name ===
896
- new InvalidRebalanceConditionError(createSolautoProgram()).name
897
- ) {
898
- canBeIgnored = true;
899
- }
900
- } else if (errIx.programId === MARGINFI_PROGRAM_ID) {
901
- programName = "Marginfi";
902
- programError = getMarginfiErrorFromCode(
903
- errCode,
904
- createMarginfiProgram()
905
- );
906
- } else if (errIx.programId === JUPITER_PROGRAM_ID) {
907
- programName = "Jupiter";
908
- programError = getJupiterErrorFromCode(errCode, createJupiterProgram());
909
- }
910
-
911
- if (errName && errCode === undefined) {
912
- errorName = `${programName ?? "Program"} error`;
913
- errorInfo = errName;
898
+ canBeIgnored = true;
914
899
  }
900
+ } else if (errCode && errIx?.programId === MARGINFI_PROGRAM_ID) {
901
+ programName = "Marginfi";
902
+ programError = marginfiError;
903
+ } else if (errCode && errIx?.programId === JUPITER_PROGRAM_ID) {
904
+ programName = "Jupiter";
905
+ programError = getJupiterErrorFromCode(errCode, createJupiterProgram());
915
906
  }
916
907
 
917
908
  if (programError) {
918
909
  errorName = programError?.name;
919
910
  errorInfo = programError?.message;
911
+ } else if (errName) {
912
+ errorName = `${programName ?? "Program"} error`;
913
+ errorInfo = errName;
920
914
  }
921
- } catch {}
915
+ } catch (e) {
916
+ consoleLog(e);
917
+ }
922
918
 
923
919
  return {
924
920
  errorName: errorName,
@@ -614,7 +614,7 @@ export class TransactionsManager {
614
614
  this.txHandler.log("Capturing error info...");
615
615
  const errorDetails = getErrorInfo(
616
616
  this.txHandler.umi,
617
- transactionBuilder().add(transactions),
617
+ transactions,
618
618
  e,
619
619
  itemSets.filter(
620
620
  (x) =>
@@ -756,7 +756,7 @@ export class TransactionsManager {
756
756
  this.txHandler.log("Capturing error info...");
757
757
  const errorDetails = getErrorInfo(
758
758
  this.txHandler.umi,
759
- tx,
759
+ [tx],
760
760
  e,
761
761
  this.statuses.find((x) => x.name === txName)?.simulationSuccessful
762
762
  );
@@ -0,0 +1,23 @@
1
+ export interface BundleInstructionFailure {
2
+ transactionIdx: number;
3
+ instructionIdx: number;
4
+ errorCode: number;
5
+ }
6
+
7
+ export class BundleSimulationError extends Error {
8
+ public statusCode: number;
9
+ public details: BundleInstructionFailure;
10
+
11
+ constructor(
12
+ message: string,
13
+ statusCode: number,
14
+ details: BundleInstructionFailure
15
+ ) {
16
+ super(message);
17
+
18
+ this.statusCode = statusCode;
19
+ this.details = details;
20
+
21
+ Object.setPrototypeOf(this, BundleSimulationError.prototype);
22
+ }
23
+ }
@@ -21,6 +21,7 @@ import { consoleLog, retryWithExponentialBackoff } from "./generalUtils";
21
21
  import { PriorityFeeSetting, TransactionRunType } from "../types";
22
22
  import axios from "axios";
23
23
  import base58 from "bs58";
24
+ import { BundleSimulationError } from "../types/transactions";
24
25
 
25
26
  export async function getRandomTipAccount(): Promise<PublicKey> {
26
27
  const tipAccounts = [
@@ -48,6 +49,30 @@ async function getTipInstruction(
48
49
  );
49
50
  }
50
51
 
52
+ function parseJitoErrorMessage(message: string) {
53
+ const regex =
54
+ /Error processing Instruction (\d+): custom program error: (0x[0-9A-Fa-f]+|\d+)/;
55
+ const match = message.match(regex);
56
+
57
+ if (match) {
58
+ const instructionIndex = parseInt(match[1], 10);
59
+
60
+ let errorCode: number;
61
+ if (match[2].toLowerCase().startsWith("0x")) {
62
+ errorCode = parseInt(match[2], 16);
63
+ } else {
64
+ errorCode = parseInt(match[2], 10);
65
+ }
66
+
67
+ return {
68
+ instructionIndex,
69
+ errorCode,
70
+ };
71
+ } else {
72
+ return null;
73
+ }
74
+ }
75
+
51
76
  async function simulateJitoBundle(umi: Umi, txs: VersionedTransaction[]) {
52
77
  const simulationResult = await retryWithExponentialBackoff(async () => {
53
78
  const resp = await axios.post(
@@ -89,7 +114,20 @@ async function simulateJitoBundle(umi: Umi, txs: VersionedTransaction[]) {
89
114
  });
90
115
  });
91
116
 
117
+ const failedTxIdx = transactionResults.length;
92
118
  const txFailure = res.summary.failed.error.TransactionFailure;
119
+
120
+ if (txFailure) {
121
+ const info = parseJitoErrorMessage(txFailure[1] as string);
122
+ if (info) {
123
+ throw new BundleSimulationError("Failed to simulate transaction", 400, {
124
+ transactionIdx: failedTxIdx,
125
+ instructionIdx: info.instructionIndex,
126
+ errorCode: info.errorCode,
127
+ });
128
+ }
129
+ }
130
+
93
131
  throw new Error(txFailure ? txFailure[1] : res.summary.failed.toString());
94
132
  }
95
133
 
@@ -52,20 +52,20 @@ describe("Solauto Marginfi tests", async () => {
52
52
  const supplyDecimals = 6;
53
53
  const debtDecimals = 6;
54
54
 
55
- // await client.initialize({
56
- // signer,
57
- // positionId,
58
- // authority: new PublicKey("rC5dMP5dmSsfQ66rynzfFzuc122Eex9h1RJHVDkeH6D"),
59
- // // new: true,
60
- // // marginfiAccount: new PublicKey(
61
- // // "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
62
- // // ),
63
- // // marginfiGroup: new PublicKey("G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"),
64
- // // supplyMint: new PublicKey("3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump"),
65
- // // debtMint: new PublicKey(USDC),
66
- // });
67
-
68
- console.log(await getJupTokenPrices([new PublicKey(HMTR)]));
55
+ await client.initialize({
56
+ signer,
57
+ positionId,
58
+ authority: new PublicKey("rC5dMP5dmSsfQ66rynzfFzuc122Eex9h1RJHVDkeH6D"),
59
+ // new: true,
60
+ // marginfiAccount: new PublicKey(
61
+ // "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
62
+ // ),
63
+ // marginfiGroup: new PublicKey("G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"),
64
+ // supplyMint: new PublicKey("3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump"),
65
+ // debtMint: new PublicKey(USDC),
66
+ });
67
+
68
+ // console.log(await getJupTokenPrices([new PublicKey(HMTR)]));
69
69
 
70
70
  const transactionItems: TransactionItem[] = [];
71
71
  // const settingParams: SolautoSettingsParametersInpArgs = {
@@ -220,18 +220,19 @@ describe("Solauto Marginfi tests", async () => {
220
220
  // )
221
221
  // );
222
222
 
223
- // const temp = (statuses: TransactionManagerStatuses) =>
224
- // console.log(statuses);
223
+ const temp = (statuses: TransactionManagerStatuses) =>
224
+ console.log(statuses);
225
225
 
226
- // const statuses = await new TransactionsManager(
227
- // client,
228
- // // temp,
229
- // undefined,
230
- // !payForTransactions ? "only-simulate" : "normal",
231
- // PriorityFeeSetting.Low,
232
- // true
233
- // ).clientSend(transactionItems);
226
+ const statuses = await new TransactionsManager(
227
+ client,
228
+ temp,
229
+ !payForTransactions ? "only-simulate" : "normal",
230
+ PriorityFeeSetting.Low,
231
+ true,
232
+ undefined,
233
+ 0
234
+ ).clientSend(transactionItems);
234
235
 
235
- // console.log(statuses);
236
+ console.log(statuses);
236
237
  });
237
238
  });