@uniswap/universal-router-sdk 4.34.2 → 5.0.0

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 (133) hide show
  1. package/README.md +104 -96
  2. package/dist/{entities → cjs/src/entities}/Command.d.ts +12 -12
  3. package/dist/cjs/src/entities/Command.js +9 -0
  4. package/dist/cjs/src/entities/Command.js.map +1 -0
  5. package/dist/{entities → cjs/src/entities}/actions/across.d.ts +21 -21
  6. package/dist/cjs/src/entities/actions/across.js +7 -0
  7. package/dist/cjs/src/entities/actions/across.js.map +1 -0
  8. package/dist/{entities → cjs/src/entities}/actions/index.d.ts +3 -3
  9. package/dist/cjs/src/entities/actions/index.js +7 -0
  10. package/dist/cjs/src/entities/actions/index.js.map +1 -0
  11. package/dist/{entities → cjs/src/entities}/actions/uniswap.d.ts +38 -39
  12. package/dist/cjs/src/entities/actions/uniswap.js +532 -0
  13. package/dist/cjs/src/entities/actions/uniswap.js.map +1 -0
  14. package/dist/{entities → cjs/src/entities}/actions/unwrapWETH.d.ts +12 -12
  15. package/dist/cjs/src/entities/actions/unwrapWETH.js +33 -0
  16. package/dist/cjs/src/entities/actions/unwrapWETH.js.map +1 -0
  17. package/dist/{entities → cjs/src/entities}/index.d.ts +2 -2
  18. package/dist/cjs/src/entities/index.js +6 -0
  19. package/dist/cjs/src/entities/index.js.map +1 -0
  20. package/dist/{index.d.ts → cjs/src/index.d.ts} +12 -12
  21. package/dist/cjs/src/index.js +33 -0
  22. package/dist/cjs/src/index.js.map +1 -0
  23. package/dist/{swapRouter.d.ts → cjs/src/swapRouter.d.ts} +87 -87
  24. package/dist/cjs/src/swapRouter.js +276 -0
  25. package/dist/cjs/src/swapRouter.js.map +1 -0
  26. package/dist/{utils → cjs/src/utils}/commandParser.d.ts +34 -34
  27. package/dist/cjs/src/utils/commandParser.js +145 -0
  28. package/dist/cjs/src/utils/commandParser.js.map +1 -0
  29. package/dist/{utils → cjs/src/utils}/constants.d.ts +33 -33
  30. package/dist/cjs/src/utils/constants.js +541 -0
  31. package/dist/cjs/src/utils/constants.js.map +1 -0
  32. package/dist/{utils → cjs/src/utils}/eip712.d.ts +17 -17
  33. package/dist/cjs/src/utils/eip712.js +43 -0
  34. package/dist/cjs/src/utils/eip712.js.map +1 -0
  35. package/dist/{utils → cjs/src/utils}/getCurrencyAddress.d.ts +2 -2
  36. package/dist/cjs/src/utils/getCurrencyAddress.js +9 -0
  37. package/dist/cjs/src/utils/getCurrencyAddress.js.map +1 -0
  38. package/dist/{utils → cjs/src/utils}/inputTokens.d.ts +23 -23
  39. package/dist/cjs/src/utils/inputTokens.js +58 -0
  40. package/dist/cjs/src/utils/inputTokens.js.map +1 -0
  41. package/dist/{utils → cjs/src/utils}/numbers.d.ts +7 -6
  42. package/dist/cjs/src/utils/numbers.js +27 -0
  43. package/dist/cjs/src/utils/numbers.js.map +1 -0
  44. package/dist/{utils → cjs/src/utils}/pathCurrency.d.ts +3 -3
  45. package/dist/cjs/src/utils/pathCurrency.js +27 -0
  46. package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
  47. package/dist/{utils → cjs/src/utils}/routerCommands.d.ts +77 -72
  48. package/dist/cjs/src/utils/routerCommands.js +334 -0
  49. package/dist/cjs/src/utils/routerCommands.js.map +1 -0
  50. package/dist/{utils → cjs/src/utils}/routerTradeAdapter.d.ts +73 -73
  51. package/dist/cjs/src/utils/routerTradeAdapter.js +139 -0
  52. package/dist/cjs/src/utils/routerTradeAdapter.js.map +1 -0
  53. package/dist/esm/src/entities/Command.d.ts +12 -0
  54. package/dist/esm/src/entities/Command.js +6 -0
  55. package/dist/esm/src/entities/Command.js.map +1 -0
  56. package/dist/esm/src/entities/actions/across.d.ts +21 -0
  57. package/dist/esm/src/entities/actions/across.js +3 -0
  58. package/dist/esm/src/entities/actions/across.js.map +1 -0
  59. package/dist/esm/src/entities/actions/index.d.ts +3 -0
  60. package/dist/esm/src/entities/actions/index.js +4 -0
  61. package/dist/esm/src/entities/actions/index.js.map +1 -0
  62. package/dist/esm/src/entities/actions/uniswap.d.ts +38 -0
  63. package/dist/esm/src/entities/actions/uniswap.js +528 -0
  64. package/dist/esm/src/entities/actions/uniswap.js.map +1 -0
  65. package/dist/esm/src/entities/actions/unwrapWETH.d.ts +12 -0
  66. package/dist/esm/src/entities/actions/unwrapWETH.js +28 -0
  67. package/dist/esm/src/entities/actions/unwrapWETH.js.map +1 -0
  68. package/dist/esm/src/entities/index.d.ts +2 -0
  69. package/dist/esm/src/entities/index.js +3 -0
  70. package/dist/esm/src/entities/index.js.map +1 -0
  71. package/dist/esm/src/index.d.ts +12 -0
  72. package/dist/esm/src/index.js +9 -0
  73. package/dist/esm/src/index.js.map +1 -0
  74. package/dist/esm/src/swapRouter.d.ts +87 -0
  75. package/dist/esm/src/swapRouter.js +271 -0
  76. package/dist/esm/src/swapRouter.js.map +1 -0
  77. package/dist/esm/src/utils/commandParser.d.ts +34 -0
  78. package/dist/esm/src/utils/commandParser.js +137 -0
  79. package/dist/esm/src/utils/commandParser.js.map +1 -0
  80. package/dist/esm/src/utils/constants.d.ts +33 -0
  81. package/dist/esm/src/utils/constants.js +534 -0
  82. package/dist/esm/src/utils/constants.js.map +1 -0
  83. package/dist/esm/src/utils/eip712.d.ts +17 -0
  84. package/dist/esm/src/utils/eip712.js +38 -0
  85. package/dist/esm/src/utils/eip712.js.map +1 -0
  86. package/dist/esm/src/utils/getCurrencyAddress.d.ts +2 -0
  87. package/dist/esm/src/utils/getCurrencyAddress.js +5 -0
  88. package/dist/esm/src/utils/getCurrencyAddress.js.map +1 -0
  89. package/dist/esm/src/utils/inputTokens.d.ts +23 -0
  90. package/dist/esm/src/utils/inputTokens.js +51 -0
  91. package/dist/esm/src/utils/inputTokens.js.map +1 -0
  92. package/dist/esm/src/utils/numbers.d.ts +7 -0
  93. package/dist/esm/src/utils/numbers.js +19 -0
  94. package/dist/esm/src/utils/numbers.js.map +1 -0
  95. package/dist/esm/src/utils/pathCurrency.d.ts +3 -0
  96. package/dist/esm/src/utils/pathCurrency.js +23 -0
  97. package/dist/esm/src/utils/pathCurrency.js.map +1 -0
  98. package/dist/esm/src/utils/routerCommands.d.ts +77 -0
  99. package/dist/esm/src/utils/routerCommands.js +329 -0
  100. package/dist/esm/src/utils/routerCommands.js.map +1 -0
  101. package/dist/esm/src/utils/routerTradeAdapter.d.ts +73 -0
  102. package/dist/esm/src/utils/routerTradeAdapter.js +134 -0
  103. package/dist/esm/src/utils/routerTradeAdapter.js.map +1 -0
  104. package/dist/types/src/entities/Command.d.ts +12 -0
  105. package/dist/types/src/entities/actions/across.d.ts +21 -0
  106. package/dist/types/src/entities/actions/index.d.ts +3 -0
  107. package/dist/types/src/entities/actions/uniswap.d.ts +38 -0
  108. package/dist/types/src/entities/actions/unwrapWETH.d.ts +12 -0
  109. package/dist/types/src/entities/index.d.ts +2 -0
  110. package/dist/types/src/index.d.ts +12 -0
  111. package/dist/types/src/swapRouter.d.ts +87 -0
  112. package/dist/types/src/utils/commandParser.d.ts +34 -0
  113. package/dist/types/src/utils/constants.d.ts +33 -0
  114. package/dist/types/src/utils/eip712.d.ts +17 -0
  115. package/dist/types/src/utils/getCurrencyAddress.d.ts +2 -0
  116. package/dist/types/src/utils/inputTokens.d.ts +23 -0
  117. package/dist/types/src/utils/numbers.d.ts +7 -0
  118. package/dist/types/src/utils/pathCurrency.d.ts +3 -0
  119. package/dist/types/src/utils/routerCommands.d.ts +77 -0
  120. package/dist/types/src/utils/routerTradeAdapter.d.ts +73 -0
  121. package/package.json +31 -22
  122. package/dist/index.js +0 -8
  123. package/dist/test/forge/writeInterop.d.ts +0 -2
  124. package/dist/test/utils/addresses.d.ts +0 -5
  125. package/dist/test/utils/hexToDecimalString.d.ts +0 -2
  126. package/dist/test/utils/permit2.d.ts +0 -7
  127. package/dist/test/utils/uniswapData.d.ts +0 -24
  128. package/dist/universal-router-sdk.cjs.development.js +0 -1925
  129. package/dist/universal-router-sdk.cjs.development.js.map +0 -1
  130. package/dist/universal-router-sdk.cjs.production.min.js +0 -2
  131. package/dist/universal-router-sdk.cjs.production.min.js.map +0 -1
  132. package/dist/universal-router-sdk.esm.js +0 -1912
  133. package/dist/universal-router-sdk.esm.js.map +0 -1
