@uniswap/universal-router-sdk 1.5.7 → 1.5.8
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/dist/entities/protocols/uniswap.d.ts +6 -0
- package/dist/universal-router-sdk.cjs.development.js +31 -15
- 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 +31 -15
- package/dist/universal-router-sdk.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,8 +3,14 @@ import { Trade as RouterTrade, SwapOptions as RouterSwapOptions } from '@uniswap
|
|
|
3
3
|
import { Permit2Permit } from '../../utils/inputTokens';
|
|
4
4
|
import { Currency, TradeType } from '@uniswap/sdk-core';
|
|
5
5
|
import { Command, RouterTradeType, TradeConfig } from '../Command';
|
|
6
|
+
import { BigNumberish } from 'ethers';
|
|
7
|
+
export declare type FlatFeeOptions = {
|
|
8
|
+
amount: BigNumberish;
|
|
9
|
+
recipient: string;
|
|
10
|
+
};
|
|
6
11
|
export declare type SwapOptions = Omit<RouterSwapOptions, 'inputTokenPermit'> & {
|
|
7
12
|
inputTokenPermit?: Permit2Permit;
|
|
13
|
+
flatFee?: FlatFeeOptions;
|
|
8
14
|
};
|
|
9
15
|
export declare class UniswapTrade implements Command {
|
|
10
16
|
trade: RouterTrade<Currency, Currency, TradeType>;
|
|
@@ -200,53 +200,53 @@ var CHAIN_CONFIGS = (_CHAIN_CONFIGS = {}, _CHAIN_CONFIGS[1] = {
|
|
|
200
200
|
weth: '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14',
|
|
201
201
|
creationBlock: 3543575
|
|
202
202
|
}, _CHAIN_CONFIGS[137] = {
|
|
203
|
-
router: '
|
|
203
|
+
router: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
|
|
204
204
|
weth: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
|
|
205
|
-
creationBlock:
|
|
205
|
+
creationBlock: 46866777
|
|
206
206
|
}, _CHAIN_CONFIGS[80001] = {
|
|
207
207
|
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
|
|
208
208
|
weth: '0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889',
|
|
209
209
|
creationBlock: 35176052
|
|
210
210
|
}, _CHAIN_CONFIGS[10] = {
|
|
211
|
-
router: '
|
|
211
|
+
router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
|
|
212
212
|
weth: '0x4200000000000000000000000000000000000006',
|
|
213
|
-
creationBlock:
|
|
213
|
+
creationBlock: 108825869
|
|
214
214
|
}, _CHAIN_CONFIGS[420] = {
|
|
215
215
|
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
|
|
216
216
|
weth: '0x4200000000000000000000000000000000000006',
|
|
217
217
|
creationBlock: 8887728
|
|
218
218
|
}, _CHAIN_CONFIGS[42161] = {
|
|
219
|
-
router: '
|
|
219
|
+
router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
|
|
220
220
|
weth: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
|
|
221
|
-
creationBlock:
|
|
221
|
+
creationBlock: 125861718
|
|
222
222
|
}, _CHAIN_CONFIGS[421613] = {
|
|
223
223
|
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
|
|
224
224
|
weth: '0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3',
|
|
225
225
|
creationBlock: 18815277
|
|
226
226
|
}, _CHAIN_CONFIGS[42220] = {
|
|
227
|
-
router: '
|
|
227
|
+
router: '0x88a3ED7F21A3fCF6adb86b6F878C5B7a02D20e9b',
|
|
228
228
|
weth: WETH_NOT_SUPPORTED_ON_CHAIN,
|
|
229
|
-
creationBlock:
|
|
229
|
+
creationBlock: 21116361
|
|
230
230
|
}, _CHAIN_CONFIGS[44787] = {
|
|
231
231
|
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
|
|
232
232
|
weth: WETH_NOT_SUPPORTED_ON_CHAIN,
|
|
233
233
|
creationBlock: 17566658
|
|
234
234
|
}, _CHAIN_CONFIGS[56] = {
|
|
235
|
-
router: '
|
|
235
|
+
router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
|
|
236
236
|
weth: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
|
|
237
|
-
creationBlock:
|
|
237
|
+
creationBlock: 31254967
|
|
238
238
|
}, _CHAIN_CONFIGS[43114] = {
|
|
239
|
-
router: '
|
|
239
|
+
router: '0x82635AF6146972cD6601161c4472ffe97237D292',
|
|
240
240
|
weth: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
|
|
241
|
-
creationBlock:
|
|
241
|
+
creationBlock: 34491144
|
|
242
242
|
}, _CHAIN_CONFIGS[84531] = {
|
|
243
243
|
router: '0xd0872d928672ae2ff74bdb2f5130ac12229cafaf',
|
|
244
244
|
weth: '0x4200000000000000000000000000000000000006',
|
|
245
245
|
creationBlock: 6915289
|
|
246
246
|
}, _CHAIN_CONFIGS[8453] = {
|
|
247
|
-
router: '
|
|
247
|
+
router: '0xeC8B0F7Ffe3ae75d7FfAb09429e3675bb63503e4',
|
|
248
248
|
weth: '0x4200000000000000000000000000000000000006',
|
|
249
|
-
creationBlock:
|
|
249
|
+
creationBlock: 3229053
|
|
250
250
|
}, _CHAIN_CONFIGS);
|
|
251
251
|
var UNIVERSAL_ROUTER_ADDRESS = function UNIVERSAL_ROUTER_ADDRESS(chainId) {
|
|
252
252
|
if (!(chainId in CHAIN_CONFIGS)) throw new Error("Universal Router not deployed on chain " + chainId);
|
|
@@ -282,6 +282,7 @@ var UniswapTrade = /*#__PURE__*/function () {
|
|
|
282
282
|
this.trade = trade;
|
|
283
283
|
this.options = options;
|
|
284
284
|
this.tradeType = exports.RouterTradeType.UniswapTrade;
|
|
285
|
+
if (!!options.fee && !!options.flatFee) throw new Error('Only one fee option permitted');
|
|
285
286
|
}
|
|
286
287
|
var _proto = UniswapTrade.prototype;
|
|
287
288
|
_proto.encode = function encode(planner, _config) {
|
|
@@ -303,7 +304,7 @@ var UniswapTrade = /*#__PURE__*/function () {
|
|
|
303
304
|
var performAggregatedSlippageCheck = this.trade.tradeType === sdkCore.TradeType.EXACT_INPUT && this.trade.routes.length > 2;
|
|
304
305
|
var outputIsNative = this.trade.outputAmount.currency.isNative;
|
|
305
306
|
var inputIsNative = this.trade.inputAmount.currency.isNative;
|
|
306
|
-
var routerMustCustody = performAggregatedSlippageCheck || outputIsNative ||
|
|
307
|
+
var routerMustCustody = performAggregatedSlippageCheck || outputIsNative || hasFeeOption(this.options);
|
|
307
308
|
for (var _iterator = _createForOfIteratorHelperLoose(this.trade.swaps), _step; !(_step = _iterator()).done;) {
|
|
308
309
|
var swap = _step.value;
|
|
309
310
|
switch (swap.route.protocol) {
|
|
@@ -334,6 +335,18 @@ var UniswapTrade = /*#__PURE__*/function () {
|
|
|
334
335
|
minimumAmountOut = minimumAmountOut.sub(minimumAmountOut.mul(feeBips).div(10000));
|
|
335
336
|
}
|
|
336
337
|
}
|
|
338
|
+
// If there is a flat fee, that absolute amount is sent to the fee recipient
|
|
339
|
+
// In the case where ETH is the output currency, the fee is taken in WETH (for gas reasons)
|
|
340
|
+
if (!!this.options.flatFee) {
|
|
341
|
+
var feeAmount = this.options.flatFee.amount;
|
|
342
|
+
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]);
|
|
344
|
+
// 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
|
+
// Otherwise we continue as expected with the trade's normal expected output
|
|
346
|
+
if (this.trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
|
|
347
|
+
minimumAmountOut = minimumAmountOut.sub(feeAmount);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
337
350
|
// The remaining tokens that need to be sent to the user after the fee is taken will be caught
|
|
338
351
|
// by this if-else clause.
|
|
339
352
|
if (outputIsNative) {
|
|
@@ -448,6 +461,9 @@ function addMixedSwap(planner, swap, tradeType, options, payerIsUser, routerMust
|
|
|
448
461
|
function riskOfPartialFill(trade) {
|
|
449
462
|
return trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD);
|
|
450
463
|
}
|
|
464
|
+
function hasFeeOption(swapOptions) {
|
|
465
|
+
return !!swapOptions.fee || !!swapOptions.flatFee;
|
|
466
|
+
}
|
|
451
467
|
|
|
452
468
|
var SIGNATURE_LENGTH = 65;
|
|
453
469
|
var EIP_2098_SIGNATURE_LENGTH = 64;
|