Skip to content

Instantly share code, notes, and snippets.

@snowkidind
Created July 15, 2022 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snowkidind/ffb651cd2c9f11bd4d6ef10a7d89d8f8 to your computer and use it in GitHub Desktop.
Save snowkidind/ffb651cd2c9f11bd4d6ef10a7d89d8f8 to your computer and use it in GitHub Desktop.
const env = require('node-env-file')
env(__dirname + '/../.env')
const { ethers, BigNumber } = require('ethers')
const { dbCurrency } = require('../db')
const { multiEth, dateutils, decimals } = require('../utils')
const { round, weiToDisplay, displayToWei, bigD, d } = decimals
const { getProvider, newSigner } = multiEth
const provider = getProvider('mainnet')
const quoterAbi = require('../utils/lib/uniswapQuoter.json')
// the quoter contract
const quoterAddr = '0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6'
const quoter = new ethers.Contract(quoterAddr, quoterAbi, provider)
const pools = [
['0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640', 'WETH', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 'USDC', '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 500],
['0x99ac8ca7087fa4a2a1fb6357269965a2014abc35', 'WBTC', '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', 'USDC', '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 3000],
['0x3416cF6C708Da44DB2624D63ea0AAef7113527C6', 'USDT', '0xdAC17F958D2ee523a2206206994597C13D831ec7', 'USDC', '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 100],
['0x122c12fcab68cb8cd96615c636ac44999ba90f2b', 'SFI', '0xb753428af26E81097e7fD17f40c88aaA3E04902c', 'WETH', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 3000], // in this case, the SFI v3 pool has no liquidity
['0xa6cc3c2531fdaa6ae1a3ca84c2855806728693e8', 'LINK', '0x514910771AF9Ca656af840dff83E8264EcF986CA', 'WETH', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 3000],
['0x6ce6d6d40a4c4088309293b0582372a2e6bb632e', 'STG', '0xAf5191B0De278C7286d6C7CC6ab6BB8A73bA2Cd6', 'WETH', '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 3000]
]
; (async () => {
try {
let ethPrice
for (let i = 0; i < pools.length; i++) {
const fromCurrency = await dbCurrency.getCurrency(pools[i][1], 'mainnet')
const toCurrency = await dbCurrency.getCurrency(pools[i][3], 'mainnet')
const from = pools[i][2]
const to = pools[i][4]
const poolFee = pools[i][5]
const amountIn = ethers.utils.parseUnits("1", fromCurrency.decimals)
const sqrtPriceLimitX96 = 0
const amountOut = await quoter.callStatic.quoteExactInputSingle(
from,
to,
poolFee,
amountIn,
sqrtPriceLimitX96
)
let last = bigD(ethers.utils.formatUnits(amountOut, toCurrency.decimals))
if (pools[i][3]=== 'WETH'){
lastUsd = ethPrice.multiply(last)
console.log(pools[i][1] + '-' + pools[i][3] + ': ' + last.getValue())
console.log(pools[i][1] + '-' + pools[i][3] + '-USDC: ' + lastUsd.getValue())
} else {
console.log(pools[i][1] + '-' + pools[i][3] + ': ' + last.getValue())
}
if (i === 1) {
ethPrice = last
}
}
} catch (error) {
console.log(error)
}
process.exit()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment