@pancakeswap/sdk 3.2.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/constants.d.ts +32 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/entities/index.d.ts +6 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/native.d.ts +18 -0
- package/dist/entities/native.d.ts.map +1 -0
- package/dist/entities/pair.d.ts +45 -0
- package/dist/entities/pair.d.ts.map +1 -0
- package/dist/entities/route.d.ts +13 -0
- package/dist/entities/route.d.ts.map +1 -0
- package/dist/entities/token.d.ts +13 -0
- package/dist/entities/token.d.ts.map +1 -0
- package/dist/entities/trade.d.ts +104 -0
- package/dist/entities/trade.d.ts.map +1 -0
- package/dist/ether.d.ts +12 -0
- package/dist/ether.d.ts.map +1 -0
- package/dist/fetcher.d.ts +29 -0
- package/dist/fetcher.d.ts.map +1 -0
- package/dist/index.d.ts +8 -281
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +829 -37
- package/dist/index.mjs +830 -35
- package/dist/router.d.ts +61 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/trade.d.ts +5 -0
- package/dist/trade.d.ts.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +11 -14
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ You can refer to the Uniswap SDK documentation [uniswap.org](https://docs.uniswa
|
|
|
6
6
|
|
|
7
7
|
## Running tests
|
|
8
8
|
|
|
9
|
-
To run the tests, follow these steps. You must have at least node v10 and [
|
|
9
|
+
To run the tests, follow these steps. You must have at least node v10 and [pnpm](https://pnpm.io) installed.
|
|
10
10
|
|
|
11
11
|
First clone the repository:
|
|
12
12
|
|
|
@@ -23,19 +23,19 @@ cd pancakeswap-sdk/
|
|
|
23
23
|
Install dependencies
|
|
24
24
|
|
|
25
25
|
```sh
|
|
26
|
-
|
|
26
|
+
pnpm install
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
Run tests
|
|
30
30
|
|
|
31
31
|
```sh
|
|
32
|
-
|
|
32
|
+
pnpm test
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
You should see output like the following:
|
|
36
36
|
|
|
37
37
|
```sh
|
|
38
|
-
|
|
38
|
+
pnpm run v1.22.4
|
|
39
39
|
$ tsdx test
|
|
40
40
|
PASS test/constants.test.ts
|
|
41
41
|
PASS test/pair.test.ts
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Percent } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
import { ERC20Token } from './entities/token';
|
|
3
|
+
export declare enum ChainId {
|
|
4
|
+
ETHEREUM = 1,
|
|
5
|
+
GOERLI = 5,
|
|
6
|
+
BSC = 56,
|
|
7
|
+
BSC_TESTNET = 97
|
|
8
|
+
}
|
|
9
|
+
export declare const ZERO_PERCENT: Percent;
|
|
10
|
+
export declare const ONE_HUNDRED_PERCENT: Percent;
|
|
11
|
+
export declare const FACTORY_ADDRESS = "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73";
|
|
12
|
+
export declare const FACTORY_ADDRESS_MAP: Record<number, string>;
|
|
13
|
+
export declare const INIT_CODE_HASH = "0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5";
|
|
14
|
+
export declare const INIT_CODE_HASH_MAP: Record<number, string>;
|
|
15
|
+
export declare const WETH9: {
|
|
16
|
+
1: ERC20Token;
|
|
17
|
+
5: ERC20Token;
|
|
18
|
+
56: ERC20Token;
|
|
19
|
+
97: ERC20Token;
|
|
20
|
+
};
|
|
21
|
+
export declare const WBNB: {
|
|
22
|
+
1: ERC20Token;
|
|
23
|
+
56: ERC20Token;
|
|
24
|
+
97: ERC20Token;
|
|
25
|
+
};
|
|
26
|
+
export declare const WNATIVE: Record<number, ERC20Token>;
|
|
27
|
+
export declare const NATIVE: Record<number, {
|
|
28
|
+
name: string;
|
|
29
|
+
symbol: string;
|
|
30
|
+
decimals: number;
|
|
31
|
+
}>;
|
|
32
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,oBAAY,OAAO;IACjB,QAAQ,IAAI;IACZ,MAAM,IAAI;IACV,GAAG,KAAK;IACR,WAAW,KAAK;CACjB;AAED,eAAO,MAAM,YAAY,SAAmB,CAAA;AAC5C,eAAO,MAAM,mBAAmB,SAAmB,CAAA;AAEnD,eAAO,MAAM,eAAe,+CAA+C,CAAA;AAI3E,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKtD,CAAA;AACD,eAAO,MAAM,cAAc,uEAAuE,CAAA;AAGlG,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKrD,CAAA;AAED,eAAO,MAAM,KAAK;;;;;CAiCjB,CAAA;AAED,eAAO,MAAM,IAAI;;;;CAyBhB,CAAA;AAED,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAK9C,CAAA;AAED,eAAO,MAAM,MAAM,EAAE,MAAM,CACzB,MAAM,EACN;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB,CAcF,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/entities/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Currency, Token, NativeCurrency } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* Native is the main usage of a 'native' currency, i.e. for BSC mainnet and all testnets
|
|
5
|
+
*/
|
|
6
|
+
export declare class Native extends NativeCurrency {
|
|
7
|
+
protected constructor({ chainId, decimals, name, symbol, }: {
|
|
8
|
+
chainId: number;
|
|
9
|
+
decimals: number;
|
|
10
|
+
symbol: string;
|
|
11
|
+
name: string;
|
|
12
|
+
});
|
|
13
|
+
get wrapped(): Token;
|
|
14
|
+
private static cache;
|
|
15
|
+
static onChain(chainId: number): Native;
|
|
16
|
+
equals(other: Currency): boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../src/entities/native.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAG5E;;;GAGG;AACH,qBAAa,MAAO,SAAQ,cAAc;IACxC,SAAS,aAAa,EACpB,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,GACP,EAAE;QACD,OAAO,EAAE,MAAM,CAAA;QACf,QAAQ,EAAE,MAAM,CAAA;QAChB,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;KACb;IAID,IAAW,OAAO,IAAI,KAAK,CAI1B;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAoC;WAE1C,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IASvC,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;CAGxC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CurrencyAmount, Price, BigintIsh } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
import { ERC20Token } from './token';
|
|
3
|
+
export declare const computePairAddress: ({ factoryAddress, tokenA, tokenB, }: {
|
|
4
|
+
factoryAddress: string;
|
|
5
|
+
tokenA: ERC20Token;
|
|
6
|
+
tokenB: ERC20Token;
|
|
7
|
+
}) => string;
|
|
8
|
+
export declare class Pair {
|
|
9
|
+
readonly liquidityToken: ERC20Token;
|
|
10
|
+
private readonly tokenAmounts;
|
|
11
|
+
static getAddress(tokenA: ERC20Token, tokenB: ERC20Token): string;
|
|
12
|
+
constructor(currencyAmountA: CurrencyAmount<ERC20Token>, tokenAmountB: CurrencyAmount<ERC20Token>);
|
|
13
|
+
/**
|
|
14
|
+
* Returns true if the token is either token0 or token1
|
|
15
|
+
* @param token to check
|
|
16
|
+
*/
|
|
17
|
+
involvesToken(token: ERC20Token): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0
|
|
20
|
+
*/
|
|
21
|
+
get token0Price(): Price<ERC20Token, ERC20Token>;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1
|
|
24
|
+
*/
|
|
25
|
+
get token1Price(): Price<ERC20Token, ERC20Token>;
|
|
26
|
+
/**
|
|
27
|
+
* Return the price of the given token in terms of the other token in the pair.
|
|
28
|
+
* @param token token to return price of
|
|
29
|
+
*/
|
|
30
|
+
priceOf(token: ERC20Token): Price<ERC20Token, ERC20Token>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the chain ID of the tokens in the pair.
|
|
33
|
+
*/
|
|
34
|
+
get chainId(): number;
|
|
35
|
+
get token0(): ERC20Token;
|
|
36
|
+
get token1(): ERC20Token;
|
|
37
|
+
get reserve0(): CurrencyAmount<ERC20Token>;
|
|
38
|
+
get reserve1(): CurrencyAmount<ERC20Token>;
|
|
39
|
+
reserveOf(token: ERC20Token): CurrencyAmount<ERC20Token>;
|
|
40
|
+
getOutputAmount(inputAmount: CurrencyAmount<ERC20Token>): [CurrencyAmount<ERC20Token>, Pair];
|
|
41
|
+
getInputAmount(outputAmount: CurrencyAmount<ERC20Token>): [CurrencyAmount<ERC20Token>, Pair];
|
|
42
|
+
getLiquidityMinted(totalSupply: CurrencyAmount<ERC20Token>, tokenAmountA: CurrencyAmount<ERC20Token>, tokenAmountB: CurrencyAmount<ERC20Token>): CurrencyAmount<ERC20Token>;
|
|
43
|
+
getLiquidityValue(token: ERC20Token, totalSupply: CurrencyAmount<ERC20Token>, liquidity: CurrencyAmount<ERC20Token>, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount<ERC20Token>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=pair.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pair.d.ts","sourceRoot":"","sources":["../../src/entities/pair.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,cAAc,EACd,KAAK,EAML,SAAS,EAEV,MAAM,4BAA4B,CAAA;AAMnC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAMpC,eAAO,MAAM,kBAAkB;oBAKb,MAAM;YACd,UAAU;YACV,UAAU;MAChB,MAgBH,CAAA;AAED,qBAAa,IAAI;IACf,SAAgB,cAAc,EAAE,UAAU,CAAA;IAE1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA0D;WAEzE,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM;gBAIrD,eAAe,EAAE,cAAc,CAAC,UAAU,CAAC,EAAE,YAAY,EAAE,cAAc,CAAC,UAAU,CAAC;IAcxG;;;OAGG;IACI,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;IAIhD;;OAEG;IACH,IAAW,WAAW,IAAI,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,CAGtD;IAED;;OAEG;IACH,IAAW,WAAW,IAAI,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,CAGtD;IAED;;;OAGG;IACI,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC;IAKhE;;OAEG;IACH,IAAW,OAAO,IAAI,MAAM,CAE3B;IAED,IAAW,MAAM,IAAI,UAAU,CAE9B;IAED,IAAW,MAAM,IAAI,UAAU,CAE9B;IAED,IAAW,QAAQ,IAAI,cAAc,CAAC,UAAU,CAAC,CAEhD;IAED,IAAW,QAAQ,IAAI,cAAc,CAAC,UAAU,CAAC,CAEhD;IAEM,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC;IAKxD,eAAe,CAAC,WAAW,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC;IAoB5F,cAAc,CAAC,YAAY,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC;IAqB5F,kBAAkB,CACvB,WAAW,EAAE,cAAc,CAAC,UAAU,CAAC,EACvC,YAAY,EAAE,cAAc,CAAC,UAAU,CAAC,EACxC,YAAY,EAAE,cAAc,CAAC,UAAU,CAAC,GACvC,cAAc,CAAC,UAAU,CAAC;IAqBtB,iBAAiB,CACtB,KAAK,EAAE,UAAU,EACjB,WAAW,EAAE,cAAc,CAAC,UAAU,CAAC,EACvC,SAAS,EAAE,cAAc,CAAC,UAAU,CAAC,EACrC,KAAK,UAAQ,EACb,KAAK,CAAC,EAAE,SAAS,GAChB,cAAc,CAAC,UAAU,CAAC;CAiC9B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Token, Currency, Price } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
import { Pair } from './pair';
|
|
3
|
+
export declare class Route<TInput extends Currency, TOutput extends Currency> {
|
|
4
|
+
readonly pairs: Pair[];
|
|
5
|
+
readonly path: Token[];
|
|
6
|
+
readonly input: TInput;
|
|
7
|
+
readonly output: TOutput;
|
|
8
|
+
constructor(pairs: Pair[], input: TInput, output: TOutput);
|
|
9
|
+
private _midPrice;
|
|
10
|
+
get midPrice(): Price<TInput, TOutput>;
|
|
11
|
+
get chainId(): number;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/entities/route.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAE7B,qBAAa,KAAK,CAAC,MAAM,SAAS,QAAQ,EAAE,OAAO,SAAS,QAAQ;IAClE,SAAgB,KAAK,EAAE,IAAI,EAAE,CAAA;IAE7B,SAAgB,IAAI,EAAE,KAAK,EAAE,CAAA;IAE7B,SAAgB,KAAK,EAAE,MAAM,CAAA;IAE7B,SAAgB,MAAM,EAAE,OAAO,CAAA;gBAEZ,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;IA2BhE,OAAO,CAAC,SAAS,CAAsC;IAEvD,IAAW,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAa5C;IAED,IAAW,OAAO,IAAI,MAAM,CAE3B;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Token } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
export interface SerializedToken {
|
|
3
|
+
chainId: number;
|
|
4
|
+
address: string;
|
|
5
|
+
decimals: number;
|
|
6
|
+
symbol: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
projectLink?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class ERC20Token extends Token {
|
|
11
|
+
constructor(chainId: number, address: string, decimals: number, symbol: string, name?: string, projectLink?: string);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/entities/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAGlD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAKD,qBAAa,UAAW,SAAQ,KAAK;gBAEjC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM;CAIvB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { TradeType, CurrencyAmount, Currency, Percent, Price } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
import { Pair } from './pair';
|
|
3
|
+
import { Route } from './route';
|
|
4
|
+
interface InputOutput<TInput extends Currency, TOutput extends Currency> {
|
|
5
|
+
readonly inputAmount: CurrencyAmount<TInput>;
|
|
6
|
+
readonly outputAmount: CurrencyAmount<TOutput>;
|
|
7
|
+
}
|
|
8
|
+
export declare function inputOutputComparator<TInput extends Currency, TOutput extends Currency>(a: InputOutput<TInput, TOutput>, b: InputOutput<TInput, TOutput>): number;
|
|
9
|
+
export declare function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(a: Trade<TInput, TOutput, TTradeType>, b: Trade<TInput, TOutput, TTradeType>): number;
|
|
10
|
+
export interface BestTradeOptions {
|
|
11
|
+
maxNumResults?: number;
|
|
12
|
+
maxHops?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Represents a trade executed against a list of pairs.
|
|
16
|
+
* Does not account for slippage, i.e. trades that front run this trade and move the price.
|
|
17
|
+
*/
|
|
18
|
+
export declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {
|
|
19
|
+
/**
|
|
20
|
+
* The route of the trade, i.e. which pairs the trade goes through and the input/output currencies.
|
|
21
|
+
*/
|
|
22
|
+
readonly route: Route<TInput, TOutput>;
|
|
23
|
+
/**
|
|
24
|
+
* The type of the trade, either exact in or exact out.
|
|
25
|
+
*/
|
|
26
|
+
readonly tradeType: TTradeType;
|
|
27
|
+
/**
|
|
28
|
+
* The input amount for the trade assuming no slippage.
|
|
29
|
+
*/
|
|
30
|
+
readonly inputAmount: CurrencyAmount<TInput>;
|
|
31
|
+
/**
|
|
32
|
+
* The output amount for the trade assuming no slippage.
|
|
33
|
+
*/
|
|
34
|
+
readonly outputAmount: CurrencyAmount<TOutput>;
|
|
35
|
+
/**
|
|
36
|
+
* The price expressed in terms of output amount/input amount.
|
|
37
|
+
*/
|
|
38
|
+
readonly executionPrice: Price<TInput, TOutput>;
|
|
39
|
+
/**
|
|
40
|
+
* The percent difference between the mid price before the trade and the trade execution price.
|
|
41
|
+
*/
|
|
42
|
+
readonly priceImpact: Percent;
|
|
43
|
+
/**
|
|
44
|
+
* Constructs an exact in trade with the given amount in and route
|
|
45
|
+
* @param route route of the exact in trade
|
|
46
|
+
* @param amountIn the amount being passed in
|
|
47
|
+
*/
|
|
48
|
+
static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Trade<TInput, TOutput, TradeType.EXACT_INPUT>;
|
|
49
|
+
/**
|
|
50
|
+
* Constructs an exact out trade with the given amount out and route
|
|
51
|
+
* @param route route of the exact out trade
|
|
52
|
+
* @param amountOut the amount returned by the trade
|
|
53
|
+
*/
|
|
54
|
+
static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>;
|
|
55
|
+
constructor(route: Route<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType);
|
|
56
|
+
/**
|
|
57
|
+
* Get the minimum amount that must be received from this trade for the given slippage tolerance
|
|
58
|
+
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
|
|
59
|
+
*/
|
|
60
|
+
minimumAmountOut(slippageTolerance: Percent): CurrencyAmount<TOutput>;
|
|
61
|
+
/**
|
|
62
|
+
* Get the maximum amount in that can be spent via this trade for the given slippage tolerance
|
|
63
|
+
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
|
|
64
|
+
*/
|
|
65
|
+
maximumAmountIn(slippageTolerance: Percent): CurrencyAmount<TInput>;
|
|
66
|
+
/**
|
|
67
|
+
* Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
|
|
68
|
+
* amount to an output token, making at most `maxHops` hops.
|
|
69
|
+
* Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
|
|
70
|
+
* the amount in among multiple routes.
|
|
71
|
+
* @param pairs the pairs to consider in finding the best trade
|
|
72
|
+
* @param nextAmountIn exact amount of input currency to spend
|
|
73
|
+
* @param currencyOut the desired currency out
|
|
74
|
+
* @param maxNumResults maximum number of results to return
|
|
75
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
|
|
76
|
+
* @param currentPairs used in recursion; the current list of pairs
|
|
77
|
+
* @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
|
|
78
|
+
* @param bestTrades used in recursion; the current list of best trades
|
|
79
|
+
*/
|
|
80
|
+
static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyAmountIn: CurrencyAmount<TInput>, currencyOut: TOutput, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountIn?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[];
|
|
81
|
+
/**
|
|
82
|
+
* Return the execution price after accounting for slippage tolerance
|
|
83
|
+
* @param slippageTolerance the allowed tolerated slippage
|
|
84
|
+
*/
|
|
85
|
+
worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>;
|
|
86
|
+
/**
|
|
87
|
+
* similar to the above method but instead targets a fixed output amount
|
|
88
|
+
* given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token
|
|
89
|
+
* to an output token amount, making at most `maxHops` hops
|
|
90
|
+
* note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
|
|
91
|
+
* the amount in among multiple routes.
|
|
92
|
+
* @param pairs the pairs to consider in finding the best trade
|
|
93
|
+
* @param currencyIn the currency to spend
|
|
94
|
+
* @param nextAmountOut the exact amount of currency out
|
|
95
|
+
* @param maxNumResults maximum number of results to return
|
|
96
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
|
|
97
|
+
* @param currentPairs used in recursion; the current list of pairs
|
|
98
|
+
* @param currencyAmountOut used in recursion; the original value of the currencyAmountOut parameter
|
|
99
|
+
* @param bestTrades used in recursion; the current list of best trades
|
|
100
|
+
*/
|
|
101
|
+
static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyIn: TInput, currencyAmountOut: CurrencyAmount<TOutput>, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountOut?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[];
|
|
102
|
+
}
|
|
103
|
+
export {};
|
|
104
|
+
//# sourceMappingURL=trade.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trade.d.ts","sourceRoot":"","sources":["../../src/entities/trade.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,SAAS,EAET,cAAc,EACd,QAAQ,EAER,OAAO,EACP,KAAK,EAIN,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAG/B,UAAU,WAAW,CAAC,MAAM,SAAS,QAAQ,EAAE,OAAO,SAAS,QAAQ;IACrE,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;IAC5C,QAAQ,CAAC,YAAY,EAAE,cAAc,CAAC,OAAO,CAAC,CAAA;CAC/C;AAID,wBAAgB,qBAAqB,CAAC,MAAM,SAAS,QAAQ,EAAE,OAAO,SAAS,QAAQ,EACrF,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAmBR;AAGD,wBAAgB,eAAe,CAAC,MAAM,SAAS,QAAQ,EAAE,OAAO,SAAS,QAAQ,EAAE,UAAU,SAAS,SAAS,EAC7G,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,EACrC,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,UAiBtC;AAED,MAAM,WAAW,gBAAgB;IAE/B,aAAa,CAAC,EAAE,MAAM,CAAA;IAEtB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,qBAAa,KAAK,CAAC,MAAM,SAAS,QAAQ,EAAE,OAAO,SAAS,QAAQ,EAAE,UAAU,SAAS,SAAS;IAChG;;OAEG;IACH,SAAgB,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAE7C;;OAEG;IACH,SAAgB,SAAS,EAAE,UAAU,CAAA;IAErC;;OAEG;IACH,SAAgB,WAAW,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;IAEnD;;OAEG;IACH,SAAgB,YAAY,EAAE,cAAc,CAAC,OAAO,CAAC,CAAA;IAErD;;OAEG;IACH,SAAgB,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEtD;;OAEG;IACH,SAAgB,WAAW,EAAE,OAAO,CAAA;IAEpC;;;;OAIG;WACW,OAAO,CAAC,MAAM,SAAS,QAAQ,EAAE,OAAO,SAAS,QAAQ,EACrE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,QAAQ,EAAE,cAAc,CAAC,MAAM,CAAC,GAC/B,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,WAAW,CAAC;IAIhD;;;;OAIG;WACW,QAAQ,CAAC,MAAM,SAAS,QAAQ,EAAE,OAAO,SAAS,QAAQ,EACtE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,SAAS,EAAE,cAAc,CAAC,OAAO,CAAC,GACjC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,YAAY,CAAC;gBAK/C,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,UAAU,SAAS,SAAS,CAAC,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,OAAO,CAAC,EACnG,SAAS,EAAE,UAAU;IA4CvB;;;OAGG;IACI,gBAAgB,CAAC,iBAAiB,EAAE,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC;IAY5E;;;OAGG;IACI,eAAe,CAAC,iBAAiB,EAAE,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC;IAW1E;;;;;;;;;;;;;OAaG;WACW,gBAAgB,CAAC,MAAM,SAAS,QAAQ,EAAE,OAAO,SAAS,QAAQ,EAC9E,KAAK,EAAE,IAAI,EAAE,EACb,gBAAgB,EAAE,cAAc,CAAC,MAAM,CAAC,EACxC,WAAW,EAAE,OAAO,EACpB,EAAE,aAAiB,EAAE,OAAW,EAAE,GAAE,gBAAqB,EAEzD,YAAY,GAAE,IAAI,EAAO,EACzB,YAAY,GAAE,cAAc,CAAC,QAAQ,CAAoB,EACzD,UAAU,GAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,WAAW,CAAC,EAAO,GAC/D,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,WAAW,CAAC,EAAE;IA6DlD;;;OAGG;IACI,mBAAmB,CAAC,iBAAiB,EAAE,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC;IAS9E;;;;;;;;;;;;;;OAcG;WACW,iBAAiB,CAAC,MAAM,SAAS,QAAQ,EAAE,OAAO,SAAS,QAAQ,EAC/E,KAAK,EAAE,IAAI,EAAE,EACb,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,cAAc,CAAC,OAAO,CAAC,EAC1C,EAAE,aAAiB,EAAE,OAAW,EAAE,GAAE,gBAAqB,EAEzD,YAAY,GAAE,IAAI,EAAO,EACzB,aAAa,GAAE,cAAc,CAAC,QAAQ,CAAqB,EAC3D,UAAU,GAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,YAAY,CAAC,EAAO,GAChE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,YAAY,CAAC,EAAE;CA4DpD"}
|
package/dist/ether.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Currency, NativeCurrency, Token } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
/**
|
|
3
|
+
* Ether is the main usage of a 'native' currency, i.e. for Ethereum mainnet and all testnets
|
|
4
|
+
*/
|
|
5
|
+
export declare class Ether extends NativeCurrency {
|
|
6
|
+
protected constructor(chainId: number);
|
|
7
|
+
get wrapped(): Token;
|
|
8
|
+
private static _etherCache;
|
|
9
|
+
static onChain(chainId: number): Ether;
|
|
10
|
+
equals(other: Currency): boolean;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ether.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ether.d.ts","sourceRoot":"","sources":["../src/ether.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAG5E;;GAEG;AACH,qBAAa,KAAM,SAAQ,cAAc;IACvC,SAAS,aAAa,OAAO,EAAE,MAAM;IAIrC,IAAW,OAAO,IAAI,KAAK,CAM1B;IAED,OAAO,CAAC,MAAM,CAAC,WAAW,CAAmC;WAE/C,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK;IAQtC,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;CAGxC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Token } from '@pancakeswap/swap-sdk-core';
|
|
2
|
+
import { Pair } from './entities/pair';
|
|
3
|
+
import { ChainId } from './constants';
|
|
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 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 | undefined, 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
|
+
}
|
|
29
|
+
//# sourceMappingURL=fetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAElE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAQrC;;GAEG;AACH,8BAAsB,OAAO;IAC3B;;OAEG;IAEH,OAAO;IAEP;;;;;;;OAOG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,QAAQ,6DAA0C,EAClD,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,KAAK,CAAC;IAiBjB;;;;;OAKG;WACiB,aAAa,CAC/B,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,KAAK,EACb,QAAQ,kDAAiD,GACxD,OAAO,CAAC,IAAI,CAAC;CAUjB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,282 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export * from './constants';
|
|
2
|
+
export * from './trade';
|
|
3
|
+
export * from './entities';
|
|
4
|
+
export * from './router';
|
|
5
|
+
export * from './utils';
|
|
6
|
+
export * from './ether';
|
|
7
|
+
export * from './fetcher';
|
|
3
8
|
export * from '@pancakeswap/swap-sdk-core';
|
|
4
|
-
|
|
5
|
-
declare class ERC20Token extends Token {
|
|
6
|
-
constructor(chainId: number, address: string, decimals: number, symbol: string, name?: string, projectLink?: string);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
declare enum ChainId {
|
|
10
|
-
ETHEREUM = 1,
|
|
11
|
-
GOERLI = 5,
|
|
12
|
-
BSC = 56,
|
|
13
|
-
BSC_TESTNET = 97
|
|
14
|
-
}
|
|
15
|
-
declare const ZERO_PERCENT: Percent;
|
|
16
|
-
declare const ONE_HUNDRED_PERCENT: Percent;
|
|
17
|
-
declare const FACTORY_ADDRESS = "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73";
|
|
18
|
-
declare const FACTORY_ADDRESS_MAP: Record<number, string>;
|
|
19
|
-
declare const INIT_CODE_HASH = "0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5";
|
|
20
|
-
declare const INIT_CODE_HASH_MAP: Record<number, string>;
|
|
21
|
-
declare const WETH9: {
|
|
22
|
-
1: ERC20Token;
|
|
23
|
-
5: ERC20Token;
|
|
24
|
-
};
|
|
25
|
-
declare const WBNB: {
|
|
26
|
-
1: ERC20Token;
|
|
27
|
-
56: ERC20Token;
|
|
28
|
-
97: ERC20Token;
|
|
29
|
-
};
|
|
30
|
-
declare const WNATIVE: Record<number, ERC20Token>;
|
|
31
|
-
declare const NATIVE: Record<number, {
|
|
32
|
-
name: string;
|
|
33
|
-
symbol: string;
|
|
34
|
-
decimals: number;
|
|
35
|
-
}>;
|
|
36
|
-
|
|
37
|
-
declare const computePairAddress: ({ factoryAddress, tokenA, tokenB, }: {
|
|
38
|
-
factoryAddress: string;
|
|
39
|
-
tokenA: ERC20Token;
|
|
40
|
-
tokenB: ERC20Token;
|
|
41
|
-
}) => string;
|
|
42
|
-
declare class Pair {
|
|
43
|
-
readonly liquidityToken: ERC20Token;
|
|
44
|
-
private readonly tokenAmounts;
|
|
45
|
-
static getAddress(tokenA: ERC20Token, tokenB: ERC20Token): string;
|
|
46
|
-
constructor(currencyAmountA: CurrencyAmount<ERC20Token>, tokenAmountB: CurrencyAmount<ERC20Token>);
|
|
47
|
-
/**
|
|
48
|
-
* Returns true if the token is either token0 or token1
|
|
49
|
-
* @param token to check
|
|
50
|
-
*/
|
|
51
|
-
involvesToken(token: ERC20Token): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0
|
|
54
|
-
*/
|
|
55
|
-
get token0Price(): Price<ERC20Token, ERC20Token>;
|
|
56
|
-
/**
|
|
57
|
-
* Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1
|
|
58
|
-
*/
|
|
59
|
-
get token1Price(): Price<ERC20Token, ERC20Token>;
|
|
60
|
-
/**
|
|
61
|
-
* Return the price of the given token in terms of the other token in the pair.
|
|
62
|
-
* @param token token to return price of
|
|
63
|
-
*/
|
|
64
|
-
priceOf(token: ERC20Token): Price<ERC20Token, ERC20Token>;
|
|
65
|
-
/**
|
|
66
|
-
* Returns the chain ID of the tokens in the pair.
|
|
67
|
-
*/
|
|
68
|
-
get chainId(): number;
|
|
69
|
-
get token0(): ERC20Token;
|
|
70
|
-
get token1(): ERC20Token;
|
|
71
|
-
get reserve0(): CurrencyAmount<ERC20Token>;
|
|
72
|
-
get reserve1(): CurrencyAmount<ERC20Token>;
|
|
73
|
-
reserveOf(token: ERC20Token): CurrencyAmount<ERC20Token>;
|
|
74
|
-
getOutputAmount(inputAmount: CurrencyAmount<ERC20Token>): [CurrencyAmount<ERC20Token>, Pair];
|
|
75
|
-
getInputAmount(outputAmount: CurrencyAmount<ERC20Token>): [CurrencyAmount<ERC20Token>, Pair];
|
|
76
|
-
getLiquidityMinted(totalSupply: CurrencyAmount<ERC20Token>, tokenAmountA: CurrencyAmount<ERC20Token>, tokenAmountB: CurrencyAmount<ERC20Token>): CurrencyAmount<ERC20Token>;
|
|
77
|
-
getLiquidityValue(token: ERC20Token, totalSupply: CurrencyAmount<ERC20Token>, liquidity: CurrencyAmount<ERC20Token>, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount<ERC20Token>;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
declare class Route<TInput extends Currency, TOutput extends Currency> {
|
|
81
|
-
readonly pairs: Pair[];
|
|
82
|
-
readonly path: Token[];
|
|
83
|
-
readonly input: TInput;
|
|
84
|
-
readonly output: TOutput;
|
|
85
|
-
constructor(pairs: Pair[], input: TInput, output: TOutput);
|
|
86
|
-
private _midPrice;
|
|
87
|
-
get midPrice(): Price<TInput, TOutput>;
|
|
88
|
-
get chainId(): number;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
interface InputOutput<TInput extends Currency, TOutput extends Currency> {
|
|
92
|
-
readonly inputAmount: CurrencyAmount<TInput>;
|
|
93
|
-
readonly outputAmount: CurrencyAmount<TOutput>;
|
|
94
|
-
}
|
|
95
|
-
declare function inputOutputComparator<TInput extends Currency, TOutput extends Currency>(a: InputOutput<TInput, TOutput>, b: InputOutput<TInput, TOutput>): number;
|
|
96
|
-
declare function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(a: Trade<TInput, TOutput, TTradeType>, b: Trade<TInput, TOutput, TTradeType>): number;
|
|
97
|
-
interface BestTradeOptions {
|
|
98
|
-
maxNumResults?: number;
|
|
99
|
-
maxHops?: number;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Represents a trade executed against a list of pairs.
|
|
103
|
-
* Does not account for slippage, i.e. trades that front run this trade and move the price.
|
|
104
|
-
*/
|
|
105
|
-
declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {
|
|
106
|
-
/**
|
|
107
|
-
* The route of the trade, i.e. which pairs the trade goes through and the input/output currencies.
|
|
108
|
-
*/
|
|
109
|
-
readonly route: Route<TInput, TOutput>;
|
|
110
|
-
/**
|
|
111
|
-
* The type of the trade, either exact in or exact out.
|
|
112
|
-
*/
|
|
113
|
-
readonly tradeType: TTradeType;
|
|
114
|
-
/**
|
|
115
|
-
* The input amount for the trade assuming no slippage.
|
|
116
|
-
*/
|
|
117
|
-
readonly inputAmount: CurrencyAmount<TInput>;
|
|
118
|
-
/**
|
|
119
|
-
* The output amount for the trade assuming no slippage.
|
|
120
|
-
*/
|
|
121
|
-
readonly outputAmount: CurrencyAmount<TOutput>;
|
|
122
|
-
/**
|
|
123
|
-
* The price expressed in terms of output amount/input amount.
|
|
124
|
-
*/
|
|
125
|
-
readonly executionPrice: Price<TInput, TOutput>;
|
|
126
|
-
/**
|
|
127
|
-
* The percent difference between the mid price before the trade and the trade execution price.
|
|
128
|
-
*/
|
|
129
|
-
readonly priceImpact: Percent;
|
|
130
|
-
/**
|
|
131
|
-
* Constructs an exact in trade with the given amount in and route
|
|
132
|
-
* @param route route of the exact in trade
|
|
133
|
-
* @param amountIn the amount being passed in
|
|
134
|
-
*/
|
|
135
|
-
static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Trade<TInput, TOutput, TradeType.EXACT_INPUT>;
|
|
136
|
-
/**
|
|
137
|
-
* Constructs an exact out trade with the given amount out and route
|
|
138
|
-
* @param route route of the exact out trade
|
|
139
|
-
* @param amountOut the amount returned by the trade
|
|
140
|
-
*/
|
|
141
|
-
static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>;
|
|
142
|
-
constructor(route: Route<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType);
|
|
143
|
-
/**
|
|
144
|
-
* Get the minimum amount that must be received from this trade for the given slippage tolerance
|
|
145
|
-
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
|
|
146
|
-
*/
|
|
147
|
-
minimumAmountOut(slippageTolerance: Percent): CurrencyAmount<TOutput>;
|
|
148
|
-
/**
|
|
149
|
-
* Get the maximum amount in that can be spent via this trade for the given slippage tolerance
|
|
150
|
-
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
|
|
151
|
-
*/
|
|
152
|
-
maximumAmountIn(slippageTolerance: Percent): CurrencyAmount<TInput>;
|
|
153
|
-
/**
|
|
154
|
-
* Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
|
|
155
|
-
* amount to an output token, making at most `maxHops` hops.
|
|
156
|
-
* Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
|
|
157
|
-
* the amount in among multiple routes.
|
|
158
|
-
* @param pairs the pairs to consider in finding the best trade
|
|
159
|
-
* @param nextAmountIn exact amount of input currency to spend
|
|
160
|
-
* @param currencyOut the desired currency out
|
|
161
|
-
* @param maxNumResults maximum number of results to return
|
|
162
|
-
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
|
|
163
|
-
* @param currentPairs used in recursion; the current list of pairs
|
|
164
|
-
* @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
|
|
165
|
-
* @param bestTrades used in recursion; the current list of best trades
|
|
166
|
-
*/
|
|
167
|
-
static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyAmountIn: CurrencyAmount<TInput>, currencyOut: TOutput, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountIn?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[];
|
|
168
|
-
/**
|
|
169
|
-
* Return the execution price after accounting for slippage tolerance
|
|
170
|
-
* @param slippageTolerance the allowed tolerated slippage
|
|
171
|
-
*/
|
|
172
|
-
worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>;
|
|
173
|
-
/**
|
|
174
|
-
* similar to the above method but instead targets a fixed output amount
|
|
175
|
-
* given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token
|
|
176
|
-
* to an output token amount, making at most `maxHops` hops
|
|
177
|
-
* note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
|
|
178
|
-
* the amount in among multiple routes.
|
|
179
|
-
* @param pairs the pairs to consider in finding the best trade
|
|
180
|
-
* @param currencyIn the currency to spend
|
|
181
|
-
* @param nextAmountOut the exact amount of currency out
|
|
182
|
-
* @param maxNumResults maximum number of results to return
|
|
183
|
-
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
|
|
184
|
-
* @param currentPairs used in recursion; the current list of pairs
|
|
185
|
-
* @param currencyAmountOut used in recursion; the original value of the currencyAmountOut parameter
|
|
186
|
-
* @param bestTrades used in recursion; the current list of best trades
|
|
187
|
-
*/
|
|
188
|
-
static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyIn: TInput, currencyAmountOut: CurrencyAmount<TOutput>, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountOut?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[];
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
*
|
|
193
|
-
* Native is the main usage of a 'native' currency, i.e. for BSC mainnet and all testnets
|
|
194
|
-
*/
|
|
195
|
-
declare class Native extends NativeCurrency {
|
|
196
|
-
protected constructor({ chainId, decimals, name, symbol, }: {
|
|
197
|
-
chainId: number;
|
|
198
|
-
decimals: number;
|
|
199
|
-
symbol: string;
|
|
200
|
-
name: string;
|
|
201
|
-
});
|
|
202
|
-
get wrapped(): Token;
|
|
203
|
-
private static cache;
|
|
204
|
-
static onChain(chainId: number): Native;
|
|
205
|
-
equals(other: Currency): boolean;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
declare function isTradeBetter(tradeA: Trade<Currency, Currency, TradeType> | undefined | null, tradeB: Trade<Currency, Currency, TradeType> | undefined | null, minimumDelta?: Percent): boolean | undefined;
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Options for producing the arguments to send call to the router.
|
|
212
|
-
*/
|
|
213
|
-
interface TradeOptions {
|
|
214
|
-
/**
|
|
215
|
-
* How much the execution price is allowed to move unfavorably from the trade execution price.
|
|
216
|
-
*/
|
|
217
|
-
allowedSlippage: Percent;
|
|
218
|
-
/**
|
|
219
|
-
* How long the swap is valid until it expires, in seconds.
|
|
220
|
-
* This will be used to produce a `deadline` parameter which is computed from when the swap call parameters
|
|
221
|
-
* are generated.
|
|
222
|
-
*/
|
|
223
|
-
ttl: number;
|
|
224
|
-
/**
|
|
225
|
-
* The account that should receive the output of the swap.
|
|
226
|
-
*/
|
|
227
|
-
recipient: string;
|
|
228
|
-
/**
|
|
229
|
-
* Whether any of the tokens in the path are fee on transfer tokens, which should be handled with special methods
|
|
230
|
-
*/
|
|
231
|
-
feeOnTransfer?: boolean;
|
|
232
|
-
}
|
|
233
|
-
interface TradeOptionsDeadline extends Omit<TradeOptions, 'ttl'> {
|
|
234
|
-
/**
|
|
235
|
-
* When the transaction expires.
|
|
236
|
-
* This is an atlernate to specifying the ttl, for when you do not want to use local time.
|
|
237
|
-
*/
|
|
238
|
-
deadline: number;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* The parameters to use in the call to the Pancake Router to execute a trade.
|
|
242
|
-
*/
|
|
243
|
-
interface SwapParameters {
|
|
244
|
-
/**
|
|
245
|
-
* The method to call on the Pancake Router.
|
|
246
|
-
*/
|
|
247
|
-
methodName: string;
|
|
248
|
-
/**
|
|
249
|
-
* The arguments to pass to the method, all hex encoded.
|
|
250
|
-
*/
|
|
251
|
-
args: (string | string[])[];
|
|
252
|
-
/**
|
|
253
|
-
* The amount of wei to send in hex.
|
|
254
|
-
*/
|
|
255
|
-
value: string;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Represents the Pancake Router, and has static methods for helping execute trades.
|
|
259
|
-
*/
|
|
260
|
-
declare abstract class Router {
|
|
261
|
-
/**
|
|
262
|
-
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
|
263
|
-
* @param trade to produce call parameters for
|
|
264
|
-
* @param options options for the call parameters
|
|
265
|
-
*/
|
|
266
|
-
static swapCallParameters(trade: Trade<Currency, Currency, TradeType>, options: TradeOptions | TradeOptionsDeadline): SwapParameters;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
declare function validateAndParseAddress(address: string): string;
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Ether is the main usage of a 'native' currency, i.e. for Ethereum mainnet and all testnets
|
|
273
|
-
*/
|
|
274
|
-
declare class Ether extends NativeCurrency {
|
|
275
|
-
protected constructor(chainId: number);
|
|
276
|
-
get wrapped(): Token;
|
|
277
|
-
private static _etherCache;
|
|
278
|
-
static onChain(chainId: number): Ether;
|
|
279
|
-
equals(other: Currency): boolean;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export { BestTradeOptions, ChainId, ERC20Token, Ether, FACTORY_ADDRESS, FACTORY_ADDRESS_MAP, INIT_CODE_HASH, INIT_CODE_HASH_MAP, NATIVE, Native, ONE_HUNDRED_PERCENT, Pair, Route, Router, SwapParameters, Trade, TradeOptions, TradeOptionsDeadline, WBNB, WETH9, WNATIVE, ZERO_PERCENT, computePairAddress, inputOutputComparator, isTradeBetter, tradeComparator, validateAndParseAddress };
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AAEvB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AAExB,cAAc,SAAS,CAAA;AAEvB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AAEzB,cAAc,4BAA4B,CAAA"}
|