Monitor using commons (#143)

This commit is contained in:
Przemyslaw Rzad 2019-07-12 14:49:46 +02:00 committed by GitHub
parent 2e89d7724a
commit 208cfafa95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 30 additions and 262 deletions

@ -3,6 +3,7 @@ FROM node:8
WORKDIR /mono
COPY package.json .
COPY contracts/package.json ./contracts/
COPY commons/package.json ./commons/
COPY monitor/package.json ./monitor/
COPY yarn.lock .
RUN yarn install --frozen-lockfile --production
@ -11,6 +12,8 @@ COPY ./contracts ./contracts
RUN yarn run compile:contracts
RUN mv ./contracts/build ./ && rm -rf ./contracts/* ./contracts/.[!.]* && mv ./build ./contracts/
COPY ./commons ./commons
COPY ./monitor ./monitor
WORKDIR /mono/monitor
CMD echo "To start the monitor run:" \

@ -2,7 +2,7 @@ const fs = require('fs')
const path = require('path')
const Web3 = require('web3')
const logger = require('./logger')('checkWorker')
const { getBridgeMode } = require('./utils/bridgeMode')
const { getBridgeMode } = require('../commons')
const getBalances = require('./getBalances')
const getShortEventStats = require('./getShortEventStats')
const validators = require('./validators')
@ -11,7 +11,7 @@ const { HOME_BRIDGE_ADDRESS, HOME_RPC_URL } = process.env
const homeProvider = new Web3.providers.HttpProvider(HOME_RPC_URL)
const web3Home = new Web3(homeProvider)
const HOME_ERC_TO_ERC_ABI = require('../contracts/build/contracts/HomeBridgeErcToErc').abi
const { HOME_ERC_TO_ERC_ABI } = require('../commons')
async function checkWorker() {
try {

@ -2,7 +2,7 @@ require('dotenv').config()
const BN = require('bignumber.js')
const Web3 = require('web3')
const logger = require('./logger')('getBalances')
const { BRIDGE_MODES } = require('./utils/bridgeMode')
const { BRIDGE_MODES } = require('../commons')
const Web3Utils = Web3.utils
@ -14,16 +14,16 @@ const web3Home = new Web3(homeProvider)
const foreignProvider = new Web3.providers.HttpProvider(FOREIGN_RPC_URL)
const web3Foreign = new Web3(foreignProvider)
const ERC20_ABI = require('../contracts/build/contracts/ERC20').abi
const ERC677_ABI = require('../contracts/build/contracts/ERC677').abi
const HOME_ERC_TO_ERC_ABI = require('../contracts/build/contracts/HomeBridgeErcToErc').abi
const HOME_ERC_TO_NATIVE_ABI = require('../contracts/build/contracts/HomeBridgeErcToNative').abi
const BLOCK_REWARD_ABI = require('../contracts/build/contracts/IBlockReward').abi
const FOREIGN_ERC_TO_ERC_ABI = require('../contracts/build/contracts/ForeignBridgeErcToErc').abi
const FOREIGN_ERC_TO_NATIVE_ABI = require('../contracts/build/contracts/ForeignBridgeErcToNative')
.abi
const FOREIGN_NATIVE_TO_ERC_ABI = require('../contracts/build/contracts/ForeignBridgeNativeToErc')
.abi
const {
ERC20_ABI,
ERC677_ABI,
BLOCK_REWARD_ABI,
HOME_ERC_TO_ERC_ABI,
HOME_ERC_TO_NATIVE_ABI,
FOREIGN_ERC_TO_ERC_ABI,
FOREIGN_ERC_TO_NATIVE_ABI,
FOREIGN_NATIVE_TO_ERC_ABI
} = require('../commons')
async function main(bridgeMode) {
if (bridgeMode === BRIDGE_MODES.ERC_TO_ERC) {

@ -1,7 +1,7 @@
require('dotenv').config()
const Web3 = require('web3')
const logger = require('./logger')('stuckTransfers.js')
const { foreignViAbi } = require('./utils/v1Abis')
const { foreignViAbi } = require('../commons/abis')
const { FOREIGN_RPC_URL, FOREIGN_BRIDGE_ADDRESS } = process.env
const FOREIGN_DEPLOYMENT_BLOCK = Number(process.env.FOREIGN_DEPLOYMENT_BLOCK) || 0

@ -1,74 +0,0 @@
const HOME_NATIVE_TO_ERC_ABI = require('../../contracts/build/contracts/HomeBridgeNativeToErc').abi
const FOREIGN_NATIVE_TO_ERC_ABI = require('../../contracts/build/contracts/ForeignBridgeNativeToErc')
.abi
const HOME_ERC_TO_ERC_ABI = require('../../contracts/build/contracts/HomeBridgeErcToErc').abi
const FOREIGN_ERC_TO_ERC_ABI = require('../../contracts/build/contracts/ForeignBridgeErc677ToErc677')
.abi
const HOME_ERC_TO_NATIVE_ABI = require('../../contracts/build/contracts/HomeBridgeErcToNative').abi
const FOREIGN_ERC_TO_NATIVE_ABI = require('../../contracts/build/contracts/ForeignBridgeErcToNative')
.abi
const { homeV1Abi, foreignViAbi } = require('./v1Abis')
const BRIDGE_MODES = {
NATIVE_TO_ERC: 'NATIVE_TO_ERC',
ERC_TO_ERC: 'ERC_TO_ERC',
ERC_TO_NATIVE: 'ERC_TO_NATIVE',
NATIVE_TO_ERC_V1: 'NATIVE_TO_ERC_V1'
}
const ERC_TYPES = {
ERC20: 'ERC20',
ERC677: 'ERC677'
}
function getBridgeABIs(bridgeMode) {
let HOME_ABI = null
let FOREIGN_ABI = null
if (bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC) {
HOME_ABI = HOME_NATIVE_TO_ERC_ABI
FOREIGN_ABI = FOREIGN_NATIVE_TO_ERC_ABI
} else if (bridgeMode === BRIDGE_MODES.ERC_TO_ERC) {
HOME_ABI = HOME_ERC_TO_ERC_ABI
FOREIGN_ABI = FOREIGN_ERC_TO_ERC_ABI
} else if (bridgeMode === BRIDGE_MODES.ERC_TO_NATIVE) {
HOME_ABI = HOME_ERC_TO_NATIVE_ABI
FOREIGN_ABI = FOREIGN_ERC_TO_NATIVE_ABI
} else if (bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1) {
HOME_ABI = homeV1Abi
FOREIGN_ABI = foreignViAbi
} else {
throw new Error(`Unrecognized bridge mode: ${bridgeMode}`)
}
return { HOME_ABI, FOREIGN_ABI }
}
function decodeBridgeMode(bridgeModeHash) {
switch (bridgeModeHash) {
case '0x92a8d7fe':
return BRIDGE_MODES.NATIVE_TO_ERC
case '0xba4690f5':
return BRIDGE_MODES.ERC_TO_ERC
case '0x18762d46':
return BRIDGE_MODES.ERC_TO_NATIVE
default:
throw new Error(`Unrecognized bridge mode hash: '${bridgeModeHash}'`)
}
}
async function getBridgeMode(contract) {
try {
const bridgeModeHash = await contract.methods.getBridgeMode().call()
return decodeBridgeMode(bridgeModeHash)
} catch (e) {
return BRIDGE_MODES.NATIVE_TO_ERC_V1
}
}
module.exports = {
getBridgeABIs,
getBridgeMode,
BRIDGE_MODES,
ERC_TYPES
}

@ -1,4 +1,4 @@
const { ERC_TYPES } = require('./bridgeMode')
const { ERC_TYPES } = require('../../commons')
const getTokenType = async (contract, bridgeAddress) => {
try {

@ -2,7 +2,14 @@ require('dotenv').config()
const Web3 = require('web3')
const { toBN } = require('web3').utils
const logger = require('../logger')('eventsUtils')
const { BRIDGE_MODES, getBridgeMode, getBridgeABIs, ERC_TYPES } = require('./bridgeMode')
const {
BRIDGE_MODES,
ERC_TYPES,
getBridgeABIs,
getBridgeMode,
HOME_ERC_TO_ERC_ABI,
ERC20_ABI
} = require('../../commons')
const { getTokenType } = require('./ercUtils')
const { HOME_RPC_URL, FOREIGN_RPC_URL, HOME_BRIDGE_ADDRESS, FOREIGN_BRIDGE_ADDRESS } = process.env
@ -15,8 +22,6 @@ const web3Home = new Web3(homeProvider)
const foreignProvider = new Web3.providers.HttpProvider(FOREIGN_RPC_URL)
const web3Foreign = new Web3(foreignProvider)
const HOME_ERC_TO_ERC_ABI = require('../../contracts/build/contracts/HomeBridgeErcToErc').abi
const ERC20_ABI = require('../../contracts/build/contracts/ERC20').abi
const { getPastEvents, getBlockNumber } = require('./contract')
async function main(mode) {

@ -1,6 +1,5 @@
const Web3 = require('web3')
const { getBridgeMode, BRIDGE_MODES } = require('./bridgeMode')
const HOME_ERC_TO_ERC_ABI = require('../../contracts/build/contracts/HomeBridgeErcToErc').abi
const { BRIDGE_MODES, getBridgeMode, HOME_ERC_TO_ERC_ABI } = require('../../commons')
const { HOME_BRIDGE_ADDRESS, HOME_RPC_URL } = process.env
const homeProvider = new Web3.providers.HttpProvider(HOME_RPC_URL)

@ -1,163 +0,0 @@
const homeV1Abi = [
{
constant: true,
inputs: [],
name: 'validatorContract',
outputs: [
{
name: '',
type: 'address'
}
],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
anonymous: false,
inputs: [
{
indexed: false,
name: 'recipient',
type: 'address'
},
{
indexed: false,
name: 'value',
type: 'uint256'
}
],
name: 'Deposit',
type: 'event'
},
{
anonymous: false,
inputs: [
{
indexed: false,
name: 'recipient',
type: 'address'
},
{
indexed: false,
name: 'value',
type: 'uint256'
},
{
indexed: false,
name: 'transactionHash',
type: 'bytes32'
}
],
name: 'Withdraw',
type: 'event'
},
{
constant: true,
inputs: [],
name: 'deployedAtBlock',
outputs: [
{
name: '',
type: 'uint256'
}
],
payable: false,
stateMutability: 'view',
type: 'function'
}
]
const foreignViAbi = [
{
constant: true,
inputs: [],
name: 'validatorContract',
outputs: [
{
name: '',
type: 'address'
}
],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
anonymous: false,
inputs: [
{
indexed: false,
name: 'recipient',
type: 'address'
},
{
indexed: false,
name: 'value',
type: 'uint256'
},
{
indexed: false,
name: 'transactionHash',
type: 'bytes32'
}
],
name: 'Deposit',
type: 'event'
},
{
anonymous: false,
inputs: [
{
indexed: false,
name: 'recipient',
type: 'address'
},
{
indexed: false,
name: 'value',
type: 'uint256'
},
{
indexed: false,
name: 'homeGasPrice',
type: 'uint256'
}
],
name: 'Withdraw',
type: 'event'
},
{
constant: true,
inputs: [],
name: 'deployedAtBlock',
outputs: [
{
name: '',
type: 'uint256'
}
],
payable: false,
stateMutability: 'view',
type: 'function'
},
{
constant: true,
inputs: [],
name: 'erc677token',
outputs: [
{
name: '',
type: 'address'
}
],
payable: false,
stateMutability: 'view',
type: 'function'
}
]
module.exports = {
homeV1Abi,
foreignViAbi
}

@ -1,6 +1,6 @@
/* eslint no-param-reassign: ["error", { "props": false }] */
const bridgeValidatorsAbi = require('../../contracts/build/contracts/BridgeValidators').abi
const { BRIDGE_VALIDATORS_ABI } = require('../../commons')
const logger = require('../logger')('validatorsUtils')
const { getPastEvents } = require('./contract')
@ -54,7 +54,7 @@ const validatorList = async contract => {
const getValidatorList = async (address, eth, fromBlock, toBlock) => {
logger.debug('getting validatorList')
const validatorsContract = new eth.Contract(bridgeValidatorsAbi, address)
const validatorsContract = new eth.Contract(BRIDGE_VALIDATORS_ABI, address)
const validators = await validatorList(validatorsContract)
if (validators.length) {

@ -2,7 +2,7 @@ require('dotenv').config()
const Web3 = require('web3')
const fetch = require('node-fetch')
const logger = require('./logger')('validators')
const { getBridgeABIs } = require('./utils/bridgeMode')
const { getBridgeABIs, BRIDGE_VALIDATORS_ABI } = require('../commons')
const { getValidatorList } = require('./utils/validatorUtils')
const { getBlockNumber } = require('./utils/contract')
@ -26,8 +26,6 @@ const web3Home = new Web3(homeProvider)
const foreignProvider = new Web3.providers.HttpProvider(FOREIGN_RPC_URL)
const web3Foreign = new Web3(foreignProvider)
const BRIDGE_VALIDATORS_ABI = require('../contracts/build/contracts/BridgeValidators').abi
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)