@uniswap/universal-router-sdk 1.5.8 → 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';
@@ -10,6 +10,7 @@ export declare type FlatFeeOptions = {
10
10
  };
11
11
  export declare type SwapOptions = Omit<RouterSwapOptions, 'inputTokenPermit'> & {
12
12
  inputTokenPermit?: Permit2Permit;
13
+ payerIsRouter?: boolean;
13
14
  flatFee?: FlatFeeOptions;
14
15
  };
15
16
  export declare class UniswapTrade implements Command {
@@ -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,66 +190,96 @@ 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
213
  router: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
204
214
  weth: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
215
+ steth: NOT_SUPPORTED_ON_CHAIN,
216
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
205
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
225
  router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
212
226
  weth: '0x4200000000000000000000000000000000000006',
227
+ steth: NOT_SUPPORTED_ON_CHAIN,
228
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
213
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
237
  router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
220
238
  weth: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
239
+ steth: NOT_SUPPORTED_ON_CHAIN,
240
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
221
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
249
  router: '0x88a3ED7F21A3fCF6adb86b6F878C5B7a02D20e9b',
228
- weth: WETH_NOT_SUPPORTED_ON_CHAIN,
250
+ weth: NOT_SUPPORTED_ON_CHAIN,
251
+ steth: NOT_SUPPORTED_ON_CHAIN,
252
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
229
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
261
  router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
236
262
  weth: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
263
+ steth: NOT_SUPPORTED_ON_CHAIN,
264
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
237
265
  creationBlock: 31254967
238
266
  }, _CHAIN_CONFIGS[43114] = {
239
267
  router: '0x82635AF6146972cD6601161c4472ffe97237D292',
240
268
  weth: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
269
+ steth: NOT_SUPPORTED_ON_CHAIN,
270
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
241
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
279
  router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
248
280
  weth: '0x4200000000000000000000000000000000000006',
281
+ steth: NOT_SUPPORTED_ON_CHAIN,
282
+ wsteth: NOT_SUPPORTED_ON_CHAIN,
249
283
  creationBlock: 3229053
250
284
  }, _CHAIN_CONFIGS);
251
285
  var UNIVERSAL_ROUTER_ADDRESS = function UNIVERSAL_ROUTER_ADDRESS(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';
@@ -287,7 +326,7 @@ var UniswapTrade = /*#__PURE__*/function () {
287
326
  var _proto = UniswapTrade.prototype;
288
327
  _proto.encode = function encode(planner, _config) {
289
328
  var _this$options$recipie;
290
- var payerIsUser = true;
329
+ var payerIsUser = !this.options.payerIsRouter;
291
330
  // If the input currency is the native currency, we need to wrap it with the router as the recipient
292
331
  if (this.trade.inputAmount.currency.isNative) {
293
332
  // TODO: optimize if only one v2 pool we can directly send this to the pool
@@ -590,11 +629,18 @@ var SwapRouter = /*#__PURE__*/function () {
590
629
  allowRevert: false
591
630
  });
592
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
+ });
593
639
  /**
594
640
  * else
595
641
  */
596
642
  } else {
597
- throw 'trade must be of instance: UniswapTrade or NFTTrade';
643
+ throw 'trade must be of instance: UniswapTrade, NFTTrade, UnwrapWETH, WrapSTETH';
598
644
  }
599
645
  }
600
646
  // TODO: matches current logic for now, but should eventually only sweep for multiple NFT trades
@@ -10547,6 +10593,46 @@ var UnwrapWETH = /*#__PURE__*/function () {
10547
10593
  return UnwrapWETH;
10548
10594
  }();
10549
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
+
10550
10636
  exports.CryptopunkTrade = CryptopunkTrade;
10551
10637
  exports.FoundationTrade = FoundationTrade;
10552
10638
  exports.LooksRareV2Trade = LooksRareV2Trade;
@@ -10561,7 +10647,9 @@ exports.SwapRouter = SwapRouter;
10561
10647
  exports.UNIVERSAL_ROUTER_ADDRESS = UNIVERSAL_ROUTER_ADDRESS;
10562
10648
  exports.UNIVERSAL_ROUTER_CREATION_BLOCK = UNIVERSAL_ROUTER_CREATION_BLOCK;
10563
10649
  exports.UniswapTrade = UniswapTrade;
10650
+ exports.UnwrapSTETH = UnwrapSTETH;
10564
10651
  exports.UnwrapWETH = UnwrapWETH;
10565
10652
  exports.WETH_ADDRESS = WETH_ADDRESS;
10653
+ exports.WrapSTETH = WrapSTETH;
10566
10654
  exports.X2Y2Trade = X2Y2Trade;
10567
10655
  //# sourceMappingURL=universal-router-sdk.cjs.development.js.map