@uniswap/universal-router-sdk 4.34.2 → 4.35.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 +104 -96
- package/dist/{entities → cjs/src/entities}/Command.d.ts +12 -12
- package/dist/cjs/src/entities/Command.js +9 -0
- package/dist/cjs/src/entities/Command.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/actions/across.d.ts +21 -21
- package/dist/cjs/src/entities/actions/across.js +7 -0
- package/dist/cjs/src/entities/actions/across.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/actions/index.d.ts +3 -3
- package/dist/cjs/src/entities/actions/index.js +7 -0
- package/dist/cjs/src/entities/actions/index.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/actions/uniswap.d.ts +38 -39
- package/dist/cjs/src/entities/actions/uniswap.js +532 -0
- package/dist/cjs/src/entities/actions/uniswap.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/actions/unwrapWETH.d.ts +12 -12
- package/dist/cjs/src/entities/actions/unwrapWETH.js +33 -0
- package/dist/cjs/src/entities/actions/unwrapWETH.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/index.d.ts +2 -2
- package/dist/cjs/src/entities/index.js +6 -0
- package/dist/cjs/src/entities/index.js.map +1 -0
- package/dist/{index.d.ts → cjs/src/index.d.ts} +12 -12
- package/dist/cjs/src/index.js +33 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/{swapRouter.d.ts → cjs/src/swapRouter.d.ts} +87 -87
- package/dist/cjs/src/swapRouter.js +276 -0
- package/dist/cjs/src/swapRouter.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/commandParser.d.ts +34 -34
- package/dist/cjs/src/utils/commandParser.js +145 -0
- package/dist/cjs/src/utils/commandParser.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/constants.d.ts +33 -33
- package/dist/cjs/src/utils/constants.js +541 -0
- package/dist/cjs/src/utils/constants.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/eip712.d.ts +17 -17
- package/dist/cjs/src/utils/eip712.js +43 -0
- package/dist/cjs/src/utils/eip712.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/getCurrencyAddress.d.ts +2 -2
- package/dist/cjs/src/utils/getCurrencyAddress.js +9 -0
- package/dist/cjs/src/utils/getCurrencyAddress.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/inputTokens.d.ts +23 -23
- package/dist/cjs/src/utils/inputTokens.js +58 -0
- package/dist/cjs/src/utils/inputTokens.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/numbers.d.ts +7 -6
- package/dist/cjs/src/utils/numbers.js +27 -0
- package/dist/cjs/src/utils/numbers.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/pathCurrency.d.ts +3 -3
- package/dist/cjs/src/utils/pathCurrency.js +27 -0
- package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/routerCommands.d.ts +77 -72
- package/dist/cjs/src/utils/routerCommands.js +334 -0
- package/dist/cjs/src/utils/routerCommands.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/routerTradeAdapter.d.ts +73 -73
- package/dist/cjs/src/utils/routerTradeAdapter.js +139 -0
- package/dist/cjs/src/utils/routerTradeAdapter.js.map +1 -0
- package/dist/esm/src/entities/Command.d.ts +12 -0
- package/dist/esm/src/entities/Command.js +6 -0
- package/dist/esm/src/entities/Command.js.map +1 -0
- package/dist/esm/src/entities/actions/across.d.ts +21 -0
- package/dist/esm/src/entities/actions/across.js +3 -0
- package/dist/esm/src/entities/actions/across.js.map +1 -0
- package/dist/esm/src/entities/actions/index.d.ts +3 -0
- package/dist/esm/src/entities/actions/index.js +4 -0
- package/dist/esm/src/entities/actions/index.js.map +1 -0
- package/dist/esm/src/entities/actions/uniswap.d.ts +38 -0
- package/dist/esm/src/entities/actions/uniswap.js +528 -0
- package/dist/esm/src/entities/actions/uniswap.js.map +1 -0
- package/dist/esm/src/entities/actions/unwrapWETH.d.ts +12 -0
- package/dist/esm/src/entities/actions/unwrapWETH.js +28 -0
- package/dist/esm/src/entities/actions/unwrapWETH.js.map +1 -0
- package/dist/esm/src/entities/index.d.ts +2 -0
- package/dist/esm/src/entities/index.js +3 -0
- package/dist/esm/src/entities/index.js.map +1 -0
- package/dist/esm/src/index.d.ts +12 -0
- package/dist/esm/src/index.js +9 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/swapRouter.d.ts +87 -0
- package/dist/esm/src/swapRouter.js +271 -0
- package/dist/esm/src/swapRouter.js.map +1 -0
- package/dist/esm/src/utils/commandParser.d.ts +34 -0
- package/dist/esm/src/utils/commandParser.js +137 -0
- package/dist/esm/src/utils/commandParser.js.map +1 -0
- package/dist/esm/src/utils/constants.d.ts +33 -0
- package/dist/esm/src/utils/constants.js +534 -0
- package/dist/esm/src/utils/constants.js.map +1 -0
- package/dist/esm/src/utils/eip712.d.ts +17 -0
- package/dist/esm/src/utils/eip712.js +38 -0
- package/dist/esm/src/utils/eip712.js.map +1 -0
- package/dist/esm/src/utils/getCurrencyAddress.d.ts +2 -0
- package/dist/esm/src/utils/getCurrencyAddress.js +5 -0
- package/dist/esm/src/utils/getCurrencyAddress.js.map +1 -0
- package/dist/esm/src/utils/inputTokens.d.ts +23 -0
- package/dist/esm/src/utils/inputTokens.js +51 -0
- package/dist/esm/src/utils/inputTokens.js.map +1 -0
- package/dist/esm/src/utils/numbers.d.ts +7 -0
- package/dist/esm/src/utils/numbers.js +19 -0
- package/dist/esm/src/utils/numbers.js.map +1 -0
- package/dist/esm/src/utils/pathCurrency.d.ts +3 -0
- package/dist/esm/src/utils/pathCurrency.js +23 -0
- package/dist/esm/src/utils/pathCurrency.js.map +1 -0
- package/dist/esm/src/utils/routerCommands.d.ts +77 -0
- package/dist/esm/src/utils/routerCommands.js +329 -0
- package/dist/esm/src/utils/routerCommands.js.map +1 -0
- package/dist/esm/src/utils/routerTradeAdapter.d.ts +73 -0
- package/dist/esm/src/utils/routerTradeAdapter.js +134 -0
- package/dist/esm/src/utils/routerTradeAdapter.js.map +1 -0
- package/dist/types/src/entities/Command.d.ts +12 -0
- package/dist/types/src/entities/actions/across.d.ts +21 -0
- package/dist/types/src/entities/actions/index.d.ts +3 -0
- package/dist/types/src/entities/actions/uniswap.d.ts +38 -0
- package/dist/types/src/entities/actions/unwrapWETH.d.ts +12 -0
- package/dist/types/src/entities/index.d.ts +2 -0
- package/dist/types/src/index.d.ts +12 -0
- package/dist/types/src/swapRouter.d.ts +87 -0
- package/dist/types/src/utils/commandParser.d.ts +34 -0
- package/dist/types/src/utils/constants.d.ts +33 -0
- package/dist/types/src/utils/eip712.d.ts +17 -0
- package/dist/types/src/utils/getCurrencyAddress.d.ts +2 -0
- package/dist/types/src/utils/inputTokens.d.ts +23 -0
- package/dist/types/src/utils/numbers.d.ts +7 -0
- package/dist/types/src/utils/pathCurrency.d.ts +3 -0
- package/dist/types/src/utils/routerCommands.d.ts +77 -0
- package/dist/types/src/utils/routerTradeAdapter.d.ts +73 -0
- package/package.json +31 -22
- package/dist/index.js +0 -8
- package/dist/test/forge/writeInterop.d.ts +0 -2
- package/dist/test/utils/addresses.d.ts +0 -5
- package/dist/test/utils/hexToDecimalString.d.ts +0 -2
- package/dist/test/utils/permit2.d.ts +0 -7
- package/dist/test/utils/uniswapData.d.ts +0 -24
- package/dist/universal-router-sdk.cjs.development.js +0 -1925
- package/dist/universal-router-sdk.cjs.development.js.map +0 -1
- package/dist/universal-router-sdk.cjs.production.min.js +0 -2
- package/dist/universal-router-sdk.cjs.production.min.js.map +0 -1
- package/dist/universal-router-sdk.esm.js +0 -1912
- package/dist/universal-router-sdk.esm.js.map +0 -1
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniswapTrade = exports.TokenTransferMode = void 0;
|
|
4
|
+
const routerCommands_1 = require("../../utils/routerCommands");
|
|
5
|
+
const v2_sdk_1 = require("@uniswap/v2-sdk");
|
|
6
|
+
const v3_sdk_1 = require("@uniswap/v3-sdk");
|
|
7
|
+
const v4_sdk_1 = require("@uniswap/v4-sdk");
|
|
8
|
+
const router_sdk_1 = require("@uniswap/router-sdk");
|
|
9
|
+
const pathCurrency_1 = require("../../utils/pathCurrency");
|
|
10
|
+
const sdk_core_1 = require("@uniswap/sdk-core");
|
|
11
|
+
const Command_1 = require("../Command");
|
|
12
|
+
const constants_1 = require("../../utils/constants");
|
|
13
|
+
const getCurrencyAddress_1 = require("../../utils/getCurrencyAddress");
|
|
14
|
+
const numbers_1 = require("../../utils/numbers");
|
|
15
|
+
const ethers_1 = require("ethers");
|
|
16
|
+
// the existing router permit object doesn't include enough data for permit2
|
|
17
|
+
// so we extend swap options with the permit2 permit
|
|
18
|
+
// when safe mode is enabled, the SDK will add an extra ETH sweep for security
|
|
19
|
+
// when useRouterBalance is enabled the SDK will use the balance in the router for the swap
|
|
20
|
+
var TokenTransferMode;
|
|
21
|
+
(function (TokenTransferMode) {
|
|
22
|
+
TokenTransferMode["Permit2"] = "Permit2";
|
|
23
|
+
TokenTransferMode["ApproveProxy"] = "ApproveProxy";
|
|
24
|
+
})(TokenTransferMode = exports.TokenTransferMode || (exports.TokenTransferMode = {}));
|
|
25
|
+
const REFUND_ETH_PRICE_IMPACT_THRESHOLD = new sdk_core_1.Percent(50, 100);
|
|
26
|
+
// Wrapper for uniswap router-sdk trade entity to encode swaps for Universal Router
|
|
27
|
+
// also translates trade objects from previous (v2, v3) SDKs
|
|
28
|
+
class UniswapTrade {
|
|
29
|
+
constructor(trade, options) {
|
|
30
|
+
this.trade = trade;
|
|
31
|
+
this.options = options;
|
|
32
|
+
this.tradeType = Command_1.RouterActionType.UniswapTrade;
|
|
33
|
+
if (!!options.fee && !!options.flatFee)
|
|
34
|
+
throw new Error('Only one fee option permitted');
|
|
35
|
+
if (options.tokenTransferMode === TokenTransferMode.ApproveProxy) {
|
|
36
|
+
if (!options.recipient || options.recipient === constants_1.SENDER_AS_RECIPIENT) {
|
|
37
|
+
throw new Error('Explicit recipient address required when using SwapProxy (SENDER_AS_RECIPIENT resolves to proxy)');
|
|
38
|
+
}
|
|
39
|
+
this.payerIsUser = false;
|
|
40
|
+
}
|
|
41
|
+
else if (this.inputRequiresWrap || this.inputRequiresUnwrap || this.options.useRouterBalance) {
|
|
42
|
+
this.payerIsUser = false;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.payerIsUser = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
get isAllV4() {
|
|
49
|
+
let result = true;
|
|
50
|
+
for (const swap of this.trade.swaps) {
|
|
51
|
+
result = result && swap.route.protocol == router_sdk_1.Protocol.V4;
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
// this.trade.swaps is an array of swaps / trades.
|
|
56
|
+
// we are iterating over one swap (trade) at a time so length is 1
|
|
57
|
+
// route is either v2, v3, v4, or mixed
|
|
58
|
+
// pathInput and pathOutput are the currencies of the input and output of the route
|
|
59
|
+
// this.trade.inputAmount is the input currency of the trade (could be different from pathInput)
|
|
60
|
+
// this.trade.outputAmount is the output currency of the trade (could be different from pathOutput)
|
|
61
|
+
// each route can have multiple pools
|
|
62
|
+
get inputRequiresWrap() {
|
|
63
|
+
const swap = this.trade.swaps[0];
|
|
64
|
+
const route = swap.route;
|
|
65
|
+
const firstPool = route.pools[0];
|
|
66
|
+
if (firstPool instanceof v4_sdk_1.Pool) {
|
|
67
|
+
// If first pool is a v4 pool and input currency is native and the path input currency in the route is not native, we need to wrap.
|
|
68
|
+
return (this.trade.inputAmount.currency.isNative &&
|
|
69
|
+
!this.trade.swaps[0].route.pathInput.isNative);
|
|
70
|
+
}
|
|
71
|
+
// If first pool is not a v4 pool and input currency is native, we need to wrap
|
|
72
|
+
return this.trade.inputAmount.currency.isNative;
|
|
73
|
+
}
|
|
74
|
+
get inputRequiresUnwrap() {
|
|
75
|
+
const swap = this.trade.swaps[0];
|
|
76
|
+
const route = swap.route;
|
|
77
|
+
const firstPool = route.pools[0];
|
|
78
|
+
if (firstPool instanceof v4_sdk_1.Pool) {
|
|
79
|
+
// If the first pool is a v4 pool and input currency is not native and the path input currency is native, we need to unwrap
|
|
80
|
+
return (!this.trade.inputAmount.currency.isNative &&
|
|
81
|
+
this.trade.swaps[0].route.pathInput.isNative);
|
|
82
|
+
}
|
|
83
|
+
// If the first pool is not a v4 pool, we don't need to unwrap.
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
get outputRequiresWrap() {
|
|
87
|
+
const swap = this.trade.swaps[0];
|
|
88
|
+
const lastRoute = swap.route;
|
|
89
|
+
const lastPool = lastRoute.pools[lastRoute.pools.length - 1];
|
|
90
|
+
// if last pool is v4:
|
|
91
|
+
if (lastPool instanceof v4_sdk_1.Pool) {
|
|
92
|
+
// If output currency is not native but path currency output is native, we need to wrap
|
|
93
|
+
if (!this.trade.outputAmount.currency.isNative) {
|
|
94
|
+
if (lastRoute.pathOutput.isNative) {
|
|
95
|
+
// this means path output is native and we need to wrap
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
else if (lastPool.currency1.equals(lastPool.currency0.wrapped) && lastRoute.pools.length > 1) {
|
|
99
|
+
let poolBefore = lastRoute.pools[lastRoute.pools.length - 2];
|
|
100
|
+
// this means last pool is eth-weth and pool before contains weth
|
|
101
|
+
if (poolBefore instanceof v4_sdk_1.Pool &&
|
|
102
|
+
(poolBefore.currency0.equals(lastPool.currency1) || poolBefore.currency1.equals(lastPool.currency1))) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
else if (poolBefore.token0.equals(lastPool.currency1) || poolBefore.token1.equals(lastPool.currency1)) {
|
|
106
|
+
// same for v2 and v3 pools
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// if last pool is not v4:
|
|
113
|
+
// we do not need to wrap because v2 and v3 pools already require wrapped tokens
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
get outputRequiresUnwrap() {
|
|
117
|
+
const swap = this.trade.swaps[0];
|
|
118
|
+
const lastRoute = swap.route;
|
|
119
|
+
const lastPool = lastRoute.pools[lastRoute.pools.length - 1];
|
|
120
|
+
// if last pool is v4:
|
|
121
|
+
if (lastPool instanceof v4_sdk_1.Pool) {
|
|
122
|
+
// If output currency is native and path currency output is not native, we need to unwrap
|
|
123
|
+
if (this.trade.outputAmount.currency.isNative) {
|
|
124
|
+
if (!this.trade.swaps[0].route.pathOutput.isNative) {
|
|
125
|
+
// this means path output is weth and we need to unwrap
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
else if (lastRoute.pools.length > 1 &&
|
|
129
|
+
lastRoute.pools[lastRoute.pools.length - 2] instanceof v4_sdk_1.Pool &&
|
|
130
|
+
lastRoute.pools[lastRoute.pools.length - 2].currency0.isNative &&
|
|
131
|
+
lastPool.currency1.equals(lastPool.currency0.wrapped)) {
|
|
132
|
+
// this means last pool is eth-weth and we need to unwrap
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// else: if path output currency is native, we need to unwrap because v2 and v3 pools already require wrapped tokens
|
|
141
|
+
return this.trade.outputAmount.currency.isNative;
|
|
142
|
+
}
|
|
143
|
+
get outputRequiresTransition() {
|
|
144
|
+
return this.outputRequiresWrap || this.outputRequiresUnwrap;
|
|
145
|
+
}
|
|
146
|
+
encode(planner, _config) {
|
|
147
|
+
var _a;
|
|
148
|
+
// If the input currency is the native currency, we need to wrap it with the router as the recipient
|
|
149
|
+
if (this.inputRequiresWrap) {
|
|
150
|
+
// TODO: optimize if only one v2 pool we can directly send this to the pool
|
|
151
|
+
planner.addCommand(routerCommands_1.CommandType.WRAP_ETH, [
|
|
152
|
+
constants_1.ROUTER_AS_RECIPIENT,
|
|
153
|
+
this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString(),
|
|
154
|
+
]);
|
|
155
|
+
}
|
|
156
|
+
else if (this.inputRequiresUnwrap) {
|
|
157
|
+
if (this.options.tokenTransferMode !== TokenTransferMode.ApproveProxy) {
|
|
158
|
+
// send wrapped token to router to unwrap via Permit2
|
|
159
|
+
planner.addCommand(routerCommands_1.CommandType.PERMIT2_TRANSFER_FROM, [
|
|
160
|
+
this.trade.inputAmount.currency.address,
|
|
161
|
+
constants_1.ROUTER_AS_RECIPIENT,
|
|
162
|
+
this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString(),
|
|
163
|
+
]);
|
|
164
|
+
}
|
|
165
|
+
// In proxy mode, the proxy already transferred tokens to the UR; just unwrap
|
|
166
|
+
planner.addCommand(routerCommands_1.CommandType.UNWRAP_WETH, [constants_1.ROUTER_AS_RECIPIENT, 0]);
|
|
167
|
+
}
|
|
168
|
+
// The overall recipient at the end of the trade, SENDER_AS_RECIPIENT uses the msg.sender
|
|
169
|
+
this.options.recipient = (_a = this.options.recipient) !== null && _a !== void 0 ? _a : constants_1.SENDER_AS_RECIPIENT;
|
|
170
|
+
// flag for whether we want to perform slippage check on aggregate output of multiple routes
|
|
171
|
+
// 1. when there are >2 exact input trades. this is only a heuristic,
|
|
172
|
+
// as it's still more gas-expensive even in this case, but has benefits
|
|
173
|
+
// in that the reversion probability is lower
|
|
174
|
+
const performAggregatedSlippageCheck = this.trade.tradeType === sdk_core_1.TradeType.EXACT_INPUT && this.trade.routes.length > 2;
|
|
175
|
+
const routerMustCustody = performAggregatedSlippageCheck || this.outputRequiresTransition || hasFeeOption(this.options);
|
|
176
|
+
for (const swap of this.trade.swaps) {
|
|
177
|
+
switch (swap.route.protocol) {
|
|
178
|
+
case router_sdk_1.Protocol.V2:
|
|
179
|
+
addV2Swap(planner, swap, this.trade.tradeType, this.options, this.payerIsUser, routerMustCustody);
|
|
180
|
+
break;
|
|
181
|
+
case router_sdk_1.Protocol.V3:
|
|
182
|
+
addV3Swap(planner, swap, this.trade.tradeType, this.options, this.payerIsUser, routerMustCustody);
|
|
183
|
+
break;
|
|
184
|
+
case router_sdk_1.Protocol.V4:
|
|
185
|
+
addV4Swap(planner, swap, this.trade.tradeType, this.options, this.payerIsUser, routerMustCustody);
|
|
186
|
+
break;
|
|
187
|
+
case router_sdk_1.Protocol.MIXED:
|
|
188
|
+
addMixedSwap(planner, swap, this.trade.tradeType, this.options, this.payerIsUser, routerMustCustody);
|
|
189
|
+
break;
|
|
190
|
+
default:
|
|
191
|
+
throw new Error('UNSUPPORTED_TRADE_PROTOCOL');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
let minimumAmountOut = ethers_1.BigNumber.from(this.trade.minimumAmountOut(this.options.slippageTolerance).quotient.toString());
|
|
195
|
+
// The router custodies for 3 reasons: to unwrap, to take a fee, and/or to do a slippage check
|
|
196
|
+
if (routerMustCustody) {
|
|
197
|
+
const pools = this.trade.swaps[0].route.pools;
|
|
198
|
+
const pathOutputCurrencyAddress = (0, getCurrencyAddress_1.getCurrencyAddress)((0, pathCurrency_1.getPathCurrency)(this.trade.outputAmount.currency, pools[pools.length - 1]));
|
|
199
|
+
let feeDeduction = ethers_1.BigNumber.from(0);
|
|
200
|
+
// If there is a fee, that percentage is sent to the fee recipient
|
|
201
|
+
// In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
|
|
202
|
+
if (!!this.options.fee) {
|
|
203
|
+
// UR >= V2_1_1 supports PAY_PORTION_FULL_PRECISION (1e18 precision),
|
|
204
|
+
// older versions only support PAY_PORTION (bips)
|
|
205
|
+
const useFullPrecision = this.options.urVersion !== undefined && this.options.urVersion >= v4_sdk_1.URVersion.V2_1_1;
|
|
206
|
+
// Reject fractional bips fees on older UR versions to prevent silent precision loss
|
|
207
|
+
if (!useFullPrecision && !this.options.fee.fee.multiply(10000).remainder.equalTo(0)) {
|
|
208
|
+
throw new Error('Fractional fee bips require Universal Router version V2_1_1 or higher');
|
|
209
|
+
}
|
|
210
|
+
if (useFullPrecision) {
|
|
211
|
+
const fee1e18 = (0, numbers_1.encodeFee1e18)(this.options.fee.fee);
|
|
212
|
+
planner.addCommand(routerCommands_1.CommandType.PAY_PORTION_FULL_PRECISION, [pathOutputCurrencyAddress, this.options.fee.recipient, fee1e18], false, this.options.urVersion);
|
|
213
|
+
feeDeduction = minimumAmountOut.mul(fee1e18).div(ethers_1.BigNumber.from(10).pow(18));
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
const feeBips = (0, numbers_1.encodeFeeBips)(this.options.fee.fee);
|
|
217
|
+
planner.addCommand(routerCommands_1.CommandType.PAY_PORTION, [pathOutputCurrencyAddress, this.options.fee.recipient, feeBips]);
|
|
218
|
+
feeDeduction = minimumAmountOut.mul(feeBips).div(10000);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// If there is a flat fee, that absolute amount is sent to the fee recipient
|
|
222
|
+
// In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
|
|
223
|
+
if (!!this.options.flatFee) {
|
|
224
|
+
const feeAmount = this.options.flatFee.amount;
|
|
225
|
+
if (minimumAmountOut.lt(feeAmount))
|
|
226
|
+
throw new Error('Flat fee amount greater than minimumAmountOut');
|
|
227
|
+
planner.addCommand(routerCommands_1.CommandType.TRANSFER, [pathOutputCurrencyAddress, this.options.flatFee.recipient, feeAmount]);
|
|
228
|
+
feeDeduction = ethers_1.BigNumber.from(feeAmount);
|
|
229
|
+
}
|
|
230
|
+
// If the trade is exact output, and a fee was taken, we must adjust the amount out to be the amount after the fee
|
|
231
|
+
// Otherwise we continue as expected with the trade's normal expected output
|
|
232
|
+
if (this.trade.tradeType === sdk_core_1.TradeType.EXACT_OUTPUT) {
|
|
233
|
+
minimumAmountOut = minimumAmountOut.sub(feeDeduction);
|
|
234
|
+
}
|
|
235
|
+
// The remaining tokens that need to be sent to the user after the fee is taken will be caught
|
|
236
|
+
// by this if-else clause.
|
|
237
|
+
if (this.outputRequiresUnwrap) {
|
|
238
|
+
planner.addCommand(routerCommands_1.CommandType.UNWRAP_WETH, [this.options.recipient, minimumAmountOut]);
|
|
239
|
+
}
|
|
240
|
+
else if (this.outputRequiresWrap) {
|
|
241
|
+
planner.addCommand(routerCommands_1.CommandType.WRAP_ETH, [this.options.recipient, constants_1.CONTRACT_BALANCE]);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
planner.addCommand(routerCommands_1.CommandType.SWEEP, [
|
|
245
|
+
(0, getCurrencyAddress_1.getCurrencyAddress)(this.trade.outputAmount.currency),
|
|
246
|
+
this.options.recipient,
|
|
247
|
+
minimumAmountOut,
|
|
248
|
+
]);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// for exactOutput swaps with native input or that perform an inputToken transition (wrap or unwrap)
|
|
252
|
+
// we need to send back the change to the user
|
|
253
|
+
if (this.trade.tradeType === sdk_core_1.TradeType.EXACT_OUTPUT || riskOfPartialFill(this.trade)) {
|
|
254
|
+
if (this.inputRequiresWrap) {
|
|
255
|
+
planner.addCommand(routerCommands_1.CommandType.UNWRAP_WETH, [this.options.recipient, 0]);
|
|
256
|
+
}
|
|
257
|
+
else if (this.inputRequiresUnwrap) {
|
|
258
|
+
planner.addCommand(routerCommands_1.CommandType.WRAP_ETH, [this.options.recipient, constants_1.CONTRACT_BALANCE]);
|
|
259
|
+
}
|
|
260
|
+
else if (this.options.tokenTransferMode === TokenTransferMode.ApproveProxy) {
|
|
261
|
+
// Proxy pulled maximumAmountIn into the UR; sweep any unused input back to the user
|
|
262
|
+
planner.addCommand(routerCommands_1.CommandType.SWEEP, [
|
|
263
|
+
(0, getCurrencyAddress_1.getCurrencyAddress)(this.trade.inputAmount.currency),
|
|
264
|
+
this.options.recipient,
|
|
265
|
+
0,
|
|
266
|
+
]);
|
|
267
|
+
}
|
|
268
|
+
else if (this.trade.inputAmount.currency.isNative) {
|
|
269
|
+
// must refund extra native currency sent along for native v4 trades (no input transition)
|
|
270
|
+
planner.addCommand(routerCommands_1.CommandType.SWEEP, [constants_1.ETH_ADDRESS, this.options.recipient, 0]);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (this.options.safeMode)
|
|
274
|
+
planner.addCommand(routerCommands_1.CommandType.SWEEP, [constants_1.ETH_ADDRESS, this.options.recipient, 0]);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
exports.UniswapTrade = UniswapTrade;
|
|
278
|
+
// encode a uniswap v2 swap
|
|
279
|
+
function addV2Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }, tradeType, options, payerIsUser, routerMustCustody) {
|
|
280
|
+
if ((maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.length) && maxHopSlippage.length !== route.pools.length) {
|
|
281
|
+
throw new Error(`maxHopSlippage length (${maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
|
|
282
|
+
}
|
|
283
|
+
const trade = new v2_sdk_1.Trade(route, tradeType == sdk_core_1.TradeType.EXACT_INPUT ? inputAmount : outputAmount, tradeType);
|
|
284
|
+
const useV2_1_1 = (0, v4_sdk_1.isAtLeastV2_1_1)(options.urVersion);
|
|
285
|
+
if (tradeType == sdk_core_1.TradeType.EXACT_INPUT) {
|
|
286
|
+
const params = [
|
|
287
|
+
// if native, we have to unwrap so keep in the router for now
|
|
288
|
+
routerMustCustody ? constants_1.ROUTER_AS_RECIPIENT : options.recipient,
|
|
289
|
+
trade.maximumAmountIn(options.slippageTolerance).quotient.toString(),
|
|
290
|
+
// if router will custody funds, we do aggregated slippage check from router
|
|
291
|
+
routerMustCustody ? 0 : trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
|
|
292
|
+
route.path.map((token) => token.wrapped.address),
|
|
293
|
+
payerIsUser,
|
|
294
|
+
];
|
|
295
|
+
if (useV2_1_1)
|
|
296
|
+
params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
|
|
297
|
+
planner.addCommand(routerCommands_1.CommandType.V2_SWAP_EXACT_IN, params, false, options.urVersion);
|
|
298
|
+
}
|
|
299
|
+
else if (tradeType == sdk_core_1.TradeType.EXACT_OUTPUT) {
|
|
300
|
+
const params = [
|
|
301
|
+
routerMustCustody ? constants_1.ROUTER_AS_RECIPIENT : options.recipient,
|
|
302
|
+
trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
|
|
303
|
+
trade.maximumAmountIn(options.slippageTolerance).quotient.toString(),
|
|
304
|
+
route.path.map((token) => token.wrapped.address),
|
|
305
|
+
payerIsUser,
|
|
306
|
+
];
|
|
307
|
+
if (useV2_1_1)
|
|
308
|
+
params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
|
|
309
|
+
planner.addCommand(routerCommands_1.CommandType.V2_SWAP_EXACT_OUT, params, false, options.urVersion);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// encode a uniswap v3 swap
|
|
313
|
+
function addV3Swap(planner, { route, inputAmount, outputAmount, maxHopSlippage }, tradeType, options, payerIsUser, routerMustCustody) {
|
|
314
|
+
if ((maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.length) && maxHopSlippage.length !== route.pools.length) {
|
|
315
|
+
throw new Error(`maxHopSlippage length (${maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
|
|
316
|
+
}
|
|
317
|
+
const trade = v3_sdk_1.Trade.createUncheckedTrade({
|
|
318
|
+
route: route,
|
|
319
|
+
inputAmount,
|
|
320
|
+
outputAmount,
|
|
321
|
+
tradeType,
|
|
322
|
+
});
|
|
323
|
+
const useV2_1_1 = (0, v4_sdk_1.isAtLeastV2_1_1)(options.urVersion);
|
|
324
|
+
const path = (0, v3_sdk_1.encodeRouteToPath)(route, trade.tradeType === sdk_core_1.TradeType.EXACT_OUTPUT);
|
|
325
|
+
if (tradeType == sdk_core_1.TradeType.EXACT_INPUT) {
|
|
326
|
+
const params = [
|
|
327
|
+
routerMustCustody ? constants_1.ROUTER_AS_RECIPIENT : options.recipient,
|
|
328
|
+
trade.maximumAmountIn(options.slippageTolerance).quotient.toString(),
|
|
329
|
+
routerMustCustody ? 0 : trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
|
|
330
|
+
path,
|
|
331
|
+
payerIsUser,
|
|
332
|
+
];
|
|
333
|
+
if (useV2_1_1)
|
|
334
|
+
params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
|
|
335
|
+
planner.addCommand(routerCommands_1.CommandType.V3_SWAP_EXACT_IN, params, false, options.urVersion);
|
|
336
|
+
}
|
|
337
|
+
else if (tradeType == sdk_core_1.TradeType.EXACT_OUTPUT) {
|
|
338
|
+
const params = [
|
|
339
|
+
routerMustCustody ? constants_1.ROUTER_AS_RECIPIENT : options.recipient,
|
|
340
|
+
trade.minimumAmountOut(options.slippageTolerance).quotient.toString(),
|
|
341
|
+
trade.maximumAmountIn(options.slippageTolerance).quotient.toString(),
|
|
342
|
+
path,
|
|
343
|
+
payerIsUser,
|
|
344
|
+
];
|
|
345
|
+
if (useV2_1_1)
|
|
346
|
+
params.push(maxHopSlippage !== null && maxHopSlippage !== void 0 ? maxHopSlippage : []);
|
|
347
|
+
planner.addCommand(routerCommands_1.CommandType.V3_SWAP_EXACT_OUT, params, false, options.urVersion);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function addV4Swap(planner, { inputAmount, outputAmount, route, maxHopSlippage }, tradeType, options, payerIsUser, routerMustCustody) {
|
|
351
|
+
var _a, _b;
|
|
352
|
+
if ((maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.length) && maxHopSlippage.length !== route.pools.length) {
|
|
353
|
+
throw new Error(`maxHopSlippage length (${maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
|
|
354
|
+
}
|
|
355
|
+
// create a deep copy of pools since v4Planner encoding tampers with array
|
|
356
|
+
const pools = route.pools.map((p) => p);
|
|
357
|
+
const v4Route = new v4_sdk_1.Route(pools, inputAmount.currency, outputAmount.currency);
|
|
358
|
+
const trade = v4_sdk_1.Trade.createUncheckedTrade({
|
|
359
|
+
route: v4Route,
|
|
360
|
+
inputAmount,
|
|
361
|
+
outputAmount,
|
|
362
|
+
tradeType,
|
|
363
|
+
});
|
|
364
|
+
const slippageToleranceOnSwap = routerMustCustody && tradeType == sdk_core_1.TradeType.EXACT_INPUT ? undefined : options.slippageTolerance;
|
|
365
|
+
const perHopSlippage = (_a = maxHopSlippage === null || maxHopSlippage === void 0 ? void 0 : maxHopSlippage.map((s) => ethers_1.BigNumber.from(s))) !== null && _a !== void 0 ? _a : [];
|
|
366
|
+
const v4Planner = new v4_sdk_1.V4Planner();
|
|
367
|
+
v4Planner.addTrade(trade, slippageToleranceOnSwap, perHopSlippage, options.urVersion);
|
|
368
|
+
v4Planner.addSettle(trade.route.pathInput, payerIsUser);
|
|
369
|
+
// Handle split route output consistency:
|
|
370
|
+
// - If output is ETH and some routes output WETH: force all to output WETH, then unwrap
|
|
371
|
+
// - If output is WETH and some routes output ETH: force all to output ETH, then wrap
|
|
372
|
+
let pathOutputForTake = trade.route.pathOutput;
|
|
373
|
+
let lastPool = v4Route.pools[v4Route.pools.length - 1];
|
|
374
|
+
let ethWethPool = lastPool.currency1.equals(lastPool.currency0.wrapped);
|
|
375
|
+
if (ethWethPool && v4Route.pools.length > 1) {
|
|
376
|
+
let poolBefore = v4Route.pools[v4Route.pools.length - 2];
|
|
377
|
+
if (pathOutputForTake.isNative && poolBefore.currency0.isNative) {
|
|
378
|
+
pathOutputForTake = pathOutputForTake.wrapped;
|
|
379
|
+
}
|
|
380
|
+
else if (!pathOutputForTake.isNative &&
|
|
381
|
+
(poolBefore.currency0.equals(lastPool.currency1) || poolBefore.currency1.equals(lastPool.currency1))) {
|
|
382
|
+
pathOutputForTake = lastPool.currency0;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
v4Planner.addTake(pathOutputForTake, routerMustCustody ? constants_1.ROUTER_AS_RECIPIENT : (_b = options.recipient) !== null && _b !== void 0 ? _b : constants_1.SENDER_AS_RECIPIENT);
|
|
386
|
+
planner.addCommand(routerCommands_1.CommandType.V4_SWAP, [v4Planner.finalize()]);
|
|
387
|
+
}
|
|
388
|
+
// encode a mixed route swap, i.e. including both v2 and v3 pools
|
|
389
|
+
function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMustCustody) {
|
|
390
|
+
var _a, _b, _c, _d;
|
|
391
|
+
const route = swap.route;
|
|
392
|
+
if (((_a = swap.maxHopSlippage) === null || _a === void 0 ? void 0 : _a.length) && swap.maxHopSlippage.length !== route.pools.length) {
|
|
393
|
+
throw new Error(`maxHopSlippage length (${swap.maxHopSlippage.length}) must equal route.pools.length (${route.pools.length})`);
|
|
394
|
+
}
|
|
395
|
+
const inputAmount = swap.inputAmount;
|
|
396
|
+
const outputAmount = swap.outputAmount;
|
|
397
|
+
const tradeRecipient = routerMustCustody ? constants_1.ROUTER_AS_RECIPIENT : (_b = options.recipient) !== null && _b !== void 0 ? _b : constants_1.SENDER_AS_RECIPIENT;
|
|
398
|
+
// single hop, so it can be reduced to plain swap logic for one protocol version
|
|
399
|
+
if (route.pools.length === 1) {
|
|
400
|
+
if (route.pools[0] instanceof v4_sdk_1.Pool) {
|
|
401
|
+
return addV4Swap(planner, swap, tradeType, options, payerIsUser, routerMustCustody);
|
|
402
|
+
}
|
|
403
|
+
else if (route.pools[0] instanceof v3_sdk_1.Pool) {
|
|
404
|
+
return addV3Swap(planner, swap, tradeType, options, payerIsUser, routerMustCustody);
|
|
405
|
+
}
|
|
406
|
+
else if (route.pools[0] instanceof v2_sdk_1.Pair) {
|
|
407
|
+
return addV2Swap(planner, swap, tradeType, options, payerIsUser, routerMustCustody);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
throw new Error('Invalid route type');
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
const trade = router_sdk_1.MixedRouteTrade.createUncheckedTrade({
|
|
414
|
+
route: route,
|
|
415
|
+
inputAmount,
|
|
416
|
+
outputAmount,
|
|
417
|
+
tradeType,
|
|
418
|
+
});
|
|
419
|
+
const amountIn = trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient.toString();
|
|
420
|
+
const amountOut = routerMustCustody
|
|
421
|
+
? 0
|
|
422
|
+
: trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient.toString();
|
|
423
|
+
// logic from
|
|
424
|
+
// https://github.com/Uniswap/router-sdk/blob/d8eed164e6c79519983844ca8b6a3fc24ebcb8f8/src/swapRouter.ts#L276
|
|
425
|
+
const sections = (0, router_sdk_1.partitionMixedRouteByProtocol)(route);
|
|
426
|
+
const isLastSectionInRoute = (i) => {
|
|
427
|
+
return i === sections.length - 1;
|
|
428
|
+
};
|
|
429
|
+
const useV2_1_1 = (0, v4_sdk_1.isAtLeastV2_1_1)(options.urVersion);
|
|
430
|
+
let inputToken = route.pathInput;
|
|
431
|
+
let hopOffset = 0;
|
|
432
|
+
for (let i = 0; i < sections.length; i++) {
|
|
433
|
+
const section = sections[i];
|
|
434
|
+
const routePool = section[0];
|
|
435
|
+
const outputToken = (0, router_sdk_1.getOutputOfPools)(section, inputToken);
|
|
436
|
+
const subRoute = new router_sdk_1.MixedRoute(new router_sdk_1.MixedRouteSDK([...section], inputToken, outputToken));
|
|
437
|
+
// Slice this section's portion of maxHopSlippage from the flat array
|
|
438
|
+
const sectionHopSlippage = (_c = swap.maxHopSlippage) === null || _c === void 0 ? void 0 : _c.slice(hopOffset, hopOffset + section.length);
|
|
439
|
+
let nextInputToken;
|
|
440
|
+
let swapRecipient;
|
|
441
|
+
if (isLastSectionInRoute(i)) {
|
|
442
|
+
nextInputToken = outputToken;
|
|
443
|
+
swapRecipient = tradeRecipient;
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
const nextPool = sections[i + 1][0];
|
|
447
|
+
nextInputToken = (0, pathCurrency_1.getPathCurrency)(outputToken, nextPool);
|
|
448
|
+
const v2PoolIsSwapRecipient = nextPool instanceof v2_sdk_1.Pair && outputToken.equals(nextInputToken);
|
|
449
|
+
swapRecipient = v2PoolIsSwapRecipient ? nextPool.liquidityToken.address : constants_1.ROUTER_AS_RECIPIENT;
|
|
450
|
+
}
|
|
451
|
+
if (routePool instanceof v4_sdk_1.Pool) {
|
|
452
|
+
const v4Planner = new v4_sdk_1.V4Planner();
|
|
453
|
+
const v4SubRoute = new v4_sdk_1.Route(section, subRoute.input, subRoute.output);
|
|
454
|
+
const v4SectionSlippage = (_d = sectionHopSlippage === null || sectionHopSlippage === void 0 ? void 0 : sectionHopSlippage.map((s) => ethers_1.BigNumber.from(s))) !== null && _d !== void 0 ? _d : [];
|
|
455
|
+
v4Planner.addSettle(inputToken, payerIsUser && i === 0, (i == 0 ? amountIn : constants_1.CONTRACT_BALANCE));
|
|
456
|
+
v4Planner.addAction(v4_sdk_1.Actions.SWAP_EXACT_IN, [
|
|
457
|
+
{
|
|
458
|
+
currencyIn: inputToken.isNative ? constants_1.ETH_ADDRESS : inputToken.address,
|
|
459
|
+
path: (0, v4_sdk_1.encodeRouteToPath)(v4SubRoute),
|
|
460
|
+
maxHopSlippage: v4SectionSlippage,
|
|
461
|
+
amountIn: 0,
|
|
462
|
+
amountOutMinimum: !isLastSectionInRoute(i) ? 0 : amountOut,
|
|
463
|
+
},
|
|
464
|
+
], options.urVersion);
|
|
465
|
+
// Handle split route output consistency for V4 sections in mixed routes
|
|
466
|
+
let outputTokenForTake = outputToken;
|
|
467
|
+
if (isLastSectionInRoute(i)) {
|
|
468
|
+
let lastPool = route.pools[route.pools.length - 1];
|
|
469
|
+
let v4Pool = lastPool instanceof v4_sdk_1.Pool;
|
|
470
|
+
let ethWethPool = v4Pool ? lastPool.currency1.equals(lastPool.currency0.wrapped) : false;
|
|
471
|
+
let poolBefore = route.pools[route.pools.length - 2];
|
|
472
|
+
if (ethWethPool) {
|
|
473
|
+
if (outputToken.isNative && poolBefore.token0.isNative) {
|
|
474
|
+
outputTokenForTake = outputToken.wrapped;
|
|
475
|
+
}
|
|
476
|
+
else if (!outputToken.isNative &&
|
|
477
|
+
(poolBefore.token0.equals(lastPool.token1) || poolBefore.token1.equals(lastPool.token1))) {
|
|
478
|
+
outputTokenForTake = lastPool.token0;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
v4Planner.addTake(outputTokenForTake, swapRecipient);
|
|
483
|
+
planner.addCommand(routerCommands_1.CommandType.V4_SWAP, [v4Planner.finalize()]);
|
|
484
|
+
}
|
|
485
|
+
else if (routePool instanceof v3_sdk_1.Pool) {
|
|
486
|
+
const v3Params = [
|
|
487
|
+
swapRecipient,
|
|
488
|
+
i == 0 ? amountIn : constants_1.CONTRACT_BALANCE,
|
|
489
|
+
!isLastSectionInRoute(i) ? 0 : amountOut,
|
|
490
|
+
(0, router_sdk_1.encodeMixedRouteToPath)(subRoute),
|
|
491
|
+
payerIsUser && i === 0, // payerIsUser
|
|
492
|
+
];
|
|
493
|
+
if (useV2_1_1)
|
|
494
|
+
v3Params.push(sectionHopSlippage !== null && sectionHopSlippage !== void 0 ? sectionHopSlippage : []);
|
|
495
|
+
planner.addCommand(routerCommands_1.CommandType.V3_SWAP_EXACT_IN, v3Params, false, options.urVersion);
|
|
496
|
+
}
|
|
497
|
+
else if (routePool instanceof v2_sdk_1.Pair) {
|
|
498
|
+
const v2Params = [
|
|
499
|
+
swapRecipient,
|
|
500
|
+
i === 0 ? amountIn : constants_1.CONTRACT_BALANCE,
|
|
501
|
+
!isLastSectionInRoute(i) ? 0 : amountOut,
|
|
502
|
+
subRoute.path.map((token) => token.wrapped.address),
|
|
503
|
+
payerIsUser && i === 0,
|
|
504
|
+
];
|
|
505
|
+
if (useV2_1_1)
|
|
506
|
+
v2Params.push(sectionHopSlippage !== null && sectionHopSlippage !== void 0 ? sectionHopSlippage : []);
|
|
507
|
+
planner.addCommand(routerCommands_1.CommandType.V2_SWAP_EXACT_IN, v2Params, false, options.urVersion);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
throw new Error('Unexpected Pool Type');
|
|
511
|
+
}
|
|
512
|
+
// perform a token transition (wrap/unwrap if necessary)
|
|
513
|
+
if (!isLastSectionInRoute(i)) {
|
|
514
|
+
if (outputToken.isNative && !nextInputToken.isNative) {
|
|
515
|
+
planner.addCommand(routerCommands_1.CommandType.WRAP_ETH, [constants_1.ROUTER_AS_RECIPIENT, constants_1.CONTRACT_BALANCE]);
|
|
516
|
+
}
|
|
517
|
+
else if (!outputToken.isNative && nextInputToken.isNative) {
|
|
518
|
+
planner.addCommand(routerCommands_1.CommandType.UNWRAP_WETH, [constants_1.ROUTER_AS_RECIPIENT, 0]);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
hopOffset += section.length;
|
|
522
|
+
inputToken = nextInputToken;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
// if price impact is very high, there's a chance of hitting max/min prices resulting in a partial fill of the swap
|
|
526
|
+
function riskOfPartialFill(trade) {
|
|
527
|
+
return trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD);
|
|
528
|
+
}
|
|
529
|
+
function hasFeeOption(swapOptions) {
|
|
530
|
+
return !!swapOptions.fee || !!swapOptions.flatFee;
|
|
531
|
+
}
|
|
532
|
+
//# sourceMappingURL=uniswap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniswap.js","sourceRoot":"","sources":["../../../../../src/entities/actions/uniswap.ts"],"names":[],"mappings":";;;AAAA,+DAAsE;AACtE,4CAAwD;AACxD,4CAAqF;AACrF,4CASwB;AACxB,oDAa4B;AAE5B,2DAA0D;AAC1D,gDAAuF;AACvF,wCAAmE;AACnE,qDAA+G;AAC/G,uEAAmE;AACnE,iDAAkE;AAClE,mCAAgD;AAQhD,4EAA4E;AAC5E,oDAAoD;AACpD,8EAA8E;AAC9E,2FAA2F;AAC3F,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,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;gBACpD,OAAO,CAAC,UAAU,CAAC,4BAAW,CAAC,QAAQ,EAAE,CAAC,+BAAmB,EAAE,4BAAgB,CAAC,CAAC,CAAA;aAClF;iBAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,IAAI,cAAc,CAAC,QAAQ,EAAE;gBAC3D,OAAO,CAAC,UAAU,CAAC,4BAAW,CAAC,WAAW,EAAE,CAAC,+BAAmB,EAAE,CAAC,CAAC,CAAC,CAAA;aACtE;SACF;QAED,SAAS,IAAI,OAAO,CAAC,MAAM,CAAA;QAC3B,UAAU,GAAG,cAAc,CAAA;KAC5B;AACH,CAAC;AAED,mHAAmH;AACnH,SAAS,iBAAiB,CAAC,KAAiD;IAC1E,OAAO,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,iCAAiC,CAAC,CAAA;AACzE,CAAC;AAED,SAAS,YAAY,CAAC,WAAwB;IAC5C,OAAO,CAAC,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC,WAAW,CAAC,OAAO,CAAA;AACnD,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { BigNumberish } from 'ethers';
|
|
2
|
-
import { RoutePlanner } from '../../utils/routerCommands';
|
|
3
|
-
import { Permit2Permit } from '../../utils/inputTokens';
|
|
4
|
-
import { Command, RouterActionType, TradeConfig } from '../Command';
|
|
5
|
-
export declare class UnwrapWETH implements Command {
|
|
6
|
-
readonly tradeType: RouterActionType;
|
|
7
|
-
readonly permit2Data?: Permit2Permit;
|
|
8
|
-
readonly wethAddress: string;
|
|
9
|
-
readonly amount: BigNumberish;
|
|
10
|
-
constructor(amount: BigNumberish, chainId: number, permit2?: Permit2Permit);
|
|
11
|
-
encode(planner: RoutePlanner, _: TradeConfig): void;
|
|
12
|
-
}
|
|
1
|
+
import { BigNumberish } from 'ethers';
|
|
2
|
+
import { RoutePlanner } from '../../utils/routerCommands';
|
|
3
|
+
import { Permit2Permit } from '../../utils/inputTokens';
|
|
4
|
+
import { Command, RouterActionType, TradeConfig } from '../Command';
|
|
5
|
+
export declare class UnwrapWETH implements Command {
|
|
6
|
+
readonly tradeType: RouterActionType;
|
|
7
|
+
readonly permit2Data?: Permit2Permit;
|
|
8
|
+
readonly wethAddress: string;
|
|
9
|
+
readonly amount: BigNumberish;
|
|
10
|
+
constructor(amount: BigNumberish, chainId: number, permit2?: Permit2Permit);
|
|
11
|
+
encode(planner: RoutePlanner, _: TradeConfig): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnwrapWETH = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
|
|
6
|
+
const routerCommands_1 = require("../../utils/routerCommands");
|
|
7
|
+
const inputTokens_1 = require("../../utils/inputTokens");
|
|
8
|
+
const Command_1 = require("../Command");
|
|
9
|
+
const constants_1 = require("../../utils/constants");
|
|
10
|
+
class UnwrapWETH {
|
|
11
|
+
constructor(amount, chainId, permit2) {
|
|
12
|
+
this.tradeType = Command_1.RouterActionType.UnwrapWETH;
|
|
13
|
+
this.wethAddress = (0, constants_1.WETH_ADDRESS)(chainId);
|
|
14
|
+
this.amount = amount;
|
|
15
|
+
if (!!permit2) {
|
|
16
|
+
(0, tiny_invariant_1.default)(permit2.details.token.toLowerCase() === this.wethAddress.toLowerCase(), `must be permitting WETH address: ${this.wethAddress}`);
|
|
17
|
+
(0, tiny_invariant_1.default)(permit2.details.amount >= amount, `Did not permit enough WETH for unwrapWETH transaction`);
|
|
18
|
+
this.permit2Data = permit2;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
encode(planner, _) {
|
|
22
|
+
(0, inputTokens_1.encodeInputTokenOptions)(planner, {
|
|
23
|
+
permit2Permit: this.permit2Data,
|
|
24
|
+
permit2TransferFrom: {
|
|
25
|
+
token: this.wethAddress,
|
|
26
|
+
amount: this.amount.toString(),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
planner.addCommand(routerCommands_1.CommandType.UNWRAP_WETH, [constants_1.ROUTER_AS_RECIPIENT, this.amount]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.UnwrapWETH = UnwrapWETH;
|
|
33
|
+
//# sourceMappingURL=unwrapWETH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrapWETH.js","sourceRoot":"","sources":["../../../../../src/entities/actions/unwrapWETH.ts"],"names":[],"mappings":";;;;AAAA,4EAAsC;AAEtC,+DAAsE;AACtE,yDAAgF;AAChF,wCAAmE;AACnE,qDAAyE;AAEzE,MAAa,UAAU;IAMrB,YAAY,MAAoB,EAAE,OAAe,EAAE,OAAuB;QALjE,cAAS,GAAqB,0BAAgB,CAAC,UAAU,CAAA;QAMhE,IAAI,CAAC,WAAW,GAAG,IAAA,wBAAY,EAAC,OAAO,CAAC,CAAA;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,IAAI,CAAC,CAAC,OAAO,EAAE;YACb,IAAA,wBAAS,EACP,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,EACtE,oCAAoC,IAAI,CAAC,WAAW,EAAE,CACvD,CAAA;YACD,IAAA,wBAAS,EAAC,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,EAAE,uDAAuD,CAAC,CAAA;YACpG,IAAI,CAAC,WAAW,GAAG,OAAO,CAAA;SAC3B;IACH,CAAC;IAED,MAAM,CAAC,OAAqB,EAAE,CAAc;QAC1C,IAAA,qCAAuB,EAAC,OAAO,EAAE;YAC/B,aAAa,EAAE,IAAI,CAAC,WAAW;YAC/B,mBAAmB,EAAE;gBACnB,KAAK,EAAE,IAAI,CAAC,WAAW;gBACvB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;aAC/B;SACF,CAAC,CAAA;QACF,OAAO,CAAC,UAAU,CAAC,4BAAW,CAAC,WAAW,EAAE,CAAC,+BAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;IACjF,CAAC;CACF;AA9BD,gCA8BC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './actions';
|
|
2
|
-
export * from './Command';
|
|
1
|
+
export * from './actions';
|
|
2
|
+
export * from './Command';
|