mirror of
https://github.com/0xbow-io/privacy-pools-core.git
synced 2026-01-09 01:17:58 -05:00
feat: adding quote case for native asset
This commit is contained in:
@@ -3,9 +3,6 @@ import { uniswapProvider } from "./index.js";
|
||||
|
||||
export class QuoteProvider {
|
||||
|
||||
// a typical withdrawal costs between 450k-650k gas
|
||||
static txCost: bigint = 700_000n;
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
@@ -14,9 +11,4 @@ export class QuoteProvider {
|
||||
return { num: out.amount, den: in_.amount };
|
||||
}
|
||||
|
||||
async quoteFeeBPSNative(baseFee: bigint, balance: bigint, nativeQuote: { num: bigint, den: bigint }, gasPrice: bigint, value: bigint): Promise<bigint> {
|
||||
const nativeCosts = (1n * gasPrice * QuoteProvider.txCost + value)
|
||||
return baseFee + nativeQuote.den * 10_000n * nativeCosts / balance / nativeQuote.num;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,13 +9,34 @@ interface QuoteFeeBPSParams {
|
||||
baseFeeBPS: bigint
|
||||
};
|
||||
|
||||
const NativeAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
||||
|
||||
export class QuoteService {
|
||||
|
||||
readonly txCost: bigint;
|
||||
|
||||
constructor() {
|
||||
// a typical withdrawal costs between 450k-650k gas
|
||||
this.txCost = 700_000n;
|
||||
}
|
||||
|
||||
async netFeeBPSNative(baseFee: bigint, balance: bigint, nativeQuote: { num: bigint, den: bigint }, gasPrice: bigint, value: bigint): Promise<bigint> {
|
||||
const nativeCosts = (1n * gasPrice * this.txCost + value)
|
||||
return baseFee + nativeQuote.den * 10_000n * nativeCosts / balance / nativeQuote.num;
|
||||
}
|
||||
|
||||
async quoteFeeBPSNative(quoteParams: QuoteFeeBPSParams): Promise<bigint> {
|
||||
const { chainId, assetAddress, amountIn, baseFeeBPS, value } = quoteParams;
|
||||
const gasPrice = await web3Provider.getGasPrice(chainId);
|
||||
const quote = await quoteProvider.quoteNativeTokenInERC20(chainId, assetAddress, amountIn);
|
||||
const feeBPS = await quoteProvider.quoteFeeBPSNative(baseFeeBPS, amountIn, quote, gasPrice, value);
|
||||
|
||||
let quote: { num: bigint, den: bigint };
|
||||
if (assetAddress.toLowerCase() === NativeAddress.toLowerCase()) {
|
||||
quote = { num: 1n, den: 1n };
|
||||
} else {
|
||||
quote = await quoteProvider.quoteNativeTokenInERC20(chainId, assetAddress, amountIn);
|
||||
}
|
||||
|
||||
const feeBPS = await this.netFeeBPSNative(baseFeeBPS, amountIn, quote, gasPrice, value);
|
||||
return feeBPS
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user