@juiceswapxyz/v4-sdk 3.0.0 → 3.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.
@@ -0,0 +1,169 @@
1
+ import { BigintIsh, Percent, NativeCurrency } from '@juiceswapxyz/sdk-core';
2
+ import { TypedDataDomain, TypedDataField } from '@ethersproject/abstract-signer';
3
+ import { Position } from './entities/position';
4
+ import { MethodParameters } from './utils/calldata';
5
+ import { Interface } from '@ethersproject/abi';
6
+ import { PoolKey } from './entities';
7
+ export interface CommonOptions {
8
+ /**
9
+ * How much the pool price is allowed to move from the specified action.
10
+ */
11
+ slippageTolerance: Percent;
12
+ /**
13
+ * Optional data to pass to hooks
14
+ */
15
+ hookData?: string;
16
+ /**
17
+ * When the transaction expires, in epoch seconds.
18
+ */
19
+ deadline: BigintIsh;
20
+ }
21
+ export interface ModifyPositionSpecificOptions {
22
+ /**
23
+ * Indicates the ID of the position to increase liquidity for.
24
+ */
25
+ tokenId: BigintIsh;
26
+ }
27
+ export interface MintSpecificOptions {
28
+ /**
29
+ * The account that should receive the minted NFT.
30
+ */
31
+ recipient: string;
32
+ /**
33
+ * Creates pool if not initialized before mint.
34
+ */
35
+ createPool?: boolean;
36
+ /**
37
+ * Initial price to set on the pool if creating
38
+ */
39
+ sqrtPriceX96?: BigintIsh;
40
+ /**
41
+ * Whether the mint is part of a migration from V3 to V4.
42
+ */
43
+ migrate?: boolean;
44
+ }
45
+ /**
46
+ * Options for producing the calldata to add liquidity.
47
+ */
48
+ export interface CommonAddLiquidityOptions {
49
+ /**
50
+ * Whether to spend ether. If true, one of the currencies must be the NATIVE currency.
51
+ */
52
+ useNative?: NativeCurrency;
53
+ /**
54
+ * The optional permit2 batch permit parameters for spending token0 and token1
55
+ */
56
+ batchPermit?: BatchPermitOptions;
57
+ }
58
+ /**
59
+ * Options for producing the calldata to exit a position.
60
+ */
61
+ export interface RemoveLiquiditySpecificOptions {
62
+ /**
63
+ * The percentage of position liquidity to exit.
64
+ */
65
+ liquidityPercentage: Percent;
66
+ /**
67
+ * Whether the NFT should be burned if the entire position is being exited, by default false.
68
+ */
69
+ burnToken?: boolean;
70
+ /**
71
+ * The optional permit of the token ID being exited, in case the exit transaction is being sent by an account that does not own the NFT
72
+ */
73
+ permit?: NFTPermitOptions;
74
+ }
75
+ export interface CollectSpecificOptions {
76
+ /**
77
+ * Indicates the ID of the position to collect for.
78
+ */
79
+ tokenId: BigintIsh;
80
+ /**
81
+ * The account that should receive the tokens.
82
+ */
83
+ recipient: string;
84
+ }
85
+ export interface TransferOptions {
86
+ /**
87
+ * The account sending the NFT.
88
+ */
89
+ sender: string;
90
+ /**
91
+ * The account that should receive the NFT.
92
+ */
93
+ recipient: string;
94
+ /**
95
+ * The id of the token being sent.
96
+ */
97
+ tokenId: BigintIsh;
98
+ }
99
+ export interface PermitDetails {
100
+ token: string;
101
+ amount: BigintIsh;
102
+ expiration: BigintIsh;
103
+ nonce: BigintIsh;
104
+ }
105
+ export interface AllowanceTransferPermitSingle {
106
+ details: PermitDetails;
107
+ spender: string;
108
+ sigDeadline: BigintIsh;
109
+ }
110
+ export interface AllowanceTransferPermitBatch {
111
+ details: PermitDetails[];
112
+ spender: string;
113
+ sigDeadline: BigintIsh;
114
+ }
115
+ export interface BatchPermitOptions {
116
+ owner: string;
117
+ permitBatch: AllowanceTransferPermitBatch;
118
+ signature: string;
119
+ }
120
+ export interface NFTPermitValues {
121
+ spender: string;
122
+ tokenId: BigintIsh;
123
+ deadline: BigintIsh;
124
+ nonce: BigintIsh;
125
+ }
126
+ export interface NFTPermitOptions extends NFTPermitValues {
127
+ signature: string;
128
+ }
129
+ export interface NFTPermitData {
130
+ domain: TypedDataDomain;
131
+ types: Record<string, TypedDataField[]>;
132
+ values: NFTPermitValues;
133
+ }
134
+ export declare type MintOptions = CommonOptions & CommonAddLiquidityOptions & MintSpecificOptions;
135
+ export declare type IncreaseLiquidityOptions = CommonOptions & CommonAddLiquidityOptions & ModifyPositionSpecificOptions;
136
+ export declare type AddLiquidityOptions = MintOptions | IncreaseLiquidityOptions;
137
+ export declare type RemoveLiquidityOptions = CommonOptions & RemoveLiquiditySpecificOptions & ModifyPositionSpecificOptions;
138
+ export declare type CollectOptions = CommonOptions & CollectSpecificOptions;
139
+ export declare abstract class V4PositionManager {
140
+ static INTERFACE: Interface;
141
+ /**
142
+ * Cannot be constructed.
143
+ */
144
+ private constructor();
145
+ /**
146
+ * Public methods to encode method parameters for different actions on the PositionManager contract
147
+ */
148
+ static createCallParameters(poolKey: PoolKey, sqrtPriceX96: BigintIsh): MethodParameters;
149
+ static addCallParameters(position: Position, options: AddLiquidityOptions): MethodParameters;
150
+ /**
151
+ * Produces the calldata for completely or partially exiting a position
152
+ * @param position The position to exit
153
+ * @param options Additional information necessary for generating the calldata
154
+ * @returns The call parameters
155
+ */
156
+ static removeCallParameters(position: Position, options: RemoveLiquidityOptions): MethodParameters;
157
+ /**
158
+ * Produces the calldata for collecting fees from a position
159
+ * @param position The position to collect fees from
160
+ * @param options Additional information necessary for generating the calldata
161
+ * @returns The call parameters
162
+ */
163
+ static collectCallParameters(position: Position, options: CollectOptions): MethodParameters;
164
+ private static encodeInitializePool;
165
+ static encodeModifyLiquidities(unlockData: string, deadline: BigintIsh): string;
166
+ static encodePermitBatch(owner: string, permitBatch: AllowanceTransferPermitBatch, signature: string): string;
167
+ static encodeERC721Permit(spender: string, tokenId: BigintIsh, deadline: BigintIsh, nonce: BigintIsh, signature: string): string;
168
+ static getPermitData(permit: NFTPermitValues, positionManagerAddress: string, chainId: number): NFTPermitData;
169
+ }
@@ -0,0 +1 @@
1
+ export declare const MSG_SENDER = "0x0000000000000000000000000000000000000001";
@@ -0,0 +1,4 @@
1
+ export * from './pool';
2
+ export * from './route';
3
+ export * from './trade';
4
+ export * from './position';
@@ -0,0 +1,103 @@
1
+ import { BigintIsh, Currency, CurrencyAmount, Price } from '@juiceswapxyz/sdk-core';
2
+ import { Tick, TickConstructorArgs, TickDataProvider } from '@juiceswapxyz/v3-sdk';
3
+ import JSBI from 'jsbi';
4
+ export declare const DYNAMIC_FEE_FLAG = 8388608;
5
+ export declare type PoolKey = {
6
+ currency0: string;
7
+ currency1: string;
8
+ fee: number;
9
+ tickSpacing: number;
10
+ hooks: string;
11
+ };
12
+ /**
13
+ * Represents a V4 pool
14
+ */
15
+ export declare class Pool {
16
+ readonly currency0: Currency;
17
+ readonly currency1: Currency;
18
+ readonly fee: number;
19
+ readonly tickSpacing: number;
20
+ readonly sqrtRatioX96: JSBI;
21
+ readonly hooks: string;
22
+ readonly liquidity: JSBI;
23
+ readonly tickCurrent: number;
24
+ readonly tickDataProvider: TickDataProvider;
25
+ readonly poolKey: PoolKey;
26
+ readonly poolId: string;
27
+ private _currency0Price?;
28
+ private _currency1Price?;
29
+ static getPoolKey(currencyA: Currency, currencyB: Currency, fee: number, tickSpacing: number, hooks: string): PoolKey;
30
+ static getPoolId(currencyA: Currency, currencyB: Currency, fee: number, tickSpacing: number, hooks: string): string;
31
+ /**
32
+ * Construct a pool
33
+ * @param currencyA One of the currencys in the pool
34
+ * @param currencyB The other currency in the pool
35
+ * @param fee The fee in hundredths of a bips of the input amount of every swap that is collected by the pool
36
+ * @param tickSpacing The tickSpacing of the pool
37
+ * @param hooks The address of the hook contract
38
+ * @param sqrtRatioX96 The sqrt of the current ratio of amounts of currency1 to currency0
39
+ * @param liquidity The current value of in range liquidity
40
+ * @param tickCurrent The current tick of the pool
41
+ */
42
+ constructor(currencyA: Currency, currencyB: Currency, fee: number, tickSpacing: number, hooks: string, sqrtRatioX96: BigintIsh, liquidity: BigintIsh, tickCurrent: number, ticks?: TickDataProvider | (Tick | TickConstructorArgs)[]);
43
+ /** backwards compatibility with v2/3 sdks */
44
+ get token0(): Currency;
45
+ get token1(): Currency;
46
+ /**
47
+ * Returns true if the currency is either currency0 or currency1
48
+ * @param currency The currency to check
49
+ * @returns True if currency is either currency0 or currency1
50
+ */
51
+ involvesCurrency(currency: Currency): boolean;
52
+ /** backwards compatibility with v2/3 sdks */
53
+ involvesToken(currency: Currency): boolean;
54
+ /**
55
+ * v4-only involvesToken convenience method, used for mixed route ETH <-> WETH connection only
56
+ * @param currency
57
+ */
58
+ v4InvolvesToken(currency: Currency): boolean;
59
+ /**
60
+ * Returns the current mid price of the pool in terms of currency0, i.e. the ratio of currency1 over currency0
61
+ */
62
+ get currency0Price(): Price<Currency, Currency>;
63
+ /** backwards compatibility with v2/3 sdks */
64
+ get token0Price(): Price<Currency, Currency>;
65
+ /**
66
+ * Returns the current mid price of the pool in terms of currency1, i.e. the ratio of currency0 over currency1
67
+ */
68
+ get currency1Price(): Price<Currency, Currency>;
69
+ /** backwards compatibility with v2/3 sdks */
70
+ get token1Price(): Price<Currency, Currency>;
71
+ /**
72
+ * Return the price of the given currency in terms of the other currency in the pool.
73
+ * @param currency The currency to return price of
74
+ * @returns The price of the given currency, in terms of the other.
75
+ */
76
+ priceOf(currency: Currency): Price<Currency, Currency>;
77
+ /**
78
+ * Returns the chain ID of the currencies in the pool.
79
+ */
80
+ get chainId(): number;
81
+ /** Works only for vanilla hookless v3 pools, otherwise throws an error */
82
+ getOutputAmount(inputAmount: CurrencyAmount<Currency>, sqrtPriceLimitX96?: JSBI): Promise<[CurrencyAmount<Currency>, Pool]>;
83
+ /**
84
+ * Given a desired output amount of a currency, return the computed input amount and a pool with state updated after the trade
85
+ * Works only for vanilla hookless v3 pools, otherwise throws an error
86
+ * @param outputAmount the output amount for which to quote the input amount
87
+ * @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
88
+ * @returns The input amount and the pool with updated state
89
+ */
90
+ getInputAmount(outputAmount: CurrencyAmount<Currency>, sqrtPriceLimitX96?: JSBI): Promise<[CurrencyAmount<Currency>, Pool]>;
91
+ /**
92
+ * Executes a swap
93
+ * @param zeroForOne Whether the amount in is token0 or token1
94
+ * @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
95
+ * @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
96
+ * @returns amountCalculated
97
+ * @returns sqrtRatioX96
98
+ * @returns liquidity
99
+ * @returns tickCurrent
100
+ */
101
+ private swap;
102
+ private hookImpactsSwap;
103
+ }
@@ -0,0 +1,144 @@
1
+ import { BigintIsh, Percent, Price, CurrencyAmount, Currency } from '@juiceswapxyz/sdk-core';
2
+ import JSBI from 'jsbi';
3
+ import { Pool } from './pool';
4
+ import { AllowanceTransferPermitBatch } from '../PositionManager';
5
+ interface PositionConstructorArgs {
6
+ pool: Pool;
7
+ liquidity: BigintIsh;
8
+ tickLower: number;
9
+ tickUpper: number;
10
+ }
11
+ /**
12
+ * Represents a position on a Uniswap V4 Pool
13
+ * @dev Similar to the V3 implementation
14
+ * - using Currency instead of Token
15
+ * - keep in mind that Pool and liquidity must be fetched from the pool manager
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
+ private _mintAmounts;
25
+ /**
26
+ * Constructs a position for a given pool with the given liquidity
27
+ * @param pool For which pool the liquidity is assigned
28
+ * @param liquidity The amount of liquidity that is in the position
29
+ * @param tickLower The lower tick of the position
30
+ * @param tickUpper The upper tick of the position
31
+ */
32
+ constructor({ pool, liquidity, tickLower, tickUpper }: PositionConstructorArgs);
33
+ /**
34
+ * Returns the price of token0 at the lower tick
35
+ */
36
+ get token0PriceLower(): Price<Currency, Currency>;
37
+ /**
38
+ * Returns the price of token0 at the upper tick
39
+ */
40
+ get token0PriceUpper(): Price<Currency, Currency>;
41
+ /**
42
+ * Returns the amount of token0 that this position's liquidity could be burned for at the current pool price
43
+ */
44
+ get amount0(): CurrencyAmount<Currency>;
45
+ /**
46
+ * Returns the amount of token1 that this position's liquidity could be burned for at the current pool price
47
+ */
48
+ get amount1(): CurrencyAmount<Currency>;
49
+ /**
50
+ * Returns the lower and upper sqrt ratios if the price 'slips' up to slippage tolerance percentage
51
+ * @param slippageTolerance The amount by which the price can 'slip' before the transaction will revert
52
+ * @returns The sqrt ratios after slippage
53
+ */
54
+ private ratiosAfterSlippage;
55
+ /**
56
+ * Returns the maximum amount of token0 and token1 that must be sent in order to safely mint the amount of liquidity held by the position
57
+ * with the given slippage tolerance
58
+ * @param slippageTolerance Tolerance of unfavorable slippage from the current price
59
+ * @returns The amounts, with slippage
60
+ * @dev In v4, minting and increasing is protected by maximum amounts of token0 and token1.
61
+ */
62
+ mintAmountsWithSlippage(slippageTolerance: Percent): Readonly<{
63
+ amount0: JSBI;
64
+ amount1: JSBI;
65
+ }>;
66
+ /**
67
+ * Returns the minimum amounts that should be requested in order to safely burn the amount of liquidity held by the
68
+ * position with the given slippage tolerance
69
+ * @param slippageTolerance tolerance of unfavorable slippage from the current price
70
+ * @returns The amounts, with slippage
71
+ */
72
+ burnAmountsWithSlippage(slippageTolerance: Percent): Readonly<{
73
+ amount0: JSBI;
74
+ amount1: JSBI;
75
+ }>;
76
+ /**
77
+ * Returns the minimum amounts that must be sent in order to mint the amount of liquidity held by the position at
78
+ * the current price for the pool
79
+ */
80
+ get mintAmounts(): Readonly<{
81
+ amount0: JSBI;
82
+ amount1: JSBI;
83
+ }>;
84
+ /**
85
+ * Returns the AllowanceTransferPermitBatch for adding liquidity to a position
86
+ * @param slippageTolerance The amount by which the price can 'slip' before the transaction will revert
87
+ * @param spender The spender of the permit (should usually be the PositionManager)
88
+ * @param nonce A valid permit2 nonce
89
+ * @param deadline The deadline for the permit
90
+ */
91
+ permitBatchData(slippageTolerance: Percent, spender: string, nonce: BigintIsh, deadline: BigintIsh): AllowanceTransferPermitBatch;
92
+ /**
93
+ * Computes the maximum amount of liquidity received for a given amount of token0, token1,
94
+ * and the prices at the tick boundaries.
95
+ * @param pool The pool for which the position should be created
96
+ * @param tickLower The lower tick of the position
97
+ * @param tickUpper The upper tick of the position
98
+ * @param amount0 token0 amountzw
99
+ * @param amount1 token1 amount
100
+ * @param useFullPrecision If false, liquidity will be maximized according to what the router can calculate,
101
+ * not what core can theoretically support
102
+ * @returns The amount of liquidity for the position
103
+ */
104
+ static fromAmounts({ pool, tickLower, tickUpper, amount0, amount1, useFullPrecision, }: {
105
+ pool: Pool;
106
+ tickLower: number;
107
+ tickUpper: number;
108
+ amount0: BigintIsh;
109
+ amount1: BigintIsh;
110
+ useFullPrecision: boolean;
111
+ }): Position;
112
+ /**
113
+ * Computes a position with the maximum amount of liquidity received for a given amount of token0, assuming an unlimited amount of token1
114
+ * @param pool The pool for which the position is created
115
+ * @param tickLower The lower tick
116
+ * @param tickUpper The upper tick
117
+ * @param amount0 The desired amount of token0
118
+ * @param useFullPrecision If true, liquidity will be maximized according to what the router can calculate,
119
+ * not what core can theoretically support
120
+ * @returns The position
121
+ */
122
+ static fromAmount0({ pool, tickLower, tickUpper, amount0, useFullPrecision, }: {
123
+ pool: Pool;
124
+ tickLower: number;
125
+ tickUpper: number;
126
+ amount0: BigintIsh;
127
+ useFullPrecision: boolean;
128
+ }): Position;
129
+ /**
130
+ * Computes a position with the maximum amount of liquidity received for a given amount of token1, assuming an unlimited amount of token0
131
+ * @param pool The pool for which the position is created
132
+ * @param tickLower The lower tick
133
+ * @param tickUpper The upper tick
134
+ * @param amount1 The desired amount of token1
135
+ * @returns The position
136
+ */
137
+ static fromAmount1({ pool, tickLower, tickUpper, amount1, }: {
138
+ pool: Pool;
139
+ tickLower: number;
140
+ tickUpper: number;
141
+ amount1: BigintIsh;
142
+ }): Position;
143
+ }
144
+ export {};
@@ -0,0 +1,28 @@
1
+ import { Currency, Price } from '@juiceswapxyz/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 currency
6
+ * @template TOutput The output currency
7
+ */
8
+ export declare class Route<TInput extends Currency, TOutput extends Currency> {
9
+ readonly pools: Pool[];
10
+ readonly currencyPath: Currency[];
11
+ readonly input: TInput;
12
+ readonly output: TOutput;
13
+ readonly pathInput: Currency;
14
+ readonly pathOutput: Currency;
15
+ private _midPrice;
16
+ /**
17
+ * Creates an instance of route.
18
+ * @param pools An array of `Pool` objects, ordered by the route the swap will take
19
+ * @param input The input currency
20
+ * @param output The output currency
21
+ */
22
+ constructor(pools: Pool[], input: TInput, output: TOutput);
23
+ get chainId(): number;
24
+ /**
25
+ * Returns the mid price of the route
26
+ */
27
+ get midPrice(): Price<TInput, TOutput>;
28
+ }
@@ -0,0 +1,220 @@
1
+ import { Currency, Percent, Price, CurrencyAmount, TradeType } from '@juiceswapxyz/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 currency, either Ether or an ERC-20
7
+ * @template TOutput The output currency, 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 currency, either Ether or an ERC-20
27
+ * @template TOutput The output currency, 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 currency, either Ether or an ERC-20
91
+ * @template TOutput The output currency, 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 currency, either Ether or an ERC-20
100
+ * @template TOutput The output currency, 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 currency, either Ether or an ERC-20.
109
+ * @template TOutput The output currency, 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 currency, either Ether or an ERC-20.
121
+ * @template TOutput The output currency, 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 currency, either Ether or an ERC-20
135
+ * @template TOutput The output currency, 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 currency, either Ether or an ERC-20
150
+ * @template TOutput The output currency, 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 currency
189
+ * amount to an output currency, 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 currency
206
+ * to an output currency 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
+ }
@@ -0,0 +1,3 @@
1
+ export * from './entities';
2
+ export * from './utils';
3
+ export * from './PositionManager';