@huuduynvc/v3-sdk 3.24.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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/constants.d.ts +23 -0
- package/dist/entities/index.d.ts +7 -0
- package/dist/entities/pool.d.ts +81 -0
- package/dist/entities/position.d.ts +131 -0
- package/dist/entities/route.d.ts +26 -0
- package/dist/entities/tick.d.ts +13 -0
- package/dist/entities/tickDataProvider.d.ts +31 -0
- package/dist/entities/tickListDataProvider.d.ts +15 -0
- package/dist/entities/trade.d.ts +220 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +8 -0
- package/dist/internalConstants.d.ts +6 -0
- package/dist/multicall.d.ts +10 -0
- package/dist/nonfungiblePositionManager.d.ts +159 -0
- package/dist/payments.d.ts +24 -0
- package/dist/quoter.d.ts +37 -0
- package/dist/selfPermit.d.ts +25 -0
- package/dist/staker.d.ts +101 -0
- package/dist/swapRouter.d.ts +51 -0
- package/dist/utils/calldata.d.ts +20 -0
- package/dist/utils/computePoolAddress.d.ts +20 -0
- package/dist/utils/encodeRouteToPath.d.ts +8 -0
- package/dist/utils/encodeSqrtRatioX96.d.ts +9 -0
- package/dist/utils/fullMath.d.ts +8 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/isSorted.d.ts +7 -0
- package/dist/utils/liquidityMath.d.ts +8 -0
- package/dist/utils/maxLiquidityForAmounts.d.ts +14 -0
- package/dist/utils/mostSignificantBit.d.ts +2 -0
- package/dist/utils/nearestUsableTick.d.ts +6 -0
- package/dist/utils/position.d.ts +8 -0
- package/dist/utils/priceTickConversions.d.ts +15 -0
- package/dist/utils/sqrtPriceMath.d.ts +13 -0
- package/dist/utils/swapMath.d.ts +9 -0
- package/dist/utils/tickLibrary.d.ts +14 -0
- package/dist/utils/tickList.d.ts +23 -0
- package/dist/utils/tickMath.d.ts +34 -0
- package/dist/utils/v3swap.d.ts +8 -0
- package/dist/v3-sdk.cjs.development.js +3265 -0
- package/dist/v3-sdk.cjs.development.js.map +1 -0
- package/dist/v3-sdk.cjs.production.min.js +2 -0
- package/dist/v3-sdk.cjs.production.min.js.map +1 -0
- package/dist/v3-sdk.esm.js +3224 -0
- package/dist/v3-sdk.esm.js.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Uniswap Labs
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
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 V3 SDK
|
9
|
+
|
10
|
+
[](https://www.npmjs.com/package/@uniswap/v3-sdk/v/latest)
|
11
|
+
[](https://bundlephobia.com/result?p=@uniswap/v3-sdk@latest)
|
12
|
+
|
13
|
+
In-depth documentation on this SDK is available at [uniswap.org](https://docs.uniswap.org/).
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { ChainId } from '@uniswap/sdk-core';
|
2
|
+
export declare const FACTORY_ADDRESS = "0x1F98431c8aD98523631AE4a59f267346ea31F984";
|
3
|
+
export declare const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000";
|
4
|
+
export declare const POOL_INIT_CODE_HASH = "0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54";
|
5
|
+
export declare function poolInitCodeHash(chainId?: ChainId): string;
|
6
|
+
/**
|
7
|
+
* The default factory enabled fee amounts, denominated in hundredths of bips.
|
8
|
+
*/
|
9
|
+
export declare enum FeeAmount {
|
10
|
+
LOWEST = 100,
|
11
|
+
LOW_200 = 200,
|
12
|
+
LOW_300 = 300,
|
13
|
+
LOW_400 = 400,
|
14
|
+
LOW = 500,
|
15
|
+
MEDIUM = 3000,
|
16
|
+
HIGH = 10000
|
17
|
+
}
|
18
|
+
/**
|
19
|
+
* The default factory tick spacings by fee amount.
|
20
|
+
*/
|
21
|
+
export declare const TICK_SPACINGS: {
|
22
|
+
[amount in FeeAmount]: number;
|
23
|
+
};
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import { BigintIsh, CurrencyAmount, Price, Token } from '@uniswap/sdk-core';
|
2
|
+
import JSBI from 'jsbi';
|
3
|
+
import { FeeAmount } from '../constants';
|
4
|
+
import { Tick, TickConstructorArgs } from './tick';
|
5
|
+
import { TickDataProvider } from './tickDataProvider';
|
6
|
+
/**
|
7
|
+
* Represents a V3 pool
|
8
|
+
*/
|
9
|
+
export declare class Pool {
|
10
|
+
readonly token0: Token;
|
11
|
+
readonly token1: Token;
|
12
|
+
readonly fee: FeeAmount;
|
13
|
+
readonly sqrtRatioX96: JSBI;
|
14
|
+
readonly liquidity: JSBI;
|
15
|
+
readonly tickCurrent: number;
|
16
|
+
readonly tickDataProvider: TickDataProvider;
|
17
|
+
private _token0Price?;
|
18
|
+
private _token1Price?;
|
19
|
+
static getAddress(tokenA: Token, tokenB: Token, fee: FeeAmount, initCodeHashManualOverride?: string, factoryAddressOverride?: string): string;
|
20
|
+
/**
|
21
|
+
* Construct a pool
|
22
|
+
* @param tokenA One of the tokens in the pool
|
23
|
+
* @param tokenB The other token in the pool
|
24
|
+
* @param fee The fee in hundredths of a bips of the input amount of every swap that is collected by the pool
|
25
|
+
* @param sqrtRatioX96 The sqrt of the current ratio of amounts of token1 to token0
|
26
|
+
* @param liquidity The current value of in range liquidity
|
27
|
+
* @param tickCurrent The current tick of the pool
|
28
|
+
* @param ticks The current state of the pool ticks or a data provider that can return tick data
|
29
|
+
*/
|
30
|
+
constructor(tokenA: Token, tokenB: Token, fee: FeeAmount, sqrtRatioX96: BigintIsh, liquidity: BigintIsh, tickCurrent: number, ticks?: TickDataProvider | (Tick | TickConstructorArgs)[]);
|
31
|
+
/**
|
32
|
+
* Returns true if the token is either token0 or token1
|
33
|
+
* @param token The token to check
|
34
|
+
* @returns True if token is either token0 or token
|
35
|
+
*/
|
36
|
+
involvesToken(token: Token): boolean;
|
37
|
+
/**
|
38
|
+
* Returns the current mid price of the pool in terms of token0, i.e. the ratio of token1 over token0
|
39
|
+
*/
|
40
|
+
get token0Price(): Price<Token, Token>;
|
41
|
+
/**
|
42
|
+
* Returns the current mid price of the pool in terms of token1, i.e. the ratio of token0 over token1
|
43
|
+
*/
|
44
|
+
get token1Price(): Price<Token, Token>;
|
45
|
+
/**
|
46
|
+
* Return the price of the given token in terms of the other token in the pool.
|
47
|
+
* @param token The token to return price of
|
48
|
+
* @returns The price of the given token, in terms of the other.
|
49
|
+
*/
|
50
|
+
priceOf(token: Token): Price<Token, Token>;
|
51
|
+
/**
|
52
|
+
* Returns the chain ID of the tokens in the pool.
|
53
|
+
*/
|
54
|
+
get chainId(): number;
|
55
|
+
/**
|
56
|
+
* Given an input amount of a token, return the computed output amount, and a pool with state updated after the trade
|
57
|
+
* @param inputAmount The input amount for which to quote the output amount
|
58
|
+
* @param sqrtPriceLimitX96 The Q64.96 sqrt price limit
|
59
|
+
* @returns The output amount and the pool with updated state
|
60
|
+
*/
|
61
|
+
getOutputAmount(inputAmount: CurrencyAmount<Token>, sqrtPriceLimitX96?: JSBI): Promise<[CurrencyAmount<Token>, Pool]>;
|
62
|
+
/**
|
63
|
+
* Given a desired output amount of a token, return the computed input amount and a pool with state updated after the trade
|
64
|
+
* @param outputAmount the output amount for which to quote the input amount
|
65
|
+
* @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
|
66
|
+
* @returns The input amount and the pool with updated state
|
67
|
+
*/
|
68
|
+
getInputAmount(outputAmount: CurrencyAmount<Token>, sqrtPriceLimitX96?: JSBI): Promise<[CurrencyAmount<Token>, Pool]>;
|
69
|
+
/**
|
70
|
+
* Executes a swap
|
71
|
+
* @param zeroForOne Whether the amount in is token0 or token1
|
72
|
+
* @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
|
73
|
+
* @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
|
74
|
+
* @returns amountCalculated
|
75
|
+
* @returns sqrtRatioX96
|
76
|
+
* @returns liquidity
|
77
|
+
* @returns tickCurrent
|
78
|
+
*/
|
79
|
+
private swap;
|
80
|
+
get tickSpacing(): number;
|
81
|
+
}
|
@@ -0,0 +1,131 @@
|
|
1
|
+
import { BigintIsh, Percent, Price, CurrencyAmount, Token } from '@uniswap/sdk-core';
|
2
|
+
import JSBI from 'jsbi';
|
3
|
+
import { Pool } from './pool';
|
4
|
+
interface PositionConstructorArgs {
|
5
|
+
pool: Pool;
|
6
|
+
tickLower: number;
|
7
|
+
tickUpper: number;
|
8
|
+
liquidity: BigintIsh;
|
9
|
+
}
|
10
|
+
/**
|
11
|
+
* Represents a position on a Uniswap V3 Pool
|
12
|
+
*/
|
13
|
+
export declare class Position {
|
14
|
+
readonly pool: Pool;
|
15
|
+
readonly tickLower: number;
|
16
|
+
readonly tickUpper: number;
|
17
|
+
readonly liquidity: JSBI;
|
18
|
+
private _token0Amount;
|
19
|
+
private _token1Amount;
|
20
|
+
private _mintAmounts;
|
21
|
+
/**
|
22
|
+
* Constructs a position for a given pool with the given liquidity
|
23
|
+
* @param pool For which pool the liquidity is assigned
|
24
|
+
* @param liquidity The amount of liquidity that is in the position
|
25
|
+
* @param tickLower The lower tick of the position
|
26
|
+
* @param tickUpper The upper tick of the position
|
27
|
+
*/
|
28
|
+
constructor({ pool, liquidity, tickLower, tickUpper }: PositionConstructorArgs);
|
29
|
+
/**
|
30
|
+
* Returns the price of token0 at the lower tick
|
31
|
+
*/
|
32
|
+
get token0PriceLower(): Price<Token, Token>;
|
33
|
+
/**
|
34
|
+
* Returns the price of token0 at the upper tick
|
35
|
+
*/
|
36
|
+
get token0PriceUpper(): Price<Token, Token>;
|
37
|
+
/**
|
38
|
+
* Returns the amount of token0 that this position's liquidity could be burned for at the current pool price
|
39
|
+
*/
|
40
|
+
get amount0(): CurrencyAmount<Token>;
|
41
|
+
/**
|
42
|
+
* Returns the amount of token1 that this position's liquidity could be burned for at the current pool price
|
43
|
+
*/
|
44
|
+
get amount1(): CurrencyAmount<Token>;
|
45
|
+
/**
|
46
|
+
* Returns the lower and upper sqrt ratios if the price 'slips' up to slippage tolerance percentage
|
47
|
+
* @param slippageTolerance The amount by which the price can 'slip' before the transaction will revert
|
48
|
+
* @returns The sqrt ratios after slippage
|
49
|
+
*/
|
50
|
+
private ratiosAfterSlippage;
|
51
|
+
/**
|
52
|
+
* Returns the minimum amounts that must be sent in order to safely mint the amount of liquidity held by the position
|
53
|
+
* with the given slippage tolerance
|
54
|
+
* @param slippageTolerance Tolerance of unfavorable slippage from the current price
|
55
|
+
* @returns The amounts, with slippage
|
56
|
+
*/
|
57
|
+
mintAmountsWithSlippage(slippageTolerance: Percent): Readonly<{
|
58
|
+
amount0: JSBI;
|
59
|
+
amount1: JSBI;
|
60
|
+
}>;
|
61
|
+
/**
|
62
|
+
* Returns the minimum amounts that should be requested in order to safely burn the amount of liquidity held by the
|
63
|
+
* position with the given slippage tolerance
|
64
|
+
* @param slippageTolerance tolerance of unfavorable slippage from the current price
|
65
|
+
* @returns The amounts, with slippage
|
66
|
+
*/
|
67
|
+
burnAmountsWithSlippage(slippageTolerance: Percent): Readonly<{
|
68
|
+
amount0: JSBI;
|
69
|
+
amount1: JSBI;
|
70
|
+
}>;
|
71
|
+
/**
|
72
|
+
* Returns the minimum amounts that must be sent in order to mint the amount of liquidity held by the position at
|
73
|
+
* the current price for the pool
|
74
|
+
*/
|
75
|
+
get mintAmounts(): Readonly<{
|
76
|
+
amount0: JSBI;
|
77
|
+
amount1: JSBI;
|
78
|
+
}>;
|
79
|
+
/**
|
80
|
+
* Computes the maximum amount of liquidity received for a given amount of token0, token1,
|
81
|
+
* and the prices at the tick boundaries.
|
82
|
+
* @param pool The pool for which the position should be created
|
83
|
+
* @param tickLower The lower tick of the position
|
84
|
+
* @param tickUpper The upper tick of the position
|
85
|
+
* @param amount0 token0 amount
|
86
|
+
* @param amount1 token1 amount
|
87
|
+
* @param useFullPrecision If false, liquidity will be maximized according to what the router can calculate,
|
88
|
+
* not what core can theoretically support
|
89
|
+
* @returns The amount of liquidity for the position
|
90
|
+
*/
|
91
|
+
static fromAmounts({ pool, tickLower, tickUpper, amount0, amount1, useFullPrecision, }: {
|
92
|
+
pool: Pool;
|
93
|
+
tickLower: number;
|
94
|
+
tickUpper: number;
|
95
|
+
amount0: BigintIsh;
|
96
|
+
amount1: BigintIsh;
|
97
|
+
useFullPrecision: boolean;
|
98
|
+
}): Position;
|
99
|
+
/**
|
100
|
+
* Computes a position with the maximum amount of liquidity received for a given amount of token0, assuming an unlimited amount of token1
|
101
|
+
* @param pool The pool for which the position is created
|
102
|
+
* @param tickLower The lower tick
|
103
|
+
* @param tickUpper The upper tick
|
104
|
+
* @param amount0 The desired amount of token0
|
105
|
+
* @param useFullPrecision If true, liquidity will be maximized according to what the router can calculate,
|
106
|
+
* not what core can theoretically support
|
107
|
+
* @returns The position
|
108
|
+
*/
|
109
|
+
static fromAmount0({ pool, tickLower, tickUpper, amount0, useFullPrecision, }: {
|
110
|
+
pool: Pool;
|
111
|
+
tickLower: number;
|
112
|
+
tickUpper: number;
|
113
|
+
amount0: BigintIsh;
|
114
|
+
useFullPrecision: boolean;
|
115
|
+
}): Position;
|
116
|
+
/**
|
117
|
+
* Computes a position with the maximum amount of liquidity received for a given amount of token1, assuming an unlimited amount of token0
|
118
|
+
* @param pool The pool for which the position is created
|
119
|
+
* @param tickLower The lower tick
|
120
|
+
* @param tickUpper The upper tick
|
121
|
+
* @param amount1 The desired amount of token1
|
122
|
+
* @returns The position
|
123
|
+
*/
|
124
|
+
static fromAmount1({ pool, tickLower, tickUpper, amount1, }: {
|
125
|
+
pool: Pool;
|
126
|
+
tickLower: number;
|
127
|
+
tickUpper: number;
|
128
|
+
amount1: BigintIsh;
|
129
|
+
}): Position;
|
130
|
+
}
|
131
|
+
export {};
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { Currency, Price, Token } from '@uniswap/sdk-core';
|
2
|
+
import { Pool } from './pool';
|
3
|
+
/**
|
4
|
+
* Represents a list of pools through which a swap can occur
|
5
|
+
* @template TInput The input token
|
6
|
+
* @template TOutput The output token
|
7
|
+
*/
|
8
|
+
export declare class Route<TInput extends Currency, TOutput extends Currency> {
|
9
|
+
readonly pools: Pool[];
|
10
|
+
readonly tokenPath: Token[];
|
11
|
+
readonly input: TInput;
|
12
|
+
readonly output: TOutput;
|
13
|
+
private _midPrice;
|
14
|
+
/**
|
15
|
+
* Creates an instance of route.
|
16
|
+
* @param pools An array of `Pool` objects, ordered by the route the swap will take
|
17
|
+
* @param input The input token
|
18
|
+
* @param output The output token
|
19
|
+
*/
|
20
|
+
constructor(pools: Pool[], input: TInput, output: TOutput);
|
21
|
+
get chainId(): number;
|
22
|
+
/**
|
23
|
+
* Returns the mid price of the route
|
24
|
+
*/
|
25
|
+
get midPrice(): Price<TInput, TOutput>;
|
26
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import JSBI from 'jsbi';
|
2
|
+
import { BigintIsh } from '@uniswap/sdk-core';
|
3
|
+
export interface TickConstructorArgs {
|
4
|
+
index: number;
|
5
|
+
liquidityGross: BigintIsh;
|
6
|
+
liquidityNet: BigintIsh;
|
7
|
+
}
|
8
|
+
export declare class Tick {
|
9
|
+
readonly index: number;
|
10
|
+
readonly liquidityGross: JSBI;
|
11
|
+
readonly liquidityNet: JSBI;
|
12
|
+
constructor({ index, liquidityGross, liquidityNet }: TickConstructorArgs);
|
13
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { BigintIsh } from '@uniswap/sdk-core';
|
2
|
+
/**
|
3
|
+
* Provides information about ticks
|
4
|
+
*/
|
5
|
+
export interface TickDataProvider {
|
6
|
+
/**
|
7
|
+
* Return information corresponding to a specific tick
|
8
|
+
* @param tick the tick to load
|
9
|
+
*/
|
10
|
+
getTick(tick: number): Promise<{
|
11
|
+
liquidityNet: BigintIsh;
|
12
|
+
}>;
|
13
|
+
/**
|
14
|
+
* Return the next tick that is initialized within a single word
|
15
|
+
* @param tick The current tick
|
16
|
+
* @param lte Whether the next tick should be lte the current tick
|
17
|
+
* @param tickSpacing The tick spacing of the pool
|
18
|
+
*/
|
19
|
+
nextInitializedTickWithinOneWord(tick: number, lte: boolean, tickSpacing: number): Promise<[number, boolean]>;
|
20
|
+
}
|
21
|
+
/**
|
22
|
+
* This tick data provider does not know how to fetch any tick data. It throws whenever it is required. Useful if you
|
23
|
+
* do not need to load tick data for your use case.
|
24
|
+
*/
|
25
|
+
export declare class NoTickDataProvider implements TickDataProvider {
|
26
|
+
private static ERROR_MESSAGE;
|
27
|
+
getTick(_tick: number): Promise<{
|
28
|
+
liquidityNet: BigintIsh;
|
29
|
+
}>;
|
30
|
+
nextInitializedTickWithinOneWord(_tick: number, _lte: boolean, _tickSpacing: number): Promise<[number, boolean]>;
|
31
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { BigintIsh } from '@uniswap/sdk-core';
|
2
|
+
import { Tick, TickConstructorArgs } from './tick';
|
3
|
+
import { TickDataProvider } from './tickDataProvider';
|
4
|
+
/**
|
5
|
+
* A data provider for ticks that is backed by an in-memory array of ticks.
|
6
|
+
*/
|
7
|
+
export declare class TickListDataProvider implements TickDataProvider {
|
8
|
+
private ticks;
|
9
|
+
constructor(ticks: (Tick | TickConstructorArgs)[], tickSpacing: number);
|
10
|
+
getTick(tick: number): Promise<{
|
11
|
+
liquidityNet: BigintIsh;
|
12
|
+
liquidityGross: BigintIsh;
|
13
|
+
}>;
|
14
|
+
nextInitializedTickWithinOneWord(tick: number, lte: boolean, tickSpacing: number): Promise<[number, boolean]>;
|
15
|
+
}
|
@@ -0,0 +1,220 @@
|
|
1
|
+
import { Currency, Percent, Price, CurrencyAmount, TradeType } from '@uniswap/sdk-core';
|
2
|
+
import { Pool } from './pool';
|
3
|
+
import { Route } from './route';
|
4
|
+
/**
|
5
|
+
* Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them
|
6
|
+
* @template TInput The input token, either Ether or an ERC-20
|
7
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
8
|
+
* @template TTradeType The trade type, either exact input or exact output
|
9
|
+
* @param a The first trade to compare
|
10
|
+
* @param b The second trade to compare
|
11
|
+
* @returns A sorted ordering for two neighboring elements in a trade array
|
12
|
+
*/
|
13
|
+
export declare function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(a: Trade<TInput, TOutput, TTradeType>, b: Trade<TInput, TOutput, TTradeType>): number;
|
14
|
+
export interface BestTradeOptions {
|
15
|
+
maxNumResults?: number;
|
16
|
+
maxHops?: number;
|
17
|
+
}
|
18
|
+
/**
|
19
|
+
* Represents a trade executed against a set of routes where some percentage of the input is
|
20
|
+
* split across each route.
|
21
|
+
*
|
22
|
+
* Each route has its own set of pools. Pools can not be re-used across routes.
|
23
|
+
*
|
24
|
+
* Does not account for slippage, i.e., changes in price environment that can occur between
|
25
|
+
* the time the trade is submitted and when it is executed.
|
26
|
+
* @template TInput The input token, either Ether or an ERC-20
|
27
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
28
|
+
* @template TTradeType The trade type, either exact input or exact output
|
29
|
+
*/
|
30
|
+
export declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {
|
31
|
+
/**
|
32
|
+
* @deprecated Deprecated in favor of 'swaps' property. If the trade consists of multiple routes
|
33
|
+
* this will return an error.
|
34
|
+
*
|
35
|
+
* When the trade consists of just a single route, this returns the route of the trade,
|
36
|
+
* i.e. which pools the trade goes through.
|
37
|
+
*/
|
38
|
+
get route(): Route<TInput, TOutput>;
|
39
|
+
/**
|
40
|
+
* The swaps of the trade, i.e. which routes and how much is swapped in each that
|
41
|
+
* make up the trade.
|
42
|
+
*/
|
43
|
+
readonly swaps: {
|
44
|
+
route: Route<TInput, TOutput>;
|
45
|
+
inputAmount: CurrencyAmount<TInput>;
|
46
|
+
outputAmount: CurrencyAmount<TOutput>;
|
47
|
+
}[];
|
48
|
+
/**
|
49
|
+
* The type of the trade, either exact in or exact out.
|
50
|
+
*/
|
51
|
+
readonly tradeType: TTradeType;
|
52
|
+
/**
|
53
|
+
* The cached result of the input amount computation
|
54
|
+
* @private
|
55
|
+
*/
|
56
|
+
private _inputAmount;
|
57
|
+
/**
|
58
|
+
* The input amount for the trade assuming no slippage.
|
59
|
+
*/
|
60
|
+
get inputAmount(): CurrencyAmount<TInput>;
|
61
|
+
/**
|
62
|
+
* The cached result of the output amount computation
|
63
|
+
* @private
|
64
|
+
*/
|
65
|
+
private _outputAmount;
|
66
|
+
/**
|
67
|
+
* The output amount for the trade assuming no slippage.
|
68
|
+
*/
|
69
|
+
get outputAmount(): CurrencyAmount<TOutput>;
|
70
|
+
/**
|
71
|
+
* The cached result of the computed execution price
|
72
|
+
* @private
|
73
|
+
*/
|
74
|
+
private _executionPrice;
|
75
|
+
/**
|
76
|
+
* The price expressed in terms of output amount/input amount.
|
77
|
+
*/
|
78
|
+
get executionPrice(): Price<TInput, TOutput>;
|
79
|
+
/**
|
80
|
+
* The cached result of the price impact computation
|
81
|
+
* @private
|
82
|
+
*/
|
83
|
+
private _priceImpact;
|
84
|
+
/**
|
85
|
+
* Returns the percent difference between the route's mid price and the price impact
|
86
|
+
*/
|
87
|
+
get priceImpact(): Percent;
|
88
|
+
/**
|
89
|
+
* Constructs an exact in trade with the given amount in and route
|
90
|
+
* @template TInput The input token, either Ether or an ERC-20
|
91
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
92
|
+
* @param route The route of the exact in trade
|
93
|
+
* @param amountIn The amount being passed in
|
94
|
+
* @returns The exact in trade
|
95
|
+
*/
|
96
|
+
static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Promise<Trade<TInput, TOutput, TradeType.EXACT_INPUT>>;
|
97
|
+
/**
|
98
|
+
* Constructs an exact out trade with the given amount out and route
|
99
|
+
* @template TInput The input token, either Ether or an ERC-20
|
100
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
101
|
+
* @param route The route of the exact out trade
|
102
|
+
* @param amountOut The amount returned by the trade
|
103
|
+
* @returns The exact out trade
|
104
|
+
*/
|
105
|
+
static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Promise<Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>>;
|
106
|
+
/**
|
107
|
+
* Constructs a trade by simulating swaps through the given route
|
108
|
+
* @template TInput The input token, either Ether or an ERC-20.
|
109
|
+
* @template TOutput The output token, either Ether or an ERC-20.
|
110
|
+
* @template TTradeType The type of the trade, either exact in or exact out.
|
111
|
+
* @param route route to swap through
|
112
|
+
* @param amount the amount specified, either input or output, depending on tradeType
|
113
|
+
* @param tradeType whether the trade is an exact input or exact output swap
|
114
|
+
* @returns The route
|
115
|
+
*/
|
116
|
+
static fromRoute<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(route: Route<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType): Promise<Trade<TInput, TOutput, TTradeType>>;
|
117
|
+
/**
|
118
|
+
* Constructs a trade from routes by simulating swaps
|
119
|
+
*
|
120
|
+
* @template TInput The input token, either Ether or an ERC-20.
|
121
|
+
* @template TOutput The output token, either Ether or an ERC-20.
|
122
|
+
* @template TTradeType The type of the trade, either exact in or exact out.
|
123
|
+
* @param routes the routes to swap through and how much of the amount should be routed through each
|
124
|
+
* @param tradeType whether the trade is an exact input or exact output swap
|
125
|
+
* @returns The trade
|
126
|
+
*/
|
127
|
+
static fromRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(routes: {
|
128
|
+
amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
|
129
|
+
route: Route<TInput, TOutput>;
|
130
|
+
}[], tradeType: TTradeType): Promise<Trade<TInput, TOutput, TTradeType>>;
|
131
|
+
/**
|
132
|
+
* Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade
|
133
|
+
* elsewhere and do not have any tick data
|
134
|
+
* @template TInput The input token, either Ether or an ERC-20
|
135
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
136
|
+
* @template TTradeType The type of the trade, either exact in or exact out
|
137
|
+
* @param constructorArguments The arguments passed to the trade constructor
|
138
|
+
* @returns The unchecked trade
|
139
|
+
*/
|
140
|
+
static createUncheckedTrade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(constructorArguments: {
|
141
|
+
route: Route<TInput, TOutput>;
|
142
|
+
inputAmount: CurrencyAmount<TInput>;
|
143
|
+
outputAmount: CurrencyAmount<TOutput>;
|
144
|
+
tradeType: TTradeType;
|
145
|
+
}): Trade<TInput, TOutput, TTradeType>;
|
146
|
+
/**
|
147
|
+
* Creates a trade without computing the result of swapping through the routes. Useful when you have simulated the trade
|
148
|
+
* elsewhere and do not have any tick data
|
149
|
+
* @template TInput The input token, either Ether or an ERC-20
|
150
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
151
|
+
* @template TTradeType The type of the trade, either exact in or exact out
|
152
|
+
* @param constructorArguments The arguments passed to the trade constructor
|
153
|
+
* @returns The unchecked trade
|
154
|
+
*/
|
155
|
+
static createUncheckedTradeWithMultipleRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(constructorArguments: {
|
156
|
+
routes: {
|
157
|
+
route: Route<TInput, TOutput>;
|
158
|
+
inputAmount: CurrencyAmount<TInput>;
|
159
|
+
outputAmount: CurrencyAmount<TOutput>;
|
160
|
+
}[];
|
161
|
+
tradeType: TTradeType;
|
162
|
+
}): Trade<TInput, TOutput, TTradeType>;
|
163
|
+
/**
|
164
|
+
* Construct a trade by passing in the pre-computed property values
|
165
|
+
* @param routes The routes through which the trade occurs
|
166
|
+
* @param tradeType The type of trade, exact input or exact output
|
167
|
+
*/
|
168
|
+
private constructor();
|
169
|
+
/**
|
170
|
+
* Get the minimum amount that must be received from this trade for the given slippage tolerance
|
171
|
+
* @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
|
172
|
+
* @returns The amount out
|
173
|
+
*/
|
174
|
+
minimumAmountOut(slippageTolerance: Percent, amountOut?: CurrencyAmount<TOutput>): CurrencyAmount<TOutput>;
|
175
|
+
/**
|
176
|
+
* Get the maximum amount in that can be spent via this trade for the given slippage tolerance
|
177
|
+
* @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
|
178
|
+
* @returns The amount in
|
179
|
+
*/
|
180
|
+
maximumAmountIn(slippageTolerance: Percent, amountIn?: CurrencyAmount<TInput>): CurrencyAmount<TInput>;
|
181
|
+
/**
|
182
|
+
* Return the execution price after accounting for slippage tolerance
|
183
|
+
* @param slippageTolerance the allowed tolerated slippage
|
184
|
+
* @returns The execution price
|
185
|
+
*/
|
186
|
+
worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>;
|
187
|
+
/**
|
188
|
+
* Given a list of pools, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
|
189
|
+
* amount to an output token, making at most `maxHops` hops.
|
190
|
+
* Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
|
191
|
+
* the amount in among multiple routes.
|
192
|
+
* @param pools the pools to consider in finding the best trade
|
193
|
+
* @param nextAmountIn exact amount of input currency to spend
|
194
|
+
* @param currencyOut the desired currency out
|
195
|
+
* @param maxNumResults maximum number of results to return
|
196
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
|
197
|
+
* @param currentPools used in recursion; the current list of pools
|
198
|
+
* @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
|
199
|
+
* @param bestTrades used in recursion; the current list of best trades
|
200
|
+
* @returns The exact in trade
|
201
|
+
*/
|
202
|
+
static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(pools: Pool[], currencyAmountIn: CurrencyAmount<TInput>, currencyOut: TOutput, { maxNumResults, maxHops }?: BestTradeOptions, currentPools?: Pool[], nextAmountIn?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]): Promise<Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]>;
|
203
|
+
/**
|
204
|
+
* similar to the above method but instead targets a fixed output amount
|
205
|
+
* given a list of pools, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token
|
206
|
+
* to an output token amount, making at most `maxHops` hops
|
207
|
+
* note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
|
208
|
+
* the amount in among multiple routes.
|
209
|
+
* @param pools the pools to consider in finding the best trade
|
210
|
+
* @param currencyIn the currency to spend
|
211
|
+
* @param currencyAmountOut the desired currency amount out
|
212
|
+
* @param nextAmountOut the exact amount of currency out
|
213
|
+
* @param maxNumResults maximum number of results to return
|
214
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
|
215
|
+
* @param currentPools used in recursion; the current list of pools
|
216
|
+
* @param bestTrades used in recursion; the current list of best trades
|
217
|
+
* @returns The exact out trade
|
218
|
+
*/
|
219
|
+
static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(pools: Pool[], currencyIn: TInput, currencyAmountOut: CurrencyAmount<TOutput>, { maxNumResults, maxHops }?: BestTradeOptions, currentPools?: Pool[], nextAmountOut?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]): Promise<Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]>;
|
220
|
+
}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
export * from './entities';
|
2
|
+
export * from './utils';
|
3
|
+
export * from './constants';
|
4
|
+
export * from './multicall';
|
5
|
+
export * from './nonfungiblePositionManager';
|
6
|
+
export * from './payments';
|
7
|
+
export * from './quoter';
|
8
|
+
export * from './selfPermit';
|
9
|
+
export * from './staker';
|
10
|
+
export * from './swapRouter';
|
package/dist/index.js
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
2
|
+
export declare abstract class Multicall {
|
3
|
+
static INTERFACE: Interface;
|
4
|
+
/**
|
5
|
+
* Cannot be constructed.
|
6
|
+
*/
|
7
|
+
private constructor();
|
8
|
+
static encodeMulticall(calldatas: string | string[]): string;
|
9
|
+
static decodeMulticall(multicall: string): string[];
|
10
|
+
}
|