Skip to content

Instantly share code, notes, and snippets.

@nazt
Forked from earthchie/DOP_price_monitor.js
Created May 30, 2021 12:18
Show Gist options
  • Save nazt/f454b09e1145e93c5285448204d1a1b6 to your computer and use it in GitHub Desktop.
Save nazt/f454b09e1145e93c5285448204d1a1b6 to your computer and use it in GitHub Desktop.

Revisions

  1. @earthchie earthchie revised this gist May 30, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions DOP_price_monitor.js
    Original file line number Diff line number Diff line change
    @@ -11,11 +11,11 @@ let Contract = {
    provider.on('block', async (blockNumber) => {

    const pancakeReserves = await Contract.PancakePair.getReserves();
    const at_pancake = Number(ethers.utils.formatUnits(pancakeReserves[1], 18)) / Number(ethers.utils.formatUnits(pancakeReserves[0], 18));
    const at_pancake = pancakeReserves[1] / pancakeReserves[0];
    console.log(`Pancake 1 DOP = ${at_pancake} BUSD`);

    const twindexReserves = await Contract.TwindexPair.getReserves();
    const at_twindex = Number(ethers.utils.formatUnits(twindexReserves[1], 18)) / Number(ethers.utils.formatUnits(twindexReserves[0], 18));
    const at_twindex = twindexReserves[1] / twindexReserves[0];
    console.log(`Twindex 1 DOP = ${at_twindex} BUSD`);

    });
  2. @earthchie earthchie revised this gist May 30, 2021. 1 changed file with 13 additions and 18 deletions.
    31 changes: 13 additions & 18 deletions DOP_price_monitor.js
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,21 @@
    const ethers = require('ethers');

    const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org/');
    const BEP20 = {
    BUSD: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
    DOP: '0x844fa82f1e54824655470970f7004dd90546bb28'
    };
    const Contract = {
    PancakeRouter: new ethers.Contract('0x10ED43C718714eb63d5aA57B78B54704E256024E', ['function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)'], provider),
    TwindexRouter: new ethers.Contract('0xBCB41906bE2C2724A8CD0dec87512B2463535586', ['function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)'], provider),
    Dopple: new ethers.Contract(BEP20.DOP, ['event Transfer(address indexed from, address indexed to, uint256 value)'], provider)

    // 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)
    }

    Contract.Dopple.on('Transfer', async (from, to, amount, event) => {

    const One = ethers.utils.parseUnits('1', 18);

    let at_pancake = await Contract.PancakeRouter.getAmountsOut(One, [BEP20.DOP, BEP20.BUSD]);
    at_pancake = at_pancake[1].toString() / 1e18;
    provider.on('block', async (blockNumber) => {

    const pancakeReserves = await Contract.PancakePair.getReserves();
    const at_pancake = Number(ethers.utils.formatUnits(pancakeReserves[1], 18)) / Number(ethers.utils.formatUnits(pancakeReserves[0], 18));
    console.log(`Pancake 1 DOP = ${at_pancake} BUSD`);

    let at_twindex = await Contract.TwindexRouter.getAmountsOut(One, [BEP20.DOP, BEP20.BUSD]);
    at_twindex = at_twindex[1].toString() / 1e18;
    const twindexReserves = await Contract.TwindexPair.getReserves();
    const at_twindex = Number(ethers.utils.formatUnits(twindexReserves[1], 18)) / Number(ethers.utils.formatUnits(twindexReserves[0], 18));
    console.log(`Twindex 1 DOP = ${at_twindex} BUSD`);

    });
  3. @earthchie earthchie revised this gist May 24, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions DOP_price_monitor.js
    Original file line number Diff line number Diff line change
    @@ -17,10 +17,10 @@ Contract.Dopple.on('Transfer', async (from, to, amount, event) => {

    let at_pancake = await Contract.PancakeRouter.getAmountsOut(One, [BEP20.DOP, BEP20.BUSD]);
    at_pancake = at_pancake[1].toString() / 1e18;
    console.log('Pancake 1 DOP = ${at_pancake} BUSD');
    console.log(`Pancake 1 DOP = ${at_pancake} BUSD`);

    let at_twindex = await Contract.TwindexRouter.getAmountsOut(One, [BEP20.DOP, BEP20.BUSD]);
    at_twindex = at_twindex[1].toString() / 1e18;
    console.log('Twindex 1 DOP = ${at_twindex} BUSD');
    console.log(`Twindex 1 DOP = ${at_twindex} BUSD`);

    });
  4. @earthchie earthchie revised this gist May 24, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion DOP_price_monitor.js
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ const Contract = {
    Dopple: new ethers.Contract(BEP20.DOP, ['event Transfer(address indexed from, address indexed to, uint256 value)'], provider)
    }

    Contract.Dopple.on('Transfer', (from, to, amount, event) => {
    Contract.Dopple.on('Transfer', async (from, to, amount, event) => {

    const One = ethers.utils.parseUnits('1', 18);

  5. @earthchie earthchie revised this gist May 24, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions DOP_price_monitor.js
    Original file line number Diff line number Diff line change
    @@ -17,10 +17,10 @@ Contract.Dopple.on('Transfer', (from, to, amount, event) => {

    let at_pancake = await Contract.PancakeRouter.getAmountsOut(One, [BEP20.DOP, BEP20.BUSD]);
    at_pancake = at_pancake[1].toString() / 1e18;
    console.log('Pancake 1 DOP = ${at_pancake}');
    console.log('Pancake 1 DOP = ${at_pancake} BUSD');

    let at_twindex = await Contract.TwindexRouter.getAmountsOut(One, [BEP20.DOP, BEP20.BUSD]);
    at_twindex = at_twindex[1].toString() / 1e18;
    console.log('Twindex 1 DOP = ${at_twindex}');
    console.log('Twindex 1 DOP = ${at_twindex} BUSD');

    });
  6. @earthchie earthchie created this gist May 24, 2021.
    26 changes: 26 additions & 0 deletions DOP_price_monitor.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    const ethers = require('ethers');

    const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org/');
    const BEP20 = {
    BUSD: '0xe9e7cea3dedca5984780bafc599bd69add087d56',
    DOP: '0x844fa82f1e54824655470970f7004dd90546bb28'
    };
    const Contract = {
    PancakeRouter: new ethers.Contract('0x10ED43C718714eb63d5aA57B78B54704E256024E', ['function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)'], provider),
    TwindexRouter: new ethers.Contract('0xBCB41906bE2C2724A8CD0dec87512B2463535586', ['function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)'], provider),
    Dopple: new ethers.Contract(BEP20.DOP, ['event Transfer(address indexed from, address indexed to, uint256 value)'], provider)
    }

    Contract.Dopple.on('Transfer', (from, to, amount, event) => {

    const One = ethers.utils.parseUnits('1', 18);

    let at_pancake = await Contract.PancakeRouter.getAmountsOut(One, [BEP20.DOP, BEP20.BUSD]);
    at_pancake = at_pancake[1].toString() / 1e18;
    console.log('Pancake 1 DOP = ${at_pancake}');

    let at_twindex = await Contract.TwindexRouter.getAmountsOut(One, [BEP20.DOP, BEP20.BUSD]);
    at_twindex = at_twindex[1].toString() / 1e18;
    console.log('Twindex 1 DOP = ${at_twindex}');

    });