@switch-win/sdk 1.0.6 → 1.0.8

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 CHANGED
@@ -86,7 +86,8 @@ curl -H "x-api-key: YOUR_KEY" \
86
86
  # 2. Approve the SwitchRouter to spend your input token (ERC-20 only, skip for native PLS)
87
87
 
88
88
  # 3. Send the transaction using the `tx` object from the response:
89
- # { to: "0x31077...", data: "0x...", value: "0" }
89
+ # { to: "0x0305...", data: "0x...", value: "0" }
90
+ # ⚠️ Always use tx.to — do NOT hardcode the router address
90
91
  ```
91
92
 
92
93
  ### Using the SDK types (TypeScript)
@@ -106,10 +107,12 @@ const quote: BestPathResponse = await res.json();
106
107
  const token = new ethers.Contract(fromToken, ["function approve(address,uint256)"], signer);
107
108
  await (await token.approve(SWITCH_ROUTER, amount)).wait();
108
109
 
109
- // 3. Send the swap
110
+ // 3. Send the swap — always use quote.tx which includes the correct router address
110
111
  await signer.sendTransaction(quote.tx);
111
112
  ```
112
113
 
114
+ > **⚠️ Always use `tx.to` from the quote response** when sending swap transactions. Do NOT hardcode the router address — the contract may be redeployed.
115
+
113
116
  For a production integration with tax token handling, adapter filtering, and fee mode selection, see [Swap Integration Flow](#swap-integration-flow) and the [full examples](examples/).
114
117
 
115
118
  ---
@@ -297,6 +300,8 @@ console.log("Swap confirmed:", receipt.hash);
297
300
 
298
301
  That's it. The `tx.data` already encodes the correct `goSwitch()` call with your routes, slippage protection, fee, and partner address.
299
302
 
303
+ > **⚠️ Always use `tx.to` from the response** — do NOT hardcode the router address. The `SWITCH_ROUTER` constant is provided for **token approvals only**. The router contract may be redeployed; `tx.to` always points to the current production router.
304
+
300
305
  The `tx` object does not include a `gas` field. Most wallet libraries (ethers.js, web3.py, MetaMask) auto-estimate gas when `gas` is omitted. For multi-hop split swaps, `500,000`–`1,000,000` gas is typically sufficient:
301
306
 
302
307
  ```js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@switch-win/sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Official integration kit for the Switch DEX Aggregator on PulseChain — types, constants, ABIs, limit orders, and examples",
5
5
  "author": "BuildTheTech",
6
6
  "license": "MIT",
package/src/constants.ts CHANGED
@@ -32,8 +32,15 @@ export const CHAIN_ID = 369;
32
32
 
33
33
  // ── Contract addresses --
34
34
 
35
- /** SwitchRouter contract — target for all swap transactions */
36
- export const SWITCH_ROUTER = "0xc6d4f096A7a4B3d534DEa725821346Ee1b4FE5CE";
35
+ /**
36
+ * SwitchRouter contract — approval target for swap transactions.
37
+ *
38
+ * **Important:** Do NOT hardcode this address as the `to` field when sending
39
+ * swap transactions. Always use `tx.to` from the quote response — the router
40
+ * contract may be redeployed. This constant is safe for **approvals only**
41
+ * (the new router honours legacy allowances).
42
+ */
43
+ export const SWITCH_ROUTER = "0x0305fcb5dA680EA6fd1B01A96C1949175B99d406";
37
44
 
38
45
  /**
39
46
  * Native PLS sentinel address.
@@ -49,9 +56,25 @@ export const WPLS = "0xA1077a294dDE1B09bB078844df40758a5D0f9a27";
49
56
  /**
50
57
  * SwitchLimitOrder contract address on PulseChain.
51
58
  *
59
+ * This is the current production limit order contract.
60
+ * For integrators, treat this as user-facing V2.
52
61
  * The EIP-712 domain `verifyingContract` MUST match this address.
53
62
  */
54
- export const SWITCH_LIMIT_ORDER = "0x0e884072a891b406C0D814907A1E2310fE5F5Deb";
63
+ export const SWITCH_LIMIT_ORDER = "0x8e3881bdF81Fc0211383B2e576076B654F7aFD86";
64
+
65
+ /**
66
+ * Previous production SwitchLimitOrder contract on PulseChain.
67
+ *
68
+ * For integrators, treat this as user-facing V1.
69
+ */
70
+ export const SWITCH_LIMIT_ORDER_V1 = "0x0e884072a891b406c0d814907a1e2310fe5f5deb";
71
+
72
+ /**
73
+ * Current production SwitchLimitOrder contract alias.
74
+ *
75
+ * Use this if you want explicit user-facing version naming in integrations.
76
+ */
77
+ export const SWITCH_LIMIT_ORDER_V2 = SWITCH_LIMIT_ORDER;
55
78
 
56
79
  /**
57
80
  * SwitchPLSFlow contract address on PulseChain.
package/src/index.ts CHANGED
@@ -75,6 +75,8 @@ export {
75
75
  // Constants — Limit Orders
76
76
  export {
77
77
  SWITCH_LIMIT_ORDER,
78
+ SWITCH_LIMIT_ORDER_V1,
79
+ SWITCH_LIMIT_ORDER_V2,
78
80
  SWITCH_PLS_FLOW,
79
81
  LIMIT_ORDER_API_BASE,
80
82
  LIMIT_ORDERS_ENDPOINT,
@@ -181,7 +181,18 @@ export function buildLimitOrder(options: BuildLimitOrderOptions): LimitOrderPara
181
181
  * const signature = await signer._signTypedData(domain, types, order);
182
182
  * ```
183
183
  */
184
- export function getEIP712SigningParams() {
184
+ export function getEIP712SigningParams(limitOrderContract?: string) {
185
+ if (limitOrderContract) {
186
+ return {
187
+ domain: {
188
+ name: "SwitchLimitOrder" as const,
189
+ version: "2" as const,
190
+ chainId: 369 as const,
191
+ verifyingContract: limitOrderContract,
192
+ },
193
+ types: LIMIT_ORDER_EIP712_TYPES,
194
+ } as const;
195
+ }
185
196
  return {
186
197
  domain: LIMIT_ORDER_EIP712_DOMAIN,
187
198
  types: LIMIT_ORDER_EIP712_TYPES,
@@ -199,8 +210,8 @@ export function getEIP712SigningParams() {
199
210
  *
200
211
  * @returns The SwitchLimitOrder contract address
201
212
  */
202
- export function getApprovalTarget(): string {
203
- return SWITCH_LIMIT_ORDER;
213
+ export function getApprovalTarget(limitOrderContract?: string): string {
214
+ return limitOrderContract || SWITCH_LIMIT_ORDER;
204
215
  }
205
216
 
206
217
  /**