2019-05-08 16:12:02 +03:00
|
|
|
require('dotenv').config()
|
2020-10-29 11:25:43 +03:00
|
|
|
const BN = require('bignumber.js')
|
|
|
|
const Web3Utils = require('web3').utils
|
2020-11-04 22:16:43 +03:00
|
|
|
const {
|
|
|
|
eventWithoutReference,
|
|
|
|
deliveredMsgNotProcessed,
|
|
|
|
unclaimedHomeToForeignRequests,
|
|
|
|
manuallyProcessedAMBHomeToForeignRequests
|
|
|
|
} = require('./utils/message')
|
2019-10-21 15:57:28 +03:00
|
|
|
const { BRIDGE_MODES } = require('../commons')
|
2020-10-29 11:25:43 +03:00
|
|
|
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
|
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) {
|
2020-11-04 22:16:43 +03:00
|
|
|
const onlyInHomeRequests = homeToForeignRequests.filter(deliveredMsgNotProcessed(homeToForeignConfirmations))
|
|
|
|
const manuallyProcessedRequests = onlyInHomeRequests.filter(manuallyProcessedAMBHomeToForeignRequests())
|
2019-10-21 15:57:28 +03:00
|
|
|
return {
|
2020-11-04 22:16:43 +03:00
|
|
|
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
|
|
|
|
},
|
|
|
|
foreign: {
|
|
|
|
fromHome: homeToForeignConfirmations.length,
|
|
|
|
toHome: foreignToHomeRequests.length
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-10-29 11:25:43 +03:00
|
|
|
const stats = {
|
2019-10-21 15:57:28 +03:00
|
|
|
depositsDiff: homeToForeignRequests.length - homeToForeignConfirmations.length,
|
2020-10-29 11:25:43 +03:00
|
|
|
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())
|
2020-10-29 11:25:43 +03:00
|
|
|
}
|
|
|
|
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
|