smart-order-router-tbd 0.1.2 → 0.1.3

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.
Files changed (71) hide show
  1. package/README.md +328 -328
  2. package/build/main/providers/caching-token-provider.js +1 -1
  3. package/build/main/providers/on-chain-quote-provider.js +15 -3
  4. package/build/main/providers/pv2/subgraph-provider.js +20 -20
  5. package/build/main/providers/pv3/subgraph-provider.js +21 -21
  6. package/build/main/providers/pv4cl/subgraph-provider.js +23 -23
  7. package/build/main/providers/subgraph-provider.js +70 -70
  8. package/build/main/providers/v2/subgraph-provider.js +114 -114
  9. package/build/main/providers/v4/subgraph-provider.js +20 -20
  10. package/build/main/routers/alpha-router/alpha-router.js +70 -13
  11. package/build/main/routers/alpha-router/quoters/pv3-quoter.js +5 -1
  12. package/build/main/routers/alpha-router/quoters/pv4cl-quoter.js +8 -12
  13. package/build/main/routers/alpha-router/quoters/v3-quoter.js +5 -1
  14. package/build/main/routers/alpha-router/quoters/v4-quoter.js +5 -1
  15. package/build/main/tsconfig.tsbuildinfo +1 -1
  16. package/build/main/util/index.d.ts +1 -0
  17. package/build/main/util/index.js +2 -1
  18. package/build/main/util/pv4cl-constants.d.ts +2 -2
  19. package/build/main/util/pv4cl-constants.js +7 -3
  20. package/build/main/util/route-caps.d.ts +30 -0
  21. package/build/main/util/route-caps.js +57 -0
  22. package/build/main/util/route-caps.js.bak +57 -0
  23. package/build/module/providers/caching-token-provider.js +1 -1
  24. package/build/module/providers/on-chain-quote-provider.js +15 -3
  25. package/build/module/providers/pv2/subgraph-provider.js +20 -20
  26. package/build/module/providers/pv3/subgraph-provider.js +21 -21
  27. package/build/module/providers/pv4cl/subgraph-provider.js +23 -23
  28. package/build/module/providers/subgraph-provider.js +70 -70
  29. package/build/module/providers/v2/subgraph-provider.js +114 -114
  30. package/build/module/providers/v4/subgraph-provider.js +20 -20
  31. package/build/module/routers/alpha-router/alpha-router.js +70 -13
  32. package/build/module/routers/alpha-router/quoters/pv3-quoter.js +6 -2
  33. package/build/module/routers/alpha-router/quoters/pv4cl-quoter.js +8 -12
  34. package/build/module/routers/alpha-router/quoters/v3-quoter.js +6 -2
  35. package/build/module/routers/alpha-router/quoters/v4-quoter.js +6 -2
  36. package/build/module/tsconfig.module.tsbuildinfo +1 -1
  37. package/build/module/util/index.d.ts +1 -0
  38. package/build/module/util/index.js +2 -1
  39. package/build/module/util/pv4cl-constants.d.ts +2 -2
  40. package/build/module/util/pv4cl-constants.js +7 -3
  41. package/build/module/util/route-caps.d.ts +30 -0
  42. package/build/module/util/route-caps.js +50 -0
  43. package/package.json +126 -126
  44. package/build/main/providers/pancakeswap/index.d.ts +0 -2
  45. package/build/main/providers/pancakeswap/index.js +0 -19
  46. package/build/main/providers/pancakeswap/pool-provider.d.ts +0 -8
  47. package/build/main/providers/pancakeswap/pool-provider.js +0 -43
  48. package/build/main/providers/pancakeswap/type-bridge.d.ts +0 -8
  49. package/build/main/providers/pancakeswap/type-bridge.js +0 -56
  50. package/build/main/routers/alpha-router/entities/pancakeswap-route.d.ts +0 -55
  51. package/build/main/routers/alpha-router/entities/pancakeswap-route.js +0 -76
  52. package/build/main/routers/alpha-router/gas-models/pancakeswap/pancakeswap-gas-model.d.ts +0 -16
  53. package/build/main/routers/alpha-router/gas-models/pancakeswap/pancakeswap-gas-model.js +0 -48
  54. package/build/main/routers/alpha-router/quoters/pancakeswap-quoter.d.ts +0 -24
  55. package/build/main/routers/alpha-router/quoters/pancakeswap-quoter.js +0 -205
  56. package/build/main/util/pancakeswap-protocols.d.ts +0 -11
  57. package/build/main/util/pancakeswap-protocols.js +0 -22
  58. package/build/module/providers/pancakeswap/index.d.ts +0 -2
  59. package/build/module/providers/pancakeswap/index.js +0 -3
  60. package/build/module/providers/pancakeswap/pool-provider.d.ts +0 -8
  61. package/build/module/providers/pancakeswap/pool-provider.js +0 -37
  62. package/build/module/providers/pancakeswap/type-bridge.d.ts +0 -8
  63. package/build/module/providers/pancakeswap/type-bridge.js +0 -50
  64. package/build/module/routers/alpha-router/entities/pancakeswap-route.d.ts +0 -55
  65. package/build/module/routers/alpha-router/entities/pancakeswap-route.js +0 -46
  66. package/build/module/routers/alpha-router/gas-models/pancakeswap/pancakeswap-gas-model.d.ts +0 -16
  67. package/build/module/routers/alpha-router/gas-models/pancakeswap/pancakeswap-gas-model.js +0 -40
  68. package/build/module/routers/alpha-router/quoters/pancakeswap-quoter.d.ts +0 -24
  69. package/build/module/routers/alpha-router/quoters/pancakeswap-quoter.js +0 -200
  70. package/build/module/util/pancakeswap-protocols.d.ts +0 -11
  71. package/build/module/util/pancakeswap-protocols.js +0 -18
