@uniswap/universal-router-sdk 1.5.8 → 2.0.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.
- package/README.md +57 -0
- package/dist/entities/Command.d.ts +3 -1
- package/dist/entities/protocols/index.d.ts +2 -0
- package/dist/entities/protocols/uniswap.d.ts +1 -0
- package/dist/entities/protocols/unwrapSTETH.d.ts +10 -0
- package/dist/entities/protocols/wrapSTETH.d.ts +13 -0
- package/dist/index.d.ts +1 -0
- package/dist/universal-router-sdk.cjs.development.js +129 -46
- package/dist/universal-router-sdk.cjs.development.js.map +1 -1
- package/dist/universal-router-sdk.cjs.production.min.js +1 -1
- package/dist/universal-router-sdk.cjs.production.min.js.map +1 -1
- package/dist/universal-router-sdk.esm.js +96 -10
- package/dist/universal-router-sdk.esm.js.map +1 -1
- package/dist/utils/constants.d.ts +3 -0
- package/dist/utils/routerCommands.d.ts +3 -1
- package/package.json +2 -2
- package/dist/test/utils/uniswapData.d.ts +0 -23
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;
|
|
@@ -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
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { SwapRouter } from './swapRouter';
|
|
2
2
|
export * from './entities';
|
|
3
|
+
export { RoutePlanner, CommandType } from './utils/routerCommands';
|
|
3
4
|
export { UNIVERSAL_ROUTER_ADDRESS, UNIVERSAL_ROUTER_CREATION_BLOCK, PERMIT2_ADDRESS, ROUTER_AS_RECIPIENT, WETH_ADDRESS, } from './utils/constants';
|
|
@@ -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) {
|
|
@@ -104,12 +106,6 @@ var NFTTrade = function NFTTrade(market, orders) {
|
|
|
104
106
|
})(exports.TokenType || (exports.TokenType = {}));
|
|
105
107
|
|
|
106
108
|
var _ABI_DEFINITION;
|
|
107
|
-
/**
|
|
108
|
-
* CommandTypes
|
|
109
|
-
* @description Flags that modify a command's execution
|
|
110
|
-
* @enum {number}
|
|
111
|
-
*/
|
|
112
|
-
var CommandType;
|
|
113
109
|
(function (CommandType) {
|
|
114
110
|
CommandType[CommandType["V3_SWAP_EXACT_IN"] = 0] = "V3_SWAP_EXACT_IN";
|
|
115
111
|
CommandType[CommandType["V3_SWAP_EXACT_OUT"] = 1] = "V3_SWAP_EXACT_OUT";
|
|
@@ -144,14 +140,16 @@ var CommandType;
|
|
|
144
140
|
CommandType[CommandType["SEAPORT_V1_4"] = 32] = "SEAPORT_V1_4";
|
|
145
141
|
CommandType[CommandType["EXECUTE_SUB_PLAN"] = 33] = "EXECUTE_SUB_PLAN";
|
|
146
142
|
CommandType[CommandType["APPROVE_ERC20"] = 34] = "APPROVE_ERC20";
|
|
147
|
-
|
|
143
|
+
CommandType[CommandType["WRAP_STETH"] = 35] = "WRAP_STETH";
|
|
144
|
+
CommandType[CommandType["UNWRAP_STETH"] = 36] = "UNWRAP_STETH";
|
|
145
|
+
})(exports.CommandType || (exports.CommandType = {}));
|
|
148
146
|
var ALLOW_REVERT_FLAG = 0x80;
|
|
149
|
-
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]);
|
|
147
|
+
var REVERTIBLE_COMMANDS = /*#__PURE__*/new Set([exports.CommandType.SEAPORT_V1_5, exports.CommandType.SEAPORT_V1_4, exports.CommandType.NFTX, exports.CommandType.LOOKS_RARE_V2, exports.CommandType.X2Y2_721, exports.CommandType.X2Y2_1155, exports.CommandType.FOUNDATION, exports.CommandType.SUDOSWAP, exports.CommandType.NFT20, exports.CommandType.EXECUTE_SUB_PLAN, exports.CommandType.CRYPTOPUNKS, exports.CommandType.ELEMENT_MARKET]);
|
|
150
148
|
var PERMIT_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 nonce) details,address spender,uint256 sigDeadline)';
|
|
151
149
|
var PERMIT_BATCH_STRUCT = '((address token,uint160 amount,uint48 expiration,uint48 nonce)[] details,address spender,uint256 sigDeadline)';
|
|
152
150
|
var PERMIT2_TRANSFER_FROM_STRUCT = '(address from,address to,uint160 amount,address token)';
|
|
153
151
|
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);
|
|
152
|
+
var ABI_DEFINITION = (_ABI_DEFINITION = {}, _ABI_DEFINITION[exports.CommandType.EXECUTE_SUB_PLAN] = ['bytes', 'bytes[]'], _ABI_DEFINITION[exports.CommandType.PERMIT2_PERMIT] = [PERMIT_STRUCT, 'bytes'], _ABI_DEFINITION[exports.CommandType.PERMIT2_PERMIT_BATCH] = [PERMIT_BATCH_STRUCT, 'bytes'], _ABI_DEFINITION[exports.CommandType.PERMIT2_TRANSFER_FROM] = ['address', 'address', 'uint160'], _ABI_DEFINITION[exports.CommandType.PERMIT2_TRANSFER_FROM_BATCH] = [PERMIT2_TRANSFER_FROM_BATCH_STRUCT], _ABI_DEFINITION[exports.CommandType.V3_SWAP_EXACT_IN] = ['address', 'uint256', 'uint256', 'bytes', 'bool'], _ABI_DEFINITION[exports.CommandType.V3_SWAP_EXACT_OUT] = ['address', 'uint256', 'uint256', 'bytes', 'bool'], _ABI_DEFINITION[exports.CommandType.V2_SWAP_EXACT_IN] = ['address', 'uint256', 'uint256', 'address[]', 'bool'], _ABI_DEFINITION[exports.CommandType.V2_SWAP_EXACT_OUT] = ['address', 'uint256', 'uint256', 'address[]', 'bool'], _ABI_DEFINITION[exports.CommandType.WRAP_ETH] = ['address', 'uint256'], _ABI_DEFINITION[exports.CommandType.UNWRAP_WETH] = ['address', 'uint256'], _ABI_DEFINITION[exports.CommandType.SWEEP] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.SWEEP_ERC721] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.SWEEP_ERC1155] = ['address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[exports.CommandType.TRANSFER] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.PAY_PORTION] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.BALANCE_CHECK_ERC20] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.OWNER_CHECK_721] = ['address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.OWNER_CHECK_1155] = ['address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[exports.CommandType.APPROVE_ERC20] = ['address', 'uint256'], _ABI_DEFINITION[exports.CommandType.WRAP_STETH] = ['address', 'uint256'], _ABI_DEFINITION[exports.CommandType.UNWRAP_STETH] = ['address', 'uint256'], _ABI_DEFINITION[exports.CommandType.SEAPORT_V1_5] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.SEAPORT_V1_4] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.NFTX] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.LOOKS_RARE_V2] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.X2Y2_721] = ['uint256', 'bytes', 'address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.X2Y2_1155] = ['uint256', 'bytes', 'address', 'address', 'uint256', 'uint256'], _ABI_DEFINITION[exports.CommandType.FOUNDATION] = ['uint256', 'bytes', 'address', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.SUDOSWAP] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.NFT20] = ['uint256', 'bytes'], _ABI_DEFINITION[exports.CommandType.CRYPTOPUNKS] = ['uint256', 'address', 'uint256'], _ABI_DEFINITION[exports.CommandType.ELEMENT_MARKET] = ['uint256', 'bytes'], _ABI_DEFINITION);
|
|
155
153
|
var RoutePlanner = /*#__PURE__*/function () {
|
|
156
154
|
function RoutePlanner() {
|
|
157
155
|
this.commands = '0x';
|
|
@@ -159,7 +157,7 @@ var RoutePlanner = /*#__PURE__*/function () {
|
|
|
159
157
|
}
|
|
160
158
|
var _proto = RoutePlanner.prototype;
|
|
161
159
|
_proto.addSubPlan = function addSubPlan(subplan) {
|
|
162
|
-
this.addCommand(CommandType.EXECUTE_SUB_PLAN, [subplan.commands, subplan.inputs], true);
|
|
160
|
+
this.addCommand(exports.CommandType.EXECUTE_SUB_PLAN, [subplan.commands, subplan.inputs], true);
|
|
163
161
|
};
|
|
164
162
|
_proto.addCommand = function addCommand(type, parameters, allowRevert) {
|
|
165
163
|
if (allowRevert === void 0) {
|
|
@@ -186,66 +184,96 @@ function createCommand(type, parameters) {
|
|
|
186
184
|
}
|
|
187
185
|
|
|
188
186
|
var _CHAIN_CONFIGS;
|
|
189
|
-
var
|
|
187
|
+
var NOT_SUPPORTED_ON_CHAIN = '0x0000000000000000000000000000000000000000';
|
|
190
188
|
var CHAIN_CONFIGS = (_CHAIN_CONFIGS = {}, _CHAIN_CONFIGS[1] = {
|
|
191
|
-
router: '
|
|
189
|
+
router: '0x3F6328669a86bef431Dc6F9201A5B90F7975a023',
|
|
192
190
|
weth: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
191
|
+
steth: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84',
|
|
192
|
+
wsteth: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
193
193
|
creationBlock: 17143817
|
|
194
194
|
}, _CHAIN_CONFIGS[5] = {
|
|
195
|
-
router: '
|
|
195
|
+
router: '0x3F6328669a86bef431Dc6F9201A5B90F7975a023',
|
|
196
196
|
weth: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
|
|
197
|
+
steth: '0x1643E812aE58766192Cf7D2Cf9567dF2C37e9B7F',
|
|
198
|
+
wsteth: '0x6320cD32aA674d2898A68ec82e869385Fc5f7E2f',
|
|
197
199
|
creationBlock: 8940568
|
|
198
200
|
}, _CHAIN_CONFIGS[11155111] = {
|
|
199
201
|
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
|
|
200
202
|
weth: '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14',
|
|
203
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
204
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
201
205
|
creationBlock: 3543575
|
|
202
206
|
}, _CHAIN_CONFIGS[137] = {
|
|
203
207
|
router: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
|
|
204
208
|
weth: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
|
|
209
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
210
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
205
211
|
creationBlock: 46866777
|
|
206
212
|
}, _CHAIN_CONFIGS[80001] = {
|
|
207
213
|
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
|
|
208
214
|
weth: '0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889',
|
|
215
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
216
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
209
217
|
creationBlock: 35176052
|
|
210
218
|
}, _CHAIN_CONFIGS[10] = {
|
|
211
219
|
router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
|
|
212
220
|
weth: '0x4200000000000000000000000000000000000006',
|
|
221
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
222
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
213
223
|
creationBlock: 108825869
|
|
214
224
|
}, _CHAIN_CONFIGS[420] = {
|
|
215
225
|
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
|
|
216
226
|
weth: '0x4200000000000000000000000000000000000006',
|
|
227
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
228
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
217
229
|
creationBlock: 8887728
|
|
218
230
|
}, _CHAIN_CONFIGS[42161] = {
|
|
219
231
|
router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
|
|
220
232
|
weth: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
|
|
233
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
234
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
221
235
|
creationBlock: 125861718
|
|
222
236
|
}, _CHAIN_CONFIGS[421613] = {
|
|
223
237
|
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
|
|
224
238
|
weth: '0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3',
|
|
239
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
240
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
225
241
|
creationBlock: 18815277
|
|
226
242
|
}, _CHAIN_CONFIGS[42220] = {
|
|
227
243
|
router: '0x88a3ED7F21A3fCF6adb86b6F878C5B7a02D20e9b',
|
|
228
|
-
weth:
|
|
244
|
+
weth: NOT_SUPPORTED_ON_CHAIN,
|
|
245
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
246
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
229
247
|
creationBlock: 21116361
|
|
230
248
|
}, _CHAIN_CONFIGS[44787] = {
|
|
231
249
|
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
|
|
232
|
-
weth:
|
|
250
|
+
weth: NOT_SUPPORTED_ON_CHAIN,
|
|
251
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
252
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
233
253
|
creationBlock: 17566658
|
|
234
254
|
}, _CHAIN_CONFIGS[56] = {
|
|
235
255
|
router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
|
|
236
256
|
weth: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
|
|
257
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
258
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
237
259
|
creationBlock: 31254967
|
|
238
260
|
}, _CHAIN_CONFIGS[43114] = {
|
|
239
261
|
router: '0x82635AF6146972cD6601161c4472ffe97237D292',
|
|
240
262
|
weth: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
|
|
263
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
264
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
241
265
|
creationBlock: 34491144
|
|
242
266
|
}, _CHAIN_CONFIGS[84531] = {
|
|
243
267
|
router: '0xd0872d928672ae2ff74bdb2f5130ac12229cafaf',
|
|
244
268
|
weth: '0x4200000000000000000000000000000000000006',
|
|
269
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
270
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
245
271
|
creationBlock: 6915289
|
|
246
272
|
}, _CHAIN_CONFIGS[8453] = {
|
|
247
273
|
router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
|
|
248
274
|
weth: '0x4200000000000000000000000000000000000006',
|
|
275
|
+
steth: NOT_SUPPORTED_ON_CHAIN,
|
|
276
|
+
wsteth: NOT_SUPPORTED_ON_CHAIN,
|
|
249
277
|
creationBlock: 3229053
|
|
250
278
|
}, _CHAIN_CONFIGS);
|
|
251
279
|
var UNIVERSAL_ROUTER_ADDRESS = function UNIVERSAL_ROUTER_ADDRESS(chainId) {
|
|
@@ -258,9 +286,14 @@ var UNIVERSAL_ROUTER_CREATION_BLOCK = function UNIVERSAL_ROUTER_CREATION_BLOCK(c
|
|
|
258
286
|
};
|
|
259
287
|
var WETH_ADDRESS = function WETH_ADDRESS(chainId) {
|
|
260
288
|
if (!(chainId in CHAIN_CONFIGS)) throw new Error("Universal Router not deployed on chain " + chainId);
|
|
261
|
-
if (CHAIN_CONFIGS[chainId].weth ==
|
|
289
|
+
if (CHAIN_CONFIGS[chainId].weth == NOT_SUPPORTED_ON_CHAIN) throw new Error("Chain " + chainId + " does not have WETH");
|
|
262
290
|
return CHAIN_CONFIGS[chainId].weth;
|
|
263
291
|
};
|
|
292
|
+
var STETH_ADDRESS = function STETH_ADDRESS(chainId) {
|
|
293
|
+
if (!(chainId in CHAIN_CONFIGS)) throw new Error("Universal Router not deployed on chain " + chainId);
|
|
294
|
+
if (CHAIN_CONFIGS[chainId].steth == NOT_SUPPORTED_ON_CHAIN) throw new Error("Chain " + chainId + " does not have STETH support");
|
|
295
|
+
return CHAIN_CONFIGS[chainId].steth;
|
|
296
|
+
};
|
|
264
297
|
var PERMIT2_ADDRESS = '0x000000000022D473030F116dDEE9F6B43aC78BA3';
|
|
265
298
|
var CONTRACT_BALANCE = /*#__PURE__*/ethers.BigNumber.from(2).pow(255);
|
|
266
299
|
var ETH_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
@@ -287,11 +320,11 @@ var UniswapTrade = /*#__PURE__*/function () {
|
|
|
287
320
|
var _proto = UniswapTrade.prototype;
|
|
288
321
|
_proto.encode = function encode(planner, _config) {
|
|
289
322
|
var _this$options$recipie;
|
|
290
|
-
var payerIsUser =
|
|
323
|
+
var payerIsUser = !this.options.payerIsRouter;
|
|
291
324
|
// If the input currency is the native currency, we need to wrap it with the router as the recipient
|
|
292
325
|
if (this.trade.inputAmount.currency.isNative) {
|
|
293
326
|
// TODO: optimize if only one v2 pool we can directly send this to the pool
|
|
294
|
-
planner.addCommand(CommandType.WRAP_ETH, [ROUTER_AS_RECIPIENT, this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString()]);
|
|
327
|
+
planner.addCommand(exports.CommandType.WRAP_ETH, [ROUTER_AS_RECIPIENT, this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString()]);
|
|
295
328
|
// since WETH is now owned by the router, the router pays for inputs
|
|
296
329
|
payerIsUser = false;
|
|
297
330
|
}
|
|
@@ -328,7 +361,7 @@ var UniswapTrade = /*#__PURE__*/function () {
|
|
|
328
361
|
// In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
|
|
329
362
|
if (!!this.options.fee) {
|
|
330
363
|
var feeBips = encodeFeeBips(this.options.fee.fee);
|
|
331
|
-
planner.addCommand(CommandType.PAY_PORTION, [this.trade.outputAmount.currency.wrapped.address, this.options.fee.recipient, feeBips]);
|
|
364
|
+
planner.addCommand(exports.CommandType.PAY_PORTION, [this.trade.outputAmount.currency.wrapped.address, this.options.fee.recipient, feeBips]);
|
|
332
365
|
// If the trade is exact output, and a fee was taken, we must adjust the amount out to be the amount after the fee
|
|
333
366
|
// Otherwise we continue as expected with the trade's normal expected output
|
|
334
367
|
if (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
|
|
@@ -340,7 +373,7 @@ var UniswapTrade = /*#__PURE__*/function () {
|
|
|
340
373
|
if (!!this.options.flatFee) {
|
|
341
374
|
var feeAmount = this.options.flatFee.amount;
|
|
342
375
|
if (minimumAmountOut.lt(feeAmount)) throw new Error('Flat fee amount greater than minimumAmountOut');
|
|
343
|
-
planner.addCommand(CommandType.TRANSFER, [this.trade.outputAmount.currency.wrapped.address, this.options.flatFee.recipient, feeAmount]);
|
|
376
|
+
planner.addCommand(exports.CommandType.TRANSFER, [this.trade.outputAmount.currency.wrapped.address, this.options.flatFee.recipient, feeAmount]);
|
|
344
377
|
// If the trade is exact output, and a fee was taken, we must adjust the amount out to be the amount after the fee
|
|
345
378
|
// Otherwise we continue as expected with the trade's normal expected output
|
|
346
379
|
if (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
|
|
@@ -350,15 +383,15 @@ var UniswapTrade = /*#__PURE__*/function () {
|
|
|
350
383
|
// The remaining tokens that need to be sent to the user after the fee is taken will be caught
|
|
351
384
|
// by this if-else clause.
|
|
352
385
|
if (outputIsNative) {
|
|
353
|
-
planner.addCommand(CommandType.UNWRAP_WETH, [this.options.recipient, minimumAmountOut]);
|
|
386
|
+
planner.addCommand(exports.CommandType.UNWRAP_WETH, [this.options.recipient, minimumAmountOut]);
|
|
354
387
|
} else {
|
|
355
|
-
planner.addCommand(CommandType.SWEEP, [this.trade.outputAmount.currency.wrapped.address, this.options.recipient, minimumAmountOut]);
|
|
388
|
+
planner.addCommand(exports.CommandType.SWEEP, [this.trade.outputAmount.currency.wrapped.address, this.options.recipient, minimumAmountOut]);
|
|
356
389
|
}
|
|
357
390
|
}
|
|
358
391
|
if (inputIsNative && (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT || riskOfPartialFill(this.trade))) {
|
|
359
392
|
// for exactOutput swaps that take native currency as input
|
|
360
393
|
// we need to send back the change to the user
|
|
361
|
-
planner.addCommand(CommandType.UNWRAP_WETH, [this.options.recipient, 0]);
|
|
394
|
+
planner.addCommand(exports.CommandType.UNWRAP_WETH, [this.options.recipient, 0]);
|
|
362
395
|
}
|
|
363
396
|
};
|
|
364
397
|
return UniswapTrade;
|
|
@@ -370,13 +403,13 @@ function addV2Swap(planner, _ref, tradeType, options, payerIsUser, routerMustCus
|
|
|
370
403
|
outputAmount = _ref.outputAmount;
|
|
371
404
|
var trade = new v2Sdk.Trade(route, tradeType == sdkCore.TradeType.EXACT_INPUT ? inputAmount : outputAmount, tradeType);
|
|
372
405
|
if (tradeType == sdkCore.TradeType.EXACT_INPUT) {
|
|
373
|
-
planner.addCommand(CommandType.V2_SWAP_EXACT_IN, [
|
|
406
|
+
planner.addCommand(exports.CommandType.V2_SWAP_EXACT_IN, [
|
|
374
407
|
// if native, we have to unwrap so keep in the router for now
|
|
375
408
|
routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), route.path.map(function (pool) {
|
|
376
409
|
return pool.address;
|
|
377
410
|
}), payerIsUser]);
|
|
378
411
|
} else if (tradeType == sdkCore.TradeType.EXACT_OUTPUT) {
|
|
379
|
-
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 (pool) {
|
|
412
|
+
planner.addCommand(exports.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 (pool) {
|
|
380
413
|
return pool.address;
|
|
381
414
|
}), payerIsUser]);
|
|
382
415
|
}
|
|
@@ -394,9 +427,9 @@ function addV3Swap(planner, _ref2, tradeType, options, payerIsUser, routerMustCu
|
|
|
394
427
|
});
|
|
395
428
|
var path = v3Sdk.encodeRouteToPath(route, trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT);
|
|
396
429
|
if (tradeType == sdkCore.TradeType.EXACT_INPUT) {
|
|
397
|
-
planner.addCommand(CommandType.V3_SWAP_EXACT_IN, [routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), path, payerIsUser]);
|
|
430
|
+
planner.addCommand(exports.CommandType.V3_SWAP_EXACT_IN, [routerMustCustody ? ROUTER_AS_RECIPIENT : options.recipient, trade.maximumAmountIn(options.slippageTolerance).quotient.toString(), trade.minimumAmountOut(options.slippageTolerance).quotient.toString(), path, payerIsUser]);
|
|
398
431
|
} else if (tradeType == sdkCore.TradeType.EXACT_OUTPUT) {
|
|
399
|
-
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]);
|
|
432
|
+
planner.addCommand(exports.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]);
|
|
400
433
|
}
|
|
401
434
|
}
|
|
402
435
|
// encode a mixed route swap, i.e. including both v2 and v3 pools
|
|
@@ -446,12 +479,12 @@ function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMust
|
|
|
446
479
|
};
|
|
447
480
|
if (mixedRouteIsAllV3(newRoute)) {
|
|
448
481
|
var path = routerSdk.encodeMixedRouteToPath(newRoute);
|
|
449
|
-
planner.addCommand(CommandType.V3_SWAP_EXACT_IN, [
|
|
482
|
+
planner.addCommand(exports.CommandType.V3_SWAP_EXACT_IN, [
|
|
450
483
|
// if not last section: send tokens directly to the first v2 pair of the next section
|
|
451
484
|
// note: because of the partitioning function we can be sure that the next section is v2
|
|
452
485
|
isLastSectionInRoute(i) ? tradeRecipient : sections[i + 1][0].liquidityToken.address, i == 0 ? amountIn : CONTRACT_BALANCE, !isLastSectionInRoute(i) ? 0 : amountOut, path, payerIsUser && i === 0]);
|
|
453
486
|
} else {
|
|
454
|
-
planner.addCommand(CommandType.V2_SWAP_EXACT_IN, [isLastSectionInRoute(i) ? tradeRecipient : ROUTER_AS_RECIPIENT, i === 0 ? amountIn : CONTRACT_BALANCE, !isLastSectionInRoute(i) ? 0 : amountOut, newRoute.path.map(function (pool) {
|
|
487
|
+
planner.addCommand(exports.CommandType.V2_SWAP_EXACT_IN, [isLastSectionInRoute(i) ? tradeRecipient : ROUTER_AS_RECIPIENT, i === 0 ? amountIn : CONTRACT_BALANCE, !isLastSectionInRoute(i) ? 0 : amountOut, newRoute.path.map(function (pool) {
|
|
455
488
|
return pool.address;
|
|
456
489
|
}), payerIsUser && i === 0]);
|
|
457
490
|
}
|
|
@@ -475,7 +508,7 @@ function encodePermit(planner, permit2) {
|
|
|
475
508
|
// sanitizes signature to cover edge cases of malformed EIP-2098 sigs and v used as recovery id
|
|
476
509
|
signature = ethers.ethers.utils.joinSignature(ethers.ethers.utils.splitSignature(permit2.signature));
|
|
477
510
|
}
|
|
478
|
-
planner.addCommand(CommandType.PERMIT2_PERMIT, [permit2, signature]);
|
|
511
|
+
planner.addCommand(exports.CommandType.PERMIT2_PERMIT, [permit2, signature]);
|
|
479
512
|
}
|
|
480
513
|
// Handles the encoding of commands needed to gather input tokens for a trade
|
|
481
514
|
// Approval: The router approving another address to take tokens.
|
|
@@ -489,14 +522,14 @@ function encodeInputTokenOptions(planner, options) {
|
|
|
489
522
|
if (!!options.permit2TransferFrom && !!options.permit2Permit) !(options.permit2TransferFrom.token === options.permit2Permit.details.token) ? invariant(false, "inconsistent token") : void 0;
|
|
490
523
|
// if an options.approval is required, add it
|
|
491
524
|
if (!!options.approval) {
|
|
492
|
-
planner.addCommand(CommandType.APPROVE_ERC20, [options.approval.token, mapApprovalProtocol(options.approval.protocol)]);
|
|
525
|
+
planner.addCommand(exports.CommandType.APPROVE_ERC20, [options.approval.token, mapApprovalProtocol(options.approval.protocol)]);
|
|
493
526
|
}
|
|
494
527
|
// if this order has a options.permit2Permit, encode it
|
|
495
528
|
if (!!options.permit2Permit) {
|
|
496
529
|
encodePermit(planner, options.permit2Permit);
|
|
497
530
|
}
|
|
498
531
|
if (!!options.permit2TransferFrom) {
|
|
499
|
-
planner.addCommand(CommandType.PERMIT2_TRANSFER_FROM, [options.permit2TransferFrom.token, options.permit2TransferFrom.recipient ? options.permit2TransferFrom.recipient : ROUTER_AS_RECIPIENT, options.permit2TransferFrom.amount]);
|
|
532
|
+
planner.addCommand(exports.CommandType.PERMIT2_TRANSFER_FROM, [options.permit2TransferFrom.token, options.permit2TransferFrom.recipient ? options.permit2TransferFrom.recipient : ROUTER_AS_RECIPIENT, options.permit2TransferFrom.amount]);
|
|
500
533
|
}
|
|
501
534
|
}
|
|
502
535
|
function mapApprovalProtocol(protocolAddress) {
|
|
@@ -590,18 +623,25 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
590
623
|
allowRevert: false
|
|
591
624
|
});
|
|
592
625
|
currentNativeValueInRouter = currentNativeValueInRouter.add(UnwrapWETH.amount);
|
|
626
|
+
/**
|
|
627
|
+
* is (Un)WrapSTETH
|
|
628
|
+
*/
|
|
629
|
+
} else if (trade.tradeType == exports.RouterTradeType.WrapSTETH || trade.tradeType == exports.RouterTradeType.UnwrapSTETH) {
|
|
630
|
+
trade.encode(planner, {
|
|
631
|
+
allowRevert: false
|
|
632
|
+
});
|
|
593
633
|
/**
|
|
594
634
|
* else
|
|
595
635
|
*/
|
|
596
636
|
} else {
|
|
597
|
-
throw 'trade must be of instance: UniswapTrade
|
|
637
|
+
throw 'trade must be of instance: UniswapTrade, NFTTrade, UnwrapWETH, WrapSTETH';
|
|
598
638
|
}
|
|
599
639
|
}
|
|
600
640
|
// TODO: matches current logic for now, but should eventually only sweep for multiple NFT trades
|
|
601
641
|
// or NFT trades with potential slippage (i.e. sudo).
|
|
602
642
|
// Note: NFTXV2 sends excess ETH to the caller (router), not the specified recipient
|
|
603
643
|
nftInputTokens.forEach(function (inputToken) {
|
|
604
|
-
planner.addCommand(CommandType.SWEEP, [inputToken, SENDER_AS_RECIPIENT, 0]);
|
|
644
|
+
planner.addCommand(exports.CommandType.SWEEP, [inputToken, SENDER_AS_RECIPIENT, 0]);
|
|
605
645
|
});
|
|
606
646
|
return SwapRouter.encodePlan(planner, transactionValue, config);
|
|
607
647
|
}
|
|
@@ -625,7 +665,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
625
665
|
});
|
|
626
666
|
totalPrice = totalPrice.add(trade.getTotalPrice());
|
|
627
667
|
}
|
|
628
|
-
planner.addCommand(CommandType.SWEEP, [ETH_ADDRESS, SENDER_AS_RECIPIENT, 0]);
|
|
668
|
+
planner.addCommand(exports.CommandType.SWEEP, [ETH_ADDRESS, SENDER_AS_RECIPIENT, 0]);
|
|
629
669
|
return SwapRouter.encodePlan(planner, totalPrice, config);
|
|
630
670
|
}
|
|
631
671
|
/**
|
|
@@ -684,7 +724,7 @@ var CryptopunkTrade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
684
724
|
_proto.encode = function encode(planner, config) {
|
|
685
725
|
for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
|
|
686
726
|
var item = _step.value;
|
|
687
|
-
planner.addCommand(CommandType.CRYPTOPUNKS, [item.tokenId, item.recipient, item.value], config.allowRevert);
|
|
727
|
+
planner.addCommand(exports.CommandType.CRYPTOPUNKS, [item.tokenId, item.recipient, item.value], config.allowRevert);
|
|
688
728
|
}
|
|
689
729
|
};
|
|
690
730
|
_proto.getBuyItems = function getBuyItems() {
|
|
@@ -2343,7 +2383,7 @@ var FoundationTrade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
2343
2383
|
for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
|
|
2344
2384
|
var item = _step.value;
|
|
2345
2385
|
var calldata = FoundationTrade.INTERFACE.encodeFunctionData('buyV2', [item.tokenAddress, item.tokenId, item.price, item.referrer]);
|
|
2346
|
-
planner.addCommand(CommandType.FOUNDATION, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
|
|
2386
|
+
planner.addCommand(exports.CommandType.FOUNDATION, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
|
|
2347
2387
|
}
|
|
2348
2388
|
};
|
|
2349
2389
|
_proto.getBuyItems = function getBuyItems() {
|
|
@@ -4389,7 +4429,7 @@ var LooksRareV2Trade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
4389
4429
|
} else {
|
|
4390
4430
|
calldata = LooksRareV2Trade.INTERFACE.encodeFunctionData('executeMultipleTakerBids', [takerBids, makerOrders, makerSignatures, merkleTrees, ZERO_ADDRESS, false]);
|
|
4391
4431
|
}
|
|
4392
|
-
planner.addCommand(CommandType.LOOKS_RARE_V2, [totalValue, calldata], config.allowRevert);
|
|
4432
|
+
planner.addCommand(exports.CommandType.LOOKS_RARE_V2, [totalValue, calldata], config.allowRevert);
|
|
4393
4433
|
};
|
|
4394
4434
|
_proto.getBuyItems = function getBuyItems() {
|
|
4395
4435
|
var buyItems = [];
|
|
@@ -4717,7 +4757,7 @@ var NFT20Trade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
4717
4757
|
for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
|
|
4718
4758
|
var order = _step.value;
|
|
4719
4759
|
var calldata = NFT20Trade.INTERFACE.encodeFunctionData('ethForNft', [order.tokenAddress, order.tokenIds, order.tokenAmounts, order.recipient, order.fee, order.isV3]);
|
|
4720
|
-
planner.addCommand(CommandType.NFT20, [order.value, calldata], config.allowRevert);
|
|
4760
|
+
planner.addCommand(exports.CommandType.NFT20, [order.value, calldata], config.allowRevert);
|
|
4721
4761
|
}
|
|
4722
4762
|
};
|
|
4723
4763
|
_proto.getBuyItems = function getBuyItems() {
|
|
@@ -5378,7 +5418,7 @@ var NFTXTrade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
5378
5418
|
for (var _iterator = _createForOfIteratorHelperLoose(this.orders), _step; !(_step = _iterator()).done;) {
|
|
5379
5419
|
var order = _step.value;
|
|
5380
5420
|
var calldata = NFTXTrade.INTERFACE.encodeFunctionData('buyAndRedeem', [order.vaultId, order.tokenIds.length, order.tokenIds, order.swapCalldata, order.recipient]);
|
|
5381
|
-
planner.addCommand(CommandType.NFTX, [order.value, calldata], config.allowRevert);
|
|
5421
|
+
planner.addCommand(exports.CommandType.NFTX, [order.value, calldata], config.allowRevert);
|
|
5382
5422
|
}
|
|
5383
5423
|
};
|
|
5384
5424
|
_proto.getBuyItems = function getBuyItems() {
|
|
@@ -8145,10 +8185,10 @@ var SeaportTrade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
8145
8185
|
switch (protocolAddress.toLowerCase()) {
|
|
8146
8186
|
case '0x00000000000000adc04c56bf30ac9d3c0aaf14dc':
|
|
8147
8187
|
// Seaport v1.5
|
|
8148
|
-
return CommandType.SEAPORT_V1_5;
|
|
8188
|
+
return exports.CommandType.SEAPORT_V1_5;
|
|
8149
8189
|
case '0x00000000000001ad428e4906ae43d8f9852d0dd6':
|
|
8150
8190
|
// Seaport v1.4
|
|
8151
|
-
return CommandType.SEAPORT_V1_4;
|
|
8191
|
+
return exports.CommandType.SEAPORT_V1_4;
|
|
8152
8192
|
default:
|
|
8153
8193
|
throw new Error('unsupported Seaport address');
|
|
8154
8194
|
}
|
|
@@ -9339,7 +9379,7 @@ var SudoswapTrade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
9339
9379
|
var value = order.swaps.reduce(function (prevVal, swap) {
|
|
9340
9380
|
return prevVal.add(swap.maxCost);
|
|
9341
9381
|
}, ethers.BigNumber.from(0));
|
|
9342
|
-
planner.addCommand(CommandType.SUDOSWAP, [value, calldata], config.allowRevert);
|
|
9382
|
+
planner.addCommand(exports.CommandType.SUDOSWAP, [value, calldata], config.allowRevert);
|
|
9343
9383
|
}
|
|
9344
9384
|
};
|
|
9345
9385
|
_proto.getBuyItems = function getBuyItems() {
|
|
@@ -10492,9 +10532,9 @@ var X2Y2Trade = /*#__PURE__*/function (_NFTTrade) {
|
|
|
10492
10532
|
var functionSelector = X2Y2Trade.INTERFACE.getSighash(X2Y2Trade.INTERFACE.getFunction('run'));
|
|
10493
10533
|
var calldata = functionSelector + item.signedInput.slice(2);
|
|
10494
10534
|
if (item.tokenType == exports.TokenType.ERC721) {
|
|
10495
|
-
planner.addCommand(CommandType.X2Y2_721, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
|
|
10535
|
+
planner.addCommand(exports.CommandType.X2Y2_721, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId], config.allowRevert);
|
|
10496
10536
|
} else if (item.tokenType == exports.TokenType.ERC1155) {
|
|
10497
|
-
planner.addCommand(CommandType.X2Y2_1155, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId, item.tokenAmount], config.allowRevert);
|
|
10537
|
+
planner.addCommand(exports.CommandType.X2Y2_1155, [item.price, calldata, item.recipient, item.tokenAddress, item.tokenId, item.tokenAmount], config.allowRevert);
|
|
10498
10538
|
}
|
|
10499
10539
|
}
|
|
10500
10540
|
};
|
|
@@ -10542,11 +10582,51 @@ var UnwrapWETH = /*#__PURE__*/function () {
|
|
|
10542
10582
|
amount: this.amount.toString()
|
|
10543
10583
|
}
|
|
10544
10584
|
});
|
|
10545
|
-
planner.addCommand(CommandType.UNWRAP_WETH, [ROUTER_AS_RECIPIENT, this.amount]);
|
|
10585
|
+
planner.addCommand(exports.CommandType.UNWRAP_WETH, [ROUTER_AS_RECIPIENT, this.amount]);
|
|
10546
10586
|
};
|
|
10547
10587
|
return UnwrapWETH;
|
|
10548
10588
|
}();
|
|
10549
10589
|
|
|
10590
|
+
var WrapSTETH = /*#__PURE__*/function () {
|
|
10591
|
+
function WrapSTETH(amount, chainId, permit2, wrapAmount) {
|
|
10592
|
+
this.tradeType = exports.RouterTradeType.WrapSTETH;
|
|
10593
|
+
this.stethAddress = STETH_ADDRESS(chainId);
|
|
10594
|
+
this.amount = amount;
|
|
10595
|
+
this.wrapAmount = wrapAmount != null ? wrapAmount : CONTRACT_BALANCE;
|
|
10596
|
+
if (!!permit2) {
|
|
10597
|
+
!(permit2.details.token.toLowerCase() === this.stethAddress.toLowerCase()) ? invariant(false, "must be permitting STETH address: " + this.stethAddress) : void 0;
|
|
10598
|
+
!(permit2.details.amount >= amount) ? invariant(false, "Did not permit enough STETH for unwrapSTETH transaction") : void 0;
|
|
10599
|
+
this.permit2Data = permit2;
|
|
10600
|
+
}
|
|
10601
|
+
}
|
|
10602
|
+
var _proto = WrapSTETH.prototype;
|
|
10603
|
+
_proto.encode = function encode(planner, _) {
|
|
10604
|
+
encodeInputTokenOptions(planner, {
|
|
10605
|
+
permit2Permit: this.permit2Data,
|
|
10606
|
+
permit2TransferFrom: {
|
|
10607
|
+
token: this.stethAddress,
|
|
10608
|
+
amount: this.amount.toString()
|
|
10609
|
+
}
|
|
10610
|
+
});
|
|
10611
|
+
planner.addCommand(exports.CommandType.WRAP_STETH, [ROUTER_AS_RECIPIENT, this.wrapAmount]);
|
|
10612
|
+
};
|
|
10613
|
+
return WrapSTETH;
|
|
10614
|
+
}();
|
|
10615
|
+
|
|
10616
|
+
var UnwrapSTETH = /*#__PURE__*/function () {
|
|
10617
|
+
function UnwrapSTETH(recipient, amountMinimum, chainId) {
|
|
10618
|
+
this.tradeType = exports.RouterTradeType.UnwrapSTETH;
|
|
10619
|
+
this.recipient = recipient;
|
|
10620
|
+
this.amountMinimum = amountMinimum;
|
|
10621
|
+
!(STETH_ADDRESS(chainId) != NOT_SUPPORTED_ON_CHAIN) ? invariant(false, "STETH not supported on chain " + chainId) : void 0;
|
|
10622
|
+
}
|
|
10623
|
+
var _proto = UnwrapSTETH.prototype;
|
|
10624
|
+
_proto.encode = function encode(planner, _) {
|
|
10625
|
+
planner.addCommand(exports.CommandType.UNWRAP_STETH, [this.recipient, this.amountMinimum]);
|
|
10626
|
+
};
|
|
10627
|
+
return UnwrapSTETH;
|
|
10628
|
+
}();
|
|
10629
|
+
|
|
10550
10630
|
exports.CryptopunkTrade = CryptopunkTrade;
|
|
10551
10631
|
exports.FoundationTrade = FoundationTrade;
|
|
10552
10632
|
exports.LooksRareV2Trade = LooksRareV2Trade;
|
|
@@ -10555,13 +10635,16 @@ exports.NFTTrade = NFTTrade;
|
|
|
10555
10635
|
exports.NFTXTrade = NFTXTrade;
|
|
10556
10636
|
exports.PERMIT2_ADDRESS = PERMIT2_ADDRESS;
|
|
10557
10637
|
exports.ROUTER_AS_RECIPIENT = ROUTER_AS_RECIPIENT;
|
|
10638
|
+
exports.RoutePlanner = RoutePlanner;
|
|
10558
10639
|
exports.SeaportTrade = SeaportTrade;
|
|
10559
10640
|
exports.SudoswapTrade = SudoswapTrade;
|
|
10560
10641
|
exports.SwapRouter = SwapRouter;
|
|
10561
10642
|
exports.UNIVERSAL_ROUTER_ADDRESS = UNIVERSAL_ROUTER_ADDRESS;
|
|
10562
10643
|
exports.UNIVERSAL_ROUTER_CREATION_BLOCK = UNIVERSAL_ROUTER_CREATION_BLOCK;
|
|
10563
10644
|
exports.UniswapTrade = UniswapTrade;
|
|
10645
|
+
exports.UnwrapSTETH = UnwrapSTETH;
|
|
10564
10646
|
exports.UnwrapWETH = UnwrapWETH;
|
|
10565
10647
|
exports.WETH_ADDRESS = WETH_ADDRESS;
|
|
10648
|
+
exports.WrapSTETH = WrapSTETH;
|
|
10566
10649
|
exports.X2Y2Trade = X2Y2Trade;
|
|
10567
10650
|
//# sourceMappingURL=universal-router-sdk.cjs.development.js.map
|