Get price quotes without executing trades
function getQuoteBuy( address tokenAddress, uint256 ethAmount ) external view returns (uint256)
import { ethers } from 'ethers' const factory = new ethers.Contract( TOKEN_FACTORY_ADDRESS, FACTORY_ABI, provider ) async function getQuote(tokenAddress: string, ethAmount: string) { const amountInWei = ethers.utils.parseEther(ethAmount) const tokensOut = await factory.getQuoteBuy( tokenAddress, amountInWei ) console.log(`Tokens out: ${ethers.utils.formatEther(tokensOut)}`) const pricePerToken = amountInWei.mul(1e18).div(tokensOut) console.log(`Price per token: ${ethers.utils.formatEther(pricePerToken)} ETH`) return tokensOut }
function getQuoteSell( address tokenAddress, uint256 tokenAmount ) external view returns (uint256)
async function getSellQuote( tokenAddress: string, tokenAmount: string ) { const amount = ethers.utils.parseEther(tokenAmount) const ethOut = await factory.getQuoteSell( tokenAddress, amount ) console.log(`ETH out (before fees): ${ethers.utils.formatEther(ethOut)}`) const feePercent = await factory.getCurrentFeePercent( tokenAddress, await signer.getAddress() ) const feeAmount = ethOut.mul(feePercent).div(10000) const ethAfterFees = ethOut.sub(feeAmount) console.log(`ETH after fees: ${ethers.utils.formatEther(ethAfterFees)}`) return ethAfterFees }