@sebtoday/u-exchange-sdk 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +56 -0
- package/dist/constants.d.ts +44 -0
- package/dist/entities/currency.d.ts +24 -0
- package/dist/entities/fractions/currencyAmount.d.ts +19 -0
- package/dist/entities/fractions/fraction.d.ts +19 -0
- package/dist/entities/fractions/index.d.ts +5 -0
- package/dist/entities/fractions/percent.d.ts +6 -0
- package/dist/entities/fractions/price.d.ts +19 -0
- package/dist/entities/fractions/tokenAmount.d.ts +9 -0
- package/dist/entities/index.d.ts +6 -0
- package/dist/entities/pair.d.ts +41 -0
- package/dist/entities/route.d.ts +14 -0
- package/dist/entities/token.d.ts +39 -0
- package/dist/entities/trade.d.ts +106 -0
- package/dist/errors.d.ts +16 -0
- package/dist/fetcher.d.ts +28 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/router.d.ts +63 -0
- package/dist/test/constants.test.d.ts +1 -0
- package/dist/test/data.test.d.ts +1 -0
- package/dist/test/entities.test.d.ts +1 -0
- package/dist/test/fraction.test.d.ts +1 -0
- package/dist/test/miscellaneous.test.d.ts +1 -0
- package/dist/test/pair.test.d.ts +1 -0
- package/dist/test/route.test.d.ts +1 -0
- package/dist/test/router.test.d.ts +1 -0
- package/dist/test/token.test.d.ts +1 -0
- package/dist/test/trade.test.d.ts +1 -0
- package/dist/u-exchange-sdk.cjs.development.js +1630 -0
- package/dist/u-exchange-sdk.cjs.development.js.map +1 -0
- package/dist/u-exchange-sdk.cjs.production.min.js +2 -0
- package/dist/u-exchange-sdk.cjs.production.min.js.map +1 -0
- package/dist/u-exchange-sdk.esm.js +1608 -0
- package/dist/u-exchange-sdk.esm.js.map +1 -0
- package/dist/utils.d.ts +7 -0
- package/package.json +70 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Noah Zinsmeister
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Uniswap SDK
|
2
|
+
|
3
|
+
[](https://github.com/prettier/prettier)
|
4
|
+
[](https://github.com/Uniswap/uniswap-sdk)
|
5
|
+
[](https://www.npmjs.com/package/@uniswap/sdk/v/latest)
|
6
|
+
[](https://bundlephobia.com/result?p=@uniswap/sdk@latest)
|
7
|
+
|
8
|
+
In-depth documentation on this SDK is available at [uniswap.org](https://uniswap.org/docs/v2/SDK/getting-started/).
|
9
|
+
|
10
|
+
## Running tests
|
11
|
+
|
12
|
+
To run the tests, follow these steps. You must have at least node v10 and [yarn](https://yarnpkg.com/) installed.
|
13
|
+
|
14
|
+
First clone the repository:
|
15
|
+
|
16
|
+
```sh
|
17
|
+
git clone https://github.com/Uniswap/uniswap-sdk.git
|
18
|
+
```
|
19
|
+
|
20
|
+
Move into the uniswap-sdk working directory
|
21
|
+
|
22
|
+
```sh
|
23
|
+
cd uniswap-sdk/
|
24
|
+
```
|
25
|
+
|
26
|
+
Install dependencies
|
27
|
+
|
28
|
+
```sh
|
29
|
+
yarn install
|
30
|
+
```
|
31
|
+
|
32
|
+
Run tests
|
33
|
+
|
34
|
+
```sh
|
35
|
+
yarn test
|
36
|
+
```
|
37
|
+
|
38
|
+
You should see output like the following:
|
39
|
+
|
40
|
+
```sh
|
41
|
+
yarn run v1.22.4
|
42
|
+
$ tsdx test
|
43
|
+
PASS test/constants.test.ts
|
44
|
+
PASS test/pair.test.ts
|
45
|
+
PASS test/fraction.test.ts
|
46
|
+
PASS test/miscellaneous.test.ts
|
47
|
+
PASS test/entities.test.ts
|
48
|
+
PASS test/trade.test.ts
|
49
|
+
|
50
|
+
Test Suites: 1 skipped, 6 passed, 6 of 7 total
|
51
|
+
Tests: 3 skipped, 82 passed, 85 total
|
52
|
+
Snapshots: 0 total
|
53
|
+
Time: 5.091s
|
54
|
+
Ran all test suites.
|
55
|
+
✨ Done in 6.61s.
|
56
|
+
```
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import JSBI from 'jsbi';
|
2
|
+
export declare type BigintIsh = JSBI | bigint | string;
|
3
|
+
export declare enum ChainId {
|
4
|
+
MAINNET = 1,
|
5
|
+
ROPSTEN = 3,
|
6
|
+
RINKEBY = 4,
|
7
|
+
GÖRLI = 5,
|
8
|
+
RSK = 30,
|
9
|
+
RSKTEST = 31,
|
10
|
+
KOVAN = 42,
|
11
|
+
BINANCE = 56,
|
12
|
+
BINANCETEST = 97,
|
13
|
+
XDAI = 100,
|
14
|
+
POLYGON = 137
|
15
|
+
}
|
16
|
+
export declare enum TradeType {
|
17
|
+
EXACT_INPUT = 0,
|
18
|
+
EXACT_OUTPUT = 1
|
19
|
+
}
|
20
|
+
export declare enum Rounding {
|
21
|
+
ROUND_DOWN = 0,
|
22
|
+
ROUND_HALF_UP = 1,
|
23
|
+
ROUND_UP = 2
|
24
|
+
}
|
25
|
+
export declare const FACTORY_ADDRESS = "0x063af7b01B067eE135344FEf85d6Aecea14CFA05";
|
26
|
+
export declare const INIT_CODE_HASH = "0x6c0dd0b3d906c70e40fd9e96936f31ff1b70fe5784bae36fcbab40725d974a67";
|
27
|
+
export declare const MINIMUM_LIQUIDITY: JSBI;
|
28
|
+
export declare const ZERO: JSBI;
|
29
|
+
export declare const ONE: JSBI;
|
30
|
+
export declare const TWO: JSBI;
|
31
|
+
export declare const THREE: JSBI;
|
32
|
+
export declare const FIVE: JSBI;
|
33
|
+
export declare const TEN: JSBI;
|
34
|
+
export declare const _100: JSBI;
|
35
|
+
export declare const _997: JSBI;
|
36
|
+
export declare const _1000: JSBI;
|
37
|
+
export declare enum SolidityType {
|
38
|
+
uint8 = "uint8",
|
39
|
+
uint256 = "uint256"
|
40
|
+
}
|
41
|
+
export declare const SOLIDITY_TYPE_MAXIMA: {
|
42
|
+
uint8: JSBI;
|
43
|
+
uint256: JSBI;
|
44
|
+
};
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens.
|
3
|
+
*
|
4
|
+
* The only instance of the base class `Currency` is Ether.
|
5
|
+
*/
|
6
|
+
export declare class Currency {
|
7
|
+
decimals: number;
|
8
|
+
symbol?: string;
|
9
|
+
name?: string;
|
10
|
+
/**
|
11
|
+
* The only instance of the base class `Currency`.
|
12
|
+
*/
|
13
|
+
static ETHER: Currency;
|
14
|
+
/**
|
15
|
+
* Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`.
|
16
|
+
* @param decimals decimals of the currency
|
17
|
+
* @param symbol symbol of the currency
|
18
|
+
* @param name of the currency
|
19
|
+
*/
|
20
|
+
protected constructor(decimals: number, symbol?: string, name?: string);
|
21
|
+
change(cId: number): void;
|
22
|
+
}
|
23
|
+
declare const ETHER: Currency;
|
24
|
+
export { ETHER };
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Currency } from '../currency';
|
2
|
+
import JSBI from 'jsbi';
|
3
|
+
import { BigintIsh, Rounding } from '../../constants';
|
4
|
+
import { Fraction } from './fraction';
|
5
|
+
export declare class CurrencyAmount extends Fraction {
|
6
|
+
readonly currency: Currency;
|
7
|
+
/**
|
8
|
+
* Helper that calls the constructor with the ETHER currency
|
9
|
+
* @param amount ether amount in wei
|
10
|
+
*/
|
11
|
+
static ether(amount: BigintIsh): CurrencyAmount;
|
12
|
+
protected constructor(currency: Currency, amount: BigintIsh);
|
13
|
+
get raw(): JSBI;
|
14
|
+
add(other: CurrencyAmount): CurrencyAmount;
|
15
|
+
subtract(other: CurrencyAmount): CurrencyAmount;
|
16
|
+
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
17
|
+
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
18
|
+
toExact(format?: object): string;
|
19
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import JSBI from 'jsbi';
|
2
|
+
import { BigintIsh, Rounding } from '../../constants';
|
3
|
+
export declare class Fraction {
|
4
|
+
readonly numerator: JSBI;
|
5
|
+
readonly denominator: JSBI;
|
6
|
+
constructor(numerator: BigintIsh, denominator?: BigintIsh);
|
7
|
+
get quotient(): JSBI;
|
8
|
+
get remainder(): Fraction;
|
9
|
+
invert(): Fraction;
|
10
|
+
add(other: Fraction | BigintIsh): Fraction;
|
11
|
+
subtract(other: Fraction | BigintIsh): Fraction;
|
12
|
+
lessThan(other: Fraction | BigintIsh): boolean;
|
13
|
+
equalTo(other: Fraction | BigintIsh): boolean;
|
14
|
+
greaterThan(other: Fraction | BigintIsh): boolean;
|
15
|
+
multiply(other: Fraction | BigintIsh): Fraction;
|
16
|
+
divide(other: Fraction | BigintIsh): Fraction;
|
17
|
+
toSignificant(significantDigits: number, format?: object, rounding?: Rounding): string;
|
18
|
+
toFixed(decimalPlaces: number, format?: object, rounding?: Rounding): string;
|
19
|
+
}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { Rounding } from '../../constants';
|
2
|
+
import { Fraction } from './fraction';
|
3
|
+
export declare class Percent extends Fraction {
|
4
|
+
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
5
|
+
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
6
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { BigintIsh, Rounding } from '../../constants';
|
2
|
+
import { Currency } from '../currency';
|
3
|
+
import { Route } from '../route';
|
4
|
+
import { Fraction } from './fraction';
|
5
|
+
import { CurrencyAmount } from './currencyAmount';
|
6
|
+
export declare class Price extends Fraction {
|
7
|
+
readonly baseCurrency: Currency;
|
8
|
+
readonly quoteCurrency: Currency;
|
9
|
+
readonly scalar: Fraction;
|
10
|
+
static fromRoute(route: Route): Price;
|
11
|
+
constructor(baseCurrency: Currency, quoteCurrency: Currency, denominator: BigintIsh, numerator: BigintIsh);
|
12
|
+
get raw(): Fraction;
|
13
|
+
get adjusted(): Fraction;
|
14
|
+
invert(): Price;
|
15
|
+
multiply(other: Price): Price;
|
16
|
+
quote(currencyAmount: CurrencyAmount): CurrencyAmount;
|
17
|
+
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
|
18
|
+
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
|
19
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { CurrencyAmount } from './currencyAmount';
|
2
|
+
import { Token } from '../token';
|
3
|
+
import { BigintIsh } from '../../constants';
|
4
|
+
export declare class TokenAmount extends CurrencyAmount {
|
5
|
+
readonly token: Token;
|
6
|
+
constructor(token: Token, amount: BigintIsh);
|
7
|
+
add(other: TokenAmount): TokenAmount;
|
8
|
+
subtract(other: TokenAmount): TokenAmount;
|
9
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { Price } from './fractions/price';
|
2
|
+
import { TokenAmount } from './fractions/tokenAmount';
|
3
|
+
import { BigintIsh, ChainId } from '../constants';
|
4
|
+
import { Token } from './token';
|
5
|
+
export declare class Pair {
|
6
|
+
readonly liquidityToken: Token;
|
7
|
+
private readonly tokenAmounts;
|
8
|
+
static getAddress(tokenA: Token, tokenB: Token): string;
|
9
|
+
constructor(tokenAmountA: TokenAmount, tokenAmountB: TokenAmount);
|
10
|
+
/**
|
11
|
+
* Returns true if the token is either token0 or token1
|
12
|
+
* @param token to check
|
13
|
+
*/
|
14
|
+
involvesToken(token: Token): boolean;
|
15
|
+
/**
|
16
|
+
* Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0
|
17
|
+
*/
|
18
|
+
get token0Price(): Price;
|
19
|
+
/**
|
20
|
+
* Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1
|
21
|
+
*/
|
22
|
+
get token1Price(): Price;
|
23
|
+
/**
|
24
|
+
* Return the price of the given token in terms of the other token in the pair.
|
25
|
+
* @param token token to return price of
|
26
|
+
*/
|
27
|
+
priceOf(token: Token): Price;
|
28
|
+
/**
|
29
|
+
* Returns the chain ID of the tokens in the pair.
|
30
|
+
*/
|
31
|
+
get chainId(): ChainId;
|
32
|
+
get token0(): Token;
|
33
|
+
get token1(): Token;
|
34
|
+
get reserve0(): TokenAmount;
|
35
|
+
get reserve1(): TokenAmount;
|
36
|
+
reserveOf(token: Token): TokenAmount;
|
37
|
+
getOutputAmount(inputAmount: TokenAmount): [TokenAmount, Pair];
|
38
|
+
getInputAmount(outputAmount: TokenAmount): [TokenAmount, Pair];
|
39
|
+
getLiquidityMinted(totalSupply: TokenAmount, tokenAmountA: TokenAmount, tokenAmountB: TokenAmount): TokenAmount;
|
40
|
+
getLiquidityValue(token: Token, totalSupply: TokenAmount, liquidity: TokenAmount, feeOn?: boolean, kLast?: BigintIsh): TokenAmount;
|
41
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { ChainId } from '../constants';
|
2
|
+
import { Currency } from './currency';
|
3
|
+
import { Token } from './token';
|
4
|
+
import { Pair } from './pair';
|
5
|
+
import { Price } from './fractions/price';
|
6
|
+
export declare class Route {
|
7
|
+
readonly pairs: Pair[];
|
8
|
+
readonly path: Token[];
|
9
|
+
readonly input: Currency;
|
10
|
+
readonly output: Currency;
|
11
|
+
readonly midPrice: Price;
|
12
|
+
constructor(pairs: Pair[], input: Currency, output?: Currency);
|
13
|
+
get chainId(): ChainId;
|
14
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { ChainId } from '../constants';
|
2
|
+
import { Currency } from './currency';
|
3
|
+
/**
|
4
|
+
* Represents an ERC20 token with a unique address and some metadata.
|
5
|
+
*/
|
6
|
+
export declare class Token extends Currency {
|
7
|
+
readonly chainId: ChainId;
|
8
|
+
readonly address: string;
|
9
|
+
constructor(chainId: ChainId, address: string, decimals: number, symbol?: string, name?: string);
|
10
|
+
/**
|
11
|
+
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
|
12
|
+
* @param other other token to compare
|
13
|
+
*/
|
14
|
+
equals(other: Token): boolean;
|
15
|
+
/**
|
16
|
+
* Returns true if the address of this token sorts before the address of the other token
|
17
|
+
* @param other other token to compare
|
18
|
+
* @throws if the tokens have the same address
|
19
|
+
* @throws if the tokens are on different chains
|
20
|
+
*/
|
21
|
+
sortsBefore(other: Token): boolean;
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* Compares two currencies for equality
|
25
|
+
*/
|
26
|
+
export declare function currencyEquals(currencyA: Currency, currencyB: Currency): boolean;
|
27
|
+
export declare const WETH: {
|
28
|
+
1: Token;
|
29
|
+
3: Token;
|
30
|
+
4: Token;
|
31
|
+
5: Token;
|
32
|
+
42: Token;
|
33
|
+
56: Token;
|
34
|
+
97: Token;
|
35
|
+
30: Token;
|
36
|
+
31: Token;
|
37
|
+
100: Token;
|
38
|
+
137: Token;
|
39
|
+
};
|
@@ -0,0 +1,106 @@
|
|
1
|
+
import { TradeType } from '../constants';
|
2
|
+
import { Currency } from './currency';
|
3
|
+
import { CurrencyAmount } from './fractions/currencyAmount';
|
4
|
+
import { Percent } from './fractions/percent';
|
5
|
+
import { Price } from './fractions/price';
|
6
|
+
import { Pair } from './pair';
|
7
|
+
import { Route } from './route';
|
8
|
+
interface InputOutput {
|
9
|
+
readonly inputAmount: CurrencyAmount;
|
10
|
+
readonly outputAmount: CurrencyAmount;
|
11
|
+
}
|
12
|
+
export declare function inputOutputComparator(a: InputOutput, b: InputOutput): number;
|
13
|
+
export declare function tradeComparator(a: Trade, b: Trade): number;
|
14
|
+
export interface BestTradeOptions {
|
15
|
+
maxNumResults?: number;
|
16
|
+
maxHops?: number;
|
17
|
+
}
|
18
|
+
/**
|
19
|
+
* Represents a trade executed against a list of pairs.
|
20
|
+
* Does not account for slippage, i.e. trades that front run this trade and move the price.
|
21
|
+
*/
|
22
|
+
export declare class Trade {
|
23
|
+
/**
|
24
|
+
* The route of the trade, i.e. which pairs the trade goes through.
|
25
|
+
*/
|
26
|
+
readonly route: Route;
|
27
|
+
/**
|
28
|
+
* The type of the trade, either exact in or exact out.
|
29
|
+
*/
|
30
|
+
readonly tradeType: TradeType;
|
31
|
+
/**
|
32
|
+
* The input amount for the trade assuming no slippage.
|
33
|
+
*/
|
34
|
+
readonly inputAmount: CurrencyAmount;
|
35
|
+
/**
|
36
|
+
* The output amount for the trade assuming no slippage.
|
37
|
+
*/
|
38
|
+
readonly outputAmount: CurrencyAmount;
|
39
|
+
/**
|
40
|
+
* The price expressed in terms of output amount/input amount.
|
41
|
+
*/
|
42
|
+
readonly executionPrice: Price;
|
43
|
+
/**
|
44
|
+
* The mid price after the trade executes assuming no slippage.
|
45
|
+
*/
|
46
|
+
readonly nextMidPrice: Price;
|
47
|
+
/**
|
48
|
+
* The percent difference between the mid price before the trade and the trade execution price.
|
49
|
+
*/
|
50
|
+
readonly priceImpact: Percent;
|
51
|
+
/**
|
52
|
+
* Constructs an exact in trade with the given amount in and route
|
53
|
+
* @param route route of the exact in trade
|
54
|
+
* @param amountIn the amount being passed in
|
55
|
+
*/
|
56
|
+
static exactIn(route: Route, amountIn: CurrencyAmount): Trade;
|
57
|
+
/**
|
58
|
+
* Constructs an exact out trade with the given amount out and route
|
59
|
+
* @param route route of the exact out trade
|
60
|
+
* @param amountOut the amount returned by the trade
|
61
|
+
*/
|
62
|
+
static exactOut(route: Route, amountOut: CurrencyAmount): Trade;
|
63
|
+
constructor(route: Route, amount: CurrencyAmount, tradeType: TradeType);
|
64
|
+
/**
|
65
|
+
* Get the minimum amount that must be received from this trade for the given slippage tolerance
|
66
|
+
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
|
67
|
+
*/
|
68
|
+
minimumAmountOut(slippageTolerance: Percent): CurrencyAmount;
|
69
|
+
/**
|
70
|
+
* Get the maximum amount in that can be spent via this trade for the given slippage tolerance
|
71
|
+
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
|
72
|
+
*/
|
73
|
+
maximumAmountIn(slippageTolerance: Percent): CurrencyAmount;
|
74
|
+
/**
|
75
|
+
* Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
|
76
|
+
* amount to an output token, making at most `maxHops` hops.
|
77
|
+
* Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
|
78
|
+
* the amount in among multiple routes.
|
79
|
+
* @param pairs the pairs to consider in finding the best trade
|
80
|
+
* @param currencyAmountIn exact amount of input currency to spend
|
81
|
+
* @param currencyOut the desired currency out
|
82
|
+
* @param maxNumResults maximum number of results to return
|
83
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
|
84
|
+
* @param currentPairs used in recursion; the current list of pairs
|
85
|
+
* @param originalAmountIn used in recursion; the original value of the currencyAmountIn parameter
|
86
|
+
* @param bestTrades used in recursion; the current list of best trades
|
87
|
+
*/
|
88
|
+
static bestTradeExactIn(pairs: Pair[], currencyAmountIn: CurrencyAmount, currencyOut: Currency, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], originalAmountIn?: CurrencyAmount, bestTrades?: Trade[]): Trade[];
|
89
|
+
/**
|
90
|
+
* similar to the above method but instead targets a fixed output amount
|
91
|
+
* given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token
|
92
|
+
* to an output token amount, making at most `maxHops` hops
|
93
|
+
* note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
|
94
|
+
* the amount in among multiple routes.
|
95
|
+
* @param pairs the pairs to consider in finding the best trade
|
96
|
+
* @param currencyIn the currency to spend
|
97
|
+
* @param currencyAmountOut the exact amount of currency out
|
98
|
+
* @param maxNumResults maximum number of results to return
|
99
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
|
100
|
+
* @param currentPairs used in recursion; the current list of pairs
|
101
|
+
* @param originalAmountOut used in recursion; the original value of the currencyAmountOut parameter
|
102
|
+
* @param bestTrades used in recursion; the current list of best trades
|
103
|
+
*/
|
104
|
+
static bestTradeExactOut(pairs: Pair[], currencyIn: Currency, currencyAmountOut: CurrencyAmount, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], originalAmountOut?: CurrencyAmount, bestTrades?: Trade[]): Trade[];
|
105
|
+
}
|
106
|
+
export {};
|
package/dist/errors.d.ts
ADDED
@@ -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,28 @@
|
|
1
|
+
import { Pair } from './entities/pair';
|
2
|
+
import { ChainId } from './constants';
|
3
|
+
import { Token } from './entities/token';
|
4
|
+
/**
|
5
|
+
* Contains methods for constructing instances of pairs and tokens from on-chain data.
|
6
|
+
*/
|
7
|
+
export declare abstract class Fetcher {
|
8
|
+
/**
|
9
|
+
* Cannot be constructed.
|
10
|
+
*/
|
11
|
+
private constructor();
|
12
|
+
/**
|
13
|
+
* Fetch information for a given token on the given chain, using the given ethers provider.
|
14
|
+
* @param chainId chain of the token
|
15
|
+
* @param address address of the token on the chain
|
16
|
+
* @param provider provider used to fetch the token
|
17
|
+
* @param symbol optional symbol of the token
|
18
|
+
* @param name optional name of the token
|
19
|
+
*/
|
20
|
+
static fetchTokenData(chainId: ChainId, address: string, provider?: import("@ethersproject/providers").BaseProvider, symbol?: string, name?: string): Promise<Token>;
|
21
|
+
/**
|
22
|
+
* Fetches information about a pair and constructs a pair from the given two tokens.
|
23
|
+
* @param tokenA first token
|
24
|
+
* @param tokenB second token
|
25
|
+
* @param provider the provider to use to fetch the data
|
26
|
+
*/
|
27
|
+
static fetchPairData(tokenA: Token, tokenB: Token, provider?: import("@ethersproject/providers").BaseProvider): Promise<Pair>;
|
28
|
+
}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
import JSBI from 'jsbi';
|
2
|
+
export { JSBI };
|
3
|
+
export { BigintIsh, ChainId, TradeType, Rounding, FACTORY_ADDRESS, INIT_CODE_HASH, MINIMUM_LIQUIDITY } from './constants';
|
4
|
+
export * from './errors';
|
5
|
+
export * from './entities';
|
6
|
+
export * from './router';
|
7
|
+
export * from './fetcher';
|
package/dist/index.js
ADDED
package/dist/router.d.ts
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
import { Percent, Trade } from './entities';
|
2
|
+
/**
|
3
|
+
* Options for producing the arguments to send call to the router.
|
4
|
+
*/
|
5
|
+
export interface TradeOptions {
|
6
|
+
/**
|
7
|
+
* How much the execution price is allowed to move unfavorably from the trade execution price.
|
8
|
+
*/
|
9
|
+
allowedSlippage: Percent;
|
10
|
+
/**
|
11
|
+
* How long the swap is valid until it expires, in seconds.
|
12
|
+
* This will be used to produce a `deadline` parameter which is computed from when the swap call parameters
|
13
|
+
* are generated.
|
14
|
+
*/
|
15
|
+
ttl: number;
|
16
|
+
/**
|
17
|
+
* The account that should receive the output of the swap.
|
18
|
+
*/
|
19
|
+
recipient: string;
|
20
|
+
/**
|
21
|
+
* Whether any of the tokens in the path are fee on transfer tokens, which should be handled with special methods
|
22
|
+
*/
|
23
|
+
feeOnTransfer?: boolean;
|
24
|
+
}
|
25
|
+
export interface TradeOptionsDeadline extends Omit<TradeOptions, 'ttl'> {
|
26
|
+
/**
|
27
|
+
* When the transaction expires.
|
28
|
+
* This is an atlernate to specifying the ttl, for when you do not want to use local time.
|
29
|
+
*/
|
30
|
+
deadline: number;
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* The parameters to use in the call to the Uniswap V2 Router to execute a trade.
|
34
|
+
*/
|
35
|
+
export interface SwapParameters {
|
36
|
+
/**
|
37
|
+
* The method to call on the Uniswap V2 Router.
|
38
|
+
*/
|
39
|
+
methodName: string;
|
40
|
+
/**
|
41
|
+
* The arguments to pass to the method, all hex encoded.
|
42
|
+
*/
|
43
|
+
args: (string | string[])[];
|
44
|
+
/**
|
45
|
+
* The amount of wei to send in hex.
|
46
|
+
*/
|
47
|
+
value: string;
|
48
|
+
}
|
49
|
+
/**
|
50
|
+
* Represents the Uniswap V2 Router, and has static methods for helping execute trades.
|
51
|
+
*/
|
52
|
+
export declare abstract class Router {
|
53
|
+
/**
|
54
|
+
* Cannot be constructed.
|
55
|
+
*/
|
56
|
+
private constructor();
|
57
|
+
/**
|
58
|
+
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
59
|
+
* @param trade to produce call parameters for
|
60
|
+
* @param options options for the call parameters
|
61
|
+
*/
|
62
|
+
static swapCallParameters(trade: Trade, options: TradeOptions | TradeOptionsDeadline): SwapParameters;
|
63
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|