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.
@@ -1,4 +1,4 @@
1
- import { SendTransactionError, VersionedTransaction, TransactionInstruction } from '@solana/web3.js';
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.getFailingSwapProgram = exports.matchError = exports.parseErrorLogs = exports.parseSimulationError = exports.parseError = exports.parseSendTransactionError = exports.NOT_ENOUGH_SOL_ERROR = exports.SimulationError = void 0;
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 spl_token_1 = require("@solana/spl-token");
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 wasabiProgramId = 'spicyTHtbmarmUxwFSHYpA8G4uP2nRNq38RReMpoZ9c';
47
- const wasabiExpectedErrors = [
48
- 6004, // MinTokensNotMet
49
- 6015, // PrincipalTooHigh
50
- 6017, // PriceTargetNotReached
51
- 6026 // LiquidationThresholdNotReached
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 jupiterProgramId = 'JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4';
54
- const jupiterExpectedErrors = [
55
- 6001 // SlippageToleranceExceeded
56
- ];
57
- const titanProgramId = 'T1TANpTeScyeqVzzgNViGDNrkQ6qHz9KrSBS4aNXvGT';
58
- const titanExpectedErrors = [
59
- 6008 // LessThanMinimumAmountOut
60
- ];
61
- //@ts-ignore
62
- const raydiumErrors = [
63
- 6028, // Invalid first tick array
64
- ];
65
- // Index errors by code for quick lookup
66
- const wasabiErrorIndex = WasabiIDL.errors.reduce((acc, error) => {
67
- const expected = wasabiExpectedErrors.includes(error.code);
68
- acc[error.code] = {
69
- ...error,
70
- expected,
71
- program: 'Wasabi'
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 jupiterErrorIndex = jupiter_1.IDL.errors.reduce((acc, error) => {
79
- const expected = jupiterExpectedErrors.includes(error.code);
80
- acc[error.code] = {
81
- ...error,
82
- expected,
83
- program: 'Jupiter'
84
- };
85
- return acc;
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 titanErrorIndex = titan_1.IDL.errors.reduce((acc, error) => {
91
- const expected = titanExpectedErrors.includes(error.code);
92
- acc[error.code] = {
93
- ...error,
94
- expected,
95
- program: 'Titan'
96
- };
97
- return acc;
98
- }, {});
99
- const findTitanError = (code) => {
100
- return titanErrorIndex[code];
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
- const systemError = parseSystemError(errorCode, programId);
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
- if (failingProgramId.localeCompare(jupiterProgramId) === 0) {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasabi-solana-ts",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "description": "Typescript library for the Wasabi program",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",