Skip to content

Instantly share code, notes, and snippets.

@lifez
Forked from earthchie/DOP_price_monitor.js
Created June 18, 2021 03:42
Show Gist options
  • Save lifez/7f5d39f087c2be84dc7c1c8e89478cc6 to your computer and use it in GitHub Desktop.
Save lifez/7f5d39f087c2be84dc7c1c8e89478cc6 to your computer and use it in GitHub Desktop.
const ethers = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org/');
// you can find pair address from Factory Contract, method getPair(token1Addr, token2Addr).
let Contract = {
PancakePair: new ethers.Contract('0xb694ec7C2a7C433E69200b1dA3EBc86907B4578B',['function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)'], provider),
TwindexPair: new ethers.Contract('0xC789F6C658809eED4d1769a46fc7BCe5dbB8316E',['function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)'], provider)
}
provider.on('block', async (blockNumber) => {
const pancakeReserves = await Contract.PancakePair.getReserves();
const at_pancake = pancakeReserves[1] / pancakeReserves[0];
console.log(`Pancake 1 DOP = ${at_pancake} BUSD`);
const twindexReserves = await Contract.TwindexPair.getReserves();
const at_twindex = twindexReserves[1] / twindexReserves[0];
console.log(`Twindex 1 DOP = ${at_twindex} BUSD`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment