import { RequestArguments } from "web3-core"; import * as Eulith from "./index"; import { IUniswapV3Pool } from "../known_contracts_typings"; /** * The Uniswap module wraps access to a bunch of UNISWAP APIs (which are mediated by control * structures within the Eulith Toolkit), as well as raw direct access to UNISWAP APIs. */ export declare module Uniswap { /** * Uniswap.V3 wraps the V3 version of the Uniswap API and adds convenience methods */ module V3 { /** * Uniswap pools are organized by Fee, and have 3 categories of fee. * * Fee's are applied to swaps as rate * sellAmount (in units of the sell token). * * Selecting a fee is an advanced topic - for experts; obviously buyers want * the lowest fee possible, but depending on the size of the pool, you may see lower liquidity * on the lower feed pools, and so worse pricing. * * When in doubt, use Eulith.Uniswap.getBestPriceQuote. * * Historical Notes: Based on class UniswapV3PoolFee(int, Enum): */ enum PoolFee { OneBip = 100, FiveBips = 500, ThirtyBips = 3000, OneHundredBips = 10000 } /** * A LoanRequest implements IFlashLoanable - so it's designed to work with the 'Flash' mechanism, to create * instant, temporary liquidity. * * In the context of Uniswap, this just means using Uniswap pools to create that instant, temporary liquidity. * * This object requires a borrowTokenA (and borrowAmountA), and an optional borrowTokenB (and borrowAmountB). * * payTransferFrom designates who PAYS the loan or sell side of the swap. */ class LoanRequest implements Eulith.FlashLiquidity.IFlashLoanable { borrowTokenA: Eulith.Contracts.ERC20TokenContract; borrowAmountA: number; borrowTokenB?: Eulith.Contracts.ERC20TokenContract; borrowAmountB?: number; payTransferFrom?: string; recipient?: string; constructor(p: Partial); generateLoanRequest(): RequestArguments; get tokenValues(): Eulith.Tokens.Value.ITokenValue[]; } /** * This class is may generally be thought of as opaque, and is generally not used directly. * * Instead, these 'swap requests' are generally created by * Eulith.Uniswap.Pool instance method getQuote OR * Eulith.Uniswap.getBestPriceQuote, which both produce a Eulith.Uniswap.PriceQuote (which aggregates this object in the swapRequest member). * * This is then typically used via a call to Eulith.Uniswap.startSwap() */ class SwapRequest { sellToken: Eulith.Contracts.ERC20TokenContract; sellAmount: number; poolAddress: string; fillOrKill: boolean; sqrtLimitPrice: string; recipient?: string; payTransferFrom?: string; constructor(p: Partial); } /** * Generally not created directly, but as a result of calls * to Eulith.Uniswap.getBestPriceQuote, or 'a uniswap pool'.getQuote */ class PriceQuote { private readonly feePct_; constructor(p?: Partial); /** * The price is in units of the 'sellToken' - used to create the quote. */ price: number; /** * This is the request object passed along to the Eulith.Uniswap.startSwap API. */ swapRequest: SwapRequest; /** * The fee is in units of the 'sellToken', and a percent of the swapRequest.sellAmount - used to create the quote. */ get feeAmt(): Eulith.Tokens.Value.ITokenValue; /** * The fee is in units of the 'sellToken', and a percent of the swapRequest.sellAmount - used to create the quote. */ get feePct(): number; } interface MintByPriceRequest { priceLower: number; priceUpper: number; priceDenominatedInToken: string; amountZero: number; amountOne: number; recipient?: string; payTransferFrom?: string; } /** * A UNISWAP pool contains exactly two different token contracts, and allows the user * to exchange tokens in one, for the other. * * This cannot be constructed directly, but rather by Eulith.Uniswap.getSwapPool () */ class Pool { private web3; private readonly poolAddress; private fee_?; private token0_; private token1_; private readonly contract_; private readonly logger_; private constructor(); static AsyncConstructor({ provider, poolAddress, fee, token0Address, token1Address }: { provider: Eulith.Web3 | Eulith.Provider; poolAddress: string; fee?: PoolFee; token0Address?: string; token1Address?: string; }): Promise; /** * This return the fee (percentage) associated with this pool - Eulith.Uniswap.PoolFee * * This number is used to derive the actual fee that appears in specific quotes. * * There is an enumeration of possible fees. */ get fee(): PoolFee; /** * Returns the web3js native IUniswapV3Pool contract interface, with typescript typings for that interface. * * This extension point allows for calling any of the IUniswapV3Pool apis, via the standard web3js contract syntax */ get contract(): IUniswapV3Pool; get token0(): Eulith.Contracts.ERC20TokenContract; get token1(): Eulith.Contracts.ERC20TokenContract; get address(): string; /** * Given a uniswap pool, request a quote for the given sellToken and amount. */ getQuote({ sellToken, sellAmount, fillOrKill, recipient, payTransferFrom }: { sellToken: Eulith.Contracts.ERC20TokenContract; sellAmount: number; fillOrKill?: boolean; recipient?: string; payTransferFrom?: string; }): Promise; mintByPrice({ request, parentTransaction }: { request: MintByPriceRequest; parentTransaction: Eulith.AtomicTx.NestedTransaction | Eulith.AtomicTx.Transaction; }): Promise; } /** * Return the best available price (object Eulith.Uniswap.PriceQuote) which contains * the price, the fee, and actual swapRequest to use to perform this operation. */ function getBestPriceQuote({ swapQuoteRequest, fillOrKill, recipient, payTransferFrom, provider }: { swapQuoteRequest: { sellToken: Eulith.Contracts.ERC20TokenContract; buyToken: Eulith.Contracts.ERC20TokenContract; amount: number; trueForAmountIn?: boolean; fee?: PoolFee; }; fillOrKill?: boolean; recipient?: string; payTransferFrom?: string; provider: Eulith.Provider; }): Promise; /** * Starts a swap directly on the pool * * Uniswap swaps are represented as NestedTransactions; you can use the buyToken inside the transaction before * you have to pay the sell side before the transaction ends. */ function startSwap({ request, parentTx }: { request: SwapRequest; parentTx: Eulith.AtomicTx.NestedTransaction | Eulith.AtomicTx.Transaction; }): Promise; /** * A Uniswap pool contains exactly two different token Contracts, and allows the user * to exchange currency in one, for the other. Each pool also has exactly one fee associated (as a percent of exchange amount). * * This method looks up the pool details from its constituent token contracts, and the fee. * * Note the order of the request.tokenContracts is meaningless for fetching the pool * * The fee is a required parameter for looking up a pool - see Eulith.Uniswap.PoolFee for details. * If you don't know what fee to use, don't use getSwapPool, but use Eulith.Uniswap.getBestPriceQuote instead */ function getPool({ request, provider }: { request: { tokenContracts?: Eulith.Contracts.ERC20TokenContract[]; fee: PoolFee; }; provider: Eulith.Provider | Eulith.Web3; }): Promise; /** * A Uniswap pool contains exactly two different token Contracts, and allows the user * to exchange currency in one, for the other. Each pool also has exactly one fee associated (as a percent of exchange amount). * * This method constructs the pool from its address. This is sufficient information to uniquely identify a pool. */ function getPoolFromAddress({ provider, poolAddress, }: { poolAddress: string; provider: Eulith.Provider | Eulith.Web3; }): Promise; class CreateLimitOrderRequest { price: number | null; tick_lower: number | null; tick_upper: number | null; sell_amount: number; sell_token: string; pool_address: string; } interface CreateLimitOrderResponse { order: LimitOrderDetails; actualSellAmount: number; expectedBuyAmount: number; sellToken: string; buyToken: string; expectedAveragePrice: string; } /** * Creates a Uniswap limit order and returns the details of the order that will be executed. * * This does *not* actually submit an order to the Uniswap pool on-chain. In order to do that, you need to call * addLimitOrderToAtomicTx and then Atomic.Transaction.commitForAce(). */ function createLimitOrder(provider: Eulith.Provider, request: CreateLimitOrderRequest): Promise; interface AceUniBurnCollect { chainId: number; liquidity: string; tickLower: number; tickUpper: number; pool: string; } interface AddLimitOrderToAtomicTxResponse { orderId: number; burnCollectInstruction: AceUniBurnCollect; } /** * Adds a previously created Uniswap limit order to the pending atomic transaction. */ function addLimitOrderToAtomicTx(provider: Eulith.Provider, tx: Eulith.AtomicTx.Transaction, order: LimitOrderDetails, poolAddress: string): Promise; /** * Submits the hash of the transaction to mint the Uniswap limit order. * * This should be the hash returned by Atomic.Transaction.commitForAce() after having called * addLimitOrderToAtomicTx. */ function submitMintHash(provider: Eulith.Provider, orderId: number, txHash: string, burnCollectSig: string | null): Promise; /** * Retrieves all Uniswap limit orders (both pending and filled) for the current user. */ function getLimitOrders(provider: Eulith.Provider): Promise; /** * Confirms the status of the Uniswap limit order. * * While getLimitOrders returns limit orders as stored in Eulith's database, this method double-checks the status * against the chain. */ function confirmLimitOrder(provider: Eulith.Provider, orderId: number): Promise; interface LimitOrder { orderId: number; authAddress: string; poolAddress: string; network: number; details: LimitOrderDetails; status: string; txHash: string | null; fillOrCancelTxHash: string | null; burnCollectSig: string | null; sub: string; } interface LimitOrderDetails { liquidity: string; tickLower: number; tickUpper: number; sellZero: boolean; t0Decimals: number; t1Decimals: number; fee: number; } } function parsePoolFee(poolFee: number | string): V3.PoolFee; /** * Eulith.Uniswap.PoolFee: see Eulith.Uniswap.V3.PoolFee */ const PoolFee: typeof V3.PoolFee; type PoolFee = V3.PoolFee; /** * Eulith.Uniswap.Pool: see Eulith.Uniswap.V3.Pool */ const Pool: typeof V3.Pool; type Pool = V3.Pool; /** * Eulith.Uniswap.PriceQuote: See Eulith.Uniswap.V3.PriceQuote */ const PriceQuote: typeof V3.PriceQuote; type PriceQuote = V3.PriceQuote; /** * Eulith.Uniswap.LoanRequest: see Eulith.Uniswap.V3.LoanRequest */ const LoanRequest: typeof V3.LoanRequest; type LoanRequest = V3.LoanRequest; /** * Eulith.Uniswap.SwapRequest: see Eulith.Uniswap.V3.SwapRequest */ const SwapRequest: typeof V3.SwapRequest; type SwapRequest = V3.SwapRequest; /** * Eulith.Uniswap.getBestPriceQuote: see Eulith.Uniswap.V3.getBestPriceQuote */ const getBestPriceQuote: typeof V3.getBestPriceQuote; /** * Eulith.Uniswap.getSwapPool: see Eulith.Uniswap.V3.getSwapPool */ const getSwapPool: typeof V3.getPool; /** * Eulith.Uniswap.getSwapPoolFromAddress: see Eulith.Uniswap.V3.getSwapPoolFromAddress */ const getSwapPoolFromAddress: typeof V3.getPoolFromAddress; /** * Eulith.Uniswap.startSwap: see Eulith.Uniswap.V3.startSwap */ const startSwap: typeof V3.startSwap; }