@uniswap/router-sdk 1.0.0-beta.5 → 1.0.0-beta.6
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 +10 -0
- package/dist/entities/route.d.ts +1 -1
- package/dist/entities/trade.d.ts +2 -2
- package/dist/paymentsExtended.d.ts +3 -3
- package/dist/router-sdk.cjs.development.js +24 -18
- package/dist/router-sdk.cjs.development.js.map +1 -1
- package/dist/router-sdk.cjs.production.min.js +1 -1
- package/dist/router-sdk.cjs.production.min.js.map +1 -1
- package/dist/router-sdk.esm.js +26 -20
- package/dist/router-sdk.esm.js.map +1 -1
- package/dist/swapRouter.d.ts +2 -3
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Alpha software
|
|
2
|
+
|
|
3
|
+
The latest version of the SDK is used in production in the Uniswap Interface,
|
|
4
|
+
but it is considered Alpha software and may contain bugs or change significantly between patch versions.
|
|
5
|
+
If you have questions about how to use the SDK, please reach out in the `#dev-chat` channel of the Discord.
|
|
6
|
+
Pull requests welcome!
|
|
7
|
+
|
|
8
|
+
# Uniswap Swap Router SDK
|
|
9
|
+
|
|
10
|
+
This SDK is meant to facilitate interactions with the contracts in [swap-router-contracts](https://github.com/Uniswap/swap-router-contracts).
|
package/dist/entities/route.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Route as V2RouteSDK, Pair } from '@uniswap/v2-sdk';
|
|
|
2
2
|
import { Route as V3RouteSDK, Pool } from '@uniswap/v3-sdk';
|
|
3
3
|
import { Protocol } from './protocol';
|
|
4
4
|
import { Currency, Price, Token } from '@uniswap/sdk-core';
|
|
5
|
-
export interface IRoute<TInput extends Currency, TOutput extends Currency, TPool extends
|
|
5
|
+
export interface IRoute<TInput extends Currency, TOutput extends Currency, TPool extends Pool | Pair> {
|
|
6
6
|
protocol: Protocol;
|
|
7
7
|
pools: TPool[];
|
|
8
8
|
path: Token[];
|
package/dist/entities/trade.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { IRoute } from './route';
|
|
|
3
3
|
import { Route as V2RouteSDK, Pair } from '@uniswap/v2-sdk';
|
|
4
4
|
import { Route as V3RouteSDK, Pool } from '@uniswap/v3-sdk';
|
|
5
5
|
export declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {
|
|
6
|
-
readonly routes: IRoute<TInput, TOutput,
|
|
6
|
+
readonly routes: IRoute<TInput, TOutput, Pair | Pool>[];
|
|
7
7
|
readonly tradeType: TTradeType;
|
|
8
8
|
private _outputAmount;
|
|
9
9
|
private _inputAmount;
|
|
@@ -12,7 +12,7 @@ export declare class Trade<TInput extends Currency, TOutput extends Currency, TT
|
|
|
12
12
|
* make up the trade. May consist of swaps in v2 or v3.
|
|
13
13
|
*/
|
|
14
14
|
readonly swaps: {
|
|
15
|
-
route: IRoute<TInput, TOutput,
|
|
15
|
+
route: IRoute<TInput, TOutput, Pair | Pool>;
|
|
16
16
|
inputAmount: CurrencyAmount<TInput>;
|
|
17
17
|
outputAmount: CurrencyAmount<TOutput>;
|
|
18
18
|
}[];
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import JSBI from 'jsbi';
|
|
2
1
|
import { Interface } from '@ethersproject/abi';
|
|
3
|
-
import { FeeOptions } from '@uniswap/v3-sdk';
|
|
4
2
|
import { Token } from '@uniswap/sdk-core';
|
|
3
|
+
import { FeeOptions } from '@uniswap/v3-sdk';
|
|
4
|
+
import JSBI from 'jsbi';
|
|
5
5
|
export declare abstract class PaymentsExtended {
|
|
6
6
|
static INTERFACE: Interface;
|
|
7
7
|
/**
|
|
8
8
|
* Cannot be constructed.
|
|
9
9
|
*/
|
|
10
10
|
private constructor();
|
|
11
|
-
private static encodeFeeBips;
|
|
12
11
|
static encodeUnwrapWETH9(amountMinimum: JSBI, recipient?: string, feeOptions?: FeeOptions): string;
|
|
13
12
|
static encodeSweepToken(token: Token, amountMinimum: JSBI, recipient?: string, feeOptions?: FeeOptions): string;
|
|
14
13
|
static encodePull(token: Token, amount: JSBI): string;
|
|
14
|
+
static encodeWrapETH(amount: JSBI): string;
|
|
15
15
|
}
|
|
@@ -8,11 +8,11 @@ var JSBI = _interopDefault(require('jsbi'));
|
|
|
8
8
|
var abi = require('@ethersproject/abi');
|
|
9
9
|
var v3Sdk = require('@uniswap/v3-sdk');
|
|
10
10
|
var IMulticallExtended_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json');
|
|
11
|
-
var IPeripheryPaymentsWithFeeExtended_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json');
|
|
12
11
|
var sdkCore = require('@uniswap/sdk-core');
|
|
13
|
-
var
|
|
12
|
+
var IPeripheryPaymentsWithFeeExtended_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json');
|
|
14
13
|
var ISwapRouter02_json = require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json');
|
|
15
14
|
var v2Sdk = require('@uniswap/v2-sdk');
|
|
15
|
+
var invariant = _interopDefault(require('tiny-invariant'));
|
|
16
16
|
|
|
17
17
|
var MSG_SENDER = '0x0000000000000000000000000000000000000000';
|
|
18
18
|
var ADDRESS_THIS = '0x0000000000000000000000000000000000000001';
|
|
@@ -58,16 +58,16 @@ var MulticallExtended = /*#__PURE__*/function () {
|
|
|
58
58
|
}();
|
|
59
59
|
MulticallExtended.INTERFACE = /*#__PURE__*/new abi.Interface(IMulticallExtended_json.abi);
|
|
60
60
|
|
|
61
|
+
function encodeFeeBips(fee) {
|
|
62
|
+
return v3Sdk.toHex(fee.multiply(10000).quotient);
|
|
63
|
+
}
|
|
64
|
+
|
|
61
65
|
var PaymentsExtended = /*#__PURE__*/function () {
|
|
62
66
|
/**
|
|
63
67
|
* Cannot be constructed.
|
|
64
68
|
*/
|
|
65
69
|
function PaymentsExtended() {}
|
|
66
70
|
|
|
67
|
-
PaymentsExtended.encodeFeeBips = function encodeFeeBips(fee) {
|
|
68
|
-
return v3Sdk.toHex(fee.multiply(10000).quotient);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
71
|
PaymentsExtended.encodeUnwrapWETH9 = function encodeUnwrapWETH9(amountMinimum, recipient, feeOptions) {
|
|
72
72
|
// if there's a recipient, just pass it along
|
|
73
73
|
if (typeof recipient === 'string') {
|
|
@@ -75,7 +75,7 @@ var PaymentsExtended = /*#__PURE__*/function () {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
if (!!feeOptions) {
|
|
78
|
-
var feeBips =
|
|
78
|
+
var feeBips = encodeFeeBips(feeOptions.fee);
|
|
79
79
|
var feeRecipient = sdkCore.validateAndParseAddress(feeOptions.recipient);
|
|
80
80
|
return PaymentsExtended.INTERFACE.encodeFunctionData('unwrapWETH9WithFee(uint256,uint256,address)', [v3Sdk.toHex(amountMinimum), feeBips, feeRecipient]);
|
|
81
81
|
} else {
|
|
@@ -90,7 +90,7 @@ var PaymentsExtended = /*#__PURE__*/function () {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
if (!!feeOptions) {
|
|
93
|
-
var feeBips =
|
|
93
|
+
var feeBips = encodeFeeBips(feeOptions.fee);
|
|
94
94
|
var feeRecipient = sdkCore.validateAndParseAddress(feeOptions.recipient);
|
|
95
95
|
return PaymentsExtended.INTERFACE.encodeFunctionData('sweepTokenWithFee(address,uint256,uint256,address)', [token.address, v3Sdk.toHex(amountMinimum), feeBips, feeRecipient]);
|
|
96
96
|
} else {
|
|
@@ -102,6 +102,10 @@ var PaymentsExtended = /*#__PURE__*/function () {
|
|
|
102
102
|
return PaymentsExtended.INTERFACE.encodeFunctionData('pull', [token.address, v3Sdk.toHex(amount)]);
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
+
PaymentsExtended.encodeWrapETH = function encodeWrapETH(amount) {
|
|
106
|
+
return PaymentsExtended.INTERFACE.encodeFunctionData('wrapETH', [v3Sdk.toHex(amount)]);
|
|
107
|
+
};
|
|
108
|
+
|
|
105
109
|
return PaymentsExtended;
|
|
106
110
|
}();
|
|
107
111
|
PaymentsExtended.INTERFACE = /*#__PURE__*/new abi.Interface(IPeripheryPaymentsWithFeeExtended_json.abi);
|
|
@@ -212,6 +216,11 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
|
212
216
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
213
217
|
}
|
|
214
218
|
|
|
219
|
+
(function (Protocol) {
|
|
220
|
+
Protocol["V2"] = "V2";
|
|
221
|
+
Protocol["V3"] = "V3";
|
|
222
|
+
})(exports.Protocol || (exports.Protocol = {}));
|
|
223
|
+
|
|
215
224
|
function createCommonjsModule(fn, module) {
|
|
216
225
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
217
226
|
}
|
|
@@ -972,11 +981,6 @@ try {
|
|
|
972
981
|
}
|
|
973
982
|
});
|
|
974
983
|
|
|
975
|
-
(function (Protocol) {
|
|
976
|
-
Protocol["V2"] = "V2";
|
|
977
|
-
Protocol["V3"] = "V3";
|
|
978
|
-
})(exports.Protocol || (exports.Protocol = {}));
|
|
979
|
-
|
|
980
984
|
var RouteV2 = /*#__PURE__*/function (_V2RouteSDK) {
|
|
981
985
|
_inheritsLoose(RouteV2, _V2RouteSDK);
|
|
982
986
|
|
|
@@ -1324,12 +1328,12 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1324
1328
|
var path = trade.route.path.map(function (token) {
|
|
1325
1329
|
return token.address;
|
|
1326
1330
|
});
|
|
1327
|
-
var recipient = routerMustCustody ? ADDRESS_THIS : options.recipient ? sdkCore.validateAndParseAddress(options.recipient)
|
|
1331
|
+
var recipient = routerMustCustody ? ADDRESS_THIS : typeof options.recipient === 'undefined' ? MSG_SENDER : sdkCore.validateAndParseAddress(options.recipient);
|
|
1328
1332
|
|
|
1329
1333
|
if (trade.tradeType === sdkCore.TradeType.EXACT_INPUT) {
|
|
1330
1334
|
var exactInputParams = [amountIn, // save gas by only passing slippage check if we can't check it later
|
|
1331
1335
|
// not a pure win, as sometimes this will cost us more when it would have caused an earlier failure
|
|
1332
|
-
routerMustCustody ? 0 : amountOut, path, recipient];
|
|
1336
|
+
routerMustCustody ? 0 : amountOut, path, recipient, false];
|
|
1333
1337
|
return SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', exactInputParams);
|
|
1334
1338
|
} else {
|
|
1335
1339
|
var exactOutputParams = [amountOut, amountIn, path, recipient];
|
|
@@ -1349,7 +1353,7 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1349
1353
|
var amountOut = v3Sdk.toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient); // flag for whether the trade is single hop or not
|
|
1350
1354
|
|
|
1351
1355
|
var singleHop = route.pools.length === 1;
|
|
1352
|
-
var recipient = routerMustCustody ? ADDRESS_THIS : options.recipient ? sdkCore.validateAndParseAddress(options.recipient)
|
|
1356
|
+
var recipient = routerMustCustody ? ADDRESS_THIS : typeof options.recipient === 'undefined' ? MSG_SENDER : sdkCore.validateAndParseAddress(options.recipient);
|
|
1353
1357
|
|
|
1354
1358
|
if (singleHop) {
|
|
1355
1359
|
if (trade.tradeType === sdkCore.TradeType.EXACT_INPUT) {
|
|
@@ -1360,7 +1364,8 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1360
1364
|
recipient: recipient,
|
|
1361
1365
|
amountIn: amountIn,
|
|
1362
1366
|
amountOutMinimum: amountOut,
|
|
1363
|
-
sqrtPriceLimitX96: 0
|
|
1367
|
+
sqrtPriceLimitX96: 0,
|
|
1368
|
+
hasAlreadyPaid: false
|
|
1364
1369
|
};
|
|
1365
1370
|
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInputSingle', [exactInputSingleParams]));
|
|
1366
1371
|
} else {
|
|
@@ -1383,7 +1388,8 @@ var SwapRouter = /*#__PURE__*/function () {
|
|
|
1383
1388
|
path: path,
|
|
1384
1389
|
recipient: recipient,
|
|
1385
1390
|
amountIn: amountIn,
|
|
1386
|
-
amountOutMinimum: amountOut
|
|
1391
|
+
amountOutMinimum: amountOut,
|
|
1392
|
+
hasAlreadyPaid: false
|
|
1387
1393
|
};
|
|
1388
1394
|
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [exactInputParams]));
|
|
1389
1395
|
} else {
|