@alcorexchange/alcor-swap-sdk 1.0.392 → 1.0.393

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 (40) 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 +5 -0
  22. package/build/utils/encodeSqrtRatioX64.d.ts +9 -0
  23. package/build/utils/fullMath.d.ts +8 -0
  24. package/build/utils/getBestSwapRoute.d.ts +9 -0
  25. package/build/utils/index.d.ts +17 -0
  26. package/build/utils/isSorted.d.ts +7 -0
  27. package/build/utils/liquidityMath.d.ts +8 -0
  28. package/build/utils/maxLiquidityForAmounts.d.ts +14 -0
  29. package/build/utils/mostSignificantBit.d.ts +2 -0
  30. package/build/utils/nearestUsableTick.d.ts +6 -0
  31. package/build/utils/positionLibrary.d.ts +8 -0
  32. package/build/utils/priceTickConversions.d.ts +16 -0
  33. package/build/utils/sortedInsert.d.ts +1 -0
  34. package/build/utils/sqrt.d.ts +7 -0
  35. package/build/utils/sqrtPriceMath.d.ts +13 -0
  36. package/build/utils/swapMath.d.ts +9 -0
  37. package/build/utils/tickLibrary.d.ts +15 -0
  38. package/build/utils/tickList.d.ts +23 -0
  39. package/build/utils/tickMath.d.ts +30 -0
  40. package/package.json +2 -2
