@haven-fi/solauto-sdk 1.0.176 → 1.0.178
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/generalAccounts.d.ts.map +1 -1
- package/dist/constants/generalAccounts.js +0 -1
- package/dist/constants/solautoConstants.d.ts +0 -1
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +3 -3
- package/dist/generated/errors/solauto.d.ts +8 -26
- package/dist/generated/errors/solauto.d.ts.map +1 -1
- package/dist/generated/errors/solauto.js +26 -59
- package/dist/index.js +2 -0
- package/dist/jupiter-sdk/errors/index.d.ts +9 -0
- package/dist/jupiter-sdk/errors/index.d.ts.map +1 -0
- package/dist/jupiter-sdk/errors/index.js +24 -0
- package/dist/jupiter-sdk/errors/jupiter.d.ts +127 -0
- package/dist/jupiter-sdk/errors/jupiter.d.ts.map +1 -0
- package/dist/jupiter-sdk/errors/jupiter.js +229 -0
- package/dist/jupiter-sdk/index.d.ts +10 -0
- package/dist/jupiter-sdk/index.d.ts.map +1 -0
- package/dist/jupiter-sdk/index.js +25 -0
- package/dist/jupiter-sdk/programs/index.d.ts +9 -0
- package/dist/jupiter-sdk/programs/index.d.ts.map +1 -0
- package/dist/jupiter-sdk/programs/index.js +24 -0
- package/dist/jupiter-sdk/programs/jupiter.d.ts +13 -0
- package/dist/jupiter-sdk/programs/jupiter.d.ts.map +1 -0
- package/dist/jupiter-sdk/programs/jupiter.js +36 -0
- package/dist/transactions/transactionUtils.d.ts +5 -0
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +46 -4
- package/dist/transactions/transactionsManager.d.ts +2 -1
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +12 -20
- package/package.json +1 -1
- package/src/constants/generalAccounts.ts +0 -3
- package/src/constants/solautoConstants.ts +1 -2
- package/src/generated/errors/solauto.ts +30 -88
- package/src/index.ts +3 -1
- package/src/jupiter-sdk/errors/index.ts +9 -0
- package/src/jupiter-sdk/errors/jupiter.ts +282 -0
- package/src/jupiter-sdk/index.ts +10 -0
- package/src/jupiter-sdk/programs/index.ts +9 -0
- package/src/jupiter-sdk/programs/jupiter.ts +52 -0
- package/src/transactions/transactionUtils.ts +72 -5
- package/src/transactions/transactionsManager.ts +26 -29
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Instruction,
|
|
3
|
+
ProgramError,
|
|
3
4
|
TransactionBuilder,
|
|
4
5
|
Umi,
|
|
5
6
|
publicKey,
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
NATIVE_MINT,
|
|
13
14
|
} from "@solana/spl-token";
|
|
14
15
|
import {
|
|
16
|
+
InvalidRebalanceConditionError,
|
|
15
17
|
LendingPlatform,
|
|
16
18
|
ReferralState,
|
|
17
19
|
SOLAUTO_PROGRAM_ID,
|
|
@@ -19,8 +21,10 @@ import {
|
|
|
19
21
|
SolautoRebalanceType,
|
|
20
22
|
TokenType,
|
|
21
23
|
convertReferralFees,
|
|
24
|
+
createSolautoProgram,
|
|
22
25
|
getMarginfiProtocolInteractionInstructionDataSerializer,
|
|
23
26
|
getMarginfiRebalanceInstructionDataSerializer,
|
|
27
|
+
getSolautoErrorFromCode,
|
|
24
28
|
isSolautoAction,
|
|
25
29
|
solautoAction,
|
|
26
30
|
} from "../generated";
|
|
@@ -50,12 +54,20 @@ import {
|
|
|
50
54
|
import { eligibleForRebalance } from "../utils/solauto/generalUtils";
|
|
51
55
|
import { getTokenAccount, getTokenAccountData } from "../utils/accountUtils";
|
|
52
56
|
import {
|
|
57
|
+
createMarginfiProgram,
|
|
53
58
|
getLendingAccountBorrowInstructionDataSerializer,
|
|
54
59
|
getLendingAccountDepositInstructionDataSerializer,
|
|
55
60
|
getLendingAccountRepayInstructionDataSerializer,
|
|
56
61
|
getLendingAccountWithdrawInstructionDataSerializer,
|
|
62
|
+
getMarginfiErrorFromName,
|
|
57
63
|
MARGINFI_PROGRAM_ID,
|
|
58
64
|
} from "../marginfi-sdk";
|
|
65
|
+
import { TxHandler } from "../clients";
|
|
66
|
+
import {
|
|
67
|
+
createJupiterProgram,
|
|
68
|
+
getJupiterErrorFromName,
|
|
69
|
+
JUPITER_PROGRAM_ID,
|
|
70
|
+
} from "../jupiter-sdk";
|
|
59
71
|
|
|
60
72
|
interface wSolTokenUsage {
|
|
61
73
|
wSolTokenAccount: PublicKey;
|
|
@@ -577,17 +589,28 @@ export function requiresRefreshBeforeRebalance(client: SolautoClient) {
|
|
|
577
589
|
) {
|
|
578
590
|
return true;
|
|
579
591
|
} else if (client.solautoPositionData && !client.selfManaged) {
|
|
580
|
-
if (
|
|
592
|
+
if (
|
|
593
|
+
client.livePositionUpdates.supplyAdjustment > BigInt(0) ||
|
|
594
|
+
client.livePositionUpdates.debtAdjustment > BigInt(0)
|
|
595
|
+
) {
|
|
581
596
|
return false;
|
|
582
597
|
}
|
|
583
598
|
|
|
584
|
-
const oldSupply =
|
|
599
|
+
const oldSupply =
|
|
600
|
+
client.solautoPositionData.state.supply.amountUsed.baseUnit;
|
|
585
601
|
const oldDebt = client.solautoPositionData.state.debt.amountUsed.baseUnit;
|
|
586
602
|
|
|
587
|
-
const supplyDiff =
|
|
588
|
-
|
|
603
|
+
const supplyDiff =
|
|
604
|
+
(client.solautoPositionState?.supply.amountUsed.baseUnit ?? BigInt(0)) -
|
|
605
|
+
oldSupply;
|
|
606
|
+
const debtDiff =
|
|
607
|
+
(client.solautoPositionState?.debt.amountUsed.baseUnit ?? BigInt(0)) -
|
|
608
|
+
oldDebt;
|
|
589
609
|
|
|
590
|
-
if (
|
|
610
|
+
if (
|
|
611
|
+
Math.abs(Number(supplyDiff)) / Number(oldSupply) >= 0.01 ||
|
|
612
|
+
Math.abs(Number(debtDiff)) / Number(oldDebt) >= 0.01
|
|
613
|
+
) {
|
|
591
614
|
return true;
|
|
592
615
|
}
|
|
593
616
|
}
|
|
@@ -769,3 +792,47 @@ export async function convertReferralFeesToDestination(
|
|
|
769
792
|
|
|
770
793
|
return [tx, lookupTableAddresses];
|
|
771
794
|
}
|
|
795
|
+
|
|
796
|
+
export function getErrorInfo(tx: TransactionBuilder, error: any) {
|
|
797
|
+
let canBeIgnored = false;
|
|
798
|
+
let errorName: string | undefined = undefined;
|
|
799
|
+
let errorInfo: string | undefined = undefined;
|
|
800
|
+
|
|
801
|
+
try {
|
|
802
|
+
let programError: ProgramError | null = null;
|
|
803
|
+
|
|
804
|
+
if (typeof error === "object" && (error as any)["InstructionError"]) {
|
|
805
|
+
const err = (error as any)["InstructionError"];
|
|
806
|
+
const errIx = tx.getInstructions()[Math.max(0, err[0] - 2)];
|
|
807
|
+
const errCode = err[1]["Custom"];
|
|
808
|
+
|
|
809
|
+
if (errIx.programId === SOLAUTO_PROGRAM_ID) {
|
|
810
|
+
programError = getSolautoErrorFromCode(errCode, createSolautoProgram());
|
|
811
|
+
if (
|
|
812
|
+
programError?.name ===
|
|
813
|
+
new InvalidRebalanceConditionError(createSolautoProgram()).name
|
|
814
|
+
) {
|
|
815
|
+
canBeIgnored = true;
|
|
816
|
+
}
|
|
817
|
+
} else if (errIx.programId === MARGINFI_PROGRAM_ID) {
|
|
818
|
+
programError = getMarginfiErrorFromName(
|
|
819
|
+
errCode,
|
|
820
|
+
createMarginfiProgram()
|
|
821
|
+
);
|
|
822
|
+
} else if (errIx.programId === JUPITER_PROGRAM_ID) {
|
|
823
|
+
programError = getJupiterErrorFromName(errCode, createJupiterProgram());
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
if (programError) {
|
|
828
|
+
errorName = programError?.name;
|
|
829
|
+
errorName = programError?.message;
|
|
830
|
+
}
|
|
831
|
+
} catch {}
|
|
832
|
+
|
|
833
|
+
return {
|
|
834
|
+
errorName: errorName ?? "Unknown error",
|
|
835
|
+
errorInfo: errorInfo ?? "Unknown error",
|
|
836
|
+
canBeIgnored,
|
|
837
|
+
};
|
|
838
|
+
}
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
ErrorsToThrow,
|
|
15
15
|
retryWithExponentialBackoff,
|
|
16
16
|
} from "../utils/generalUtils";
|
|
17
|
-
import { getTransactionChores } from "./transactionUtils";
|
|
17
|
+
import { getErrorInfo, getTransactionChores } from "./transactionUtils";
|
|
18
18
|
import { PriorityFeeSetting, TransactionRunType } from "../types";
|
|
19
19
|
import { ReferralStateManager, TxHandler } from "../clients";
|
|
20
20
|
import {
|
|
@@ -183,10 +183,11 @@ export enum TransactionStatus {
|
|
|
183
183
|
|
|
184
184
|
export type TransactionManagerStatuses = {
|
|
185
185
|
name: string;
|
|
186
|
+
attemptNum: number;
|
|
186
187
|
status: TransactionStatus;
|
|
188
|
+
moreInfo?: string;
|
|
187
189
|
simulationSuccessful?: boolean;
|
|
188
190
|
txSig?: string;
|
|
189
|
-
attemptNum: number;
|
|
190
191
|
}[];
|
|
191
192
|
|
|
192
193
|
export class TransactionsManager {
|
|
@@ -253,7 +254,8 @@ export class TransactionsManager {
|
|
|
253
254
|
status: TransactionStatus,
|
|
254
255
|
attemptNum: number,
|
|
255
256
|
txSig?: string,
|
|
256
|
-
simulationSuccessful?: boolean
|
|
257
|
+
simulationSuccessful?: boolean,
|
|
258
|
+
moreInfo?: string
|
|
257
259
|
) {
|
|
258
260
|
if (!this.statuses.filter((x) => x.name === name)) {
|
|
259
261
|
this.statuses.push({
|
|
@@ -262,6 +264,7 @@ export class TransactionsManager {
|
|
|
262
264
|
txSig,
|
|
263
265
|
attemptNum,
|
|
264
266
|
simulationSuccessful,
|
|
267
|
+
moreInfo,
|
|
265
268
|
});
|
|
266
269
|
} else {
|
|
267
270
|
const idx = this.statuses.findIndex(
|
|
@@ -273,6 +276,9 @@ export class TransactionsManager {
|
|
|
273
276
|
if (simulationSuccessful) {
|
|
274
277
|
this.statuses[idx].simulationSuccessful = simulationSuccessful;
|
|
275
278
|
}
|
|
279
|
+
if (moreInfo) {
|
|
280
|
+
this.statuses[idx].moreInfo = moreInfo;
|
|
281
|
+
}
|
|
276
282
|
} else {
|
|
277
283
|
this.statuses.push({
|
|
278
284
|
name,
|
|
@@ -280,6 +286,7 @@ export class TransactionsManager {
|
|
|
280
286
|
txSig,
|
|
281
287
|
attemptNum,
|
|
282
288
|
simulationSuccessful,
|
|
289
|
+
moreInfo,
|
|
283
290
|
});
|
|
284
291
|
}
|
|
285
292
|
}
|
|
@@ -524,33 +531,23 @@ export class TransactionsManager {
|
|
|
524
531
|
attemptNum,
|
|
525
532
|
txSig ? bs58.encode(txSig) : undefined
|
|
526
533
|
);
|
|
527
|
-
} catch (e) {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
if (
|
|
541
|
-
tx.getInstructions()[Math.max(0, errIx - 2)].programId ===
|
|
542
|
-
SOLAUTO_PROGRAM_ID &&
|
|
543
|
-
solautoProgram.getErrorFromCode(errCode)?.name ===
|
|
544
|
-
invalidRebalanceError.name
|
|
545
|
-
) {
|
|
546
|
-
this.updateStatus(txName, TransactionStatus.Skipped, attemptNum);
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
} catch {}
|
|
534
|
+
} catch (e: any) {
|
|
535
|
+
const errorDetails = getErrorInfo(tx, e);
|
|
536
|
+
|
|
537
|
+
this.updateStatus(
|
|
538
|
+
txName,
|
|
539
|
+
errorDetails.canBeIgnored
|
|
540
|
+
? TransactionStatus.Skipped
|
|
541
|
+
: TransactionStatus.Failed,
|
|
542
|
+
attemptNum,
|
|
543
|
+
undefined,
|
|
544
|
+
undefined,
|
|
545
|
+
errorDetails.errorInfo
|
|
546
|
+
);
|
|
551
547
|
|
|
552
|
-
|
|
553
|
-
|
|
548
|
+
if (!errorDetails.canBeIgnored) {
|
|
549
|
+
throw e;
|
|
550
|
+
}
|
|
554
551
|
}
|
|
555
552
|
}
|
|
556
553
|
}
|