Compare commits
2 Commits
master
...
monitor-ou
Author | SHA1 | Date | |
---|---|---|---|
|
65dc698022 | ||
|
c254e35d11 |
@ -79,6 +79,67 @@ const homeV1Abi = [
|
|||||||
payable: false,
|
payable: false,
|
||||||
stateMutability: 'view',
|
stateMutability: 'view',
|
||||||
type: 'function'
|
type: 'function'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
constant: true,
|
||||||
|
inputs: [],
|
||||||
|
name: 'foreignDailyLimit',
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
name: '',
|
||||||
|
type: 'uint256'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
payable: false,
|
||||||
|
stateMutability: 'view',
|
||||||
|
type: 'function'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
constant: true,
|
||||||
|
inputs: [],
|
||||||
|
name: 'foreignMaxPerTx',
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
name: '',
|
||||||
|
type: 'uint256'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
payable: false,
|
||||||
|
stateMutability: 'view',
|
||||||
|
type: 'function'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
constant: true,
|
||||||
|
inputs: [],
|
||||||
|
name: 'getCurrentDay',
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
name: '',
|
||||||
|
type: 'uint256'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
payable: false,
|
||||||
|
stateMutability: 'view',
|
||||||
|
type: 'function'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
constant: true,
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: '',
|
||||||
|
type: 'uint256'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
name: 'totalExecutedPerDay',
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
name: '',
|
||||||
|
type: 'uint256'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
payable: false,
|
||||||
|
stateMutability: 'view',
|
||||||
|
type: 'function'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -182,6 +243,67 @@ const foreignViAbi = [
|
|||||||
payable: false,
|
payable: false,
|
||||||
stateMutability: 'view',
|
stateMutability: 'view',
|
||||||
type: 'function'
|
type: 'function'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
constant: true,
|
||||||
|
inputs: [],
|
||||||
|
name: 'homeDailyLimit',
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
name: '',
|
||||||
|
type: 'uint256'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
payable: false,
|
||||||
|
stateMutability: 'view',
|
||||||
|
type: 'function'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
constant: true,
|
||||||
|
inputs: [],
|
||||||
|
name: 'homeMaxPerTx',
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
name: '',
|
||||||
|
type: 'uint256'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
payable: false,
|
||||||
|
stateMutability: 'view',
|
||||||
|
type: 'function'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
constant: true,
|
||||||
|
inputs: [],
|
||||||
|
name: 'getCurrentDay',
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
name: '',
|
||||||
|
type: 'uint256'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
payable: false,
|
||||||
|
stateMutability: 'view',
|
||||||
|
type: 'function'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
constant: true,
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
name: '',
|
||||||
|
type: 'uint256'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
name: 'totalExecutedPerDay',
|
||||||
|
outputs: [
|
||||||
|
{
|
||||||
|
name: '',
|
||||||
|
type: 'uint256'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
payable: false,
|
||||||
|
stateMutability: 'view',
|
||||||
|
type: 'function'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
70
monitor/getRequestsOutOfLimits.js
Normal file
70
monitor/getRequestsOutOfLimits.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
require('dotenv').config()
|
||||||
|
const BN = require('bignumber.js')
|
||||||
|
const { fromWei } = require('web3').utils
|
||||||
|
const logger = require('./logger')('getRequestsOutOfLimits')
|
||||||
|
const { BRIDGE_MODES, getBridgeABIs } = require('../commons')
|
||||||
|
const { web3Home, web3Foreign } = require('./utils/web3')
|
||||||
|
|
||||||
|
const { COMMON_HOME_BRIDGE_ADDRESS, COMMON_FOREIGN_BRIDGE_ADDRESS } = process.env
|
||||||
|
|
||||||
|
function outOfRemainingQuota(remainingLimit) {
|
||||||
|
let limit = remainingLimit
|
||||||
|
return event => {
|
||||||
|
if (limit.lt(event.value)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
limit = limit.minus(event.value)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkOutOfLimitsStats(contract, requests) {
|
||||||
|
logger.debug('calling contract.getCurrentDay()')
|
||||||
|
const day = await contract.methods.getCurrentDay().call()
|
||||||
|
logger.debug('calling contract.executionDailyLimit()')
|
||||||
|
const executionDailyLimit = new BN(await contract.methods.executionDailyLimit().call())
|
||||||
|
logger.debug('calling contract.executionMaxPerTx()')
|
||||||
|
const executionMaxPerTx = new BN(await contract.methods.executionMaxPerTx().call())
|
||||||
|
logger.debug('calling contract.totalExecutedPerDay()')
|
||||||
|
const executedPerDay = new BN(await contract.methods.totalExecutedPerDay(day).call())
|
||||||
|
|
||||||
|
const remainingExecutionDailyLimit = executionDailyLimit.minus(executedPerDay)
|
||||||
|
|
||||||
|
// value > executionMaxPerTx
|
||||||
|
const requestsAboveMaxPerTx = requests.filter(event => executionMaxPerTx.lt(event.value))
|
||||||
|
|
||||||
|
// value <= executionMaxPerTx && remainingExecutionDailyLimit < value
|
||||||
|
const requestsAboveDailyLimit = requests
|
||||||
|
.filter(event => executionMaxPerTx.gte(event.value))
|
||||||
|
.filter(outOfRemainingQuota(remainingExecutionDailyLimit))
|
||||||
|
|
||||||
|
return {
|
||||||
|
aboveExecutionMaxPerTx: requestsAboveMaxPerTx.length,
|
||||||
|
aboveExecutionDailyLimit: requestsAboveDailyLimit.length,
|
||||||
|
aboveExecutionDailyLimitAmount: fromWei(BN.sum(0, ...requestsAboveDailyLimit.map(e => e.value)).toFixed()),
|
||||||
|
remainingExecutionDailyLimit: fromWei(remainingExecutionDailyLimit.toFixed())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main(bridgeMode, unprocessedRequests) {
|
||||||
|
const { homeRequests, foreignRequests } = unprocessedRequests
|
||||||
|
|
||||||
|
const { HOME_ABI, FOREIGN_ABI } = getBridgeABIs(bridgeMode)
|
||||||
|
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
|
||||||
|
const homeBridge = new web3Home.eth.Contract(HOME_ABI, COMMON_HOME_BRIDGE_ADDRESS)
|
||||||
|
|
||||||
|
// replace the required methods by their legacy versions
|
||||||
|
if (bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1) {
|
||||||
|
homeBridge.methods.executionDailyLimit = homeBridge.methods.foreignDailyLimit
|
||||||
|
homeBridge.methods.executionMaxPerTx = homeBridge.methods.foreignMaxPerTx
|
||||||
|
foreignBridge.methods.executionDailyLimit = foreignBridge.methods.homeDailyLimit
|
||||||
|
foreignBridge.methods.executionMaxPerTx = foreignBridge.methods.homeMaxPerTx
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
home: await checkOutOfLimitsStats(homeBridge, foreignRequests),
|
||||||
|
foreign: await checkOutOfLimitsStats(foreignBridge, homeRequests)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = main
|
@ -8,6 +8,7 @@ const {
|
|||||||
manuallyProcessedAMBHomeToForeignRequests
|
manuallyProcessedAMBHomeToForeignRequests
|
||||||
} = require('./utils/message')
|
} = require('./utils/message')
|
||||||
const { BRIDGE_MODES } = require('../commons')
|
const { BRIDGE_MODES } = require('../commons')
|
||||||
|
const getRequestsOutOfLimits = require('./getRequestsOutOfLimits')
|
||||||
const { getHomeTxSender } = require('./utils/web3Cache')
|
const { getHomeTxSender } = require('./utils/web3Cache')
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -46,8 +47,11 @@ async function main(bridgeMode, eventsInfo) {
|
|||||||
depositsDiff: homeToForeignRequests.length - homeToForeignConfirmations.length,
|
depositsDiff: homeToForeignRequests.length - homeToForeignConfirmations.length,
|
||||||
withdrawalDiff: foreignToHomeConfirmations.length - foreignToHomeRequests.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))
|
const onlyInHomeDeposits = homeToForeignRequests.filter(eventWithoutReference(homeToForeignConfirmations))
|
||||||
|
const onlyInForeignWithdrawals = foreignToHomeRequests.filter(eventWithoutReference(foreignToHomeConfirmations))
|
||||||
|
|
||||||
|
if (MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST || MONITOR_HOME_TO_FOREIGN_BLOCK_LIST) {
|
||||||
if (MONITOR_HOME_TO_FOREIGN_CHECK_SENDER === 'true') {
|
if (MONITOR_HOME_TO_FOREIGN_CHECK_SENDER === 'true') {
|
||||||
for (let i = 0; i < onlyInHomeDeposits.length; i++) {
|
for (let i = 0; i < onlyInHomeDeposits.length; i++) {
|
||||||
onlyInHomeDeposits[i].sender = await getHomeTxSender(onlyInHomeDeposits[i].transactionHash)
|
onlyInHomeDeposits[i].sender = await getHomeTxSender(onlyInHomeDeposits[i].transactionHash)
|
||||||
@ -60,15 +64,23 @@ async function main(bridgeMode, eventsInfo) {
|
|||||||
stats.unclaimedDiff = unclaimedPool.length
|
stats.unclaimedDiff = unclaimedPool.length
|
||||||
stats.unclaimedBalance = Web3Utils.fromWei(BN.sum(0, ...unclaimedPool.map(e => e.value)).toFixed())
|
stats.unclaimedBalance = Web3Utils.fromWei(BN.sum(0, ...unclaimedPool.map(e => e.value)).toFixed())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const limitsStats = await getRequestsOutOfLimits(bridgeMode, {
|
||||||
|
homeRequests: onlyInHomeDeposits,
|
||||||
|
foreignRequests: onlyInForeignWithdrawals
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...stats,
|
...stats,
|
||||||
home: {
|
home: {
|
||||||
deposits: homeToForeignRequests.length,
|
deposits: homeToForeignRequests.length,
|
||||||
withdrawals: foreignToHomeConfirmations.length
|
withdrawals: foreignToHomeConfirmations.length,
|
||||||
|
outOfLimits: limitsStats.home
|
||||||
},
|
},
|
||||||
foreign: {
|
foreign: {
|
||||||
deposits: homeToForeignConfirmations.length,
|
deposits: homeToForeignConfirmations.length,
|
||||||
withdrawals: foreignToHomeRequests.length
|
withdrawals: foreignToHomeRequests.length,
|
||||||
|
outOfLimits: limitsStats.foreign
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user