@uniswap/router-sdk 1.21.4 → 1.22.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/dist/entities/route.d.ts +7 -0
- package/dist/entities/trade.d.ts +18 -0
- package/dist/router-sdk.cjs.development.js +58 -6
- 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 +58 -7
- package/dist/router-sdk.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/entities/route.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Route as V4RouteSDK, Pool as V4Pool } from '@uniswap/v4-sdk';
|
|
|
4
4
|
import { Protocol } from './protocol';
|
|
5
5
|
import { Currency, Price, Token } from '@uniswap/sdk-core';
|
|
6
6
|
import { MixedRouteSDK } from './mixedRoute/route';
|
|
7
|
+
export declare function getPathToken(currency: Currency, pool: Pair | V3Pool): Token;
|
|
7
8
|
export interface IRoute<TInput extends Currency, TOutput extends Currency, TPool extends Pair | V3Pool | V4Pool> {
|
|
8
9
|
protocol: Protocol;
|
|
9
10
|
pools: TPool[];
|
|
@@ -11,15 +12,21 @@ export interface IRoute<TInput extends Currency, TOutput extends Currency, TPool
|
|
|
11
12
|
midPrice: Price<TInput, TOutput>;
|
|
12
13
|
input: TInput;
|
|
13
14
|
output: TOutput;
|
|
15
|
+
pathInput: Currency;
|
|
16
|
+
pathOutput: Currency;
|
|
14
17
|
}
|
|
15
18
|
export declare class RouteV2<TInput extends Currency, TOutput extends Currency> extends V2RouteSDK<TInput, TOutput> implements IRoute<TInput, TOutput, Pair> {
|
|
16
19
|
readonly protocol: Protocol;
|
|
17
20
|
readonly pools: Pair[];
|
|
21
|
+
pathInput: Currency;
|
|
22
|
+
pathOutput: Currency;
|
|
18
23
|
constructor(v2Route: V2RouteSDK<TInput, TOutput>);
|
|
19
24
|
}
|
|
20
25
|
export declare class RouteV3<TInput extends Currency, TOutput extends Currency> extends V3RouteSDK<TInput, TOutput> implements IRoute<TInput, TOutput, V3Pool> {
|
|
21
26
|
readonly protocol: Protocol;
|
|
22
27
|
readonly path: Token[];
|
|
28
|
+
pathInput: Currency;
|
|
29
|
+
pathOutput: Currency;
|
|
23
30
|
constructor(v3Route: V3RouteSDK<TInput, TOutput>);
|
|
24
31
|
}
|
|
25
32
|
export declare class RouteV4<TInput extends Currency, TOutput extends Currency> extends V4RouteSDK<TInput, TOutput> implements IRoute<TInput, TOutput, V4Pool> {
|
package/dist/entities/trade.d.ts
CHANGED
|
@@ -43,6 +43,24 @@ export declare class Trade<TInput extends Currency, TOutput extends Currency, TT
|
|
|
43
43
|
});
|
|
44
44
|
get inputAmount(): CurrencyAmount<TInput>;
|
|
45
45
|
get outputAmount(): CurrencyAmount<TOutput>;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the sum of all swaps within the trade
|
|
48
|
+
* @returns
|
|
49
|
+
* inputAmount: total input amount
|
|
50
|
+
* inputAmountNative: total amount of native currency required for ETH input paths
|
|
51
|
+
* - 0 if inputAmount is native but no native input paths
|
|
52
|
+
* - undefined if inputAmount is not native
|
|
53
|
+
* outputAmount: total output amount
|
|
54
|
+
* outputAmountNative: total amount of native currency returned from ETH output paths
|
|
55
|
+
* - 0 if outputAmount is native but no native output paths
|
|
56
|
+
* - undefined if outputAmount is not native
|
|
57
|
+
*/
|
|
58
|
+
get amounts(): {
|
|
59
|
+
inputAmount: CurrencyAmount<TInput>;
|
|
60
|
+
inputAmountNative: CurrencyAmount<TInput> | undefined;
|
|
61
|
+
outputAmount: CurrencyAmount<TOutput>;
|
|
62
|
+
outputAmountNative: CurrencyAmount<TOutput> | undefined;
|
|
63
|
+
};
|
|
46
64
|
private _executionPrice;
|
|
47
65
|
/**
|
|
48
66
|
* The price expressed in terms of output amount/input amount.
|
|
@@ -1285,6 +1285,17 @@ var MixedRouteTrade = /*#__PURE__*/function () {
|
|
|
1285
1285
|
Protocol["MIXED"] = "MIXED";
|
|
1286
1286
|
})(exports.Protocol || (exports.Protocol = {}));
|
|
1287
1287
|
|
|
1288
|
+
// Helper function to get the pathInput and pathOutput for a V2 / V3 route
|
|
1289
|
+
// currency could be native so we check against the wrapped version as they don't support native ETH in path
|
|
1290
|
+
function getPathToken(currency, pool) {
|
|
1291
|
+
if (pool.token0.wrapped.equals(currency.wrapped)) {
|
|
1292
|
+
return pool.token0;
|
|
1293
|
+
} else if (pool.token1.wrapped.equals(currency.wrapped)) {
|
|
1294
|
+
return pool.token1;
|
|
1295
|
+
} else {
|
|
1296
|
+
throw new Error("Expected token " + currency.symbol + " to be either " + pool.token0.symbol + " or " + pool.token1.symbol);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1288
1299
|
// V2 route wrapper
|
|
1289
1300
|
var RouteV2 = /*#__PURE__*/function (_V2RouteSDK) {
|
|
1290
1301
|
_inheritsLoose(RouteV2, _V2RouteSDK);
|
|
@@ -1293,6 +1304,8 @@ var RouteV2 = /*#__PURE__*/function (_V2RouteSDK) {
|
|
|
1293
1304
|
_this = _V2RouteSDK.call(this, v2Route.pairs, v2Route.input, v2Route.output) || this;
|
|
1294
1305
|
_this.protocol = exports.Protocol.V2;
|
|
1295
1306
|
_this.pools = _this.pairs;
|
|
1307
|
+
_this.pathInput = getPathToken(v2Route.input, _this.pairs[0]);
|
|
1308
|
+
_this.pathOutput = getPathToken(v2Route.output, _this.pairs[_this.pairs.length - 1]);
|
|
1296
1309
|
return _this;
|
|
1297
1310
|
}
|
|
1298
1311
|
return RouteV2;
|
|
@@ -1305,6 +1318,8 @@ var RouteV3 = /*#__PURE__*/function (_V3RouteSDK) {
|
|
|
1305
1318
|
_this2 = _V3RouteSDK.call(this, v3Route.pools, v3Route.input, v3Route.output) || this;
|
|
1306
1319
|
_this2.protocol = exports.Protocol.V3;
|
|
1307
1320
|
_this2.path = v3Route.tokenPath;
|
|
1321
|
+
_this2.pathInput = getPathToken(v3Route.input, _this2.pools[0]);
|
|
1322
|
+
_this2.pathOutput = getPathToken(v3Route.output, _this2.pools[_this2.pools.length - 1]);
|
|
1308
1323
|
return _this2;
|
|
1309
1324
|
}
|
|
1310
1325
|
return RouteV3;
|
|
@@ -1696,13 +1711,13 @@ var Trade = /*#__PURE__*/function () {
|
|
|
1696
1711
|
if (this._inputAmount) {
|
|
1697
1712
|
return this._inputAmount;
|
|
1698
1713
|
}
|
|
1699
|
-
var
|
|
1714
|
+
var inputAmountCurrency = this.swaps[0].inputAmount.currency;
|
|
1700
1715
|
var totalInputFromRoutes = this.swaps.map(function (_ref5) {
|
|
1701
|
-
var
|
|
1702
|
-
return
|
|
1716
|
+
var routeInputAmount = _ref5.inputAmount;
|
|
1717
|
+
return routeInputAmount;
|
|
1703
1718
|
}).reduce(function (total, cur) {
|
|
1704
1719
|
return total.add(cur);
|
|
1705
|
-
}, sdkCore.CurrencyAmount.fromRawAmount(
|
|
1720
|
+
}, sdkCore.CurrencyAmount.fromRawAmount(inputAmountCurrency, 0));
|
|
1706
1721
|
this._inputAmount = totalInputFromRoutes;
|
|
1707
1722
|
return this._inputAmount;
|
|
1708
1723
|
}
|
|
@@ -1714,14 +1729,50 @@ var Trade = /*#__PURE__*/function () {
|
|
|
1714
1729
|
}
|
|
1715
1730
|
var outputCurrency = this.swaps[0].outputAmount.currency;
|
|
1716
1731
|
var totalOutputFromRoutes = this.swaps.map(function (_ref6) {
|
|
1717
|
-
var
|
|
1718
|
-
return
|
|
1732
|
+
var routeOutputAmount = _ref6.outputAmount;
|
|
1733
|
+
return routeOutputAmount;
|
|
1719
1734
|
}).reduce(function (total, cur) {
|
|
1720
1735
|
return total.add(cur);
|
|
1721
1736
|
}, sdkCore.CurrencyAmount.fromRawAmount(outputCurrency, 0));
|
|
1722
1737
|
this._outputAmount = totalOutputFromRoutes;
|
|
1723
1738
|
return this._outputAmount;
|
|
1724
1739
|
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Returns the sum of all swaps within the trade
|
|
1742
|
+
* @returns
|
|
1743
|
+
* inputAmount: total input amount
|
|
1744
|
+
* inputAmountNative: total amount of native currency required for ETH input paths
|
|
1745
|
+
* - 0 if inputAmount is native but no native input paths
|
|
1746
|
+
* - undefined if inputAmount is not native
|
|
1747
|
+
* outputAmount: total output amount
|
|
1748
|
+
* outputAmountNative: total amount of native currency returned from ETH output paths
|
|
1749
|
+
* - 0 if outputAmount is native but no native output paths
|
|
1750
|
+
* - undefined if outputAmount is not native
|
|
1751
|
+
*/
|
|
1752
|
+
}, {
|
|
1753
|
+
key: "amounts",
|
|
1754
|
+
get: function get() {
|
|
1755
|
+
var _this$swaps$find, _this$swaps$find2;
|
|
1756
|
+
// Find native currencies for reduce below
|
|
1757
|
+
var inputNativeCurrency = (_this$swaps$find = this.swaps.find(function (_ref7) {
|
|
1758
|
+
var inputAmount = _ref7.inputAmount;
|
|
1759
|
+
return inputAmount.currency.isNative;
|
|
1760
|
+
})) == null ? void 0 : _this$swaps$find.inputAmount.currency;
|
|
1761
|
+
var outputNativeCurrency = (_this$swaps$find2 = this.swaps.find(function (_ref8) {
|
|
1762
|
+
var outputAmount = _ref8.outputAmount;
|
|
1763
|
+
return outputAmount.currency.isNative;
|
|
1764
|
+
})) == null ? void 0 : _this$swaps$find2.outputAmount.currency;
|
|
1765
|
+
return {
|
|
1766
|
+
inputAmount: this.inputAmount,
|
|
1767
|
+
inputAmountNative: inputNativeCurrency ? this.swaps.reduce(function (total, swap) {
|
|
1768
|
+
return swap.route.pathInput.isNative ? total.add(swap.inputAmount) : total;
|
|
1769
|
+
}, sdkCore.CurrencyAmount.fromRawAmount(inputNativeCurrency, 0)) : undefined,
|
|
1770
|
+
outputAmount: this.outputAmount,
|
|
1771
|
+
outputAmountNative: outputNativeCurrency ? this.swaps.reduce(function (total, swap) {
|
|
1772
|
+
return swap.route.pathOutput.isNative ? total.add(swap.outputAmount) : total;
|
|
1773
|
+
}, sdkCore.CurrencyAmount.fromRawAmount(outputNativeCurrency, 0)) : undefined
|
|
1774
|
+
};
|
|
1775
|
+
}
|
|
1725
1776
|
/**
|
|
1726
1777
|
* The price expressed in terms of output amount/input amount.
|
|
1727
1778
|
*/
|
|
@@ -2368,6 +2419,7 @@ exports.amountWithPathCurrency = amountWithPathCurrency;
|
|
|
2368
2419
|
exports.encodeMixedRouteToPath = encodeMixedRouteToPath;
|
|
2369
2420
|
exports.getOutputOfPools = getOutputOfPools;
|
|
2370
2421
|
exports.getPathCurrency = getPathCurrency;
|
|
2422
|
+
exports.getPathToken = getPathToken;
|
|
2371
2423
|
exports.isMint = isMint;
|
|
2372
2424
|
exports.isValidTokenPath = isValidTokenPath;
|
|
2373
2425
|
exports.partitionMixedRouteByProtocol = partitionMixedRouteByProtocol;
|