wasabi-solana-ts 1.2.8 → 1.2.10
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/error-handling/dflow.d.ts +573 -0
- package/dist/error-handling/dflow.js +3511 -0
- package/dist/error-handling/jupiter.d.ts +280 -1425
- package/dist/error-handling/jupiter.js +2016 -920
- package/dist/error-handling/raydium.d.ts +871 -0
- package/dist/error-handling/raydium.js +5611 -0
- package/dist/error-handling/titan.d.ts +146 -751
- package/dist/error-handling/transactionErrorHandling.d.ts +2 -2
- package/dist/error-handling/transactionErrorHandling.js +85 -144
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SendTransactionError, VersionedTransaction
|
|
1
|
+
import { SendTransactionError, VersionedTransaction } from '@solana/web3.js';
|
|
2
2
|
export declare class SimulationError extends Error {
|
|
3
3
|
error: string;
|
|
4
4
|
transaction: VersionedTransaction;
|
|
@@ -12,10 +12,10 @@ type ErrorObject = {
|
|
|
12
12
|
expected: boolean;
|
|
13
13
|
program: string;
|
|
14
14
|
};
|
|
15
|
+
export declare const NOT_ENOUGH_SOL_ERROR = "Insufficient SOL for transaction fees. Please add more SOL and try again.";
|
|
15
16
|
export declare const parseSendTransactionError: (error: SendTransactionError, transaction: VersionedTransaction) => ErrorObject | undefined;
|
|
16
17
|
export declare const parseError: (instructionNumber: number, errorCode: number, transaction: VersionedTransaction) => ErrorObject | undefined;
|
|
17
18
|
export declare const parseSimulationError: (error: SimulationError, transaction: VersionedTransaction) => ErrorObject | undefined;
|
|
18
19
|
export declare const parseErrorLogs: (logs: string[] | undefined) => ErrorObject | undefined;
|
|
19
20
|
export declare const matchError: (error: Error) => ErrorObject | undefined;
|
|
20
|
-
export declare const getFailingSwapProgram: (instructions: TransactionInstruction[]) => string;
|
|
21
21
|
export {};
|
|
@@ -23,13 +23,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.matchError = exports.parseErrorLogs = exports.parseSimulationError = exports.parseError = exports.parseSendTransactionError = exports.NOT_ENOUGH_SOL_ERROR = exports.SimulationError = void 0;
|
|
27
27
|
const jupiter_1 = require("./jupiter");
|
|
28
28
|
const titan_1 = require("./titan");
|
|
29
|
+
const raydium_1 = require("./raydium");
|
|
30
|
+
const dflow_1 = require("./dflow");
|
|
29
31
|
const web3_js_1 = require("@solana/web3.js");
|
|
30
|
-
const
|
|
31
|
-
const idl = __importStar(require("../idl/wasabi_solana.json"));
|
|
32
|
-
const WasabiIDL = idl;
|
|
32
|
+
const WasabiIDL = __importStar(require("../idl/wasabi_solana.json"));
|
|
33
33
|
class SimulationError extends Error {
|
|
34
34
|
error;
|
|
35
35
|
transaction;
|
|
@@ -42,61 +42,84 @@ class SimulationError extends Error {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
exports.SimulationError = SimulationError;
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
exports.NOT_ENOUGH_SOL_ERROR = "Insufficient SOL for transaction fees. Please add more SOL and try again.";
|
|
46
|
+
const IDLS = [
|
|
47
|
+
WasabiIDL,
|
|
48
|
+
jupiter_1.IDL,
|
|
49
|
+
titan_1.IDL,
|
|
50
|
+
raydium_1.IDL,
|
|
51
|
+
dflow_1.IDL
|
|
51
52
|
];
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
]
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return acc;
|
|
73
|
-
}, {});
|
|
74
|
-
const findWasabiError = (code) => {
|
|
75
|
-
return wasabiErrorIndex[code];
|
|
53
|
+
const programToExpectedErrors = {
|
|
54
|
+
[WasabiIDL.address]: [
|
|
55
|
+
6004, // MinTokensNotMet
|
|
56
|
+
6015, // PrincipalTooHigh
|
|
57
|
+
6017, // PriceTargetNotReached
|
|
58
|
+
6026 // LiquidationThresholdNotReached
|
|
59
|
+
],
|
|
60
|
+
[jupiter_1.IDL.address]: [
|
|
61
|
+
6001 // SlippageToleranceExceeded
|
|
62
|
+
],
|
|
63
|
+
[titan_1.IDL.address]: [
|
|
64
|
+
6008 // LessThanMinimumAmountOut
|
|
65
|
+
],
|
|
66
|
+
[raydium_1.IDL.address]: [
|
|
67
|
+
6022, // TooLittleOutputReceived
|
|
68
|
+
6023, // TooMuchInputPaid
|
|
69
|
+
],
|
|
70
|
+
[dflow_1.IDL.address]: [
|
|
71
|
+
15001, // SlippageLimitExceeded
|
|
72
|
+
]
|
|
76
73
|
};
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}, {});
|
|
86
|
-
const findJupiterError = (code) => {
|
|
87
|
-
return jupiterErrorIndex[code];
|
|
74
|
+
const programErrors = {};
|
|
75
|
+
const programNames = {
|
|
76
|
+
[WasabiIDL.address]: 'Wasabi',
|
|
77
|
+
[jupiter_1.IDL.address]: 'Jupiter',
|
|
78
|
+
[titan_1.IDL.address]: 'Titan',
|
|
79
|
+
[raydium_1.IDL.address]: 'Raydium',
|
|
80
|
+
[dflow_1.IDL.address]: 'DFlow',
|
|
81
|
+
[web3_js_1.SystemProgram.programId.toBase58()]: 'System'
|
|
88
82
|
};
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
for (const idl of IDLS) {
|
|
84
|
+
const expectedErrors = programToExpectedErrors[idl.address] ?? [];
|
|
85
|
+
programErrors[idl.address] = idl.errors.reduce((acc, error) => {
|
|
86
|
+
acc[error.code] = {
|
|
87
|
+
...error,
|
|
88
|
+
expected: expectedErrors.includes(error.code),
|
|
89
|
+
program: programNames[idl.address] ?? 'Unknown'
|
|
90
|
+
};
|
|
91
|
+
return acc;
|
|
92
|
+
}, {});
|
|
93
|
+
}
|
|
94
|
+
const findProgramError = (programId, code) => {
|
|
95
|
+
if (code === 0) {
|
|
96
|
+
return {
|
|
97
|
+
code,
|
|
98
|
+
name: 'InsufficientFundsForRent',
|
|
99
|
+
msg: 'Insufficient SOL to pay for rent',
|
|
100
|
+
expected: true,
|
|
101
|
+
program: programNames[programId] ?? 'Unknown'
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
else if (code === 1) {
|
|
105
|
+
return {
|
|
106
|
+
code,
|
|
107
|
+
name: 'InsufficientFunds',
|
|
108
|
+
msg: 'Insufficient Funds',
|
|
109
|
+
expected: true,
|
|
110
|
+
program: programNames[programId] ?? 'Unknown'
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
else if (code === 4) {
|
|
114
|
+
return {
|
|
115
|
+
code,
|
|
116
|
+
name: 'OwnerDoesNotMatch',
|
|
117
|
+
msg: 'Owner does not match',
|
|
118
|
+
expected: false,
|
|
119
|
+
program: programNames[programId] ?? 'Unknown'
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return programErrors[programId]?.[code];
|
|
100
123
|
};
|
|
101
124
|
const parseSendTransactionError = (error, transaction) => {
|
|
102
125
|
const message = error.transactionError.message;
|
|
@@ -115,20 +138,7 @@ const parseError = (instructionNumber, errorCode, transaction) => {
|
|
|
115
138
|
// Validate instruction against parsed addresses
|
|
116
139
|
const instruction = transaction.message.compiledInstructions[instructionNumber];
|
|
117
140
|
const programId = transaction.message.staticAccountKeys[instruction.programIdIndex].toBase58();
|
|
118
|
-
|
|
119
|
-
if (systemError) {
|
|
120
|
-
return systemError;
|
|
121
|
-
}
|
|
122
|
-
if (programId === wasabiProgramId) {
|
|
123
|
-
return findWasabiError(errorCode);
|
|
124
|
-
}
|
|
125
|
-
else if (programId === jupiterProgramId) {
|
|
126
|
-
return findJupiterError(errorCode);
|
|
127
|
-
}
|
|
128
|
-
else if (programId === titanProgramId) {
|
|
129
|
-
return findTitanError(errorCode);
|
|
130
|
-
}
|
|
131
|
-
return undefined;
|
|
141
|
+
return findProgramError(programId, errorCode);
|
|
132
142
|
};
|
|
133
143
|
exports.parseError = parseError;
|
|
134
144
|
const parseSimulationError = (error, transaction) => {
|
|
@@ -175,58 +185,12 @@ const parseErrorLogs = (logs) => {
|
|
|
175
185
|
if (match) {
|
|
176
186
|
const [_, failingProgramId, errorHex] = match;
|
|
177
187
|
const errorCode = parseInt(errorHex);
|
|
178
|
-
|
|
179
|
-
return findJupiterError(errorCode);
|
|
180
|
-
}
|
|
181
|
-
else if (failingProgramId.localeCompare(titanProgramId) === 0) {
|
|
182
|
-
return findTitanError(errorCode);
|
|
183
|
-
}
|
|
184
|
-
else if (failingProgramId.localeCompare(wasabiProgramId) === 0) {
|
|
185
|
-
return findWasabiError(errorCode);
|
|
186
|
-
}
|
|
187
|
-
else if (failingProgramId.localeCompare(web3_js_1.SystemProgram.programId.toBase58()) === 0) {
|
|
188
|
-
return parseSystemError(errorCode, web3_js_1.SystemProgram.programId.toBase58());
|
|
189
|
-
}
|
|
188
|
+
return findProgramError(failingProgramId, errorCode);
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
191
|
return undefined;
|
|
193
192
|
};
|
|
194
193
|
exports.parseErrorLogs = parseErrorLogs;
|
|
195
|
-
const parseSystemError = (code, programId) => {
|
|
196
|
-
const program = programId === wasabiProgramId
|
|
197
|
-
? 'Wasabi'
|
|
198
|
-
: programId === jupiterProgramId
|
|
199
|
-
? 'Jupiter'
|
|
200
|
-
: 'System';
|
|
201
|
-
if (code === 0) {
|
|
202
|
-
return {
|
|
203
|
-
code,
|
|
204
|
-
name: 'InsufficientFundsForRent',
|
|
205
|
-
msg: 'Insufficient SOL to pay for rent',
|
|
206
|
-
expected: true,
|
|
207
|
-
program
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
else if (code === 1) {
|
|
211
|
-
return {
|
|
212
|
-
code,
|
|
213
|
-
name: 'InsufficientFunds',
|
|
214
|
-
msg: 'Insufficient Funds',
|
|
215
|
-
expected: true,
|
|
216
|
-
program
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
else if (code === 4) {
|
|
220
|
-
return {
|
|
221
|
-
code,
|
|
222
|
-
name: 'OwnerDoesNotMatch',
|
|
223
|
-
msg: 'Owner does not match',
|
|
224
|
-
expected: false,
|
|
225
|
-
program
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
return undefined;
|
|
229
|
-
};
|
|
230
194
|
const matchError = (error) => {
|
|
231
195
|
const msg = error.message;
|
|
232
196
|
const errorPatterns = {
|
|
@@ -242,26 +206,26 @@ const matchError = (error) => {
|
|
|
242
206
|
name: 'TransactionTooLarge',
|
|
243
207
|
msg: 'Routing Error: Failed to find route',
|
|
244
208
|
expected: true,
|
|
245
|
-
program: ''
|
|
209
|
+
program: 'System'
|
|
246
210
|
},
|
|
247
211
|
'.*encoding overruns Uint8Array.*': {
|
|
248
212
|
code: 0,
|
|
249
213
|
name: 'EncodingOverrunsUint8Array',
|
|
250
214
|
msg: 'Routing Error: Failed to find route',
|
|
251
215
|
expected: true,
|
|
252
|
-
program: ''
|
|
216
|
+
program: 'System'
|
|
253
217
|
},
|
|
254
218
|
'.*InsufficientFundsForFee.*': {
|
|
255
219
|
code: 0,
|
|
256
220
|
name: 'InsufficientFundsForFee',
|
|
257
|
-
msg:
|
|
221
|
+
msg: exports.NOT_ENOUGH_SOL_ERROR,
|
|
258
222
|
expected: true,
|
|
259
223
|
program: 'ComputeBudget'
|
|
260
224
|
},
|
|
261
225
|
'.*InsufficientFundsForRent.*': {
|
|
262
226
|
code: 0,
|
|
263
227
|
name: 'InsufficientFundsForRent',
|
|
264
|
-
msg:
|
|
228
|
+
msg: exports.NOT_ENOUGH_SOL_ERROR,
|
|
265
229
|
expected: true,
|
|
266
230
|
program: 'System'
|
|
267
231
|
},
|
|
@@ -309,26 +273,3 @@ const matchError = (error) => {
|
|
|
309
273
|
return undefined;
|
|
310
274
|
};
|
|
311
275
|
exports.matchError = matchError;
|
|
312
|
-
const getFailingSwapProgram = (instructions) => {
|
|
313
|
-
let failingProgramIdx = 0;
|
|
314
|
-
for (let i = 0; i < instructions.length; i++) {
|
|
315
|
-
if (instructions[i].programId.toBase58().localeCompare(wasabiProgramId) === 0) {
|
|
316
|
-
failingProgramIdx = i + 1;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
try {
|
|
321
|
-
const failingProgram = instructions[failingProgramIdx].programId.toBase58();
|
|
322
|
-
return failingProgram === jupiterProgramId
|
|
323
|
-
? 'Jupiter'
|
|
324
|
-
: failingProgram === spl_token_1.TOKEN_PROGRAM_ID.toBase58()
|
|
325
|
-
? 'Token'
|
|
326
|
-
: failingProgram === spl_token_1.TOKEN_2022_PROGRAM_ID.toBase58()
|
|
327
|
-
? 'Token2022'
|
|
328
|
-
: 'Raydium';
|
|
329
|
-
}
|
|
330
|
-
catch (error) {
|
|
331
|
-
return 'Unknown';
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
exports.getFailingSwapProgram = getFailingSwapProgram;
|