@uniswap/router-sdk 1.23.0 → 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/dist/{approveAndCall.d.ts → cjs/src/approveAndCall.d.ts} +33 -33
- package/dist/cjs/src/approveAndCall.js +111 -0
- package/dist/cjs/src/approveAndCall.js.map +1 -0
- package/dist/{constants.d.ts → cjs/src/constants.d.ts} +13 -13
- package/dist/cjs/src/constants.js +22 -0
- package/dist/cjs/src/constants.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/mixedRoute/route.d.ts +29 -29
- package/dist/cjs/src/entities/mixedRoute/route.js +119 -0
- package/dist/cjs/src/entities/mixedRoute/route.js.map +1 -0
- package/dist/cjs/src/entities/mixedRoute/route.test.d.ts +1 -0
- package/dist/cjs/src/entities/mixedRoute/route.test.js +469 -0
- package/dist/cjs/src/entities/mixedRoute/route.test.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/mixedRoute/trade.d.ts +183 -183
- package/dist/cjs/src/entities/mixedRoute/trade.js +357 -0
- package/dist/cjs/src/entities/mixedRoute/trade.js.map +1 -0
- package/dist/cjs/src/entities/mixedRoute/trade.test.d.ts +1 -0
- package/dist/cjs/src/entities/mixedRoute/trade.test.js +1010 -0
- package/dist/cjs/src/entities/mixedRoute/trade.test.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/protocol.d.ts +6 -6
- package/dist/cjs/src/entities/protocol.js +11 -0
- package/dist/cjs/src/entities/protocol.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/route.d.ts +40 -40
- package/dist/cjs/src/entities/route.js +63 -0
- package/dist/cjs/src/entities/route.js.map +1 -0
- package/dist/cjs/src/entities/route.test.d.ts +1 -0
- package/dist/cjs/src/entities/route.test.js +192 -0
- package/dist/cjs/src/entities/route.test.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/trade.d.ts +127 -127
- package/dist/cjs/src/entities/trade.js +366 -0
- package/dist/cjs/src/entities/trade.js.map +1 -0
- package/dist/cjs/src/entities/trade.test.d.ts +1 -0
- package/dist/cjs/src/entities/trade.test.js +1267 -0
- package/dist/cjs/src/entities/trade.test.js.map +1 -0
- package/dist/{index.d.ts → cjs/src/index.d.ts} +14 -14
- package/dist/cjs/src/index.js +18 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/{multicallExtended.d.ts → cjs/src/multicallExtended.d.ts} +11 -11
- package/dist/cjs/src/multicallExtended.js +43 -0
- package/dist/cjs/src/multicallExtended.js.map +1 -0
- package/dist/cjs/src/multicallExtended.test.d.ts +1 -0
- package/dist/cjs/src/multicallExtended.test.js +22 -0
- package/dist/cjs/src/multicallExtended.test.js.map +1 -0
- package/dist/{paymentsExtended.d.ts → cjs/src/paymentsExtended.d.ts} +15 -15
- package/dist/cjs/src/paymentsExtended.js +65 -0
- package/dist/cjs/src/paymentsExtended.js.map +1 -0
- package/dist/cjs/src/paymentsExtended.test.d.ts +1 -0
- package/dist/cjs/src/paymentsExtended.test.js +60 -0
- package/dist/cjs/src/paymentsExtended.test.js.map +1 -0
- package/dist/{swapRouter.d.ts → cjs/src/swapRouter.d.ts} +95 -95
- package/dist/cjs/src/swapRouter.js +439 -0
- package/dist/cjs/src/swapRouter.js.map +1 -0
- package/dist/cjs/src/swapRouter.test.d.ts +1 -0
- package/dist/cjs/src/swapRouter.test.js +1161 -0
- package/dist/cjs/src/swapRouter.test.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/TPool.d.ts +4 -4
- package/dist/cjs/src/utils/TPool.js +3 -0
- package/dist/cjs/src/utils/TPool.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/encodeMixedRouteToPath.d.ts +9 -9
- package/dist/cjs/src/utils/encodeMixedRouteToPath.js +90 -0
- package/dist/cjs/src/utils/encodeMixedRouteToPath.js.map +1 -0
- package/dist/cjs/src/utils/encodeMixedRouteToPath.test.d.ts +1 -0
- package/dist/cjs/src/utils/encodeMixedRouteToPath.test.js +136 -0
- package/dist/cjs/src/utils/encodeMixedRouteToPath.test.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/index.d.ts +16 -16
- package/dist/cjs/src/utils/index.js +51 -0
- package/dist/cjs/src/utils/index.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/pathCurrency.d.ts +4 -4
- package/dist/cjs/src/utils/pathCurrency.js +35 -0
- package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
- package/dist/cjs/src/utils/pathCurrency.test.d.ts +1 -0
- package/dist/cjs/src/utils/pathCurrency.test.js +17 -0
- package/dist/cjs/src/utils/pathCurrency.test.js.map +1 -0
- package/dist/esm/src/approveAndCall.d.ts +33 -0
- package/dist/esm/src/approveAndCall.js +105 -0
- package/dist/esm/src/approveAndCall.js.map +1 -0
- package/dist/esm/src/constants.d.ts +13 -0
- package/dist/esm/src/constants.js +18 -0
- package/dist/esm/src/constants.js.map +1 -0
- package/dist/esm/src/entities/mixedRoute/route.d.ts +29 -0
- package/dist/esm/src/entities/mixedRoute/route.js +114 -0
- package/dist/esm/src/entities/mixedRoute/route.js.map +1 -0
- package/dist/esm/src/entities/mixedRoute/route.test.d.ts +1 -0
- package/dist/esm/src/entities/mixedRoute/route.test.js +467 -0
- package/dist/esm/src/entities/mixedRoute/route.test.js.map +1 -0
- package/dist/esm/src/entities/mixedRoute/trade.d.ts +183 -0
- package/dist/esm/src/entities/mixedRoute/trade.js +352 -0
- package/dist/esm/src/entities/mixedRoute/trade.js.map +1 -0
- package/dist/esm/src/entities/mixedRoute/trade.test.d.ts +1 -0
- package/dist/esm/src/entities/mixedRoute/trade.test.js +1008 -0
- package/dist/esm/src/entities/mixedRoute/trade.test.js.map +1 -0
- package/dist/esm/src/entities/protocol.d.ts +6 -0
- package/dist/esm/src/entities/protocol.js +8 -0
- package/dist/esm/src/entities/protocol.js.map +1 -0
- package/dist/esm/src/entities/route.d.ts +40 -0
- package/dist/esm/src/entities/route.js +55 -0
- package/dist/esm/src/entities/route.js.map +1 -0
- package/dist/esm/src/entities/route.test.d.ts +1 -0
- package/dist/esm/src/entities/route.test.js +190 -0
- package/dist/esm/src/entities/route.test.js.map +1 -0
- package/dist/esm/src/entities/trade.d.ts +127 -0
- package/dist/esm/src/entities/trade.js +362 -0
- package/dist/esm/src/entities/trade.js.map +1 -0
- package/dist/esm/src/entities/trade.test.d.ts +1 -0
- package/dist/esm/src/entities/trade.test.js +1265 -0
- package/dist/esm/src/entities/trade.test.js.map +1 -0
- package/dist/esm/src/index.d.ts +14 -0
- package/dist/esm/src/index.js +15 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/multicallExtended.d.ts +11 -0
- package/dist/esm/src/multicallExtended.js +39 -0
- package/dist/esm/src/multicallExtended.js.map +1 -0
- package/dist/esm/src/multicallExtended.test.d.ts +1 -0
- package/dist/esm/src/multicallExtended.test.js +20 -0
- package/dist/esm/src/multicallExtended.test.js.map +1 -0
- package/dist/esm/src/paymentsExtended.d.ts +15 -0
- package/dist/esm/src/paymentsExtended.js +61 -0
- package/dist/esm/src/paymentsExtended.js.map +1 -0
- package/dist/esm/src/paymentsExtended.test.d.ts +1 -0
- package/dist/esm/src/paymentsExtended.test.js +57 -0
- package/dist/esm/src/paymentsExtended.test.js.map +1 -0
- package/dist/esm/src/swapRouter.d.ts +95 -0
- package/dist/esm/src/swapRouter.js +434 -0
- package/dist/esm/src/swapRouter.js.map +1 -0
- package/dist/esm/src/swapRouter.test.d.ts +1 -0
- package/dist/esm/src/swapRouter.test.js +1159 -0
- package/dist/esm/src/swapRouter.test.js.map +1 -0
- package/dist/esm/src/utils/TPool.d.ts +4 -0
- package/dist/esm/src/utils/TPool.js +2 -0
- package/dist/esm/src/utils/TPool.js.map +1 -0
- package/dist/esm/src/utils/encodeMixedRouteToPath.d.ts +9 -0
- package/dist/esm/src/utils/encodeMixedRouteToPath.js +86 -0
- package/dist/esm/src/utils/encodeMixedRouteToPath.js.map +1 -0
- package/dist/esm/src/utils/encodeMixedRouteToPath.test.d.ts +1 -0
- package/dist/esm/src/utils/encodeMixedRouteToPath.test.js +134 -0
- package/dist/esm/src/utils/encodeMixedRouteToPath.test.js.map +1 -0
- package/dist/esm/src/utils/index.d.ts +16 -0
- package/dist/esm/src/utils/index.js +46 -0
- package/dist/esm/src/utils/index.js.map +1 -0
- package/dist/esm/src/utils/pathCurrency.d.ts +4 -0
- package/dist/esm/src/utils/pathCurrency.js +30 -0
- package/dist/esm/src/utils/pathCurrency.js.map +1 -0
- package/dist/esm/src/utils/pathCurrency.test.d.ts +1 -0
- package/dist/esm/src/utils/pathCurrency.test.js +15 -0
- package/dist/esm/src/utils/pathCurrency.test.js.map +1 -0
- package/dist/types/src/approveAndCall.d.ts +33 -0
- package/dist/types/src/constants.d.ts +13 -0
- package/dist/types/src/entities/mixedRoute/route.d.ts +29 -0
- package/dist/types/src/entities/mixedRoute/route.test.d.ts +1 -0
- package/dist/types/src/entities/mixedRoute/trade.d.ts +183 -0
- package/dist/types/src/entities/mixedRoute/trade.test.d.ts +1 -0
- package/dist/types/src/entities/protocol.d.ts +6 -0
- package/dist/types/src/entities/route.d.ts +40 -0
- package/dist/types/src/entities/route.test.d.ts +1 -0
- package/dist/types/src/entities/trade.d.ts +127 -0
- package/dist/types/src/entities/trade.test.d.ts +1 -0
- package/dist/types/src/index.d.ts +14 -0
- package/dist/types/src/multicallExtended.d.ts +11 -0
- package/dist/types/src/multicallExtended.test.d.ts +1 -0
- package/dist/types/src/paymentsExtended.d.ts +15 -0
- package/dist/types/src/paymentsExtended.test.d.ts +1 -0
- package/dist/types/src/swapRouter.d.ts +95 -0
- package/dist/types/src/swapRouter.test.d.ts +1 -0
- package/dist/types/src/utils/TPool.d.ts +4 -0
- package/dist/types/src/utils/encodeMixedRouteToPath.d.ts +9 -0
- package/dist/types/src/utils/encodeMixedRouteToPath.test.d.ts +1 -0
- package/dist/types/src/utils/index.d.ts +16 -0
- package/dist/types/src/utils/pathCurrency.d.ts +4 -0
- package/dist/types/src/utils/pathCurrency.test.d.ts +1 -0
- package/package.json +33 -18
- package/dist/index.js +0 -8
- package/dist/router-sdk.cjs.development.js +0 -2485
- package/dist/router-sdk.cjs.development.js.map +0 -1
- package/dist/router-sdk.cjs.production.min.js +0 -2
- package/dist/router-sdk.cjs.production.min.js.map +0 -1
- package/dist/router-sdk.esm.js +0 -2452
- package/dist/router-sdk.esm.js.map +0 -1
|
@@ -0,0 +1,1008 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { Percent, Price, sqrt, Token, CurrencyAmount, TradeType, WETH9, Ether } from '@uniswap/sdk-core';
|
|
3
|
+
import { Pair } from '@uniswap/v2-sdk';
|
|
4
|
+
import { encodeSqrtRatioX96, FeeAmount, nearestUsableTick, Pool as V3Pool, TickMath, TICK_SPACINGS, } from '@uniswap/v3-sdk';
|
|
5
|
+
import { Pool as V4Pool } from '@uniswap/v4-sdk';
|
|
6
|
+
import JSBI from 'jsbi';
|
|
7
|
+
import { MixedRouteSDK } from './route';
|
|
8
|
+
import { MixedRouteTrade } from './trade';
|
|
9
|
+
import { ADDRESS_ZERO } from '../../constants';
|
|
10
|
+
describe('MixedRouteTrade', () => {
|
|
11
|
+
const ETHER = Ether.onChain(1);
|
|
12
|
+
const token0 = new Token(1, '0x0000000000000000000000000000000000000001', 18, 't0', 'token0');
|
|
13
|
+
const token1 = new Token(1, '0x0000000000000000000000000000000000000002', 18, 't1', 'token1');
|
|
14
|
+
const token2 = new Token(1, '0x0000000000000000000000000000000000000003', 18, 't2', 'token2');
|
|
15
|
+
const token3 = new Token(1, '0x0000000000000000000000000000000000000004', 18, 't3', 'token3');
|
|
16
|
+
function v2StylePool(reserve0, reserve1, v4Pool = false) {
|
|
17
|
+
const currency0 = reserve0.currency;
|
|
18
|
+
const currency1 = reserve1.currency;
|
|
19
|
+
const fee = FeeAmount.MEDIUM;
|
|
20
|
+
const sqrtRatioX96 = encodeSqrtRatioX96(reserve1.quotient, reserve0.quotient);
|
|
21
|
+
const liquidity = sqrt(JSBI.multiply(reserve0.quotient, reserve1.quotient));
|
|
22
|
+
const tick = TickMath.getTickAtSqrtRatio(sqrtRatioX96);
|
|
23
|
+
const tickSpacing = TICK_SPACINGS[fee];
|
|
24
|
+
const tickBitmap = [
|
|
25
|
+
{
|
|
26
|
+
index: nearestUsableTick(TickMath.MIN_TICK, tickSpacing),
|
|
27
|
+
liquidityNet: liquidity,
|
|
28
|
+
liquidityGross: liquidity,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
index: nearestUsableTick(TickMath.MAX_TICK, tickSpacing),
|
|
32
|
+
liquidityNet: JSBI.multiply(liquidity, JSBI.BigInt(-1)),
|
|
33
|
+
liquidityGross: liquidity,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
if (!v4Pool) {
|
|
37
|
+
return new V3Pool(currency0.wrapped, currency1.wrapped, fee, sqrtRatioX96, liquidity, tick, tickBitmap);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return new V4Pool(currency0, currency1, fee, tickSpacing, ADDRESS_ZERO, sqrtRatioX96, liquidity, tick, tickBitmap);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const pool_v4_0_weth = v2StylePool(CurrencyAmount.fromRawAmount(token0, 120000), CurrencyAmount.fromRawAmount(WETH9[1], 130000), true);
|
|
44
|
+
const pool_v4_0_eth = v2StylePool(CurrencyAmount.fromRawAmount(token0, 120000), CurrencyAmount.fromRawAmount(ETHER, 130000), true);
|
|
45
|
+
const pool_v3_0_1 = v2StylePool(CurrencyAmount.fromRawAmount(token0, 100000), CurrencyAmount.fromRawAmount(token1, 100000));
|
|
46
|
+
const pool_v3_0_2 = v2StylePool(CurrencyAmount.fromRawAmount(token0, 100000), CurrencyAmount.fromRawAmount(token2, 110000));
|
|
47
|
+
const pool_v3_0_3 = v2StylePool(CurrencyAmount.fromRawAmount(token0, 100000), CurrencyAmount.fromRawAmount(token3, 90000));
|
|
48
|
+
const pool_v3_1_2 = v2StylePool(CurrencyAmount.fromRawAmount(token1, 120000), CurrencyAmount.fromRawAmount(token2, 100000));
|
|
49
|
+
const pool_v3_1_3 = v2StylePool(CurrencyAmount.fromRawAmount(token1, 120000), CurrencyAmount.fromRawAmount(token3, 130000));
|
|
50
|
+
const pool_v3_weth_0 = v2StylePool(CurrencyAmount.fromRawAmount(WETH9[1], JSBI.BigInt(100000)), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100000)));
|
|
51
|
+
const pool_v3_weth_1 = v2StylePool(CurrencyAmount.fromRawAmount(WETH9[1], JSBI.BigInt(100000)), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100000)));
|
|
52
|
+
const pool_v3_weth_2 = v2StylePool(CurrencyAmount.fromRawAmount(WETH9[1], JSBI.BigInt(100000)), CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(100000)));
|
|
53
|
+
const pair_0_1 = new Pair(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000)), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(1000)));
|
|
54
|
+
const pair_0_2 = new Pair(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000)), CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(1100)));
|
|
55
|
+
const pair_0_3 = new Pair(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000)), CurrencyAmount.fromRawAmount(token3, JSBI.BigInt(900)));
|
|
56
|
+
const pair_1_2 = new Pair(CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(1200)), CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(1000)));
|
|
57
|
+
const pair_1_3 = new Pair(CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(1200)), CurrencyAmount.fromRawAmount(token3, JSBI.BigInt(1300)));
|
|
58
|
+
const pair_weth_0 = new Pair(CurrencyAmount.fromRawAmount(WETH9[1], JSBI.BigInt(1000)), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000)));
|
|
59
|
+
const empty_pair_0_1 = new Pair(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(0)), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(0)));
|
|
60
|
+
/// @dev copied over from v3-sdk trade.test.ts
|
|
61
|
+
describe('is backwards compatible with pure v3 routes', () => {
|
|
62
|
+
describe('#fromRoute', () => {
|
|
63
|
+
it('can be constructed with ETHER as input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v3_weth_0], ETHER, token0), CurrencyAmount.fromRawAmount(Ether.onChain(1), JSBI.BigInt(10000)), TradeType.EXACT_INPUT);
|
|
65
|
+
expect(trade.inputAmount.currency).toEqual(ETHER);
|
|
66
|
+
expect(trade.outputAmount.currency).toEqual(token0);
|
|
67
|
+
}));
|
|
68
|
+
it('can be constructed with ETHER as output for exact input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v3_weth_0], token0, ETHER), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)), TradeType.EXACT_INPUT);
|
|
70
|
+
expect(trade.inputAmount.currency).toEqual(token0);
|
|
71
|
+
expect(trade.outputAmount.currency).toEqual(ETHER);
|
|
72
|
+
}));
|
|
73
|
+
it('throws regardless for exact output', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
|
+
yield expect(MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v3_weth_0], ETHER, token0), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)), TradeType.EXACT_OUTPUT)).rejects.toThrow('TRADE_TYPE');
|
|
75
|
+
}));
|
|
76
|
+
});
|
|
77
|
+
describe('#fromRoutes', () => {
|
|
78
|
+
it('can be constructed with ETHER as input with multiple routes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
const trade = yield MixedRouteTrade.fromRoutes([
|
|
80
|
+
{
|
|
81
|
+
amount: CurrencyAmount.fromRawAmount(Ether.onChain(1), JSBI.BigInt(10000)),
|
|
82
|
+
route: new MixedRouteSDK([pool_v3_weth_0], ETHER, token0),
|
|
83
|
+
},
|
|
84
|
+
], TradeType.EXACT_INPUT);
|
|
85
|
+
expect(trade.inputAmount.currency).toEqual(ETHER);
|
|
86
|
+
expect(trade.outputAmount.currency).toEqual(token0);
|
|
87
|
+
}));
|
|
88
|
+
it('can be constructed with ETHER as output for exact input with multiple routes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
const trade = yield MixedRouteTrade.fromRoutes([
|
|
90
|
+
{
|
|
91
|
+
amount: CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(3000)),
|
|
92
|
+
route: new MixedRouteSDK([pool_v3_weth_0], token0, ETHER),
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
amount: CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(7000)),
|
|
96
|
+
route: new MixedRouteSDK([pool_v3_0_1, pool_v3_weth_1], token0, ETHER),
|
|
97
|
+
},
|
|
98
|
+
], TradeType.EXACT_INPUT);
|
|
99
|
+
expect(trade.inputAmount.currency).toEqual(token0);
|
|
100
|
+
expect(trade.outputAmount.currency).toEqual(ETHER);
|
|
101
|
+
}));
|
|
102
|
+
it('throws if pools are re-used between routes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
yield expect(MixedRouteTrade.fromRoutes([
|
|
104
|
+
{
|
|
105
|
+
amount: CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(4500)),
|
|
106
|
+
route: new MixedRouteSDK([pool_v3_0_1, pool_v3_weth_1], token0, ETHER),
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
amount: CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(5500)),
|
|
110
|
+
route: new MixedRouteSDK([pool_v3_0_1, pool_v3_1_2, pool_v3_weth_2], token0, ETHER),
|
|
111
|
+
},
|
|
112
|
+
], TradeType.EXACT_INPUT)).rejects.toThrow('POOLS_DUPLICATED');
|
|
113
|
+
}));
|
|
114
|
+
it('throws if created with exact output', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
+
yield expect(MixedRouteTrade.fromRoutes([
|
|
116
|
+
{
|
|
117
|
+
amount: CurrencyAmount.fromRawAmount(Ether.onChain(1), JSBI.BigInt(10000)),
|
|
118
|
+
route: new MixedRouteSDK([pool_v3_weth_0], ETHER, token0),
|
|
119
|
+
},
|
|
120
|
+
], TradeType.EXACT_OUTPUT)).rejects.toThrow('TRADE_TYPE');
|
|
121
|
+
}));
|
|
122
|
+
});
|
|
123
|
+
describe('#createUncheckedTrade', () => {
|
|
124
|
+
it('throws if input currency does not match route', () => {
|
|
125
|
+
expect(() => MixedRouteTrade.createUncheckedTrade({
|
|
126
|
+
route: new MixedRouteSDK([pool_v3_0_1], token0, token1),
|
|
127
|
+
inputAmount: CurrencyAmount.fromRawAmount(token2, 10000),
|
|
128
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 10000),
|
|
129
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
130
|
+
})).toThrow('INPUT_CURRENCY_MATCH');
|
|
131
|
+
});
|
|
132
|
+
it('throws if output currency does not match route', () => {
|
|
133
|
+
expect(() => MixedRouteTrade.createUncheckedTrade({
|
|
134
|
+
route: new MixedRouteSDK([pool_v3_0_1], token0, token1),
|
|
135
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 10000),
|
|
136
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 10000),
|
|
137
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
138
|
+
})).toThrow('OUTPUT_CURRENCY_MATCH');
|
|
139
|
+
});
|
|
140
|
+
it('throws if tradeType is exactOutput', () => {
|
|
141
|
+
try {
|
|
142
|
+
MixedRouteTrade.createUncheckedTrade({
|
|
143
|
+
route: new MixedRouteSDK([pool_v3_0_1], token1, token0),
|
|
144
|
+
inputAmount: CurrencyAmount.fromRawAmount(token1, 10000),
|
|
145
|
+
outputAmount: CurrencyAmount.fromRawAmount(token0, 100000),
|
|
146
|
+
tradeType: TradeType.EXACT_OUTPUT,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
expect(err.message).toEqual('Invariant failed: TRADE_TYPE');
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
it('can create an exact input trade without simulating', () => {
|
|
155
|
+
MixedRouteTrade.createUncheckedTrade({
|
|
156
|
+
route: new MixedRouteSDK([pool_v3_0_1], token0, token1),
|
|
157
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 10000),
|
|
158
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 100000),
|
|
159
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
describe('#createUncheckedTradeWithMultipleRoutes', () => {
|
|
164
|
+
it('throws if input currency does not match route with multiple routes', () => {
|
|
165
|
+
expect(() => MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
166
|
+
routes: [
|
|
167
|
+
{
|
|
168
|
+
route: new MixedRouteSDK([pool_v3_1_2], token2, token1),
|
|
169
|
+
inputAmount: CurrencyAmount.fromRawAmount(token2, 2000),
|
|
170
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 2000),
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
route: new MixedRouteSDK([pool_v3_0_1], token0, token1),
|
|
174
|
+
inputAmount: CurrencyAmount.fromRawAmount(token2, 8000),
|
|
175
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 8000),
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
179
|
+
})).toThrow('INPUT_CURRENCY_MATCH');
|
|
180
|
+
});
|
|
181
|
+
it('throws if output currency does not match route with multiple routes', () => {
|
|
182
|
+
expect(() => MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
183
|
+
routes: [
|
|
184
|
+
{
|
|
185
|
+
route: new MixedRouteSDK([pool_v3_0_2], token0, token2),
|
|
186
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 10000),
|
|
187
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 10000),
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
route: new MixedRouteSDK([pool_v3_0_1], token0, token1),
|
|
191
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 10000),
|
|
192
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 10000),
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
196
|
+
})).toThrow('OUTPUT_CURRENCY_MATCH');
|
|
197
|
+
});
|
|
198
|
+
it('throws if tradeType is exact output', () => {
|
|
199
|
+
try {
|
|
200
|
+
MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
201
|
+
routes: [
|
|
202
|
+
{
|
|
203
|
+
route: new MixedRouteSDK([pool_v3_0_1], token0, token1),
|
|
204
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 5000),
|
|
205
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 50000),
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
route: new MixedRouteSDK([pool_v3_0_2, pool_v3_1_2], token0, token1),
|
|
209
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 5000),
|
|
210
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 50000),
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
tradeType: TradeType.EXACT_OUTPUT,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
// @ts-ignore
|
|
218
|
+
expect(err.message).toEqual('Invariant failed: TRADE_TYPE');
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
it('can create an exact input trade without simulating with multiple routes', () => {
|
|
222
|
+
MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
223
|
+
routes: [
|
|
224
|
+
{
|
|
225
|
+
route: new MixedRouteSDK([pool_v3_0_1], token0, token1),
|
|
226
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 5000),
|
|
227
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 50000),
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
route: new MixedRouteSDK([pool_v3_0_2, pool_v3_1_2], token0, token1),
|
|
231
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 5000),
|
|
232
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 50000),
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
describe('#route and #swaps', () => {
|
|
240
|
+
const singleRoute = MixedRouteTrade.createUncheckedTrade({
|
|
241
|
+
route: new MixedRouteSDK([pool_v3_0_1, pool_v3_1_2], token0, token2),
|
|
242
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
|
|
243
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 69),
|
|
244
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
245
|
+
});
|
|
246
|
+
const multiRoute = MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
247
|
+
routes: [
|
|
248
|
+
{
|
|
249
|
+
route: new MixedRouteSDK([pool_v3_0_1, pool_v3_1_2], token0, token2),
|
|
250
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
|
|
251
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 35),
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
route: new MixedRouteSDK([pool_v3_0_2], token0, token2),
|
|
255
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
|
|
256
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 34),
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
260
|
+
});
|
|
261
|
+
it('can access route for single route trade if less than 0', () => {
|
|
262
|
+
expect(singleRoute.swaps).toBeDefined();
|
|
263
|
+
});
|
|
264
|
+
it('can access routes for both single and multi route trades', () => {
|
|
265
|
+
expect(singleRoute.swaps).toBeDefined();
|
|
266
|
+
expect(singleRoute.swaps).toHaveLength(1);
|
|
267
|
+
expect(multiRoute.swaps).toBeDefined();
|
|
268
|
+
expect(multiRoute.swaps).toHaveLength(2);
|
|
269
|
+
});
|
|
270
|
+
it('throws if access route on multi route trade', () => {
|
|
271
|
+
expect(() => multiRoute.route).toThrow('MULTIPLE_ROUTES');
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
describe('#worstExecutionPrice', () => {
|
|
275
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
276
|
+
const exactIn = MixedRouteTrade.createUncheckedTrade({
|
|
277
|
+
route: new MixedRouteSDK([pool_v3_0_1, pool_v3_1_2], token0, token2),
|
|
278
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
|
|
279
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 69),
|
|
280
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
281
|
+
});
|
|
282
|
+
const exactInMultiRoute = MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
283
|
+
routes: [
|
|
284
|
+
{
|
|
285
|
+
route: new MixedRouteSDK([pool_v3_0_1, pool_v3_1_2], token0, token2),
|
|
286
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
|
|
287
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 35),
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
route: new MixedRouteSDK([pool_v3_0_2], token0, token2),
|
|
291
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
|
|
292
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 34),
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
296
|
+
});
|
|
297
|
+
it('throws if less than 0', () => {
|
|
298
|
+
expect(() => exactIn.minimumAmountOut(new Percent(-1, 100))).toThrow('SLIPPAGE_TOLERANCE');
|
|
299
|
+
});
|
|
300
|
+
it('returns exact if 0', () => {
|
|
301
|
+
expect(exactIn.worstExecutionPrice(new Percent(0, 100))).toEqual(exactIn.executionPrice);
|
|
302
|
+
});
|
|
303
|
+
it('returns exact if nonzero', () => {
|
|
304
|
+
expect(exactIn.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 100, 69));
|
|
305
|
+
expect(exactIn.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 100, 65));
|
|
306
|
+
expect(exactIn.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 100, 23));
|
|
307
|
+
});
|
|
308
|
+
it('returns exact if nonzero with multiple routes', () => {
|
|
309
|
+
expect(exactInMultiRoute.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 100, 69));
|
|
310
|
+
expect(exactInMultiRoute.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 100, 65));
|
|
311
|
+
expect(exactInMultiRoute.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 100, 23));
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
describe('#priceImpact', () => {
|
|
316
|
+
describe('100% v3 route', () => {
|
|
317
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
318
|
+
const exactIn = MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
319
|
+
routes: [
|
|
320
|
+
{
|
|
321
|
+
route: new MixedRouteSDK([pool_v3_0_1, pool_v3_1_2], token0, token2),
|
|
322
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
|
|
323
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 69),
|
|
324
|
+
},
|
|
325
|
+
],
|
|
326
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
327
|
+
});
|
|
328
|
+
const exactInMultipleRoutes = MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
329
|
+
routes: [
|
|
330
|
+
{
|
|
331
|
+
route: new MixedRouteSDK([pool_v3_0_1, pool_v3_1_2], token0, token2),
|
|
332
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 90),
|
|
333
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 62),
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
route: new MixedRouteSDK([pool_v3_0_2], token0, token2),
|
|
337
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 10),
|
|
338
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 7),
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
342
|
+
});
|
|
343
|
+
it('is correct', () => {
|
|
344
|
+
expect(exactIn.priceImpact.toSignificant(3)).toEqual('17.2');
|
|
345
|
+
});
|
|
346
|
+
it('is correct with multiple routes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
347
|
+
expect(exactInMultipleRoutes.priceImpact.toSignificant(3)).toEqual('19.8');
|
|
348
|
+
}));
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
describe('mixed route', () => {
|
|
352
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
353
|
+
const exactIn = MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
354
|
+
routes: [
|
|
355
|
+
{
|
|
356
|
+
route: new MixedRouteSDK([pool_v3_0_1, pair_1_2], token0, token2),
|
|
357
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
|
|
358
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 69),
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
362
|
+
});
|
|
363
|
+
const exactInMultipleRoutes = MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
364
|
+
routes: [
|
|
365
|
+
{
|
|
366
|
+
route: new MixedRouteSDK([pool_v3_0_1, pair_1_2], token0, token2),
|
|
367
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 90),
|
|
368
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 62),
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
route: new MixedRouteSDK([pool_v3_0_2], token0, token2),
|
|
372
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 10),
|
|
373
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 7),
|
|
374
|
+
},
|
|
375
|
+
],
|
|
376
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
377
|
+
});
|
|
378
|
+
it('is correct', () => {
|
|
379
|
+
expect(exactIn.priceImpact.toSignificant(3)).toEqual('17.2');
|
|
380
|
+
});
|
|
381
|
+
it('is correct with multiple routes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
382
|
+
expect(exactInMultipleRoutes.priceImpact.toSignificant(3)).toEqual('19.8');
|
|
383
|
+
}));
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
describe('#bestTradeExactIn', () => {
|
|
388
|
+
it('throws with empty pools', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
389
|
+
yield expect(MixedRouteTrade.bestTradeExactIn([], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)), token2)).rejects.toThrow('POOLS');
|
|
390
|
+
}));
|
|
391
|
+
it('throws with max hops of 0', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
392
|
+
yield expect(MixedRouteTrade.bestTradeExactIn([pool_v3_0_2], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)), token2, {
|
|
393
|
+
maxHops: 0,
|
|
394
|
+
})).rejects.toThrow('MAX_HOPS');
|
|
395
|
+
}));
|
|
396
|
+
it('provides best route', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
397
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_0_1, pool_v3_0_2, pool_v3_1_2], CurrencyAmount.fromRawAmount(token0, 10000), token2);
|
|
398
|
+
expect(result).toHaveLength(2);
|
|
399
|
+
expect(result[0].swaps[0].route.pools).toHaveLength(1); // 0 -> 2 at 10:11
|
|
400
|
+
expect(result[0].swaps[0].route.path).toEqual([token0, token2]);
|
|
401
|
+
expect(result[0].inputAmount.equalTo(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)))).toBeTruthy();
|
|
402
|
+
expect(result[0].outputAmount.equalTo(CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(9971)))).toBeTruthy();
|
|
403
|
+
expect(result[1].swaps[0].route.pools).toHaveLength(2); // 0 -> 1 -> 2 at 12:12:10
|
|
404
|
+
expect(result[1].swaps[0].route.path).toEqual([token0, token1, token2]);
|
|
405
|
+
expect(result[1].inputAmount.equalTo(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)))).toBeTruthy();
|
|
406
|
+
expect(result[1].outputAmount.equalTo(CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(7004)))).toBeTruthy();
|
|
407
|
+
}));
|
|
408
|
+
it('respects maxHops', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
409
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_0_1, pool_v3_0_2, pool_v3_1_2], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10)), token2, { maxHops: 1 });
|
|
410
|
+
expect(result).toHaveLength(1);
|
|
411
|
+
expect(result[0].swaps[0].route.pools).toHaveLength(1); // 0 -> 2 at 10:11
|
|
412
|
+
expect(result[0].swaps[0].route.path).toEqual([token0, token2]);
|
|
413
|
+
}));
|
|
414
|
+
it('insufficient input for one pool', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
415
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_0_1, pool_v3_0_2, pool_v3_1_2], CurrencyAmount.fromRawAmount(token0, 1), token2);
|
|
416
|
+
expect(result).toHaveLength(2);
|
|
417
|
+
expect(result[0].swaps[0].route.pools).toHaveLength(1); // 0 -> 2 at 10:11
|
|
418
|
+
expect(result[0].swaps[0].route.path).toEqual([token0, token2]);
|
|
419
|
+
expect(result[0].outputAmount).toEqual(CurrencyAmount.fromRawAmount(token2, 0));
|
|
420
|
+
}));
|
|
421
|
+
it('respects n', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
422
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_0_1, pool_v3_0_2, pool_v3_1_2], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10)), token2, { maxNumResults: 1 });
|
|
423
|
+
expect(result).toHaveLength(1);
|
|
424
|
+
}));
|
|
425
|
+
it('no path', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
426
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_0_1, pool_v3_0_3, pool_v3_1_3], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10)), token2);
|
|
427
|
+
expect(result).toHaveLength(0);
|
|
428
|
+
}));
|
|
429
|
+
it('works for ETHER currency input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
430
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_weth_0, pool_v3_0_1, pool_v3_0_3, pool_v3_1_3], CurrencyAmount.fromRawAmount(Ether.onChain(1), JSBI.BigInt(100)), token3);
|
|
431
|
+
expect(result).toHaveLength(2);
|
|
432
|
+
expect(result[0].inputAmount.currency).toEqual(ETHER);
|
|
433
|
+
expect(result[0].swaps[0].route.path).toEqual([WETH9[1], token0, token1, token3]);
|
|
434
|
+
expect(result[0].outputAmount.currency).toEqual(token3);
|
|
435
|
+
expect(result[1].inputAmount.currency).toEqual(ETHER);
|
|
436
|
+
expect(result[1].swaps[0].route.path).toEqual([WETH9[1], token0, token3]);
|
|
437
|
+
expect(result[1].outputAmount.currency).toEqual(token3);
|
|
438
|
+
}));
|
|
439
|
+
it('works for ETHER currency output', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
440
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_weth_0, pool_v3_0_1, pool_v3_0_3, pool_v3_1_3], CurrencyAmount.fromRawAmount(token3, JSBI.BigInt(100)), ETHER);
|
|
441
|
+
expect(result).toHaveLength(2);
|
|
442
|
+
expect(result[0].inputAmount.currency).toEqual(token3);
|
|
443
|
+
expect(result[0].swaps[0].route.path).toEqual([token3, token0, WETH9[1]]);
|
|
444
|
+
expect(result[0].outputAmount.currency).toEqual(ETHER);
|
|
445
|
+
expect(result[1].inputAmount.currency).toEqual(token3);
|
|
446
|
+
expect(result[1].swaps[0].route.path).toEqual([token3, token1, token0, WETH9[1]]);
|
|
447
|
+
expect(result[1].outputAmount.currency).toEqual(ETHER);
|
|
448
|
+
}));
|
|
449
|
+
});
|
|
450
|
+
describe('#maximumAmountIn', () => {
|
|
451
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
452
|
+
let exactIn;
|
|
453
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
454
|
+
exactIn = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v3_0_1, pool_v3_1_2], token0, token2), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
455
|
+
}));
|
|
456
|
+
it('throws if less than 0', () => {
|
|
457
|
+
expect(() => exactIn.maximumAmountIn(new Percent(JSBI.BigInt(-1), JSBI.BigInt(100)))).toThrow('SLIPPAGE_TOLERANCE');
|
|
458
|
+
});
|
|
459
|
+
it('returns exact if 0', () => {
|
|
460
|
+
expect(exactIn.maximumAmountIn(new Percent(JSBI.BigInt(0), JSBI.BigInt(100)))).toEqual(exactIn.inputAmount);
|
|
461
|
+
});
|
|
462
|
+
it('returns exact if nonzero', () => {
|
|
463
|
+
expect(exactIn
|
|
464
|
+
.maximumAmountIn(new Percent(JSBI.BigInt(0), JSBI.BigInt(100)))
|
|
465
|
+
.equalTo(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)))).toBeTruthy();
|
|
466
|
+
expect(exactIn
|
|
467
|
+
.maximumAmountIn(new Percent(JSBI.BigInt(5), JSBI.BigInt(100)))
|
|
468
|
+
.equalTo(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)))).toBeTruthy();
|
|
469
|
+
expect(exactIn
|
|
470
|
+
.maximumAmountIn(new Percent(JSBI.BigInt(200), JSBI.BigInt(100)))
|
|
471
|
+
.equalTo(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)))).toBeTruthy();
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
describe('#minimumAmountOut', () => {
|
|
476
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
477
|
+
let exactIn;
|
|
478
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
479
|
+
return (exactIn = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v3_0_1, pool_v3_1_2], token0, token2), CurrencyAmount.fromRawAmount(token0, 10000), TradeType.EXACT_INPUT));
|
|
480
|
+
}));
|
|
481
|
+
it('throws if less than 0', () => {
|
|
482
|
+
expect(() => exactIn.minimumAmountOut(new Percent(JSBI.BigInt(-1), 100))).toThrow('SLIPPAGE_TOLERANCE');
|
|
483
|
+
});
|
|
484
|
+
it('returns exact if 0', () => {
|
|
485
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(0), 10000))).toEqual(exactIn.outputAmount);
|
|
486
|
+
});
|
|
487
|
+
it('returns exact if nonzero', () => {
|
|
488
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(0), 100))).toEqual(CurrencyAmount.fromRawAmount(token2, 7004));
|
|
489
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(5), 100))).toEqual(CurrencyAmount.fromRawAmount(token2, 6670));
|
|
490
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(200), 100))).toEqual(CurrencyAmount.fromRawAmount(token2, 2334));
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
/// @dev copied over from v2-sdk trade.test.ts
|
|
496
|
+
describe('is backwards compatible with pure v2 routes', () => {
|
|
497
|
+
it('can be constructed with ETHER as input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
498
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_weth_0], ETHER, token0), CurrencyAmount.fromRawAmount(Ether.onChain(1), JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
499
|
+
expect(trade.inputAmount.currency).toEqual(ETHER);
|
|
500
|
+
expect(trade.outputAmount.currency).toEqual(token0);
|
|
501
|
+
}));
|
|
502
|
+
it('can be constructed with ETHER as output for exact input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
503
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_weth_0], token0, ETHER), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
504
|
+
expect(trade.inputAmount.currency).toEqual(token0);
|
|
505
|
+
expect(trade.outputAmount.currency).toEqual(ETHER);
|
|
506
|
+
}));
|
|
507
|
+
describe('#bestTradeExactIn', () => {
|
|
508
|
+
it('throws with empty pairs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
509
|
+
yield expect(MixedRouteTrade.bestTradeExactIn([], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), token2)).rejects.toThrow('POOLS');
|
|
510
|
+
}));
|
|
511
|
+
it('throws with max hops of 0', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
512
|
+
yield expect(MixedRouteTrade.bestTradeExactIn([pair_0_2], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), token2, {
|
|
513
|
+
maxHops: 0,
|
|
514
|
+
})).rejects.toThrow('MAX_HOPS');
|
|
515
|
+
}));
|
|
516
|
+
it('provides best route', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
517
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pair_0_1, pair_0_2, pair_1_2], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), token2);
|
|
518
|
+
expect(result).toHaveLength(2);
|
|
519
|
+
expect(result[0].swaps[0].route.pools).toHaveLength(1); // 0 -> 2 at 10:11
|
|
520
|
+
expect(result[0].swaps[0].route.path).toEqual([token0, token2]);
|
|
521
|
+
expect(result[0].inputAmount).toEqual(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)));
|
|
522
|
+
expect(result[0].outputAmount).toEqual(CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(99)));
|
|
523
|
+
expect(result[1].swaps[0].route.pools).toHaveLength(2); // 0 -> 1 -> 2 at 12:12:10
|
|
524
|
+
expect(result[1].swaps[0].route.path).toEqual([token0, token1, token2]);
|
|
525
|
+
expect(result[1].inputAmount).toEqual(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)));
|
|
526
|
+
expect(result[1].outputAmount).toEqual(CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(69)));
|
|
527
|
+
}));
|
|
528
|
+
it('doesnt throw for zero liquidity pairs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
529
|
+
expect(yield MixedRouteTrade.bestTradeExactIn([empty_pair_0_1], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), token1)).toHaveLength(0);
|
|
530
|
+
}));
|
|
531
|
+
it('respects maxHops', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
532
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pair_0_1, pair_0_2, pair_1_2], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10)), token2, { maxHops: 1 });
|
|
533
|
+
expect(result).toHaveLength(1);
|
|
534
|
+
expect(result[0].swaps[0].route.pools).toHaveLength(1); // 0 -> 2 at 10:11
|
|
535
|
+
expect(result[0].swaps[0].route.path).toEqual([token0, token2]);
|
|
536
|
+
}));
|
|
537
|
+
it('insufficient input for one pair', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
538
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pair_0_1, pair_0_2, pair_1_2], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1)), token2);
|
|
539
|
+
expect(result).toHaveLength(1);
|
|
540
|
+
expect(result[0].swaps[0].route.pools).toHaveLength(1); // 0 -> 2 at 10:11
|
|
541
|
+
expect(result[0].swaps[0].route.path).toEqual([token0, token2]);
|
|
542
|
+
expect(result[0].outputAmount).toEqual(CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(1)));
|
|
543
|
+
}));
|
|
544
|
+
it('respects n', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
545
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pair_0_1, pair_0_2, pair_1_2], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10)), token2, { maxNumResults: 1 });
|
|
546
|
+
expect(result).toHaveLength(1);
|
|
547
|
+
}));
|
|
548
|
+
it('no path', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
549
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pair_0_1, pair_0_3, pair_1_3], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10)), token2);
|
|
550
|
+
expect(result).toHaveLength(0);
|
|
551
|
+
}));
|
|
552
|
+
it('works for ETHER currency input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
553
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pair_weth_0, pair_0_1, pair_0_3, pair_1_3], CurrencyAmount.fromRawAmount(Ether.onChain(1), JSBI.BigInt(100)), token3);
|
|
554
|
+
expect(result).toHaveLength(2);
|
|
555
|
+
expect(result[0].inputAmount.currency).toEqual(ETHER);
|
|
556
|
+
expect(result[0].swaps[0].route.path).toEqual([WETH9[1], token0, token1, token3]);
|
|
557
|
+
expect(result[0].outputAmount.currency).toEqual(token3);
|
|
558
|
+
expect(result[1].inputAmount.currency).toEqual(ETHER);
|
|
559
|
+
expect(result[1].swaps[0].route.path).toEqual([WETH9[1], token0, token3]);
|
|
560
|
+
expect(result[1].outputAmount.currency).toEqual(token3);
|
|
561
|
+
}));
|
|
562
|
+
it('works for ETHER currency output', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
563
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pair_weth_0, pair_0_1, pair_0_3, pair_1_3], CurrencyAmount.fromRawAmount(token3, JSBI.BigInt(100)), ETHER);
|
|
564
|
+
expect(result).toHaveLength(2);
|
|
565
|
+
expect(result[0].inputAmount.currency).toEqual(token3);
|
|
566
|
+
expect(result[0].swaps[0].route.path).toEqual([token3, token0, WETH9[1]]);
|
|
567
|
+
expect(result[0].outputAmount.currency).toEqual(ETHER);
|
|
568
|
+
expect(result[1].inputAmount.currency).toEqual(token3);
|
|
569
|
+
expect(result[1].swaps[0].route.path).toEqual([token3, token1, token0, WETH9[1]]);
|
|
570
|
+
expect(result[1].outputAmount.currency).toEqual(ETHER);
|
|
571
|
+
}));
|
|
572
|
+
});
|
|
573
|
+
describe('#maximumAmountIn', () => {
|
|
574
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
575
|
+
let exactIn;
|
|
576
|
+
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
577
|
+
exactIn = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1, pair_1_2], token0, token2), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
578
|
+
}));
|
|
579
|
+
it('throws if less than 0', () => {
|
|
580
|
+
expect(() => exactIn.maximumAmountIn(new Percent(JSBI.BigInt(-1), JSBI.BigInt(100)))).toThrow('SLIPPAGE_TOLERANCE');
|
|
581
|
+
});
|
|
582
|
+
it('returns exact if 0', () => {
|
|
583
|
+
expect(exactIn.maximumAmountIn(new Percent(JSBI.BigInt(0), JSBI.BigInt(100)))).toEqual(exactIn.inputAmount);
|
|
584
|
+
});
|
|
585
|
+
it('returns exact if nonzero', () => {
|
|
586
|
+
expect(exactIn.maximumAmountIn(new Percent(JSBI.BigInt(0), JSBI.BigInt(100)))).toEqual(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)));
|
|
587
|
+
expect(exactIn.maximumAmountIn(new Percent(JSBI.BigInt(5), JSBI.BigInt(100)))).toEqual(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)));
|
|
588
|
+
expect(exactIn.maximumAmountIn(new Percent(JSBI.BigInt(200), JSBI.BigInt(100)))).toEqual(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)));
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
describe('#minimumAmountOut', () => {
|
|
593
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
594
|
+
let exactIn;
|
|
595
|
+
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
596
|
+
exactIn = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1, pair_1_2], token0, token2), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
597
|
+
}));
|
|
598
|
+
it('throws if less than 0', () => {
|
|
599
|
+
expect(() => exactIn.minimumAmountOut(new Percent(JSBI.BigInt(-1), JSBI.BigInt(100)))).toThrow('SLIPPAGE_TOLERANCE');
|
|
600
|
+
});
|
|
601
|
+
it('returns exact if 0', () => {
|
|
602
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(0), JSBI.BigInt(100)))).toEqual(exactIn.outputAmount);
|
|
603
|
+
});
|
|
604
|
+
it('returns exact if nonzero', () => {
|
|
605
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(0), JSBI.BigInt(100)))).toEqual(CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(69)));
|
|
606
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(5), JSBI.BigInt(100)))).toEqual(CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(65)));
|
|
607
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(200), JSBI.BigInt(100)))).toEqual(CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(23)));
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
describe('#worstExecutionPrice', () => {
|
|
612
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
613
|
+
let exactIn;
|
|
614
|
+
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
615
|
+
exactIn = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1, pair_1_2], token0, token2), CurrencyAmount.fromRawAmount(token0, 100), TradeType.EXACT_INPUT);
|
|
616
|
+
}));
|
|
617
|
+
it('throws if less than 0', () => {
|
|
618
|
+
expect(() => exactIn.minimumAmountOut(new Percent(-1, 100))).toThrow('SLIPPAGE_TOLERANCE');
|
|
619
|
+
});
|
|
620
|
+
it('returns exact if 0', () => {
|
|
621
|
+
expect(exactIn.worstExecutionPrice(new Percent(0, 100))).toEqual(exactIn.executionPrice);
|
|
622
|
+
});
|
|
623
|
+
it('returns exact if nonzero', () => {
|
|
624
|
+
expect(exactIn.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 100, 69));
|
|
625
|
+
expect(exactIn.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 100, 65));
|
|
626
|
+
expect(exactIn.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 100, 23));
|
|
627
|
+
});
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
describe('multihop v2 + v3', () => {
|
|
632
|
+
describe('#fromRoute', () => {
|
|
633
|
+
it('can be constructed with ETHER as input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
634
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v3_weth_0, pair_0_1], ETHER, token1), CurrencyAmount.fromRawAmount(Ether.onChain(1), JSBI.BigInt(10000)), TradeType.EXACT_INPUT);
|
|
635
|
+
expect(trade.inputAmount.currency).toEqual(ETHER);
|
|
636
|
+
expect(trade.outputAmount.currency).toEqual(token1);
|
|
637
|
+
}));
|
|
638
|
+
it('can be constructed with ETHER as output for exact input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
639
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1, pool_v3_weth_0], token1, ETHER), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(10000)), TradeType.EXACT_INPUT);
|
|
640
|
+
expect(trade.inputAmount.currency).toEqual(token1);
|
|
641
|
+
expect(trade.outputAmount.currency).toEqual(ETHER);
|
|
642
|
+
}));
|
|
643
|
+
it('allows using input tokens as intermediary', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
644
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1, pool_v3_0_1, pair_0_2], token0, token2), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
645
|
+
expect(trade.inputAmount.currency).toEqual(token0);
|
|
646
|
+
expect(trade.outputAmount.currency).toEqual(token2);
|
|
647
|
+
}));
|
|
648
|
+
});
|
|
649
|
+
describe('#fromRoutes', () => {
|
|
650
|
+
it('can be constructed with ETHER as input with multiple routes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
651
|
+
const trade = yield MixedRouteTrade.fromRoutes([
|
|
652
|
+
{
|
|
653
|
+
amount: CurrencyAmount.fromRawAmount(Ether.onChain(1), JSBI.BigInt(10000)),
|
|
654
|
+
route: new MixedRouteSDK([pool_v3_weth_0, pair_0_1], ETHER, token1),
|
|
655
|
+
},
|
|
656
|
+
], TradeType.EXACT_INPUT);
|
|
657
|
+
expect(trade.inputAmount.currency).toEqual(ETHER);
|
|
658
|
+
expect(trade.outputAmount.currency).toEqual(token1);
|
|
659
|
+
}));
|
|
660
|
+
it('can be constructed with ETHER as output for exact input with multiple routes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
661
|
+
const trade = yield MixedRouteTrade.fromRoutes([
|
|
662
|
+
{
|
|
663
|
+
amount: CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(3000)),
|
|
664
|
+
route: new MixedRouteSDK([pair_0_1, pool_v3_weth_0], token1, ETHER),
|
|
665
|
+
},
|
|
666
|
+
{
|
|
667
|
+
amount: CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(7000)),
|
|
668
|
+
route: new MixedRouteSDK([pair_1_2, pool_v3_weth_2], token1, ETHER),
|
|
669
|
+
},
|
|
670
|
+
], TradeType.EXACT_INPUT);
|
|
671
|
+
expect(trade.inputAmount.currency).toEqual(token1);
|
|
672
|
+
expect(trade.outputAmount.currency).toEqual(ETHER);
|
|
673
|
+
}));
|
|
674
|
+
/// no test for pool duplication because both v3 and v2 tests above cover it
|
|
675
|
+
});
|
|
676
|
+
describe('#createUncheckedTrade', () => {
|
|
677
|
+
it('throws if input currency does not match route', () => {
|
|
678
|
+
expect(() => MixedRouteTrade.createUncheckedTrade({
|
|
679
|
+
route: new MixedRouteSDK([pool_v3_0_1, pair_1_2], token0, token2),
|
|
680
|
+
inputAmount: CurrencyAmount.fromRawAmount(token2, 10000),
|
|
681
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 10000),
|
|
682
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
683
|
+
})).toThrow('INPUT_CURRENCY_MATCH');
|
|
684
|
+
});
|
|
685
|
+
it('throws if output currency does not match route', () => {
|
|
686
|
+
expect(() => MixedRouteTrade.createUncheckedTrade({
|
|
687
|
+
route: new MixedRouteSDK([pool_v3_0_1, pair_1_2], token0, token2),
|
|
688
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 10000),
|
|
689
|
+
outputAmount: CurrencyAmount.fromRawAmount(token3, 10000),
|
|
690
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
691
|
+
})).toThrow('OUTPUT_CURRENCY_MATCH');
|
|
692
|
+
});
|
|
693
|
+
it('can create an exact input trade without simulating', () => {
|
|
694
|
+
MixedRouteTrade.createUncheckedTrade({
|
|
695
|
+
route: new MixedRouteSDK([pool_v3_0_1, pair_1_2], token0, token2),
|
|
696
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 10000),
|
|
697
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 100000),
|
|
698
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
699
|
+
});
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
describe('#createUncheckedTradeWithMultipleRoutes', () => {
|
|
703
|
+
it('throws if input currency does not match route with multiple routes', () => {
|
|
704
|
+
expect(() => MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
705
|
+
routes: [
|
|
706
|
+
{
|
|
707
|
+
route: new MixedRouteSDK([pool_v3_1_2], token2, token1),
|
|
708
|
+
inputAmount: CurrencyAmount.fromRawAmount(token2, 2000),
|
|
709
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 2000),
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
route: new MixedRouteSDK([pair_0_1], token0, token1),
|
|
713
|
+
inputAmount: CurrencyAmount.fromRawAmount(token2, 8000),
|
|
714
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 8000),
|
|
715
|
+
},
|
|
716
|
+
],
|
|
717
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
718
|
+
})).toThrow('INPUT_CURRENCY_MATCH');
|
|
719
|
+
});
|
|
720
|
+
it('throws if output currency does not match route with multiple routes', () => {
|
|
721
|
+
expect(() => MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
722
|
+
routes: [
|
|
723
|
+
{
|
|
724
|
+
route: new MixedRouteSDK([pool_v3_0_2], token0, token2),
|
|
725
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 10000),
|
|
726
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 10000),
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
route: new MixedRouteSDK([pair_0_1], token0, token1),
|
|
730
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 10000),
|
|
731
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 10000),
|
|
732
|
+
},
|
|
733
|
+
],
|
|
734
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
735
|
+
})).toThrow('OUTPUT_CURRENCY_MATCH');
|
|
736
|
+
});
|
|
737
|
+
it('can create an exact input trade without simulating with multiple routes', () => {
|
|
738
|
+
MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
739
|
+
routes: [
|
|
740
|
+
{
|
|
741
|
+
route: new MixedRouteSDK([pool_v3_0_1], token0, token1),
|
|
742
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 5000),
|
|
743
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 50000),
|
|
744
|
+
},
|
|
745
|
+
{
|
|
746
|
+
route: new MixedRouteSDK([pool_v3_0_2, pair_1_2], token0, token1),
|
|
747
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 5000),
|
|
748
|
+
outputAmount: CurrencyAmount.fromRawAmount(token1, 50000),
|
|
749
|
+
},
|
|
750
|
+
],
|
|
751
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
});
|
|
755
|
+
describe('#route and #swaps', () => {
|
|
756
|
+
const singleRoute = MixedRouteTrade.createUncheckedTrade({
|
|
757
|
+
route: new MixedRouteSDK([pool_v3_0_1, pair_1_2], token0, token2),
|
|
758
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
|
|
759
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 69),
|
|
760
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
761
|
+
});
|
|
762
|
+
const multiRoute = MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
763
|
+
routes: [
|
|
764
|
+
{
|
|
765
|
+
route: new MixedRouteSDK([pool_v3_0_1, pair_1_2], token0, token2),
|
|
766
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
|
|
767
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 35),
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
route: new MixedRouteSDK([pool_v3_0_2], token0, token2),
|
|
771
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
|
|
772
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 34),
|
|
773
|
+
},
|
|
774
|
+
],
|
|
775
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
776
|
+
});
|
|
777
|
+
it('can access route for single route trade if less than 0', () => {
|
|
778
|
+
expect(singleRoute.route).toBeDefined();
|
|
779
|
+
});
|
|
780
|
+
it('can access routes for both single and multi route trades', () => {
|
|
781
|
+
expect(singleRoute.swaps).toBeDefined();
|
|
782
|
+
expect(singleRoute.swaps).toHaveLength(1);
|
|
783
|
+
expect(multiRoute.swaps).toBeDefined();
|
|
784
|
+
expect(multiRoute.swaps).toHaveLength(2);
|
|
785
|
+
});
|
|
786
|
+
it('throws if access route on multi route trade', () => {
|
|
787
|
+
expect(() => multiRoute.route).toThrow('MULTIPLE_ROUTES');
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
describe('#worstExecutionPrice', () => {
|
|
791
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
792
|
+
const exactIn = MixedRouteTrade.createUncheckedTrade({
|
|
793
|
+
route: new MixedRouteSDK([pair_0_1, pool_v3_1_2], token0, token2),
|
|
794
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
|
|
795
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 69),
|
|
796
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
797
|
+
});
|
|
798
|
+
const exactInMultiRoute = MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
799
|
+
routes: [
|
|
800
|
+
{
|
|
801
|
+
route: new MixedRouteSDK([pair_0_1, pool_v3_1_2], token0, token2),
|
|
802
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
|
|
803
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 35),
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
route: new MixedRouteSDK([pool_v3_0_2], token0, token2),
|
|
807
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
|
|
808
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 34),
|
|
809
|
+
},
|
|
810
|
+
],
|
|
811
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
812
|
+
});
|
|
813
|
+
it('throws if less than 0', () => {
|
|
814
|
+
expect(() => exactIn.minimumAmountOut(new Percent(-1, 100))).toThrow('SLIPPAGE_TOLERANCE');
|
|
815
|
+
});
|
|
816
|
+
it('returns exact if 0', () => {
|
|
817
|
+
expect(exactIn.worstExecutionPrice(new Percent(0, 100))).toEqual(exactIn.executionPrice);
|
|
818
|
+
});
|
|
819
|
+
it('returns exact if nonzero', () => {
|
|
820
|
+
expect(exactIn.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 100, 69));
|
|
821
|
+
expect(exactIn.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 100, 65));
|
|
822
|
+
expect(exactIn.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 100, 23));
|
|
823
|
+
});
|
|
824
|
+
it('returns exact if nonzero with multiple routes', () => {
|
|
825
|
+
expect(exactInMultiRoute.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 100, 69));
|
|
826
|
+
expect(exactInMultiRoute.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 100, 65));
|
|
827
|
+
expect(exactInMultiRoute.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 100, 23));
|
|
828
|
+
});
|
|
829
|
+
});
|
|
830
|
+
});
|
|
831
|
+
describe('#priceImpact', () => {
|
|
832
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
833
|
+
const exactIn = MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
834
|
+
routes: [
|
|
835
|
+
{
|
|
836
|
+
route: new MixedRouteSDK([pair_0_1, pool_v3_1_2], token0, token2),
|
|
837
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
|
|
838
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 69),
|
|
839
|
+
},
|
|
840
|
+
],
|
|
841
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
842
|
+
});
|
|
843
|
+
const exactInMultipleRoutes = MixedRouteTrade.createUncheckedTradeWithMultipleRoutes({
|
|
844
|
+
routes: [
|
|
845
|
+
{
|
|
846
|
+
route: new MixedRouteSDK([pair_0_1, pool_v3_1_2], token0, token2),
|
|
847
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 90),
|
|
848
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 62),
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
route: new MixedRouteSDK([pool_v3_0_2], token0, token2),
|
|
852
|
+
inputAmount: CurrencyAmount.fromRawAmount(token0, 10),
|
|
853
|
+
outputAmount: CurrencyAmount.fromRawAmount(token2, 7),
|
|
854
|
+
},
|
|
855
|
+
],
|
|
856
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
857
|
+
});
|
|
858
|
+
it('is correct', () => {
|
|
859
|
+
expect(exactIn.priceImpact.toSignificant(3)).toEqual('17.2');
|
|
860
|
+
});
|
|
861
|
+
it('is correct with multiple routes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
862
|
+
expect(exactInMultipleRoutes.priceImpact.toSignificant(3)).toEqual('19.8');
|
|
863
|
+
}));
|
|
864
|
+
});
|
|
865
|
+
});
|
|
866
|
+
describe('#bestTradeExactIn', () => {
|
|
867
|
+
/// no empty check because covered by v3 backward compatibility test
|
|
868
|
+
it('throws with max hops of 0', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
869
|
+
yield expect(MixedRouteTrade.bestTradeExactIn([pool_v3_0_2, pair_1_2], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)), token1, {
|
|
870
|
+
maxHops: 0,
|
|
871
|
+
})).rejects.toThrow('MAX_HOPS');
|
|
872
|
+
}));
|
|
873
|
+
it('provides best route', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
874
|
+
const large_pair_0_1 = new Pair(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100000)), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100000)));
|
|
875
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([large_pair_0_1, pool_v3_0_2, pool_v3_1_2], CurrencyAmount.fromRawAmount(token0, 10000), token2);
|
|
876
|
+
expect(result).toHaveLength(2);
|
|
877
|
+
expect(result[0].swaps[0].route.pools).toHaveLength(1); // 0 -> 2 at 10:11
|
|
878
|
+
expect(result[0].swaps[0].route.path).toEqual([token0, token2]);
|
|
879
|
+
expect(result[0].inputAmount.equalTo(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)))).toBeTruthy();
|
|
880
|
+
expect(result[0].outputAmount.equalTo(CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(9971)))).toBeTruthy();
|
|
881
|
+
expect(result[1].swaps[0].route.pools).toHaveLength(2); // 0 -> 1 -> 2 at 12:12:10
|
|
882
|
+
expect(result[1].swaps[0].route.path).toEqual([token0, token1, token2]);
|
|
883
|
+
expect(result[1].inputAmount.equalTo(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)))).toBeTruthy();
|
|
884
|
+
expect(result[1].outputAmount.equalTo(CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(7004)))).toBeTruthy();
|
|
885
|
+
}));
|
|
886
|
+
it('respects maxHops', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
887
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_0_1, pool_v3_0_2, pair_1_2], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10)), token2, { maxHops: 1 });
|
|
888
|
+
expect(result).toHaveLength(1);
|
|
889
|
+
expect(result[0].swaps[0].route.pools).toHaveLength(1); // 0 -> 2 at 10:11
|
|
890
|
+
expect(result[0].swaps[0].route.path).toEqual([token0, token2]);
|
|
891
|
+
}));
|
|
892
|
+
it('insufficient input for one pool', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
893
|
+
/// pairs are just skipped
|
|
894
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pair_0_1, pool_v3_0_2, pair_1_2], CurrencyAmount.fromRawAmount(token0, 1), token2);
|
|
895
|
+
expect(result).toHaveLength(1);
|
|
896
|
+
expect(result[0].swaps[0].route.pools).toHaveLength(1);
|
|
897
|
+
expect(result[0].swaps[0].route.path).toEqual([token0, token2]);
|
|
898
|
+
expect(result[0].outputAmount).toEqual(CurrencyAmount.fromRawAmount(token2, 0));
|
|
899
|
+
}));
|
|
900
|
+
it('respects n', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
901
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_0_1, pair_0_2, pool_v3_1_2], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10)), token2, { maxNumResults: 1 });
|
|
902
|
+
expect(result).toHaveLength(1);
|
|
903
|
+
}));
|
|
904
|
+
it('no path between v2 and v3', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
905
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_0_1, pair_0_3, pool_v3_1_3], CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10)), token2);
|
|
906
|
+
expect(result).toHaveLength(0);
|
|
907
|
+
}));
|
|
908
|
+
it('works for ETHER currency input', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
909
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_weth_0, pair_0_1, pool_v3_0_3, pair_1_3], CurrencyAmount.fromRawAmount(Ether.onChain(1), JSBI.BigInt(100)), token3);
|
|
910
|
+
expect(result).toHaveLength(2);
|
|
911
|
+
expect(result[0].inputAmount.currency).toEqual(ETHER);
|
|
912
|
+
expect(result[0].swaps[0].route.path).toEqual([WETH9[1], token0, token1, token3]);
|
|
913
|
+
expect(result[0].outputAmount.currency).toEqual(token3);
|
|
914
|
+
expect(result[1].inputAmount.currency).toEqual(ETHER);
|
|
915
|
+
expect(result[1].swaps[0].route.path).toEqual([WETH9[1], token0, token3]);
|
|
916
|
+
expect(result[1].outputAmount.currency).toEqual(token3);
|
|
917
|
+
}));
|
|
918
|
+
it('works for ETHER currency output', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
919
|
+
const result = yield MixedRouteTrade.bestTradeExactIn([pool_v3_weth_0, pool_v3_0_1, pair_0_3, pair_1_3], CurrencyAmount.fromRawAmount(token3, JSBI.BigInt(100)), ETHER);
|
|
920
|
+
expect(result).toHaveLength(2);
|
|
921
|
+
expect(result[0].inputAmount.currency).toEqual(token3);
|
|
922
|
+
expect(result[0].swaps[0].route.path).toEqual([token3, token0, WETH9[1]]);
|
|
923
|
+
expect(result[0].outputAmount.currency).toEqual(ETHER);
|
|
924
|
+
expect(result[1].inputAmount.currency).toEqual(token3);
|
|
925
|
+
expect(result[1].swaps[0].route.path).toEqual([token3, token1, token0, WETH9[1]]);
|
|
926
|
+
expect(result[1].outputAmount.currency).toEqual(ETHER);
|
|
927
|
+
}));
|
|
928
|
+
});
|
|
929
|
+
describe('#maximumAmountIn', () => {
|
|
930
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
931
|
+
let exactIn;
|
|
932
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
933
|
+
exactIn = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v3_0_1, pair_1_2], token0, token2), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
934
|
+
}));
|
|
935
|
+
it('throws if less than 0', () => {
|
|
936
|
+
expect(() => exactIn.maximumAmountIn(new Percent(JSBI.BigInt(-1), JSBI.BigInt(100)))).toThrow('SLIPPAGE_TOLERANCE');
|
|
937
|
+
});
|
|
938
|
+
it('returns exact if 0', () => {
|
|
939
|
+
expect(exactIn.maximumAmountIn(new Percent(JSBI.BigInt(0), JSBI.BigInt(100)))).toEqual(exactIn.inputAmount);
|
|
940
|
+
});
|
|
941
|
+
it('returns exact if nonzero', () => {
|
|
942
|
+
expect(exactIn
|
|
943
|
+
.maximumAmountIn(new Percent(JSBI.BigInt(0), JSBI.BigInt(100)))
|
|
944
|
+
.equalTo(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)))).toBeTruthy();
|
|
945
|
+
expect(exactIn
|
|
946
|
+
.maximumAmountIn(new Percent(JSBI.BigInt(5), JSBI.BigInt(100)))
|
|
947
|
+
.equalTo(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)))).toBeTruthy();
|
|
948
|
+
expect(exactIn
|
|
949
|
+
.maximumAmountIn(new Percent(JSBI.BigInt(200), JSBI.BigInt(100)))
|
|
950
|
+
.equalTo(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)))).toBeTruthy();
|
|
951
|
+
});
|
|
952
|
+
});
|
|
953
|
+
});
|
|
954
|
+
describe('#minimumAmountOut', () => {
|
|
955
|
+
describe('tradeType = EXACT_INPUT', () => {
|
|
956
|
+
let exactIn;
|
|
957
|
+
const large_pair_0_1 = new Pair(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100000)), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100000)));
|
|
958
|
+
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
959
|
+
return (exactIn = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([large_pair_0_1, pool_v3_1_2], token0, token2), CurrencyAmount.fromRawAmount(token0, 10000), TradeType.EXACT_INPUT));
|
|
960
|
+
}));
|
|
961
|
+
it('throws if less than 0', () => {
|
|
962
|
+
expect(() => exactIn.minimumAmountOut(new Percent(JSBI.BigInt(-1), 100))).toThrow('SLIPPAGE_TOLERANCE');
|
|
963
|
+
});
|
|
964
|
+
it('returns exact if 0', () => {
|
|
965
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(0), 10000))).toEqual(exactIn.outputAmount);
|
|
966
|
+
});
|
|
967
|
+
it('returns exact if nonzero', () => {
|
|
968
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(0), 100))).toEqual(CurrencyAmount.fromRawAmount(token2, 7004));
|
|
969
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(5), 100))).toEqual(CurrencyAmount.fromRawAmount(token2, 6670));
|
|
970
|
+
expect(exactIn.minimumAmountOut(new Percent(JSBI.BigInt(200), 100))).toEqual(CurrencyAmount.fromRawAmount(token2, 2334));
|
|
971
|
+
});
|
|
972
|
+
});
|
|
973
|
+
});
|
|
974
|
+
});
|
|
975
|
+
describe('multihop v2 + v3 + v4', () => {
|
|
976
|
+
it('can be constructed with a weth output from a v4 pool', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
977
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v3_0_1, pool_v4_0_weth], token1, WETH9[1]), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
978
|
+
expect(trade.inputAmount.currency).toEqual(token1);
|
|
979
|
+
expect(trade.outputAmount.currency).toEqual(WETH9[1]);
|
|
980
|
+
}));
|
|
981
|
+
it('can be constructed with an eth output from a v4 pool', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
982
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v3_0_1, pool_v4_0_eth], token1, ETHER), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
983
|
+
expect(trade.inputAmount.currency).toEqual(token1);
|
|
984
|
+
expect(trade.outputAmount.currency).toEqual(ETHER);
|
|
985
|
+
}));
|
|
986
|
+
it('can be constructed with an eth output from a v4 weth pool', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
987
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v3_0_1, pool_v4_0_weth], token1, ETHER), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
988
|
+
expect(trade.inputAmount.currency).toEqual(token1);
|
|
989
|
+
expect(trade.outputAmount.currency).toEqual(ETHER);
|
|
990
|
+
}));
|
|
991
|
+
it('can be constructed with an intermediate conversion WETH->ETH when trading to v4 pool', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
992
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v3_weth_0, pool_v4_0_eth], token0, ETHER), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
993
|
+
expect(trade.inputAmount.currency).toEqual(token0);
|
|
994
|
+
expect(trade.outputAmount.currency).toEqual(ETHER);
|
|
995
|
+
}));
|
|
996
|
+
it('can be constructed with an intermediate conversion ETH->WETH when trading from a v4 pool', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
997
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v4_0_eth, pool_v3_weth_0], token0, WETH9[1]), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
998
|
+
expect(trade.inputAmount.currency).toEqual(token0);
|
|
999
|
+
expect(trade.outputAmount.currency).toEqual(WETH9[1]);
|
|
1000
|
+
}));
|
|
1001
|
+
it('can be constructed with an intermediate conversion ETH->WETH when trading from a v4 pool with ETH output', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1002
|
+
const trade = yield MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_v4_0_eth, pool_v3_weth_0], token0, ETHER), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100)), TradeType.EXACT_INPUT);
|
|
1003
|
+
expect(trade.inputAmount.currency).toEqual(token0);
|
|
1004
|
+
expect(trade.outputAmount.currency).toEqual(ETHER);
|
|
1005
|
+
}));
|
|
1006
|
+
});
|
|
1007
|
+
});
|
|
1008
|
+
//# sourceMappingURL=trade.test.js.map
|