wasabi-solana-ts 1.2.9 → 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 +1 -2
- package/dist/error-handling/transactionErrorHandling.js +82 -142
- 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;
|
|
@@ -18,5 +18,4 @@ export declare const parseError: (instructionNumber: number, errorCode: number,
|
|
|
18
18
|
export declare const parseSimulationError: (error: SimulationError, transaction: VersionedTransaction) => ErrorObject | undefined;
|
|
19
19
|
export declare const parseErrorLogs: (logs: string[] | undefined) => ErrorObject | undefined;
|
|
20
20
|
export declare const matchError: (error: Error) => ErrorObject | undefined;
|
|
21
|
-
export declare const getFailingSwapProgram: (instructions: TransactionInstruction[]) => string;
|
|
22
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;
|
|
@@ -43,61 +43,83 @@ class SimulationError extends Error {
|
|
|
43
43
|
}
|
|
44
44
|
exports.SimulationError = SimulationError;
|
|
45
45
|
exports.NOT_ENOUGH_SOL_ERROR = "Insufficient SOL for transaction fees. Please add more SOL and try again.";
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const IDLS = [
|
|
47
|
+
WasabiIDL,
|
|
48
|
+
jupiter_1.IDL,
|
|
49
|
+
titan_1.IDL,
|
|
50
|
+
raydium_1.IDL,
|
|
51
|
+
dflow_1.IDL
|
|
52
52
|
];
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
]
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return acc;
|
|
74
|
-
}, {});
|
|
75
|
-
const findWasabiError = (code) => {
|
|
76
|
-
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
|
+
]
|
|
77
73
|
};
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}, {});
|
|
87
|
-
const findJupiterError = (code) => {
|
|
88
|
-
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'
|
|
89
82
|
};
|
|
90
|
-
const
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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];
|
|
101
123
|
};
|
|
102
124
|
const parseSendTransactionError = (error, transaction) => {
|
|
103
125
|
const message = error.transactionError.message;
|
|
@@ -116,20 +138,7 @@ const parseError = (instructionNumber, errorCode, transaction) => {
|
|
|
116
138
|
// Validate instruction against parsed addresses
|
|
117
139
|
const instruction = transaction.message.compiledInstructions[instructionNumber];
|
|
118
140
|
const programId = transaction.message.staticAccountKeys[instruction.programIdIndex].toBase58();
|
|
119
|
-
|
|
120
|
-
if (systemError) {
|
|
121
|
-
return systemError;
|
|
122
|
-
}
|
|
123
|
-
if (programId === wasabiProgramId) {
|
|
124
|
-
return findWasabiError(errorCode);
|
|
125
|
-
}
|
|
126
|
-
else if (programId === jupiterProgramId) {
|
|
127
|
-
return findJupiterError(errorCode);
|
|
128
|
-
}
|
|
129
|
-
else if (programId === titanProgramId) {
|
|
130
|
-
return findTitanError(errorCode);
|
|
131
|
-
}
|
|
132
|
-
return undefined;
|
|
141
|
+
return findProgramError(programId, errorCode);
|
|
133
142
|
};
|
|
134
143
|
exports.parseError = parseError;
|
|
135
144
|
const parseSimulationError = (error, transaction) => {
|
|
@@ -176,58 +185,12 @@ const parseErrorLogs = (logs) => {
|
|
|
176
185
|
if (match) {
|
|
177
186
|
const [_, failingProgramId, errorHex] = match;
|
|
178
187
|
const errorCode = parseInt(errorHex);
|
|
179
|
-
|
|
180
|
-
return findJupiterError(errorCode);
|
|
181
|
-
}
|
|
182
|
-
else if (failingProgramId.localeCompare(titanProgramId) === 0) {
|
|
183
|
-
return findTitanError(errorCode);
|
|
184
|
-
}
|
|
185
|
-
else if (failingProgramId.localeCompare(wasabiProgramId) === 0) {
|
|
186
|
-
return findWasabiError(errorCode);
|
|
187
|
-
}
|
|
188
|
-
else if (failingProgramId.localeCompare(web3_js_1.SystemProgram.programId.toBase58()) === 0) {
|
|
189
|
-
return parseSystemError(errorCode, web3_js_1.SystemProgram.programId.toBase58());
|
|
190
|
-
}
|
|
188
|
+
return findProgramError(failingProgramId, errorCode);
|
|
191
189
|
}
|
|
192
190
|
}
|
|
193
191
|
return undefined;
|
|
194
192
|
};
|
|
195
193
|
exports.parseErrorLogs = parseErrorLogs;
|
|
196
|
-
const parseSystemError = (code, programId) => {
|
|
197
|
-
const program = programId === wasabiProgramId
|
|
198
|
-
? 'Wasabi'
|
|
199
|
-
: programId === jupiterProgramId
|
|
200
|
-
? 'Jupiter'
|
|
201
|
-
: 'System';
|
|
202
|
-
if (code === 0) {
|
|
203
|
-
return {
|
|
204
|
-
code,
|
|
205
|
-
name: 'InsufficientFundsForRent',
|
|
206
|
-
msg: 'Insufficient SOL to pay for rent',
|
|
207
|
-
expected: true,
|
|
208
|
-
program
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
else if (code === 1) {
|
|
212
|
-
return {
|
|
213
|
-
code,
|
|
214
|
-
name: 'InsufficientFunds',
|
|
215
|
-
msg: 'Insufficient Funds',
|
|
216
|
-
expected: true,
|
|
217
|
-
program
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
else if (code === 4) {
|
|
221
|
-
return {
|
|
222
|
-
code,
|
|
223
|
-
name: 'OwnerDoesNotMatch',
|
|
224
|
-
msg: 'Owner does not match',
|
|
225
|
-
expected: false,
|
|
226
|
-
program
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
return undefined;
|
|
230
|
-
};
|
|
231
194
|
const matchError = (error) => {
|
|
232
195
|
const msg = error.message;
|
|
233
196
|
const errorPatterns = {
|
|
@@ -243,14 +206,14 @@ const matchError = (error) => {
|
|
|
243
206
|
name: 'TransactionTooLarge',
|
|
244
207
|
msg: 'Routing Error: Failed to find route',
|
|
245
208
|
expected: true,
|
|
246
|
-
program: ''
|
|
209
|
+
program: 'System'
|
|
247
210
|
},
|
|
248
211
|
'.*encoding overruns Uint8Array.*': {
|
|
249
212
|
code: 0,
|
|
250
213
|
name: 'EncodingOverrunsUint8Array',
|
|
251
214
|
msg: 'Routing Error: Failed to find route',
|
|
252
215
|
expected: true,
|
|
253
|
-
program: ''
|
|
216
|
+
program: 'System'
|
|
254
217
|
},
|
|
255
218
|
'.*InsufficientFundsForFee.*': {
|
|
256
219
|
code: 0,
|
|
@@ -310,26 +273,3 @@ const matchError = (error) => {
|
|
|
310
273
|
return undefined;
|
|
311
274
|
};
|
|
312
275
|
exports.matchError = matchError;
|
|
313
|
-
const getFailingSwapProgram = (instructions) => {
|
|
314
|
-
let failingProgramIdx = 0;
|
|
315
|
-
for (let i = 0; i < instructions.length; i++) {
|
|
316
|
-
if (instructions[i].programId.toBase58().localeCompare(wasabiProgramId) === 0) {
|
|
317
|
-
failingProgramIdx = i + 1;
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
try {
|
|
322
|
-
const failingProgram = instructions[failingProgramIdx].programId.toBase58();
|
|
323
|
-
return failingProgram === jupiterProgramId
|
|
324
|
-
? 'Jupiter'
|
|
325
|
-
: failingProgram === spl_token_1.TOKEN_PROGRAM_ID.toBase58()
|
|
326
|
-
? 'Token'
|
|
327
|
-
: failingProgram === spl_token_1.TOKEN_2022_PROGRAM_ID.toBase58()
|
|
328
|
-
? 'Token2022'
|
|
329
|
-
: 'Raydium';
|
|
330
|
-
}
|
|
331
|
-
catch (error) {
|
|
332
|
-
return 'Unknown';
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
exports.getFailingSwapProgram = getFailingSwapProgram;
|