@alcorexchange/alcor-swap-sdk 1.0.392 → 1.0.394

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.
Files changed (42) hide show
  1. package/build/entities/baseCurrency.d.ts +32 -0
  2. package/build/entities/currency.d.ts +2 -0
  3. package/build/entities/fractions/currencyAmount.d.ts +38 -0
  4. package/build/entities/fractions/fraction.d.ts +24 -0
  5. package/build/entities/fractions/index.d.ts +4 -0
  6. package/build/entities/fractions/percent.d.ts +14 -0
  7. package/build/entities/fractions/price.d.ts +40 -0
  8. package/build/entities/index.d.ts +10 -0
  9. package/build/entities/pool.d.ts +118 -0
  10. package/build/entities/position.d.ts +170 -0
  11. package/build/entities/route.d.ts +47 -0
  12. package/build/entities/tick.d.ts +25 -0
  13. package/build/entities/tickDataProvider.d.ts +27 -0
  14. package/build/entities/tickListDataProvider.d.ts +13 -0
  15. package/build/entities/token.d.ts +30 -0
  16. package/build/entities/trade.d.ts +198 -0
  17. package/build/errors.d.ts +16 -0
  18. package/build/index.d.ts +3 -0
  19. package/build/internalConstants.d.ts +37 -0
  20. package/build/utils/common.d.ts +14 -0
  21. package/build/utils/computeAllRoutes.d.ts +6 -0
  22. package/build/utils/computeAllRoutes.js +59 -0
  23. package/build/utils/encodeSqrtRatioX64.d.ts +9 -0
  24. package/build/utils/fullMath.d.ts +8 -0
  25. package/build/utils/getBestSwapRoute.d.ts +9 -0
  26. package/build/utils/index.d.ts +17 -0
  27. package/build/utils/isSorted.d.ts +7 -0
  28. package/build/utils/liquidityMath.d.ts +8 -0
  29. package/build/utils/maxLiquidityForAmounts.d.ts +14 -0
  30. package/build/utils/mostSignificantBit.d.ts +2 -0
  31. package/build/utils/nearestUsableTick.d.ts +6 -0
  32. package/build/utils/positionLibrary.d.ts +8 -0
  33. package/build/utils/priceTickConversions.d.ts +16 -0
  34. package/build/utils/sortedInsert.d.ts +1 -0
  35. package/build/utils/sqrt.d.ts +7 -0
  36. package/build/utils/sqrtPriceMath.d.ts +13 -0
  37. package/build/utils/swapMath.d.ts +9 -0
  38. package/build/utils/tickLibrary.d.ts +15 -0
  39. package/build/utils/tickList.d.ts +23 -0
  40. package/build/utils/tickMath.d.ts +30 -0
  41. package/package.json +2 -2
  42. package/src/utils/computeAllRoutes.ts +69 -0