package/README.md CHANGED
@@ -1,328 +1,328 @@
1
- # Uniswap Smart Order Router
2
-
3
- This repository contains routing logic for the Uniswap V3 protocol.
4
-
5
- It searches for the most efficient way to swap token A for token B, considering splitting swaps across multiple routes and gas costs.
6
-
7
- ## Documentation
8
-
9
- - **[Add a new chain for PV2 (PancakeSwap V2)](docs/PV2-ADD-NEW-CHAIN.md)** — Step-by-step guide to enable PV2 routing on additional chains.
10
- - **[Add a new chain for PV3 (PancakeSwap V3) and use the subgraph](docs/PV3-ADD-NEW-CHAIN-AND-SUBGRAPH.md)** — Enable PV3 on new chains and configure real PancakeSwap V3 subgraph endpoints.
11
- - **[Use PSS (PancakeSwap StableSwap) and add a new chain](docs/PSS-USAGE-AND-ADD-NEW-CHAIN.md)** — How to use PSS routing and add new chains/pools (no subgraph; static pool list).
12
- - **[Use PV4CL (PancakeSwap Infinity CL) and add chain, subgraph, hook](docs/PV4CL-USAGE-AND-ADD-NEW-CHAIN-SUBGRAPH-HOOK.md)** — How to use PV4CL routing, add a new chain, configure the subgraph, and add/configure hooks.
13
- - **[Use Uniswap V3 subgraph with AlphaRouter](docs/V3-SUBGRAPH.md)** — How to pass a V3 GraphQL subgraph provider so the router uses it for pool discovery.
14
-
15
- ## Testing
16
-
17
- ### Unit Tests
18
-
19
- First make sure you have run `npm install` and `npm run build`.
20
-
21
- ```
22
- npm run test
23
- ```
24
-
25
- ### Integration Tests
26
-
27
- Make sure the `.env` file is configured to connect to mainnet and other chains. See the [CLI](#cli) section below for more details.
28
-
29
- ```
30
- npm run integ-test
31
- ```
32
-
33
- ### Tenderly Simulations
34
-
35
- Quotes can be simulated on Tenderly
36
-
37
- Ensure you set the following environment variables:
38
-
39
- ```
40
- process.env.TENDERLY_BASE_URL!,
41
- process.env.TENDERLY_USER!,
42
- process.env.TENDERLY_PROJECT!,
43
- process.env.TENDERLY_ACCESS_KEY!,
44
- ```
45
-
46
- ### CLI
47
-
48
- The package can be run as a CLI for testing purposes.
49
-
50
- First create a `.env` file in the root of the project and configure:
51
-
52
- ```
53
- JSON_RPC_PROVIDER = '<JSON_RPC_PROVIDER>'
54
- ```
55
-
56
- To run on chains other than mainnet set up a connection by specifying the environment variable
57
-
58
- ```
59
- JSON_RPC_PROVIDER_GORLI = '<JSON_RPC_PROVIDER>'
60
- JSON_RPC_PROVIDER_OPTIMISM = '<JSON_RPC_PROVIDER>'
61
- JSON_RPC_PROVIDER_OPTIMISM_GOERLI = '<JSON_RPC_PROVIDER>'
62
- JSON_RPC_PROVIDER_ARBITRUM_ONE = '<JSON_RPC_PROVIDER>'
63
- JSON_RPC_PROVIDER_ARBITRUM_GOERLI = '<JSON_RPC_PROVIDER>'
64
- JSON_RPC_PROVIDER_POLYGON = '<JSON_RPC_PROVIDER>'
65
- JSON_RPC_PROVIDER_POLYGON_MUMBAI = '<JSON_RPC_PROVIDER>'
66
- JSON_RPC_PROVIDER_CELO = '<JSON_RPC_PROVIDER>'
67
- JSON_RPC_PROVIDER_CELO_ALFAJORES = '<JSON_RPC_PROVIDER>'
68
- JSON_RPC_PROVIDER_BNB = '<JSON_RPC_PROVIDER>'
69
- JSON_RPC_PROVIDER_AVALANCHE = '<JSON_RPC_PROVIDER>'
70
- JSON_RPC_PROVIDER_BASE = '<JSON_RPC_PROVIDER>'
71
- JSON_RPC_PROVIDER_XLAYER = '<JSON_RPC_XLAYER>'
72
- ```
73
-
74
- Then from the root directory you can execute the CLI.
75
-
76
- ## Examples
77
-
78
- Some examples to use for manual CLI testing.
79
-
80
- ### Mainnet
81
-
82
- ```
83
- ./bin/cli quote --tokenIn 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 --tokenOut 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984 --amount 1000 --exactIn --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --protocols v2,v3
84
-
85
- Best Route:
86
- 100.00% = USDC -- 0.3% --> UNI
87
- Raw Quote Out:
88
- 35.72
89
- Gas Adjusted Quote Out:
90
- 34.03
91
-
92
- Gas Used Quote Token: 1.691772
93
- Gas Used USD: 47.592951
94
- Calldata: 0x414bf389000000000000...
95
- Value: 0x00
96
-
97
- blockNumber: "13088815"
98
- estimatedGasUsed: "113000"
99
- gasPriceWei: "130000000000"
100
-
101
-
102
- ./bin/cli quote-to-ratio --token0 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 --token1 0xdac17f958d2ee523a2206206994597c13d831ec7 --feeAmount 3000 --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --token0Balance 1000 --token1Balance 2000 --tickLower -120 --tickUpper 120
103
-
104
- Best Route:
105
- 100.00% = USDT -- 0.05% --> USDC
106
- Raw Quote Exact In:
107
- 392.68
108
- Gas Adjusted Quote In}:
109
- 346.13
110
-
111
- Gas Used Quote Token: 46.550010
112
- Gas Used USD: 46.342899
113
- Calldata: 0x414bf389000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000ab5801a7d398351b8be11c439e05c5b3259aec9b000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000176a736c000000000000000000000000000000000000000000000000000000001764f8650000000000000000000000000000000000000000000000000000000000000000
114
- Value: 0x00
115
-
116
- blockNumber: "13239188"
117
- estimatedGasUsed: "113000"
118
- gasPriceWei: "116690684398"
119
-
120
- ./bin/cli quote --tokenIn 0x0391D2021f89DC339F60Fff84546EA23E337750f --tokenOut 0x4d224452801ACEd8B2F0aebE155379bb5D594381 --amount 10000 --exactIn --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --protocols v2,v3,mixed
121
- Best Route:
122
- [V2 + V3] 100.00% = BOND -- [0x6591c4BcD6D7A1eb4E537DA8B78676C1576Ba244] --> USDC -- 0.3% [0xB07Fe2F407F971125D4EB1977f8aCEe8846C7324] --> APE
123
- Raw Quote Exact In:
124
- 10437.85
125
- Gas Adjusted Quote In:
126
- 10433.83
127
-
128
- Gas Used Quote Token: 4.018625
129
- Gas Used USD: 29.669402
130
- Calldata: 0x5ae401dc0000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f300000000000000000000000000000000000000000000021e19e0c9bab240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000391d2021f89dc339f60fff84546ea23e337750f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104b858183f00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000080000000000000000000000000ab5801a7d398351b8be11c439e05c5b3259aec9b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002358df5b3b4459a3f5b000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000bb84d224452801aced8b2f0aebe155379bb5d59438100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
131
- Value: 0x00
132
-
133
- blockNumber: "15303839"
134
- estimatedGasUsed: "434000"
135
- gasPriceWei: "38218865879"
136
- Total ticks crossed: 7
137
- ```
138
-
139
- ## Rinkeby
140
-
141
- ```
142
- ./bin/cli quote --tokenIn 0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea --tokenOut 0x4DBCdF9B62e891a7cec5A2568C3F4FAF9E8Abe2b --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 4
143
- ```
144
-
145
- ## Sepolia
146
-
147
- ```
148
- ./bin/cli quote --tokenIn 0x7AF17A48a6336F7dc1beF9D485139f7B6f4FB5C8 --tokenOut 0x6f14C02Fc1F78322cFd7d707aB90f18baD3B54f5 --amount 10 --exactIn --minSplits 1 --router alpha --chainId 11155111
149
- ```
150
-
151
- ## Kovan
152
-
153
- ```
154
- ./bin/cli quote --tokenIn 0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa --tokenOut 0xd0a1e359811322d97991e03f863a0c30c2cf029c --amount 10 --exactIn --minSplits 1 --router alpha --chainId 42
155
- ```
156
-
157
- ## Ropsten
158
-
159
- ```
160
- ./bin/cli quote --tokenIn 0x07865c6e87b9f70255377e024ace6630c1eaa37f --tokenOut 0xc778417e063141139fce010982780140aa0cd5ab --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 3
161
- ```
162
-
163
- ## Optimism
164
-
165
- ```
166
- ./bin/cli quote --tokenIn 0x7F5c764cBc14f9669B88837ca1490cCa17c31607 --tokenOut 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1 --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 10
167
-
168
- ```
169
-
170
- ```
171
- ./bin/cli quote --tokenIn 0x7F5c764cBc14f9669B88837ca1490cCa17c31607 --tokenOut 0x4200000000000000000000000000000000000042 --amount 1 --exactIn --minSplits 1 --protocols v2 --router alpha --chainId 10
172
- ```
173
-
174
-
175
- ## Optimism-Goerli
176
-
177
- ```
178
- ./bin/cli quote --tokenIn 0x7E07E15D2a87A24492740D16f5bdF58c16db0c4E --tokenOut 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1 --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 420
179
- ```
180
-
181
- ## Optimistic-Kovan
182
-
183
- ```
184
- ./bin/cli quote --tokenIn 0x7F5c764cBc14f9669B88837ca1490cCa17c31607 --tokenOut 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1 --amount 200 --exactIn --minSplits 1 --router alpha --chainId 69
185
- ```
186
-
187
- ## Arbitrum
188
-
189
- ```
190
- ./bin/cli quote --tokenIn 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9 --tokenOut 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 --amount 20000 --exactIn --minSplits 1 --router alpha --chainId 42161 --debug
191
- ```
192
-
193
- ## Arbitrum-Rinkeby
194
-
195
- ```
196
- ./bin/cli quote --tokenIn 0x09b98f8b2395d076514037ff7d39a091a536206c --tokenOut 0xb47e6a5f8b33b3f17603c83a0535a9dcd7e32681 --amount 200 --exactIn --minSplits 1 --router alpha --chainId 421611
197
- ```
198
-
199
- ## Arbitrum-Goerli
200
-
201
- ```
202
- ./bin/cli quote --tokenIn 0xe39ab88f8a4777030a534146a9ca3b52bd5d43a3 --tokenOut 0x8FB1E3fC51F3b789dED7557E680551d93Ea9d892 --amount 200 --exactIn --minSplits 1 --router alpha --chainId 421613
203
- ```
204
-
205
- ## Polygon Mumbai
206
-
207
- ```
208
- ./bin/cli quote --tokenIn 0x001b3b4d0f3714ca98ba10f6042daebf0b1b7b6f --tokenOut 0x9c3c9283d3e44854697cd22d3faa240cfb032889 --amount 1 --exactIn --protocols v3 --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --minSplits 1 --router alpha --chainId 80001
209
- ```
210
-
211
- ## Polygon Mainnet
212
-
213
- ```
214
- ./bin/cli quote --tokenIn 0x2791bca1f2de4661ed88a30c99a7a9449aa84174 --tokenOut 0x7ceb23fd6bc0add59e62ac25578270cff1b9f619 --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 137
215
- ```
216
-
217
- ## Celo Mainnet
218
-
219
- ```
220
- ./bin/cli quote --tokenIn CELO --tokenOut 0x765DE816845861e75A25fCA122bb6898B8B1282a --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 42220
221
- ```
222
-
223
- ## BNB Mainnet
224
-
225
- ```
226
- ./bin/cli quote --tokenIn 0x55d398326f99059fF775485246999027B3197955 --tokenOut 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d --amount 1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 56
227
- ```
228
-
229
- ## AVAX Mainnet
230
-
231
- ```
232
- ./bin/cli quote --tokenIn 0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E --tokenOut 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7 --amount 1000 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 43114
233
- ```
234
-
235
- ## BASE Mainnet
236
-
237
- ```
238
- ./bin/cli quote --tokenIn 0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA --tokenOut 0x4200000000000000000000000000000000000006 --amount 10 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 8453
239
- ```
240
-
241
- ## ZKSYNC Mainnet
242
-
243
- ```
244
- ./bin/cli quote --tokenIn 0x5aea5775959fbc2557cc8789bc1bf90a239d9a91 --tokenOut 0x1d17cbcf0d6d143135ae902365d2e5e2a16538d4 --amount 10 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 324
245
- ```
246
-
247
- ## WorldChain Mainnet
248
-
249
- ```
250
- ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0x79A02482A880bCE3F13e09Da970dC34db4CD24d1 --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 480
251
- ```
252
-
253
- ## UNICHAIN Sepolia
254
-
255
- ```
256
- ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0x31d0220469e10c4E71834a79b1f276d740d3768F --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 1301
257
- ```
258
-
259
- ## Unichain Mainnet
260
-
261
- ```
262
- ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0x078D782b760474a361dDA0AF3839290b0EF57AD6 --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 130
263
- ```
264
-
265
- ## Monad Testnet
266
-
267
- ```
268
- ./bin/cli quote --tokenIn 0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701 --tokenOut 0xfBC2D240A5eD44231AcA3A9e9066bc4b33f01149 --amount 0.1 --exactIn --minSplits 1 --protocols v2 --router alpha --chainId 10143
269
- ```
270
-
271
- ## Monad Mainnet
272
- ```
273
- ./bin/cli quote --tokenIn 0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A --tokenOut 0x754704Bc059F8C67012fEd69BC8A327a5aafb603 --amount 0.1 --exactIn --minSplits 1 --protocols v2 --router alpha --chainId 143
274
- ```
275
-
276
- ## Base Sepolia
277
-
278
- ```
279
- ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0x036CbD53842c5426634e7929541eC2318f3dCF7e --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 84532
280
- ```
281
-
282
- ## Soneium
283
-
284
- ```
285
- ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0xbA9986D2381edf1DA03B0B9c1f8b00dc4AacC369 --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 1868
286
- ```
287
-
288
- ## XLayer
289
-
290
- ```
291
- ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut ETH --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 196
292
- ```
293
-
294
- ## Adding a new Chain
295
-
296
- The main components to complete are:
297
-
298
- - Deploy contracts on chain, add the pools to subgraph
299
- - Populate v3 providers in `src/providers/v3/subgraph-provider` and `src/providers/v3/static-subgraph-provider`
300
- - Populate chainId and addresses in `src/util/chains.ts` and `src/util/addresses.ts`
301
- - Populate token providers in `src/providers/caching-token-provider` and `src/providers/token-provider.ts`
302
- - Populate gas constants in `src/routers/alpha-router/gas-models/*`
303
- - Populate bases in `src/routers/legacy-router/bases.ts`
304
- - Populate `test/integ/routers/alpha-router/alpha-router.integration.test.ts` and `src/providers/v2/static-subgraph-provider.ts`
305
- - Populate `src/routers/alpha-router/*`
306
- - Add a log to `/CHANGELOG.md`
307
- - Run `npm run integ-test` successfully
308
-
309
- # Troubleshooting
310
-
311
- ## ProviderGasLimit errors
312
-
313
- The package sends many large multicall requests to nodes. You must ensure that your node provider's `eth_call` gas limit is high enough to successfully process the RPC calls.
314
-
315
- By default each `eth_call` will consume up to:
316
-
317
- - 132,000,000 gas on Optimism
318
- - 120,000,000 gas on Arbitrum
319
- - 50,000,000 gas on Celo
320
- - 150,000,000 gas on every other network (Mainnet, Goerli, etc.)
321
-
322
- These parameters should work on Infura and Alchemy by default.
323
-
324
- This total amount of gas each `eth_call` can consume is equal to the `multicallChunk` config value multiplied by the `gasLimitPerCall` config value. If you are using a node provider with a lower gas limit per `eth_call` you will need to override the default `V3QuoteProvider` with an instance that lowers the `multicallChunk` and `gasLimitPerCall` parameters such that the multiplication is below your node providers limit. Lowering these values will cause each multicall to consume less gas. See [here](https://github.com/Uniswap/smart-order-router/blob/98c58bdee9981fd9ffac9e7d7a97b18302d5f77a/src/routers/alpha-router/alpha-router.ts#L415-L416) for examples of how to set these values. Note some providers have different limits per chain.
325
-
326
- If you are running your own node, we recommend you configure start your node with a higher gas limit per call. For example, on Geth you can use the command line argument `--rpc.gascap 150000000` to raise the limit to 150m, which is enough to run the default configuration of this package.
327
-
328
- If you are using Hardhat mainnet forking, you should add `blockGasLimit: 150_000_000` to your Hardhat config to use the default package configuration.
1
+ # Uniswap Smart Order Router
2
+
3
+ This repository contains routing logic for the Uniswap V3 protocol.
4
+
5
+ It searches for the most efficient way to swap token A for token B, considering splitting swaps across multiple routes and gas costs.
6
+
7
+ ## Documentation
8
+
9
+ - **[Add a new chain for PV2 (PancakeSwap V2)](docs/PV2-ADD-NEW-CHAIN.md)** — Step-by-step guide to enable PV2 routing on additional chains.
10
+ - **[Add a new chain for PV3 (PancakeSwap V3) and use the subgraph](docs/PV3-ADD-NEW-CHAIN-AND-SUBGRAPH.md)** — Enable PV3 on new chains and configure real PancakeSwap V3 subgraph endpoints.
11
+ - **[Use PSS (PancakeSwap StableSwap) and add a new chain](docs/PSS-USAGE-AND-ADD-NEW-CHAIN.md)** — How to use PSS routing and add new chains/pools (no subgraph; static pool list).
12
+ - **[Use PV4CL (PancakeSwap Infinity CL) and add chain, subgraph, hook](docs/PV4CL-USAGE-AND-ADD-NEW-CHAIN-SUBGRAPH-HOOK.md)** — How to use PV4CL routing, add a new chain, configure the subgraph, and add/configure hooks.
13
+ - **[Use Uniswap V3 subgraph with AlphaRouter](docs/V3-SUBGRAPH.md)** — How to pass a V3 GraphQL subgraph provider so the router uses it for pool discovery.
14
+
15
+ ## Testing
16
+
17
+ ### Unit Tests
18
+
19
+ First make sure you have run `npm install` and `npm run build`.
20
+
21
+ ```
22
+ npm run test
23
+ ```
24
+
25
+ ### Integration Tests
26
+
27
+ Make sure the `.env` file is configured to connect to mainnet and other chains. See the [CLI](#cli) section below for more details.
28
+
29
+ ```
30
+ npm run integ-test
31
+ ```
32
+
33
+ ### Tenderly Simulations
34
+
35
+ Quotes can be simulated on Tenderly
36
+
37
+ Ensure you set the following environment variables:
38
+
39
+ ```
40
+ process.env.TENDERLY_BASE_URL!,
41
+ process.env.TENDERLY_USER!,
42
+ process.env.TENDERLY_PROJECT!,
43
+ process.env.TENDERLY_ACCESS_KEY!,
44
+ ```
45
+
46
+ ### CLI
47
+
48
+ The package can be run as a CLI for testing purposes.
49
+
50
+ First create a `.env` file in the root of the project and configure:
51
+
52
+ ```
53
+ JSON_RPC_PROVIDER = '<JSON_RPC_PROVIDER>'
54
+ ```
55
+
56
+ To run on chains other than mainnet set up a connection by specifying the environment variable
57
+
58
+ ```
59
+ JSON_RPC_PROVIDER_GORLI = '<JSON_RPC_PROVIDER>'
60
+ JSON_RPC_PROVIDER_OPTIMISM = '<JSON_RPC_PROVIDER>'
61
+ JSON_RPC_PROVIDER_OPTIMISM_GOERLI = '<JSON_RPC_PROVIDER>'
62
+ JSON_RPC_PROVIDER_ARBITRUM_ONE = '<JSON_RPC_PROVIDER>'
63
+ JSON_RPC_PROVIDER_ARBITRUM_GOERLI = '<JSON_RPC_PROVIDER>'
64
+ JSON_RPC_PROVIDER_POLYGON = '<JSON_RPC_PROVIDER>'
65
+ JSON_RPC_PROVIDER_POLYGON_MUMBAI = '<JSON_RPC_PROVIDER>'
66
+ JSON_RPC_PROVIDER_CELO = '<JSON_RPC_PROVIDER>'
67
+ JSON_RPC_PROVIDER_CELO_ALFAJORES = '<JSON_RPC_PROVIDER>'
68
+ JSON_RPC_PROVIDER_BNB = '<JSON_RPC_PROVIDER>'
69
+ JSON_RPC_PROVIDER_AVALANCHE = '<JSON_RPC_PROVIDER>'
70
+ JSON_RPC_PROVIDER_BASE = '<JSON_RPC_PROVIDER>'
71
+ JSON_RPC_PROVIDER_XLAYER = '<JSON_RPC_XLAYER>'
72
+ ```
73
+
74
+ Then from the root directory you can execute the CLI.
75
+
76
+ ## Examples
77
+
78
+ Some examples to use for manual CLI testing.
79
+
80
+ ### Mainnet
81
+
82
+ ```
83
+ ./bin/cli quote --tokenIn 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 --tokenOut 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984 --amount 1000 --exactIn --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --protocols v2,v3
84
+
85
+ Best Route:
86
+ 100.00% = USDC -- 0.3% --> UNI
87
+ Raw Quote Out:
88
+ 35.72
89
+ Gas Adjusted Quote Out:
90
+ 34.03
91
+
92
+ Gas Used Quote Token: 1.691772
93
+ Gas Used USD: 47.592951
94
+ Calldata: 0x414bf389000000000000...
95
+ Value: 0x00
96
+
97
+ blockNumber: "13088815"
98
+ estimatedGasUsed: "113000"
99
+ gasPriceWei: "130000000000"
100
+
101
+
102
+ ./bin/cli quote-to-ratio --token0 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 --token1 0xdac17f958d2ee523a2206206994597c13d831ec7 --feeAmount 3000 --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --token0Balance 1000 --token1Balance 2000 --tickLower -120 --tickUpper 120
103
+
104
+ Best Route:
105
+ 100.00% = USDT -- 0.05% --> USDC
106
+ Raw Quote Exact In:
107
+ 392.68
108
+ Gas Adjusted Quote In}:
109
+ 346.13
110
+
111
+ Gas Used Quote Token: 46.550010
112
+ Gas Used USD: 46.342899
113
+ Calldata: 0x414bf389000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000ab5801a7d398351b8be11c439e05c5b3259aec9b000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000176a736c000000000000000000000000000000000000000000000000000000001764f8650000000000000000000000000000000000000000000000000000000000000000
114
+ Value: 0x00
115
+
116
+ blockNumber: "13239188"
117
+ estimatedGasUsed: "113000"
118
+ gasPriceWei: "116690684398"
119
+
120
+ ./bin/cli quote --tokenIn 0x0391D2021f89DC339F60Fff84546EA23E337750f --tokenOut 0x4d224452801ACEd8B2F0aebE155379bb5D594381 --amount 10000 --exactIn --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --protocols v2,v3,mixed
121
+ Best Route:
122
+ [V2 + V3] 100.00% = BOND -- [0x6591c4BcD6D7A1eb4E537DA8B78676C1576Ba244] --> USDC -- 0.3% [0xB07Fe2F407F971125D4EB1977f8aCEe8846C7324] --> APE
123
+ Raw Quote Exact In:
124
+ 10437.85
125
+ Gas Adjusted Quote In:
126
+ 10433.83
127
+
128
+ Gas Used Quote Token: 4.018625
129
+ Gas Used USD: 29.669402
130
+ Calldata: 0x5ae401dc0000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f300000000000000000000000000000000000000000000021e19e0c9bab240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000391d2021f89dc339f60fff84546ea23e337750f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104b858183f00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000080000000000000000000000000ab5801a7d398351b8be11c439e05c5b3259aec9b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002358df5b3b4459a3f5b000000000000000000000000000000000000000000000000000000000000002ba0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000bb84d224452801aced8b2f0aebe155379bb5d59438100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
131
+ Value: 0x00
132
+
133
+ blockNumber: "15303839"
134
+ estimatedGasUsed: "434000"
135
+ gasPriceWei: "38218865879"
136
+ Total ticks crossed: 7
137
+ ```
138
+
139
+ ## Rinkeby
140
+
141
+ ```
142
+ ./bin/cli quote --tokenIn 0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea --tokenOut 0x4DBCdF9B62e891a7cec5A2568C3F4FAF9E8Abe2b --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 4
143
+ ```
144
+
145
+ ## Sepolia
146
+
147
+ ```
148
+ ./bin/cli quote --tokenIn 0x7AF17A48a6336F7dc1beF9D485139f7B6f4FB5C8 --tokenOut 0x6f14C02Fc1F78322cFd7d707aB90f18baD3B54f5 --amount 10 --exactIn --minSplits 1 --router alpha --chainId 11155111
149
+ ```
150
+
151
+ ## Kovan
152
+
153
+ ```
154
+ ./bin/cli quote --tokenIn 0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa --tokenOut 0xd0a1e359811322d97991e03f863a0c30c2cf029c --amount 10 --exactIn --minSplits 1 --router alpha --chainId 42
155
+ ```
156
+
157
+ ## Ropsten
158
+
159
+ ```
160
+ ./bin/cli quote --tokenIn 0x07865c6e87b9f70255377e024ace6630c1eaa37f --tokenOut 0xc778417e063141139fce010982780140aa0cd5ab --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 3
161
+ ```
162
+
163
+ ## Optimism
164
+
165
+ ```
166
+ ./bin/cli quote --tokenIn 0x7F5c764cBc14f9669B88837ca1490cCa17c31607 --tokenOut 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1 --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 10
167
+
168
+ ```
169
+
170
+ ```
171
+ ./bin/cli quote --tokenIn 0x7F5c764cBc14f9669B88837ca1490cCa17c31607 --tokenOut 0x4200000000000000000000000000000000000042 --amount 1 --exactIn --minSplits 1 --protocols v2 --router alpha --chainId 10
172
+ ```
173
+
174
+
175
+ ## Optimism-Goerli
176
+
177
+ ```
178
+ ./bin/cli quote --tokenIn 0x7E07E15D2a87A24492740D16f5bdF58c16db0c4E --tokenOut 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1 --amount 200000 --exactIn --minSplits 1 --router alpha --chainId 420
179
+ ```
180
+
181
+ ## Optimistic-Kovan
182
+
183
+ ```
184
+ ./bin/cli quote --tokenIn 0x7F5c764cBc14f9669B88837ca1490cCa17c31607 --tokenOut 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1 --amount 200 --exactIn --minSplits 1 --router alpha --chainId 69
185
+ ```
186
+
187
+ ## Arbitrum
188
+
189
+ ```
190
+ ./bin/cli quote --tokenIn 0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9 --tokenOut 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 --amount 20000 --exactIn --minSplits 1 --router alpha --chainId 42161 --debug
191
+ ```
192
+
193
+ ## Arbitrum-Rinkeby
194
+
195
+ ```
196
+ ./bin/cli quote --tokenIn 0x09b98f8b2395d076514037ff7d39a091a536206c --tokenOut 0xb47e6a5f8b33b3f17603c83a0535a9dcd7e32681 --amount 200 --exactIn --minSplits 1 --router alpha --chainId 421611
197
+ ```
198
+
199
+ ## Arbitrum-Goerli
200
+
201
+ ```
202
+ ./bin/cli quote --tokenIn 0xe39ab88f8a4777030a534146a9ca3b52bd5d43a3 --tokenOut 0x8FB1E3fC51F3b789dED7557E680551d93Ea9d892 --amount 200 --exactIn --minSplits 1 --router alpha --chainId 421613
203
+ ```
204
+
205
+ ## Polygon Mumbai
206
+
207
+ ```
208
+ ./bin/cli quote --tokenIn 0x001b3b4d0f3714ca98ba10f6042daebf0b1b7b6f --tokenOut 0x9c3c9283d3e44854697cd22d3faa240cfb032889 --amount 1 --exactIn --protocols v3 --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --minSplits 1 --router alpha --chainId 80001
209
+ ```
210
+
211
+ ## Polygon Mainnet
212
+
213
+ ```
214
+ ./bin/cli quote --tokenIn 0x2791bca1f2de4661ed88a30c99a7a9449aa84174 --tokenOut 0x7ceb23fd6bc0add59e62ac25578270cff1b9f619 --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 137
215
+ ```
216
+
217
+ ## Celo Mainnet
218
+
219
+ ```
220
+ ./bin/cli quote --tokenIn CELO --tokenOut 0x765DE816845861e75A25fCA122bb6898B8B1282a --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 42220
221
+ ```
222
+
223
+ ## BNB Mainnet
224
+
225
+ ```
226
+ ./bin/cli quote --tokenIn 0x55d398326f99059fF775485246999027B3197955 --tokenOut 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d --amount 1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 56
227
+ ```
228
+
229
+ ## AVAX Mainnet
230
+
231
+ ```
232
+ ./bin/cli quote --tokenIn 0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E --tokenOut 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7 --amount 1000 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 43114
233
+ ```
234
+
235
+ ## BASE Mainnet
236
+
237
+ ```
238
+ ./bin/cli quote --tokenIn 0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA --tokenOut 0x4200000000000000000000000000000000000006 --amount 10 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 8453
239
+ ```
240
+
241
+ ## ZKSYNC Mainnet
242
+
243
+ ```
244
+ ./bin/cli quote --tokenIn 0x5aea5775959fbc2557cc8789bc1bf90a239d9a91 --tokenOut 0x1d17cbcf0d6d143135ae902365d2e5e2a16538d4 --amount 10 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 324
245
+ ```
246
+
247
+ ## WorldChain Mainnet
248
+
249
+ ```
250
+ ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0x79A02482A880bCE3F13e09Da970dC34db4CD24d1 --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 480
251
+ ```
252
+
253
+ ## UNICHAIN Sepolia
254
+
255
+ ```
256
+ ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0x31d0220469e10c4E71834a79b1f276d740d3768F --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 1301
257
+ ```
258
+
259
+ ## Unichain Mainnet
260
+
261
+ ```
262
+ ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0x078D782b760474a361dDA0AF3839290b0EF57AD6 --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 130
263
+ ```
264
+
265
+ ## Monad Testnet
266
+
267
+ ```
268
+ ./bin/cli quote --tokenIn 0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701 --tokenOut 0xfBC2D240A5eD44231AcA3A9e9066bc4b33f01149 --amount 0.1 --exactIn --minSplits 1 --protocols v2 --router alpha --chainId 10143
269
+ ```
270
+
271
+ ## Monad Mainnet
272
+ ```
273
+ ./bin/cli quote --tokenIn 0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A --tokenOut 0x754704Bc059F8C67012fEd69BC8A327a5aafb603 --amount 0.1 --exactIn --minSplits 1 --protocols v2 --router alpha --chainId 143
274
+ ```
275
+
276
+ ## Base Sepolia
277
+
278
+ ```
279
+ ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0x036CbD53842c5426634e7929541eC2318f3dCF7e --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 84532
280
+ ```
281
+
282
+ ## Soneium
283
+
284
+ ```
285
+ ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut 0xbA9986D2381edf1DA03B0B9c1f8b00dc4AacC369 --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 1868
286
+ ```
287
+
288
+ ## XLayer
289
+
290
+ ```
291
+ ./bin/cli quote --tokenIn 0x4200000000000000000000000000000000000006 --tokenOut ETH --amount 0.1 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 196
292
+ ```
293
+
294
+ ## Adding a new Chain
295
+
296
+ The main components to complete are:
297
+
298
+ - Deploy contracts on chain, add the pools to subgraph
299
+ - Populate v3 providers in `src/providers/v3/subgraph-provider` and `src/providers/v3/static-subgraph-provider`
300
+ - Populate chainId and addresses in `src/util/chains.ts` and `src/util/addresses.ts`
301
+ - Populate token providers in `src/providers/caching-token-provider` and `src/providers/token-provider.ts`
302
+ - Populate gas constants in `src/routers/alpha-router/gas-models/*`
303
+ - Populate bases in `src/routers/legacy-router/bases.ts`
304
+ - Populate `test/integ/routers/alpha-router/alpha-router.integration.test.ts` and `src/providers/v2/static-subgraph-provider.ts`
305
+ - Populate `src/routers/alpha-router/*`
306
+ - Add a log to `/CHANGELOG.md`
307
+ - Run `npm run integ-test` successfully
308
+
309
+ # Troubleshooting
310
+
311
+ ## ProviderGasLimit errors
312
+
313
+ The package sends many large multicall requests to nodes. You must ensure that your node provider's `eth_call` gas limit is high enough to successfully process the RPC calls.
314
+
315
+ By default each `eth_call` will consume up to:
316
+
317
+ - 132,000,000 gas on Optimism
318
+ - 120,000,000 gas on Arbitrum
319
+ - 50,000,000 gas on Celo
320
+ - 150,000,000 gas on every other network (Mainnet, Goerli, etc.)
321
+
322
+ These parameters should work on Infura and Alchemy by default.
323
+
324
+ This total amount of gas each `eth_call` can consume is equal to the `multicallChunk` config value multiplied by the `gasLimitPerCall` config value. If you are using a node provider with a lower gas limit per `eth_call` you will need to override the default `V3QuoteProvider` with an instance that lowers the `multicallChunk` and `gasLimitPerCall` parameters such that the multiplication is below your node providers limit. Lowering these values will cause each multicall to consume less gas. See [here](https://github.com/Uniswap/smart-order-router/blob/98c58bdee9981fd9ffac9e7d7a97b18302d5f77a/src/routers/alpha-router/alpha-router.ts#L415-L416) for examples of how to set these values. Note some providers have different limits per chain.
325
+
326
+ If you are running your own node, we recommend you configure start your node with a higher gas limit per call. For example, on Geth you can use the command line argument `--rpc.gascap 150000000` to raise the limit to 150m, which is enough to run the default configuration of this package.
327
+
328
+ If you are using Hardhat mainnet forking, you should add `blockGasLimit: 150_000_000` to your Hardhat config to use the default package configuration.