-
Notifications
You must be signed in to change notification settings - Fork 4
/
uniswap-watcher.js
36 lines (31 loc) · 1.17 KB
/
uniswap-watcher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// this loads the pooled liquidities on uniswap
// and allows calculating DTC / ETH price
let tokenAddress = config.ethContractAddress
let wethAddress = config.wethTokenAddress
let uniswapWallet = config.uniswapPoolAddress
let minErc20ABI = [
{
"constant":true,
"inputs":[{"name":"_owner","type":"address"}],
"name":"balanceOf",
"outputs":[{"name":"balance","type":"uint256"}],
"type":"function"
}
];
const Web3 = require('web3')
let web3 = new Web3('https://mainnet.infura.io/v3/'+config.infuraKey);
module.exports = async function(cb) {
let contractDtc = new web3.eth.Contract(minErc20ABI, tokenAddress)
let contractWeth = new web3.eth.Contract(minErc20ABI, wethAddress)
let balanceDtc = await contractDtc.methods.balanceOf(uniswapWallet).call()
let balanceWeth = await contractWeth.methods.balanceOf(uniswapWallet).call()
balanceDtc /= Math.pow(10,2)
balanceWeth /= Math.pow(10,18)
if (balanceWeth / balanceDtc != dtcEther) {
dtcEther = balanceWeth / balanceDtc
console.log('UNI Pool: '+balanceDtc+' DTUBE + '+balanceWeth+' ETH')
console.log('DTUBE/ETH = '+dtcEther)
updateFee()
}
if (cb) cb()
}