tokenbridge/monitor/utils/events.js
Przemyslaw Rzad 8b010f887d
Consistent variable naming (#198)
* Add console.table

* First steps in validate script

* env rename

* Added parameter names

* Descriptions

* Print and configuration

* Added more parameters

* Rename gas oracle to gas supplier

* More changes

* Removed env examples for now

* RPC rename

* Bridge address rename

* More changes

* jobs

* Renames

* Typo

* jobs

* Changes

* jobs

* Changes

* Monitor changes

* jovs

* Typo

* Changes

* REACT_APP_ env prefix

* Typo

* Rollback changes

* Oracle deployment

* Defaults

* Monitor

* Naming

* Typo

* Typo

* Envs

* ui deployment

* ALl jobs

* Vars in ultimate

* Lint

* Lint

* Lint

* Another way to add REACT_APP prefixing

* Unnecessary mapping

* No output timeout

* No output timeout

* Got rid of ERC20_TOKEN_ADDRESS

* Configuration readme

* Configuration

* Prefixes

* timeout

* Docs

* Docs

* docs

* docs

* docs

* Roll back ERC20_TOKEN_ADDRESS for erc-to-erc

* Typo

* lint

* Rollback

* ROllback validator

* Rollback yarn.lock

* dai and wetc update

* Rollback ERC20_TOKEN_ADDRESS

* erc to native

* examples

* all jobs

* roll back

* roll back ERC20_TOKEN_ADDRESS: "0xdbeE25CbE97e4A5CC6c499875774dc7067E9426B"

* ui env example

* typo

* Allow rpc for ultimate

* Test

* ERC20_TOKEN_ADDRESS rollback

* Specify port

* React port

* All jobs

* cosmetics

* Values

* Restore erc20 token

* Rearrange example for easier comparision

* Rearrange ultimate for easier comparision

* Rearrange for easier comparision

* Refactor

* Conditional app styles

* Loading environment variables in react app

* Add missing vars for UI in wetc and dai

* Bring back test parameters readme

* Readme for monitor vars

* Reading environment variables in e2e-commons (#207)
2019-09-13 09:11:38 +02:00

100 lines
3.5 KiB
JavaScript

require('dotenv').config()
const Web3 = require('web3')
const { toBN } = require('web3').utils
const logger = require('../logger')('eventsUtils')
const {
BRIDGE_MODES,
ERC_TYPES,
getBridgeABIs,
getBridgeMode,
HOME_ERC_TO_ERC_ABI,
ERC20_ABI,
ERC677_BRIDGE_TOKEN_ABI,
getTokenType,
getPastEvents
} = require('../../commons')
const {
COMMON_HOME_RPC_URL,
COMMON_FOREIGN_RPC_URL,
COMMON_HOME_BRIDGE_ADDRESS,
COMMON_FOREIGN_BRIDGE_ADDRESS
} = process.env
const MONITOR_HOME_START_BLOCK = toBN(Number(process.env.MONITOR_HOME_START_BLOCK) || 0)
const MONITOR_FOREIGN_START_BLOCK = toBN(Number(process.env.MONITOR_FOREIGN_START_BLOCK) || 0)
const homeProvider = new Web3.providers.HttpProvider(COMMON_HOME_RPC_URL)
const web3Home = new Web3(homeProvider)
const foreignProvider = new Web3.providers.HttpProvider(COMMON_FOREIGN_RPC_URL)
const web3Foreign = new Web3(foreignProvider)
const { getBlockNumber } = require('./contract')
async function main(mode) {
const homeErcBridge = new web3Home.eth.Contract(HOME_ERC_TO_ERC_ABI, COMMON_HOME_BRIDGE_ADDRESS)
const bridgeMode = mode || (await getBridgeMode(homeErcBridge))
const { HOME_ABI, FOREIGN_ABI } = getBridgeABIs(bridgeMode)
const homeBridge = new web3Home.eth.Contract(HOME_ABI, COMMON_HOME_BRIDGE_ADDRESS)
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
const v1Bridge = bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1
const erc20MethodName = bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC || v1Bridge ? 'erc677token' : 'erc20token'
const erc20Address = await foreignBridge.methods[erc20MethodName]().call()
const tokenType = await getTokenType(
new web3Foreign.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, erc20Address),
COMMON_FOREIGN_BRIDGE_ADDRESS
)
const isExternalErc20 = tokenType === ERC_TYPES.ERC20
const erc20Contract = new web3Foreign.eth.Contract(ERC20_ABI, erc20Address)
logger.debug('getting last block numbers')
const [homeBlockNumber, foreignBlockNumber] = await getBlockNumber(web3Home, web3Foreign)
logger.debug("calling homeBridge.getPastEvents('UserRequestForSignature')")
const homeDeposits = await getPastEvents(homeBridge, {
event: v1Bridge ? 'Deposit' : 'UserRequestForSignature',
fromBlock: MONITOR_HOME_START_BLOCK,
toBlock: homeBlockNumber
})
logger.debug("calling foreignBridge.getPastEvents('RelayedMessage')")
const foreignDeposits = await getPastEvents(foreignBridge, {
event: v1Bridge ? 'Deposit' : 'RelayedMessage',
fromBlock: MONITOR_FOREIGN_START_BLOCK,
toBlock: foreignBlockNumber
})
logger.debug("calling homeBridge.getPastEvents('AffirmationCompleted')")
const homeWithdrawals = await getPastEvents(homeBridge, {
event: v1Bridge ? 'Withdraw' : 'AffirmationCompleted',
fromBlock: MONITOR_HOME_START_BLOCK,
toBlock: homeBlockNumber
})
logger.debug("calling foreignBridge.getPastEvents('UserRequestForAffirmation')")
const foreignWithdrawals = isExternalErc20
? await getPastEvents(erc20Contract, {
event: 'Transfer',
fromBlock: MONITOR_FOREIGN_START_BLOCK,
toBlock: foreignBlockNumber,
options: {
filter: { to: COMMON_FOREIGN_BRIDGE_ADDRESS }
}
})
: await getPastEvents(foreignBridge, {
event: v1Bridge ? 'Withdraw' : 'UserRequestForAffirmation',
fromBlock: MONITOR_FOREIGN_START_BLOCK,
toBlock: foreignBlockNumber
})
logger.debug('Done')
return {
homeDeposits,
foreignDeposits,
homeWithdrawals,
foreignWithdrawals,
isExternalErc20
}
}
module.exports = main