feat: quote provider

This commit is contained in:
Francisco Bezzecchi
2025-04-04 13:53:42 -03:00
parent 76ddd6eb42
commit 01d353d466

View File

@@ -0,0 +1,21 @@
import { Address } from "viem";
import { uniswapProvider } from "./index.js";
export class QuoteProvider {
static txCost: bigint = 700_000n;
constructor(readonly baseFee: bigint) {
}
async quoteNativeTokenInERC20(chainId: number, addressIn: Address, amountIn: bigint): Promise<{ num: bigint, den: bigint }> {
const { in: in_, out } = (await uniswapProvider.quoteNativeToken(chainId, addressIn, amountIn))!;
return { num: out.amount, den: in_.amount };
}
async quoteFeeBPSNative(balance: bigint, nativeQuote: { num: bigint, den: bigint }, gasPrice: bigint, value: bigint): Promise<bigint> {
const nativeCosts = (1n * gasPrice * QuoteProvider.txCost + value)
return this.baseFee + nativeQuote.den * 10_000n * nativeCosts / balance / nativeQuote.num;
}
}