@xspswap/smart-order-router
Version:
XSwap Protocol V3 Smart Order Router
70 lines (69 loc) • 2.64 kB
TypeScript
import { BigNumber } from '@ethersproject/bignumber';
import { ChainId, FactoryConfig, Token } from '@x-swap-protocol/sdk-core';
import { Pair } from '@x-swap-protocol/v2-sdk';
import { Options as RetryOptions } from 'async-retry';
import { IMulticallProvider } from '../multicall-provider';
import { ProviderConfig } from '../provider';
export type IReserves = {
reserve0: BigNumber;
reserve1: BigNumber;
blockTimestampLast: number;
};
/**
* Provider for getting V2 pools.
*
* @export
* @interface IV2PoolProvider
*/
export interface IV2PoolProvider {
/**
* Gets the pools for the specified token pairs.
*
* @param tokenPairs The token pairs to get.
* @param [providerConfig] The provider config.
* @returns A pool accessor with methods for accessing the pools.
*/
getPools(tokenPairs: [Token, Token][], providerConfig?: ProviderConfig): Promise<V2PoolAccessor>;
/**
* Gets the pool address for the specified token pair.
*
* @param tokenA Token A in the pool.
* @param tokenB Token B in the pool.
* @returns The pool address and the two tokens.
*/
getPoolAddress(tokenA: Token, tokenB: Token): {
poolAddress: string;
token0: Token;
token1: Token;
};
}
export type V2PoolAccessor = {
getPool: (tokenA: Token, tokenB: Token) => Pair | undefined;
getPoolByAddress: (address: string) => Pair | undefined;
getAllPools: () => Pair[];
};
export type V2PoolRetryOptions = RetryOptions;
export declare class V2PoolProvider implements IV2PoolProvider {
protected chainId: ChainId;
protected multicall2Provider: IMulticallProvider;
protected retryOptions: V2PoolRetryOptions;
protected factory?: FactoryConfig | undefined;
protected name?: string | undefined;
private POOL_ADDRESS_CACHE;
/**
* Creates an instance of V2PoolProvider.
* @param chainId The chain id to use.
* @param multicall2Provider The multicall provider to use to get the pools.
* @param [retryOptions] The retry options for each call to the multicall.
* @param {FactoryConfig} [factory] specific factory.
* @param name name of the provider.
*/
constructor(chainId: ChainId, multicall2Provider: IMulticallProvider, retryOptions: V2PoolRetryOptions, factory?: FactoryConfig | undefined, name?: string | undefined);
getPools(tokenPairs: [Token, Token][], providerConfig?: ProviderConfig): Promise<V2PoolAccessor>;
getPoolAddress(tokenA: Token, tokenB: Token): {
poolAddress: string;
token0: Token;
token1: Token;
};
private getPoolsData;
}