mirror of
https://github.com/0xbow-io/privacy-pools-core.git
synced 2026-01-09 17:37: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 { getAddress } from "viem";
|
||||||
import { getAssetConfig, getFeeReceiverAddress } from "../../config/index.js";
|
import { getAssetConfig, getFeeReceiverAddress } from "../../config/index.js";
|
||||||
import { QuoterError } from "../../exceptions/base.exception.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 { QuoteMarshall } from "../../types.js";
|
||||||
import { encodeWithdrawalData } from "../../utils.js";
|
import { encodeWithdrawalData } from "../../utils.js";
|
||||||
|
|
||||||
@@ -16,17 +17,15 @@ export async function relayQuoteHandler(
|
|||||||
|
|
||||||
const chainId = Number(req.body.chainId!);
|
const chainId = Number(req.body.chainId!);
|
||||||
const amountIn = BigInt(req.body.amount!.toString());
|
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)
|
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 feeBPS = await quoteService.quoteFeeBPSNative({
|
||||||
const value = 0n; // for future features
|
chainId, amountIn, assetAddress, baseFeeBPS: config.fee_bps, value: 0n
|
||||||
|
});
|
||||||
const quote = await quoteProvider.quoteNativeTokenInERC20(chainId, tokenAddress, amountIn);
|
|
||||||
const feeBPS = await quoteProvider.quoteFeeBPSNative(config.fee_bps, amountIn, quote, gasPrice, value);
|
|
||||||
|
|
||||||
const recipient = req.body.recipient ? getAddress(req.body.recipient.toString()) : undefined
|
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 {
|
export class QuoteService {
|
||||||
|
|
||||||
static feeNet: bigint = 100n;
|
async quoteFeeBPSNative(quoteParams: QuoteFeeBPSParams): Promise<bigint> {
|
||||||
static txCost: bigint = 700_000n;
|
const { chainId, assetAddress, amountIn, baseFeeBPS, value } = quoteParams;
|
||||||
|
const gasPrice = await web3Provider.getGasPrice(chainId);
|
||||||
static async quoteFeeBPSNative(balance: bigint, nativeQuote: bigint, gasPrice: bigint, value: bigint): Promise<bigint> {
|
const quote = await quoteProvider.quoteNativeTokenInERC20(chainId, assetAddress, amountIn);
|
||||||
let tokenQuote = await uniswapService.quote({
|
const feeBPS = await quoteProvider.quoteFeeBPSNative(baseFeeBPS, amountIn, quote, gasPrice, value);
|
||||||
chainId: 137,
|
return feeBPS
|
||||||
inToken: "0x0000000000000000000000000000000000000000",
|
|
||||||
outToken: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
|
|
||||||
inAmount: 10000000000000000000n
|
|
||||||
});
|
|
||||||
console.log(tokenQuote)
|
|
||||||
return 0n
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user