Support amb balances info in monitor

This commit is contained in:
Gerardo Nardelli 2019-07-24 11:50:35 -03:00
parent 08d2c46a03
commit 3d0f68fad9
5 changed files with 57 additions and 16 deletions

@ -35,6 +35,9 @@ function getBridgeABIs(bridgeMode) {
} else if (bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1) {
HOME_ABI = homeV1Abi
FOREIGN_ABI = foreignViAbi
} else if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
HOME_ABI = HOME_AMB_ABI
FOREIGN_ABI = FOREIGN_AMB_ABI
} else {
throw new Error(`Unrecognized bridge mode: ${bridgeMode}`)
}

@ -8,6 +8,8 @@ function decodeBridgeMode(bridgeModeHash) {
return BRIDGE_MODES.ERC_TO_ERC
case '0x18762d46':
return BRIDGE_MODES.ERC_TO_NATIVE
case '0x2544fbb9':
return BRIDGE_MODES.ARBITRARY_MESSAGE
default:
throw new Error(`Unrecognized bridge mode hash: '${bridgeModeHash}'`)
}

@ -119,6 +119,22 @@ async function main(bridgeMode) {
balanceDiff: Number(Web3Utils.fromWei(diff)),
lastChecked: Math.floor(Date.now() / 1000)
}
} else if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
const homeBalance = await web3Home.eth.getBalance(HOME_BRIDGE_ADDRESS)
const foreignBalance = await web3Foreign.eth.getBalance(FOREIGN_BRIDGE_ADDRESS)
const diff = new BN(homeBalance).minus(new BN(foreignBalance)).toString()
return {
home: {
balance: Web3Utils.fromWei(homeBalance, 'ether')
},
foreign: {
balance: Web3Utils.fromWei(foreignBalance, 'ether')
},
balanceDiff: Number(Web3Utils.fromWei(diff, 'ether')),
lastChecked: Math.floor(Date.now() / 1000)
}
} else {
throw new Error(`Unrecognized bridge mode: '${bridgeMode}'`)
}

@ -1,21 +1,37 @@
require('dotenv').config()
const eventsInfo = require('./utils/events')
const { BRIDGE_MODES } = require('../commons')
async function main(bridgeMode) {
const { foreignDeposits, homeDeposits, homeWithdrawals, foreignWithdrawals } = await eventsInfo(
bridgeMode
)
return {
depositsDiff: homeDeposits.length - foreignDeposits.length,
withdrawalDiff: homeWithdrawals.length - foreignWithdrawals.length,
home: {
deposits: homeDeposits.length,
withdrawals: homeWithdrawals.length
},
foreign: {
deposits: foreignDeposits.length,
withdrawals: foreignWithdrawals.length
if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
return {
deliveryDiff: homeDeposits.length - foreignDeposits.length,
processedDiff: homeWithdrawals.length - foreignWithdrawals.length,
home: {
delivered: homeDeposits.length,
processed: homeWithdrawals.length
},
foreign: {
delivered: foreignDeposits.length,
processed: foreignWithdrawals.length
}
}
} else {
return {
depositsDiff: homeDeposits.length - foreignDeposits.length,
withdrawalDiff: homeWithdrawals.length - foreignWithdrawals.length,
home: {
deposits: homeDeposits.length,
withdrawals: homeWithdrawals.length
},
foreign: {
deposits: foreignDeposits.length,
withdrawals: foreignWithdrawals.length
}
}
}
}

@ -30,13 +30,17 @@ async function main(mode) {
const { HOME_ABI, FOREIGN_ABI } = getBridgeABIs(bridgeMode)
const homeBridge = new web3Home.eth.Contract(HOME_ABI, HOME_BRIDGE_ADDRESS)
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, FOREIGN_BRIDGE_ADDRESS)
const tokenType = await getTokenType(foreignBridge, FOREIGN_BRIDGE_ADDRESS)
const isExternalErc20 = tokenType === ERC_TYPES.ERC20
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 erc20Contract = new web3Foreign.eth.Contract(ERC20_ABI, erc20Address)
let isExternalErc20
let erc20Contract
if (bridgeMode !== BRIDGE_MODES.ARBITRARY_MESSAGE) {
const tokenType = await getTokenType(foreignBridge, FOREIGN_BRIDGE_ADDRESS)
isExternalErc20 = tokenType === ERC_TYPES.ERC20
const erc20MethodName =
bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC || v1Bridge ? 'erc677token' : 'erc20token'
const erc20Address = await foreignBridge.methods[erc20MethodName]().call()
erc20Contract = new web3Foreign.eth.Contract(ERC20_ABI, erc20Address)
}
logger.debug('getting last block numbers')
const [homeBlockNumber, foreignBlockNumber] = await getBlockNumber(web3Home, web3Foreign)