UNPKG

doppler-v3-sdk

Version:
95 lines 3.87 kB
import { createDrift, } from "@delvtech/drift"; import { quoterV2Abi, uniswapV2Router02Abi } from "../../abis"; /** * A read-only interface to the Uniswap V3 QuoterV2 contract that provides: * - Price quotes for exact input and output swaps * - Formatted amounts with proper decimal handling * - Simulation of swap outcomes without executing transactions * * @example * ```typescript * const quoter = new ReadQuoter("0x..."); * const quote = await quoter.quoteExactInput({ * tokenIn: "0x...", * tokenOut: "0x...", * amountIn: 1000000n, * fee: 3000, * sqrtPriceLimitX96: 0n * }); * ``` */ export class ReadQuoter { /** * Create a ReadQuoter instance * @param quoteV2Address - Contract address of the QuoterV2 * @param univ2RouterAddress - Contract address of the Uniswap V2 Router * @param drift - Drift instance for blockchain interaction (defaults to new instance) */ constructor(quoteV2Address, univ2RouterAddress, drift = createDrift()) { this.quoter = drift.contract({ abi: quoterV2Abi, address: quoteV2Address, }); this.univ2Router = drift.contract({ abi: uniswapV2Router02Abi, address: univ2RouterAddress, }); } /** * Get a price quote for swapping an exact amount of input tokens * @param params - Arguments for the quoteExactInputSingle contract method * @param options - Formatting options for the output amount, defaults to 18 decimals * @returns Promise resolving to: * - Raw contract return values */ async quoteExactInputV3(params) { return await this.quoter.simulateWrite("quoteExactInputSingle", { params: { ...params }, }); } /** * Get a price quote for receiving an exact amount of output tokens * @param params - Arguments for the quoteExactOutputSingle contract method * @param options - Formatting options for the input amount, defaults to 18 decimals * @returns Promise resolving to: * - Raw contract return values */ async quoteExactOutputV3(params) { return await this.quoter.simulateWrite("quoteExactOutputSingle", { params: { ...params }, }); } /** * Get a price quote for swapping an exact amount of input tokens using Uniswap V2 * @param params - Arguments for the swapExactTokensForTokens contract method containing: * - amountIn: Exact amount of input tokens to swap * - amountOutMin: Minimum amount of output tokens to receive * - path: Array of token addresses representing swap path * - to: Recipient address of output tokens * - deadline: Unix timestamp deadline for transaction validity * @returns Promise resolving to raw contract return values including: * - amounts: Array of input/output amounts at each swap step */ async quoteExactInputV2(params) { return await this.univ2Router.read("getAmountsOut", { ...params, }); } /** * Get a price quote for receiving an exact amount of output tokens using Uniswap V2 * @param params - Arguments for the swapExactTokensForTokens contract method containing: * - amountOut: Exact amount of output tokens to receive * - amountInMax: Maximum amount of input tokens to spend * - path: Array of token addresses representing swap path * - to: Recipient address of output tokens * - deadline: Unix timestamp deadline for transaction validity * @returns Promise resolving to raw contract return values including: * - amounts: Array of input/output amounts at each swap step */ async quoteExactOutputV2(params) { return await this.univ2Router.read("getAmountsIn", { ...params, }); } } //# sourceMappingURL=ReadQuoter.js.map