@uniswap/universal-router-sdk 1.5.7 → 2.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.
package/README.md CHANGED
@@ -92,6 +92,63 @@ const unwrapWETH = new UnwrapWETH(amountWETH, chainId, optionalPermit2Params)
92
92
  const { calldata, value } = SwapRouter.swapCallParameters([unwrapWETH, seaportTrades, looksRareTrades])
93
93
  ```
94
94
 
95
+ ### Trading stETH
96
+ To trade stETH as an input token, you can make sure the router automatically wraps stETH to wstETH before trading across a wstETH route. Make sure to specify the router is the payer of the swap (since it's in custody of wSTETH after wrapping)
97
+
98
+ If this is an exactOut trade, we'll need to wrap the maximumAmountIn of steth, and therefore should add an unwrap command at the end of the transaction to account for any leftover steth that didn't get traded. `amountMinimum` can be set to 0 in this scenario for the unwrapSteth commmand.
99
+ ```typescript
100
+ import { TradeType } from '@uniswap/sdk-core'
101
+ import { Trade as V2TradeSDK } from '@uniswap/v2-sdk'
102
+ import { Trade as V3TradeSDK } from '@uniswap/v3-sdk'
103
+ import { MixedRouteTrade, MixedRouteSDK, Trade as RouterTrade } from '@uniswap/router-sdk'
104
+ import {
105
+ UniswapTrade,
106
+ WrapSTETH
107
+ } from "@uniswap/universal-router-sdk";
108
+
109
+ // EXACT INPUT
110
+ // including optional permit2 parameter will transfer STETH amount using permit2
111
+ const wrapSTETH = new WrapSTETH(inputSTETH, chainId, WrapSTETHPermitData?, wrapAmountOtherThanContractBalance?)
112
+ const uniswapWstethTrade = new UniswapTrade(
113
+ new RouterTrade({ v2Routes, v3Routes, mixedRoutes, tradeType: TradeType.EXACT_INPUT }),
114
+ { slippageTolerance, payerIsRouter: true }
115
+ )
116
+ const { calldata, value } = SwapRouter.swapCallParameters([wrapSTETH, uniswapWstethTrade])
117
+
118
+ // EXACT OUTPUT
119
+ const wrapSTETH = new WrapSTETH(maximumInputSTETH, chainId, WrapSTETHPermitData?, wrapAmountOtherThanContractBalance?)
120
+ const uniswapWstethTrade = new UniswapTrade(
121
+ new RouterTrade({ v2Routes, v3Routes, mixedRoutes, tradeType: TradeType.EXACT_OUTPUT }),
122
+ { slippageTolerance, payerIsRouter: true }
123
+ )
124
+ const unwrapSTETH = new UnwrapSTETH(recipient, amountMinimum = 0, chainId)
125
+
126
+ const { calldata, value } = SwapRouter.swapCallParameters([wrapSTETH, uniswapWstethTrade, unwrapSTETH])
127
+
128
+ ```
129
+
130
+ To recieve stETH as an output token, you can make sure the router automatically unwraps wstETH to stETH before returning to the swapper
131
+ ```typescript
132
+ import { TradeType } from '@uniswap/sdk-core'
133
+ import { Trade as V2TradeSDK } from '@uniswap/v2-sdk'
134
+ import { Trade as V3TradeSDK } from '@uniswap/v3-sdk'
135
+ import { MixedRouteTrade, MixedRouteSDK, Trade as RouterTrade } from '@uniswap/router-sdk'
136
+ import {
137
+ ROUTER_AS_RECIPIENT,
138
+ UniswapTrade,
139
+ UnwrapSTETH
140
+ } from "@uniswap/universal-router-sdk";
141
+
142
+ // return trade to the router instead of the recipient using the ROUTER_AS_RECIPIENT constant so that the router may custody tokens to unwrap
143
+ const uniswapWstethTrade = new UniswapTrade(
144
+ new RouterTrade({ v2Routes, v3Routes, mixedRoutes, tradeType: TradeType.EXACT_INPUT }),
145
+ { slippageTolerance, recipient: ROUTER_AS_RECIPIENT}
146
+ )
147
+ const unwrapSTETH = new UnwrapSTETH(recipient, amountMinimum, chainId)
148
+
149
+ const { calldata, value } = SwapRouter.swapCallParameters([uniswapWstethTrade, unwrapSTETH])
150
+ ```
151
+
95
152
 
96
153
  ## Running this package
97
154
  Make sure you are running `node v16`
@@ -5,7 +5,9 @@ export declare type TradeConfig = {
5
5
  export declare enum RouterTradeType {
6
6
  UniswapTrade = "UniswapTrade",
7
7
  NFTTrade = "NFTTrade",
8
- UnwrapWETH = "UnwrapWETH"
8
+ UnwrapWETH = "UnwrapWETH",
9
+ WrapSTETH = "WrapSTETH",
10
+ UnwrapSTETH = "UnwrapSTETH"
9
11
  }
10
12
  export interface Command {
11
13
  tradeType: RouterTradeType;
@@ -8,3 +8,5 @@ export * from './uniswap';
8
8
  export * from './sudoswap';
9
9
  export * from './x2y2';
10
10
  export * from './unwrapWETH';
11
+ export * from './wrapSTETH';
12
+ export * from './unwrapSTETH';
@@ -3,8 +3,15 @@ import { Trade as RouterTrade, SwapOptions as RouterSwapOptions } from '@uniswap
3
3
  import { Permit2Permit } from '../../utils/inputTokens';
4
4
  import { Currency, TradeType } from '@uniswap/sdk-core';
5
5
  import { Command, RouterTradeType, TradeConfig } from '../Command';
6
+ import { BigNumberish } from 'ethers';
7
+ export declare type FlatFeeOptions = {
8
+ amount: BigNumberish;
9
+ recipient: string;
10
+ };
6
11
  export declare type SwapOptions = Omit<RouterSwapOptions, 'inputTokenPermit'> & {
7
12
  inputTokenPermit?: Permit2Permit;
13
+ payerIsRouter?: boolean;
14
+ flatFee?: FlatFeeOptions;
8
15
  };
9
16
  export declare class UniswapTrade implements Command {
10
17
  trade: RouterTrade<Currency, Currency, TradeType>;
@@ -0,0 +1,10 @@
1
+ import { BigNumberish } from 'ethers';
2
+ import { RoutePlanner } from '../../utils/routerCommands';
3
+ import { Command, RouterTradeType, TradeConfig } from '../Command';
4
+ export declare class UnwrapSTETH implements Command {
5
+ readonly tradeType: RouterTradeType;
6
+ readonly recipient: string;
7
+ readonly amountMinimum: BigNumberish;
8
+ constructor(recipient: string, amountMinimum: BigNumberish, chainId: number);
9
+ encode(planner: RoutePlanner, _: TradeConfig): void;
10
+ }
@@ -0,0 +1,13 @@
1
+ import { BigNumberish } from 'ethers';
2
+ import { RoutePlanner } from '../../utils/routerCommands';
3
+ import { Permit2Permit } from '../../utils/inputTokens';
4
+ import { Command, RouterTradeType, TradeConfig } from '../Command';
5
+ export declare class WrapSTETH implements Command {
6
+ readonly tradeType: RouterTradeType;
7
+ readonly permit2Data: Permit2Permit;
8
+ readonly stethAddress: string;
9
+ readonly amount: BigNumberish;
10
+ readonly wrapAmount: BigNumberish;
11
+ constructor(amount: BigNumberish, chainId: number, permit2?: Permit2Permit, wrapAmount?: BigNumberish);
12
+ encode(planner: RoutePlanner, _: TradeConfig): void;
13
+ }
@@ -78,6 +78,8 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
78
78
  RouterTradeType["UniswapTrade"] = "UniswapTrade";
79
79
  RouterTradeType["NFTTrade"] = "NFTTrade";
80
80
  RouterTradeType["UnwrapWETH"] = "UnwrapWETH";
81
+ RouterTradeType["WrapSTETH"] = "WrapSTETH";
82
+ RouterTradeType["UnwrapSTETH"] = "UnwrapSTETH";
81
83
  })(exports.RouterTradeType || (exports.RouterTradeType = {}));
82
84
 
83
85
  var NFTTrade = function NFTTrade(market, orders) {
@@ -144,6 +146,8 @@ var CommandType;
144
146
  CommandType[CommandType["SEAPORT_V1_4"] = 32] = "SEAPORT_V1_4";
145
147
  CommandType[CommandType["EXECUTE_SUB_PLAN"] = 33] = "EXECUTE_SUB_PLAN";
146
148
  CommandType[CommandType["APPROVE_ERC20"] = 34] = "APPROVE_ERC20";
149
+ CommandType[CommandType["WRAP_STETH"] = 35] = "WRAP_STETH";
150
+ CommandType[CommandType["UNWRAP_STETH"] = 36] = "UNWRAP_STETH";
147
151
  })(CommandType || (CommandType = {}));
148
152
  var ALLOW_REVERT_FLAG = 0x80;
149
153
  var REVERTIBLE_COMMANDS = /*#__PURE__*/new Set([CommandType.SEAPORT_V1_5, CommandType.SEAPORT_V1_4, CommandType.NFTX, CommandType.LOOKS_RARE_V2, CommandType.X2Y2_721, CommandType.X2Y2_1155, CommandType.FOUNDATION, CommandType.SUDOSWAP, CommandType.NFT20, CommandType.EXECUTE_SUB_PLAN, CommandType.CRYPTOPUNKS, CommandType.ELEMENT_MARKET]);
@@ -151,7 +155,7 @@ var PERMIT_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 non
151
155
  var PERMIT_BATCH_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 nonce)[] details,address spender,uint256 sigDeadline)';
152
156
  var PERMIT2_TRANSFER_FROM_STRUCT = '(address from,address to,uint160 amount,address token)';
153
157
  var PERMIT2_TRANSFER_FROM_BATCH_STRUCT = PERMIT2_TRANSFER_FROM_STRUCT + '[]';
154
- var ABI_DEFINITION = (_ABI_DEFINITION = {}, _ABI_DEFINITION[CommandType.EXECUTE_SUB_PLAN] = ['bytes', 'bytes[]'], _ABI_DEFINITION[CommandType.PERMIT2_PERMIT] = [PERMIT_STRUCT, 'bytes'], _ABI_DEFINITION[CommandType.PERMIT2_PERMIT_BATCH] = [PERMIT_BATCH_STRUCT, 'bytes'], _ABI_DEFINITION[CommandType.PERMIT2_TRANSFER_FROM] = ['address', 'address', 'uint160'], _ABI_DEFINITION[CommandType.PERMIT2_TRANSFER_FROM_BATCH] = [PERMIT2_TRANSFER_FROM_BATCH_STRUCT], _ABI_DEFINITION[CommandType.V3_SWAP_EXACT_IN] = ['address', 'uint256', 'uint256', 'bytes', 'bool'], _ABI_DEFINITION[CommandType.V3_SWAP_EXACT_OUT] = ['address', 'uint256', 'uint256', 'bytes', 'bool'], _ABI_DEFINITION[CommandType.V2_SWAP_EXACT_IN] = ['address', 'uint256', 'uint256', 'address[]', 'bool'], _ABI_DEFINITION[CommandType.V2_SWAP_EXACT_OUT] = ['address', 'uint256', 'uint256', 'address[]', 'bool'], _ABI_DEFINITION[CommandType.WRAP_ETH] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.UNWRAP_WETH] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.SWEEP] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.SWEEP_ERC721] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.SWEEP_ERC1155] = ['address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[CommandType.TRANSFER] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.PAY_PORTION] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.BALANCE_CHECK_ERC20] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.OWNER_CHECK_721] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.OWNER_CHECK_1155] = ['address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[CommandType.APPROVE_ERC20] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.SEAPORT_V1_5] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.SEAPORT_V1_4] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.NFTX] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.LOOKS_RARE_V2] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.X2Y2_721] = ['uint256', 'bytes', 'address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.X2Y2_1155] = ['uint256', 'bytes', 'address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[CommandType.FOUNDATION] = ['uint256', 'bytes', 'address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.SUDOSWAP] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.NFT20] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.CRYPTOPUNKS] = ['uint256', 'address', 'uint256'], _ABI_DEFINITION[CommandType.ELEMENT_MARKET] = ['uint256', 'bytes'], _ABI_DEFINITION);
158
+ var ABI_DEFINITION = (_ABI_DEFINITION = {}, _ABI_DEFINITION[CommandType.EXECUTE_SUB_PLAN] = ['bytes', 'bytes[]'], _ABI_DEFINITION[CommandType.PERMIT2_PERMIT] = [PERMIT_STRUCT, 'bytes'], _ABI_DEFINITION[CommandType.PERMIT2_PERMIT_BATCH] = [PERMIT_BATCH_STRUCT, 'bytes'], _ABI_DEFINITION[CommandType.PERMIT2_TRANSFER_FROM] = ['address', 'address', 'uint160'], _ABI_DEFINITION[CommandType.PERMIT2_TRANSFER_FROM_BATCH] = [PERMIT2_TRANSFER_FROM_BATCH_STRUCT], _ABI_DEFINITION[CommandType.V3_SWAP_EXACT_IN] = ['address', 'uint256', 'uint256', 'bytes', 'bool'], _ABI_DEFINITION[CommandType.V3_SWAP_EXACT_OUT] = ['address', 'uint256', 'uint256', 'bytes', 'bool'], _ABI_DEFINITION[CommandType.V2_SWAP_EXACT_IN] = ['address', 'uint256', 'uint256', 'address[]', 'bool'], _ABI_DEFINITION[CommandType.V2_SWAP_EXACT_OUT] = ['address', 'uint256', 'uint256', 'address[]', 'bool'], _ABI_DEFINITION[CommandType.WRAP_ETH] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.UNWRAP_WETH] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.SWEEP] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.SWEEP_ERC721] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.SWEEP_ERC1155] = ['address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[CommandType.TRANSFER] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.PAY_PORTION] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.BALANCE_CHECK_ERC20] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.OWNER_CHECK_721] = ['address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.OWNER_CHECK_1155] = ['address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[CommandType.APPROVE_ERC20] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.WRAP_STETH] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.UNWRAP_STETH] = ['address', 'uint256'], _ABI_DEFINITION[CommandType.SEAPORT_V1_5] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.SEAPORT_V1_4] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.NFTX] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.LOOKS_RARE_V2] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.X2Y2_721] = ['uint256', 'bytes', 'address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.X2Y2_1155] = ['uint256', 'bytes', 'address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[CommandType.FOUNDATION] = ['uint256', 'bytes', 'address', 'address', 'uint256'], _ABI_DEFINITION[CommandType.SUDOSWAP] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.NFT20] = ['uint256', 'bytes'], _ABI_DEFINITION[CommandType.CRYPTOPUNKS] = ['uint256', 'address', 'uint256'], _ABI_DEFINITION[CommandType.ELEMENT_MARKET] = ['uint256', 'bytes'], _ABI_DEFINITION);
155
159
  var RoutePlanner = /*#__PURE__*/function () {
156
160
  function RoutePlanner() {
157
161
  this.commands = '0x';
@@ -186,67 +190,97 @@ function createCommand(type, parameters) {
186
190
  }
187
191
 
188
192
  var _CHAIN_CONFIGS;
189
- var WETH_NOT_SUPPORTED_ON_CHAIN = '0x0000000000000000000000000000000000000000';
193
+ var NOT_SUPPORTED_ON_CHAIN = '0x0000000000000000000000000000000000000000';
190
194
  var CHAIN_CONFIGS = (_CHAIN_CONFIGS = {}, _CHAIN_CONFIGS[1] = {
191
- router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
195
+ router: '0x3F6328669a86bef431Dc6F9201A5B90F7975a023',
192
196
  weth: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
197
+ steth: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84',
198
+ wsteth: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
193
199
  creationBlock: 17143817
194
200
  }, _CHAIN_CONFIGS[5] = {
195
- router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
201
+ router: '0x3F6328669a86bef431Dc6F9201A5B90F7975a023',
196
202
  weth: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
203
+ steth: '0x1643E812aE58766192Cf7D2Cf9567dF2C37e9B7F',
204
+ wsteth: '0x6320cD32aA674d2898A68ec82e869385Fc5f7E2f',
197
205
  creationBlock: 8940568
198
206
  }, _CHAIN_CONFIGS[11155111] = {
199
207
  router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
200
208
  weth: '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14',
209
+ steth: NOT_SUPPORTED_ON_CHAIN,
210
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
201
211
  creationBlock: 3543575
202
212
  }, _CHAIN_CONFIGS[137] = {
203
- router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
213
+ router: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
204
214
  weth: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
205
- creationBlock: 42294741
215
+ steth: NOT_SUPPORTED_ON_CHAIN,
216
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
217
+ creationBlock: 46866777
206
218
  }, _CHAIN_CONFIGS[80001] = {
207
219
  router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
208
220
  weth: '0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889',
221
+ steth: NOT_SUPPORTED_ON_CHAIN,
222
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
209
223
  creationBlock: 35176052
210
224
  }, _CHAIN_CONFIGS[10] = {
211
- router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
225
+ router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
212
226
  weth: '0x4200000000000000000000000000000000000006',
213
- creationBlock: 96333990
227
+ steth: NOT_SUPPORTED_ON_CHAIN,
228
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
229
+ creationBlock: 108825869
214
230
  }, _CHAIN_CONFIGS[420] = {
215
231
  router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
216
232
  weth: '0x4200000000000000000000000000000000000006',
233
+ steth: NOT_SUPPORTED_ON_CHAIN,
234
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
217
235
  creationBlock: 8887728
218
236
  }, _CHAIN_CONFIGS[42161] = {
219
- router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
237
+ router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
220
238
  weth: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
221
- creationBlock: 87206402
239
+ steth: NOT_SUPPORTED_ON_CHAIN,
240
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
241
+ creationBlock: 125861718
222
242
  }, _CHAIN_CONFIGS[421613] = {
223
243
  router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
224
244
  weth: '0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3',
245
+ steth: NOT_SUPPORTED_ON_CHAIN,
246
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
225
247
  creationBlock: 18815277
226
248
  }, _CHAIN_CONFIGS[42220] = {
227
- router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
228
- weth: WETH_NOT_SUPPORTED_ON_CHAIN,
229
- creationBlock: 19106929
249
+ router: '0x88a3ED7F21A3fCF6adb86b6F878C5B7a02D20e9b',
250
+ weth: NOT_SUPPORTED_ON_CHAIN,
251
+ steth: NOT_SUPPORTED_ON_CHAIN,
252
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
253
+ creationBlock: 21116361
230
254
  }, _CHAIN_CONFIGS[44787] = {
231
255
  router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
232
- weth: WETH_NOT_SUPPORTED_ON_CHAIN,
256
+ weth: NOT_SUPPORTED_ON_CHAIN,
257
+ steth: NOT_SUPPORTED_ON_CHAIN,
258
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
233
259
  creationBlock: 17566658
234
260
  }, _CHAIN_CONFIGS[56] = {
235
- router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
261
+ router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
236
262
  weth: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
237
- creationBlock: 27915533
263
+ steth: NOT_SUPPORTED_ON_CHAIN,
264
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
265
+ creationBlock: 31254967
238
266
  }, _CHAIN_CONFIGS[43114] = {
239
- router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
267
+ router: '0x82635AF6146972cD6601161c4472ffe97237D292',
240
268
  weth: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
241
- creationBlock: 31583684
269
+ steth: NOT_SUPPORTED_ON_CHAIN,
270
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
271
+ creationBlock: 34491144
242
272
  }, _CHAIN_CONFIGS[84531] = {
243
273
  router: '0xd0872d928672ae2ff74bdb2f5130ac12229cafaf',
244
274
  weth: '0x4200000000000000000000000000000000000006',
275
+ steth: NOT_SUPPORTED_ON_CHAIN,
276
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
245
277
  creationBlock: 6915289
246
278
  }, _CHAIN_CONFIGS[8453] = {
247
- router: '0x198EF79F1F515F02dFE9e3115eD9fC07183f02fC',
279
+ router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
248
280
  weth: '0x4200000000000000000000000000000000000006',
249
- creationBlock: 1452376
281
+ steth: NOT_SUPPORTED_ON_CHAIN,
282
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
283
+ creationBlock: 3229053
250
284
  }, _CHAIN_CONFIGS);
251
285
  var UNIVERSAL_ROUTER_ADDRESS = function UNIVERSAL_ROUTER_ADDRESS(chainId) {
252
286
  if (!(chainId in CHAIN_CONFIGS)) throw new Error("Universal Router not deployed on chain " + chainId);
@@ -258,9 +292,14 @@ var UNIVERSAL_ROUTER_CREATION_BLOCK = function UNIVERSAL_ROUTER_CREATION_BLOCK(c
258
292
  };
259
293
  var WETH_ADDRESS = function WETH_ADDRESS(chainId) {
260
294
  if (!(chainId in CHAIN_CONFIGS)) throw new Error("Universal Router not deployed on chain " + chainId);
261
- if (CHAIN_CONFIGS[chainId].weth == WETH_NOT_SUPPORTED_ON_CHAIN) throw new Error("Chain " + chainId + " does not have WETH");
295
+ if (CHAIN_CONFIGS[chainId].weth == NOT_SUPPORTED_ON_CHAIN) throw new Error("Chain " + chainId + " does not have WETH");
262
296
  return CHAIN_CONFIGS[chainId].weth;
263
297
  };
298
+ var STETH_ADDRESS = function STETH_ADDRESS(chainId) {
299
+ if (!(chainId in CHAIN_CONFIGS)) throw new Error("Universal Router not deployed on chain " + chainId);
300
+ if (CHAIN_CONFIGS[chainId].steth == NOT_SUPPORTED_ON_CHAIN) throw new Error("Chain " + chainId + " does not have STETH support");
301
+ return CHAIN_CONFIGS[chainId].steth;
302
+ };
264
303
  var PERMIT2_ADDRESS = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
265
304
  var CONTRACT_BALANCE = /*#__PURE__*/ethers.BigNumber.from(2).pow(255);
266
305
  var ETH_ADDRESS = '0x0000000000000000000000000000000000000000';
@@ -282,11 +321,12 @@ var UniswapTrade = /*#__PURE__*/function () {
282
321
  this.trade = trade;
283
322
  this.options = options;
284
323
  this.tradeType = exports.RouterTradeType.UniswapTrade;
324
+ if (!!options.fee && !!options.flatFee) throw new Error('Only one fee option permitted');
285
325
  }
286
326
  var _proto = UniswapTrade.prototype;
287
327
  _proto.encode = function encode(planner, _config) {
288
328
  var _this$options$recipie;
289
- var payerIsUser = true;
329
+ var payerIsUser = !this.options.payerIsRouter;
290
330
  // If the input currency is the native currency, we need to wrap it with the router as the recipient
291
331
  if (this.trade.inputAmount.currency.isNative) {
292
332
  // TODO: optimize if only one v2 pool we can directly send this to the pool
@@ -303,7 +343,7 @@ var UniswapTrade = /*#__PURE__*/function () {
303
343
  var performAggregatedSlippageCheck = this.trade.tradeType === sdkCore.TradeType.EXACT_INPUT && this.trade.routes.length > 2;
304
344
  var outputIsNative = this.trade.outputAmount.currency.isNative;
305
345
  var inputIsNative = this.trade.inputAmount.currency.isNative;
306
- var routerMustCustody = performAggregatedSlippageCheck || outputIsNative || !!this.options.fee;
346
+ var routerMustCustody = performAggregatedSlippageCheck || outputIsNative || hasFeeOption(this.options);
307
347
  for (var _iterator = _createForOfIteratorHelperLoose(this.trade.swaps), _step; !(_step = _iterator()).done;) {
308
348
  var swap = _step.value;
309
349
  switch (swap.route.protocol) {
@@ -334,6 +374,18 @@ var UniswapTrade = /*#__PURE__*/function () {
334
374
  minimumAmountOut = minimumAmountOut.sub(minimumAmountOut.mul(feeBips).div(10000));
335
375
  }
336
376
  }
377
+ // If there is a flat fee, that absolute amount is sent to the fee recipient
378
+ // In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
379
+ if (!!this.options.flatFee) {
380
+ var feeAmount = this.options.flatFee.amount;
381
+ if (minimumAmountOut.lt(feeAmount)) throw new Error('Flat fee amount greater than minimumAmountOut');
382
+ planner.addCommand(CommandType.TRANSFER, [this.trade.outputAmount.currency.wrapped.address, this.options.flatFee.recipient, feeAmount]);
383
+ // If the trade is exact output, and a fee was taken, we must adjust the amount out to be the amount after the fee
384
+ // Otherwise we continue as expected with the trade's normal expected output
385
+ if (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
386
+ minimumAmountOut = minimumAmountOut.sub(feeAmount);
387
+ }
388
+ }
337
389
  // The remaining tokens that need to be sent to the user after the fee is taken will be caught
338
390
  // by this if-else clause.
339
391
  if (outputIsNative) {
@@ -448,6 +500,9 @@ function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMust
448
500
  function riskOfPartialFill(trade) {
449
501
  return trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD);
450
502
  }
503
+ function hasFeeOption(swapOptions) {
504
+ return !!swapOptions.fee || !!swapOptions.flatFee;
505
+ }
451
506
 
452
507
  var SIGNATURE_LENGTH = 65;
453
508
  var EIP_2098_SIGNATURE_LENGTH = 64;
@@ -574,11 +629,18 @@ var SwapRouter = /*#__PURE__*/function () {
574
629
  allowRevert: false
575
630
  });
576
631
  currentNativeValueInRouter = currentNativeValueInRouter.add(UnwrapWETH.amount);
632
+ /**
633
+ * is (Un)WrapSTETH
634
+ */
635
+ } else if (trade.tradeType == exports.RouterTradeType.WrapSTETH || trade.tradeType == exports.RouterTradeType.UnwrapSTETH) {
636
+ trade.encode(planner, {
637
+ allowRevert: false
638
+ });
577
639
  /**
578
640
  * else
579
641
  */
580
642
  } else {
581
- throw 'trade must be of instance: UniswapTrade or NFTTrade';
643
+ throw 'trade must be of instance: UniswapTrade, NFTTrade, UnwrapWETH, WrapSTETH';
582
644
  }
583
645
  }
584
646
  // TODO: matches current logic for now, but should eventually only sweep for multiple NFT trades
@@ -10531,6 +10593,46 @@ var UnwrapWETH = /*#__PURE__*/function () {
10531
10593
  return UnwrapWETH;
10532
10594
  }();
10533
10595
 
10596
+ var WrapSTETH = /*#__PURE__*/function () {
10597
+ function WrapSTETH(amount, chainId, permit2, wrapAmount) {
10598
+ this.tradeType = exports.RouterTradeType.WrapSTETH;
10599
+ this.stethAddress = STETH_ADDRESS(chainId);
10600
+ this.amount = amount;
10601
+ this.wrapAmount = wrapAmount != null ? wrapAmount : CONTRACT_BALANCE;
10602
+ if (!!permit2) {
10603
+ !(permit2.details.token.toLowerCase() === this.stethAddress.toLowerCase()) ? invariant(false, "must be permitting STETH address: " + this.stethAddress) : void 0;
10604
+ !(permit2.details.amount >= amount) ? invariant(false, "Did not permit enough STETH for unwrapSTETH transaction") : void 0;
10605
+ this.permit2Data = permit2;
10606
+ }
10607
+ }
10608
+ var _proto = WrapSTETH.prototype;
10609
+ _proto.encode = function encode(planner, _) {
10610
+ encodeInputTokenOptions(planner, {
10611
+ permit2Permit: this.permit2Data,
10612
+ permit2TransferFrom: {
10613
+ token: this.stethAddress,
10614
+ amount: this.amount.toString()
10615
+ }
10616
+ });
10617
+ planner.addCommand(CommandType.WRAP_STETH, [ROUTER_AS_RECIPIENT, this.wrapAmount]);
10618
+ };
10619
+ return WrapSTETH;
10620
+ }();
10621
+
10622
+ var UnwrapSTETH = /*#__PURE__*/function () {
10623
+ function UnwrapSTETH(recipient, amountMinimum, chainId) {
10624
+ this.tradeType = exports.RouterTradeType.UnwrapSTETH;
10625
+ this.recipient = recipient;
10626
+ this.amountMinimum = amountMinimum;
10627
+ !(STETH_ADDRESS(chainId) != NOT_SUPPORTED_ON_CHAIN) ? invariant(false, "STETH not supported on chain " + chainId) : void 0;
10628
+ }
10629
+ var _proto = UnwrapSTETH.prototype;
10630
+ _proto.encode = function encode(planner, _) {
10631
+ planner.addCommand(CommandType.UNWRAP_STETH, [this.recipient, this.amountMinimum]);
10632
+ };
10633
+ return UnwrapSTETH;
10634
+ }();
10635
+
10534
10636
  exports.CryptopunkTrade = CryptopunkTrade;
10535
10637
  exports.FoundationTrade = FoundationTrade;
10536
10638
  exports.LooksRareV2Trade = LooksRareV2Trade;
@@ -10545,7 +10647,9 @@ exports.SwapRouter = SwapRouter;
10545
10647
  exports.UNIVERSAL_ROUTER_ADDRESS = UNIVERSAL_ROUTER_ADDRESS;
10546
10648
  exports.UNIVERSAL_ROUTER_CREATION_BLOCK = UNIVERSAL_ROUTER_CREATION_BLOCK;
10547
10649
  exports.UniswapTrade = UniswapTrade;
10650
+ exports.UnwrapSTETH = UnwrapSTETH;
10548
10651
  exports.UnwrapWETH = UnwrapWETH;
10549
10652
  exports.WETH_ADDRESS = WETH_ADDRESS;
10653
+ exports.WrapSTETH = WrapSTETH;
10550
10654
  exports.X2Y2Trade = X2Y2Trade;
10551
10655
  //# sourceMappingURL=universal-router-sdk.cjs.development.js.map