@switch-win/sdk 1.0.4 → 1.0.6
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/README.md +5 -5
- package/abi/SwitchLimitOrderABI.json +1 -1295
- package/abi/SwitchRouterABI.json +1 -954
- package/package.json +1 -1
- package/src/constants.ts +77 -10
- package/src/index.ts +3 -0
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -33,7 +33,7 @@ export const CHAIN_ID = 369;
|
|
|
33
33
|
// ── Contract addresses --
|
|
34
34
|
|
|
35
35
|
/** SwitchRouter contract — target for all swap transactions */
|
|
36
|
-
export const SWITCH_ROUTER = "
|
|
36
|
+
export const SWITCH_ROUTER = "0xc6d4f096A7a4B3d534DEa725821346Ee1b4FE5CE";
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Native PLS sentinel address.
|
|
@@ -51,7 +51,7 @@ export const WPLS = "0xA1077a294dDE1B09bB078844df40758a5D0f9a27";
|
|
|
51
51
|
*
|
|
52
52
|
* The EIP-712 domain `verifyingContract` MUST match this address.
|
|
53
53
|
*/
|
|
54
|
-
export const SWITCH_LIMIT_ORDER = "
|
|
54
|
+
export const SWITCH_LIMIT_ORDER = "0x0e884072a891b406C0D814907A1E2310fE5F5Deb";
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* SwitchPLSFlow contract address on PulseChain.
|
|
@@ -60,7 +60,7 @@ export const SWITCH_LIMIT_ORDER = "0x79925587bE77C25b292C0ecA6FEdD3A3f07916F9";
|
|
|
60
60
|
* which wraps to WPLS and creates the limit order on their behalf.
|
|
61
61
|
* No EIP-712 signing required — single transaction.
|
|
62
62
|
*/
|
|
63
|
-
export const SWITCH_PLS_FLOW = "
|
|
63
|
+
export const SWITCH_PLS_FLOW = "0x88c9e2C83b6B7c707602e548481e58E920694E64";
|
|
64
64
|
|
|
65
65
|
// ── Limit Order API endpoints ───────────────────────────────────────────────
|
|
66
66
|
|
|
@@ -135,13 +135,49 @@ export const GO_SWITCH_ABI = [
|
|
|
135
135
|
* SwitchRouter custom error signatures for decoding reverts.
|
|
136
136
|
*/
|
|
137
137
|
export const SWITCH_ROUTER_ERRORS = [
|
|
138
|
-
"error FinalAmountOutTooLow()",
|
|
139
|
-
"error ExcessiveFee()",
|
|
140
138
|
"error InsufficientFee()",
|
|
141
|
-
"error
|
|
139
|
+
"error ExcessiveFee()",
|
|
140
|
+
"error FinalAmountOutTooLow()",
|
|
141
|
+
"error EmptySplit()",
|
|
142
|
+
"error SplitMixedTokenIn()",
|
|
143
|
+
"error SplitMixedTokenOut()",
|
|
142
144
|
"error ZeroInput()",
|
|
145
|
+
"error MsgValueMismatch()",
|
|
146
|
+
"error PathNeedsBeginWithWPLS()",
|
|
147
|
+
"error PathNeedsEndWithWPLS()",
|
|
148
|
+
"error AdapterNotApproved(address)",
|
|
149
|
+
"error EmptyHop()",
|
|
150
|
+
"error FeeNotSupported()",
|
|
143
151
|
] as const;
|
|
144
152
|
|
|
153
|
+
/**
|
|
154
|
+
* 4-byte error selectors for SwitchRouter reverts.
|
|
155
|
+
*
|
|
156
|
+
* Useful for matching raw revert data from `eth_call` or failed transactions.
|
|
157
|
+
* Key = selector hex, value = human-readable error name.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* const selector = revertData.slice(0, 10); // "0x4a2ab023"
|
|
162
|
+
* const name = SWITCH_ROUTER_ERROR_SELECTORS[selector]; // "FinalAmountOutTooLow"
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export const SWITCH_ROUTER_ERROR_SELECTORS: Record<string, string> = {
|
|
166
|
+
"0x025dbdd4": "InsufficientFee",
|
|
167
|
+
"0x2977da44": "ExcessiveFee",
|
|
168
|
+
"0x4a2ab023": "FinalAmountOutTooLow",
|
|
169
|
+
"0x5725cad2": "EmptySplit",
|
|
170
|
+
"0xdceb8b7a": "SplitMixedTokenIn",
|
|
171
|
+
"0x45a68c8c": "SplitMixedTokenOut",
|
|
172
|
+
"0xaf458c07": "ZeroInput",
|
|
173
|
+
"0xbc6f88c5": "MsgValueMismatch",
|
|
174
|
+
"0x906478dc": "PathNeedsBeginWithWPLS",
|
|
175
|
+
"0x037ccaee": "PathNeedsEndWithWPLS",
|
|
176
|
+
"0x0c48343e": "AdapterNotApproved",
|
|
177
|
+
"0xb19ef58a": "EmptyHop",
|
|
178
|
+
"0x73620122": "FeeNotSupported",
|
|
179
|
+
};
|
|
180
|
+
|
|
145
181
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
146
182
|
// Limit Order — EIP-712 Constants
|
|
147
183
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
@@ -205,17 +241,40 @@ export const LIMIT_ORDER_ABI = [
|
|
|
205
241
|
* SwitchLimitOrder custom error signatures for decoding reverts.
|
|
206
242
|
*/
|
|
207
243
|
export const LIMIT_ORDER_ERRORS = [
|
|
208
|
-
"error ExcessiveFee()",
|
|
209
|
-
"error InsufficientOutput()",
|
|
210
|
-
"error InvalidAmount()",
|
|
211
244
|
"error InvalidSignature()",
|
|
212
|
-
"error InvalidTokens()",
|
|
213
245
|
"error NonceAlreadyUsed()",
|
|
214
246
|
"error OrderExpired()",
|
|
247
|
+
"error InsufficientOutput()",
|
|
248
|
+
"error InvalidAmount()",
|
|
249
|
+
"error ExcessiveFee()",
|
|
215
250
|
"error RouteInputExceedsMax()",
|
|
251
|
+
"error InvalidTokens()",
|
|
216
252
|
"error TransferFailed()",
|
|
253
|
+
"error OperatorOnly()",
|
|
217
254
|
] as const;
|
|
218
255
|
|
|
256
|
+
/**
|
|
257
|
+
* 4-byte error selectors for SwitchLimitOrder reverts.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```ts
|
|
261
|
+
* const selector = revertData.slice(0, 10); // "0x8baa579f"
|
|
262
|
+
* const name = LIMIT_ORDER_ERROR_SELECTORS[selector]; // "InvalidSignature"
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
export const LIMIT_ORDER_ERROR_SELECTORS: Record<string, string> = {
|
|
266
|
+
"0x8baa579f": "InvalidSignature",
|
|
267
|
+
"0x1fb09b80": "NonceAlreadyUsed",
|
|
268
|
+
"0xc56873ba": "OrderExpired",
|
|
269
|
+
"0xbb2875c3": "InsufficientOutput",
|
|
270
|
+
"0x2c5211c6": "InvalidAmount",
|
|
271
|
+
"0x2977da44": "ExcessiveFee",
|
|
272
|
+
"0xb6972a87": "RouteInputExceedsMax",
|
|
273
|
+
"0x672215de": "InvalidTokens",
|
|
274
|
+
"0x90b8ec18": "TransferFailed",
|
|
275
|
+
"0xae5e3e00": "OperatorOnly",
|
|
276
|
+
};
|
|
277
|
+
|
|
219
278
|
/**
|
|
220
279
|
* Minimal ABI for the SwitchPLSFlow contract.
|
|
221
280
|
*
|
|
@@ -237,3 +296,11 @@ export const PLS_FLOW_ERRORS = [
|
|
|
237
296
|
"error ZeroAmountIn()",
|
|
238
297
|
"error InvalidTokenOut()",
|
|
239
298
|
] as const;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* 4-byte error selectors for SwitchPLSFlow reverts.
|
|
302
|
+
*/
|
|
303
|
+
export const PLS_FLOW_ERROR_SELECTORS: Record<string, string> = {
|
|
304
|
+
"0x990965c1": "ZeroAmountIn",
|
|
305
|
+
"0x1b6d1fa0": "InvalidTokenOut",
|
|
306
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -69,6 +69,7 @@ export {
|
|
|
69
69
|
ERC20_ABI,
|
|
70
70
|
GO_SWITCH_ABI,
|
|
71
71
|
SWITCH_ROUTER_ERRORS,
|
|
72
|
+
SWITCH_ROUTER_ERROR_SELECTORS,
|
|
72
73
|
} from "./constants.js";
|
|
73
74
|
|
|
74
75
|
// Constants — Limit Orders
|
|
@@ -83,8 +84,10 @@ export {
|
|
|
83
84
|
LIMIT_ORDER_EIP712_TYPES,
|
|
84
85
|
LIMIT_ORDER_ABI,
|
|
85
86
|
LIMIT_ORDER_ERRORS,
|
|
87
|
+
LIMIT_ORDER_ERROR_SELECTORS,
|
|
86
88
|
PLS_FLOW_ABI,
|
|
87
89
|
PLS_FLOW_ERRORS,
|
|
90
|
+
PLS_FLOW_ERROR_SELECTORS,
|
|
88
91
|
} from "./constants.js";
|
|
89
92
|
|
|
90
93
|
// Limit Order helpers
|