@@ -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
+ }
@@ -0,0 +1,198 @@
1
+ import { Currency } from './currency';
2
+ import { Percent, Price, CurrencyAmount } from './fractions';
3
+ import { TradeType } from '../internalConstants';
4
+ import { Route } from './route';
5
+ /**
6
+ * Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them
7
+ * @template TInput The input token, either Ether or an ERC-20
8
+ * @template TOutput The output token, either Ether or an ERC-20
9
+ * @template TTradeType The trade type, either exact input or exact output
10
+ * @param a The first trade to compare
11
+ * @param b The second trade to compare
12
+ * @returns A sorted ordering for two neighboring elements in a trade array
13
+ */
14
+ export declare function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(a: Trade<TInput, TOutput, TTradeType>, b: Trade<TInput, TOutput, TTradeType>): number;
15
+ export interface BestTradeOptions {
16
+ maxNumResults?: number;
17
+ maxHops?: number;
18
+ }
19
+ /**
20
+ * Represents a trade executed against a set of routes where some percentage of the input is
21
+ * split across each route.
22
+ *
23
+ * Each route has its own set of pools. Pools can not be re-used across routes.
24
+ *
25
+ * Does not account for slippage, i.e., changes in price environment that can occur between
26
+ * the time the trade is submitted and when it is executed.
27
+ * @template TInput The input token, either Ether or an ERC-20
28
+ * @template TOutput The output token, either Ether or an ERC-20
29
+ * @template TTradeType The trade type, either exact input or exact output
30
+ */
31
+ export declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {
32
+ /**
33
+ * @deprecated Deprecated in favor of 'swaps' property. If the trade consists of multiple routes
34
+ * this will return an error.
35
+ *
36
+ * When the trade consists of just a single route, this returns the route of the trade,
37
+ * i.e. which pools the trade goes through.
38
+ */
39
+ get route(): Route<TInput, TOutput>;
40
+ /**
41
+ * The swaps of the trade, i.e. which routes and how much is swapped in each that
42
+ * make up the trade.
43
+ */
44
+ readonly swaps: {
45
+ percent: number;
46
+ route: Route<TInput, TOutput>;
47
+ inputAmount: CurrencyAmount<TInput>;
48
+ outputAmount: CurrencyAmount<TOutput>;
49
+ }[];
50
+ /**
51
+ * The type of the trade, either exact in or exact out.
52
+ */
53
+ readonly tradeType: TTradeType;
54
+ /**
55
+ * The cached result of the input amount computation
56
+ * @private
57
+ */
58
+ private _inputAmount;
59
+ /**
60
+ * The input amount for the trade assuming no slippage.
61
+ */
62
+ get inputAmount(): CurrencyAmount<TInput>;
63
+ /**
64
+ * The cached result of the output amount computation
65
+ * @private
66
+ */
67
+ private _outputAmount;
68
+ /**
69
+ * The output amount for the trade assuming no slippage.
70
+ */
71
+ get outputAmount(): CurrencyAmount<TOutput>;
72
+ /**
73
+ * The cached result of the computed execution price
74
+ * @private
75
+ */
76
+ private _executionPrice;
77
+ /**
78
+ * The price expressed in terms of output amount/input amount.
79
+ */
80
+ get executionPrice(): Price<TInput, TOutput>;
81
+ /**
82
+ * The cached result of the price impact computation
83
+ * @private
84
+ */
85
+ private _priceImpact;
86
+ /**
87
+ * Returns the percent difference between the route's mid price and the price impact
88
+ */
89
+ get priceImpact(): Percent;
90
+ /**
91
+ * Constructs an exact in trade with the given amount in and route
92
+ * @template TInput The input token, either Ether or an ERC-20
93
+ * @template TOutput The output token, either Ether or an ERC-20
94
+ * @param route The route of the exact in trade
95
+ * @param amountIn The amount being passed in
96
+ * @returns The exact in trade
97
+ */
98
+ static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Trade<TInput, TOutput, TradeType.EXACT_INPUT>;
99
+ /**
100
+ * Constructs an exact out trade with the given amount out and route
101
+ * @template TInput The input token, either Ether or an ERC-20
102
+ * @template TOutput The output token, either Ether or an ERC-20
103
+ * @param route The route of the exact out trade
104
+ * @param amountOut The amount returned by the trade
105
+ * @returns The exact out trade
106
+ */
107
+ static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>;
108
+ /**
109
+ * Constructs a trade by simulating swaps through the given route
110
+ * @template TInput The input token, either Ether or an ERC-20.
111
+ * @template TOutput The output token, either Ether or an ERC-20.
112
+ * @template TTradeType The type of the trade, either exact in or exact out.
113
+ * @param route route to swap through
114
+ * @param amount the amount specified, either input or output, depending on tradeType
115
+ * @param tradeType whether the trade is an exact input or exact output swap
116
+ * @returns The route
117
+ */
118
+ 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, percent?: number): Trade<TInput, TOutput, TTradeType>;
119
+ /**
120
+ * Constructs a trade from routes by simulating swaps
121
+ *
122
+ * @template TInput The input token, either Ether or an ERC-20.
123
+ * @template TOutput The output token, either Ether or an ERC-20.
124
+ * @template TTradeType The type of the trade, either exact in or exact out.
125
+ * @param routes the routes to swap through and how much of the amount should be routed through each
126
+ * @param tradeType whether the trade is an exact input or exact output swap
127
+ * @returns The trade
128
+ */
129
+ static fromRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(routes: {
130
+ amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
131
+ route: Route<TInput, TOutput>;
132
+ percent: number;
133
+ }[], tradeType: TTradeType): Trade<TInput, TOutput, TTradeType>;
134
+ /**
135
+ * Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade
136
+ * elsewhere and do not have any tick data
137
+ * @template TInput The input token, either Ether or an ERC-20
138
+ * @template TOutput The output token, either Ether or an ERC-20
139
+ * @template TTradeType The type of the trade, either exact in or exact out
140
+ * @param constructorArguments The arguments passed to the trade constructor
141
+ * @returns The unchecked trade
142
+ */
143
+ static createUncheckedTrade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(constructorArguments: {
144
+ percent: number;
145
+ route: Route<TInput, TOutput>;
146
+ inputAmount: CurrencyAmount<TInput>;
147
+ outputAmount: CurrencyAmount<TOutput>;
148
+ tradeType: TTradeType;
149
+ }): Trade<TInput, TOutput, TTradeType>;
150
+ /**
151
+ * Creates a trade without computing the result of swapping through the routes. Useful when you have simulated the trade
152
+ * elsewhere and do not have any tick data
153
+ * @template TInput The input token, either Ether or an ERC-20
154
+ * @template TOutput The output token, either Ether or an ERC-20
155
+ * @template TTradeType The type of the trade, either exact in or exact out
156
+ * @param constructorArguments The arguments passed to the trade constructor
157
+ * @returns The unchecked trade
158
+ */
159
+ static createUncheckedTradeWithMultipleRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(constructorArguments: {
160
+ routes: {
161
+ percent: number;
162
+ route: Route<TInput, TOutput>;
163
+ inputAmount: CurrencyAmount<TInput>;
164
+ outputAmount: CurrencyAmount<TOutput>;
165
+ }[];
166
+ tradeType: TTradeType;
167
+ }): Trade<TInput, TOutput, TTradeType>;
168
+ /**
169
+ * Construct a trade by passing in the pre-computed property values
170
+ * @param routes The routes through which the trade occurs
171
+ * @param tradeType The type of trade, exact input or exact output
172
+ */
173
+ private constructor();
174
+ /**
175
+ * Get the minimum amount that must be received from this trade for the given slippage tolerance
176
+ * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
177
+ * @returns The amount out
178
+ */
179
+ minimumAmountOut(slippageTolerance: Percent, amountOut?: CurrencyAmount<TOutput>): CurrencyAmount<TOutput>;
180
+ /**
181
+ * Get the maximum amount in that can be spent via this trade for the given slippage tolerance
182
+ * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
183
+ * @returns The amount in
184
+ */
185
+ maximumAmountIn(slippageTolerance: Percent, amountIn?: CurrencyAmount<TInput>): CurrencyAmount<TInput>;
186
+ /**
187
+ * Return the execution price after accounting for slippage tolerance
188
+ * @param slippageTolerance the allowed tolerated slippage
189
+ * @returns The execution price
190
+ */
191
+ worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>;
192
+ static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(routes: Route<TInput, TOutput>[], currencyAmountIn: CurrencyAmount<TInput>, maxNumResults?: number): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[];
193
+ static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(routes: Route<TInput, TOutput>[], currencyAmountOut: CurrencyAmount<TOutput>, maxNumResults?: number): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[];
194
+ static bestTradeWithSplit<TInput extends Currency, TOutput extends Currency>(_routes: Route<TInput, TOutput>[], amount: CurrencyAmount<Currency>, percents: number[], tradeType: TradeType, swapConfig?: {
195
+ minSplits: number;
196
+ maxSplits: number;
197
+ }): Trade<Currency, Currency, TradeType> | null;
198
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be
3
+ * obtained by sending any amount of input.
4
+ */
5
+ export declare class InsufficientReservesError extends Error {
6
+ readonly isInsufficientReservesError = true;
7
+ constructor();
8
+ }
9
+ /**
10
+ * Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less
11
+ * than the price of a single unit of output after fees.
12
+ */
13
+ export declare class InsufficientInputAmountError extends Error {
14
+ readonly isInsufficientInputAmountError = true;
15
+ constructor();
16
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./utils";
2
+ export * from "./entities";
3
+ export * from "./internalConstants";
@@ -0,0 +1,37 @@
1
+ import JSBI from "jsbi";
2
+ export declare const NEGATIVE_ONE: JSBI;
3
+ export declare const ZERO: JSBI;
4
+ export declare const ONE: JSBI;
5
+ export declare const Q32: JSBI;
6
+ export declare const Q64: JSBI;
7
+ export declare const Q96: JSBI;
8
+ export declare const Q128: JSBI;
9
+ export declare const Q192: JSBI;
10
+ export declare const Q256: JSBI;
11
+ export declare const MaxUint256: JSBI;
12
+ export declare const MaxUint128: JSBI;
13
+ export declare const MaxUint64: JSBI;
14
+ export type BigintIsh = JSBI | string | number;
15
+ export declare enum TradeType {
16
+ EXACT_INPUT = 0,
17
+ EXACT_OUTPUT = 1
18
+ }
19
+ /**
20
+ * The default factory enabled fee amounts, denominated in hundredths of bips.
21
+ */
22
+ export declare enum FeeAmount {
23
+ LOW = 500,
24
+ MEDIUM = 3000,
25
+ HIGH = 10000
26
+ }
27
+ export declare enum Rounding {
28
+ ROUND_DOWN = 0,
29
+ ROUND_HALF_UP = 1,
30
+ ROUND_UP = 2
31
+ }
32
+ /**
33
+ * The default factory tick spacings by fee amount.
34
+ */
35
+ export declare const TICK_SPACINGS: {
36
+ [amount in FeeAmount]: number;
37
+ };
@@ -0,0 +1,14 @@
1
+ export declare function parseTrade(trade: any): {
2
+ route: never[];
3
+ memo: string;
4
+ swaps: any;
5
+ input: any;
6
+ output: any;
7
+ minReceived: any;
8
+ maxSent: any;
9
+ priceImpact: any;
10
+ executionPrice: {
11
+ numerator: any;
12
+ denominator: any;
13
+ };
14
+ };
@@ -0,0 +1,5 @@
1
+ import { Token, Pool, Route } from '../entities';
2
+ export declare function computeAllRoutes(tokenIn: Token, tokenOut: Token, pools: Pool[], maxHops: number): Route<Token, Token>[];
3
+ export declare function computeAllRoutesFromMap(tokenIn: Token, tokenOut: Token, poolMap: {
4
+ [tokenId: string]: Pool[];
5
+ }, maxHops: number): Route<Token, Token>[];
@@ -0,0 +1,9 @@
1
+ import JSBI from "jsbi";
2
+ import { BigintIsh } from "../internalConstants";
3
+ /**
4
+ * Returns the sqrt ratio as a Q64.64 corresponding to a given ratio of amountB and amountA
5
+ * @param amountB The numerator amount i.e., the amount of tokenB
6
+ * @param amountA The denominator amount i.e., the amount of tokenA
7
+ * @returns The sqrt ratio
8
+ */
9
+ export declare function encodeSqrtRatioX64(amountB: BigintIsh, amountA: BigintIsh): JSBI;
@@ -0,0 +1,8 @@
1
+ import JSBI from "jsbi";
2
+ export declare abstract class FullMath {
3
+ /**
4
+ * Cannot be constructed.
5
+ */
6
+ private constructor();
7
+ static mulDivRoundingUp(a: JSBI, b: JSBI, denominator: JSBI): JSBI;
8
+ }
@@ -0,0 +1,9 @@
1
+ import { Currency } from '../entities/currency';
2
+ import { Trade } from '../entities/trade';
3
+ import { TradeType } from '../internalConstants';
4
+ export declare function getBestSwapRoute(routeType: TradeType, percentToQuotes: {
5
+ [percent: number]: Trade<Currency, Currency, TradeType>[];
6
+ }, percents: number[], swapRouteConfig?: {
7
+ minSplits: number;
8
+ maxSplits: number;
9
+ }): Trade<Currency, Currency, TradeType>[] | null;
@@ -0,0 +1,17 @@
1
+ export * from "./tickMath";
2
+ export * from "./mostSignificantBit";
3
+ export * from "./tickLibrary";
4
+ export * from "./positionLibrary";
5
+ export * from "./sqrt";
6
+ export * from "./encodeSqrtRatioX64";
7
+ export * from "./maxLiquidityForAmounts";
8
+ export * from "./nearestUsableTick";
9
+ export * from "./fullMath";
10
+ export * from "./isSorted";
11
+ export * from "./tickList";
12
+ export * from "./priceTickConversions";
13
+ export * from "./sqrtPriceMath";
14
+ export * from "./sortedInsert";
15
+ export * from "./computeAllRoutes";
16
+ export * from "./common";
17
+ export * from "./getBestSwapRoute";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Determines if a tick list is sorted
3
+ * @param list The tick list
4
+ * @param comparator The comparator
5
+ * @returns true if sorted
6
+ */
7
+ export declare function isSorted<T>(list: Array<T>, comparator: (a: T, b: T) => number): boolean;
@@ -0,0 +1,8 @@
1
+ import JSBI from "jsbi";
2
+ export declare abstract class LiquidityMath {
3
+ /**
4
+ * Cannot be constructed.
5
+ */
6
+ private constructor();
7
+ static addDelta(x: JSBI, y: JSBI): JSBI;
8
+ }
@@ -0,0 +1,14 @@
1
+ import JSBI from "jsbi";
2
+ import { BigintIsh } from "../internalConstants";
3
+ /**
4
+ * Computes the maximum amount of liquidity received for a given amount of token0, token1,
5
+ * and the prices at the tick boundaries.
6
+ * @param sqrtRatioCurrentX64 the current price
7
+ * @param sqrtRatioLX64 price at lower boundary
8
+ * @param sqrtRatioUX64 price at upper boundary
9
+ * @param amountA token0 amount
10
+ * @param amountB token1 amount
11
+ * @param useFullPrecision if false, liquidity will be maximized according to what the router can calculate,
12
+ * not what core can theoretically support
13
+ */
14
+ export declare function maxLiquidityForAmounts(sqrtRatioCurrentX64: JSBI, sqrtRatioLX64: JSBI, sqrtRatioUX64: JSBI, amountA: BigintIsh, amountB: BigintIsh, useFullPrecision: boolean): JSBI;
@@ -0,0 +1,2 @@
1
+ import JSBI from "jsbi";
2
+ export declare function mostSignificantBit(x: JSBI): number;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns the closest tick that is nearest a given tick and usable for the given tick spacing
3
+ * @param tick the target tick
4
+ * @param tickSpacing the spacing of the pool
5
+ */
6
+ export declare function nearestUsableTick(tick: number, tickSpacing: number): number;
@@ -0,0 +1,8 @@
1
+ import JSBI from "jsbi";
2
+ export declare abstract class PositionLibrary {
3
+ /**
4
+ * Cannot be constructed.
5
+ */
6
+ private constructor();
7
+ static getTokensOwed(feeGrowthInsideALastX64: JSBI, feeGrowthInsideBLastX64: JSBI, liquidity: JSBI, feeGrowthInsideAX64: JSBI, feeGrowthInsideBX64: JSBI): JSBI[];
8
+ }
@@ -0,0 +1,16 @@
1
+ import { Token } from "../entities/token";
2
+ import { Price } from "../entities/fractions/price";
3
+ /**
4
+ * Returns a price object corresponding to the input tick and the base/quote token
5
+ * Inputs must be tokens because the address order is used to interpret the price represented by the tick
6
+ * @param baseToken the base token of the price
7
+ * @param quoteToken the quote token of the price
8
+ * @param tick the tick for which to return the price
9
+ */
10
+ export declare function tickToPrice(baseToken: Token, quoteToken: Token, tick: number): Price<Token, Token>;
11
+ /**
12
+ * Returns the first tick for which the given price is greater than or equal to the tick price
13
+ * @param price for which to return the closest tick that represents a price less than or equal to the input price,
14
+ * i.e. the price of the returned tick is less than or equal to the input price
15
+ */
16
+ export declare function priceToClosestTick(price: Price<Token, Token>): number;
@@ -0,0 +1 @@
1
+ export declare function sortedInsert<T>(items: T[], add: T, maxSize: number, comparator: (a: T, b: T) => number): T | null;
@@ -0,0 +1,7 @@
1
+ import JSBI from "jsbi";
2
+ export declare const MAX_SAFE_INTEGER: JSBI;
3
+ /**
4
+ * Computes floor(sqrt(value))
5
+ * @param value the value for which to compute the square root, rounded down
6
+ */
7
+ export declare function sqrt(value: JSBI): JSBI;
@@ -0,0 +1,13 @@
1
+ import JSBI from "jsbi";
2
+ export declare abstract class SqrtPriceMath {
3
+ /**
4
+ * Cannot be constructed.
5
+ */
6
+ private constructor();
7
+ static getAmountADelta(sqrtRatioLX64: JSBI, sqrtRatioUX64: JSBI, liquidity: JSBI, roundUp: boolean): JSBI;
8
+ static getAmountBDelta(sqrtRatioLX64: JSBI, sqrtRatioUX64: JSBI, liquidity: JSBI, roundUp: boolean): JSBI;
9
+ static getNextSqrtPriceFromInput(sqrtPX64: JSBI, liquidity: JSBI, amountIn: JSBI, zeroForOne: boolean): JSBI;
10
+ static getNextSqrtPriceFromOutput(sqrtPX64: JSBI, liquidity: JSBI, amountOut: JSBI, zeroForOne: boolean): JSBI;
11
+ private static getNextSqrtPriceFromAmountARoundingUp;
12
+ private static getNextSqrtPriceFromAmountBRoundingDown;
13
+ }
@@ -0,0 +1,9 @@
1
+ import JSBI from "jsbi";
2
+ import { FeeAmount } from "../internalConstants";
3
+ export declare abstract class SwapMath {
4
+ /**
5
+ * Cannot be constructed.
6
+ */
7
+ private constructor();
8
+ static computeSwapStep(sqrtRatioCurrentX64: JSBI, sqrtRatioTargetX64: JSBI, liquidity: JSBI, amountRemaining: JSBI, feePips: FeeAmount): [JSBI, JSBI, JSBI, JSBI];
9
+ }
@@ -0,0 +1,15 @@
1
+ import JSBI from "jsbi";
2
+ interface FeeGrowthOutside {
3
+ feeGrowthOutsideAX64: JSBI;
4
+ feeGrowthOutsideBX64: JSBI;
5
+ }
6
+ export declare function subIn256(x: JSBI, y: JSBI): JSBI;
7
+ export declare function subIn128(x: JSBI, y: JSBI): JSBI;
8
+ export declare abstract class TickLibrary {
9
+ /**
10
+ * Cannot be constructed.
11
+ */
12
+ private constructor();
13
+ static getFeeGrowthInside(feeGrowthOutsideLower: FeeGrowthOutside, feeGrowthOutsideUpper: FeeGrowthOutside, tickLower: number, tickUpper: number, tickCurrent: number, feeGrowthGlobalAX64: JSBI, feeGrowthGlobalBX64: JSBI): JSBI[];
14
+ }
15
+ export {};
@@ -0,0 +1,23 @@
1
+ import { Tick } from "../entities/tick";
2
+ /**x
3
+ * Utility methods for interacting with sorted lists of ticks
4
+ */
5
+ export declare abstract class TickList {
6
+ /**
7
+ * Cannot be constructed
8
+ */
9
+ private constructor();
10
+ static validateList(ticks: Tick[], tickSpacing: number): void;
11
+ static isBelowSmallest(ticks: readonly Tick[], tick: number): boolean;
12
+ static isAtOrAboveLargest(ticks: readonly Tick[], tick: number): boolean;
13
+ static getTick(ticks: readonly Tick[], id: number): Tick;
14
+ /**
15
+ * Finds the largest tick in the list of ticks that is less than or equal to tick
16
+ * @param ticks list of ticks
17
+ * @param tick tick to find the largest tick that is less than or equal to tick
18
+ * @private
19
+ */
20
+ private static binarySearch;
21
+ static nextInitializedTick(ticks: readonly Tick[], tick: number, lte: boolean): Tick;
22
+ static nextInitializedTickWithinOneWord(ticks: readonly Tick[], tick: number, lte: boolean, tickSpacing: number): [number, boolean];
23
+ }
@@ -0,0 +1,30 @@
1
+ import JSBI from "jsbi";
2
+ export declare abstract class TickMath {
3
+ /**
4
+ * The minimum tick that can be used on any pool.
5
+ */
6
+ static MIN_TICK: number;
7
+ /**
8
+ * The maximum tick that can be used on any pool.
9
+ */
10
+ static MAX_TICK: number;
11
+ /**
12
+ * The sqrt ratio corresponding to the minimum tick that could be used on any pool.
13
+ */
14
+ static MIN_SQRT_RATIO: JSBI;
15
+ /**
16
+ * The sqrt ratio corresponding to the maximum tick that could be used on any pool.
17
+ */
18
+ static MAX_SQRT_RATIO: JSBI;
19
+ /**
20
+ * Returns the sqrt ratio as a Q64.96 for the given tick. The sqrt ratio is computed as sqrt(1.0001)^tick
21
+ * @param tick the tick for which to compute the sqrt ratio
22
+ */
23
+ static getSqrtRatioAtTick(tick: number): JSBI;
24
+ /**
25
+ * Returns the tick corresponding to a given sqrt ratio, s.t. #getSqrtRatioAtTick(tick) <= sqrtRatioX64
26
+ * and #getSqrtRatioAtTick(tick + 1) > sqrtRatioX64
27
+ * @param sqrtRatioX64 the sqrt ratio as a Q64.96 for which to compute the tick
28
+ */
29
+ static getTickAtSqrtRatio(sqrtRatioX64: JSBI): number;
30
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@alcorexchange/alcor-swap-sdk",
3
- "version": "1.0.392",
3
+ "version": "1.0.393",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
7
7
  "start:dev": "npx nodemon",
8
- "build": "rimraf ./build && babel src --out-dir build --extensions \".ts\"",
8
+ "build": "rimraf ./build && babel src --out-dir build --extensions \".ts\" && tsc --emitDeclarationOnly",
9
9
  "start": "npm run build && node build/index.js",
10
10
  "lint": "eslint . --ext .ts",
11
11
  "prettier": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",