@uniswap/universal-router-sdk 4.19.0 → 4.19.1

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 (119) hide show
  1. package/dist/{entities → cjs/src/entities}/Command.d.ts +12 -12
  2. package/dist/cjs/src/entities/Command.js +9 -0
  3. package/dist/cjs/src/entities/Command.js.map +1 -0
  4. package/dist/{entities → cjs/src/entities}/actions/index.d.ts +2 -2
  5. package/dist/cjs/src/entities/actions/index.js +6 -0
  6. package/dist/cjs/src/entities/actions/index.js.map +1 -0
  7. package/dist/{entities → cjs/src/entities}/actions/uniswap.d.ts +30 -30
  8. package/dist/cjs/src/entities/actions/uniswap.js +365 -0
  9. package/dist/cjs/src/entities/actions/uniswap.js.map +1 -0
  10. package/dist/{entities → cjs/src/entities}/actions/unwrapWETH.d.ts +12 -12
  11. package/dist/cjs/src/entities/actions/unwrapWETH.js +33 -0
  12. package/dist/cjs/src/entities/actions/unwrapWETH.js.map +1 -0
  13. package/dist/{entities → cjs/src/entities}/index.d.ts +2 -2
  14. package/dist/cjs/src/entities/index.js +6 -0
  15. package/dist/cjs/src/entities/index.js.map +1 -0
  16. package/dist/cjs/src/index.d.ts +9 -0
  17. package/dist/cjs/src/index.js +24 -0
  18. package/dist/cjs/src/index.js.map +1 -0
  19. package/dist/{swapRouter.d.ts → cjs/src/swapRouter.d.ts} +37 -37
  20. package/dist/cjs/src/swapRouter.js +120 -0
  21. package/dist/cjs/src/swapRouter.js.map +1 -0
  22. package/dist/{utils → cjs/src/utils}/commandParser.d.ts +34 -34
  23. package/dist/cjs/src/utils/commandParser.js +144 -0
  24. package/dist/cjs/src/utils/commandParser.js.map +1 -0
  25. package/dist/{utils → cjs/src/utils}/constants.d.ts +30 -30
  26. package/dist/cjs/src/utils/constants.js +373 -0
  27. package/dist/cjs/src/utils/constants.js.map +1 -0
  28. package/dist/{utils → cjs/src/utils}/getCurrencyAddress.d.ts +2 -2
  29. package/dist/cjs/src/utils/getCurrencyAddress.js +9 -0
  30. package/dist/cjs/src/utils/getCurrencyAddress.js.map +1 -0
  31. package/dist/{utils → cjs/src/utils}/inputTokens.d.ts +23 -23
  32. package/dist/cjs/src/utils/inputTokens.js +58 -0
  33. package/dist/cjs/src/utils/inputTokens.js.map +1 -0
  34. package/dist/{utils → cjs/src/utils}/numbers.d.ts +6 -6
  35. package/dist/cjs/src/utils/numbers.js +22 -0
  36. package/dist/cjs/src/utils/numbers.js.map +1 -0
  37. package/dist/{utils → cjs/src/utils}/pathCurrency.d.ts +3 -3
  38. package/dist/cjs/src/utils/pathCurrency.js +27 -0
  39. package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
  40. package/dist/{utils → cjs/src/utils}/routerCommands.d.ts +64 -64
  41. package/dist/cjs/src/utils/routerCommands.js +231 -0
  42. package/dist/cjs/src/utils/routerCommands.js.map +1 -0
  43. package/dist/{utils → cjs/src/utils}/routerTradeAdapter.d.ts +73 -73
  44. package/dist/cjs/src/utils/routerTradeAdapter.js +139 -0
  45. package/dist/cjs/src/utils/routerTradeAdapter.js.map +1 -0
  46. package/dist/esm/src/entities/Command.d.ts +12 -0
  47. package/dist/esm/src/entities/Command.js +6 -0
  48. package/dist/esm/src/entities/Command.js.map +1 -0
  49. package/dist/esm/src/entities/actions/index.d.ts +2 -0
  50. package/dist/esm/src/entities/actions/index.js +3 -0
  51. package/dist/esm/src/entities/actions/index.js.map +1 -0
  52. package/dist/esm/src/entities/actions/uniswap.d.ts +30 -0
  53. package/dist/esm/src/entities/actions/uniswap.js +361 -0
  54. package/dist/esm/src/entities/actions/uniswap.js.map +1 -0
  55. package/dist/esm/src/entities/actions/unwrapWETH.d.ts +12 -0
  56. package/dist/esm/src/entities/actions/unwrapWETH.js +28 -0
  57. package/dist/esm/src/entities/actions/unwrapWETH.js.map +1 -0
  58. package/dist/esm/src/entities/index.d.ts +2 -0
  59. package/dist/esm/src/entities/index.js +3 -0
  60. package/dist/esm/src/entities/index.js.map +1 -0
  61. package/dist/esm/src/index.d.ts +9 -0
  62. package/dist/esm/src/index.js +7 -0
  63. package/dist/esm/src/index.js.map +1 -0
  64. package/dist/esm/src/swapRouter.d.ts +37 -0
  65. package/dist/esm/src/swapRouter.js +115 -0
  66. package/dist/esm/src/swapRouter.js.map +1 -0
  67. package/dist/esm/src/utils/commandParser.d.ts +34 -0
  68. package/dist/esm/src/utils/commandParser.js +137 -0
  69. package/dist/esm/src/utils/commandParser.js.map +1 -0
  70. package/dist/esm/src/utils/constants.d.ts +30 -0
  71. package/dist/esm/src/utils/constants.js +367 -0
  72. package/dist/esm/src/utils/constants.js.map +1 -0
  73. package/dist/esm/src/utils/getCurrencyAddress.d.ts +2 -0
  74. package/dist/esm/src/utils/getCurrencyAddress.js +5 -0
  75. package/dist/esm/src/utils/getCurrencyAddress.js.map +1 -0
  76. package/dist/esm/src/utils/inputTokens.d.ts +23 -0
  77. package/dist/esm/src/utils/inputTokens.js +51 -0
  78. package/dist/esm/src/utils/inputTokens.js.map +1 -0
  79. package/dist/esm/src/utils/numbers.d.ts +6 -0
  80. package/dist/esm/src/utils/numbers.js +15 -0
  81. package/dist/esm/src/utils/numbers.js.map +1 -0
  82. package/dist/esm/src/utils/pathCurrency.d.ts +3 -0
  83. package/dist/esm/src/utils/pathCurrency.js +23 -0
  84. package/dist/esm/src/utils/pathCurrency.js.map +1 -0
  85. package/dist/esm/src/utils/routerCommands.d.ts +64 -0
  86. package/dist/esm/src/utils/routerCommands.js +226 -0
  87. package/dist/esm/src/utils/routerCommands.js.map +1 -0
  88. package/dist/esm/src/utils/routerTradeAdapter.d.ts +73 -0
  89. package/dist/esm/src/utils/routerTradeAdapter.js +134 -0
  90. package/dist/esm/src/utils/routerTradeAdapter.js.map +1 -0
  91. package/dist/types/src/entities/Command.d.ts +12 -0
  92. package/dist/types/src/entities/actions/index.d.ts +2 -0
  93. package/dist/types/src/entities/actions/uniswap.d.ts +30 -0
  94. package/dist/types/src/entities/actions/unwrapWETH.d.ts +12 -0
  95. package/dist/types/src/entities/index.d.ts +2 -0
  96. package/dist/types/src/index.d.ts +9 -0
  97. package/dist/types/src/swapRouter.d.ts +37 -0
  98. package/dist/types/src/utils/commandParser.d.ts +34 -0
  99. package/dist/types/src/utils/constants.d.ts +30 -0
  100. package/dist/types/src/utils/getCurrencyAddress.d.ts +2 -0
  101. package/dist/types/src/utils/inputTokens.d.ts +23 -0
  102. package/dist/types/src/utils/numbers.d.ts +6 -0
  103. package/dist/types/src/utils/pathCurrency.d.ts +3 -0
  104. package/dist/types/src/utils/routerCommands.d.ts +64 -0
  105. package/dist/types/src/utils/routerTradeAdapter.d.ts +73 -0
  106. package/package.json +17 -5
  107. package/dist/index.d.ts +0 -6
  108. package/dist/index.js +0 -8
  109. package/dist/test/forge/writeInterop.d.ts +0 -2
  110. package/dist/test/utils/addresses.d.ts +0 -5
  111. package/dist/test/utils/hexToDecimalString.d.ts +0 -2
  112. package/dist/test/utils/permit2.d.ts +0 -7
  113. package/dist/test/utils/uniswapData.d.ts +0 -24
  114. package/dist/universal-router-sdk.cjs.development.js +0 -1433
  115. package/dist/universal-router-sdk.cjs.development.js.map +0 -1
  116. package/dist/universal-router-sdk.cjs.production.min.js +0 -2
  117. package/dist/universal-router-sdk.cjs.production.min.js.map +0 -1
  118. package/dist/universal-router-sdk.esm.js +0 -1426
  119. package/dist/universal-router-sdk.esm.js.map +0 -1