@@ -1,1912 +0,0 @@
1
- import invariant from 'tiny-invariant';
2
- import UniversalRouter from '@uniswap/universal-router/artifacts/contracts/UniversalRouter.sol/UniversalRouter.json';
3
- import { Interface } from '@ethersproject/abi';
4
- import { BigNumber, ethers } from 'ethers';
5
- import { toHex, Trade as Trade$1, encodeRouteToPath, Pool as Pool$1, NonfungiblePositionManager, Multicall, Route as Route$1 } from '@uniswap/v3-sdk';
6
- import { Pool, Route, Trade as Trade$2, V4Planner, Actions, encodeRouteToPath as encodeRouteToPath$1, URVersion, V4PositionManager, V4BaseActionsParser } from '@uniswap/v4-sdk';
7
- export { URVersion } from '@uniswap/v4-sdk';
8
- import { TradeType, Percent, validateAndParseAddress, CHAIN_TO_ADDRESSES_MAP, CurrencyAmount, Ether, Token } from '@uniswap/sdk-core';
9
- import { defaultAbiCoder } from 'ethers/lib/utils';
10
- import { Trade, Pair, Route as Route$2 } from '@uniswap/v2-sdk';
11
- import { Protocol, MixedRouteTrade, partitionMixedRouteByProtocol, getOutputOfPools, MixedRoute, MixedRouteSDK, encodeMixedRouteToPath, Trade as Trade$3 } from '@uniswap/router-sdk';
12
- import 'jsbi';
13
- import 'bignumber.js';
14
-
15
- function _arrayLikeToArray(r, a) {
16
- (null == a || a > r.length) && (a = r.length);
17
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
18
- return n;
19
- }
20
- function _defineProperties(e, r) {
21
- for (var t = 0; t < r.length; t++) {
22
- var o = r[t];
23
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
24
- }
25
- }
26
- function _createClass(e, r, t) {
27
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
28
- writable: !1
29
- }), e;
30
- }
31
- function _createForOfIteratorHelperLoose(r, e) {
32
- var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
33
- if (t) return (t = t.call(r)).next.bind(t);
34
- if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
35
- t && (r = t);
36
- var o = 0;
37
- return function () {
38
- return o >= r.length ? {
39
- done: !0
40
- } : {
41
- done: !1,
42
- value: r[o++]
43
- };
44
- };
45
- }
46
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
47
- }
48
- function _toPrimitive(t, r) {
49
- if ("object" != typeof t || !t) return t;
50
- var e = t[Symbol.toPrimitive];
51
- if (void 0 !== e) {
52
- var i = e.call(t, r || "default");
53
- if ("object" != typeof i) return i;
54
- throw new TypeError("@@toPrimitive must return a primitive value.");
55
- }
56
- return ("string" === r ? String : Number)(t);
57
- }
58
- function _toPropertyKey(t) {
59
- var i = _toPrimitive(t, "string");
60
- return "symbol" == typeof i ? i : i + "";
61
- }
62
- function _unsupportedIterableToArray(r, a) {
63
- if (r) {
64
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
65
- var t = {}.toString.call(r).slice(8, -1);
66
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
67
- }
68
- }
69
-
70
- var _COMMAND_DEFINITION;
71
- /**
72
- * CommandTypes
73
- * @description Flags that modify a command's execution
74
- * @enum {number}
75
- */
76
- var CommandType;
77
- (function (CommandType) {
78
- CommandType[CommandType["V3_SWAP_EXACT_IN"] = 0] = "V3_SWAP_EXACT_IN";
79
- CommandType[CommandType["V3_SWAP_EXACT_OUT"] = 1] = "V3_SWAP_EXACT_OUT";
80
- CommandType[CommandType["PERMIT2_TRANSFER_FROM"] = 2] = "PERMIT2_TRANSFER_FROM";
81
- CommandType[CommandType["PERMIT2_PERMIT_BATCH"] = 3] = "PERMIT2_PERMIT_BATCH";
82
- CommandType[CommandType["SWEEP"] = 4] = "SWEEP";
83
- CommandType[CommandType["TRANSFER"] = 5] = "TRANSFER";
84
- CommandType[CommandType["PAY_PORTION"] = 6] = "PAY_PORTION";
85
- CommandType[CommandType["V2_SWAP_EXACT_IN"] = 8] = "V2_SWAP_EXACT_IN";
86
- CommandType[CommandType["V2_SWAP_EXACT_OUT"] = 9] = "V2_SWAP_EXACT_OUT";
87
- CommandType[CommandType["PERMIT2_PERMIT"] = 10] = "PERMIT2_PERMIT";
88
- CommandType[CommandType["WRAP_ETH"] = 11] = "WRAP_ETH";
89
- CommandType[CommandType["UNWRAP_WETH"] = 12] = "UNWRAP_WETH";
90
- CommandType[CommandType["PERMIT2_TRANSFER_FROM_BATCH"] = 13] = "PERMIT2_TRANSFER_FROM_BATCH";
91
- CommandType[CommandType["BALANCE_CHECK_ERC20"] = 14] = "BALANCE_CHECK_ERC20";
92
- CommandType[CommandType["V4_SWAP"] = 16] = "V4_SWAP";
93
- CommandType[CommandType["V3_POSITION_MANAGER_PERMIT"] = 17] = "V3_POSITION_MANAGER_PERMIT";
94
- CommandType[CommandType["V3_POSITION_MANAGER_CALL"] = 18] = "V3_POSITION_MANAGER_CALL";
95
- CommandType[CommandType["V4_INITIALIZE_POOL"] = 19] = "V4_INITIALIZE_POOL";
96
- CommandType[CommandType["V4_POSITION_MANAGER_CALL"] = 20] = "V4_POSITION_MANAGER_CALL";
97
- CommandType[CommandType["EXECUTE_SUB_PLAN"] = 33] = "EXECUTE_SUB_PLAN";
98
- // 3rd party integrations (0x40-0x5f range)
99
- CommandType[CommandType["ACROSS_V4_DEPOSIT_V3"] = 64] = "ACROSS_V4_DEPOSIT_V3";
100
- })(CommandType || (CommandType = {}));
101
- var Subparser;
102
- (function (Subparser) {
103
- Subparser[Subparser["V3PathExactIn"] = 0] = "V3PathExactIn";
104
- Subparser[Subparser["V3PathExactOut"] = 1] = "V3PathExactOut";
105
- })(Subparser || (Subparser = {}));
106
- var Parser;
107
- (function (Parser) {
108
- Parser[Parser["Abi"] = 0] = "Abi";
109
- Parser[Parser["V4Actions"] = 1] = "V4Actions";
110
- Parser[Parser["V3Actions"] = 2] = "V3Actions";
111
- })(Parser || (Parser = {}));
112
- var ALLOW_REVERT_FLAG = 0x80;
113
- var REVERTIBLE_COMMANDS = /*#__PURE__*/new Set([CommandType.EXECUTE_SUB_PLAN]);
114
- var PERMIT_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 nonce) details,address spender,uint256 sigDeadline)';
115
- var PERMIT_BATCH_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 nonce)[] details,address spender,uint256 sigDeadline)';
116
- var POOL_KEY_STRUCT = '(address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks)';
117
- var PERMIT2_TRANSFER_FROM_STRUCT = '(address from,address to,uint160 amount,address token)';
118
- var PERMIT2_TRANSFER_FROM_BATCH_STRUCT = PERMIT2_TRANSFER_FROM_STRUCT + '[]';
119
- var COMMAND_DEFINITION = (_COMMAND_DEFINITION = {}, _COMMAND_DEFINITION[CommandType.EXECUTE_SUB_PLAN] = {
120
- parser: Parser.Abi,
121
- params: [{
122
- name: 'commands',
123
- type: 'bytes'
124
- }, {
125
- name: 'inputs',
126
- type: 'bytes[]'
127
- }]
128
- }, _COMMAND_DEFINITION[CommandType.PERMIT2_PERMIT] = {
129
- parser: Parser.Abi,
130
- params: [{
131
- name: 'permit',
132
- type: PERMIT_STRUCT
133
- }, {
134
- name: 'signature',
135
- type: 'bytes'
136
- }]
137
- }, _COMMAND_DEFINITION[CommandType.PERMIT2_PERMIT_BATCH] = {
138
- parser: Parser.Abi,
139
- params: [{
140
- name: 'permit',
141
- type: PERMIT_BATCH_STRUCT
142
- }, {
143
- name: 'signature',
144
- type: 'bytes'
145
- }]
146
- }, _COMMAND_DEFINITION[CommandType.PERMIT2_TRANSFER_FROM] = {
147
- parser: Parser.Abi,
148
- params: [{
149
- name: 'token',
150
- type: 'address'
151
- }, {
152
- name: 'recipient',
153
- type: 'address'
154
- }, {
155
- name: 'amount',
156
- type: 'uint160'
157
- }]
158
- }, _COMMAND_DEFINITION[CommandType.PERMIT2_TRANSFER_FROM_BATCH] = {
159
- parser: Parser.Abi,
160
- params: [{
161
- name: 'transferFrom',
162
- type: PERMIT2_TRANSFER_FROM_BATCH_STRUCT
163
- }]
164
- }, _COMMAND_DEFINITION[CommandType.V3_SWAP_EXACT_IN] = {
165
- parser: Parser.Abi,
166
- params: [{
167
- name: 'recipient',
168
- type: 'address'
169
- }, {
170
- name: 'amountIn',
171
- type: 'uint256'
172
- }, {
173
- name: 'amountOutMin',
174
- type: 'uint256'
175
- }, {
176
- name: 'path',
177
- subparser: Subparser.V3PathExactIn,
178
- type: 'bytes'
179
- }, {
180
- name: 'payerIsUser',
181
- type: 'bool'
182
- }]
183
- }, _COMMAND_DEFINITION[CommandType.V3_SWAP_EXACT_OUT] = {
184
- parser: Parser.Abi,
185
- params: [{
186
- name: 'recipient',
187
- type: 'address'
188
- }, {
189
- name: 'amountOut',
190
- type: 'uint256'
191
- }, {
192
- name: 'amountInMax',
193
- type: 'uint256'
194
- }, {
195
- name: 'path',
196
- subparser: Subparser.V3PathExactOut,
197
- type: 'bytes'
198
- }, {
199
- name: 'payerIsUser',
200
- type: 'bool'
201
- }]
202
- }, _COMMAND_DEFINITION[CommandType.V2_SWAP_EXACT_IN] = {
203
- parser: Parser.Abi,
204
- params: [{
205
- name: 'recipient',
206
- type: 'address'
207
- }, {
208
- name: 'amountIn',
209
- type: 'uint256'
210
- }, {
211
- name: 'amountOutMin',
212
- type: 'uint256'
213
- }, {
214
- name: 'path',
215
- type: 'address[]'
216
- }, {
217
- name: 'payerIsUser',
218
- type: 'bool'
219
- }]
220
- }, _COMMAND_DEFINITION[CommandType.V2_SWAP_EXACT_OUT] = {
221
- parser: Parser.Abi,
222
- params: [{
223
- name: 'recipient',
224
- type: 'address'
225
- }, {
226
- name: 'amountOut',
227
- type: 'uint256'
228
- }, {
229
- name: 'amountInMax',
230
- type: 'uint256'
231
- }, {
232
- name: 'path',
233
- type: 'address[]'
234
- }, {
235
- name: 'payerIsUser',
236
- type: 'bool'
237
- }]
238
- }, _COMMAND_DEFINITION[CommandType.V4_SWAP] = {
239
- parser: Parser.V4Actions
240
- }, _COMMAND_DEFINITION[CommandType.WRAP_ETH] = {
241
- parser: Parser.Abi,
242
- params: [{
243
- name: 'recipient',
244
- type: 'address'
245
- }, {
246
- name: 'amount',
247
- type: 'uint256'
248
- }]
249
- }, _COMMAND_DEFINITION[CommandType.UNWRAP_WETH] = {
250
- parser: Parser.Abi,
251
- params: [{
252
- name: 'recipient',
253
- type: 'address'
254
- }, {
255
- name: 'amountMin',
256
- type: 'uint256'
257
- }]
258
- }, _COMMAND_DEFINITION[CommandType.SWEEP] = {
259
- parser: Parser.Abi,
260
- params: [{
261
- name: 'token',
262
- type: 'address'
263
- }, {
264
- name: 'recipient',
265
- type: 'address'
266
- }, {
267
- name: 'amountMin',
268
- type: 'uint256'
269
- }]
270
- }, _COMMAND_DEFINITION[CommandType.TRANSFER] = {
271
- parser: Parser.Abi,
272
- params: [{
273
- name: 'token',
274
- type: 'address'
275
- }, {
276
- name: 'recipient',
277
- type: 'address'
278
- }, {
279
- name: 'value',
280
- type: 'uint256'
281
- }]
282
- }, _COMMAND_DEFINITION[CommandType.PAY_PORTION] = {
283
- parser: Parser.Abi,
284
- params: [{
285
- name: 'token',
286
- type: 'address'
287
- }, {
288
- name: 'recipient',
289
- type: 'address'
290
- }, {
291
- name: 'bips',
292
- type: 'uint256'
293
- }]
294
- }, _COMMAND_DEFINITION[CommandType.BALANCE_CHECK_ERC20] = {
295
- parser: Parser.Abi,
296
- params: [{
297
- name: 'owner',
298
- type: 'address'
299
- }, {
300
- name: 'token',
301
- type: 'address'
302
- }, {
303
- name: 'minBalance',
304
- type: 'uint256'
305
- }]
306
- }, _COMMAND_DEFINITION[CommandType.V4_INITIALIZE_POOL] = {
307
- parser: Parser.Abi,
308
- params: [{
309
- name: 'poolKey',
310
- type: POOL_KEY_STRUCT
311
- }, {
312
- name: 'sqrtPriceX96',
313
- type: 'uint160'
314
- }]
315
- }, _COMMAND_DEFINITION[CommandType.V3_POSITION_MANAGER_PERMIT] = {
316
- parser: Parser.V3Actions
317
- }, _COMMAND_DEFINITION[CommandType.V3_POSITION_MANAGER_CALL] = {
318
- parser: Parser.V3Actions
319
- }, _COMMAND_DEFINITION[CommandType.V4_POSITION_MANAGER_CALL] = {
320
- parser: Parser.V4Actions
321
- }, _COMMAND_DEFINITION[CommandType.ACROSS_V4_DEPOSIT_V3] = {
322
- parser: Parser.Abi,
323
- params: [{
324
- name: 'depositor',
325
- type: 'address'
326
- }, {
327
- name: 'recipient',
328
- type: 'address'
329
- }, {
330
- name: 'inputToken',
331
- type: 'address'
332
- }, {
333
- name: 'outputToken',
334
- type: 'address'
335
- }, {
336
- name: 'inputAmount',
337
- type: 'uint256'
338
- }, {
339
- name: 'outputAmount',
340
- type: 'uint256'
341
- }, {
342
- name: 'destinationChainId',
343
- type: 'uint256'
344
- }, {
345
- name: 'exclusiveRelayer',
346
- type: 'address'
347
- }, {
348
- name: 'quoteTimestamp',
349
- type: 'uint32'
350
- }, {
351
- name: 'fillDeadline',
352
- type: 'uint32'
353
- }, {
354
- name: 'exclusivityDeadline',
355
- type: 'uint32'
356
- }, {
357
- name: 'message',
358
- type: 'bytes'
359
- }, {
360
- name: 'useNative',
361
- type: 'bool'
362
- }]
363
- }, _COMMAND_DEFINITION);
364
- var RoutePlanner = /*#__PURE__*/function () {
365
- function RoutePlanner() {
366
- this.commands = '0x';
367
- this.inputs = [];
368
- }
369
- var _proto = RoutePlanner.prototype;
370
- _proto.addSubPlan = function addSubPlan(subplan) {
371
- this.addCommand(CommandType.EXECUTE_SUB_PLAN, [subplan.commands, subplan.inputs], true);
372
- return this;
373
- };
374
- _proto.addCommand = function addCommand(type, parameters, allowRevert) {
375
- if (allowRevert === void 0) {
376
- allowRevert = false;
377
- }
378
- var command = createCommand(type, parameters);
379
- this.inputs.push(command.encodedInput);
380
- if (allowRevert) {
381
- if (!REVERTIBLE_COMMANDS.has(command.type)) {
382
- throw new Error("command type: " + command.type + " cannot be allowed to revert");
383
- }
384
- command.type = command.type | ALLOW_REVERT_FLAG;
385
- }
386
- this.commands = this.commands.concat(command.type.toString(16).padStart(2, '0'));
387
- return this;
388
- }
389
- /**
390
- * Add Across bridge deposit command for cross-chain bridging
391
- * @param params AcrossV4DepositV3Params containing bridge parameters
392
- * @returns RoutePlanner instance for chaining
393
- */;
394
- _proto.addAcrossBridge = function addAcrossBridge(params) {
395
- this.addCommand(CommandType.ACROSS_V4_DEPOSIT_V3, [params.depositor, params.recipient, params.inputToken, params.outputToken, params.inputAmount, params.outputAmount, params.destinationChainId, params.exclusiveRelayer, params.quoteTimestamp, params.fillDeadline, params.exclusivityDeadline, params.message, params.useNative]);
396
- return this;
397
- };
398
- return RoutePlanner;
399
- }();
400
- function createCommand(type, parameters) {
401
- var commandDef = COMMAND_DEFINITION[type];
402
- switch (commandDef.parser) {
403
- case Parser.Abi:
404
- var encodedInput = defaultAbiCoder.encode(commandDef.params.map(function (abi) {
405
- return abi.type;
406
- }), parameters);
407
- return {
408
- type: type,
409
- encodedInput: encodedInput
410
- };
411
- case Parser.V4Actions:
412
- // v4 swap data comes pre-encoded at index 0
413
- return {
414
- type: type,
415
- encodedInput: parameters[0]
416
- };
417
- case Parser.V3Actions:
418
- // v4 swap data comes pre-encoded at index 0
419
- return {
420
- type: type,
421
- encodedInput: parameters[0]
422
- };
423
- }
424
- }
425
-
426
- function getPathCurrency(currency, pool) {
427
- // return currency if the currency matches a currency of the pool
428
- if (pool.involvesToken(currency)) {
429
- return currency;
430
- // return if currency.wrapped if pool involves wrapped currency
431
- } else if (pool.involvesToken(currency.wrapped)) {
432
- return currency.wrapped;
433
- // return native currency if pool involves native version of wrapped currency (only applies to V4)
434
- } else if (pool instanceof Pool && pool.token0.wrapped.equals(currency)) {
435
- return pool.token0;
436
- } else if (pool instanceof Pool && pool.token1.wrapped.equals(currency)) {
437
- return pool.token1;
438
- } else {
439
- throw new Error("Expected currency " + currency.symbol + " to be either " + pool.token0.symbol + " or " + pool.token1.symbol);
440
- }
441
- }
442
-
443
- var RouterActionType;
444
- (function (RouterActionType) {
445
- RouterActionType["UniswapTrade"] = "UniswapTrade";
446
- RouterActionType["UnwrapWETH"] = "UnwrapWETH";
447
- })(RouterActionType || (RouterActionType = {}));
448
-
449
- var _routerConfigs, _routerConfigs2, _routerConfigs3, _routerConfigs4, _routerConfigs5, _routerConfigs6, _routerConfigs7, _routerConfigs8, _routerConfigs9, _routerConfigs0, _routerConfigs1, _routerConfigs10, _routerConfigs11, _routerConfigs12, _routerConfigs13, _routerConfigs14, _routerConfigs15, _routerConfigs16, _routerConfigs17, _routerConfigs18, _routerConfigs19, _routerConfigs20, _routerConfigs21, _routerConfigs22, _routerConfigs23, _routerConfigs24, _routerConfigs25, _routerConfigs26, _CHAIN_CONFIGS;
450
- var UniversalRouterVersion;
451
- (function (UniversalRouterVersion) {
452
- UniversalRouterVersion["V1_2"] = "1.2";
453
- UniversalRouterVersion["V2_0"] = "2.0";
454
- UniversalRouterVersion["V2_1"] = "2.1";
455
- })(UniversalRouterVersion || (UniversalRouterVersion = {}));
456
- var WETH_NOT_SUPPORTED_ON_CHAIN = '0x0000000000000000000000000000000000000000';
457
- var SWAP_PROXY_DEPLOY_ADDRESS = '0x02E5be68D46DAc0B524905bfF209cf47EE6dB2a9';
458
- // Todo: Change `CHAIN_CONFIGS` to pull the UR address with v4
459
- var CHAIN_CONFIGS = (_CHAIN_CONFIGS = {}, _CHAIN_CONFIGS[1] = {
460
- weth: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
461
- routerConfigs: (_routerConfigs = {}, _routerConfigs[UniversalRouterVersion.V1_2] = {
462
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
463
- creationBlock: 17143817
464
- }, _routerConfigs[UniversalRouterVersion.V2_0] = {
465
- address: '0x66a9893cc07d91d95644aedd05d03f95e1dba8af',
466
- creationBlock: 21689092
467
- }, _routerConfigs[UniversalRouterVersion.V2_1] = {
468
- address: '0xd92a36b0000531ef3063ded4de20a0783308446c',
469
- creationBlock: 23836348
470
- }, _routerConfigs),
471
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
472
- }, _CHAIN_CONFIGS[5] = {
473
- weth: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
474
- routerConfigs: (_routerConfigs2 = {}, _routerConfigs2[UniversalRouterVersion.V1_2] = {
475
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
476
- creationBlock: 8940568
477
- }, _routerConfigs2[UniversalRouterVersion.V2_0] = {
478
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
479
- creationBlock: 8940568
480
- }, _routerConfigs2[UniversalRouterVersion.V2_1] = {
481
- address: '0x0000000000000000000000000000000000000000',
482
- creationBlock: 1
483
- }, _routerConfigs2)
484
- }, _CHAIN_CONFIGS[11155111] = {
485
- weth: '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14',
486
- routerConfigs: (_routerConfigs3 = {}, _routerConfigs3[UniversalRouterVersion.V1_2] = {
487
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
488
- creationBlock: 3543575
489
- }, _routerConfigs3[UniversalRouterVersion.V2_0] = {
490
- address: '0x3a9d48ab9751398bbfa63ad67599bb04e4bdf98b',
491
- creationBlock: 7259601
492
- }, _routerConfigs3[UniversalRouterVersion.V2_1] = {
493
- address: '0x470FFC67b1feEEC31D16C46AC7545C98716a194c',
494
- creationBlock: 9664766
495
- }, _routerConfigs3),
496
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
497
- }, _CHAIN_CONFIGS[137] = {
498
- weth: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
499
- routerConfigs: (_routerConfigs4 = {}, _routerConfigs4[UniversalRouterVersion.V1_2] = {
500
- address: '0xec7BE89e9d109e7e3Fec59c222CF297125FEFda2',
501
- creationBlock: 52210153
502
- }, _routerConfigs4[UniversalRouterVersion.V2_0] = {
503
- address: '0x1095692a6237d83c6a72f3f5efedb9a670c49223',
504
- creationBlock: 66980401
505
- }, _routerConfigs4[UniversalRouterVersion.V2_1] = {
506
- address: '0xE27610fD9dD05FC061366bc9dA414CA6F948f204',
507
- creationBlock: 79245524
508
- }, _routerConfigs4),
509
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
510
- }, _CHAIN_CONFIGS[80001] = {
511
- weth: '0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889',
512
- routerConfigs: (_routerConfigs5 = {}, _routerConfigs5[UniversalRouterVersion.V1_2] = {
513
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
514
- creationBlock: 35176052
515
- }, _routerConfigs5[UniversalRouterVersion.V2_0] = {
516
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
517
- creationBlock: 35176052
518
- }, _routerConfigs5[UniversalRouterVersion.V2_1] = {
519
- address: '0x0000000000000000000000000000000000000000',
520
- creationBlock: 1
521
- }, _routerConfigs5)
522
- }, _CHAIN_CONFIGS[10] = {
523
- weth: '0x4200000000000000000000000000000000000006',
524
- routerConfigs: (_routerConfigs6 = {}, _routerConfigs6[UniversalRouterVersion.V1_2] = {
525
- address: '0xCb1355ff08Ab38bBCE60111F1bb2B784bE25D7e8',
526
- creationBlock: 114702266
527
- }, _routerConfigs6[UniversalRouterVersion.V2_0] = {
528
- address: '0x851116d9223fabed8e56c0e6b8ad0c31d98b3507',
529
- creationBlock: 130947687
530
- }, _routerConfigs6[UniversalRouterVersion.V2_1] = {
531
- address: '0xde20EEE5398D3790a4D356e8925bD21Ea65D99Af',
532
- creationBlock: 143998769
533
- }, _routerConfigs6),
534
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
535
- }, _CHAIN_CONFIGS[420] = {
536
- weth: '0x4200000000000000000000000000000000000006',
537
- routerConfigs: (_routerConfigs7 = {}, _routerConfigs7[UniversalRouterVersion.V1_2] = {
538
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
539
- creationBlock: 8887728
540
- }, _routerConfigs7[UniversalRouterVersion.V2_0] = {
541
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
542
- creationBlock: 8887728
543
- }, _routerConfigs7[UniversalRouterVersion.V2_1] = {
544
- address: '0x0000000000000000000000000000000000000000',
545
- creationBlock: 1
546
- }, _routerConfigs7)
547
- }, _CHAIN_CONFIGS[42161] = {
548
- weth: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
549
- routerConfigs: (_routerConfigs8 = {}, _routerConfigs8[UniversalRouterVersion.V1_2] = {
550
- address: '0x5E325eDA8064b456f4781070C0738d849c824258',
551
- creationBlock: 169472836
552
- }, _routerConfigs8[UniversalRouterVersion.V2_0] = {
553
- address: '0xa51afafe0263b40edaef0df8781ea9aa03e381a3',
554
- creationBlock: 297842906
555
- }, _routerConfigs8[UniversalRouterVersion.V2_1] = {
556
- address: '0x96b2FD2F80e9428Daa65d859653117D453981AB4',
557
- creationBlock: 402060097
558
- }, _routerConfigs8),
559
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
560
- }, _CHAIN_CONFIGS[421613] = {
561
- weth: '0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3',
562
- routerConfigs: (_routerConfigs9 = {}, _routerConfigs9[UniversalRouterVersion.V1_2] = {
563
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
564
- creationBlock: 18815277
565
- }, _routerConfigs9[UniversalRouterVersion.V2_0] = {
566
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
567
- creationBlock: 18815277
568
- }, _routerConfigs9[UniversalRouterVersion.V2_1] = {
569
- address: '0x0000000000000000000000000000000000000000',
570
- creationBlock: 1
571
- }, _routerConfigs9)
572
- }, _CHAIN_CONFIGS[42220] = {
573
- weth: WETH_NOT_SUPPORTED_ON_CHAIN,
574
- routerConfigs: (_routerConfigs0 = {}, _routerConfigs0[UniversalRouterVersion.V1_2] = {
575
- address: '0x643770e279d5d0733f21d6dc03a8efbabf3255b4',
576
- creationBlock: 21407637
577
- }, _routerConfigs0[UniversalRouterVersion.V2_0] = {
578
- address: '0xcb695bc5D3Aa22cAD1E6DF07801b061a05A0233A',
579
- creationBlock: 47387857
580
- }, _routerConfigs0[UniversalRouterVersion.V2_1] = {
581
- address: '0xBB8Ed9bF0BFF210652AE5f473a849F82e990DDf6',
582
- creationBlock: 51696199
583
- }, _routerConfigs0),
584
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
585
- }, _CHAIN_CONFIGS[44787] = {
586
- weth: WETH_NOT_SUPPORTED_ON_CHAIN,
587
- routerConfigs: (_routerConfigs1 = {}, _routerConfigs1[UniversalRouterVersion.V1_2] = {
588
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
589
- creationBlock: 17566658
590
- }, _routerConfigs1[UniversalRouterVersion.V2_0] = {
591
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
592
- creationBlock: 17566658
593
- }, _routerConfigs1[UniversalRouterVersion.V2_1] = {
594
- address: '0x0000000000000000000000000000000000000000',
595
- creationBlock: 1
596
- }, _routerConfigs1)
597
- }, _CHAIN_CONFIGS[56] = {
598
- weth: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
599
- routerConfigs: (_routerConfigs10 = {}, _routerConfigs10[UniversalRouterVersion.V1_2] = {
600
- address: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
601
- creationBlock: 35160263
602
- }, _routerConfigs10[UniversalRouterVersion.V2_0] = {
603
- address: '0x1906c1d672b88cd1b9ac7593301ca990f94eae07',
604
- creationBlock: 45970616
605
- }, _routerConfigs10[UniversalRouterVersion.V2_1] = {
606
- address: '0x91BF3bfAEf8D771A74E1A8fE460b3EE646b2e588',
607
- creationBlock: 68794488
608
- }, _routerConfigs10),
609
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
610
- }, _CHAIN_CONFIGS[43114] = {
611
- weth: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
612
- routerConfigs: (_routerConfigs11 = {}, _routerConfigs11[UniversalRouterVersion.V1_2] = {
613
- address: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
614
- creationBlock: 40237257
615
- }, _routerConfigs11[UniversalRouterVersion.V2_0] = {
616
- address: '0x94b75331ae8d42c1b61065089b7d48fe14aa73b7',
617
- creationBlock: 56195395
618
- }, _routerConfigs11[UniversalRouterVersion.V2_1] = {
619
- address: '0x0Cf1f86B331A03179646341D10A2A87515087221',
620
- creationBlock: 72254439
621
- }, _routerConfigs11),
622
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
623
- }, _CHAIN_CONFIGS[84531] = {
624
- weth: '0x4200000000000000000000000000000000000006',
625
- routerConfigs: (_routerConfigs12 = {}, _routerConfigs12[UniversalRouterVersion.V1_2] = {
626
- address: '0xd0872d928672ae2ff74bdb2f5130ac12229cafaf',
627
- creationBlock: 6915289
628
- }, _routerConfigs12[UniversalRouterVersion.V2_0] = {
629
- address: '0xd0872d928672ae2ff74bdb2f5130ac12229cafaf',
630
- creationBlock: 6915289
631
- }, _routerConfigs12[UniversalRouterVersion.V2_1] = {
632
- address: '0x0000000000000000000000000000000000000000',
633
- creationBlock: 1
634
- }, _routerConfigs12)
635
- }, _CHAIN_CONFIGS[8453] = {
636
- weth: '0x4200000000000000000000000000000000000006',
637
- routerConfigs: (_routerConfigs13 = {}, _routerConfigs13[UniversalRouterVersion.V1_2] = {
638
- address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
639
- creationBlock: 9107268
640
- }, _routerConfigs13[UniversalRouterVersion.V2_0] = {
641
- address: '0x6ff5693b99212da76ad316178a184ab56d299b43',
642
- creationBlock: 25350999
643
- }, _routerConfigs13[UniversalRouterVersion.V2_1] = {
644
- address: '0xf3a4f4094bd2c6c06ca2f61789d8727b8d1e7259',
645
- creationBlock: 38404211
646
- }, _routerConfigs13),
647
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
648
- }, _CHAIN_CONFIGS[81457] = {
649
- weth: '0x4300000000000000000000000000000000000004',
650
- routerConfigs: (_routerConfigs14 = {}, _routerConfigs14[UniversalRouterVersion.V1_2] = {
651
- address: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
652
- creationBlock: 1116444
653
- }, _routerConfigs14[UniversalRouterVersion.V2_0] = {
654
- address: '0xeabbcb3e8e415306207ef514f660a3f820025be3',
655
- creationBlock: 14377319
656
- }, _routerConfigs14[UniversalRouterVersion.V2_1] = {
657
- address: '0x77c0097c1acf6fd84878d3f7c0603e3f04e8bec7',
658
- creationBlock: 27394047
659
- }, _routerConfigs14),
660
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
661
- }, _CHAIN_CONFIGS[7777777] = {
662
- weth: '0x4200000000000000000000000000000000000006',
663
- routerConfigs: (_routerConfigs15 = {}, _routerConfigs15[UniversalRouterVersion.V1_2] = {
664
- address: '0x2986d9721A49838ab4297b695858aF7F17f38014',
665
- creationBlock: 11832155
666
- }, _routerConfigs15[UniversalRouterVersion.V2_0] = {
667
- address: '0x3315ef7ca28db74abadc6c44570efdf06b04b020',
668
- creationBlock: 25434544
669
- }, _routerConfigs15[UniversalRouterVersion.V2_1] = {
670
- address: '0x880853091b60f80301a0c1d2f9893c4993041295',
671
- creationBlock: 38452170
672
- }, _routerConfigs15),
673
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
674
- }, _CHAIN_CONFIGS[324] = {
675
- weth: '0x5aea5775959fbc2557cc8789bc1bf90a239d9a91',
676
- routerConfigs: (_routerConfigs16 = {}, _routerConfigs16[UniversalRouterVersion.V1_2] = {
677
- address: '0x28731BCC616B5f51dD52CF2e4dF0E78dD1136C06',
678
- creationBlock: 12640979
679
- }, _routerConfigs16[UniversalRouterVersion.V2_0] = {
680
- address: '0x28731BCC616B5f51dD52CF2e4dF0E78dD1136C06',
681
- creationBlock: 12640979
682
- }, _routerConfigs16[UniversalRouterVersion.V2_1] = {
683
- address: '0x0000000000000000000000000000000000000000',
684
- creationBlock: 1
685
- }, _routerConfigs16),
686
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
687
- }, _CHAIN_CONFIGS[480] = {
688
- weth: '0x4200000000000000000000000000000000000006',
689
- routerConfigs: (_routerConfigs17 = {}, _routerConfigs17[UniversalRouterVersion.V1_2] = {
690
- address: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
691
- creationBlock: 4063979
692
- }, _routerConfigs17[UniversalRouterVersion.V2_0] = {
693
- address: '0x8ac7bee993bb44dab564ea4bc9ea67bf9eb5e743',
694
- creationBlock: 9111895
695
- }, _routerConfigs17[UniversalRouterVersion.V2_1] = {
696
- address: '0x03c4f6b55733cdf3caa07c01e5b83ddee3381f60',
697
- creationBlock: 22131418
698
- }, _routerConfigs17),
699
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
700
- }, _CHAIN_CONFIGS[1301] = {
701
- weth: '0x4200000000000000000000000000000000000006',
702
- routerConfigs: (_routerConfigs18 = {}, _routerConfigs18[UniversalRouterVersion.V1_2] = {
703
- address: '0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6',
704
- creationBlock: 1241811
705
- }, _routerConfigs18[UniversalRouterVersion.V2_0] = {
706
- address: '0xf70536b3bcc1bd1a972dc186a2cf84cc6da6be5d',
707
- creationBlock: 7100543
708
- }, _routerConfigs18[UniversalRouterVersion.V2_1] = {
709
- address: '0x7F9B8D606E0F35E5073ABf93695814530b28a37b',
710
- creationBlock: 36746405
711
- }, _routerConfigs18),
712
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
713
- }, _CHAIN_CONFIGS[130] = {
714
- weth: '0x4200000000000000000000000000000000000006',
715
- routerConfigs: (_routerConfigs19 = {}, _routerConfigs19[UniversalRouterVersion.V1_2] = {
716
- address: '0x4D73A4411CA1c660035e4AECC8270E5DdDEC8C17',
717
- creationBlock: 23678
718
- }, _routerConfigs19[UniversalRouterVersion.V2_0] = {
719
- address: '0xef740bf23acae26f6492b10de645d6b98dc8eaf3',
720
- creationBlock: 6819690
721
- }, _routerConfigs19[UniversalRouterVersion.V2_1] = {
722
- address: '0xe6039ae5b44f90d56c6b029354fb22999861a9a0',
723
- creationBlock: 32850661
724
- }, _routerConfigs19),
725
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
726
- }, _CHAIN_CONFIGS[10143] = {
727
- weth: '0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701',
728
- routerConfigs: (_routerConfigs20 = {}, _routerConfigs20[UniversalRouterVersion.V1_2] = {
729
- address: '0x3ae6d8a282d67893e17aa70ebffb33ee5aa65893',
730
- creationBlock: 23678
731
- }, _routerConfigs20[UniversalRouterVersion.V2_0] = {
732
- address: '0x3ae6d8a282d67893e17aa70ebffb33ee5aa65893',
733
- creationBlock: 23678
734
- }, _routerConfigs20[UniversalRouterVersion.V2_1] = {
735
- address: '0x0000000000000000000000000000000000000000',
736
- creationBlock: 1
737
- }, _routerConfigs20),
738
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
739
- }, _CHAIN_CONFIGS[84532] = {
740
- weth: '0x4200000000000000000000000000000000000006',
741
- routerConfigs: (_routerConfigs21 = {}, _routerConfigs21[UniversalRouterVersion.V1_2] = {
742
- address: '0x492e6456d9528771018deb9e87ef7750ef184104',
743
- creationBlock: 20216585
744
- }, _routerConfigs21[UniversalRouterVersion.V2_0] = {
745
- address: '0x492e6456d9528771018deb9e87ef7750ef184104',
746
- creationBlock: 20216585
747
- }, _routerConfigs21[UniversalRouterVersion.V2_1] = {
748
- address: '0x0000000000000000000000000000000000000000',
749
- creationBlock: 1
750
- }, _routerConfigs21),
751
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
752
- }, _CHAIN_CONFIGS[1868] = {
753
- weth: '0x4200000000000000000000000000000000000006',
754
- routerConfigs: (_routerConfigs22 = {}, _routerConfigs22[UniversalRouterVersion.V1_2] = {
755
- address: '0x0e2850543f69f678257266e0907ff9a58b3f13de',
756
- creationBlock: 3254782
757
- }, _routerConfigs22[UniversalRouterVersion.V2_0] = {
758
- address: '0x0e2850543f69f678257266e0907ff9a58b3f13de',
759
- creationBlock: 3254782
760
- }, _routerConfigs22[UniversalRouterVersion.V2_1] = {
761
- address: '0xdb1d5986551c820bd0f3b1caca3e77ce03acb5ef',
762
- creationBlock: 15232223
763
- }, _routerConfigs22),
764
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
765
- }, _CHAIN_CONFIGS[143] = {
766
- weth: '0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A',
767
- routerConfigs: (_routerConfigs23 = {}, _routerConfigs23[UniversalRouterVersion.V1_2] = {
768
- address: '0x0d97dc33264bfc1c226207428a79b26757fb9dc3',
769
- creationBlock: 29255937
770
- }, _routerConfigs23[UniversalRouterVersion.V2_0] = {
771
- address: '0x0d97dc33264bfc1c226207428a79b26757fb9dc3',
772
- creationBlock: 29255937
773
- }, _routerConfigs23[UniversalRouterVersion.V2_1] = {
774
- address: '0xBC2A036E5027b9AE57BbA847eF88E1b14823F7B1',
775
- creationBlock: 36720825
776
- }, _routerConfigs23),
777
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
778
- }, _CHAIN_CONFIGS[59144] = {
779
- weth: '0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f',
780
- routerConfigs: (_routerConfigs24 = {}, _routerConfigs24[UniversalRouterVersion.V1_2] = {
781
- address: '0x0000000000000000000000000000000000000000',
782
- creationBlock: 1
783
- }, _routerConfigs24[UniversalRouterVersion.V2_0] = {
784
- address: '0x661e93cca42afacb172121ef892830ca3b70f08d',
785
- creationBlock: 1
786
- }, _routerConfigs24[UniversalRouterVersion.V2_1] = {
787
- address: '0xba548ce7a95f87bc66a0c7c6eab1e428735f8b57',
788
- creationBlock: 1
789
- }, _routerConfigs24),
790
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
791
- }, _CHAIN_CONFIGS[4217] = {
792
- weth: WETH_NOT_SUPPORTED_ON_CHAIN,
793
- routerConfigs: (_routerConfigs25 = {}, _routerConfigs25[UniversalRouterVersion.V1_2] = {
794
- address: '0x0000000000000000000000000000000000000000',
795
- creationBlock: 1
796
- }, _routerConfigs25[UniversalRouterVersion.V2_0] = {
797
- address: '0x1febb76be10aaf3a1402f04e8e835f2c382f7914',
798
- creationBlock: 1
799
- }, _routerConfigs25[UniversalRouterVersion.V2_1] = {
800
- address: '0xa2dc7d0266f0cc50b3eeaf36c9bfcecff1beea91',
801
- creationBlock: 1
802
- }, _routerConfigs25),
803
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
804
- }, _CHAIN_CONFIGS[196] = {
805
- weth: '0xe538905cf8410324e03A5A23C1c177a474D59b2b',
806
- routerConfigs: (_routerConfigs26 = {}, _routerConfigs26[UniversalRouterVersion.V1_2] = {
807
- address: '0x0000000000000000000000000000000000000000',
808
- creationBlock: 1
809
- }, _routerConfigs26[UniversalRouterVersion.V2_0] = {
810
- address: '0x5507749f2c558bb3e162c6e90c314c092e7372ff',
811
- creationBlock: 47680350
812
- }, _routerConfigs26[UniversalRouterVersion.V2_1] = {
813
- address: '0x0000000000000000000000000000000000000000',
814
- creationBlock: 1
815
- }, _routerConfigs26),
816
- swapProxy: SWAP_PROXY_DEPLOY_ADDRESS
817
- }, _CHAIN_CONFIGS);
818
- var UNIVERSAL_ROUTER_ADDRESS = function UNIVERSAL_ROUTER_ADDRESS(version, chainId) {
819
- if (!(chainId in CHAIN_CONFIGS)) throw new Error("Universal Router not deployed on chain " + chainId);
820
- return CHAIN_CONFIGS[chainId].routerConfigs[version].address;
821
- };
822
- var SWAP_PROXY_ADDRESS = function SWAP_PROXY_ADDRESS(chainId) {
823
- if (!(chainId in CHAIN_CONFIGS)) throw new Error("SwapProxy not deployed on chain " + chainId);
824
- var proxy = CHAIN_CONFIGS[chainId].swapProxy;
825
- if (!proxy) throw new Error("SwapProxy not configured for chain " + chainId);
826
- return proxy;
827
- };
828
- var UNIVERSAL_ROUTER_CREATION_BLOCK = function UNIVERSAL_ROUTER_CREATION_BLOCK(version, chainId) {
829
- if (!(chainId in CHAIN_CONFIGS)) throw new Error("Universal Router not deployed on chain " + chainId);
830
- return CHAIN_CONFIGS[chainId].routerConfigs[version].creationBlock;
831
- };
832
- var WETH_ADDRESS = function WETH_ADDRESS(chainId) {
833
- if (!(chainId in CHAIN_CONFIGS)) throw new Error("Universal Router not deployed on chain " + chainId);
834
- if (CHAIN_CONFIGS[chainId].weth == WETH_NOT_SUPPORTED_ON_CHAIN) throw new Error("Chain " + chainId + " does not have WETH");
835
- return CHAIN_CONFIGS[chainId].weth;
836
- };
837
- var CONTRACT_BALANCE = /*#__PURE__*/BigNumber.from(2).pow(255);
838
- var ETH_ADDRESS = '0x0000000000000000000000000000000000000000';
839
- var E_ETH_ADDRESS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
840
- var SENDER_AS_RECIPIENT = '0x0000000000000000000000000000000000000001';
841
- var ROUTER_AS_RECIPIENT = '0x0000000000000000000000000000000000000002';
842
-
843
- function getCurrencyAddress(currency) {
844
- return currency.isNative ? ETH_ADDRESS : currency.wrapped.address;
845
- }
846
-
847
- function encodeFeeBips(fee) {
848
- return toHex(fee.multiply(10000).quotient);
849
- }
850
-
851
- // the existing router permit object doesn't include enough data for permit2
852
- // so we extend swap options with the permit2 permit
853
- // when safe mode is enabled, the SDK will add an extra ETH sweep for security
854
- // when useRouterBalance is enabled the SDK will use the balance in the router for the swap
855
- var TokenTransferMode;
856
- (function (TokenTransferMode) {
857
- TokenTransferMode["Permit2"] = "Permit2";
858
- TokenTransferMode["ApproveProxy"] = "ApproveProxy";
859
- })(TokenTransferMode || (TokenTransferMode = {}));
860
- var REFUND_ETH_PRICE_IMPACT_THRESHOLD = /*#__PURE__*/new Percent(50, 100);
861
- // Wrapper for uniswap router-sdk trade entity to encode swaps for Universal Router
862
- // also translates trade objects from previous (v2, v3) SDKs
863
- var UniswapTrade = /*#__PURE__*/function () {
864
- function UniswapTrade(trade, options) {
865
- this.trade = trade;
866
- this.options = options;
867
- this.tradeType = RouterActionType.UniswapTrade;
868
- if (!!options.fee && !!options.flatFee) throw new Error('Only one fee option permitted');
869
- if (options.tokenTransferMode === TokenTransferMode.ApproveProxy) {
870
- if (!options.recipient || options.recipient === SENDER_AS_RECIPIENT) {
871
- throw new Error('Explicit recipient address required when using SwapProxy (SENDER_AS_RECIPIENT resolves to proxy)');
872
- }
873
- this.payerIsUser = false;
874
- } else if (this.inputRequiresWrap || this.inputRequiresUnwrap || this.options.useRouterBalance) {
875
- this.payerIsUser = false;
876
- } else {
877
- this.payerIsUser = true;
878
- }
879
- }
880
- var _proto = UniswapTrade.prototype;
881
- _proto.encode = function encode(planner, _config) {
882
- var _this$options$recipie;
883
- // If the input currency is the native currency, we need to wrap it with the router as the recipient
884
- if (this.inputRequiresWrap) {
885
- // TODO: optimize if only one v2 pool we can directly send this to the pool
886
- planner.addCommand(CommandType.WRAP_ETH, [ROUTER_AS_RECIPIENT, this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString()]);
887
- } else if (this.inputRequiresUnwrap) {
888
- if (this.options.tokenTransferMode !== TokenTransferMode.ApproveProxy) {
889
- // send wrapped token to router to unwrap via Permit2
890
- planner.addCommand(CommandType.PERMIT2_TRANSFER_FROM, [this.trade.inputAmount.currency.address, ROUTER_AS_RECIPIENT, this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString()]);
891
- }
892
- // In proxy mode, the proxy already transferred tokens to the UR; just unwrap
893
- planner.addCommand(CommandType.UNWRAP_WETH, [ROUTER_AS_RECIPIENT, 0]);
894
- }
895
- // The overall recipient at the end of the trade, SENDER_AS_RECIPIENT uses the msg.sender
896
- this.options.recipient = (_this$options$recipie = this.options.recipient) != null ? _this$options$recipie : SENDER_AS_RECIPIENT;
897
- // flag for whether we want to perform slippage check on aggregate output of multiple routes
898
- // 1. when there are >2 exact input trades. this is only a heuristic,
899
- // as it's still more gas-expensive even in this case, but has benefits
900
- // in that the reversion probability is lower
901
- var performAggregatedSlippageCheck = this.trade.tradeType === TradeType.EXACT_INPUT && this.trade.routes.length > 2;
902
- var routerMustCustody = performAggregatedSlippageCheck || this.outputRequiresTransition || hasFeeOption(this.options);
903
- for (var _iterator = _createForOfIteratorHelperLoose(this.trade.swaps), _step; !(_step = _iterator()).done;) {
904
- var swap = _step.value;
905
- switch (swap.route.protocol) {
906
- case Protocol.V2:
907
- addV2Swap(planner, swap, this.trade.tradeType, this.options, this.payerIsUser, routerMustCustody);
908
- break;
909
- case Protocol.V3:
910
- addV3Swap(planner, swap, this.trade.tradeType, this.options, this.payerIsUser, routerMustCustody);
911
- break;
912
- case Protocol.V4:
913
- addV4Swap(planner, swap, this.trade.tradeType, this.options, this.payerIsUser, routerMustCustody);
914
- break;
915
- case Protocol.MIXED:
916
- addMixedSwap(planner, swap, this.trade.tradeType, this.options, this.payerIsUser, routerMustCustody);
917
- break;
918
- default:
919
- throw new Error('UNSUPPORTED_TRADE_PROTOCOL');
920
- }
921
- }
922
- var minimumAmountOut = BigNumber.from(this.trade.minimumAmountOut(this.options.slippageTolerance).quotient.toString());
923
- // The router custodies for 3 reasons: to unwrap, to take a fee, and/or to do a slippage check
924
- if (routerMustCustody) {
925
- var pools = this.trade.swaps[0].route.pools;
926
- var pathOutputCurrencyAddress = getCurrencyAddress(getPathCurrency(this.trade.outputAmount.currency, pools[pools.length - 1]));
927
- // If there is a fee, that percentage is sent to the fee recipient
928
- // In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
929
- if (!!this.options.fee) {
930
- var feeBips = encodeFeeBips(this.options.fee.fee);
931
- planner.addCommand(CommandType.PAY_PORTION, [pathOutputCurrencyAddress, this.options.fee.recipient, feeBips]);
932
- // If the trade is exact output, and a fee was taken, we must adjust the amount out to be the amount after the fee
933
- // Otherwise we continue as expected with the trade's normal expected output
934
- if (this.trade.tradeType === TradeType.EXACT_OUTPUT) {
935
- minimumAmountOut = minimumAmountOut.sub(minimumAmountOut.mul(feeBips).div(10000));
936
- }
937
- }
938
- // If there is a flat fee, that absolute amount is sent to the fee recipient
939
- // In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
940
- if (!!this.options.flatFee) {
941
- var feeAmount = this.options.flatFee.amount;
942
- if (minimumAmountOut.lt(feeAmount)) throw new Error('Flat fee amount greater than minimumAmountOut');
943
- planner.addCommand(CommandType.TRANSFER, [pathOutputCurrencyAddress, this.options.flatFee.recipient, feeAmount]);
944
- // If the trade is exact output, and a fee was taken, we must adjust the amount out to be the amount after the fee
945
- // Otherwise we continue as expected with the trade's normal expected output
946
- if (this.trade.tradeType === TradeType.EXACT_OUTPUT) {
947
- minimumAmountOut = minimumAmountOut.sub(feeAmount);
948
- }
949
- }
950
- // The remaining tokens that need to be sent to the user after the fee is taken will be caught
951
- // by this if-else clause.
952
- if (this.outputRequiresUnwrap) {
953
- planner.addCommand(CommandType.UNWRAP_WETH, [this.options.recipient, minimumAmountOut]);
954
- } else if (this.outputRequiresWrap) {
955
- planner.addCommand(CommandType.WRAP_ETH, [this.options.recipient, CONTRACT_BALANCE]);
956
- } else {
957
- planner.addCommand(CommandType.SWEEP, [getCurrencyAddress(this.trade.outputAmount.currency), this.options.recipient, minimumAmountOut]);
958
- }
959
- }
960
- // for exactOutput swaps with native input or that perform an inputToken transition (wrap or unwrap)
961
- // we need to send back the change to the user
962
- if (this.trade.tradeType === TradeType.EXACT_OUTPUT || riskOfPartialFill(this.trade)) {
963
- if (this.inputRequiresWrap) {
964
- planner.addCommand(CommandType.UNWRAP_WETH, [this.options.recipient, 0]);
965
- } else if (this.inputRequiresUnwrap) {
966
- planner.addCommand(CommandType.WRAP_ETH, [this.options.recipient, CONTRACT_BALANCE]);
967
- } else if (this.options.tokenTransferMode === TokenTransferMode.ApproveProxy) {
968
- // Proxy pulled maximumAmountIn into the UR; sweep any unused input back to the user
969
- planner.addCommand(CommandType.SWEEP, [getCurrencyAddress(this.trade.inputAmount.currency), this.options.recipient, 0]);
970
- } else if (this.trade.inputAmount.currency.isNative) {
971
- // must refund extra native currency sent along for native v4 trades (no input transition)
972
- planner.addCommand(CommandType.SWEEP, [ETH_ADDRESS, this.options.recipient, 0]);
973
- }
974
- }
975
- if (this.options.safeMode) planner.addCommand(CommandType.SWEEP, [ETH_ADDRESS, this.options.recipient, 0]);
976
- };
977
- return _createClass(UniswapTrade, [{
978
- key: "isAllV4",
979
- get: function get() {
980
- var result = true;
981
- for (var _iterator2 = _createForOfIteratorHelperLoose(this.trade.swaps), _step2; !(_step2 = _iterator2()).done;) {
982
- var swap = _step2.value;
983
- result = result && swap.route.protocol == Protocol.V4;
984
- }
985
- return result;
986
- }
987
- // this.trade.swaps is an array of swaps / trades.
988
- // we are iterating over one swap (trade) at a time so length is 1
989
- // route is either v2, v3, v4, or mixed
990
- // pathInput and pathOutput are the currencies of the input and output of the route
991
- // this.trade.inputAmount is the input currency of the trade (could be different from pathInput)
992
- // this.trade.outputAmount is the output currency of the trade (could be different from pathOutput)
993
- // each route can have multiple pools
994
- }, {
995
- key: "inputRequiresWrap",
996
- get: function get() {
997
- var swap = this.trade.swaps[0];
998
- var route = swap.route;
999
- var firstPool = route.pools[0];
1000
- if (firstPool instanceof Pool) {
1001
- // If first pool is a v4 pool and input currency is native and the path input currency in the route is not native, we need to wrap.
1002
- return this.trade.inputAmount.currency.isNative && !this.trade.swaps[0].route.pathInput.isNative;
1003
- }
1004
- // If first pool is not a v4 pool and input currency is native, we need to wrap
1005
- return this.trade.inputAmount.currency.isNative;
1006
- }
1007
- }, {
1008
- key: "inputRequiresUnwrap",
1009
- get: function get() {
1010
- var swap = this.trade.swaps[0];
1011
- var route = swap.route;
1012
- var firstPool = route.pools[0];
1013
- if (firstPool instanceof Pool) {
1014
- // If the first pool is a v4 pool and input currency is not native and the path input currency is native, we need to unwrap
1015
- return !this.trade.inputAmount.currency.isNative && this.trade.swaps[0].route.pathInput.isNative;
1016
- }
1017
- // If the first pool is not a v4 pool, we don't need to unwrap.
1018
- return false;
1019
- }
1020
- }, {
1021
- key: "outputRequiresWrap",
1022
- get: function get() {
1023
- var swap = this.trade.swaps[0];
1024
- var lastRoute = swap.route;
1025
- var lastPool = lastRoute.pools[lastRoute.pools.length - 1];
1026
- // if last pool is v4:
1027
- if (lastPool instanceof Pool) {
1028
- // If output currency is not native but path currency output is native, we need to wrap
1029
- if (!this.trade.outputAmount.currency.isNative) {
1030
- if (lastRoute.pathOutput.isNative) {
1031
- // this means path output is native and we need to wrap
1032
- return true;
1033
- } else if (lastPool.currency1.equals(lastPool.currency0.wrapped) && lastRoute.pools.length > 1) {
1034
- var poolBefore = lastRoute.pools[lastRoute.pools.length - 2];
1035
- // this means last pool is eth-weth and pool before contains weth
1036
- if (poolBefore instanceof Pool && (poolBefore.currency0.equals(lastPool.currency1) || poolBefore.currency1.equals(lastPool.currency1))) {
1037
- return true;
1038
- } else if (poolBefore.token0.equals(lastPool.currency1) || poolBefore.token1.equals(lastPool.currency1)) {
1039
- // same for v2 and v3 pools
1040
- return true;
1041
- }
1042
- }
1043
- }
1044
- }
1045
- // if last pool is not v4:
1046
- // we do not need to wrap because v2 and v3 pools already require wrapped tokens
1047
- return false;
1048
- }
1049
- }, {
1050
- key: "outputRequiresUnwrap",
1051
- get: function get() {
1052
- var swap = this.trade.swaps[0];
1053
- var lastRoute = swap.route;
1054
- var lastPool = lastRoute.pools[lastRoute.pools.length - 1];
1055
- // if last pool is v4:
1056
- if (lastPool instanceof Pool) {
1057
- // If output currency is native and path currency output is not native, we need to unwrap
1058
- if (this.trade.outputAmount.currency.isNative) {
1059
- if (!this.trade.swaps[0].route.pathOutput.isNative) {
1060
- // this means path output is weth and we need to unwrap
1061
- return true;
1062
- } else if (lastRoute.pools.length > 1 && lastRoute.pools[lastRoute.pools.length - 2] instanceof Pool && lastRoute.pools[lastRoute.pools.length - 2].currency0.isNative && lastPool.currency1.equals(lastPool.currency0.wrapped)) {
1063
- // this means last pool is eth-weth and we need to unwrap
1064
- return true;
1065
- } else {
1066
- return false;
1067
- }
1068
- }
1069
- }
1070
- // else: if path output currency is native, we need to unwrap because v2 and v3 pools already require wrapped tokens
1071
- return this.trade.outputAmount.currency.isNative;
1072
- }
1073
- }, {
1074
- key: "outputRequiresTransition",
1075
- get: function get() {
1076
- return this.outputRequiresWrap || this.outputRequiresUnwrap;
1077
- }
1078
- }]);
1079
- }();
1080
- // encode a uniswap v2 swap
1081
- function addV2Swap(planner, _ref, tradeType, options, payerIsUser, routerMustCustody) {
1082
- var route = _ref.route,
1083
- inputAmount = _ref.inputAmount,
1084
- outputAmount = _ref.outputAmount;
1085
- var trade = new Trade(route, tradeType == TradeType.EXACT_INPUT ? inputAmount : outputAmount, tradeType);
1086
- if (tradeType == TradeType.EXACT_INPUT) {
1087
- planner.addCommand(CommandType.V2_SWAP_EXACT_IN, [
1088
- // if native, we have to unwrap so keep in the router for now
1089
- routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.maximumAmountIn(options.slippageTolerance).quotient.toString(),
1090
- // if router will custody funds, we do aggregated slippage check from router
1091
- routerMustCustody ? 0 : trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), route.path.map(function (token) {
1092
- return token.wrapped.address;
1093
- }), payerIsUser]);
1094
- } else if (tradeType == TradeType.EXACT_OUTPUT) {
1095
- planner.addCommand(CommandType.V2_SWAP_EXACT_OUT, [routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), route.path.map(function (token) {
1096
- return token.wrapped.address;
1097
- }), payerIsUser]);
1098
- }
1099
- }
1100
- // encode a uniswap v3 swap
1101
- function addV3Swap(planner, _ref2, tradeType, options, payerIsUser, routerMustCustody) {
1102
- var route = _ref2.route,
1103
- inputAmount = _ref2.inputAmount,
1104
- outputAmount = _ref2.outputAmount;
1105
- var trade = Trade$1.createUncheckedTrade({
1106
- route: route,
1107
- inputAmount: inputAmount,
1108
- outputAmount: outputAmount,
1109
- tradeType: tradeType
1110
- });
1111
- var path = encodeRouteToPath(route, trade.tradeType === TradeType.EXACT_OUTPUT);
1112
- if (tradeType == TradeType.EXACT_INPUT) {
1113
- planner.addCommand(CommandType.V3_SWAP_EXACT_IN, [routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), routerMustCustody ? 0 : trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), path, payerIsUser]);
1114
- } else if (tradeType == TradeType.EXACT_OUTPUT) {
1115
- planner.addCommand(CommandType.V3_SWAP_EXACT_OUT, [routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), path, payerIsUser]);
1116
- }
1117
- }
1118
- function addV4Swap(planner, _ref3, tradeType, options, payerIsUser, routerMustCustody) {
1119
- var _options$recipient;
1120
- var inputAmount = _ref3.inputAmount,
1121
- outputAmount = _ref3.outputAmount,
1122
- route = _ref3.route;
1123
- // create a deep copy of pools since v4Planner encoding tampers with array
1124
- var pools = route.pools.map(function (p) {
1125
- return p;
1126
- });
1127
- var v4Route = new Route(pools, inputAmount.currency, outputAmount.currency);
1128
- var trade = Trade$2.createUncheckedTrade({
1129
- route: v4Route,
1130
- inputAmount: inputAmount,
1131
- outputAmount: outputAmount,
1132
- tradeType: tradeType
1133
- });
1134
- var slippageToleranceOnSwap = routerMustCustody && tradeType == TradeType.EXACT_INPUT ? undefined : options.slippageTolerance;
1135
- var v4Planner = new V4Planner();
1136
- v4Planner.addTrade(trade, slippageToleranceOnSwap, options.maxHopSlippage, options.urVersion);
1137
- v4Planner.addSettle(trade.route.pathInput, payerIsUser);
1138
- // Handle split route output consistency:
1139
- // - If output is ETH and some routes output WETH: force all to output WETH, then unwrap
1140
- // - If output is WETH and some routes output ETH: force all to output ETH, then wrap
1141
- var pathOutputForTake = trade.route.pathOutput;
1142
- var lastPool = v4Route.pools[v4Route.pools.length - 1];
1143
- var ethWethPool = lastPool.currency1.equals(lastPool.currency0.wrapped);
1144
- if (ethWethPool && v4Route.pools.length > 1) {
1145
- var poolBefore = v4Route.pools[v4Route.pools.length - 2];
1146
- if (pathOutputForTake.isNative && poolBefore.currency0.isNative) {
1147
- pathOutputForTake = pathOutputForTake.wrapped;
1148
- } else if (!pathOutputForTake.isNative && (poolBefore.currency0.equals(lastPool.currency1) || poolBefore.currency1.equals(lastPool.currency1))) {
1149
- pathOutputForTake = lastPool.currency0;
1150
- }
1151
- }
1152
- v4Planner.addTake(pathOutputForTake, routerMustCustody ? ROUTER_AS_RECIPIENT : (_options$recipient = options.recipient) != null ? _options$recipient : SENDER_AS_RECIPIENT);
1153
- planner.addCommand(CommandType.V4_SWAP, [v4Planner.finalize()]);
1154
- }
1155
- // encode a mixed route swap, i.e. including both v2 and v3 pools
1156
- function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMustCustody) {
1157
- var _options$recipient2;
1158
- var route = swap.route;
1159
- var inputAmount = swap.inputAmount;
1160
- var outputAmount = swap.outputAmount;
1161
- var tradeRecipient = routerMustCustody ? ROUTER_AS_RECIPIENT : (_options$recipient2 = options.recipient) != null ? _options$recipient2 : SENDER_AS_RECIPIENT;
1162
- // single hop, so it can be reduced to plain swap logic for one protocol version
1163
- if (route.pools.length === 1) {
1164
- if (route.pools[0] instanceof Pool) {
1165
- return addV4Swap(planner, swap, tradeType, options, payerIsUser, routerMustCustody);
1166
- } else if (route.pools[0] instanceof Pool$1) {
1167
- return addV3Swap(planner, swap, tradeType, options, payerIsUser, routerMustCustody);
1168
- } else if (route.pools[0] instanceof Pair) {
1169
- return addV2Swap(planner, swap, tradeType, options, payerIsUser, routerMustCustody);
1170
- } else {
1171
- throw new Error('Invalid route type');
1172
- }
1173
- }
1174
- var trade = MixedRouteTrade.createUncheckedTrade({
1175
- route: route,
1176
- inputAmount: inputAmount,
1177
- outputAmount: outputAmount,
1178
- tradeType: tradeType
1179
- });
1180
- var amountIn = trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient.toString();
1181
- var amountOut = routerMustCustody ? 0 : trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient.toString();
1182
- // logic from
1183
- // https://github.com/Uniswap/router-sdk/blob/d8eed164e6c79519983844ca8b6a3fc24ebcb8f8/src/swapRouter.ts#L276
1184
- var sections = partitionMixedRouteByProtocol(route);
1185
- var isLastSectionInRoute = function isLastSectionInRoute(i) {
1186
- return i === sections.length - 1;
1187
- };
1188
- var inputToken = route.pathInput;
1189
- for (var i = 0; i < sections.length; i++) {
1190
- var section = sections[i];
1191
- var routePool = section[0];
1192
- var outputToken = getOutputOfPools(section, inputToken);
1193
- var subRoute = new MixedRoute(new MixedRouteSDK([].concat(section), inputToken, outputToken));
1194
- var nextInputToken = void 0;
1195
- var swapRecipient = void 0;
1196
- if (isLastSectionInRoute(i)) {
1197
- nextInputToken = outputToken;
1198
- swapRecipient = tradeRecipient;
1199
- } else {
1200
- var nextPool = sections[i + 1][0];
1201
- nextInputToken = getPathCurrency(outputToken, nextPool);
1202
- var v2PoolIsSwapRecipient = nextPool instanceof Pair && outputToken.equals(nextInputToken);
1203
- swapRecipient = v2PoolIsSwapRecipient ? nextPool.liquidityToken.address : ROUTER_AS_RECIPIENT;
1204
- }
1205
- if (routePool instanceof Pool) {
1206
- var v4Planner = new V4Planner();
1207
- var v4SubRoute = new Route(section, subRoute.input, subRoute.output);
1208
- v4Planner.addSettle(inputToken, payerIsUser && i === 0, i == 0 ? amountIn : CONTRACT_BALANCE);
1209
- v4Planner.addAction(Actions.SWAP_EXACT_IN, [{
1210
- currencyIn: inputToken.isNative ? ETH_ADDRESS : inputToken.address,
1211
- path: encodeRouteToPath$1(v4SubRoute),
1212
- maxHopSlippage: options.maxHopSlippage || [],
1213
- amountIn: 0,
1214
- amountOutMinimum: !isLastSectionInRoute(i) ? 0 : amountOut
1215
- }], options.urVersion);
1216
- // Handle split route output consistency for V4 sections in mixed routes
1217
- var outputTokenForTake = outputToken;
1218
- if (isLastSectionInRoute(i)) {
1219
- var lastPool = route.pools[route.pools.length - 1];
1220
- var v4Pool = lastPool instanceof Pool;
1221
- var ethWethPool = v4Pool ? lastPool.currency1.equals(lastPool.currency0.wrapped) : false;
1222
- var poolBefore = route.pools[route.pools.length - 2];
1223
- if (ethWethPool) {
1224
- if (outputToken.isNative && poolBefore.token0.isNative) {
1225
- outputTokenForTake = outputToken.wrapped;
1226
- } else if (!outputToken.isNative && (poolBefore.token0.equals(lastPool.token1) || poolBefore.token1.equals(lastPool.token1))) {
1227
- outputTokenForTake = lastPool.token0;
1228
- }
1229
- }
1230
- }
1231
- v4Planner.addTake(outputTokenForTake, swapRecipient);
1232
- planner.addCommand(CommandType.V4_SWAP, [v4Planner.finalize()]);
1233
- } else if (routePool instanceof Pool$1) {
1234
- planner.addCommand(CommandType.V3_SWAP_EXACT_IN, [swapRecipient, i == 0 ? amountIn : CONTRACT_BALANCE, !isLastSectionInRoute(i) ? 0 : amountOut, encodeMixedRouteToPath(subRoute), payerIsUser && i === 0]);
1235
- } else if (routePool instanceof Pair) {
1236
- planner.addCommand(CommandType.V2_SWAP_EXACT_IN, [swapRecipient, i === 0 ? amountIn : CONTRACT_BALANCE, !isLastSectionInRoute(i) ? 0 : amountOut, subRoute.path.map(function (token) {
1237
- return token.wrapped.address;
1238
- }), payerIsUser && i === 0]);
1239
- } else {
1240
- throw new Error('Unexpected Pool Type');
1241
- }
1242
- // perform a token transition (wrap/unwrap if necessary)
1243
- if (!isLastSectionInRoute(i)) {
1244
- if (outputToken.isNative && !nextInputToken.isNative) {
1245
- planner.addCommand(CommandType.WRAP_ETH, [ROUTER_AS_RECIPIENT, CONTRACT_BALANCE]);
1246
- } else if (!outputToken.isNative && nextInputToken.isNative) {
1247
- planner.addCommand(CommandType.UNWRAP_WETH, [ROUTER_AS_RECIPIENT, 0]);
1248
- }
1249
- }
1250
- inputToken = nextInputToken;
1251
- }
1252
- }
1253
- // if price impact is very high, there's a chance of hitting max/min prices resulting in a partial fill of the swap
1254
- function riskOfPartialFill(trade) {
1255
- return trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD);
1256
- }
1257
- function hasFeeOption(swapOptions) {
1258
- return !!swapOptions.fee || !!swapOptions.flatFee;
1259
- }
1260
-
1261
- var SIGNATURE_LENGTH = 65;
1262
- var EIP_2098_SIGNATURE_LENGTH = 64;
1263
- function encodePermit(planner, permit2) {
1264
- var signature = permit2.signature;
1265
- var length = ethers.utils.arrayify(permit2.signature).length;
1266
- // signature data provided for EIP-1271 may have length different from ECDSA signature
1267
- if (length === SIGNATURE_LENGTH || length === EIP_2098_SIGNATURE_LENGTH) {
1268
- // sanitizes signature to cover edge cases of malformed EIP-2098 sigs and v used as recovery id
1269
- signature = ethers.utils.joinSignature(ethers.utils.splitSignature(permit2.signature));
1270
- }
1271
- planner.addCommand(CommandType.PERMIT2_PERMIT, [permit2, signature]);
1272
- }
1273
- function encodeV3PositionPermit(planner, permit, tokenId) {
1274
- var calldata = NonfungiblePositionManager.INTERFACE.encodeFunctionData('permit', [validateAndParseAddress(permit.spender), tokenId, permit.deadline, permit.v, permit.r, permit.s]);
1275
- planner.addCommand(CommandType.V3_POSITION_MANAGER_PERMIT, [calldata]);
1276
- }
1277
- // Handles the encoding of commands needed to gather input tokens for a trade
1278
- // Approval: The router approving another address to take tokens.
1279
- // note: Only seaport and sudoswap support this action. Approvals are left open.
1280
- // Permit: A Permit2 signature-based Permit to allow the router to access a user's tokens
1281
- // Transfer: A Permit2 TransferFrom of tokens from a user to either the router or another address
1282
- function encodeInputTokenOptions(planner, options) {
1283
- // first ensure that all tokens provided for encoding are the same
1284
- if (!!options.permit2TransferFrom && !!options.permit2Permit) !(options.permit2TransferFrom.token === options.permit2Permit.details.token) ? process.env.NODE_ENV !== "production" ? invariant(false, "inconsistent token") : invariant(false) : void 0;
1285
- // if this order has a options.permit2Permit, encode it
1286
- if (!!options.permit2Permit) {
1287
- encodePermit(planner, options.permit2Permit);
1288
- }
1289
- if (!!options.permit2TransferFrom) {
1290
- planner.addCommand(CommandType.PERMIT2_TRANSFER_FROM, [options.permit2TransferFrom.token, options.permit2TransferFrom.recipient ? options.permit2TransferFrom.recipient : ROUTER_AS_RECIPIENT, options.permit2TransferFrom.amount]);
1291
- }
1292
- }
1293
-
1294
- var EIP712_DOMAIN_NAME = 'UniversalRouter';
1295
- var EIP712_DOMAIN_VERSION = '2';
1296
- var EXECUTE_SIGNED_TYPES = {
1297
- ExecuteSigned: [{
1298
- name: 'commands',
1299
- type: 'bytes'
1300
- }, {
1301
- name: 'inputs',
1302
- type: 'bytes[]'
1303
- }, {
1304
- name: 'intent',
1305
- type: 'bytes32'
1306
- }, {
1307
- name: 'data',
1308
- type: 'bytes32'
1309
- }, {
1310
- name: 'sender',
1311
- type: 'address'
1312
- }, {
1313
- name: 'nonce',
1314
- type: 'bytes32'
1315
- }, {
1316
- name: 'deadline',
1317
- type: 'uint256'
1318
- }]
1319
- };
1320
- /**
1321
- * Generate EIP712 domain for Universal Router
1322
- */
1323
- function getUniversalRouterDomain(chainId, verifyingContract) {
1324
- return {
1325
- name: EIP712_DOMAIN_NAME,
1326
- version: EIP712_DOMAIN_VERSION,
1327
- chainId: chainId,
1328
- verifyingContract: verifyingContract
1329
- };
1330
- }
1331
- /**
1332
- * Generate a random nonce for signed execution
1333
- * Uses ethers.utils.randomBytes for secure randomness
1334
- */
1335
- function generateNonce() {
1336
- var randomBytes = ethers.utils.randomBytes(32);
1337
- return ethers.utils.hexlify(randomBytes);
1338
- }
1339
- /**
1340
- * Sentinel value to skip nonce checking (allows signature replay)
1341
- */
1342
- var NONCE_SKIP_CHECK = '0x' + /*#__PURE__*/'f'.repeat(64); // bytes32(type(uint256).max)
1343
-
1344
- var _UR_VERSION_MAP;
1345
- function isMint(options) {
1346
- return Object.keys(options).some(function (k) {
1347
- return k === 'recipient';
1348
- });
1349
- }
1350
- var UR_VERSION_MAP = (_UR_VERSION_MAP = {}, _UR_VERSION_MAP[URVersion.V2_0] = UniversalRouterVersion.V2_0, _UR_VERSION_MAP[URVersion.V2_1] = UniversalRouterVersion.V2_1, _UR_VERSION_MAP);
1351
- function toUniversalRouterVersion(urVersion) {
1352
- if (urVersion === undefined) return undefined;
1353
- var mapped = UR_VERSION_MAP[urVersion];
1354
- if (!mapped) throw new Error("Unsupported URVersion: " + urVersion);
1355
- return mapped;
1356
- }
1357
- var SwapRouter = /*#__PURE__*/function () {
1358
- function SwapRouter() {}
1359
- SwapRouter.swapCallParameters = function swapCallParameters(trades, options, bridgeOptions // Optional bridge parameters
1360
- ) {
1361
- // TODO: use permit if signature included in swapOptions
1362
- var planner = new RoutePlanner();
1363
- var trade = new UniswapTrade(trades, options);
1364
- var inputCurrency = trade.trade.inputAmount.currency;
1365
- if (options.tokenTransferMode === TokenTransferMode.ApproveProxy) {
1366
- !!inputCurrency.isNative ? process.env.NODE_ENV !== "production" ? invariant(false, 'PROXY_NATIVE_INPUT: SwapProxy only supports ERC20 input') : invariant(false) : void 0;
1367
- !!!options.chainId ? process.env.NODE_ENV !== "production" ? invariant(false, 'PROXY_MISSING_CHAIN_ID: chainId required when tokenTransferMode is ApproveProxy') : invariant(false) : void 0;
1368
- !!options.inputTokenPermit ? process.env.NODE_ENV !== "production" ? invariant(false, 'PROXY_PERMIT_CONFLICT: Permit2 not used with SwapProxy') : invariant(false) : void 0;
1369
- } else {
1370
- !!(inputCurrency.isNative && !!options.inputTokenPermit) ? process.env.NODE_ENV !== "production" ? invariant(false, 'NATIVE_INPUT_PERMIT') : invariant(false) : void 0;
1371
- if (options.inputTokenPermit) {
1372
- encodePermit(planner, options.inputTokenPermit);
1373
- }
1374
- }
1375
- var nativeCurrencyValue = inputCurrency.isNative ? BigNumber.from(trade.trade.maximumAmountIn(options.slippageTolerance).quotient.toString()) : BigNumber.from(0);
1376
- trade.encode(planner, {
1377
- allowRevert: false
1378
- });
1379
- // Add bridge commands if provided
1380
- if (bridgeOptions) {
1381
- for (var _iterator = _createForOfIteratorHelperLoose(bridgeOptions), _step; !(_step = _iterator()).done;) {
1382
- var bridge = _step.value;
1383
- planner.addAcrossBridge(bridge);
1384
- }
1385
- }
1386
- if (options.tokenTransferMode === TokenTransferMode.ApproveProxy) {
1387
- return SwapRouter.encodeProxyPlan(planner, trade, options);
1388
- }
1389
- return SwapRouter.encodePlan(planner, nativeCurrencyValue, {
1390
- deadline: options.deadlineOrPreviousBlockhash ? BigNumber.from(options.deadlineOrPreviousBlockhash) : undefined
1391
- });
1392
- }
1393
- /**
1394
- * Generate EIP712 payload for signed execution (no signing performed)
1395
- * Decodes existing execute() calldata and prepares it for signing
1396
- *
1397
- * @param calldata The calldata from swapCallParameters() or similar
1398
- * @param signedOptions Options for signed execution (intent, data, sender, nonce)
1399
- * @param deadline The deadline timestamp
1400
- * @param chainId The chain ID
1401
- * @param routerAddress The Universal Router contract address
1402
- * @returns EIP712 payload ready to be signed externally
1403
- */;
1404
- SwapRouter.getExecuteSignedPayload = function getExecuteSignedPayload(calldata, signedOptions, deadline, chainId, routerAddress) {
1405
- // Decode the execute() calldata to extract commands and inputs
1406
- // Try to decode with deadline first, then without
1407
- var decoded;
1408
- var commands;
1409
- var inputs;
1410
- try {
1411
- decoded = SwapRouter.INTERFACE.decodeFunctionData('execute(bytes,bytes[],uint256)', calldata);
1412
- commands = decoded.commands;
1413
- inputs = decoded.inputs;
1414
- } catch (e) {
1415
- // Try without deadline
1416
- decoded = SwapRouter.INTERFACE.decodeFunctionData('execute(bytes,bytes[])', calldata);
1417
- commands = decoded.commands;
1418
- inputs = decoded.inputs;
1419
- }
1420
- // Use provided nonce or generate random one
1421
- var nonce = signedOptions.nonce || generateNonce();
1422
- // sender is provided directly (address(0) = skip verification)
1423
- var sender = signedOptions.sender;
1424
- var domain = getUniversalRouterDomain(chainId, routerAddress);
1425
- var intent = signedOptions.intent;
1426
- var data = signedOptions.data;
1427
- var deadlineStr = BigNumber.from(deadline).toString();
1428
- var value = {
1429
- commands: commands,
1430
- inputs: inputs,
1431
- intent: intent,
1432
- data: data,
1433
- sender: sender,
1434
- nonce: nonce,
1435
- deadline: deadlineStr
1436
- };
1437
- return {
1438
- domain: domain,
1439
- types: EXECUTE_SIGNED_TYPES,
1440
- value: value
1441
- };
1442
- }
1443
- /**
1444
- * Encode executeSigned() call with signature
1445
- *
1446
- * @param calldata The original calldata from swapCallParameters()
1447
- * @param signature The signature obtained from external signing
1448
- * @param signedOptions The same options used in getExecuteSignedPayload()
1449
- * @param deadline The deadline timestamp
1450
- * @param nativeCurrencyValue The native currency value (ETH) to send
1451
- * @returns Method parameters for executeSigned()
1452
- */;
1453
- SwapRouter.encodeExecuteSigned = function encodeExecuteSigned(calldata, signature, signedOptions, deadline, nativeCurrencyValue) {
1454
- if (nativeCurrencyValue === void 0) {
1455
- nativeCurrencyValue = BigNumber.from(0);
1456
- }
1457
- // Decode the execute() calldata to extract commands and inputs
1458
- // Try to decode with deadline first, then without
1459
- var decoded;
1460
- var commands;
1461
- var inputs;
1462
- try {
1463
- decoded = SwapRouter.INTERFACE.decodeFunctionData('execute(bytes,bytes[],uint256)', calldata);
1464
- commands = decoded.commands;
1465
- inputs = decoded.inputs;
1466
- } catch (e) {
1467
- // Try without deadline
1468
- decoded = SwapRouter.INTERFACE.decodeFunctionData('execute(bytes,bytes[])', calldata);
1469
- commands = decoded.commands;
1470
- inputs = decoded.inputs;
1471
- }
1472
- // Use provided nonce (must match what was signed)
1473
- // Nonce must match what was signed - require it to be provided
1474
- if (!signedOptions.nonce) {
1475
- throw new Error('Nonce is required for encodeExecuteSigned - use the nonce from getExecuteSignedPayload');
1476
- }
1477
- var nonce = signedOptions.nonce;
1478
- // Determine verifySender based on sender address
1479
- var verifySender = signedOptions.sender !== '0x0000000000000000000000000000000000000000';
1480
- // Encode executeSigned function call using the Universal Router v2.1 ABI
1481
- var signedCalldata = SwapRouter.INTERFACE.encodeFunctionData('executeSigned', [commands, inputs, signedOptions.intent, signedOptions.data, verifySender, nonce, signature, deadline]);
1482
- return {
1483
- calldata: signedCalldata,
1484
- value: nativeCurrencyValue.toHexString()
1485
- };
1486
- }
1487
- /**
1488
- * Builds the call parameters for a migration from a V3 position to a V4 position.
1489
- * Some requirements of the parameters:
1490
- * - v3RemoveLiquidityOptions.collectOptions.recipient must equal v4PositionManager
1491
- * - v3RemoveLiquidityOptions.liquidityPercentage must be 100%
1492
- * - input pool and output pool must have the same tokens
1493
- * - V3 NFT must be approved, or valid inputV3NFTPermit must be provided with UR as spender
1494
- */;
1495
- SwapRouter.migrateV3ToV4CallParameters = function migrateV3ToV4CallParameters(options, positionManagerOverride) {
1496
- var v4Pool = options.outputPosition.pool;
1497
- var v3Token0 = options.inputPosition.pool.token0;
1498
- var v3Token1 = options.inputPosition.pool.token1;
1499
- var v4PositionManagerAddress = positionManagerOverride != null ? positionManagerOverride : CHAIN_TO_ADDRESSES_MAP[v4Pool.chainId].v4PositionManagerAddress;
1500
- // owner of the v3 nft must be the receiver of the v4 nft
1501
- // validate the parameters
1502
- if (v4Pool.currency0.isNative) {
1503
- !(v4Pool.currency0.wrapped.equals(v3Token0) && v4Pool.currency1.equals(v3Token1) || v4Pool.currency0.wrapped.equals(v3Token1) && v4Pool.currency1.equals(v3Token0)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN_MISMATCH') : invariant(false) : void 0;
1504
- } else {
1505
- !(v3Token0 === v4Pool.token0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN0_MISMATCH') : invariant(false) : void 0;
1506
- !(v3Token1 === v4Pool.token1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN1_MISMATCH') : invariant(false) : void 0;
1507
- }
1508
- !options.v3RemoveLiquidityOptions.liquidityPercentage.equalTo(new Percent(100, 100)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'FULL_REMOVAL_REQUIRED') : invariant(false) : void 0;
1509
- !(options.v3RemoveLiquidityOptions.burnToken == true) ? process.env.NODE_ENV !== "production" ? invariant(false, 'BURN_TOKEN_REQUIRED') : invariant(false) : void 0;
1510
- !(options.v3RemoveLiquidityOptions.collectOptions.recipient === v4PositionManagerAddress) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RECIPIENT_NOT_POSITION_MANAGER') : invariant(false) : void 0;
1511
- !isMint(options.v4AddLiquidityOptions) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MINT_REQUIRED') : invariant(false) : void 0;
1512
- !options.v4AddLiquidityOptions.migrate ? process.env.NODE_ENV !== "production" ? invariant(false, 'MIGRATE_REQUIRED') : invariant(false) : void 0;
1513
- var planner = new RoutePlanner();
1514
- // to prevent reentrancy by the pool hook, we initialize the v4 pool before moving funds
1515
- if (options.v4AddLiquidityOptions.createPool) {
1516
- var poolKey = Pool.getPoolKey(v4Pool.currency0, v4Pool.currency1, v4Pool.fee, v4Pool.tickSpacing, v4Pool.hooks);
1517
- planner.addCommand(CommandType.V4_INITIALIZE_POOL, [poolKey, v4Pool.sqrtRatioX96.toString()]);
1518
- // remove createPool setting, so that it doesnt get encoded again later
1519
- delete options.v4AddLiquidityOptions.createPool;
1520
- }
1521
- // add position permit to the universal router planner
1522
- if (options.v3RemoveLiquidityOptions.permit) {
1523
- // permit spender should be UR
1524
- var universalRouterAddress = UNIVERSAL_ROUTER_ADDRESS(UniversalRouterVersion.V2_0, options.inputPosition.pool.chainId);
1525
- !(universalRouterAddress == options.v3RemoveLiquidityOptions.permit.spender) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_SPENDER') : invariant(false) : void 0;
1526
- // don't need to transfer it because v3posm uses isApprovedOrOwner()
1527
- encodeV3PositionPermit(planner, options.v3RemoveLiquidityOptions.permit, options.v3RemoveLiquidityOptions.tokenId);
1528
- // remove permit so that multicall doesnt add it again
1529
- delete options.v3RemoveLiquidityOptions.permit;
1530
- }
1531
- // encode v3 withdraw
1532
- var v3RemoveParams = NonfungiblePositionManager.removeCallParameters(options.inputPosition, options.v3RemoveLiquidityOptions);
1533
- var v3Calls = Multicall.decodeMulticall(v3RemoveParams.calldata);
1534
- for (var _iterator2 = _createForOfIteratorHelperLoose(v3Calls), _step2; !(_step2 = _iterator2()).done;) {
1535
- var v3Call = _step2.value;
1536
- // slice selector - 0x + 4 bytes = 10 characters
1537
- var _selector = v3Call.slice(0, 10);
1538
- !(_selector == NonfungiblePositionManager.INTERFACE.getSighash('collect') || _selector == NonfungiblePositionManager.INTERFACE.getSighash('decreaseLiquidity') || _selector == NonfungiblePositionManager.INTERFACE.getSighash('burn')) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_V3_CALL: ' + _selector) : invariant(false) : void 0;
1539
- planner.addCommand(CommandType.V3_POSITION_MANAGER_CALL, [v3Call]);
1540
- }
1541
- // encode v4 mint
1542
- var v4AddParams = V4PositionManager.addCallParameters(options.outputPosition, options.v4AddLiquidityOptions);
1543
- // only modifyLiquidities can be called by the UniversalRouter
1544
- var selector = v4AddParams.calldata.slice(0, 10);
1545
- !(selector == V4PositionManager.INTERFACE.getSighash('modifyLiquidities')) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_V4_CALL: ' + selector) : invariant(false) : void 0;
1546
- planner.addCommand(CommandType.V4_POSITION_MANAGER_CALL, [v4AddParams.calldata]);
1547
- return SwapRouter.encodePlan(planner, BigNumber.from(0), {
1548
- deadline: BigNumber.from(options.v4AddLiquidityOptions.deadline)
1549
- });
1550
- }
1551
- /**
1552
- * Encodes a planned route into a method name and parameters for the Router contract.
1553
- * @param planner the planned route
1554
- * @param nativeCurrencyValue the native currency value of the planned route
1555
- * @param config the router config
1556
- */;
1557
- SwapRouter.encodePlan = function encodePlan(planner, nativeCurrencyValue, config) {
1558
- if (config === void 0) {
1559
- config = {};
1560
- }
1561
- var commands = planner.commands,
1562
- inputs = planner.inputs;
1563
- var functionSignature = !!config.deadline ? 'execute(bytes,bytes[],uint256)' : 'execute(bytes,bytes[])';
1564
- var parameters = !!config.deadline ? [commands, inputs, config.deadline] : [commands, inputs];
1565
- var calldata = SwapRouter.INTERFACE.encodeFunctionData(functionSignature, parameters);
1566
- return {
1567
- calldata: calldata,
1568
- value: nativeCurrencyValue.toHexString()
1569
- };
1570
- }
1571
- /**
1572
- * Encodes a planned route into calldata targeting the SwapProxy contract.
1573
- * The proxy pulls ERC20 tokens from the user into the UR, then executes commands.
1574
- */;
1575
- SwapRouter.encodeProxyPlan = function encodeProxyPlan(planner, trade, options) {
1576
- var _toUniversalRouterVer;
1577
- var commands = planner.commands,
1578
- inputs = planner.inputs;
1579
- var urVersion = (_toUniversalRouterVer = toUniversalRouterVersion(options.urVersion)) != null ? _toUniversalRouterVer : UniversalRouterVersion.V2_0;
1580
- var routerAddress = UNIVERSAL_ROUTER_ADDRESS(urVersion, options.chainId);
1581
- var inputToken = trade.trade.inputAmount.currency.address;
1582
- var inputAmount = BigNumber.from(trade.trade.maximumAmountIn(options.slippageTolerance).quotient.toString());
1583
- var deadline = options.deadlineOrPreviousBlockhash ? BigNumber.from(options.deadlineOrPreviousBlockhash) : BigNumber.from(Math.floor(Date.now() / 1000) + 1800); // 30 min default
1584
- var calldata = SwapRouter.PROXY_INTERFACE.encodeFunctionData('execute', [routerAddress, inputToken, inputAmount, commands, inputs, deadline]);
1585
- return {
1586
- calldata: calldata,
1587
- value: BigNumber.from(0).toHexString()
1588
- };
1589
- };
1590
- return SwapRouter;
1591
- }();
1592
- SwapRouter.INTERFACE = /*#__PURE__*/new Interface(UniversalRouter.abi);
1593
- SwapRouter.PROXY_INTERFACE = /*#__PURE__*/new Interface(['function execute(address router, address token, uint256 amount, bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external']);
1594
-
1595
- var UnwrapWETH = /*#__PURE__*/function () {
1596
- function UnwrapWETH(amount, chainId, permit2) {
1597
- this.tradeType = RouterActionType.UnwrapWETH;
1598
- this.wethAddress = WETH_ADDRESS(chainId);
1599
- this.amount = amount;
1600
- if (!!permit2) {
1601
- !(permit2.details.token.toLowerCase() === this.wethAddress.toLowerCase()) ? process.env.NODE_ENV !== "production" ? invariant(false, "must be permitting WETH address: " + this.wethAddress) : invariant(false) : void 0;
1602
- !(permit2.details.amount >= amount) ? process.env.NODE_ENV !== "production" ? invariant(false, "Did not permit enough WETH for unwrapWETH transaction") : invariant(false) : void 0;
1603
- this.permit2Data = permit2;
1604
- }
1605
- }
1606
- var _proto = UnwrapWETH.prototype;
1607
- _proto.encode = function encode(planner, _) {
1608
- encodeInputTokenOptions(planner, {
1609
- permit2Permit: this.permit2Data,
1610
- permit2TransferFrom: {
1611
- token: this.wethAddress,
1612
- amount: this.amount.toString()
1613
- }
1614
- });
1615
- planner.addCommand(CommandType.UNWRAP_WETH, [ROUTER_AS_RECIPIENT, this.amount]);
1616
- };
1617
- return UnwrapWETH;
1618
- }();
1619
-
1620
- var PoolType;
1621
- (function (PoolType) {
1622
- PoolType["V2Pool"] = "v2-pool";
1623
- PoolType["V3Pool"] = "v3-pool";
1624
- PoolType["V4Pool"] = "v4-pool";
1625
- })(PoolType || (PoolType = {}));
1626
- var isNativeCurrency = function isNativeCurrency(address) {
1627
- return address.toLowerCase() === ETH_ADDRESS.toLowerCase() || address.toLowerCase() === E_ETH_ADDRESS.toLowerCase();
1628
- };
1629
- // Helper class to convert routing-specific quote entities to RouterTrade entities
1630
- // the returned RouterTrade can then be used to build the UniswapTrade entity in this package
1631
- var RouterTradeAdapter = /*#__PURE__*/function () {
1632
- function RouterTradeAdapter() {}
1633
- // Generate a RouterTrade using fields from a classic quote response
1634
- RouterTradeAdapter.fromClassicQuote = function fromClassicQuote(quote) {
1635
- var route = quote.route,
1636
- tokenIn = quote.tokenIn,
1637
- tokenOut = quote.tokenOut;
1638
- if (!route) throw new Error('Expected route to be present');
1639
- if (!route.length) throw new Error('Expected there to be at least one route');
1640
- if (route.some(function (r) {
1641
- return !r.length;
1642
- })) throw new Error('Expected all routes to have at least one pool');
1643
- var firstRoute = route[0];
1644
- var tokenInData = firstRoute[0].tokenIn;
1645
- var tokenOutData = firstRoute[firstRoute.length - 1].tokenOut;
1646
- if (!tokenInData || !tokenOutData) throw new Error('Expected both tokenIn and tokenOut to be present');
1647
- if (tokenInData.chainId !== tokenOutData.chainId) throw new Error('Expected tokenIn and tokenOut to be have same chainId');
1648
- var parsedCurrencyIn = RouterTradeAdapter.toCurrency(isNativeCurrency(tokenIn), tokenInData);
1649
- var parsedCurrencyOut = RouterTradeAdapter.toCurrency(isNativeCurrency(tokenOut), tokenOutData);
1650
- var typedRoutes = route.map(function (subRoute) {
1651
- var rawAmountIn = subRoute[0].amountIn;
1652
- var rawAmountOut = subRoute[subRoute.length - 1].amountOut;
1653
- if (!rawAmountIn || !rawAmountOut) {
1654
- throw new Error('Expected both raw amountIn and raw amountOut to be present');
1655
- }
1656
- var inputAmount = CurrencyAmount.fromRawAmount(parsedCurrencyIn, rawAmountIn);
1657
- var outputAmount = CurrencyAmount.fromRawAmount(parsedCurrencyOut, rawAmountOut);
1658
- var isOnlyV2 = RouterTradeAdapter.isVersionedRoute(PoolType.V2Pool, subRoute);
1659
- var isOnlyV3 = RouterTradeAdapter.isVersionedRoute(PoolType.V3Pool, subRoute);
1660
- var isOnlyV4 = RouterTradeAdapter.isVersionedRoute(PoolType.V4Pool, subRoute);
1661
- return {
1662
- routev4: isOnlyV4 ? new Route(subRoute.map(RouterTradeAdapter.toV4Pool), parsedCurrencyIn, parsedCurrencyOut) : null,
1663
- routev3: isOnlyV3 ? new Route$1(subRoute.map(RouterTradeAdapter.toV3Pool), parsedCurrencyIn, parsedCurrencyOut) : null,
1664
- routev2: isOnlyV2 ? new Route$2(subRoute.map(RouterTradeAdapter.toPair), parsedCurrencyIn, parsedCurrencyOut) : null,
1665
- mixedRoute: !isOnlyV4 && !isOnlyV3 && !isOnlyV2 ? new MixedRouteSDK(subRoute.map(RouterTradeAdapter.toPoolOrPair), parsedCurrencyIn, parsedCurrencyOut) : null,
1666
- inputAmount: inputAmount,
1667
- outputAmount: outputAmount
1668
- };
1669
- });
1670
- return new Trade$3({
1671
- v2Routes: typedRoutes.filter(function (route) {
1672
- return route.routev2;
1673
- }).map(function (route) {
1674
- return {
1675
- routev2: route.routev2,
1676
- inputAmount: route.inputAmount,
1677
- outputAmount: route.outputAmount
1678
- };
1679
- }),
1680
- v3Routes: typedRoutes.filter(function (route) {
1681
- return route.routev3;
1682
- }).map(function (route) {
1683
- return {
1684
- routev3: route.routev3,
1685
- inputAmount: route.inputAmount,
1686
- outputAmount: route.outputAmount
1687
- };
1688
- }),
1689
- v4Routes: typedRoutes.filter(function (route) {
1690
- return route.routev4;
1691
- }).map(function (route) {
1692
- return {
1693
- routev4: route.routev4,
1694
- inputAmount: route.inputAmount,
1695
- outputAmount: route.outputAmount
1696
- };
1697
- }),
1698
- mixedRoutes: typedRoutes.filter(function (route) {
1699
- return route.mixedRoute;
1700
- }).map(function (route) {
1701
- return {
1702
- mixedRoute: route.mixedRoute,
1703
- inputAmount: route.inputAmount,
1704
- outputAmount: route.outputAmount
1705
- };
1706
- }),
1707
- tradeType: quote.tradeType
1708
- });
1709
- };
1710
- RouterTradeAdapter.toCurrency = function toCurrency(isNative, token) {
1711
- if (isNative) {
1712
- return Ether.onChain(token.chainId);
1713
- }
1714
- return this.toToken(token);
1715
- };
1716
- RouterTradeAdapter.toToken = function toToken(token) {
1717
- var chainId = token.chainId,
1718
- address = token.address,
1719
- decimals = token.decimals,
1720
- symbol = token.symbol,
1721
- buyFeeBps = token.buyFeeBps,
1722
- sellFeeBps = token.sellFeeBps;
1723
- return new Token(chainId, address, parseInt(decimals.toString()), symbol, /* name */undefined, false, buyFeeBps ? BigNumber.from(buyFeeBps) : undefined, sellFeeBps ? BigNumber.from(sellFeeBps) : undefined);
1724
- };
1725
- RouterTradeAdapter.toV3Pool = function toV3Pool(_ref) {
1726
- var fee = _ref.fee,
1727
- sqrtRatioX96 = _ref.sqrtRatioX96,
1728
- liquidity = _ref.liquidity,
1729
- tickCurrent = _ref.tickCurrent,
1730
- tokenIn = _ref.tokenIn,
1731
- tokenOut = _ref.tokenOut;
1732
- return new Pool$1(RouterTradeAdapter.toToken(tokenIn), RouterTradeAdapter.toToken(tokenOut), parseInt(fee), sqrtRatioX96, liquidity, parseInt(tickCurrent));
1733
- };
1734
- RouterTradeAdapter.toV4Pool = function toV4Pool(pool) {
1735
- var parsedCurrencyIn = RouterTradeAdapter.toCurrency(isNativeCurrency(pool.tokenIn.address), pool.tokenIn);
1736
- var parsedCurrencyOut = RouterTradeAdapter.toCurrency(isNativeCurrency(pool.tokenOut.address), pool.tokenOut);
1737
- return new Pool(parsedCurrencyIn, parsedCurrencyOut, parseInt(pool.fee), parseInt(pool.tickSpacing), pool.hooks, pool.sqrtRatioX96, pool.liquidity, parseInt(pool.tickCurrent));
1738
- };
1739
- RouterTradeAdapter.isVersionedRoute = function isVersionedRoute(type, route) {
1740
- return route.every(function (pool) {
1741
- return pool.type === type;
1742
- });
1743
- };
1744
- return RouterTradeAdapter;
1745
- }();
1746
- RouterTradeAdapter.toPoolOrPair = function (pool) {
1747
- switch (pool.type) {
1748
- case PoolType.V4Pool:
1749
- return RouterTradeAdapter.toV4Pool(pool);
1750
- case PoolType.V3Pool:
1751
- return RouterTradeAdapter.toV3Pool(pool);
1752
- case PoolType.V2Pool:
1753
- return RouterTradeAdapter.toPair(pool);
1754
- default:
1755
- throw new Error('Invalid pool type');
1756
- }
1757
- };
1758
- RouterTradeAdapter.toPair = function (_ref2) {
1759
- var reserve0 = _ref2.reserve0,
1760
- reserve1 = _ref2.reserve1;
1761
- return new Pair(CurrencyAmount.fromRawAmount(RouterTradeAdapter.toToken(reserve0.token), reserve0.quotient), CurrencyAmount.fromRawAmount(RouterTradeAdapter.toToken(reserve1.token), reserve1.quotient));
1762
- };
1763
-
1764
- // Parses UniversalRouter V2 commands
1765
- var CommandParser = /*#__PURE__*/function () {
1766
- function CommandParser() {}
1767
- CommandParser.parseCalldata = function parseCalldata(calldata) {
1768
- var genericParser = new GenericCommandParser(COMMAND_DEFINITION);
1769
- var txDescription = CommandParser.INTERFACE.parseTransaction({
1770
- data: calldata
1771
- });
1772
- var _txDescription$args = txDescription.args,
1773
- commands = _txDescription$args.commands,
1774
- inputs = _txDescription$args.inputs;
1775
- return genericParser.parse(commands, inputs);
1776
- };
1777
- return CommandParser;
1778
- }();
1779
- CommandParser.INTERFACE = /*#__PURE__*/new Interface(UniversalRouter.abi);
1780
- // Parses commands based on given command definition
1781
- var GenericCommandParser = /*#__PURE__*/function () {
1782
- function GenericCommandParser(commandDefinition) {
1783
- this.commandDefinition = commandDefinition;
1784
- }
1785
- var _proto = GenericCommandParser.prototype;
1786
- _proto.parse = function parse(commands, inputs) {
1787
- var _this = this;
1788
- var commandTypes = GenericCommandParser.getCommands(commands);
1789
- return {
1790
- commands: commandTypes.map(function (commandType, i) {
1791
- var commandDef = _this.commandDefinition[commandType];
1792
- if (commandDef.parser === Parser.V4Actions) {
1793
- var _V4BaseActionsParser$ = V4BaseActionsParser.parseCalldata(inputs[i]),
1794
- actions = _V4BaseActionsParser$.actions;
1795
- return {
1796
- commandName: CommandType[commandType],
1797
- commandType: commandType,
1798
- params: v4RouterCallToParams(actions)
1799
- };
1800
- } else if (commandDef.parser === Parser.Abi) {
1801
- var abiDef = commandDef.params;
1802
- var rawParams = ethers.utils.defaultAbiCoder.decode(abiDef.map(function (command) {
1803
- return command.type;
1804
- }), inputs[i]);
1805
- var params = rawParams.map(function (param, j) {
1806
- switch (abiDef[j].subparser) {
1807
- case Subparser.V3PathExactIn:
1808
- return {
1809
- name: abiDef[j].name,
1810
- value: parseV3PathExactIn(param)
1811
- };
1812
- case Subparser.V3PathExactOut:
1813
- return {
1814
- name: abiDef[j].name,
1815
- value: parseV3PathExactOut(param)
1816
- };
1817
- default:
1818
- return {
1819
- name: abiDef[j].name,
1820
- value: param
1821
- };
1822
- }
1823
- });
1824
- return {
1825
- commandName: CommandType[commandType],
1826
- commandType: commandType,
1827
- params: params
1828
- };
1829
- } else if (commandDef.parser === Parser.V3Actions) {
1830
- // TODO: implement better parsing here
1831
- return {
1832
- commandName: CommandType[commandType],
1833
- commandType: commandType,
1834
- params: inputs.map(function (input) {
1835
- return {
1836
- name: 'command',
1837
- value: input
1838
- };
1839
- })
1840
- };
1841
- } else {
1842
- throw new Error("Unsupported parser: " + commandDef);
1843
- }
1844
- })
1845
- };
1846
- }
1847
- // parse command types from bytes string
1848
- ;
1849
- GenericCommandParser.getCommands = function getCommands(commands) {
1850
- var commandTypes = [];
1851
- for (var i = 2; i < commands.length; i += 2) {
1852
- var _byte = commands.substring(i, i + 2);
1853
- commandTypes.push(parseInt(_byte, 16));
1854
- }
1855
- return commandTypes;
1856
- };
1857
- return GenericCommandParser;
1858
- }();
1859
- function parseV3PathExactIn(path) {
1860
- var strippedPath = path.replace('0x', '');
1861
- var tokenIn = ethers.utils.getAddress(strippedPath.substring(0, 40));
1862
- var loc = 40;
1863
- var res = [];
1864
- while (loc < strippedPath.length) {
1865
- var feeAndTokenOut = strippedPath.substring(loc, loc + 46);
1866
- var fee = parseInt(feeAndTokenOut.substring(0, 6), 16);
1867
- var tokenOut = ethers.utils.getAddress(feeAndTokenOut.substring(6, 46));
1868
- res.push({
1869
- tokenIn: tokenIn,
1870
- tokenOut: tokenOut,
1871
- fee: fee
1872
- });
1873
- tokenIn = tokenOut;
1874
- loc += 46;
1875
- }
1876
- return res;
1877
- }
1878
- function parseV3PathExactOut(path) {
1879
- var strippedPath = path.replace('0x', '');
1880
- var tokenIn = ethers.utils.getAddress(strippedPath.substring(strippedPath.length - 40));
1881
- var loc = strippedPath.length - 86; // 86 = (20 addr + 3 fee + 20 addr) * 2 (for hex characters)
1882
- var res = [];
1883
- while (loc >= 0) {
1884
- var feeAndTokenOut = strippedPath.substring(loc, loc + 46);
1885
- var tokenOut = ethers.utils.getAddress(feeAndTokenOut.substring(0, 40));
1886
- var fee = parseInt(feeAndTokenOut.substring(40, 46), 16);
1887
- res.push({
1888
- tokenIn: tokenIn,
1889
- tokenOut: tokenOut,
1890
- fee: fee
1891
- });
1892
- tokenIn = tokenOut;
1893
- loc -= 46;
1894
- }
1895
- return res;
1896
- }
1897
- function v4RouterCallToParams(actions) {
1898
- return actions.map(function (action) {
1899
- return {
1900
- name: action.actionName,
1901
- value: action.params.map(function (param) {
1902
- return {
1903
- name: param.name,
1904
- value: param.value
1905
- };
1906
- })
1907
- };
1908
- });
1909
- }
1910
-
1911
- export { COMMAND_DEFINITION, CONTRACT_BALANCE, CommandParser, CommandType, EXECUTE_SIGNED_TYPES, GenericCommandParser, NONCE_SKIP_CHECK, Parser, PoolType, ROUTER_AS_RECIPIENT, RoutePlanner, RouterActionType, RouterTradeAdapter, SWAP_PROXY_ADDRESS, Subparser, SwapRouter, TokenTransferMode, UNIVERSAL_ROUTER_ADDRESS, UNIVERSAL_ROUTER_CREATION_BLOCK, UniswapTrade, UniversalRouterVersion, UnwrapWETH, WETH_ADDRESS, generateNonce, getUniversalRouterDomain, isNativeCurrency };
1912
- //# sourceMappingURL=universal-router-sdk.esm.js.map