wasabi-solana-ts 1.2.9 → 1.2.10-regular-interest

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;
@@ -7699,16 +7699,16 @@ export type WasabiSolana = {
7699
7699
  ];
7700
7700
  },
7701
7701
  {
7702
- "name": "recordInterestForLongPosition";
7702
+ "name": "recordLongInterest";
7703
7703
  "discriminator": [
7704
- 46,
7705
- 3,
7706
- 12,
7707
- 151,
7708
- 56,
7709
- 105,
7710
- 134,
7711
- 60
7704
+ 101,
7705
+ 57,
7706
+ 251,
7707
+ 97,
7708
+ 19,
7709
+ 118,
7710
+ 203,
7711
+ 222
7712
7712
  ];
7713
7713
  "accounts": [
7714
7714
  {
@@ -7722,25 +7722,16 @@ export type WasabiSolana = {
7722
7722
  "name": "permission";
7723
7723
  },
7724
7724
  {
7725
- "name": "lpVault";
7726
- "writable": true;
7727
- "relations": [
7728
- "position"
7729
- ];
7730
- },
7731
- {
7732
- "name": "vault";
7725
+ "name": "pool";
7733
7726
  "writable": true;
7734
- "relations": [
7735
- "lpVault"
7736
- ];
7737
7727
  },
7738
7728
  {
7739
7729
  "name": "position";
7740
7730
  "writable": true;
7741
7731
  },
7742
7732
  {
7743
- "name": "currency";
7733
+ "name": "lpVault";
7734
+ "writable": true;
7744
7735
  "relations": [
7745
7736
  "position"
7746
7737
  ];
@@ -7798,9 +7789,6 @@ export type WasabiSolana = {
7798
7789
  }
7799
7790
  ];
7800
7791
  };
7801
- },
7802
- {
7803
- "name": "tokenProgram";
7804
7792
  }
7805
7793
  ];
7806
7794
  "args": [
@@ -7811,16 +7799,16 @@ export type WasabiSolana = {
7811
7799
  ];
7812
7800
  },
7813
7801
  {
7814
- "name": "recordInterestForShortPosition";
7802
+ "name": "recordShortInterest";
7815
7803
  "discriminator": [
7816
- 0,
7817
- 204,
7818
- 6,
7819
- 181,
7804
+ 54,
7805
+ 196,
7806
+ 121,
7807
+ 111,
7820
7808
  120,
7821
- 76,
7822
- 118,
7823
- 43
7809
+ 233,
7810
+ 41,
7811
+ 104
7824
7812
  ];
7825
7813
  "accounts": [
7826
7814
  {
@@ -7834,26 +7822,19 @@ export type WasabiSolana = {
7834
7822
  "name": "permission";
7835
7823
  },
7836
7824
  {
7837
- "name": "lpVault";
7825
+ "name": "pool";
7838
7826
  "writable": true;
7839
- "relations": [
7840
- "position"
7841
- ];
7842
- },
7843
- {
7844
- "name": "vault";
7845
- "writable": true;
7846
- "relations": [
7847
- "lpVault"
7848
- ];
7849
7827
  },
7850
7828
  {
7851
7829
  "name": "position";
7852
7830
  "writable": true;
7853
7831
  },
7854
7832
  {
7855
- "name": "pool";
7833
+ "name": "lpVault";
7856
7834
  "writable": true;
7835
+ "relations": [
7836
+ "position"
7837
+ ];
7857
7838
  },
7858
7839
  {
7859
7840
  "name": "currencyVault";
@@ -7866,20 +7847,22 @@ export type WasabiSolana = {
7866
7847
  "name": "collateralVault";
7867
7848
  "writable": true;
7868
7849
  "relations": [
7869
- "pool"
7850
+ "pool",
7851
+ "position"
7870
7852
  ];
7871
7853
  },
7872
7854
  {
7873
- "name": "currency";
7855
+ "name": "vault";
7856
+ "writable": true;
7874
7857
  "relations": [
7875
- "position"
7858
+ "lpVault"
7876
7859
  ];
7877
7860
  },
7861
+ {
7862
+ "name": "currency";
7863
+ },
7878
7864
  {
7879
7865
  "name": "collateral";
7880
- "relations": [
7881
- "position"
7882
- ];
7883
7866
  },
7884
7867
  {
7885
7868
  "name": "debtController";
@@ -12183,11 +12166,6 @@ export type WasabiSolana = {
12183
12166
  },
12184
12167
  {
12185
12168
  "code": 6041;
12186
- "name": "invalidInterestAmount";
12187
- "msg": "Invalid interest amount";
12188
- },
12189
- {
12190
- "code": 6042;
12191
12169
  "name": "maxInterestExceeded";
12192
12170
  "msg": "Interest payment exceeds maximum interest";
12193
12171
  }
@@ -12607,6 +12585,10 @@ export type WasabiSolana = {
12607
12585
  "name": "id";
12608
12586
  "type": "pubkey";
12609
12587
  },
12588
+ {
12589
+ "name": "trader";
12590
+ "type": "pubkey";
12591
+ },
12610
12592
  {
12611
12593
  "name": "interestPaid";
12612
12594
  "type": "u64";
@@ -12622,6 +12604,10 @@ export type WasabiSolana = {
12622
12604
  {
12623
12605
  "name": "downPaymentReduced";
12624
12606
  "type": "u64";
12607
+ },
12608
+ {
12609
+ "name": "isLong";
12610
+ "type": "bool";
12625
12611
  }
12626
12612
  ];
12627
12613
  };
@@ -7693,16 +7693,16 @@
7693
7693
  ]
7694
7694
  },
7695
7695
  {
7696
- "name": "record_interest_for_long_position",
7696
+ "name": "record_long_interest",
7697
7697
  "discriminator": [
7698
- 46,
7699
- 3,
7700
- 12,
7701
- 151,
7702
- 56,
7703
- 105,
7704
- 134,
7705
- 60
7698
+ 101,
7699
+ 57,
7700
+ 251,
7701
+ 97,
7702
+ 19,
7703
+ 118,
7704
+ 203,
7705
+ 222
7706
7706
  ],
7707
7707
  "accounts": [
7708
7708
  {
@@ -7716,25 +7716,16 @@
7716
7716
  "name": "permission"
7717
7717
  },
7718
7718
  {
7719
- "name": "lp_vault",
7720
- "writable": true,
7721
- "relations": [
7722
- "position"
7723
- ]
7724
- },
7725
- {
7726
- "name": "vault",
7727
- "writable": true,
7728
- "relations": [
7729
- "lp_vault"
7730
- ]
7719
+ "name": "pool",
7720
+ "writable": true
7731
7721
  },
7732
7722
  {
7733
7723
  "name": "position",
7734
7724
  "writable": true
7735
7725
  },
7736
7726
  {
7737
- "name": "currency",
7727
+ "name": "lp_vault",
7728
+ "writable": true,
7738
7729
  "relations": [
7739
7730
  "position"
7740
7731
  ]
@@ -7792,9 +7783,6 @@
7792
7783
  }
7793
7784
  ]
7794
7785
  }
7795
- },
7796
- {
7797
- "name": "token_program"
7798
7786
  }
7799
7787
  ],
7800
7788
  "args": [
@@ -7805,16 +7793,16 @@
7805
7793
  ]
7806
7794
  },
