@haven-fi/solauto-sdk 1.0.231 → 1.0.233

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EAGb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAOtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gBAAgB,EAChB,eAAe,EAChB,MAAM,iCAAiC,CAAC;AAQzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,eAAe,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,OAAO,CAAC,WAAW,CAAkB;IAE9B,eAAe,EAAG,SAAS,CAAC;IAE5B,sBAAsB,EAAE,MAAM,CAAa;IAC3C,eAAe,EAAG,SAAS,GAAG,MAAM,CAAC;IACrC,iBAAiB,EAAG,SAAS,CAAC;IAC9B,aAAa,EAAG,SAAS,CAAC;IAE1B,sBAAsB,EAAG,qBAAqB,CAAC;IAC/C,oBAAoB,EAAG,qBAAqB,CAAC;IAE7C,iBAAiB,EAAG,SAAS,CAAC;IAC9B,eAAe,EAAG,SAAS,CAAC;IAG5B,iCA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AI,SAAS,EAAE;IAUzB,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IA0BvE,yBAAyB,IAAI,kBAAkB;IAS/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);
@@ -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,EAA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,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsH5C;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,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EAoDxE"}
@@ -438,23 +438,34 @@ function getErrorInfo(umi, tx, error) {
438
438
  if (typeof error === "object" && error["InstructionError"]) {
439
439
  const err = error["InstructionError"];
440
440
  const errIx = tx.getInstructions()[Math.max(0, err[0] - 2)];
441
- const errCode = err[1]["Custom"];
441
+ const errCode = typeof err[1] === "object" ? err[1]["Custom"] : undefined;
442
+ const errName = errCode === undefined ? err[1] : undefined;
443
+ let programName = "";
442
444
  if (errIx.programId.toString() === umi.programs.get("solauto").publicKey.toString()) {
443
445
  programError = (0, generated_1.getSolautoErrorFromCode)(errCode, (0, generated_1.createSolautoProgram)());
446
+ programName = "Haven";
444
447
  if (programError?.name ===
445
448
  new generated_1.InvalidRebalanceConditionError((0, generated_1.createSolautoProgram)()).name) {
446
449
  canBeIgnored = true;
447
450
  }
448
451
  }
449
452
  else if (errIx.programId === marginfi_sdk_1.MARGINFI_PROGRAM_ID) {
453
+ programName = "Marginfi";
450
454
  programError = (0, marginfi_sdk_1.getMarginfiErrorFromName)(errCode, (0, marginfi_sdk_1.createMarginfiProgram)());
451
455
  }
452
456
  else if (errIx.programId === jupiter_sdk_1.JUPITER_PROGRAM_ID) {
457
+ programName = "Jupiter";
453
458
  programError = (0, jupiter_sdk_1.getJupiterErrorFromName)(errCode, (0, jupiter_sdk_1.createJupiterProgram)());
454
459
  }
460
+ if (errName && errCode === undefined) {
461
+ errorName = `${programName ?? "Program"} error`;
462
+ errorInfo = errName;
463
+ }
464
+ }
465
+ if (programError) {
466
+ errorName = programError?.name;
467
+ errorInfo = programError?.message;
455
468
  }
456
- errorName = programError?.name;
457
- errorName = programError?.message;
458
469
  }
459
470
  catch { }
460
471
  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,oBA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O,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,0B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  })(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,SA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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,CACnC,M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,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,CA0EjC"}
@@ -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);
180
- computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.1);
232
+ simulationResult.value.err;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.231",
3
+ "version": "1.0.233",
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
 
@@ -805,10 +805,13 @@ export function getErrorInfo(umi: Umi, tx: TransactionBuilder, error: any) {
805
805
  if (typeof error === "object" && (error as any)["InstructionError"]) {
806
806
  const err = (error as any)["InstructionError"];
807
807
  const errIx = tx.getInstructions()[Math.max(0, err[0] - 2)];
808
- const errCode = err[1]["Custom"];
808
+ const errCode = typeof err[1] === "object" ? err[1]["Custom"] : undefined;
809
+ const errName = errCode === undefined ? err[1] as string : undefined;
810
+ let programName = "";
809
811
 
810
812
  if (errIx.programId.toString() === umi.programs.get("solauto").publicKey.toString()) {
811
- programError = getSolautoErrorFromCode(errCode, createSolautoProgram());
813
+ programError = getSolautoErrorFromCode(errCode, createSolautoProgram());
814
+ programName = "Haven";
812
815
  if (
813
816
  programError?.name ===
814
817
  new InvalidRebalanceConditionError(createSolautoProgram()).name
@@ -816,17 +819,26 @@ export function getErrorInfo(umi: Umi, tx: TransactionBuilder, error: any) {
816
819
  canBeIgnored = true;
817
820
  }
818
821
  } else if (errIx.programId === MARGINFI_PROGRAM_ID) {
822
+ programName = "Marginfi";
819
823
  programError = getMarginfiErrorFromName(
820
824
  errCode,
821
825
  createMarginfiProgram()
822
826
  );
823
827
  } else if (errIx.programId === JUPITER_PROGRAM_ID) {
828
+ programName = "Jupiter";
824
829
  programError = getJupiterErrorFromName(errCode, createJupiterProgram());
825
830
  }
831
+
832
+ if (errName && errCode === undefined) {
833
+ errorName = `${programName ?? "Program"} error`;
834
+ errorInfo = errName;
835
+ }
826
836
  }
827
837
 
828
- errorName = programError?.name;
829
- errorName = programError?.message;
838
+ if (programError) {
839
+ errorName = programError?.name;
840
+ errorInfo = programError?.message;
841
+ }
830
842
  } catch {}
831
843
 
832
844
  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,46 @@ export async function sendSingleOptimizedTransaction(
328
398
  ),
329
399
  3
330
400
  );
331
-
332
- computeUnitLimit = Math.round(
333
- simulationResult.value.unitsConsumed! * 1.1
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
+
422
+ const blockhash = await connection.getLatestBlockhash("confirmed");
423
+ const signedTx = await assembleFinalTransaction(
341
424
  umi.identity,
342
425
  tx,
343
426
  cuPrice,
344
427
  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);
428
+ )
429
+ .setBlockhash(blockhash)
430
+ .buildAndSign(umi);
431
+
432
+ const txSig = await spamSendTransactionUntilConfirmed(
433
+ connection,
434
+ toWeb3JsTransaction(signedTx),
435
+ blockhash,
436
+ confirmTimeout
437
+ );
354
438
  consoleLog(`Transaction signature: ${txSig}`);
355
439
  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;
440
+ return bs58.decode(txSig);
360
441
  }
361
442
 
362
443
  return undefined;
@@ -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,7 +128,7 @@ 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
  );