const chainId = 8; const name = "Ubiq"; const gransContractAddress = "0x0826180A4c981d5095Cb5c48BB2A098A44cf6f73"; const gransDecimals = 18; const { ethers } = require("ethers"); const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545", {name, chainId}); const UNISWAP = require('shinobi-sdk'); const CoinGecko = require('coingecko-api'); const CoinGeckoClient = new CoinGecko(); /* const WUBQ = { [chainId]: new UNISWAP.Token( chainId, "0x1FA6A37c64804C0D797bA6bC1955E50068FbF362", // wrapped ubiq erc20 contract 18, "WUBQ", "Wrapped Ubiq" ) } */ const GRANS = new UNISWAP.Token(chainId, gransContractAddress, gransDecimals); UNISWAP.Fetcher.fetchPairData(GRANS, UNISWAP.WETH[GRANS.chainId], provider).then(async pair => { const route = new UNISWAP.Route([pair], UNISWAP.WETH[GRANS.chainId]); const gransPerUbiq = route.midPrice.toSignificant(6); const ubiqPerGrans = route.midPrice.invert().toSignificant(6); const conversionData = await CoinGeckoClient.simple.price({ids: 'ubiq', vs_currencies: 'usd'}); const ubiqRate = conversionData.data.ubiq.usd; const dollarsPerGrans = (ubiqPerGrans * ubiqRate).toFixed(2); console.log(`1 GRANS is $${dollarsPerGrans}`); });