7807
7795
  {
7808
- "name": "record_interest_for_short_position",
7796
+ "name": "record_short_interest",
7809
7797
  "discriminator": [
7810
- 0,
7811
- 204,
7812
- 6,
7813
- 181,
7798
+ 54,
7799
+ 196,
7800
+ 121,
7801
+ 111,
7814
7802
  120,
7815
- 76,
7816
- 118,
7817
- 43
7803
+ 233,
7804
+ 41,
7805
+ 104
7818
7806
  ],
7819
7807
  "accounts": [
7820
7808
  {
@@ -7828,26 +7816,19 @@
7828
7816
  "name": "permission"
7829
7817
  },
7830
7818
  {
7831
- "name": "lp_vault",
7832
- "writable": true,
7833
- "relations": [
7834
- "position"
7835
- ]
7836
- },
7837
- {
7838
- "name": "vault",
7839
- "writable": true,
7840
- "relations": [
7841
- "lp_vault"
7842
- ]
7819
+ "name": "pool",
7820
+ "writable": true
7843
7821
  },
7844
7822
  {
7845
7823
  "name": "position",
7846
7824
  "writable": true
7847
7825
  },
7848
7826
  {
7849
- "name": "pool",
7850
- "writable": true
7827
+ "name": "lp_vault",
7828
+ "writable": true,
7829
+ "relations": [
7830
+ "position"
7831
+ ]
7851
7832
  },
7852
7833
  {
7853
7834
  "name": "currency_vault",
@@ -7860,20 +7841,22 @@
7860
7841
  "name": "collateral_vault",
7861
7842
  "writable": true,
7862
7843
  "relations": [
7863
- "pool"
7844
+ "pool",
7845
+ "position"
7864
7846
  ]
7865
7847
  },
7866
7848
  {
7867
- "name": "currency",
7849
+ "name": "vault",
7850
+ "writable": true,
7868
7851
  "relations": [
7869
- "position"
7852
+ "lp_vault"
7870
7853
  ]
7871
7854
  },
7872
7855
  {
7873
- "name": "collateral",
7874
- "relations": [
7875
- "position"
7876
- ]
7856
+ "name": "currency"
7857
+ },
7858
+ {
7859
+ "name": "collateral"
7877
7860
  },
7878
7861
  {
7879
7862
  "name": "debt_controller",
@@ -12177,11 +12160,6 @@
12177
12160
  },
12178
12161
  {
12179
12162
  "code": 6041,
12180
- "name": "InvalidInterestAmount",
12181
- "msg": "Invalid interest amount"
12182
- },
12183
- {
12184
- "code": 6042,
12185
12163
  "name": "MaxInterestExceeded",
12186
12164
  "msg": "Interest payment exceeds maximum interest"
12187
12165
  }
@@ -12601,6 +12579,10 @@
12601
12579
  "name": "id",
12602
12580
  "type": "pubkey"
12603
12581
  },
12582
+ {
12583
+ "name": "trader",
12584
+ "type": "pubkey"
12585
+ },
12604
12586
  {
12605
12587
  "name": "interest_paid",
12606
12588
  "type": "u64"
@@ -12616,6 +12598,10 @@
12616
12598
  {
12617
12599
  "name": "down_payment_reduced",
12618
12600
  "type": "u64"
12601
+ },
12602
+ {
12603
+ "name": "is_long",
12604
+ "type": "bool"
12619
12605
  }
12620
12606
  ]
12621
12607
  }
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-regular-interest",
4
4
  "description": "Typescript library for the Wasabi program",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",