Skip to content

Commit

Permalink
Commited dist to use it github reference as from package.json in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
artall64 committed Aug 3, 2020
1 parent d72eb54 commit da99985
Show file tree
Hide file tree
Showing 36 changed files with 3,633 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
dist
node_modules
38 changes: 38 additions & 0 deletions dist/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import JSBI from 'jsbi';
export declare type BigintIsh = JSBI | bigint | string;
export declare enum ChainId {
MAINNET = 1,
ROPSTEN = 3,
RINKEBY = 4,
GÖRLI = 5,
KOVAN = 42
}
export declare enum TradeType {
EXACT_INPUT = 0,
EXACT_OUTPUT = 1
}
export declare enum Rounding {
ROUND_DOWN = 0,
ROUND_HALF_UP = 1,
ROUND_UP = 2
}
export declare const FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f";
export declare const INIT_CODE_HASH = "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f";
export declare const MINIMUM_LIQUIDITY: JSBI;
export declare const ZERO: JSBI;
export declare const ONE: JSBI;
export declare const TWO: JSBI;
export declare const THREE: JSBI;
export declare const FIVE: JSBI;
export declare const TEN: JSBI;
export declare const _100: JSBI;
export declare const _997: JSBI;
export declare const _1000: JSBI;
export declare enum SolidityType {
uint8 = "uint8",
uint256 = "uint256"
}
export declare const SOLIDITY_TYPE_MAXIMA: {
uint8: JSBI;
uint256: JSBI;
};
23 changes: 23 additions & 0 deletions dist/entities/currency.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens.
*
* The only instance of the base class `Currency` is Ether.
*/
export declare class Currency {
readonly decimals: number;
readonly symbol?: string;
readonly name?: string;
/**
* The only instance of the base class `Currency`.
*/
static readonly ETHER: Currency;
/**
* Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`.
* @param decimals decimals of the currency
* @param symbol symbol of the currency
* @param name of the currency
*/
protected constructor(decimals: number, symbol?: string, name?: string);
}
declare const ETHER: Currency;
export { ETHER };
19 changes: 19 additions & 0 deletions dist/entities/fractions/currencyAmount.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Currency } from '../currency';
import JSBI from 'jsbi';
import { BigintIsh, Rounding } from '../../constants';
import { Fraction } from './fraction';
export declare class CurrencyAmount extends Fraction {
readonly currency: Currency;
/**
* Helper that calls the constructor with the ETHER currency
* @param amount ether amount in wei
*/
static ether(amount: BigintIsh): CurrencyAmount;
protected constructor(currency: Currency, amount: BigintIsh);
get raw(): JSBI;
add(other: CurrencyAmount): CurrencyAmount;
subtract(other: CurrencyAmount): CurrencyAmount;
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
toExact(format?: object): string;
}
19 changes: 19 additions & 0 deletions dist/entities/fractions/fraction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import JSBI from 'jsbi';
import { BigintIsh, Rounding } from '../../constants';
export declare class Fraction {
readonly numerator: JSBI;
readonly denominator: JSBI;
constructor(numerator: BigintIsh, denominator?: BigintIsh);
get quotient(): JSBI;
get remainder(): Fraction;
invert(): Fraction;
add(other: Fraction | BigintIsh): Fraction;
subtract(other: Fraction | BigintIsh): Fraction;
lessThan(other: Fraction | BigintIsh): boolean;
equalTo(other: Fraction | BigintIsh): boolean;
greaterThan(other: Fraction | BigintIsh): boolean;
multiply(other: Fraction | BigintIsh): Fraction;
divide(other: Fraction | BigintIsh): Fraction;
toSignificant(significantDigits: number, format?: object, rounding?: Rounding): string;
toFixed(decimalPlaces: number, format?: object, rounding?: Rounding): string;
}
5 changes: 5 additions & 0 deletions dist/entities/fractions/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './fraction';
export * from './percent';
export * from './tokenAmount';
export * from './currencyAmount';
export * from './price';
6 changes: 6 additions & 0 deletions dist/entities/fractions/percent.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Rounding } from '../../constants';
import { Fraction } from './fraction';
export declare class Percent extends Fraction {
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
}
19 changes: 19 additions & 0 deletions dist/entities/fractions/price.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BigintIsh, Rounding } from '../../constants';
import { Currency } from '../currency';
import { Route } from '../route';
import { Fraction } from './fraction';
import { CurrencyAmount } from './currencyAmount';
export declare class Price extends Fraction {
readonly baseCurrency: Currency;
readonly quoteCurrency: Currency;
readonly scalar: Fraction;
static fromRoute(route: Route): Price;
constructor(baseCurrency: Currency, quoteCurrency: Currency, denominator: BigintIsh, numerator: BigintIsh);
get raw(): Fraction;
get adjusted(): Fraction;
invert(): Price;
multiply(other: Price): Price;
quote(currencyAmount: CurrencyAmount): CurrencyAmount;
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
}
9 changes: 9 additions & 0 deletions dist/entities/fractions/tokenAmount.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { CurrencyAmount } from './currencyAmount';
import { Token } from '../token';
import { BigintIsh } from '../../constants';
export declare class TokenAmount extends CurrencyAmount {
readonly token: Token;
constructor(token: Token, amount: BigintIsh);
add(other: TokenAmount): TokenAmount;
subtract(other: TokenAmount): TokenAmount;
}
6 changes: 6 additions & 0 deletions dist/entities/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './token';
export * from './pair';
export * from './route';
export * from './trade';
export * from './currency';
export * from './fractions';
41 changes: 41 additions & 0 deletions dist/entities/pair.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Price } from './fractions/price';
import { TokenAmount } from './fractions/tokenAmount';
import { BigintIsh, ChainId } from '../constants';
import { Token } from './token';
export declare class Pair {
readonly liquidityToken: Token;
private readonly tokenAmounts;
static getAddress(tokenA: Token, tokenB: Token): string;
constructor(tokenAmountA: TokenAmount, tokenAmountB: TokenAmount);
/**
* Returns true if the token is either token0 or token1
* @param token to check
*/
involvesToken(token: Token): boolean;
/**
* Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0
*/
get token0Price(): Price;
/**
* Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1
*/
get token1Price(): Price;
/**
* Return the price of the given token in terms of the other token in the pair.
* @param token token to return price of
*/
priceOf(token: Token): Price;
/**
* Returns the chain ID of the tokens in the pair.
*/
get chainId(): ChainId;
get token0(): Token;
get token1(): Token;
get reserve0(): TokenAmount;
get reserve1(): TokenAmount;
reserveOf(token: Token): TokenAmount;
getOutputAmount(inputAmount: TokenAmount): [TokenAmount, Pair];
getInputAmount(outputAmount: TokenAmount): [TokenAmount, Pair];
getLiquidityMinted(totalSupply: TokenAmount, tokenAmountA: TokenAmount, tokenAmountB: TokenAmount): TokenAmount;
getLiquidityValue(token: Token, totalSupply: TokenAmount, liquidity: TokenAmount, feeOn?: boolean, kLast?: BigintIsh): TokenAmount;
}
14 changes: 14 additions & 0 deletions dist/entities/route.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ChainId } from '../constants';
import { Currency } from './currency';
import { Token } from './token';
import { Pair } from './pair';
import { Price } from './fractions/price';
export declare class Route {
readonly pairs: Pair[];
readonly path: Token[];
readonly input: Currency;
readonly output: Currency;
readonly midPrice: Price;
constructor(pairs: Pair[], input: Currency, output?: Currency);
get chainId(): ChainId;
}
33 changes: 33 additions & 0 deletions dist/entities/token.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ChainId } from '../constants';
import { Currency } from './currency';
/**
* Represents an ERC20 token with a unique address and some metadata.
*/
export declare class Token extends Currency {
readonly chainId: ChainId;
readonly address: string;
constructor(chainId: ChainId, address: string, decimals: number, symbol?: string, name?: string);
/**
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
* @param other other token to compare
*/
equals(other: Token): boolean;
/**
* Returns true if the address of this token sorts before the address of the other token
* @param other other token to compare
* @throws if the tokens have the same address
* @throws if the tokens are on different chains
*/
sortsBefore(other: Token): boolean;
}
/**
* Compares two currencies for equality
*/
export declare function currencyEquals(currencyA: Currency, currencyB: Currency): boolean;
export declare const WETH: {
1: Token;
3: Token;
4: Token;
5: Token;
42: Token;
};
106 changes: 106 additions & 0 deletions dist/entities/trade.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { TradeType } from '../constants';
import { Currency } from './currency';
import { CurrencyAmount } from './fractions/currencyAmount';
import { Percent } from './fractions/percent';
import { Price } from './fractions/price';
import { Pair } from './pair';
import { Route } from './route';
interface InputOutput {
readonly inputAmount: CurrencyAmount;
readonly outputAmount: CurrencyAmount;
}
export declare function inputOutputComparator(a: InputOutput, b: InputOutput): number;
export declare function tradeComparator(a: Trade, b: Trade): number;
export interface BestTradeOptions {
maxNumResults?: number;
maxHops?: number;
}
/**
* Represents a trade executed against a list of pairs.
* Does not account for slippage, i.e. trades that front run this trade and move the price.
*/
export declare class Trade {
/**
* The route of the trade, i.e. which pairs the trade goes through.
*/
readonly route: Route;
/**
* The type of the trade, either exact in or exact out.
*/
readonly tradeType: TradeType;
/**
* The input amount for the trade assuming no slippage.
*/
readonly inputAmount: CurrencyAmount;
/**
* The output amount for the trade assuming no slippage.
*/
readonly outputAmount: CurrencyAmount;
/**
* The price expressed in terms of output amount/input amount.
*/
readonly executionPrice: Price;
/**
* The mid price after the trade executes assuming no slippage.
*/
readonly nextMidPrice: Price;
/**
* The percent difference between the mid price before the trade and the trade execution price.
*/
readonly priceImpact: Percent;
/**
* Constructs an exact in trade with the given amount in and route
* @param route route of the exact in trade
* @param amountIn the amount being passed in
*/
static exactIn(route: Route, amountIn: CurrencyAmount): Trade;
/**
* Constructs an exact out trade with the given amount out and route
* @param route route of the exact out trade
* @param amountOut the amount returned by the trade
*/
static exactOut(route: Route, amountOut: CurrencyAmount): Trade;
constructor(route: Route, amount: CurrencyAmount, tradeType: TradeType);
/**
* Get the minimum amount that must be received from this trade for the given slippage tolerance
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
*/
minimumAmountOut(slippageTolerance: Percent): CurrencyAmount;
/**
* Get the maximum amount in that can be spent via this trade for the given slippage tolerance
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
*/
maximumAmountIn(slippageTolerance: Percent): CurrencyAmount;
/**
* Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
* amount to an output token, making at most `maxHops` hops.
* Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
* the amount in among multiple routes.
* @param pairs the pairs to consider in finding the best trade
* @param currencyAmountIn exact amount of input currency to spend
* @param currencyOut the desired currency out
* @param maxNumResults maximum number of results to return
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
* @param currentPairs used in recursion; the current list of pairs
* @param originalAmountIn used in recursion; the original value of the currencyAmountIn parameter
* @param bestTrades used in recursion; the current list of best trades
*/
static bestTradeExactIn(pairs: Pair[], currencyAmountIn: CurrencyAmount, currencyOut: Currency, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], originalAmountIn?: CurrencyAmount, bestTrades?: Trade[]): Trade[];
/**
* similar to the above method but instead targets a fixed output amount
* given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token
* to an output token amount, making at most `maxHops` hops
* note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
* the amount in among multiple routes.
* @param pairs the pairs to consider in finding the best trade
* @param currencyIn the currency to spend
* @param currencyAmountOut the exact amount of currency out
* @param maxNumResults maximum number of results to return
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
* @param currentPairs used in recursion; the current list of pairs
* @param originalAmountOut used in recursion; the original value of the currencyAmountOut parameter
* @param bestTrades used in recursion; the current list of best trades
*/
static bestTradeExactOut(pairs: Pair[], currencyIn: Currency, currencyAmountOut: CurrencyAmount, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], originalAmountOut?: CurrencyAmount, bestTrades?: Trade[]): Trade[];
}
export {};
16 changes: 16 additions & 0 deletions dist/errors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be
* obtained by sending any amount of input.
*/
export declare class InsufficientReservesError extends Error {
readonly isInsufficientReservesError: true;
constructor();
}
/**
* Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less
* than the price of a single unit of output after fees.
*/
export declare class InsufficientInputAmountError extends Error {
readonly isInsufficientInputAmountError: true;
constructor();
}
28 changes: 28 additions & 0 deletions dist/fetcher.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Pair } from './entities/pair';
import { ChainId } from './constants';
import { Token } from './entities/token';
/**
* Contains methods for constructing instances of pairs and tokens from on-chain data.
*/
export declare abstract class Fetcher {
/**
* Cannot be constructed.
*/
private constructor();
/**
* Fetch information for a given token on the given chain, using the given ethers provider.
* @param chainId chain of the token
* @param address address of the token on the chain
* @param provider provider used to fetch the token
* @param symbol optional symbol of the token
* @param name optional name of the token
*/
static fetchTokenData(chainId: ChainId, address: string, provider?: import("@ethersproject/providers").BaseProvider, symbol?: string, name?: string): Promise<Token>;
/**
* Fetches information about a pair and constructs a pair from the given two tokens.
* @param tokenA first token
* @param tokenB second token
* @param provider the provider to use to fetch the data
*/
static fetchPairData(tokenA: Token, tokenB: Token, provider?: import("@ethersproject/providers").BaseProvider): Promise<Pair>;
}
Loading

0 comments on commit da99985

Please sign in to comment.