@@ -0,0 +1,32 @@
1
+ import { Currency } from "./currency";
2
+ /**
3
+ * A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
4
+ */
5
+ export declare abstract class BaseCurrency {
6
+ /**
7
+ * The contract address of the currency
8
+ */
9
+ readonly contract: string;
10
+ /**
11
+ * The decimals used in representing currency amounts
12
+ */
13
+ readonly decimals: number;
14
+ /**
15
+ * The symbol of the currency, i.e. a short textual non-unique identifier
16
+ */
17
+ readonly symbol: string;
18
+ readonly id: string;
19
+ /**
20
+ * Constructs an instance of the base class `BaseCurrency`.
21
+ * @param chainId the chain ID on which this currency resides
22
+ * @param decimals decimals of the currency
23
+ * @param symbol symbol of the currency
24
+ * @param name of the currency
25
+ */
26
+ protected constructor(contract: string, decimals: number, symbol: string);
27
+ /**
28
+ * Returns whether this currency is functionally equivalent to the other currency
29
+ * @param other the other currency
30
+ */
31
+ abstract equals(other: Currency): boolean;
32
+ }
@@ -0,0 +1,2 @@
1
+ import { Token } from "./token";
2
+ export type Currency = Token;
@@ -0,0 +1,38 @@
1
+ /// <reference types="node" />
2
+ import JSBI from "jsbi";
3
+ import { Currency } from "../currency";
4
+ import { Token } from "../token";
5
+ import { Fraction } from "./fraction";
6
+ import { BigintIsh, Rounding } from "../../internalConstants";
7
+ export declare class CurrencyAmount<T extends Currency> extends Fraction {
8
+ readonly currency: T;
9
+ readonly decimalScale: JSBI;
10
+ /**
11
+ * Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
12
+ * @param currency the currency in the amount
13
+ * @param rawAmount the raw token or ether amount
14
+ */
15
+ static fromRawAmount<T extends Currency>(currency: T, rawAmount: BigintIsh): CurrencyAmount<T>;
16
+ /**
17
+ * Construct a currency amount with a denominator that is not equal to 1
18
+ * @param currency the currency
19
+ * @param numerator the numerator of the fractional token amount
20
+ * @param denominator the denominator of the fractional token amount
21
+ */
22
+ static fromFractionalAmount<T extends Currency>(currency: T, numerator: BigintIsh, denominator: BigintIsh): CurrencyAmount<T>;
23
+ protected constructor(currency: T, numerator: BigintIsh, denominator?: BigintIsh);
24
+ add(other: CurrencyAmount<T>): CurrencyAmount<T>;
25
+ subtract(other: CurrencyAmount<T>): CurrencyAmount<T>;
26
+ multiply(other: Fraction | BigintIsh): CurrencyAmount<T>;
27
+ divide(other: Fraction | BigintIsh): CurrencyAmount<T>;
28
+ toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
29
+ toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
30
+ toExact(format?: object): string;
31
+ toAsset(...args: any[]): string;
32
+ toExtendedAsset(...args: any[]): string;
33
+ toExtendedAssetObject(...args: any[]): object;
34
+ static toJSON<T extends Currency>(amount: CurrencyAmount<T>): object;
35
+ static fromJSON(json: any): CurrencyAmount<Token>;
36
+ static toBuffer<T extends Currency>(amount: CurrencyAmount<T>): object;
37
+ static fromBuffer(buffer: Buffer): CurrencyAmount<Token>;
38
+ }
@@ -0,0 +1,24 @@
1
+ import JSBI from "jsbi";
2
+ import { BigintIsh, Rounding } from "../../internalConstants";
3
+ export declare class Fraction {
4
+ readonly numerator: JSBI;
5
+ readonly denominator: JSBI;
6
+ constructor(numerator: BigintIsh, denominator?: BigintIsh);
7
+ private static tryParseFraction;
8
+ get quotient(): JSBI;
9
+ get remainder(): Fraction;
10
+ invert(): Fraction;
11
+ add(other: Fraction | BigintIsh): Fraction;
12
+ subtract(other: Fraction | BigintIsh): Fraction;
13
+ lessThan(other: Fraction | BigintIsh): boolean;
14
+ equalTo(other: Fraction | BigintIsh): boolean;
15
+ greaterThan(other: Fraction | BigintIsh): boolean;
16
+ multiply(other: Fraction | BigintIsh): Fraction;
17
+ divide(other: Fraction | BigintIsh): Fraction;
18
+ toSignificant(significantDigits: number, format?: object, rounding?: Rounding): string;
19
+ toFixed(decimalPlaces: number, format?: object, rounding?: Rounding): string;
20
+ /**
21
+ * Helper method for converting any super class back to a fraction
22
+ */
23
+ get asFraction(): Fraction;
24
+ }
@@ -0,0 +1,4 @@
1
+ export { CurrencyAmount } from "./currencyAmount";
2
+ export { Fraction } from "./fraction";
3
+ export { Percent } from "./percent";
4
+ export { Price } from "./price";
@@ -0,0 +1,14 @@
1
+ import { BigintIsh, Rounding } from "../../internalConstants";
2
+ import { Fraction } from "./fraction";
3
+ export declare class Percent extends Fraction {
4
+ /**
5
+ * This boolean prevents a fraction from being interpreted as a Percent
6
+ */
7
+ readonly isPercent: true;
8
+ add(other: Fraction | BigintIsh): Percent;
9
+ subtract(other: Fraction | BigintIsh): Percent;
10
+ multiply(other: Fraction | BigintIsh): Percent;
11
+ divide(other: Fraction | BigintIsh): Percent;
12
+ toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
13
+ toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
14
+ }
@@ -0,0 +1,40 @@
1
+ import { BigintIsh, Rounding } from "../../internalConstants";
2
+ import { Currency } from "../currency";
3
+ import { Fraction } from "./fraction";
4
+ import { CurrencyAmount } from "./currencyAmount";
5
+ export declare class Price<TBase extends Currency, TQuote extends Currency> extends Fraction {
6
+ readonly baseCurrency: TBase;
7
+ readonly quoteCurrency: TQuote;
8
+ readonly scalar: Fraction;
9
+ /**
10
+ * Construct a price, either with the base and quote currency amount, or the
11
+ * @param args
12
+ */
13
+ constructor(...args: [TBase, TQuote, BigintIsh, BigintIsh] | [
14
+ {
15
+ baseAmount: CurrencyAmount<TBase>;
16
+ quoteAmount: CurrencyAmount<TQuote>;
17
+ }
18
+ ]);
19
+ /**
20
+ * Flip the price, switching the base and quote currency
21
+ */
22
+ invert(): Price<TQuote, TBase>;
23
+ /**
24
+ * Multiply the price by another price, returning a new price. The other price must have the same base currency as this price's quote currency
25
+ * @param other the other price
26
+ */
27
+ multiply<TOtherQuote extends Currency>(other: Price<TQuote, TOtherQuote>): Price<TBase, TOtherQuote>;
28
+ /**
29
+ * Return the amount of quote currency corresponding to a given amount of the base currency
30
+ * @param currencyAmount the amount of base currency to quote against the price
31
+ */
32
+ quote(currencyAmount: CurrencyAmount<TBase>): CurrencyAmount<TQuote>;
33
+ /**
34
+ * Get the value scaled by decimals for formatting
35
+ * @private
36
+ */
37
+ private get adjustedForDecimals();
38
+ toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
39
+ toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
40
+ }
@@ -0,0 +1,10 @@
1
+ export * from "./fractions";
2
+ export * from "./tick";
3
+ export * from "./tickDataProvider";
4
+ export * from "./tickListDataProvider";
5
+ export * from "./currency";
6
+ export * from "./token";
7
+ export * from "./pool";
8
+ export * from "./position";
9
+ export * from "./route";
10
+ export * from "./trade";
@@ -0,0 +1,118 @@
1
+ /// <reference types="node" />
2
+ import { CurrencyAmount, Price } from "./fractions";
3
+ import { Token } from "./token";
4
+ import { BigintIsh, FeeAmount } from "../internalConstants";
5
+ import JSBI from "jsbi";
6
+ import { Tick, TickConstructorArgs } from "./tick";
7
+ import { TickDataProvider } from "./tickDataProvider";
8
+ export interface PoolConstructorArgs {
9
+ id: number;
10
+ active: boolean;
11
+ tokenA: Token;
12
+ tokenB: Token;
13
+ fee: FeeAmount;
14
+ sqrtPriceX64: BigintIsh;
15
+ liquidity: BigintIsh;
16
+ tickCurrent: number;
17
+ feeGrowthGlobalAX64: BigintIsh;
18
+ feeGrowthGlobalBX64: BigintIsh;
19
+ ticks: TickDataProvider | (Tick | TickConstructorArgs)[];
20
+ }
21
+ /**
22
+ * Represents a V3 pool
23
+ */
24
+ export declare class Pool {
25
+ readonly id: number;
26
+ readonly active: boolean;
27
+ readonly tokenA: Token;
28
+ readonly tokenB: Token;
29
+ readonly fee: FeeAmount;
30
+ readonly sqrtPriceX64: JSBI;
31
+ readonly liquidity: JSBI;
32
+ readonly tickCurrent: number;
33
+ readonly feeGrowthGlobalAX64: JSBI;
34
+ readonly feeGrowthGlobalBX64: JSBI;
35
+ readonly tickDataProvider: TickDataProvider;
36
+ json?: any;
37
+ buffer?: Buffer;
38
+ bufferHash?: string;
39
+ static hashToPoolMap: Map<string, Pool>;
40
+ static idToPoolMap: Map<number, Pool>;
41
+ private _tokenAPrice?;
42
+ private _tokenBPrice?;
43
+ /**
44
+ * Construct a pool
45
+ * @param tokenA One of the tokens in the pool
46
+ * @param tokenB The other token in the pool
47
+ * @param fee The fee in hundredths of a bips of the input amount of every swap that is collected by the pool
48
+ * @param sqrtPriceX64 The sqrt of the current ratio of amounts of tokenB to tokenA
49
+ * @param liquidity The current value of in range liquidity
50
+ * @param tickCurrent The current tick of the pool
51
+ * @param ticks The current state of the pool ticks or a data provider that can return tick data
52
+ */
53
+ constructor({ id, active, tokenA, tokenB, fee, sqrtPriceX64, liquidity, tickCurrent, ticks, feeGrowthGlobalAX64, feeGrowthGlobalBX64, }: PoolConstructorArgs);
54
+ /**
55
+ * Returns true if the token is either tokenA or tokenB
56
+ * @param token The token to check
57
+ * @returns True if token is either tokenA or token
58
+ */
59
+ involvesToken(token: Token): boolean;
60
+ /**
61
+ * Returns the current mid price of the pool in terms of tokenA, i.e. the ratio of tokenB over tokenA
62
+ */
63
+ get tokenAPrice(): Price<Token, Token>;
64
+ /**
65
+ * Returns the current mid price of the pool in terms of tokenB, i.e. the ratio of tokenA over tokenB
66
+ */
67
+ get tokenBPrice(): Price<Token, Token>;
68
+ /**
69
+ * Return the price of the given token in terms of the other token in the pool.
70
+ * @param token The token to return price of
71
+ * @returns The price of the given token, in terms of the other.
72
+ */
73
+ priceOf(token: Token): Price<Token, Token>;
74
+ /**
75
+ * Given an input amount of a token, return the computed output amount, and a pool with state updated after the trade
76
+ * @param inputAmount The input amount for which to quote the output amount
77
+ * @param sqrtPriceLimitX64 The Q64.96 sqrt price limit
78
+ * @returns The output amount and the pool with updated state
79
+ */
80
+ getOutputAmount(inputAmount: CurrencyAmount<Token>, sqrtPriceLimitX64?: JSBI): CurrencyAmount<Token>;
81
+ /**
82
+ * Given a desired output amount of a token, return the computed input amount and a pool with state updated after the trade
83
+ * @param outputAmount the output amount for which to quote the input amount
84
+ * @param sqrtPriceLimitX64 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
85
+ * @returns The input amount and the pool with updated state
86
+ */
87
+ getInputAmount(outputAmount: CurrencyAmount<Token>, sqrtPriceLimitX64?: JSBI): CurrencyAmount<Token>;
88
+ /**
89
+ * Executes a swap
90
+ * @param zeroForOne Whether the amount in is tokenA or tokenB
91
+ * @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
92
+ * @param sqrtPriceLimitX64 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
93
+ * @returns amountCalculated
94
+ * @returns sqrtPriceX64
95
+ * @returns liquidity
96
+ * @returns tickCurrent
97
+ */
98
+ private swap;
99
+ get tickSpacing(): number;
100
+ static toJSON(pool: Pool): object;
101
+ static fromJSON(json: any): Pool;
102
+ /**
103
+ * Converts the pool to a Buffer using msgpack encoding.
104
+ * @param {Pool} pool - The pool instance to convert.
105
+ * @returns {Buffer} The encoded buffer.
106
+ */
107
+ static toBuffer(pool: Pool): Buffer;
108
+ /**
109
+ * Creates a Pool instance from a Buffer or serialized data.
110
+ * @param {Buffer | any} data - The buffer or serialized data.
111
+ * @returns {Pool} The pool instance.
112
+ */
113
+ static fromBuffer(data: Buffer | any): Pool;
114
+ static fromId(id: number): Pool;
115
+ static createHash(buffer: Buffer, pool?: Pool): string;
116
+ static hashEquals(pool: Pool, hash: string): boolean;
117
+ equals(other: Pool): boolean;
118
+ }
@@ -0,0 +1,170 @@
1
+ import { CurrencyAmount, Price, Percent } from "./fractions";
2
+ import { Token } from "./token";
3
+ import { BigintIsh } from "../internalConstants";
4
+ import JSBI from "jsbi";
5
+ import { Pool } from "./pool";
6
+ interface PositionConstructorArgs {
7
+ id: number;
8
+ owner: string;
9
+ pool: Pool;
10
+ tickLower: number;
11
+ tickUpper: number;
12
+ liquidity: BigintIsh;
13
+ feeGrowthInsideALastX64: BigintIsh;
14
+ feeGrowthInsideBLastX64: BigintIsh;
15
+ feesA: BigintIsh;
16
+ feesB: BigintIsh;
17
+ }
18
+ interface Fees {
19
+ feesA: CurrencyAmount<Token>;
20
+ feesB: CurrencyAmount<Token>;
21
+ }
22
+ export declare class Position {
23
+ readonly id: number;
24
+ readonly owner: string;
25
+ readonly pool: Pool;
26
+ readonly tickLower: number;
27
+ readonly tickUpper: number;
28
+ readonly liquidity: JSBI;
29
+ readonly feesA: JSBI;
30
+ readonly feesB: JSBI;
31
+ readonly feeGrowthInsideALastX64: JSBI;
32
+ readonly feeGrowthInsideBLastX64: JSBI;
33
+ private _tokenAAmount;
34
+ private _tokenBAmount;
35
+ private _mintAmounts;
36
+ /**
37
+ * Constructs a position for a given pool with the given liquidity
38
+ * @param pool For which pool the liquidity is assigned
39
+ * @param liquidity The amount of liquidity that is in the position
40
+ * @param lower The lower tick of the position
41
+ * @param upper The upper tick of the position
42
+ */
43
+ constructor({ id, owner, pool, liquidity, tickLower, tickUpper, feeGrowthInsideALastX64, feeGrowthInsideBLastX64, feesA, feesB, }: PositionConstructorArgs);
44
+ get inRange(): boolean;
45
+ /**
46
+ * Returns the price of tokenA at the lower tick
47
+ */
48
+ get tokenAPriceLower(): Price<Token, Token>;
49
+ /**
50
+ * Returns the price of tokenA at the upper tick
51
+ */
52
+ get tokenAPriceUpper(): Price<Token, Token>;
53
+ /**
54
+ * Returns the amount of tokenA that this position's liquidity could be burned for at the current pool price
55
+ */
56
+ get amountA(): CurrencyAmount<Token>;
57
+ /**
58
+ * Returns the amount of tokenB that this position's liquidity could be burned for at the current pool price
59
+ */
60
+ get amountB(): CurrencyAmount<Token>;
61
+ /**
62
+ * Returns the lower and upper sqrt ratios if the price 'slips' up to slippage tolerance percentage
63
+ * @param slippageTolerance The amount by which the price can 'slip' before the transaction will revert
64
+ * @returns The sqrt ratios after slippage
65
+ */
66
+ private ratiosAfterSlippage;
67
+ /**
68
+ * Returns the minimum amounts that must be sent in order to safely mint the amount of liquidity held by the position
69
+ * with the given slippage tolerance
70
+ * @param slippageTolerance Tolerance of unfavorable slippage from the current price
71
+ * @returns The amounts, with slippage
72
+ */
73
+ mintAmountsWithSlippage(slippageTolerance: Percent): Readonly<{
74
+ amountA: JSBI;
75
+ amountB: JSBI;
76
+ }>;
77
+ /**
78
+ * Returns the minimum amounts that should be requested in order to safely burn the amount of liquidity held by the
79
+ * position with the given slippage tolerance
80
+ * @param slippageTolerance tolerance of unfavorable slippage from the current price
81
+ * @returns The amounts, with slippage
82
+ */
83
+ burnAmountsWithSlippage(slippageTolerance: Percent): Readonly<{
84
+ amountA: CurrencyAmount<Token>;
85
+ amountB: CurrencyAmount<Token>;
86
+ }>;
87
+ /**
88
+ * Returns the minimum amounts that must be sent in order to mint the amount of liquidity held by the position at
89
+ * the current price for the pool
90
+ */
91
+ get mintAmounts(): Readonly<{
92
+ amountA: JSBI;
93
+ amountB: JSBI;
94
+ }>;
95
+ /**
96
+ * Computes the maximum amount of liquidity received for a given amount of tokenA, tokenB,
97
+ * and the prices at the tick boundaries.
98
+ * @param pool The pool for which the position should be created
99
+ * @param lower The lower tick of the position
100
+ * @param upper The upper tick of the position
101
+ * @param amountA tokenA amount
102
+ * @param amountB tokenB amount
103
+ * @param useFullPrecision If false, liquidity will be maximized according to what the router can calculate,
104
+ * not what core can theoretically support
105
+ * @returns The amount of liquidity for the position
106
+ */
107
+ static fromAmounts({ id, owner, pool, tickLower, tickUpper, amountA, amountB, useFullPrecision, feeGrowthInsideALastX64, feeGrowthInsideBLastX64, feesA, feesB }: {
108
+ id: number;
109
+ owner: string;
110
+ pool: Pool;
111
+ tickLower: number;
112
+ tickUpper: number;
113
+ amountA: BigintIsh;
114
+ amountB: BigintIsh;
115
+ useFullPrecision: boolean;
116
+ feeGrowthInsideALastX64: BigintIsh;
117
+ feeGrowthInsideBLastX64: BigintIsh;
118
+ feesA: BigintIsh;
119
+ feesB: BigintIsh;
120
+ }): Position;
121
+ /**
122
+ * Computes a position with the maximum amount of liquidity received for a given amount of tokenA, assuming an unlimited amount of tokenB
123
+ * @param pool The pool for which the position is created
124
+ * @param lower The lower tick
125
+ * @param upper The upper tick
126
+ * @param amountA The desired amount of tokenA
127
+ * @param useFullPrecision If true, liquidity will be maximized according to what the router can calculate,
128
+ * not what core can theoretically support
129
+ * @returns The position
130
+ */
131
+ static fromAmountA({ id, owner, pool, tickLower, tickUpper, amountA, useFullPrecision, feeGrowthInsideALastX64, feeGrowthInsideBLastX64, feesA, feesB }: {
132
+ id: number;
133
+ owner: string;
134
+ pool: Pool;
135
+ tickLower: number;
136
+ tickUpper: number;
137
+ amountA: BigintIsh;
138
+ useFullPrecision: boolean;
139
+ feeGrowthInsideALastX64: BigintIsh;
140
+ feeGrowthInsideBLastX64: BigintIsh;
141
+ feesA: BigintIsh;
142
+ feesB: BigintIsh;
143
+ }): Position;
144
+ /**
145
+ * Computes a position with the maximum amount of liquidity received for a given amount of tokenB, assuming an unlimited amount of tokenA
146
+ * @param pool The pool for which the position is created
147
+ * @param lower The lower tick
148
+ * @param upper The upper tick
149
+ * @param amountB The desired amount of tokenB
150
+ * @returns The position
151
+ */
152
+ static fromAmountB({ id, owner, pool, tickLower, tickUpper, amountB, feeGrowthInsideALastX64, feeGrowthInsideBLastX64, feesA, feesB }: {
153
+ id: number;
154
+ owner: string;
155
+ pool: Pool;
156
+ tickLower: number;
157
+ tickUpper: number;
158
+ amountB: BigintIsh;
159
+ feeGrowthInsideALastX64: BigintIsh;
160
+ feeGrowthInsideBLastX64: BigintIsh;
161
+ feesA: BigintIsh;
162
+ feesB: BigintIsh;
163
+ }): Position;
164
+ /**
165
+ * Computes a position fees
166
+ * @returns The position
167
+ */
168
+ getFees(): Promise<Fees>;
169
+ }
170
+ export {};
@@ -0,0 +1,47 @@
1
+ /// <reference types="node" />
2
+ import { Currency } from './currency';
3
+ import { Price } from './fractions';
4
+ import { Token } from './token';
5
+ import { Pool } from './pool';
6
+ /**
7
+ * Represents a list of pools through which a swap can occur
8
+ * @template TInput The input token
9
+ * @template TOutput The output token
10
+ */
11
+ export declare class Route<TInput extends Currency, TOutput extends Currency> {
12
+ readonly pools: Pool[];
13
+ readonly tokenPath: Token[];
14
+ readonly input: TInput;
15
+ readonly output: TOutput;
16
+ private _midPrice;
17
+ /**
18
+ * Creates an instance of route.
19
+ * @param pools An array of `Pool` objects, ordered by the route the swap will take
20
+ * @param input The input token
21
+ * @param output The output token
22
+ */
23
+ constructor(pools: Pool[], input: TInput, output: TOutput);
24
+ /**
25
+ * Returns the mid price of the route
26
+ */
27
+ get midPrice(): Price<TInput, TOutput>;
28
+ static toJSON(route: Route<Currency, Currency>, lightWeightVersion?: boolean): {
29
+ pools: (number | Buffer)[];
30
+ input: {
31
+ contract: string;
32
+ decimals: number;
33
+ symbol: string;
34
+ };
35
+ output: {
36
+ contract: string;
37
+ decimals: number;
38
+ symbol: string;
39
+ };
40
+ _midPrice: Price<Token, Token> | null;
41
+ };
42
+ static fromJSON(json: any): Route<Token, Token>;
43
+ static toBuffer(route: Route<Currency, Currency>, lightWeightVersion?: boolean): any;
44
+ static fromBuffer(buffer: Buffer): Route<Token, Token>;
45
+ static toBufferAdvanced(route: Route<Currency, Currency>, pools: any[]): any;
46
+ equals(other: Route<Currency, Currency>): boolean;
47
+ }
@@ -0,0 +1,25 @@
1
+ import JSBI from "jsbi";
2
+ import { BigintIsh } from "../internalConstants";
3
+ export interface TickConstructorArgs {
4
+ id: number;
5
+ liquidityGross: BigintIsh;
6
+ liquidityNet: BigintIsh;
7
+ feeGrowthOutsideAX64: BigintIsh;
8
+ feeGrowthOutsideBX64: BigintIsh;
9
+ tickCumulativeOutside: BigintIsh;
10
+ secondsPerLiquidityOutsideX64: BigintIsh;
11
+ secondsOutside: BigintIsh;
12
+ }
13
+ export declare class Tick {
14
+ readonly id: number;
15
+ readonly liquidityGross: JSBI;
16
+ readonly liquidityNet: JSBI;
17
+ readonly feeGrowthOutsideAX64: JSBI;
18
+ readonly feeGrowthOutsideBX64: JSBI;
19
+ readonly tickCumulativeOutside: JSBI;
20
+ readonly secondsOutside: JSBI;
21
+ readonly secondsPerLiquidityOutsideX64: JSBI;
22
+ constructor({ id, liquidityGross, liquidityNet, feeGrowthOutsideAX64, feeGrowthOutsideBX64, tickCumulativeOutside, secondsOutside, secondsPerLiquidityOutsideX64, }: TickConstructorArgs);
23
+ static toJSON(tick: Tick): object;
24
+ static fromJSON(json: any): Tick;
25
+ }
@@ -0,0 +1,27 @@
1
+ import { Tick } from "./tick";
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): Tick;
11
+ /**
12
+ * Return the next tick that is initialized within a single word
13
+ * @param tick The current tick
14
+ * @param lte Whether the next tick should be lte the current tick
15
+ * @param tickSpacing The tick spacing of the pool
16
+ */
17
+ nextInitializedTickWithinOneWord(tick: number, lte: boolean, tickSpacing: number): [number, boolean];
18
+ }
19
+ /**
20
+ * This tick data provider does not know how to fetch any tick data. It throws whenever it is required. Useful if you
21
+ * do not need to load tick data for your use case.
22
+ */
23
+ export declare class NoTickDataProvider implements TickDataProvider {
24
+ private static ERROR_MESSAGE;
25
+ getTick(_tick: number): Tick;
26
+ nextInitializedTickWithinOneWord(_tick: number, _lte: boolean, _tickSpacing: number): [number, boolean];
27
+ }
@@ -0,0 +1,13 @@
1
+ import { Tick, TickConstructorArgs } from "./tick";
2
+ import { TickDataProvider } from "./tickDataProvider";
3
+ /**
4
+ * A data provider for ticks that is backed by an in-memory array of ticks.
5
+ */
6
+ export declare class TickListDataProvider implements TickDataProvider {
7
+ ticks: readonly Tick[];
8
+ constructor(ticks: (Tick | TickConstructorArgs)[], tickSpacing: number);
9
+ getTick(tick: number): Tick;
10
+ nextInitializedTickWithinOneWord(tick: number, lte: boolean, tickSpacing: number): [number, boolean];
11
+ static toJSON(ticks: Tick[]): object;
12
+ static fromJSON(ticksArray: any): TickListDataProvider;
13
+ }
@@ -0,0 +1,30 @@
1
+ import { BaseCurrency } from "./baseCurrency";
2
+ /**
3
+ * Represents an ERC20 token with a unique address and some metadata.
4
+ */
5
+ export declare class Token extends BaseCurrency {
6
+ /**
7
+ * @param contract {@link BaseCurrency#contract}
8
+ * @param decimals {@link BaseCurrency#decimals}
9
+ * @param symbol {@link BaseCurrency#symbol}
10
+ */
11
+ constructor(contract: string, decimals: number, symbol: string);
12
+ get name(): string;
13
+ /**
14
+ * Returns true if the two tokens are equivalent, i.e. have the same contract and symbol.
15
+ * @param other other token to compare
16
+ */
17
+ equals(other: Token): boolean;
18
+ /**
19
+ * Returns true if the address of this token sorts before the address of the other token
20
+ * @param other other token to compare
21
+ * @throws if the tokens have the same contract and symbol
22
+ */
23
+ sortsBefore(other: Token): boolean;
24
+ static toJSON(token: Token): {
25
+ contract: string;
26
+ decimals: number;
27
+ symbol: string;
28
+ };
29
+ static fromJSON(json: any): Token;
30
+ }