mirror of
https://github.com/0xbow-io/privacy-pools-core.git
synced 2026-01-09 01:17:58 -05:00
refactor: using quote service
This commit is contained in:
@@ -2,7 +2,8 @@ import { NextFunction, Request, Response } from "express";
|
||||
import { getAddress } from "viem";
|
||||
import { getAssetConfig, getFeeReceiverAddress } from "../../config/index.js";
|
||||
import { QuoterError } from "../../exceptions/base.exception.js";
|
||||
import { quoteProvider, web3Provider } from "../../providers/index.js";
|
||||
import { web3Provider } from "../../providers/index.js";
|
||||
import { quoteService } from "../../services/index.js";
|
||||
import { QuoteMarshall } from "../../types.js";
|
||||
import { encodeWithdrawalData } from "../../utils.js";
|
||||
|
||||
@@ -16,17 +17,15 @@ export async function relayQuoteHandler(
|
||||
|
||||
const chainId = Number(req.body.chainId!);
|
||||
const amountIn = BigInt(req.body.amount!.toString());
|
||||
const tokenAddress = getAddress(req.body.asset!.toString())
|
||||
const assetAddress = getAddress(req.body.asset!.toString())
|
||||
|
||||
const config = getAssetConfig(chainId, tokenAddress);
|
||||
const config = getAssetConfig(chainId, assetAddress);
|
||||
if (config === undefined)
|
||||
return next(QuoterError.assetNotSupported(`Asset ${tokenAddress} for chain ${chainId} is not supported`));
|
||||
return next(QuoterError.assetNotSupported(`Asset ${assetAddress} for chain ${chainId} is not supported`));
|
||||
|
||||
const gasPrice = await web3Provider.getGasPrice(chainId);
|
||||
const value = 0n; // for future features
|
||||
|
||||
const quote = await quoteProvider.quoteNativeTokenInERC20(chainId, tokenAddress, amountIn);
|
||||
const feeBPS = await quoteProvider.quoteFeeBPSNative(config.fee_bps, amountIn, quote, gasPrice, value);
|
||||
const feeBPS = await quoteService.quoteFeeBPSNative({
|
||||
chainId, amountIn, assetAddress, baseFeeBPS: config.fee_bps, value: 0n
|
||||
});
|
||||
|
||||
const recipient = req.body.recipient ? getAddress(req.body.recipient.toString()) : undefined
|
||||
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
import { uniswapService } from "./index.js";
|
||||
import { Address } from "viem";
|
||||
import { quoteProvider, web3Provider } from "../providers/index.js";
|
||||
|
||||
interface QuoteFeeBPSParams {
|
||||
chainId: number,
|
||||
assetAddress: Address,
|
||||
amountIn: bigint,
|
||||
value: bigint,
|
||||
baseFeeBPS: bigint
|
||||
};
|
||||
|
||||
export class QuoteService {
|
||||
|
||||
static feeNet: bigint = 100n;
|
||||
static txCost: bigint = 700_000n;
|
||||
|
||||
static async quoteFeeBPSNative(balance: bigint, nativeQuote: bigint, gasPrice: bigint, value: bigint): Promise<bigint> {
|
||||
let tokenQuote = await uniswapService.quote({
|
||||
chainId: 137,
|
||||
inToken: "0x0000000000000000000000000000000000000000",
|
||||
outToken: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
|
||||
inAmount: 10000000000000000000n
|
||||
});
|
||||
console.log(tokenQuote)
|
||||
return 0n
|
||||
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);
|
||||
return feeBPS
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user