@switch-win/sdk 1.2.1 → 1.2.2
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 +81 -80
- package/ROBINHOOD.md +629 -597
- package/package.json +1 -1
- package/src/index.ts +26 -26
- package/src/limit-orders.ts +60 -30
- package/src/networks/index.ts +20 -20
- package/src/networks/robinhood.ts +327 -315
package/ROBINHOOD.md
CHANGED
|
@@ -1,610 +1,642 @@
|
|
|
1
|
-
# Switch SDK — Robinhood Chain
|
|
2
|
-
|
|
3
|
-
Production integration reference for Switch swaps on Robinhood Chain mainnet.
|
|
4
|
-
|
|
5
|
-
| Setting | Value |
|
|
6
|
-
|---|---|
|
|
7
|
-
| API network | `robinhood` |
|
|
8
|
-
| Chain ID | `4663` |
|
|
9
|
-
| Native currency | ETH (18 decimals) |
|
|
10
|
-
| Public RPC | `https://rpc.mainnet.chain.robinhood.com` |
|
|
11
|
-
| Explorer | `https://robinhoodchain.blockscout.com` |
|
|
12
|
-
| Quote API | `https://quote.switch.win/swap/quote` |
|
|
13
|
-
| Tax API | `https://quote.switch.win/swap/checkTax` |
|
|
14
|
-
| Supported liquidity | Uniswap V2, V3, and hookless static-fee V4 |
|
|
15
|
-
| Limit orders | Not currently available |
|
|
16
|
-
|
|
17
|
-
## Contents
|
|
18
|
-
|
|
19
|
-
- [Installation](#installation)
|
|
20
|
-
- [Authentication](#authentication)
|
|
21
|
-
- [Network configuration](#network-configuration)
|
|
22
|
-
- [Contracts and native currency](#contracts-and-native-currency)
|
|
23
|
-
- [Uniswap V4 routing](#uniswap-v4-routing)
|
|
24
|
-
- [Swap integration flow](#swap-integration-flow)
|
|
25
|
-
- [Quickstart](#quickstart)
|
|
26
|
-
- [Tax-token checks](#tax-token-checks)
|
|
27
|
-
- [Selecting `feeOnOutput`](#selecting-feeonoutput)
|
|
28
|
-
- [Approving and executing](#approving-and-executing)
|
|
29
|
-
- [Swap API reference](#swap-api-reference)
|
|
30
|
-
- [Error handling](#error-handling)
|
|
31
|
-
- [Partner fee sharing](#partner-fee-sharing)
|
|
32
|
-
- [Tokens and routing](#tokens-and-routing)
|
|
33
|
-
- [Rate limits](#rate-limits)
|
|
34
|
-
- [Current limitations](#current-limitations)
|
|
35
|
-
|
|
36
|
-
## Installation
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
npm install @switch-win/sdk
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
```ts
|
|
43
|
-
import {
|
|
44
|
-
ROBINHOOD_CHAIN,
|
|
45
|
-
ROBINHOOD_NATIVE_ETH,
|
|
46
|
-
ROBINHOOD_SWITCH_CONTRACTS,
|
|
47
|
-
ROBINHOOD_UNISWAP_CONTRACTS,
|
|
48
|
-
ROBINHOOD_TOKENS,
|
|
49
|
-
ROBINHOOD_FEE_TOKEN_PRIORITY,
|
|
50
|
-
ROBINHOOD_FRONTEND_DEFAULT_TOKENS,
|
|
51
|
-
ROBINHOOD_FRONTEND_TOKEN_LIST,
|
|
52
|
-
buildRobinhoodQuoteUrl,
|
|
53
|
-
type BestPathResponse,
|
|
54
|
-
} from "@switch-win/sdk";
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
The same exports are available from the smaller network entrypoint:
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
import {
|
|
61
|
-
ROBINHOOD_CHAIN,
|
|
62
|
-
ROBINHOOD_TOKENS,
|
|
63
|
-
buildRobinhoodQuoteUrl,
|
|
64
|
-
} from "@switch-win/sdk/networks/robinhood";
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## Authentication
|
|
68
|
-
|
|
69
|
-
Every request to `quote.switch.win` requires a Switch API key in the
|
|
70
|
-
`x-api-key` header:
|
|
71
|
-
|
|
72
|
-
```ts
|
|
73
|
-
const headers = {
|
|
74
|
-
"x-api-key": process.env.SWITCH_API_KEY!,
|
|
75
|
-
};
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
Do not expose a production API key in browser JavaScript. Browser applications
|
|
79
|
-
should call a same-origin server route that attaches the key before forwarding
|
|
80
|
-
the request to Switch.
|
|
81
|
-
|
|
82
|
-
## Network configuration
|
|
83
|
-
|
|
84
|
-
`ROBINHOOD_CHAIN` can be adapted directly for most wallet libraries:
|
|
85
|
-
|
|
86
|
-
```ts
|
|
87
|
-
const robinhoodWalletChain = {
|
|
88
|
-
chainId: `0x${ROBINHOOD_CHAIN.id.toString(16)}`,
|
|
89
|
-
chainName: ROBINHOOD_CHAIN.name,
|
|
90
|
-
nativeCurrency: ROBINHOOD_CHAIN.nativeCurrency,
|
|
91
|
-
rpcUrls: [...ROBINHOOD_CHAIN.rpcUrls],
|
|
92
|
-
blockExplorerUrls: [ROBINHOOD_CHAIN.blockExplorerUrl],
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
await window.ethereum.request({
|
|
96
|
-
method: "wallet_addEthereumChain",
|
|
97
|
-
params: [robinhoodWalletChain],
|
|
98
|
-
});
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## Contracts and native currency
|
|
102
|
-
|
|
103
|
-
### Switch deployment
|
|
104
|
-
|
|
105
|
-
| Contract | Address |
|
|
106
|
-
|---|---|
|
|
107
|
-
| SwitchRouter | `0x8730C3e2cF2c8CDa8E6166837A1Ed26f46aa9E59` |
|
|
108
|
-
| Uniswap V2 adapter | `0x7a14d7A8509a66209D4332843b983b29bF5604A4` |
|
|
109
|
-
| Uniswap V3 adapter | `0xbcA08f296d9Ba0dc19Aa0E05D355365cE29A3205` |
|
|
1
|
+
# Switch SDK — Robinhood Chain
|
|
2
|
+
|
|
3
|
+
Production integration reference for Switch swaps on Robinhood Chain mainnet.
|
|
4
|
+
|
|
5
|
+
| Setting | Value |
|
|
6
|
+
|---|---|
|
|
7
|
+
| API network | `robinhood` |
|
|
8
|
+
| Chain ID | `4663` |
|
|
9
|
+
| Native currency | ETH (18 decimals) |
|
|
10
|
+
| Public RPC | `https://rpc.mainnet.chain.robinhood.com` |
|
|
11
|
+
| Explorer | `https://robinhoodchain.blockscout.com` |
|
|
12
|
+
| Quote API | `https://quote.switch.win/swap/quote` |
|
|
13
|
+
| Tax API | `https://quote.switch.win/swap/checkTax` |
|
|
14
|
+
| Supported liquidity | Uniswap V2, V3, and hookless static-fee V4 |
|
|
15
|
+
| Limit orders | Not currently available |
|
|
16
|
+
|
|
17
|
+
## Contents
|
|
18
|
+
|
|
19
|
+
- [Installation](#installation)
|
|
20
|
+
- [Authentication](#authentication)
|
|
21
|
+
- [Network configuration](#network-configuration)
|
|
22
|
+
- [Contracts and native currency](#contracts-and-native-currency)
|
|
23
|
+
- [Uniswap V4 routing](#uniswap-v4-routing)
|
|
24
|
+
- [Swap integration flow](#swap-integration-flow)
|
|
25
|
+
- [Quickstart](#quickstart)
|
|
26
|
+
- [Tax-token checks](#tax-token-checks)
|
|
27
|
+
- [Selecting `feeOnOutput`](#selecting-feeonoutput)
|
|
28
|
+
- [Approving and executing](#approving-and-executing)
|
|
29
|
+
- [Swap API reference](#swap-api-reference)
|
|
30
|
+
- [Error handling](#error-handling)
|
|
31
|
+
- [Partner fee sharing](#partner-fee-sharing)
|
|
32
|
+
- [Tokens and routing](#tokens-and-routing)
|
|
33
|
+
- [Rate limits](#rate-limits)
|
|
34
|
+
- [Current limitations](#current-limitations)
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install @switch-win/sdk
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import {
|
|
44
|
+
ROBINHOOD_CHAIN,
|
|
45
|
+
ROBINHOOD_NATIVE_ETH,
|
|
46
|
+
ROBINHOOD_SWITCH_CONTRACTS,
|
|
47
|
+
ROBINHOOD_UNISWAP_CONTRACTS,
|
|
48
|
+
ROBINHOOD_TOKENS,
|
|
49
|
+
ROBINHOOD_FEE_TOKEN_PRIORITY,
|
|
50
|
+
ROBINHOOD_FRONTEND_DEFAULT_TOKENS,
|
|
51
|
+
ROBINHOOD_FRONTEND_TOKEN_LIST,
|
|
52
|
+
buildRobinhoodQuoteUrl,
|
|
53
|
+
type BestPathResponse,
|
|
54
|
+
} from "@switch-win/sdk";
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The same exports are available from the smaller network entrypoint:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import {
|
|
61
|
+
ROBINHOOD_CHAIN,
|
|
62
|
+
ROBINHOOD_TOKENS,
|
|
63
|
+
buildRobinhoodQuoteUrl,
|
|
64
|
+
} from "@switch-win/sdk/networks/robinhood";
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Authentication
|
|
68
|
+
|
|
69
|
+
Every request to `quote.switch.win` requires a Switch API key in the
|
|
70
|
+
`x-api-key` header:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
const headers = {
|
|
74
|
+
"x-api-key": process.env.SWITCH_API_KEY!,
|
|
75
|
+
};
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Do not expose a production API key in browser JavaScript. Browser applications
|
|
79
|
+
should call a same-origin server route that attaches the key before forwarding
|
|
80
|
+
the request to Switch.
|
|
81
|
+
|
|
82
|
+
## Network configuration
|
|
83
|
+
|
|
84
|
+
`ROBINHOOD_CHAIN` can be adapted directly for most wallet libraries:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
const robinhoodWalletChain = {
|
|
88
|
+
chainId: `0x${ROBINHOOD_CHAIN.id.toString(16)}`,
|
|
89
|
+
chainName: ROBINHOOD_CHAIN.name,
|
|
90
|
+
nativeCurrency: ROBINHOOD_CHAIN.nativeCurrency,
|
|
91
|
+
rpcUrls: [...ROBINHOOD_CHAIN.rpcUrls],
|
|
92
|
+
blockExplorerUrls: [ROBINHOOD_CHAIN.blockExplorerUrl],
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
await window.ethereum.request({
|
|
96
|
+
method: "wallet_addEthereumChain",
|
|
97
|
+
params: [robinhoodWalletChain],
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Contracts and native currency
|
|
102
|
+
|
|
103
|
+
### Switch deployment
|
|
104
|
+
|
|
105
|
+
| Contract | Address |
|
|
106
|
+
|---|---|
|
|
107
|
+
| SwitchRouter | `0x8730C3e2cF2c8CDa8E6166837A1Ed26f46aa9E59` |
|
|
108
|
+
| Uniswap V2 adapter | `0x7a14d7A8509a66209D4332843b983b29bF5604A4` |
|
|
109
|
+
| Uniswap V3 adapter | `0xbcA08f296d9Ba0dc19Aa0E05D355365cE29A3205` |
|
|
110
110
|
| Uniswap V4 adapter | `0x754dDCD05aFbAd1cc7Bc42B9268EB586F579E7F6` |
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
`
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
111
|
+
| SwitchLimitOrder | `0x752c50DDd3B426cAE3D7A995F313Ac74ac6B0230` |
|
|
112
|
+
| Native ETH flow | `0x029FfC6aF9112eA078f1D6f4a98826DDB2136cf6` |
|
|
113
|
+
| Switch Limit Order adapter (index 3) | `0x412F625072c10e58C619D1e0b3C95cd3d5689871` |
|
|
114
|
+
|
|
115
|
+
The V4 adapter was created in
|
|
116
|
+
[deployment transaction `0x60d5...34a7`](https://robinhoodchain.blockscout.com/tx/0x60d56466a8162a643a15ecde98322ec05ea23d44d03fbd817df4ddbaef4834a7)
|
|
117
|
+
and added to the router in
|
|
118
|
+
[activation transaction `0x405b...1098`](https://robinhoodchain.blockscout.com/tx/0x405b49619ebfe4d1a73eb2d4601d8d1e63ae3d6fff0cd811a96c17e146971098).
|
|
119
|
+
|
|
120
|
+
The router constant is the ERC-20 approval target. Always submit the swap to
|
|
121
|
+
`quote.tx.to`; do not replace the API-provided transaction target with a
|
|
122
|
+
hardcoded address.
|
|
123
|
+
|
|
124
|
+
### Native ETH and WETH
|
|
125
|
+
|
|
126
|
+
Use `ROBINHOOD_NATIVE_ETH` when the user is selling or buying native ETH:
|
|
127
|
+
|
|
128
|
+
```text
|
|
129
|
+
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Use `ROBINHOOD_TOKENS.WETH.address` for the wrapped ERC-20:
|
|
133
|
+
|
|
134
|
+
```text
|
|
135
|
+
0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73
|
|
136
|
+
```
|
|
137
|
+
|
|
135
138
|
Native ETH does not require approval. WETH and every other ERC-20 input token
|
|
136
139
|
must be approved for `ROBINHOOD_SWITCH_CONTRACTS.router`.
|
|
137
140
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
Switch's Robinhood V4 integration is designed for canonical Uniswap V4, whose
|
|
141
|
-
pools share one `PoolManager`. A V4 pool is identified by its complete
|
|
142
|
-
`PoolKey`:
|
|
143
|
-
|
|
144
|
-
```ts
|
|
145
|
-
type PoolKey = {
|
|
146
|
-
currency0: string;
|
|
147
|
-
currency1: string;
|
|
148
|
-
fee: number;
|
|
149
|
-
tickSpacing: number;
|
|
150
|
-
hooks: string;
|
|
151
|
-
};
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
Do not treat V4 pools as V3 pools with another fee-tier list. The `fee`,
|
|
155
|
-
`tickSpacing`, and `hooks` values are all part of pool identity, and Robinhood
|
|
156
|
-
V4 discovery must preserve the full key. The backend selects the key and
|
|
157
|
-
embeds adapter-specific route data in the quote; clients should submit the
|
|
158
|
-
returned transaction unchanged rather than reconstructing V4 calldata.
|
|
159
|
-
|
|
160
|
-
Phase one supports **hookless static-fee pools only** (`hooks` is the zero
|
|
161
|
-
address, hook data is empty, and the dynamic-fee flag is not set). Pools with
|
|
162
|
-
custom hooks or dynamic fees are not considered until their behavior and
|
|
163
|
-
required hook data have been explicitly reviewed and allowed. This restriction
|
|
164
|
-
does not reduce V2 or V3 routing coverage.
|
|
165
|
-
|
|
166
|
-
V4 can represent native ETH as the zero-address currency. Switch routes use
|
|
167
|
-
the canonical Robinhood WETH address, so the V4 adapter unwraps WETH when a
|
|
168
|
-
selected pool consumes native ETH and wraps native ETH when that pool produces
|
|
169
|
-
it. API callers should continue using `ROBINHOOD_NATIVE_ETH` for a native user
|
|
170
|
-
input/output and `ROBINHOOD_TOKENS.WETH.address` for the ERC-20.
|
|
171
|
-
|
|
172
|
-
The Robinhood Uniswap V4 adapter is deployed at
|
|
173
|
-
`0x754dDCD05aFbAd1cc7Bc42B9268EB586F579E7F6`, whitelisted in the production
|
|
174
|
-
SwitchRouter at adapter index `2`, and exported as
|
|
175
|
-
`ROBINHOOD_SWITCH_CONTRACTS.uniswapV4Adapter`. Continue treating
|
|
176
|
-
`GET /swap/adapters?network=robinhood` as the source of truth for the adapters
|
|
177
|
-
currently available from the quote backend.
|
|
178
|
-
|
|
179
|
-
The canonical Robinhood V4 infrastructure is available through
|
|
180
|
-
`ROBINHOOD_UNISWAP_CONTRACTS`:
|
|
181
|
-
|
|
182
|
-
| Contract | Address |
|
|
183
|
-
|---|---|
|
|
184
|
-
| PoolManager | `0x8366a39cc670b4001a1121b8f6a443a643e40951` |
|
|
185
|
-
| PositionDescriptor | `0x9639443158e8c5efa35bd45287bf2effd3d8dc06` |
|
|
186
|
-
| PositionManager | `0x58daec3116aae6d93017baaea7749052e8a04fa7` |
|
|
187
|
-
| Quoter | `0x8dc178efb8111bb0973dd9d722ebeff267c98f94` |
|
|
188
|
-
| StateView | `0xf3334192d15450cdd385c8b70e03f9a6bd9e673b` |
|
|
189
|
-
| Universal Router | `0x8876789976decbfcbbbe364623c63652db8c0904` |
|
|
190
|
-
| Permit2 | `0x000000000022D473030F116dDEE9F6B43aC78BA3` |
|
|
191
|
-
|
|
192
|
-
Tax-token safety is unchanged: if either side is detected as a transfer-tax
|
|
193
|
-
token, the complete route is restricted to Uniswap V2 adapter index `0`.
|
|
194
|
-
Uniswap V3 and V4 are both excluded from that quote.
|
|
195
|
-
|
|
196
|
-
## Swap integration flow
|
|
197
|
-
|
|
198
|
-
Use the same sequence as a PulseChain integration:
|
|
199
|
-
|
|
200
|
-
1. Check both tokens with `/swap/checkTax`.
|
|
201
|
-
2. Select `feeOnOutput` from the tax results and preferred fee-token order.
|
|
202
|
-
3. Request `/swap/quote` with `network=robinhood`, the selected fee mode, and
|
|
203
|
-
`sender` when executable calldata is required.
|
|
204
|
-
4. Approve the API-provided router target for ERC-20 input tokens.
|
|
205
|
-
5. Submit `quote.tx` for fee-on-input or `quote.txFeeOnOutput` for
|
|
206
|
-
fee-on-output.
|
|
207
|
-
6. Show `expectedOutputAmount`, `minAmountOut`, route allocation, and detected
|
|
208
|
-
taxes to the user.
|
|
209
|
-
|
|
210
|
-
Any swap involving a tax token is routed entirely through Uniswap V2. This
|
|
211
|
-
also applies when both input and output are tax tokens.
|
|
212
|
-
|
|
213
|
-
## Quickstart
|
|
214
|
-
|
|
215
|
-
`amount` is always a raw integer amount in the input token's smallest unit.
|
|
216
|
-
The following requests a quote for `0.001 ETH -> USDG`:
|
|
217
|
-
|
|
218
|
-
```ts
|
|
219
|
-
// This simple pair uses fee-on-input. See "Selecting feeOnOutput" below for
|
|
220
|
-
// the recommended dynamic selection when community or tax tokens are involved.
|
|
221
|
-
const feeOnOutput = false;
|
|
222
|
-
|
|
223
|
-
const url = buildRobinhoodQuoteUrl({
|
|
224
|
-
from: ROBINHOOD_NATIVE_ETH,
|
|
225
|
-
to: ROBINHOOD_TOKENS.USDG.address,
|
|
226
|
-
amount: 1_000_000_000_000_000n,
|
|
227
|
-
sender: walletAddress,
|
|
228
|
-
slippage: 50, // 0.50%, expressed in basis points
|
|
229
|
-
feeOnOutput,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
const response = await fetch(url, {
|
|
233
|
-
headers: { "x-api-key": process.env.SWITCH_API_KEY! },
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
if (!response.ok) {
|
|
237
|
-
throw new Error(`Switch quote failed: ${response.status}`);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const quote = (await response.json()) as BestPathResponse;
|
|
241
|
-
const transaction = feeOnOutput ? quote.txFeeOnOutput : quote.tx;
|
|
242
|
-
|
|
243
|
-
if (!transaction) {
|
|
244
|
-
throw new Error("Quote did not include the selected transaction variant");
|
|
245
|
-
}
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
Equivalent curl request:
|
|
249
|
-
|
|
250
|
-
```bash
|
|
251
|
-
curl -H "x-api-key: YOUR_KEY" \
|
|
252
|
-
"https://quote.switch.win/swap/quote?network=robinhood&from=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&to=0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168&amount=1000000000000000&sender=0xYOUR_WALLET&slippage=50"
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
Omit `sender` for a display-only quote. Fetch again with the sender immediately
|
|
256
|
-
before execution to receive current transaction calldata.
|
|
257
|
-
|
|
258
|
-
## Tax-token checks
|
|
259
|
-
|
|
260
|
-
Robinhood tokens can apply pair-specific transfer taxes. Check both input and
|
|
261
|
-
output tokens before requesting or executing a swap:
|
|
262
|
-
|
|
263
|
-
```ts
|
|
264
|
-
async function checkTax(token: string) {
|
|
265
|
-
const query = new URLSearchParams({ network: "robinhood", token });
|
|
266
|
-
const response = await fetch(
|
|
267
|
-
`https://quote.switch.win/swap/checkTax?${query}`,
|
|
268
|
-
{ headers: { "x-api-key": process.env.SWITCH_API_KEY! } },
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
if (!response.ok) throw new Error(`Tax check failed: ${response.status}`);
|
|
272
|
-
return response.json();
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const [inputTax, outputTax] = await Promise.all([
|
|
276
|
-
checkTax(tokenIn),
|
|
277
|
-
checkTax(tokenOut),
|
|
278
|
-
]);
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
The quote response also includes `fromTokenTax`, `toTokenTax`,
|
|
282
|
-
`expectedOutputAmount`, and effective-slippage fields. Display these values to
|
|
283
|
-
the user rather than estimating taxes locally.
|
|
141
|
+
### Limit orders
|
|
284
142
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
`feeOnOutput` determines which side of the swap pays the Switch partner or
|
|
288
|
-
protocol fee:
|
|
289
|
-
|
|
290
|
-
| Value | Fee token | Transaction field |
|
|
291
|
-
|---|---|---|
|
|
292
|
-
| `false` | Input token | `quote.tx` |
|
|
293
|
-
| `true` | Output token | `quote.txFeeOnOutput` |
|
|
294
|
-
|
|
295
|
-
Choose the mode before requesting the executable quote and pass it to
|
|
296
|
-
`buildRobinhoodQuoteUrl`. This keeps `expectedOutputAmount`, routing, and the
|
|
297
|
-
transaction calldata aligned with the mode that will actually be submitted.
|
|
298
|
-
|
|
299
|
-
For Robinhood Chain, the recommended selection order is:
|
|
300
|
-
|
|
301
|
-
1. If both sides are tax tokens, use fee-on-input (`false`) to avoid the extra
|
|
302
|
-
output-token transfers required by fee-on-output.
|
|
303
|
-
2. If only the output token has buy tax, use fee-on-input (`false`) to avoid
|
|
304
|
-
routing the taxed output through additional transfers.
|
|
305
|
-
3. If only the input token has sell tax, use fee-on-output (`true`) so the fee
|
|
306
|
-
is collected in the non-tax output token.
|
|
307
|
-
4. Otherwise, prefer collecting tokens in this order: WETH (with native ETH
|
|
308
|
-
treated equivalently), USDG, WALLET, SEEDCOIN, then CASHCAT.
|
|
309
|
-
5. If neither token is preferred, default to fee-on-input (`false`).
|
|
310
|
-
|
|
311
|
-
The no-tax priority list is:
|
|
312
|
-
|
|
313
|
-
| Priority | Token | Address |
|
|
314
|
-
|---:|---|---|
|
|
315
|
-
| 1 | WETH / native ETH | `0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73` / native sentinel |
|
|
316
|
-
| 2 | USDG | `0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168` |
|
|
317
|
-
| 3 | WALLET | `0x0339f5459FC690aC85F1782e15782A151b4A9E1b` |
|
|
318
|
-
| 4 | SEEDCOIN | `0xD8d1C08A8bA4fc64BAC744f74290B89ADcb6Bf25` |
|
|
319
|
-
| 5 | CASHCAT | `0x020bfC650A365f8BB26819deAAbF3E21291018b4` |
|
|
320
|
-
|
|
321
|
-
The ordered ERC-20 addresses are exported as
|
|
322
|
-
`ROBINHOOD_FEE_TOKEN_PRIORITY`. When neither side is taxed, the selector takes
|
|
323
|
-
the fee from whichever side contains the higher-priority token. If neither
|
|
324
|
-
side is listed, it defaults to fee-on-input.
|
|
143
|
+
Robinhood ERC-20 limit orders use the same EIP-712 `LimitOrder` structure as
|
|
144
|
+
PulseChain, with these network-specific domain values:
|
|
325
145
|
|
|
326
146
|
```ts
|
|
327
147
|
import {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
type BestPathResponse,
|
|
148
|
+
ROBINHOOD_LIMIT_ORDER_EIP712_DOMAIN,
|
|
149
|
+
ROBINHOOD_SWITCH_CONTRACTS,
|
|
331
150
|
} from "@switch-win/sdk";
|
|
332
151
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const quoteUrl = buildRobinhoodQuoteUrl({
|
|
341
|
-
from: tokenIn,
|
|
342
|
-
to: tokenOut,
|
|
343
|
-
amount: amountIn,
|
|
344
|
-
sender: walletAddress,
|
|
345
|
-
slippage: 50,
|
|
346
|
-
feeOnOutput,
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
const quoteResponse = await fetch(quoteUrl, {
|
|
350
|
-
headers: { "x-api-key": process.env.SWITCH_API_KEY! },
|
|
351
|
-
});
|
|
352
|
-
if (!quoteResponse.ok) {
|
|
353
|
-
throw new Error(`Switch quote failed: ${quoteResponse.status}`);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const quote = (await quoteResponse.json()) as BestPathResponse;
|
|
357
|
-
const transaction = feeOnOutput ? quote.txFeeOnOutput : quote.tx;
|
|
358
|
-
if (!transaction) {
|
|
359
|
-
throw new Error("Quote did not include the selected transaction variant");
|
|
360
|
-
}
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
Do not request one fee mode and submit the other transaction variant. Taxed
|
|
364
|
-
output tokens are especially important: `feeOnOutput=true` makes the router
|
|
365
|
-
receive and redistribute the output, which can trigger additional transfer-tax
|
|
366
|
-
events.
|
|
367
|
-
|
|
368
|
-
## Approving and executing
|
|
369
|
-
|
|
370
|
-
For ERC-20 input:
|
|
371
|
-
|
|
372
|
-
```ts
|
|
373
|
-
const token = new ethers.Contract(
|
|
374
|
-
tokenIn,
|
|
375
|
-
["function approve(address spender, uint256 amount) returns (bool)"],
|
|
376
|
-
signer,
|
|
152
|
+
// { name: "SwitchLimitOrder", version: "2", chainId: 4663,
|
|
153
|
+
// verifyingContract: "0x752c...0230" }
|
|
154
|
+
await signer.signTypedData(
|
|
155
|
+
ROBINHOOD_LIMIT_ORDER_EIP712_DOMAIN,
|
|
156
|
+
LIMIT_ORDER_EIP712_TYPES,
|
|
157
|
+
order,
|
|
377
158
|
);
|
|
378
|
-
|
|
379
|
-
await (
|
|
380
|
-
await token.approve(ROBINHOOD_SWITCH_CONTRACTS.router, amountIn)
|
|
381
|
-
).wait();
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
Then submit the transaction returned by the API:
|
|
385
|
-
|
|
386
|
-
```ts
|
|
387
|
-
await signer.sendTransaction({
|
|
388
|
-
to: transaction.to,
|
|
389
|
-
data: transaction.data,
|
|
390
|
-
value: transaction.value,
|
|
391
|
-
});
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
For native ETH input, skip approval and send the API-provided `value`.
|
|
395
|
-
|
|
396
|
-
## Swap API reference
|
|
397
|
-
|
|
398
|
-
All amounts are raw integer strings in the token's smallest unit. All token and
|
|
399
|
-
wallet values are EVM addresses.
|
|
400
|
-
|
|
401
|
-
### List adapters
|
|
402
|
-
|
|
403
|
-
```http
|
|
404
|
-
GET https://quote.switch.win/swap/adapters?network=robinhood
|
|
405
|
-
x-api-key: YOUR_KEY
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
Robinhood currently returns:
|
|
409
|
-
|
|
410
|
-
| Index | Adapter |
|
|
411
|
-
|---:|---|
|
|
412
|
-
| `0` | Uniswap V2 |
|
|
413
|
-
| `1` | Uniswap V3 |
|
|
414
|
-
| `2` | Uniswap V4 |
|
|
415
|
-
|
|
416
|
-
Treat the endpoint response, not this document, as the source of truth for
|
|
417
|
-
which adapters are currently selectable.
|
|
418
|
-
|
|
419
|
-
Do not permanently hard-code the available adapter list in an integration.
|
|
420
|
-
Fetch it when presenting routing-source controls. If a quote involves a tax
|
|
421
|
-
token, the backend overrides routing to tax-safe adapter `0`; an explicit
|
|
422
|
-
filter that excludes adapter `0` is rejected.
|
|
423
|
-
|
|
424
|
-
### Check token tax
|
|
425
|
-
|
|
426
|
-
```http
|
|
427
|
-
GET https://quote.switch.win/swap/checkTax?network=robinhood&token=0xTOKEN
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
Example response:
|
|
431
|
-
|
|
432
|
-
```json
|
|
433
|
-
{
|
|
434
|
-
"token": "0x...",
|
|
435
|
-
"isTaxToken": true,
|
|
436
|
-
"buyTaxBps": 500,
|
|
437
|
-
"sellTaxBps": 300
|
|
438
|
-
}
|
|
439
159
|
```
|
|
440
160
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
The
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
`expectedOutputAmount`
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
161
|
+
Submit signed orders to `POST /limit-orders?network=robinhood`. For
|
|
162
|
+
`feeOnOutput=false`, approve `ROBINHOOD_SWITCH_CONTRACTS.limitOrder`; for
|
|
163
|
+
`feeOnOutput=true`, approve `ROBINHOOD_SWITCH_CONTRACTS.router`.
|
|
164
|
+
|
|
165
|
+
Native ETH input orders are created on-chain through
|
|
166
|
+
`ROBINHOOD_SWITCH_CONTRACTS.nativeEthFlow` and are indexed from its events; do
|
|
167
|
+
not POST them as signed EOA orders. Native ETH output is represented by WETH in
|
|
168
|
+
the order with `unwrapOutput=true`.
|
|
169
|
+
|
|
170
|
+
## Uniswap V4 routing
|
|
171
|
+
|
|
172
|
+
Switch's Robinhood V4 integration is designed for canonical Uniswap V4, whose
|
|
173
|
+
pools share one `PoolManager`. A V4 pool is identified by its complete
|
|
174
|
+
`PoolKey`:
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
type PoolKey = {
|
|
178
|
+
currency0: string;
|
|
179
|
+
currency1: string;
|
|
180
|
+
fee: number;
|
|
181
|
+
tickSpacing: number;
|
|
182
|
+
hooks: string;
|
|
183
|
+
};
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Do not treat V4 pools as V3 pools with another fee-tier list. The `fee`,
|
|
187
|
+
`tickSpacing`, and `hooks` values are all part of pool identity, and Robinhood
|
|
188
|
+
V4 discovery must preserve the full key. The backend selects the key and
|
|
189
|
+
embeds adapter-specific route data in the quote; clients should submit the
|
|
190
|
+
returned transaction unchanged rather than reconstructing V4 calldata.
|
|
191
|
+
|
|
192
|
+
Phase one supports **hookless static-fee pools only** (`hooks` is the zero
|
|
193
|
+
address, hook data is empty, and the dynamic-fee flag is not set). Pools with
|
|
194
|
+
custom hooks or dynamic fees are not considered until their behavior and
|
|
195
|
+
required hook data have been explicitly reviewed and allowed. This restriction
|
|
196
|
+
does not reduce V2 or V3 routing coverage.
|
|
197
|
+
|
|
198
|
+
V4 can represent native ETH as the zero-address currency. Switch routes use
|
|
199
|
+
the canonical Robinhood WETH address, so the V4 adapter unwraps WETH when a
|
|
200
|
+
selected pool consumes native ETH and wraps native ETH when that pool produces
|
|
201
|
+
it. API callers should continue using `ROBINHOOD_NATIVE_ETH` for a native user
|
|
202
|
+
input/output and `ROBINHOOD_TOKENS.WETH.address` for the ERC-20.
|
|
203
|
+
|
|
204
|
+
The Robinhood Uniswap V4 adapter is deployed at
|
|
205
|
+
`0x754dDCD05aFbAd1cc7Bc42B9268EB586F579E7F6`, whitelisted in the production
|
|
206
|
+
SwitchRouter at adapter index `2`, and exported as
|
|
207
|
+
`ROBINHOOD_SWITCH_CONTRACTS.uniswapV4Adapter`. Continue treating
|
|
208
|
+
`GET /swap/adapters?network=robinhood` as the source of truth for the adapters
|
|
209
|
+
currently available from the quote backend.
|
|
210
|
+
|
|
211
|
+
The canonical Robinhood V4 infrastructure is available through
|
|
212
|
+
`ROBINHOOD_UNISWAP_CONTRACTS`:
|
|
213
|
+
|
|
214
|
+
| Contract | Address |
|
|
215
|
+
|---|---|
|
|
216
|
+
| PoolManager | `0x8366a39cc670b4001a1121b8f6a443a643e40951` |
|
|
217
|
+
| PositionDescriptor | `0x9639443158e8c5efa35bd45287bf2effd3d8dc06` |
|
|
218
|
+
| PositionManager | `0x58daec3116aae6d93017baaea7749052e8a04fa7` |
|
|
219
|
+
| Quoter | `0x8dc178efb8111bb0973dd9d722ebeff267c98f94` |
|
|
220
|
+
| StateView | `0xf3334192d15450cdd385c8b70e03f9a6bd9e673b` |
|
|
221
|
+
| Universal Router | `0x8876789976decbfcbbbe364623c63652db8c0904` |
|
|
222
|
+
| Permit2 | `0x000000000022D473030F116dDEE9F6B43aC78BA3` |
|
|
223
|
+
|
|
224
|
+
Tax-token safety is unchanged: if either side is detected as a transfer-tax
|
|
225
|
+
token, the complete route is restricted to Uniswap V2 adapter index `0`.
|
|
226
|
+
Uniswap V3 and V4 are both excluded from that quote.
|
|
227
|
+
|
|
228
|
+
## Swap integration flow
|
|
229
|
+
|
|
230
|
+
Use the same sequence as a PulseChain integration:
|
|
231
|
+
|
|
232
|
+
1. Check both tokens with `/swap/checkTax`.
|
|
233
|
+
2. Select `feeOnOutput` from the tax results and preferred fee-token order.
|
|
234
|
+
3. Request `/swap/quote` with `network=robinhood`, the selected fee mode, and
|
|
235
|
+
`sender` when executable calldata is required.
|
|
236
|
+
4. Approve the API-provided router target for ERC-20 input tokens.
|
|
237
|
+
5. Submit `quote.tx` for fee-on-input or `quote.txFeeOnOutput` for
|
|
238
|
+
fee-on-output.
|
|
239
|
+
6. Show `expectedOutputAmount`, `minAmountOut`, route allocation, and detected
|
|
240
|
+
taxes to the user.
|
|
241
|
+
|
|
242
|
+
Any swap involving a tax token is routed entirely through Uniswap V2. This
|
|
243
|
+
also applies when both input and output are tax tokens.
|
|
244
|
+
|
|
245
|
+
## Quickstart
|
|
246
|
+
|
|
247
|
+
`amount` is always a raw integer amount in the input token's smallest unit.
|
|
248
|
+
The following requests a quote for `0.001 ETH -> USDG`:
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
// This simple pair uses fee-on-input. See "Selecting feeOnOutput" below for
|
|
252
|
+
// the recommended dynamic selection when community or tax tokens are involved.
|
|
253
|
+
const feeOnOutput = false;
|
|
254
|
+
|
|
255
|
+
const url = buildRobinhoodQuoteUrl({
|
|
256
|
+
from: ROBINHOOD_NATIVE_ETH,
|
|
257
|
+
to: ROBINHOOD_TOKENS.USDG.address,
|
|
258
|
+
amount: 1_000_000_000_000_000n,
|
|
259
|
+
sender: walletAddress,
|
|
260
|
+
slippage: 50, // 0.50%, expressed in basis points
|
|
261
|
+
feeOnOutput,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
const response = await fetch(url, {
|
|
265
|
+
headers: { "x-api-key": process.env.SWITCH_API_KEY! },
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
if (!response.ok) {
|
|
269
|
+
throw new Error(`Switch quote failed: ${response.status}`);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const quote = (await response.json()) as BestPathResponse;
|
|
273
|
+
const transaction = feeOnOutput ? quote.txFeeOnOutput : quote.tx;
|
|
274
|
+
|
|
275
|
+
if (!transaction) {
|
|
276
|
+
throw new Error("Quote did not include the selected transaction variant");
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Equivalent curl request:
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
curl -H "x-api-key: YOUR_KEY" \
|
|
284
|
+
"https://quote.switch.win/swap/quote?network=robinhood&from=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&to=0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168&amount=1000000000000000&sender=0xYOUR_WALLET&slippage=50"
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Omit `sender` for a display-only quote. Fetch again with the sender immediately
|
|
288
|
+
before execution to receive current transaction calldata.
|
|
289
|
+
|
|
290
|
+
## Tax-token checks
|
|
291
|
+
|
|
292
|
+
Robinhood tokens can apply pair-specific transfer taxes. Check both input and
|
|
293
|
+
output tokens before requesting or executing a swap:
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
async function checkTax(token: string) {
|
|
297
|
+
const query = new URLSearchParams({ network: "robinhood", token });
|
|
298
|
+
const response = await fetch(
|
|
299
|
+
`https://quote.switch.win/swap/checkTax?${query}`,
|
|
300
|
+
{ headers: { "x-api-key": process.env.SWITCH_API_KEY! } },
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
if (!response.ok) throw new Error(`Tax check failed: ${response.status}`);
|
|
304
|
+
return response.json();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const [inputTax, outputTax] = await Promise.all([
|
|
308
|
+
checkTax(tokenIn),
|
|
309
|
+
checkTax(tokenOut),
|
|
310
|
+
]);
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
The quote response also includes `fromTokenTax`, `toTokenTax`,
|
|
314
|
+
`expectedOutputAmount`, and effective-slippage fields. Display these values to
|
|
315
|
+
the user rather than estimating taxes locally.
|
|
316
|
+
|
|
317
|
+
## Selecting `feeOnOutput`
|
|
318
|
+
|
|
319
|
+
`feeOnOutput` determines which side of the swap pays the Switch partner or
|
|
320
|
+
protocol fee:
|
|
321
|
+
|
|
322
|
+
| Value | Fee token | Transaction field |
|
|
323
|
+
|---|---|---|
|
|
324
|
+
| `false` | Input token | `quote.tx` |
|
|
325
|
+
| `true` | Output token | `quote.txFeeOnOutput` |
|
|
326
|
+
|
|
327
|
+
Choose the mode before requesting the executable quote and pass it to
|
|
328
|
+
`buildRobinhoodQuoteUrl`. This keeps `expectedOutputAmount`, routing, and the
|
|
329
|
+
transaction calldata aligned with the mode that will actually be submitted.
|
|
330
|
+
|
|
331
|
+
For Robinhood Chain, the recommended selection order is:
|
|
332
|
+
|
|
333
|
+
1. If both sides are tax tokens, use fee-on-input (`false`) to avoid the extra
|
|
334
|
+
output-token transfers required by fee-on-output.
|
|
335
|
+
2. If only the output token has buy tax, use fee-on-input (`false`) to avoid
|
|
336
|
+
routing the taxed output through additional transfers.
|
|
337
|
+
3. If only the input token has sell tax, use fee-on-output (`true`) so the fee
|
|
338
|
+
is collected in the non-tax output token.
|
|
339
|
+
4. Otherwise, prefer collecting tokens in this order: WETH (with native ETH
|
|
340
|
+
treated equivalently), USDG, WALLET, SEEDCOIN, then CASHCAT.
|
|
341
|
+
5. If neither token is preferred, default to fee-on-input (`false`).
|
|
342
|
+
|
|
343
|
+
The no-tax priority list is:
|
|
344
|
+
|
|
345
|
+
| Priority | Token | Address |
|
|
346
|
+
|---:|---|---|
|
|
347
|
+
| 1 | WETH / native ETH | `0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73` / native sentinel |
|
|
348
|
+
| 2 | USDG | `0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168` |
|
|
349
|
+
| 3 | WALLET | `0x0339f5459FC690aC85F1782e15782A151b4A9E1b` |
|
|
350
|
+
| 4 | SEEDCOIN | `0x58f693A30F124E59b125F7c7b837b0F6bbAF5a45` |
|
|
351
|
+
| 5 | CASHCAT | `0x020bfC650A365f8BB26819deAAbF3E21291018b4` |
|
|
352
|
+
|
|
353
|
+
The ordered ERC-20 addresses are exported as
|
|
354
|
+
`ROBINHOOD_FEE_TOKEN_PRIORITY`. When neither side is taxed, the selector takes
|
|
355
|
+
the fee from whichever side contains the higher-priority token. If neither
|
|
356
|
+
side is listed, it defaults to fee-on-input.
|
|
357
|
+
|
|
358
|
+
```ts
|
|
359
|
+
import {
|
|
360
|
+
buildRobinhoodQuoteUrl,
|
|
361
|
+
selectRobinhoodFeeOnOutput,
|
|
362
|
+
type BestPathResponse,
|
|
363
|
+
} from "@switch-win/sdk";
|
|
364
|
+
|
|
365
|
+
const feeOnOutput = selectRobinhoodFeeOnOutput(
|
|
366
|
+
tokenIn,
|
|
367
|
+
tokenOut,
|
|
368
|
+
inputTax,
|
|
369
|
+
outputTax,
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
const quoteUrl = buildRobinhoodQuoteUrl({
|
|
373
|
+
from: tokenIn,
|
|
374
|
+
to: tokenOut,
|
|
375
|
+
amount: amountIn,
|
|
376
|
+
sender: walletAddress,
|
|
377
|
+
slippage: 50,
|
|
378
|
+
feeOnOutput,
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
const quoteResponse = await fetch(quoteUrl, {
|
|
382
|
+
headers: { "x-api-key": process.env.SWITCH_API_KEY! },
|
|
383
|
+
});
|
|
384
|
+
if (!quoteResponse.ok) {
|
|
385
|
+
throw new Error(`Switch quote failed: ${quoteResponse.status}`);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const quote = (await quoteResponse.json()) as BestPathResponse;
|
|
389
|
+
const transaction = feeOnOutput ? quote.txFeeOnOutput : quote.tx;
|
|
390
|
+
if (!transaction) {
|
|
391
|
+
throw new Error("Quote did not include the selected transaction variant");
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Do not request one fee mode and submit the other transaction variant. Taxed
|
|
396
|
+
output tokens are especially important: `feeOnOutput=true` makes the router
|
|
397
|
+
receive and redistribute the output, which can trigger additional transfer-tax
|
|
398
|
+
events.
|
|
399
|
+
|
|
400
|
+
## Approving and executing
|
|
401
|
+
|
|
402
|
+
For ERC-20 input:
|
|
403
|
+
|
|
404
|
+
```ts
|
|
405
|
+
const token = new ethers.Contract(
|
|
406
|
+
tokenIn,
|
|
407
|
+
["function approve(address spender, uint256 amount) returns (bool)"],
|
|
408
|
+
signer,
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
await (
|
|
412
|
+
await token.approve(ROBINHOOD_SWITCH_CONTRACTS.router, amountIn)
|
|
413
|
+
).wait();
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
Then submit the transaction returned by the API:
|
|
417
|
+
|
|
418
|
+
```ts
|
|
419
|
+
await signer.sendTransaction({
|
|
420
|
+
to: transaction.to,
|
|
421
|
+
data: transaction.data,
|
|
422
|
+
value: transaction.value,
|
|
423
|
+
});
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
For native ETH input, skip approval and send the API-provided `value`.
|
|
427
|
+
|
|
428
|
+
## Swap API reference
|
|
429
|
+
|
|
430
|
+
All amounts are raw integer strings in the token's smallest unit. All token and
|
|
431
|
+
wallet values are EVM addresses.
|
|
432
|
+
|
|
433
|
+
### List adapters
|
|
434
|
+
|
|
435
|
+
```http
|
|
436
|
+
GET https://quote.switch.win/swap/adapters?network=robinhood
|
|
437
|
+
x-api-key: YOUR_KEY
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
Robinhood currently returns:
|
|
441
|
+
|
|
442
|
+
| Index | Adapter |
|
|
443
|
+
|---:|---|
|
|
444
|
+
| `0` | Uniswap V2 |
|
|
445
|
+
| `1` | Uniswap V3 |
|
|
446
|
+
| `2` | Uniswap V4 |
|
|
447
|
+
|
|
448
|
+
Treat the endpoint response, not this document, as the source of truth for
|
|
449
|
+
which adapters are currently selectable.
|
|
450
|
+
|
|
451
|
+
Do not permanently hard-code the available adapter list in an integration.
|
|
452
|
+
Fetch it when presenting routing-source controls. If a quote involves a tax
|
|
453
|
+
token, the backend overrides routing to tax-safe adapter `0`; an explicit
|
|
454
|
+
filter that excludes adapter `0` is rejected.
|
|
455
|
+
|
|
456
|
+
### Check token tax
|
|
457
|
+
|
|
458
|
+
```http
|
|
459
|
+
GET https://quote.switch.win/swap/checkTax?network=robinhood&token=0xTOKEN
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
Example response:
|
|
463
|
+
|
|
464
|
+
```json
|
|
465
|
+
{
|
|
466
|
+
"token": "0x...",
|
|
467
|
+
"isTaxToken": true,
|
|
468
|
+
"buyTaxBps": 500,
|
|
469
|
+
"sellTaxBps": 300
|
|
470
|
+
}
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
`500` basis points is `5%`. Use the input token's `sellTaxBps` and the output
|
|
474
|
+
token's `buyTaxBps`. When both tokens are taxed, use fee-on-input.
|
|
475
|
+
|
|
476
|
+
### Get swap quote
|
|
477
|
+
|
|
478
|
+
```http
|
|
479
|
+
GET https://quote.switch.win/swap/quote
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
| Query parameter | Required | Description |
|
|
483
|
+
|---|:---:|---|
|
|
484
|
+
| `network` | Yes | Must be `robinhood`. |
|
|
485
|
+
| `from` | Yes | Input token address or `ROBINHOOD_NATIVE_ETH`. |
|
|
486
|
+
| `to` | Yes | Output token address or `ROBINHOOD_NATIVE_ETH`. |
|
|
487
|
+
| `amount` | Yes | Raw input amount. |
|
|
488
|
+
| `sender` | No | Required when transaction calldata is needed. |
|
|
489
|
+
| `receiver` | No | Output recipient; defaults to `sender`. |
|
|
490
|
+
| `slippage` | No | Basis points; default `50` (`0.5%`). |
|
|
491
|
+
| `fee` | No | Partner/protocol fee in basis points. |
|
|
492
|
+
| `partnerAddress` | No | Fee-sharing recipient. |
|
|
493
|
+
| `feeOnOutput` | No | `true` takes the fee from output; `false` takes it from input. |
|
|
494
|
+
| `adapters` | No | Comma-separated indices returned by `/swap/adapters`, such as `0,1,2`. |
|
|
495
|
+
| `gasPrice` | No | Quote gas price in wei. |
|
|
496
|
+
|
|
497
|
+
Omitting `sender` produces a display-only quote. Request a fresh executable
|
|
498
|
+
quote with `sender` immediately before execution.
|
|
499
|
+
|
|
500
|
+
### Quote response
|
|
501
|
+
|
|
502
|
+
Important response fields:
|
|
503
|
+
|
|
504
|
+
| Field | Description |
|
|
505
|
+
|---|---|
|
|
506
|
+
| `fromToken`, `toToken` | Normalized pair addresses. |
|
|
507
|
+
| `totalAmountIn` | Gross input amount. |
|
|
508
|
+
| `totalAmountOut` | Raw pool output before taxes and Switch fees. |
|
|
509
|
+
| `expectedOutputAmount` | Expected user receipt after tax and fee, before slippage. |
|
|
510
|
+
| `minAmountOut` | Minimum output encoded into calldata. |
|
|
511
|
+
| `paths` | Human-readable route descriptions. |
|
|
512
|
+
| `routeAllocation` | Structured split, hop, adapter, and pool-specific route allocation. V4 PoolKey data is encoded in the executable transaction and must not be reconstructed client-side. |
|
|
513
|
+
| `fromTokenTax`, `toTokenTax` | Detected tax metadata. |
|
|
514
|
+
| `effectiveSlippageBps` | Slippage plus applicable tax buffers. |
|
|
515
|
+
| `tx` | Fee-on-input transaction; present when `sender` is supplied. |
|
|
516
|
+
| `txFeeOnOutput` | Fee-on-output transaction; present when `sender` is supplied. |
|
|
517
|
+
|
|
518
|
+
Treat the response as authoritative. Do not recalculate output taxes, route
|
|
519
|
+
splits, minimum output, or calldata in the client.
|
|
520
|
+
|
|
521
|
+
## Error handling
|
|
522
|
+
|
|
523
|
+
The API can return an `{ "error": "..." }` object for validation or routing
|
|
524
|
+
failures. Check both the HTTP status and the response body before using quote
|
|
525
|
+
fields.
|
|
526
|
+
|
|
527
|
+
Common Robinhood errors include:
|
|
528
|
+
|
|
529
|
+
- Missing or unsupported `network`.
|
|
530
|
+
- Invalid token, sender, receiver, or partner address.
|
|
531
|
+
- Invalid raw amount, slippage, fee, gas price, or adapter filter.
|
|
532
|
+
- A tax-token quote explicitly excluded the Uniswap V2 adapter.
|
|
533
|
+
- No viable route across the currently active adapters, or insufficient liquidity.
|
|
534
|
+
- RPC timeout or public-RPC rate limiting.
|
|
535
|
+
- Missing executable transaction because `sender` was omitted.
|
|
536
|
+
|
|
537
|
+
On-chain reverts can still occur if allowance, wallet balance, slippage,
|
|
538
|
+
liquidity, token tax, or chain state changes after quoting. Fetch a fresh quote
|
|
539
|
+
before retrying rather than resubmitting stale calldata.
|
|
540
|
+
|
|
541
|
+
## Partner fee sharing
|
|
542
|
+
|
|
543
|
+
Pass `fee` in basis points and `partnerAddress` in the quote request. The chosen
|
|
544
|
+
fee mode determines the fee token:
|
|
545
|
+
|
|
546
|
+
- `feeOnOutput=false`: collect from the input token and submit `quote.tx`.
|
|
547
|
+
- `feeOnOutput=true`: collect from the output token and submit
|
|
548
|
+
`quote.txFeeOnOutput`.
|
|
549
|
+
|
|
550
|
+
Always pass `feeOnOutput` while quoting so routing and
|
|
551
|
+
`expectedOutputAmount` match the transaction variant you will execute. Partner
|
|
552
|
+
fee eligibility and revenue share are controlled by the API-key agreement; do
|
|
553
|
+
not assume that supplying an address alone enables sharing.
|
|
554
|
+
|
|
555
|
+
## Tokens and routing
|
|
556
|
+
|
|
557
|
+
### Curated frontend token list
|
|
558
|
+
|
|
559
|
+
The token dropdown contains the following ERC-20 tokens. Native ETH is merged
|
|
560
|
+
into the UI separately from this list.
|
|
561
|
+
|
|
562
|
+
| Symbol | Name | Address | Decimals |
|
|
563
|
+
|---|---|---|---:|
|
|
564
|
+
| WETH | Wrapped Ether | `0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73` | 18 |
|
|
565
|
+
| USDG | Global Dollar | `0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168` | 6 |
|
|
566
|
+
| VIRTUAL | Virtuals Protocol | `0xc6911796042b15d7Fa4F6CDe69e245DdCd3d9c31` | 18 |
|
|
567
|
+
| CASHCAT | Cash Cat | `0x020bfC650A365f8BB26819deAAbF3E21291018b4` | 18 |
|
|
568
|
+
| WALLET | Robinhood Wallet | `0x0339f5459FC690aC85F1782e15782A151b4A9E1b` | 18 |
|
|
569
|
+
| SEEDCOIN | Seedcoin | `0x58f693A30F124E59b125F7c7b837b0F6bbAF5a45` | 18 |
|
|
570
|
+
| JUGGERNAUT | The Juggernaut | `0xD7321801CAae694090694Ff55A9323139F043B88` | 18 |
|
|
571
|
+
| HOODRAT | Hoodrat | `0x8e62F281f282686fCa6dCB39288069a93fC23F1c` | 18 |
|
|
572
|
+
| DIH | Dog In Hood | `0x17bb0C898254406b1Ea2e8E99B0C263e26c9E4a4` | 18 |
|
|
573
|
+
| KITSU | KITSU | `0x8d4dFaaA4198b6486E0293Fec914C2B6a821D4DC` | 18 |
|
|
574
|
+
| WEN | Wen Lambo | `0xA80eb66b3E0CF66ccB46f8b8C9e7ff5803eEb820` | 18 |
|
|
575
|
+
| REPE | Robinhood Pepe | `0x5266eeafF092D6136AB63D18B975A60a0Cc0C8f7` | 18 |
|
|
576
|
+
| TENDIES | TENDIES | `0x45242320DBB855EeA8Fd36804C6487E10E97FCF9` | 18 |
|
|
577
|
+
| GME | GameStop | `0x7e86381A763F0Ecca2bDF27C54eAC403ddD48123` | 18 |
|
|
578
|
+
| 4663 | 4663 | `0xd4052415613B34Af236024B895574c467f65b6dD` | 18 |
|
|
579
|
+
| MARIAN | Lady Marian | `0x01637b14B7378B99dE75A64d50656d98488D9a4d` | 18 |
|
|
580
|
+
|
|
581
|
+
The ordered list is exported as `ROBINHOOD_FRONTEND_TOKEN_LIST`.
|
|
582
|
+
|
|
583
|
+
These community tokens are frontend conveniences, not an endorsement or a
|
|
584
|
+
guarantee of liquidity, price stability, tax behavior, or contract safety.
|
|
585
|
+
Always identify tokens by address and obtain a fresh quote and tax check.
|
|
586
|
+
|
|
587
|
+
### Routing configuration
|
|
588
|
+
|
|
589
|
+
Switch currently evaluates:
|
|
590
|
+
|
|
591
|
+
- Uniswap V2 adapter index `0`.
|
|
592
|
+
- Uniswap V3 adapter index `1`.
|
|
593
|
+
- V3 fee tiers `100`, `500`, `3000`, and `10000`.
|
|
594
|
+
- Trusted routing hubs WETH, USDG, VIRTUAL, and CASHCAT.
|
|
595
|
+
|
|
596
|
+
The prepared V4 integration reserves adapter index `2`. Once activated, it
|
|
597
|
+
discovers hookless static-fee V4 pools by complete `PoolKey` rather than
|
|
598
|
+
applying the V3 fee-tier list. Native-ETH V4 currencies are normalized through the WETH/native
|
|
599
|
+
alias described above. Until `/swap/adapters` returns index `2`, V4 is not part
|
|
600
|
+
of live production quotes.
|
|
601
|
+
|
|
602
|
+
If either side is detected as a transfer-tax token, the backend restricts the
|
|
603
|
+
entire route (including every split and intermediate hop) to Uniswap V2. V3 is
|
|
604
|
+
not considered for that quote, and V4 will remain excluded after activation.
|
|
605
|
+
|
|
606
|
+
The API may split a quote across routes and adapters. Integrators should render
|
|
607
|
+
the returned `paths` or `routeAllocation` instead of assuming a single path.
|
|
608
|
+
|
|
609
|
+
## Rate limits
|
|
610
|
+
|
|
611
|
+
Rate limits are assigned to the API key. A `429` response means the integration
|
|
612
|
+
must back off. Use request coalescing and short-lived UI caching, avoid polling
|
|
613
|
+
unchanged quotes, and debounce amount input before requesting a new route.
|
|
614
|
+
|
|
615
|
+
For server integrations, contact Switch to coordinate the expected request
|
|
616
|
+
rate and IP allowlisting. Do not distribute one production key across
|
|
617
|
+
untrusted clients.
|
|
618
|
+
|
|
619
|
+
## Current limitations
|
|
620
|
+
|
|
621
|
+
- Robinhood limit orders are not deployed.
|
|
622
|
+
- Rialto DEX is not integrated.
|
|
623
|
+
- The production router supports Uniswap V2, V3, and supported hookless
|
|
624
|
+
static-fee V4 liquidity. V4 participates in quotes whenever adapter index
|
|
625
|
+
`2` is advertised by `/swap/adapters`.
|
|
626
|
+
- The first V4 phase intentionally excludes hooked and dynamic-fee pools.
|
|
627
|
+
- A V4 allocation currently selects its best single PoolKey; intra-V4
|
|
628
|
+
multi-pool splitting is not yet enabled. V4 can still split against V2/V3.
|
|
629
|
+
- Contract and token addresses must be treated as chain-specific.
|
|
630
|
+
|
|
631
|
+
See the main [SDK reference](README.md) for authentication, partner fees,
|
|
632
|
+
response types, error handling, and the complete swap API schema.
|
|
633
|
+
|
|
634
|
+
## Support
|
|
635
|
+
|
|
636
|
+
- Documentation: <https://docs.switch.win>
|
|
637
|
+
- Website: <https://switch.win>
|
|
638
|
+
- Quote API: <https://quote.switch.win>
|
|
639
|
+
|
|
640
|
+
## License
|
|
641
|
+
|
|
642
|
+
See [LICENSE](LICENSE).
|