2019-05-08 16:12:02 +03:00
|
|
|
require('dotenv').config()
|
|
|
|
const Web3 = require('web3')
|
|
|
|
const logger = require('./logger')('stuckTransfers.js')
|
2019-07-26 11:30:35 +03:00
|
|
|
const { FOREIGN_V1_ABI } = require('../commons/abis')
|
2019-05-08 16:12:02 +03:00
|
|
|
|
2019-09-13 10:11:38 +03:00
|
|
|
const { COMMON_FOREIGN_RPC_URL, COMMON_FOREIGN_BRIDGE_ADDRESS } = process.env
|
|
|
|
const MONITOR_FOREIGN_START_BLOCK = Number(process.env.MONITOR_FOREIGN_START_BLOCK) || 0
|
2019-05-08 16:12:02 +03:00
|
|
|
|
2019-09-13 10:11:38 +03:00
|
|
|
const foreignProvider = new Web3.providers.HttpProvider(COMMON_FOREIGN_RPC_URL)
|
2019-05-08 16:12:02 +03:00
|
|
|
const web3Foreign = new Web3(foreignProvider)
|
|
|
|
|
|
|
|
const ABITransferWithoutData = [
|
|
|
|
{
|
|
|
|
anonymous: false,
|
|
|
|
inputs: [
|
|
|
|
{
|
|
|
|
indexed: true,
|
|
|
|
name: 'from',
|
|
|
|
type: 'address'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: true,
|
|
|
|
name: 'to',
|
|
|
|
type: 'address'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
name: 'value',
|
|
|
|
type: 'uint256'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
name: 'Transfer',
|
|
|
|
type: 'event'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
const ABIWithData = [
|
|
|
|
{
|
|
|
|
anonymous: false,
|
|
|
|
inputs: [
|
|
|
|
{
|
|
|
|
indexed: true,
|
|
|
|
name: 'from',
|
|
|
|
type: 'address'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: true,
|
|
|
|
name: 'to',
|
|
|
|
type: 'address'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
name: 'value',
|
|
|
|
type: 'uint256'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
name: 'data',
|
|
|
|
type: 'bytes'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
name: 'Transfer',
|
|
|
|
type: 'event'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
function compareTransfers(transfersNormal) {
|
|
|
|
return withData => {
|
|
|
|
return (
|
|
|
|
transfersNormal.filter(normal => {
|
|
|
|
return normal.transactionHash === withData.transactionHash
|
|
|
|
}).length === 0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
2019-09-13 10:11:38 +03:00
|
|
|
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_V1_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
|
2019-05-31 21:35:50 +03:00
|
|
|
const erc20Address = await foreignBridge.methods.erc677token().call()
|
|
|
|
const tokenContract = new web3Foreign.eth.Contract(ABITransferWithoutData, erc20Address)
|
|
|
|
const tokenContractWithData = new web3Foreign.eth.Contract(ABIWithData, erc20Address)
|
|
|
|
logger.debug('calling tokenContract.getPastEvents Transfer')
|
|
|
|
const transfersNormal = await tokenContract.getPastEvents('Transfer', {
|
|
|
|
filter: {
|
2019-09-13 10:11:38 +03:00
|
|
|
to: COMMON_FOREIGN_BRIDGE_ADDRESS
|
2019-05-31 21:35:50 +03:00
|
|
|
},
|
2019-09-13 10:11:38 +03:00
|
|
|
fromBlock: MONITOR_FOREIGN_START_BLOCK,
|
2019-05-31 21:35:50 +03:00
|
|
|
toBlock: 'latest'
|
|
|
|
})
|
|
|
|
logger.debug('calling tokenContractWithData.getPastEvents Transfer')
|
|
|
|
const transfersWithData = await tokenContractWithData.getPastEvents('Transfer', {
|
|
|
|
filter: {
|
2019-09-13 10:11:38 +03:00
|
|
|
to: COMMON_FOREIGN_BRIDGE_ADDRESS
|
2019-05-31 21:35:50 +03:00
|
|
|
},
|
2019-09-13 10:11:38 +03:00
|
|
|
fromBlock: MONITOR_FOREIGN_START_BLOCK,
|
2019-05-31 21:35:50 +03:00
|
|
|
toBlock: 'latest'
|
|
|
|
})
|
|
|
|
const stuckTransfers = transfersNormal.filter(compareTransfers(transfersWithData))
|
|
|
|
logger.debug('Done')
|
|
|
|
return {
|
|
|
|
stuckTransfers,
|
|
|
|
total: stuckTransfers.length,
|
|
|
|
lastChecked: Math.floor(Date.now() / 1000)
|
2019-05-08 16:12:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = main
|