tokenbridge/monitor/getShortEventStats.js

81 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

2019-05-08 16:12:02 +03:00
require('dotenv').config()
const BN = require('bignumber.js')
const Web3Utils = require('web3').utils
const {
eventWithoutReference,
deliveredMsgNotProcessed,
unclaimedHomeToForeignRequests,
manuallyProcessedAMBHomeToForeignRequests
} = require('./utils/message')
2019-10-21 15:57:28 +03:00
const { BRIDGE_MODES } = require('../commons')
const { getHomeTxSender } = require('./utils/web3Cache')
const {
MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST,
MONITOR_HOME_TO_FOREIGN_BLOCK_LIST,
MONITOR_HOME_TO_FOREIGN_CHECK_SENDER
} = process.env
2019-05-08 16:12:02 +03:00
2020-11-04 14:24:42 +03:00
async function main(bridgeMode, eventsInfo) {
2019-10-21 15:57:28 +03:00
const {
homeToForeignConfirmations,
homeToForeignRequests,
foreignToHomeConfirmations,
foreignToHomeRequests,
informationRequests,
informationResponses
2020-11-04 14:24:42 +03:00
} = eventsInfo
2019-05-08 16:12:02 +03:00
2019-10-21 15:57:28 +03:00
if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
const onlyInHomeRequests = homeToForeignRequests.filter(deliveredMsgNotProcessed(homeToForeignConfirmations))
const manuallyProcessedRequests = onlyInHomeRequests.filter(manuallyProcessedAMBHomeToForeignRequests())
2019-10-21 15:57:28 +03:00
return {
fromHomeToForeignDiff:
homeToForeignRequests.length - homeToForeignConfirmations.length - manuallyProcessedRequests.length,
fromHomeToForeignPBUDiff: manuallyProcessedRequests.length,
2019-10-21 15:57:28 +03:00
fromForeignToHomeDiff: foreignToHomeConfirmations.length - foreignToHomeRequests.length,
home: {
toForeign: homeToForeignRequests.length,
fromForeign: foreignToHomeConfirmations.length,
informationRequests: informationRequests.length,
informationResponses: informationResponses.length
2019-10-21 15:57:28 +03:00
},
foreign: {
fromHome: homeToForeignConfirmations.length,
toHome: foreignToHomeRequests.length
}
}
} else {
const stats = {
2019-10-21 15:57:28 +03:00
depositsDiff: homeToForeignRequests.length - homeToForeignConfirmations.length,
withdrawalDiff: foreignToHomeConfirmations.length - foreignToHomeRequests.length
}
if (MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST || MONITOR_HOME_TO_FOREIGN_BLOCK_LIST) {
const onlyInHomeDeposits = homeToForeignRequests.filter(eventWithoutReference(homeToForeignConfirmations))
if (MONITOR_HOME_TO_FOREIGN_CHECK_SENDER === 'true') {
for (let i = 0; i < onlyInHomeDeposits.length; i++) {
onlyInHomeDeposits[i].sender = await getHomeTxSender(onlyInHomeDeposits[i].transactionHash)
}
}
const unclaimedPool = onlyInHomeDeposits.filter(unclaimedHomeToForeignRequests())
stats.depositsDiff -= unclaimedPool.length
stats.unclaimedDiff = unclaimedPool.length
2020-11-04 14:24:42 +03:00
stats.unclaimedBalance = Web3Utils.fromWei(BN.sum(0, ...unclaimedPool.map(e => e.value)).toFixed())
}
return {
...stats,
2019-10-21 15:57:28 +03:00
home: {
deposits: homeToForeignRequests.length,
withdrawals: foreignToHomeConfirmations.length
},
foreign: {
deposits: homeToForeignConfirmations.length,
withdrawals: foreignToHomeRequests.length
}
2019-05-08 16:12:02 +03:00
}
}
}
module.exports = main