@pancakeswap/v2-sdk 1.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.
@@ -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,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,CAm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1C,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"}
@@ -0,0 +1,30 @@
1
+ import { ChainId } from '@pancakeswap/chains';
2
+ import { Token } from '@pancakeswap/swap-sdk-core';
3
+ import { Address } from 'viem';
4
+ import { Pair } from './entities/pair';
5
+ /**
6
+ * Contains methods for constructing instances of pairs and tokens from on-chain data.
7
+ */
8
+ export declare abstract class Fetcher {
9
+ /**
10
+ * Cannot be constructed.
11
+ */
12
+ private constructor();
13
+ /**
14
+ * Fetch information for a given token on the given chain, using the given viem provider.
15
+ * @param chainId chain of the token
16
+ * @param address address of the token on the chain
17
+ * @param provider provider used to fetch the token
18
+ * @param symbol symbol of the token
19
+ * @param name optional name of the token
20
+ */
21
+ static fetchTokenData(chainId: ChainId, address: Address, publicClient: any, symbol: string, name?: string): Promise<Token>;
22
+ /**
23
+ * Fetches information about a pair and constructs a pair from the given two tokens.
24
+ * @param tokenA first token
25
+ * @param tokenB second token
26
+ * @param provider the provider to use to fetch the data
27
+ */
28
+ static fetchPairData(tokenA: Token, tokenB: Token, publicClient?: any): Promise<Pair>;
29
+ }
30
+ //# sourceMappingURL=fetcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAkB,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAGlE,OAAO,EAAE,OAAO,EAAuD,MAAM,MAAM,CAAA;AAInF,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AA0BtC;;GAEG;AACH,8BAAsB,OAAO;IAC3B;;OAEG;IAEH,OAAO;IAEP;;;;;;;OAOG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,YAAY,KAAiC,EAC7C,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,KAAK,CAAC;IAsBjB;;;;;OAKG;WACiB,aAAa,CAC/B,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,KAAK,EACb,YAAY,GAAE,GAAsC,GACnD,OAAO,CAAC,IAAI,CAAC;CAejB"}
@@ -0,0 +1,7 @@
1
+ export * from './constants';
2
+ export * from './entities';
3
+ export * from './abis/IPancakePair';
4
+ export * from './router';
5
+ export * from './fetcher';
6
+ export * from './trade';
7
+ //# 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,YAAY,CAAA;AAC1B,cAAc,qBAAqB,CAAA;AACnC,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"}