@@ -0,0 +1,226 @@
1
+ import { defaultAbiCoder } from 'ethers/lib/utils';
2
+ /**
3
+ * CommandTypes
4
+ * @description Flags that modify a command's execution
5
+ * @enum {number}
6
+ */
7
+ export var CommandType;
8
+ (function (CommandType) {
9
+ CommandType[CommandType["V3_SWAP_EXACT_IN"] = 0] = "V3_SWAP_EXACT_IN";
10
+ CommandType[CommandType["V3_SWAP_EXACT_OUT"] = 1] = "V3_SWAP_EXACT_OUT";
11
+ CommandType[CommandType["PERMIT2_TRANSFER_FROM"] = 2] = "PERMIT2_TRANSFER_FROM";
12
+ CommandType[CommandType["PERMIT2_PERMIT_BATCH"] = 3] = "PERMIT2_PERMIT_BATCH";
13
+ CommandType[CommandType["SWEEP"] = 4] = "SWEEP";
14
+ CommandType[CommandType["TRANSFER"] = 5] = "TRANSFER";
15
+ CommandType[CommandType["PAY_PORTION"] = 6] = "PAY_PORTION";
16
+ CommandType[CommandType["V2_SWAP_EXACT_IN"] = 8] = "V2_SWAP_EXACT_IN";
17
+ CommandType[CommandType["V2_SWAP_EXACT_OUT"] = 9] = "V2_SWAP_EXACT_OUT";
18
+ CommandType[CommandType["PERMIT2_PERMIT"] = 10] = "PERMIT2_PERMIT";
19
+ CommandType[CommandType["WRAP_ETH"] = 11] = "WRAP_ETH";
20
+ CommandType[CommandType["UNWRAP_WETH"] = 12] = "UNWRAP_WETH";
21
+ CommandType[CommandType["PERMIT2_TRANSFER_FROM_BATCH"] = 13] = "PERMIT2_TRANSFER_FROM_BATCH";
22
+ CommandType[CommandType["BALANCE_CHECK_ERC20"] = 14] = "BALANCE_CHECK_ERC20";
23
+ CommandType[CommandType["V4_SWAP"] = 16] = "V4_SWAP";
24
+ CommandType[CommandType["V3_POSITION_MANAGER_PERMIT"] = 17] = "V3_POSITION_MANAGER_PERMIT";
25
+ CommandType[CommandType["V3_POSITION_MANAGER_CALL"] = 18] = "V3_POSITION_MANAGER_CALL";
26
+ CommandType[CommandType["V4_INITIALIZE_POOL"] = 19] = "V4_INITIALIZE_POOL";
27
+ CommandType[CommandType["V4_POSITION_MANAGER_CALL"] = 20] = "V4_POSITION_MANAGER_CALL";
28
+ CommandType[CommandType["EXECUTE_SUB_PLAN"] = 33] = "EXECUTE_SUB_PLAN";
29
+ })(CommandType || (CommandType = {}));
30
+ export var Subparser;
31
+ (function (Subparser) {
32
+ Subparser[Subparser["V3PathExactIn"] = 0] = "V3PathExactIn";
33
+ Subparser[Subparser["V3PathExactOut"] = 1] = "V3PathExactOut";
34
+ })(Subparser || (Subparser = {}));
35
+ export var Parser;
36
+ (function (Parser) {
37
+ Parser[Parser["Abi"] = 0] = "Abi";
38
+ Parser[Parser["V4Actions"] = 1] = "V4Actions";
39
+ Parser[Parser["V3Actions"] = 2] = "V3Actions";
40
+ })(Parser || (Parser = {}));
41
+ const ALLOW_REVERT_FLAG = 0x80;
42
+ const REVERTIBLE_COMMANDS = new Set([CommandType.EXECUTE_SUB_PLAN]);
43
+ const PERMIT_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 nonce) details,address spender,uint256 sigDeadline)';
44
+ const PERMIT_BATCH_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 nonce)[] details,address spender,uint256 sigDeadline)';
45
+ const POOL_KEY_STRUCT = '(address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks)';
46
+ const PERMIT2_TRANSFER_FROM_STRUCT = '(address from,address to,uint160 amount,address token)';
47
+ const PERMIT2_TRANSFER_FROM_BATCH_STRUCT = PERMIT2_TRANSFER_FROM_STRUCT + '[]';
48
+ export const COMMAND_DEFINITION = {
49
+ // Batch Reverts
50
+ [CommandType.EXECUTE_SUB_PLAN]: {
51
+ parser: Parser.Abi,
52
+ params: [
53
+ { name: 'commands', type: 'bytes' },
54
+ { name: 'inputs', type: 'bytes[]' },
55
+ ],
56
+ },
57
+ // Permit2 Actions
58
+ [CommandType.PERMIT2_PERMIT]: {
59
+ parser: Parser.Abi,
60
+ params: [
61
+ { name: 'permit', type: PERMIT_STRUCT },
62
+ { name: 'signature', type: 'bytes' },
63
+ ],
64
+ },
65
+ [CommandType.PERMIT2_PERMIT_BATCH]: {
66
+ parser: Parser.Abi,
67
+ params: [
68
+ { name: 'permit', type: PERMIT_BATCH_STRUCT },
69
+ { name: 'signature', type: 'bytes' },
70
+ ],
71
+ },
72
+ [CommandType.PERMIT2_TRANSFER_FROM]: {
73
+ parser: Parser.Abi,
74
+ params: [
75
+ { name: 'token', type: 'address' },
76
+ { name: 'recipient', type: 'address' },
77
+ { name: 'amount', type: 'uint160' },
78
+ ],
79
+ },
80
+ [CommandType.PERMIT2_TRANSFER_FROM_BATCH]: {
81
+ parser: Parser.Abi,
82
+ params: [
83
+ {
84
+ name: 'transferFrom',
85
+ type: PERMIT2_TRANSFER_FROM_BATCH_STRUCT,
86
+ },
87
+ ],
88
+ },
89
+ // Uniswap Actions
90
+ [CommandType.V3_SWAP_EXACT_IN]: {
91
+ parser: Parser.Abi,
92
+ params: [
93
+ { name: 'recipient', type: 'address' },
94
+ { name: 'amountIn', type: 'uint256' },
95
+ { name: 'amountOutMin', type: 'uint256' },
96
+ { name: 'path', subparser: Subparser.V3PathExactIn, type: 'bytes' },
97
+ { name: 'payerIsUser', type: 'bool' },
98
+ ],
99
+ },
100
+ [CommandType.V3_SWAP_EXACT_OUT]: {
101
+ parser: Parser.Abi,
102
+ params: [
103
+ { name: 'recipient', type: 'address' },
104
+ { name: 'amountOut', type: 'uint256' },
105
+ { name: 'amountInMax', type: 'uint256' },
106
+ { name: 'path', subparser: Subparser.V3PathExactOut, type: 'bytes' },
107
+ { name: 'payerIsUser', type: 'bool' },
108
+ ],
109
+ },
110
+ [CommandType.V2_SWAP_EXACT_IN]: {
111
+ parser: Parser.Abi,
112
+ params: [
113
+ { name: 'recipient', type: 'address' },
114
+ { name: 'amountIn', type: 'uint256' },
115
+ { name: 'amountOutMin', type: 'uint256' },
116
+ { name: 'path', type: 'address[]' },
117
+ { name: 'payerIsUser', type: 'bool' },
118
+ ],
119
+ },
120
+ [CommandType.V2_SWAP_EXACT_OUT]: {
121
+ parser: Parser.Abi,
122
+ params: [
123
+ { name: 'recipient', type: 'address' },
124
+ { name: 'amountOut', type: 'uint256' },
125
+ { name: 'amountInMax', type: 'uint256' },
126
+ { name: 'path', type: 'address[]' },
127
+ { name: 'payerIsUser', type: 'bool' },
128
+ ],
129
+ },
130
+ [CommandType.V4_SWAP]: { parser: Parser.V4Actions },
131
+ // Token Actions and Checks
132
+ [CommandType.WRAP_ETH]: {
133
+ parser: Parser.Abi,
134
+ params: [
135
+ { name: 'recipient', type: 'address' },
136
+ { name: 'amount', type: 'uint256' },
137
+ ],
138
+ },
139
+ [CommandType.UNWRAP_WETH]: {
140
+ parser: Parser.Abi,
141
+ params: [
142
+ { name: 'recipient', type: 'address' },
143
+ { name: 'amountMin', type: 'uint256' },
144
+ ],
145
+ },
146
+ [CommandType.SWEEP]: {
147
+ parser: Parser.Abi,
148
+ params: [
149
+ { name: 'token', type: 'address' },
150
+ { name: 'recipient', type: 'address' },
151
+ { name: 'amountMin', type: 'uint256' },
152
+ ],
153
+ },
154
+ [CommandType.TRANSFER]: {
155
+ parser: Parser.Abi,
156
+ params: [
157
+ { name: 'token', type: 'address' },
158
+ { name: 'recipient', type: 'address' },
159
+ { name: 'value', type: 'uint256' },
160
+ ],
161
+ },
162
+ [CommandType.PAY_PORTION]: {
163
+ parser: Parser.Abi,
164
+ params: [
165
+ { name: 'token', type: 'address' },
166
+ { name: 'recipient', type: 'address' },
167
+ { name: 'bips', type: 'uint256' },
168
+ ],
169
+ },
170
+ [CommandType.BALANCE_CHECK_ERC20]: {
171
+ parser: Parser.Abi,
172
+ params: [
173
+ { name: 'owner', type: 'address' },
174
+ { name: 'token', type: 'address' },
175
+ { name: 'minBalance', type: 'uint256' },
176
+ ],
177
+ },
178
+ [CommandType.V4_INITIALIZE_POOL]: {
179
+ parser: Parser.Abi,
180
+ params: [
181
+ { name: 'poolKey', type: POOL_KEY_STRUCT },
182
+ { name: 'sqrtPriceX96', type: 'uint160' },
183
+ ],
184
+ },
185
+ // Position Actions
186
+ [CommandType.V3_POSITION_MANAGER_PERMIT]: { parser: Parser.V3Actions },
187
+ [CommandType.V3_POSITION_MANAGER_CALL]: { parser: Parser.V3Actions },
188
+ [CommandType.V4_POSITION_MANAGER_CALL]: { parser: Parser.V4Actions },
189
+ };
190
+ export class RoutePlanner {
191
+ constructor() {
192
+ this.commands = '0x';
193
+ this.inputs = [];
194
+ }
195
+ addSubPlan(subplan) {
196
+ this.addCommand(CommandType.EXECUTE_SUB_PLAN, [subplan.commands, subplan.inputs], true);
197
+ return this;
198
+ }
199
+ addCommand(type, parameters, allowRevert = false) {
200
+ let command = createCommand(type, parameters);
201
+ this.inputs.push(command.encodedInput);
202
+ if (allowRevert) {
203
+ if (!REVERTIBLE_COMMANDS.has(command.type)) {
204
+ throw new Error(`command type: ${command.type} cannot be allowed to revert`);
205
+ }
206
+ command.type = command.type | ALLOW_REVERT_FLAG;
207
+ }
208
+ this.commands = this.commands.concat(command.type.toString(16).padStart(2, '0'));
209
+ return this;
210
+ }
211
+ }
212
+ export function createCommand(type, parameters) {
213
+ const commandDef = COMMAND_DEFINITION[type];
214
+ switch (commandDef.parser) {
215
+ case Parser.Abi:
216
+ const encodedInput = defaultAbiCoder.encode(commandDef.params.map((abi) => abi.type), parameters);
217
+ return { type, encodedInput };
218
+ case Parser.V4Actions:
219
+ // v4 swap data comes pre-encoded at index 0
220
+ return { type, encodedInput: parameters[0] };
221
+ case Parser.V3Actions:
222
+ // v4 swap data comes pre-encoded at index 0
223
+ return { type, encodedInput: parameters[0] };
224
+ }
225
+ }
226
+ //# sourceMappingURL=routerCommands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routerCommands.js","sourceRoot":"","sources":["../../../../src/utils/routerCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAElD;;;;GAIG;AACH,MAAM,CAAN,IAAY,WAwBX;AAxBD,WAAY,WAAW;IACrB,qEAAuB,CAAA;IACvB,uEAAwB,CAAA;IACxB,+EAA4B,CAAA;IAC5B,6EAA2B,CAAA;IAC3B,+CAAY,CAAA;IACZ,qDAAe,CAAA;IACf,2DAAkB,CAAA;IAElB,qEAAuB,CAAA;IACvB,uEAAwB,CAAA;IACxB,kEAAqB,CAAA;IACrB,sDAAe,CAAA;IACf,4DAAkB,CAAA;IAClB,4FAAkC,CAAA;IAClC,4EAA0B,CAAA;IAE1B,oDAAc,CAAA;IACd,0FAAiC,CAAA;IACjC,sFAA+B,CAAA;IAC/B,0EAAyB,CAAA;I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;YACnB,4CAA4C;YAC5C,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAA;KAC/C;AACH,CAAC"}
@@ -0,0 +1,73 @@
1
+ import { Trade as RouterTrade } from '@uniswap/router-sdk';
2
+ import { Currency, TradeType } from '@uniswap/sdk-core';
3
+ export type TokenInRoute = {
4
+ address: string;
5
+ chainId: number;
6
+ symbol: string;
7
+ decimals: string;
8
+ name?: string;
9
+ buyFeeBps?: string;
10
+ sellFeeBps?: string;
11
+ };
12
+ export declare enum PoolType {
13
+ V2Pool = "v2-pool",
14
+ V3Pool = "v3-pool",
15
+ V4Pool = "v4-pool"
16
+ }
17
+ export type V2Reserve = {
18
+ token: TokenInRoute;
19
+ quotient: string;
20
+ };
21
+ export type V2PoolInRoute = {
22
+ type: PoolType.V2Pool;
23
+ address?: string;
24
+ tokenIn: TokenInRoute;
25
+ tokenOut: TokenInRoute;
26
+ reserve0: V2Reserve;
27
+ reserve1: V2Reserve;
28
+ amountIn?: string;
29
+ amountOut?: string;
30
+ };
31
+ export type V3PoolInRoute = {
32
+ type: PoolType.V3Pool;
33
+ address?: string;
34
+ tokenIn: TokenInRoute;
35
+ tokenOut: TokenInRoute;
36
+ sqrtRatioX96: string;
37
+ liquidity: string;
38
+ tickCurrent: string;
39
+ fee: string;
40
+ amountIn?: string;
41
+ amountOut?: string;
42
+ };
43
+ export type V4PoolInRoute = {
44
+ type: PoolType.V4Pool;
45
+ address?: string;
46
+ tokenIn: TokenInRoute;
47
+ tokenOut: TokenInRoute;
48
+ fee: string;
49
+ tickSpacing: string;
50
+ hooks: string;
51
+ liquidity: string;
52
+ sqrtRatioX96: string;
53
+ tickCurrent: string;
54
+ amountIn?: string;
55
+ amountOut?: string;
56
+ };
57
+ export type PartialClassicQuote = {
58
+ tokenIn: string;
59
+ tokenOut: string;
60
+ tradeType: TradeType;
61
+ route: Array<(V4PoolInRoute | V3PoolInRoute | V2PoolInRoute)[]>;
62
+ };
63
+ export declare const isNativeCurrency: (address: string) => boolean;
64
+ export declare class RouterTradeAdapter {
65
+ static fromClassicQuote(quote: PartialClassicQuote): RouterTrade<Currency, Currency, TradeType>;
66
+ private static toCurrency;
67
+ private static toPoolOrPair;
68
+ private static toToken;
69
+ private static toV3Pool;
70
+ private static toV4Pool;
71
+ private static toPair;
72
+ private static isVersionedRoute;
73
+ }
@@ -0,0 +1,134 @@
1
+ import { MixedRouteSDK, Trade as RouterTrade } from '@uniswap/router-sdk';
2
+ import { CurrencyAmount, Ether, Token } from '@uniswap/sdk-core';
3
+ import { Pair, Route as V2Route } from '@uniswap/v2-sdk';
4
+ import { Pool as V3Pool, Route as V3Route } from '@uniswap/v3-sdk';
5
+ import { Pool as V4Pool, Route as V4Route } from '@uniswap/v4-sdk';
6
+ import { BigNumber } from 'ethers';
7
+ import { ETH_ADDRESS, E_ETH_ADDRESS } from './constants';
8
+ export var PoolType;
9
+ (function (PoolType) {
10
+ PoolType["V2Pool"] = "v2-pool";
11
+ PoolType["V3Pool"] = "v3-pool";
12
+ PoolType["V4Pool"] = "v4-pool";
13
+ })(PoolType || (PoolType = {}));
14
+ export const isNativeCurrency = (address) => address.toLowerCase() === ETH_ADDRESS.toLowerCase() || address.toLowerCase() === E_ETH_ADDRESS.toLowerCase();
15
+ // Helper class to convert routing-specific quote entities to RouterTrade entities
16
+ // the returned RouterTrade can then be used to build the UniswapTrade entity in this package
17
+ export class RouterTradeAdapter {
18
+ // Generate a RouterTrade using fields from a classic quote response
19
+ static fromClassicQuote(quote) {
20
+ const { route, tokenIn, tokenOut } = quote;
21
+ if (!route)
22
+ throw new Error('Expected route to be present');
23
+ if (!route.length)
24
+ throw new Error('Expected there to be at least one route');
25
+ if (route.some((r) => !r.length))
26
+ throw new Error('Expected all routes to have at least one pool');
27
+ const firstRoute = route[0];
28
+ const tokenInData = firstRoute[0].tokenIn;
29
+ const tokenOutData = firstRoute[firstRoute.length - 1].tokenOut;
30
+ if (!tokenInData || !tokenOutData)
31
+ throw new Error('Expected both tokenIn and tokenOut to be present');
32
+ if (tokenInData.chainId !== tokenOutData.chainId)
33
+ throw new Error('Expected tokenIn and tokenOut to be have same chainId');
34
+ const parsedCurrencyIn = RouterTradeAdapter.toCurrency(isNativeCurrency(tokenIn), tokenInData);
35
+ const parsedCurrencyOut = RouterTradeAdapter.toCurrency(isNativeCurrency(tokenOut), tokenOutData);
36
+ const typedRoutes = route.map((subRoute) => {
37
+ const rawAmountIn = subRoute[0].amountIn;
38
+ const rawAmountOut = subRoute[subRoute.length - 1].amountOut;
39
+ if (!rawAmountIn || !rawAmountOut) {
40
+ throw new Error('Expected both raw amountIn and raw amountOut to be present');
41
+ }
42
+ const inputAmount = CurrencyAmount.fromRawAmount(parsedCurrencyIn, rawAmountIn);
43
+ const outputAmount = CurrencyAmount.fromRawAmount(parsedCurrencyOut, rawAmountOut);
44
+ const isOnlyV2 = RouterTradeAdapter.isVersionedRoute(PoolType.V2Pool, subRoute);
45
+ const isOnlyV3 = RouterTradeAdapter.isVersionedRoute(PoolType.V3Pool, subRoute);
46
+ const isOnlyV4 = RouterTradeAdapter.isVersionedRoute(PoolType.V4Pool, subRoute);
47
+ return {
48
+ routev4: isOnlyV4
49
+ ? new V4Route(subRoute.map(RouterTradeAdapter.toV4Pool), parsedCurrencyIn, parsedCurrencyOut)
50
+ : null,
51
+ routev3: isOnlyV3
52
+ ? new V3Route(subRoute.map(RouterTradeAdapter.toV3Pool), parsedCurrencyIn, parsedCurrencyOut)
53
+ : null,
54
+ routev2: isOnlyV2
55
+ ? new V2Route(subRoute.map(RouterTradeAdapter.toPair), parsedCurrencyIn, parsedCurrencyOut)
56
+ : null,
57
+ mixedRoute: !isOnlyV4 && !isOnlyV3 && !isOnlyV2
58
+ ? new MixedRouteSDK(subRoute.map(RouterTradeAdapter.toPoolOrPair), parsedCurrencyIn, parsedCurrencyOut)
59
+ : null,
60
+ inputAmount,
61
+ outputAmount,
62
+ };
63
+ });
64
+ return new RouterTrade({
65
+ v2Routes: typedRoutes
66
+ .filter((route) => route.routev2)
67
+ .map((route) => ({
68
+ routev2: route.routev2,
69
+ inputAmount: route.inputAmount,
70
+ outputAmount: route.outputAmount,
71
+ })),
72
+ v3Routes: typedRoutes
73
+ .filter((route) => route.routev3)
74
+ .map((route) => ({
75
+ routev3: route.routev3,
76
+ inputAmount: route.inputAmount,
77
+ outputAmount: route.outputAmount,
78
+ })),
79
+ v4Routes: typedRoutes
80
+ .filter((route) => route.routev4)
81
+ .map((route) => ({
82
+ routev4: route.routev4,
83
+ inputAmount: route.inputAmount,
84
+ outputAmount: route.outputAmount,
85
+ })),
86
+ mixedRoutes: typedRoutes
87
+ .filter((route) => route.mixedRoute)
88
+ .map((route) => ({
89
+ mixedRoute: route.mixedRoute,
90
+ inputAmount: route.inputAmount,
91
+ outputAmount: route.outputAmount,
92
+ })),
93
+ tradeType: quote.tradeType,
94
+ });
95
+ }
96
+ static toCurrency(isNative, token) {
97
+ if (isNative) {
98
+ return Ether.onChain(token.chainId);
99
+ }
100
+ return this.toToken(token);
101
+ }
102
+ static toToken(token) {
103
+ const { chainId, address, decimals, symbol, buyFeeBps, sellFeeBps } = token;
104
+ return new Token(chainId, address, parseInt(decimals.toString()), symbol,
105
+ /* name */ undefined, false, buyFeeBps ? BigNumber.from(buyFeeBps) : undefined, sellFeeBps ? BigNumber.from(sellFeeBps) : undefined);
106
+ }
107
+ static toV3Pool({ fee, sqrtRatioX96, liquidity, tickCurrent, tokenIn, tokenOut }) {
108
+ return new V3Pool(RouterTradeAdapter.toToken(tokenIn), RouterTradeAdapter.toToken(tokenOut), parseInt(fee), sqrtRatioX96, liquidity, parseInt(tickCurrent));
109
+ }
110
+ static toV4Pool(pool) {
111
+ const parsedCurrencyIn = RouterTradeAdapter.toCurrency(isNativeCurrency(pool.tokenIn.address), pool.tokenIn);
112
+ const parsedCurrencyOut = RouterTradeAdapter.toCurrency(isNativeCurrency(pool.tokenOut.address), pool.tokenOut);
113
+ return new V4Pool(parsedCurrencyIn, parsedCurrencyOut, parseInt(pool.fee), parseInt(pool.tickSpacing), pool.hooks, pool.sqrtRatioX96, pool.liquidity, parseInt(pool.tickCurrent));
114
+ }
115
+ static isVersionedRoute(type, route) {
116
+ return route.every((pool) => pool.type === type);
117
+ }
118
+ }
119
+ RouterTradeAdapter.toPoolOrPair = (pool) => {
120
+ switch (pool.type) {
121
+ case PoolType.V4Pool:
122
+ return RouterTradeAdapter.toV4Pool(pool);
123
+ case PoolType.V3Pool:
124
+ return RouterTradeAdapter.toV3Pool(pool);
125
+ case PoolType.V2Pool:
126
+ return RouterTradeAdapter.toPair(pool);
127
+ default:
128
+ throw new Error('Invalid pool type');
129
+ }
130
+ };
131
+ RouterTradeAdapter.toPair = ({ reserve0, reserve1 }) => {
132
+ return new Pair(CurrencyAmount.fromRawAmount(RouterTradeAdapter.toToken(reserve0.token), reserve0.quotient), CurrencyAmount.fromRawAmount(RouterTradeAdapter.toToken(reserve1.token), reserve1.quotient));
133
+ };
134
+ //# sourceMappingURL=routerTradeAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routerTradeAdapter.js","sourceRoot":"","sources":["../../../../src/utils/routerTradeAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,EAAY,cAAc,EAAE,KAAK,EAAE,KAAK,EAAa,MAAM,mBAAmB,CAAA;AACrF,OAAO,EAAE,IAAI,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,KAAK,IAAI,OAAO,EAAa,MAAM,iBAAiB,CAAA;AAC7E,OAAO,EAAE,IAAI,IAAI,MAAM,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,aAAa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jEc,+BAAY,GAAG,CAAC,IAAmD,EAA0B,EAAE;IAC5G,QAAQ,IAAI,CAAC,IAAI,EAAE;QACjB,KAAK,QAAQ,CAAC,MAAM;YAClB,OAAO,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC1C,KAAK,QAAQ,CAAC,MAAM;YAClB,OAAO,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC1C,KAAK,QAAQ,CAAC,MAAM;YAClB,OAAO,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACxC;YACE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACvC;AACH,CAAC,CAAA;AA0Cc,yBAAM,GAAG,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAiB,EAAQ,EAAE;IACtE,OAAO,IAAI,IAAI,CACb,cAAc,CAAC,aAAa,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC3F,cAAc,CAAC,aAAa,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAC5F,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { RoutePlanner } from '../utils/routerCommands';
2
+ export type TradeConfig = {
3
+ allowRevert: boolean;
4
+ };
5
+ export declare enum RouterActionType {
6
+ UniswapTrade = "UniswapTrade",
7
+ UnwrapWETH = "UnwrapWETH"
8
+ }
9
+ export interface Command {
10
+ tradeType: RouterActionType;
11
+ encode(planner: RoutePlanner, config: TradeConfig): void;
12
+ }
@@ -0,0 +1,2 @@
1
+ export * from './uniswap';
2
+ export * from './unwrapWETH';
@@ -0,0 +1,30 @@
1
+ import { RoutePlanner } from '../../utils/routerCommands';
2
+ import { Trade as RouterTrade, SwapOptions as RouterSwapOptions } from '@uniswap/router-sdk';
3
+ import { Permit2Permit } from '../../utils/inputTokens';
4
+ import { Currency, TradeType } from '@uniswap/sdk-core';
5
+ import { Command, RouterActionType, TradeConfig } from '../Command';
6
+ import { BigNumberish } from 'ethers';
7
+ export type FlatFeeOptions = {
8
+ amount: BigNumberish;
9
+ recipient: string;
10
+ };
11
+ export type SwapOptions = Omit<RouterSwapOptions, 'inputTokenPermit'> & {
12
+ useRouterBalance?: boolean;
13
+ inputTokenPermit?: Permit2Permit;
14
+ flatFee?: FlatFeeOptions;
15
+ safeMode?: boolean;
16
+ };
17
+ export declare class UniswapTrade implements Command {
18
+ trade: RouterTrade<Currency, Currency, TradeType>;
19
+ options: SwapOptions;
20
+ readonly tradeType: RouterActionType;
21
+ readonly payerIsUser: boolean;
22
+ constructor(trade: RouterTrade<Currency, Currency, TradeType>, options: SwapOptions);
23
+ get isAllV4(): boolean;
24
+ get inputRequiresWrap(): boolean;
25
+ get inputRequiresUnwrap(): boolean;
26
+ get outputRequiresWrap(): boolean;
27
+ get outputRequiresUnwrap(): boolean;
28
+ get outputRequiresTransition(): boolean;
29
+ encode(planner: RoutePlanner, _config: TradeConfig): void;
30
+ }
@@ -0,0 +1,12 @@
1
+ import { BigNumberish } from 'ethers';
2
+ import { RoutePlanner } from '../../utils/routerCommands';
3
+ import { Permit2Permit } from '../../utils/inputTokens';
4
+ import { Command, RouterActionType, TradeConfig } from '../Command';
5
+ export declare class UnwrapWETH implements Command {
6
+ readonly tradeType: RouterActionType;
7
+ readonly permit2Data?: Permit2Permit;
8
+ readonly wethAddress: string;
9
+ readonly amount: BigNumberish;
10
+ constructor(amount: BigNumberish, chainId: number, permit2?: Permit2Permit);
11
+ encode(planner: RoutePlanner, _: TradeConfig): void;
12
+ }
@@ -0,0 +1,2 @@
1
+ export * from './actions';
2
+ export * from './Command';
@@ -0,0 +1,9 @@
1
+ export { SwapRouter } from './swapRouter';
2
+ export type { MigrateV3ToV4Options } from './swapRouter';
3
+ export * from './entities';
4
+ export * from './utils/routerTradeAdapter';
5
+ export { RoutePlanner, CommandType, COMMAND_DEFINITION, Parser, Subparser } from './utils/routerCommands';
6
+ export type { CommandDefinition, ParamType } from './utils/routerCommands';
7
+ export { UNIVERSAL_ROUTER_CREATION_BLOCK, UNIVERSAL_ROUTER_ADDRESS, ROUTER_AS_RECIPIENT, WETH_ADDRESS, UniversalRouterVersion, } from './utils/constants';
8
+ export { CommandParser, GenericCommandParser } from './utils/commandParser';
9
+ export type { UniversalRouterCommand, UniversalRouterCall, Param, CommandsDefinition } from './utils/commandParser';
@@ -0,0 +1,37 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { BigNumberish } from 'ethers';
3
+ import { MethodParameters, Position as V3Position, RemoveLiquidityOptions as V3RemoveLiquidityOptions } from '@uniswap/v3-sdk';
4
+ import { Position as V4Position, AddLiquidityOptions as V4AddLiquidityOptions } from '@uniswap/v4-sdk';
5
+ import { Trade as RouterTrade } from '@uniswap/router-sdk';
6
+ import { Currency, TradeType } from '@uniswap/sdk-core';
7
+ import { SwapOptions } from './entities/actions/uniswap';
8
+ export type SwapRouterConfig = {
9
+ sender?: string;
10
+ deadline?: BigNumberish;
11
+ };
12
+ export interface MigrateV3ToV4Options {
13
+ inputPosition: V3Position;
14
+ outputPosition: V4Position;
15
+ v3RemoveLiquidityOptions: V3RemoveLiquidityOptions;
16
+ v4AddLiquidityOptions: V4AddLiquidityOptions;
17
+ }
18
+ export declare abstract class SwapRouter {
19
+ static INTERFACE: Interface;
20
+ static swapCallParameters(trades: RouterTrade<Currency, Currency, TradeType>, options: SwapOptions): MethodParameters;
21
+ /**
22
+ * Builds the call parameters for a migration from a V3 position to a V4 position.
23
+ * Some requirements of the parameters:
24
+ * - v3RemoveLiquidityOptions.collectOptions.recipient must equal v4PositionManager
25
+ * - v3RemoveLiquidityOptions.liquidityPercentage must be 100%
26
+ * - input pool and output pool must have the same tokens
27
+ * - V3 NFT must be approved, or valid inputV3NFTPermit must be provided with UR as spender
28
+ */
29
+ static migrateV3ToV4CallParameters(options: MigrateV3ToV4Options, positionManagerOverride?: string): MethodParameters;
30
+ /**
31
+ * Encodes a planned route into a method name and parameters for the Router contract.
32
+ * @param planner the planned route
33
+ * @param nativeCurrencyValue the native currency value of the planned route
34
+ * @param config the router config
35
+ */
36
+ private static encodePlan;
37
+ }
@@ -0,0 +1,34 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { CommandType, CommandDefinition } from '../utils/routerCommands';
3
+ export type Param = {
4
+ readonly name: string;
5
+ readonly value: any;
6
+ };
7
+ export type UniversalRouterCommand = {
8
+ readonly commandName: string;
9
+ readonly commandType: CommandType;
10
+ readonly params: readonly Param[];
11
+ };
12
+ export type UniversalRouterCall = {
13
+ readonly commands: readonly UniversalRouterCommand[];
14
+ };
15
+ export type V3PathItem = {
16
+ readonly tokenIn: string;
17
+ readonly tokenOut: string;
18
+ readonly fee: number;
19
+ };
20
+ export interface CommandsDefinition {
21
+ [key: number]: CommandDefinition;
22
+ }
23
+ export declare abstract class CommandParser {
24
+ static INTERFACE: Interface;
25
+ static parseCalldata(calldata: string): UniversalRouterCall;
26
+ }
27
+ export declare class GenericCommandParser {
28
+ private readonly commandDefinition;
29
+ constructor(commandDefinition: CommandsDefinition);
30
+ parse(commands: string, inputs: string[]): UniversalRouterCall;
31
+ private static getCommands;
32
+ }
33
+ export declare function parseV3PathExactIn(path: string): readonly V3PathItem[];
34
+ export declare function parseV3PathExactOut(path: string): readonly V3PathItem[];
@@ -0,0 +1,30 @@
1
+ import { BigNumber } from 'ethers';
2
+ export declare enum UniversalRouterVersion {
3
+ V1_2 = "1.2",
4
+ V2_0 = "2.0"
5
+ }
6
+ export type RouterConfig = {
7
+ address: string;
8
+ creationBlock: number;
9
+ };
10
+ type ChainConfig = {
11
+ weth: string;
12
+ routerConfigs: {
13
+ [key in UniversalRouterVersion]: RouterConfig;
14
+ };
15
+ };
16
+ export declare const CHAIN_CONFIGS: {
17
+ [key: number]: ChainConfig;
18
+ };
19
+ export declare const UNIVERSAL_ROUTER_ADDRESS: (version: UniversalRouterVersion, chainId: number) => string;
20
+ export declare const UNIVERSAL_ROUTER_CREATION_BLOCK: (version: UniversalRouterVersion, chainId: number) => number;
21
+ export declare const WETH_ADDRESS: (chainId: number) => string;
22
+ export declare const CONTRACT_BALANCE: BigNumber;
23
+ export declare const ETH_ADDRESS = "0x0000000000000000000000000000000000000000";
24
+ export declare const E_ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
25
+ export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
26
+ export declare const MAX_UINT256: BigNumber;
27
+ export declare const MAX_UINT160: BigNumber;
28
+ export declare const SENDER_AS_RECIPIENT = "0x0000000000000000000000000000000000000001";
29
+ export declare const ROUTER_AS_RECIPIENT = "0x0000000000000000000000000000000000000002";
30
+ export {};
@@ -0,0 +1,2 @@
1
+ import { Currency } from '@uniswap/sdk-core';
2
+ export declare function getCurrencyAddress(currency: Currency): string;