monad-v3-sdk 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/abis/algebraPositionManager.d.ts +1083 -0
- package/dist/abis/algebraSwapRouter.d.ts +499 -0
- package/dist/abis/index.d.ts +3 -0
- package/dist/abis/selfPermit.d.ts +121 -0
- package/dist/classes/index.d.ts +3 -0
- package/dist/classes/nonfungiblePositionManager.d.ts +145 -0
- package/dist/classes/selfPermit.d.ts +22 -0
- package/dist/classes/swapRouter.d.ts +67 -0
- package/dist/constants/addresses.d.ts +6 -0
- package/dist/constants/chainIds.d.ts +3 -0
- package/dist/constants/constants.d.ts +3 -0
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/internalConstants.d.ts +7 -0
- package/dist/entities/AbstractCurrency.d.ts +48 -0
- package/dist/entities/Currency.d.ts +3 -0
- package/dist/entities/CurrencyAmount.d.ts +32 -0
- package/dist/entities/ExtendedNative.d.ts +7 -0
- package/dist/entities/Fraction.d.ts +25 -0
- package/dist/entities/Native.d.ts +13 -0
- package/dist/entities/NativeCurrency.d.ts +8 -0
- package/dist/entities/Percent.d.ts +16 -0
- package/dist/entities/Price.d.ts +39 -0
- package/dist/entities/Token.d.ts +32 -0
- package/dist/entities/index.d.ts +17 -0
- package/dist/entities/pool.d.ts +86 -0
- package/dist/entities/position.d.ts +135 -0
- package/dist/entities/route.d.ts +28 -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 +224 -0
- package/dist/entities/wnative.d.ts +7 -0
- package/dist/enums/bound.d.ts +4 -0
- package/dist/enums/field.d.ts +4 -0
- package/dist/enums/index.d.ts +4 -0
- package/dist/enums/rounding.d.ts +5 -0
- package/dist/enums/tradeType.d.ts +4 -0
- package/dist/functions/index.d.ts +5 -0
- package/dist/functions/maxAmountSpend.d.ts +7 -0
- package/dist/functions/mint.d.ts +3 -0
- package/dist/functions/retry.d.ts +22 -0
- package/dist/functions/tryParseAmount.d.ts +3 -0
- package/dist/functions/unwrappedToken.d.ts +2 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/monad-v3-sdk.cjs.development.js +5458 -0
- package/dist/monad-v3-sdk.cjs.development.js.map +1 -0
- package/dist/monad-v3-sdk.cjs.production.min.js +2 -0
- package/dist/monad-v3-sdk.cjs.production.min.js.map +1 -0
- package/dist/monad-v3-sdk.esm.js +5395 -0
- package/dist/monad-v3-sdk.esm.js.map +1 -0
- package/dist/types/BigIntish.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/calldata.d.ts +20 -0
- package/dist/utils/chunkArray.d.ts +2 -0
- package/dist/utils/computePoolAddress.d.ts +28 -0
- package/dist/utils/computeSurroundingTicks.d.ts +2 -0
- package/dist/utils/encodeRouteToPath.d.ts +8 -0
- package/dist/utils/encodeSqrtRatioX96.d.ts +9 -0
- package/dist/utils/format.d.ts +14 -0
- package/dist/utils/formatTickPrice.d.ts +5 -0
- package/dist/utils/fullMath.d.ts +7 -0
- package/dist/utils/getRatio.d.ts +2 -0
- package/dist/utils/getTickToPrice.d.ts +2 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/isSorted.d.ts +7 -0
- package/dist/utils/liquidityMath.d.ts +7 -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/priceTickConversions.d.ts +16 -0
- package/dist/utils/sortedInsert.d.ts +1 -0
- package/dist/utils/sqrt.d.ts +7 -0
- package/dist/utils/sqrtPriceMath.d.ts +12 -0
- package/dist/utils/stringToColour.d.ts +5 -0
- package/dist/utils/swapMath.d.ts +7 -0
- package/dist/utils/tickList.d.ts +22 -0
- package/dist/utils/tickMath.d.ts +33 -0
- package/dist/utils/validateAndParseAddress.d.ts +1 -0
- package/package.json +62 -0
@@ -0,0 +1,135 @@
|
|
1
|
+
import { Percent } from './Percent';
|
2
|
+
import { CurrencyAmount } from './CurrencyAmount';
|
3
|
+
import { Price } from './Price';
|
4
|
+
import { Token } from './Token';
|
5
|
+
import { BigintIsh } from '../types/BigIntish';
|
6
|
+
import JSBI from 'jsbi';
|
7
|
+
import { Pool } from './pool';
|
8
|
+
interface PositionConstructorArgs {
|
9
|
+
pool: Pool;
|
10
|
+
tickLower: number;
|
11
|
+
tickUpper: number;
|
12
|
+
liquidity: BigintIsh;
|
13
|
+
}
|
14
|
+
/**
|
15
|
+
* Represents a position on a Algebra Pool
|
16
|
+
*/
|
17
|
+
export declare class Position {
|
18
|
+
readonly pool: Pool;
|
19
|
+
readonly tickLower: number;
|
20
|
+
readonly tickUpper: number;
|
21
|
+
readonly liquidity: JSBI;
|
22
|
+
private _token0Amount;
|
23
|
+
private _token1Amount;
|
24
|
+
/**
|
25
|
+
* Constructs a position for a given pool with the given liquidity
|
26
|
+
* @param pool For which pool the liquidity is assigned
|
27
|
+
* @param liquidity The amount of liquidity that is in the position
|
28
|
+
* @param tickLower The lower tick of the position
|
29
|
+
* @param tickUpper The upper tick of the position
|
30
|
+
*/
|
31
|
+
constructor({ pool, liquidity, tickLower, tickUpper, }: PositionConstructorArgs);
|
32
|
+
private _mintAmounts;
|
33
|
+
/**
|
34
|
+
* Returns the minimum amounts that must be sent in order to mint the amount of liquidity held by the position at
|
35
|
+
* the current price for the pool
|
36
|
+
*/
|
37
|
+
get mintAmounts(): Readonly<{
|
38
|
+
amount0: JSBI;
|
39
|
+
amount1: JSBI;
|
40
|
+
}>;
|
41
|
+
/**
|
42
|
+
* Returns the price of token0 at the lower tick
|
43
|
+
*/
|
44
|
+
get token0PriceLower(): Price<Token, Token>;
|
45
|
+
/**
|
46
|
+
* Returns the price of token0 at the upper tick
|
47
|
+
*/
|
48
|
+
get token0PriceUpper(): Price<Token, Token>;
|
49
|
+
/**
|
50
|
+
* Returns the amount of token0 that this position's liquidity could be burned for at the current pool price
|
51
|
+
*/
|
52
|
+
get amount0(): CurrencyAmount<Token>;
|
53
|
+
/**
|
54
|
+
* Returns the amount of token1 that this position's liquidity could be burned for at the current pool price
|
55
|
+
*/
|
56
|
+
get amount1(): CurrencyAmount<Token>;
|
57
|
+
/**
|
58
|
+
* Computes the maximum amount of liquidity received for a given amount of token0, token1,
|
59
|
+
* and the prices at the tick boundaries.
|
60
|
+
* @param pool The pool for which the position should be created
|
61
|
+
* @param tickLower The lower tick of the position
|
62
|
+
* @param tickUpper The upper tick of the position
|
63
|
+
* @param amount0 token0 amount
|
64
|
+
* @param amount1 token1 amount
|
65
|
+
* @param useFullPrecision If false, liquidity will be maximized according to what the router can calculate,
|
66
|
+
* not what core can theoretically support
|
67
|
+
* @returns The amount of liquidity for the position
|
68
|
+
*/
|
69
|
+
static fromAmounts({ pool, tickLower, tickUpper, amount0, amount1, useFullPrecision, }: {
|
70
|
+
pool: Pool;
|
71
|
+
tickLower: number;
|
72
|
+
tickUpper: number;
|
73
|
+
amount0: BigintIsh;
|
74
|
+
amount1: BigintIsh;
|
75
|
+
useFullPrecision: boolean;
|
76
|
+
}): Position;
|
77
|
+
/**
|
78
|
+
* Computes a position with the maximum amount of liquidity received for a given amount of token0, assuming an unlimited amount of token1
|
79
|
+
* @param pool The pool for which the position is created
|
80
|
+
* @param tickLower The lower tick
|
81
|
+
* @param tickUpper The upper tick
|
82
|
+
* @param amount0 The desired amount of token0
|
83
|
+
* @param useFullPrecision If true, liquidity will be maximized according to what the router can calculate,
|
84
|
+
* not what core can theoretically support
|
85
|
+
* @returns The position
|
86
|
+
*/
|
87
|
+
static fromAmount0({ pool, tickLower, tickUpper, amount0, useFullPrecision, }: {
|
88
|
+
pool: Pool;
|
89
|
+
tickLower: number;
|
90
|
+
tickUpper: number;
|
91
|
+
amount0: BigintIsh;
|
92
|
+
useFullPrecision: boolean;
|
93
|
+
}): Position;
|
94
|
+
/**
|
95
|
+
* Computes a position with the maximum amount of liquidity received for a given amount of token1, assuming an unlimited amount of token0
|
96
|
+
* @param pool The pool for which the position is created
|
97
|
+
* @param tickLower The lower tick
|
98
|
+
* @param tickUpper The upper tick
|
99
|
+
* @param amount1 The desired amount of token1
|
100
|
+
* @returns The position
|
101
|
+
*/
|
102
|
+
static fromAmount1({ pool, tickLower, tickUpper, amount1, }: {
|
103
|
+
pool: Pool;
|
104
|
+
tickLower: number;
|
105
|
+
tickUpper: number;
|
106
|
+
amount1: BigintIsh;
|
107
|
+
}): Position;
|
108
|
+
/**
|
109
|
+
* Returns the minimum amounts that must be sent in order to safely mint the amount of liquidity held by the position
|
110
|
+
* with the given slippage tolerance
|
111
|
+
* @param slippageTolerance Tolerance of unfavorable slippage from the current price
|
112
|
+
* @returns The amounts, with slippage
|
113
|
+
*/
|
114
|
+
mintAmountsWithSlippage(slippageTolerance: Percent): Readonly<{
|
115
|
+
amount0: JSBI;
|
116
|
+
amount1: JSBI;
|
117
|
+
}>;
|
118
|
+
/**
|
119
|
+
* Returns the minimum amounts that should be requested in order to safely burn the amount of liquidity held by the
|
120
|
+
* position with the given slippage tolerance
|
121
|
+
* @param slippageTolerance tolerance of unfavorable slippage from the current price
|
122
|
+
* @returns The amounts, with slippage
|
123
|
+
*/
|
124
|
+
burnAmountsWithSlippage(slippageTolerance: Percent): Readonly<{
|
125
|
+
amount0: JSBI;
|
126
|
+
amount1: JSBI;
|
127
|
+
}>;
|
128
|
+
/**
|
129
|
+
* Returns the lower and upper sqrt ratios if the price 'slips' up to slippage tolerance percentage
|
130
|
+
* @param slippageTolerance The amount by which the price can 'slip' before the transaction will revert
|
131
|
+
* @returns The sqrt ratios after slippage
|
132
|
+
*/
|
133
|
+
private ratiosAfterSlippage;
|
134
|
+
}
|
135
|
+
export {};
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { Currency } from './Currency';
|
2
|
+
import { Price } from './Price';
|
3
|
+
import { Token } from './Token';
|
4
|
+
import { Pool } from './pool';
|
5
|
+
/**
|
6
|
+
* Represents a list of pools through which a swap can occur
|
7
|
+
* @template TInput The input token
|
8
|
+
* @template TOutput The output token
|
9
|
+
*/
|
10
|
+
export declare class Route<TInput extends Currency, TOutput extends Currency> {
|
11
|
+
readonly pools: Pool[];
|
12
|
+
readonly tokenPath: Token[];
|
13
|
+
readonly input: TInput;
|
14
|
+
readonly output: TOutput;
|
15
|
+
/**
|
16
|
+
* Creates an instance of route.
|
17
|
+
* @param pools An array of `Pool` objects, ordered by the route the swap will take
|
18
|
+
* @param input The input token
|
19
|
+
* @param output The output token
|
20
|
+
*/
|
21
|
+
constructor(pools: Pool[], input: TInput, output: TOutput);
|
22
|
+
private _midPrice;
|
23
|
+
/**
|
24
|
+
* Returns the mid price of the route
|
25
|
+
*/
|
26
|
+
get midPrice(): Price<TInput, TOutput>;
|
27
|
+
get chainId(): number;
|
28
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import JSBI from 'jsbi';
|
2
|
+
import { BigintIsh } from '../types/BigIntish';
|
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 '../types/BigIntish';
|
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 '../types/BigIntish';
|
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,224 @@
|
|
1
|
+
import { Currency } from '../entities/Currency';
|
2
|
+
import { CurrencyAmount } from '../entities/CurrencyAmount';
|
3
|
+
import { Percent } from '../entities/Percent';
|
4
|
+
import { Price } from '../entities/Price';
|
5
|
+
import { TradeType } from '../enums/tradeType';
|
6
|
+
import { Pool } from './pool';
|
7
|
+
import { Route } from './route';
|
8
|
+
/**
|
9
|
+
* Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them
|
10
|
+
* @template TInput The input token, either Ether or an ERC-20
|
11
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
12
|
+
* @template TTradeType The trade type, either exact input or exact output
|
13
|
+
* @param a The first trade to compare
|
14
|
+
* @param b The second trade to compare
|
15
|
+
* @returns A sorted ordering for two neighboring elements in a trade array
|
16
|
+
*/
|
17
|
+
export declare function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(a: Trade<TInput, TOutput, TTradeType>, b: Trade<TInput, TOutput, TTradeType>): number;
|
18
|
+
export interface BestTradeOptions {
|
19
|
+
maxNumResults?: number;
|
20
|
+
maxHops?: number;
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* Represents a trade executed against a set of routes where some percentage of the input is
|
24
|
+
* split across each route.
|
25
|
+
*
|
26
|
+
* Each route has its own set of pools. Pools can not be re-used across routes.
|
27
|
+
*
|
28
|
+
* Does not account for slippage, i.e., changes in price environment that can occur between
|
29
|
+
* the time the trade is submitted and when it is executed.
|
30
|
+
* @template TInput The input token, either Ether or an ERC-20
|
31
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
32
|
+
* @template TTradeType The trade type, either exact input or exact output
|
33
|
+
*/
|
34
|
+
export declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {
|
35
|
+
/**
|
36
|
+
* The swaps of the trade, i.e. which routes and how much is swapped in each that
|
37
|
+
* make up the trade.
|
38
|
+
*/
|
39
|
+
readonly swaps: {
|
40
|
+
route: Route<TInput, TOutput>;
|
41
|
+
inputAmount: CurrencyAmount<TInput>;
|
42
|
+
outputAmount: CurrencyAmount<TOutput>;
|
43
|
+
}[];
|
44
|
+
/**
|
45
|
+
* The type of the trade, either exact in or exact out.
|
46
|
+
*/
|
47
|
+
readonly tradeType: TTradeType;
|
48
|
+
/**
|
49
|
+
* Construct a trade by passing in the pre-computed property values
|
50
|
+
* @param routes The routes through which the trade occurs
|
51
|
+
* @param tradeType The type of trade, exact input or exact output
|
52
|
+
*/
|
53
|
+
private constructor();
|
54
|
+
/**
|
55
|
+
* @deprecated Deprecated in favor of 'swaps' property. If the trade consists of multiple routes
|
56
|
+
* this will return an error.
|
57
|
+
*
|
58
|
+
* When the trade consists of just a single route, this returns the route of the trade,
|
59
|
+
* i.e. which pools the trade goes through.
|
60
|
+
*/
|
61
|
+
get route(): Route<TInput, TOutput>;
|
62
|
+
/**
|
63
|
+
* The cached result of the input amount computation
|
64
|
+
* @private
|
65
|
+
*/
|
66
|
+
private _inputAmount;
|
67
|
+
/**
|
68
|
+
* The input amount for the trade assuming no slippage.
|
69
|
+
*/
|
70
|
+
get inputAmount(): CurrencyAmount<TInput>;
|
71
|
+
/**
|
72
|
+
* The cached result of the output amount computation
|
73
|
+
* @private
|
74
|
+
*/
|
75
|
+
private _outputAmount;
|
76
|
+
/**
|
77
|
+
* The output amount for the trade assuming no slippage.
|
78
|
+
*/
|
79
|
+
get outputAmount(): CurrencyAmount<TOutput>;
|
80
|
+
/**
|
81
|
+
* The cached result of the computed execution price
|
82
|
+
* @private
|
83
|
+
*/
|
84
|
+
private _executionPrice;
|
85
|
+
/**
|
86
|
+
* The price expressed in terms of output amount/input amount.
|
87
|
+
*/
|
88
|
+
get executionPrice(): Price<TInput, TOutput>;
|
89
|
+
/**
|
90
|
+
* The cached result of the price impact computation
|
91
|
+
* @private
|
92
|
+
*/
|
93
|
+
private _priceImpact;
|
94
|
+
/**
|
95
|
+
* Returns the percent difference between the route's mid price and the price impact
|
96
|
+
*/
|
97
|
+
get priceImpact(): Percent;
|
98
|
+
/**
|
99
|
+
* Constructs an exact in trade with the given amount in and route
|
100
|
+
* @template TInput The input token, either Ether or an ERC-20
|
101
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
102
|
+
* @param route The route of the exact in trade
|
103
|
+
* @param amountIn The amount being passed in
|
104
|
+
* @returns The exact in trade
|
105
|
+
*/
|
106
|
+
static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Promise<Trade<TInput, TOutput, TradeType.EXACT_INPUT>>;
|
107
|
+
/**
|
108
|
+
* Constructs an exact out trade with the given amount out and route
|
109
|
+
* @template TInput The input token, either Ether or an ERC-20
|
110
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
111
|
+
* @param route The route of the exact out trade
|
112
|
+
* @param amountOut The amount returned by the trade
|
113
|
+
* @returns The exact out trade
|
114
|
+
*/
|
115
|
+
static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Promise<Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>>;
|
116
|
+
/**
|
117
|
+
* Constructs a trade by simulating swaps through the given route
|
118
|
+
* @template TInput The input token, either Ether or an ERC-20.
|
119
|
+
* @template TOutput The output token, either Ether or an ERC-20.
|
120
|
+
* @template TTradeType The type of the trade, either exact in or exact out.
|
121
|
+
* @param route route to swap through
|
122
|
+
* @param amount the amount specified, either input or output, depending on tradeType
|
123
|
+
* @param tradeType whether the trade is an exact input or exact output swap
|
124
|
+
* @returns The route
|
125
|
+
*/
|
126
|
+
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>>;
|
127
|
+
/**
|
128
|
+
* Constructs a trade from routes by simulating swaps
|
129
|
+
*
|
130
|
+
* @template TInput The input token, either Ether or an ERC-20.
|
131
|
+
* @template TOutput The output token, either Ether or an ERC-20.
|
132
|
+
* @template TTradeType The type of the trade, either exact in or exact out.
|
133
|
+
* @param routes the routes to swap through and how much of the amount should be routed through each
|
134
|
+
* @param tradeType whether the trade is an exact input or exact output swap
|
135
|
+
* @returns The trade
|
136
|
+
*/
|
137
|
+
static fromRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(routes: {
|
138
|
+
amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
|
139
|
+
route: Route<TInput, TOutput>;
|
140
|
+
}[], tradeType: TTradeType): Promise<Trade<TInput, TOutput, TTradeType>>;
|
141
|
+
/**
|
142
|
+
* Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade
|
143
|
+
* elsewhere and do not have any tick data
|
144
|
+
* @template TInput The input token, either Ether or an ERC-20
|
145
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
146
|
+
* @template TTradeType The type of the trade, either exact in or exact out
|
147
|
+
* @param constructorArguments The arguments passed to the trade constructor
|
148
|
+
* @returns The unchecked trade
|
149
|
+
*/
|
150
|
+
static createUncheckedTrade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(constructorArguments: {
|
151
|
+
route: Route<TInput, TOutput>;
|
152
|
+
inputAmount: CurrencyAmount<TInput>;
|
153
|
+
outputAmount: CurrencyAmount<TOutput>;
|
154
|
+
tradeType: TTradeType;
|
155
|
+
}): Trade<TInput, TOutput, TTradeType>;
|
156
|
+
/**
|
157
|
+
* Creates a trade without computing the result of swapping through the routes. Useful when you have simulated the trade
|
158
|
+
* elsewhere and do not have any tick data
|
159
|
+
* @template TInput The input token, either Ether or an ERC-20
|
160
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
161
|
+
* @template TTradeType The type of the trade, either exact in or exact out
|
162
|
+
* @param constructorArguments The arguments passed to the trade constructor
|
163
|
+
* @returns The unchecked trade
|
164
|
+
*/
|
165
|
+
static createUncheckedTradeWithMultipleRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(constructorArguments: {
|
166
|
+
routes: {
|
167
|
+
route: Route<TInput, TOutput>;
|
168
|
+
inputAmount: CurrencyAmount<TInput>;
|
169
|
+
outputAmount: CurrencyAmount<TOutput>;
|
170
|
+
}[];
|
171
|
+
tradeType: TTradeType;
|
172
|
+
}): Trade<TInput, TOutput, TTradeType>;
|
173
|
+
/**
|
174
|
+
* Given a list of pools, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
|
175
|
+
* amount to an output token, making at most `maxHops` hops.
|
176
|
+
* Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
|
177
|
+
* the amount in among multiple routes.
|
178
|
+
* @param pools the pools to consider in finding the best trade
|
179
|
+
* @param nextAmountIn exact amount of input currency to spend
|
180
|
+
* @param currencyOut the desired currency out
|
181
|
+
* @param maxNumResults maximum number of results to return
|
182
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
|
183
|
+
* @param currentPools used in recursion; the current list of pools
|
184
|
+
* @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
|
185
|
+
* @param bestTrades used in recursion; the current list of best trades
|
186
|
+
* @returns The exact in trade
|
187
|
+
*/
|
188
|
+
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>[]>;
|
189
|
+
/**
|
190
|
+
* similar to the above method but instead targets a fixed output amount
|
191
|
+
* given a list of pools, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token
|
192
|
+
* to an output token amount, making at most `maxHops` hops
|
193
|
+
* note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
|
194
|
+
* the amount in among multiple routes.
|
195
|
+
* @param pools the pools to consider in finding the best trade
|
196
|
+
* @param currencyIn the currency to spend
|
197
|
+
* @param currencyAmountOut the desired currency amount out
|
198
|
+
* @param nextAmountOut the exact amount of currency out
|
199
|
+
* @param maxNumResults maximum number of results to return
|
200
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
|
201
|
+
* @param currentPools used in recursion; the current list of pools
|
202
|
+
* @param bestTrades used in recursion; the current list of best trades
|
203
|
+
* @returns The exact out trade
|
204
|
+
*/
|
205
|
+
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>[]>;
|
206
|
+
/**
|
207
|
+
* Get the minimum amount that must be received from this trade for the given slippage tolerance
|
208
|
+
* @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
|
209
|
+
* @returns The amount out
|
210
|
+
*/
|
211
|
+
minimumAmountOut(slippageTolerance: Percent, amountOut?: CurrencyAmount<TOutput>): CurrencyAmount<TOutput>;
|
212
|
+
/**
|
213
|
+
* Get the maximum amount in that can be spent via this trade for the given slippage tolerance
|
214
|
+
* @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
|
215
|
+
* @returns The amount in
|
216
|
+
*/
|
217
|
+
maximumAmountIn(slippageTolerance: Percent, amountIn?: CurrencyAmount<TInput>): CurrencyAmount<TInput>;
|
218
|
+
/**
|
219
|
+
* Return the execution price after accounting for slippage tolerance
|
220
|
+
* @param slippageTolerance the allowed tolerated slippage
|
221
|
+
* @returns The execution price
|
222
|
+
*/
|
223
|
+
worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>;
|
224
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { Currency } from '../entities/Currency';
|
2
|
+
import { CurrencyAmount } from '../entities/CurrencyAmount';
|
3
|
+
/**
|
4
|
+
* Given some token amount, return the max that can be spent of it
|
5
|
+
* @param currencyAmount to return max of
|
6
|
+
*/
|
7
|
+
export declare function maxAmountSpend(currencyAmount?: CurrencyAmount<Currency>): CurrencyAmount<Currency> | undefined;
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { Price, Token } from "../entities";
|
2
|
+
export declare function tryParsePrice(baseToken?: Token, quoteToken?: Token, value?: string): Price<Token, Token> | undefined;
|
3
|
+
export declare function tryParseTick(baseToken?: Token, quoteToken?: Token, value?: string, tickSpacing?: number): number | undefined;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/**
|
2
|
+
* Throw this error if the function should retry
|
3
|
+
*/
|
4
|
+
export declare class RetryableError extends Error {
|
5
|
+
isRetryableError: true;
|
6
|
+
}
|
7
|
+
export interface RetryOptions {
|
8
|
+
n: number;
|
9
|
+
minWait: number;
|
10
|
+
maxWait: number;
|
11
|
+
}
|
12
|
+
/**
|
13
|
+
* Retries the function that returns the promise until the promise successfully resolves up to n retries
|
14
|
+
* @param fn function to retry
|
15
|
+
* @param n how many times to retry
|
16
|
+
* @param minWait min wait between retries in ms
|
17
|
+
* @param maxWait max wait between retries in ms
|
18
|
+
*/
|
19
|
+
export declare function retry<T>(fn: () => Promise<T>, { n, minWait, maxWait }: RetryOptions): {
|
20
|
+
promise: Promise<T>;
|
21
|
+
cancel: () => void;
|
22
|
+
};
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { Currency, CurrencyAmount } from '../entities';
|
2
|
+
export declare const parseBalance: (value: string, decimals?: number) => import("@ethersproject/bignumber").BigNumber;
|
3
|
+
export declare function tryParseAmount<T extends Currency>(value?: string, currency?: T): CurrencyAmount<T> | undefined;
|
package/dist/index.d.ts
ADDED