// eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore import { QuoterV2 } from '@uniswap/v3-periphery'; import { QuoteEngine, QuoteExactInputSingleParams, QuoteExactInputSingleResult, QuoteExactOutputSingleParams, QuoteExactOutputSingleResult, } from './quote-engine'; export class UniswapV3QuoteEngine implements QuoteEngine { public quoter: QuoterV2; constructor(quoter: QuoterV2) { this.quoter = quoter; } async quoteExactInputSingle( params: QuoteExactInputSingleParams, ): Promise { const fee = params.fee; if (fee === undefined) throw new Error('fee is required for UniswapV3QuoteEngine'); const quoteFn = this.quoter.getFunction('quoteExactInputSingle'); const q = await quoteFn.staticCall({ tokenIn: params.tokenIn, tokenOut: params.tokenOut, amountIn: params.amountIn, fee, sqrtPriceLimitX96: params.sqrtPriceLimitX96 ?? 0, }); return { amountOut: BigInt(q.amountOut.toString()), sqrtPriceX96After: BigInt(q.sqrtPriceX96After.toString()), }; } async quoteExactOutputSingle( params: QuoteExactOutputSingleParams, ): Promise { const fee = params.fee; if (fee === undefined) throw new Error('fee is required for UniswapV3QuoteEngine'); const quoteFn = this.quoter.getFunction('quoteExactOutputSingle'); const q = await quoteFn.staticCall({ tokenIn: params.tokenIn, tokenOut: params.tokenOut, amount: params.amountOut, fee, sqrtPriceLimitX96: params.sqrtPriceLimitX96 ?? 0, }); // QuoterV2 returns amountIn for output quotes return { amountIn: BigInt(q.amountIn.toString()), sqrtPriceX96After: BigInt(q.sqrtPriceX96After.toString()), }; } }