2019-06-07 14:19:12 +03:00
|
|
|
require('../env')
|
2019-05-06 14:12:53 +03:00
|
|
|
const Web3 = require('web3')
|
2019-12-05 19:50:55 +03:00
|
|
|
const { getTokensState } = require('../src/utils/tokenState')
|
2019-09-14 09:04:07 +03:00
|
|
|
const {
|
|
|
|
ERC677_BRIDGE_TOKEN_ABI,
|
|
|
|
FOREIGN_ERC_TO_ERC_ABI,
|
|
|
|
FOREIGN_ERC_TO_NATIVE_ABI,
|
|
|
|
getTokenType
|
|
|
|
} = require('../../commons')
|
2019-05-06 14:12:53 +03:00
|
|
|
|
2019-12-23 18:59:03 +03:00
|
|
|
const emptyLogger = {
|
|
|
|
debug: () => {},
|
|
|
|
info: () => {}
|
|
|
|
}
|
|
|
|
|
2019-05-06 14:12:53 +03:00
|
|
|
async function initialChecks() {
|
2019-09-14 09:04:07 +03:00
|
|
|
const { ORACLE_BRIDGE_MODE, COMMON_FOREIGN_RPC_URL, COMMON_FOREIGN_BRIDGE_ADDRESS } = process.env
|
2019-12-04 23:18:14 +03:00
|
|
|
let result = {}
|
2019-09-14 09:04:07 +03:00
|
|
|
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(COMMON_FOREIGN_RPC_URL))
|
2019-05-06 14:12:53 +03:00
|
|
|
|
2019-09-13 10:11:38 +03:00
|
|
|
if (ORACLE_BRIDGE_MODE === 'ERC_TO_ERC') {
|
2019-09-14 09:04:07 +03:00
|
|
|
const bridge = new foreignWeb3.eth.Contract(FOREIGN_ERC_TO_ERC_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
|
|
|
|
result.bridgeableTokenAddress = await bridge.methods.erc20token().call()
|
|
|
|
} else if (ORACLE_BRIDGE_MODE === 'ERC_TO_NATIVE') {
|
|
|
|
const bridge = new foreignWeb3.eth.Contract(FOREIGN_ERC_TO_NATIVE_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
|
2019-12-23 18:59:03 +03:00
|
|
|
result = await getTokensState(bridge, emptyLogger)
|
2019-09-14 09:04:07 +03:00
|
|
|
}
|
2019-07-26 15:26:14 +03:00
|
|
|
|
2019-09-14 09:04:07 +03:00
|
|
|
if (ORACLE_BRIDGE_MODE === 'ERC_TO_ERC') {
|
|
|
|
const bridgeTokenContract = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, result.bridgeableTokenAddress)
|
2019-09-13 10:11:38 +03:00
|
|
|
result.foreignERC = await getTokenType(bridgeTokenContract, COMMON_FOREIGN_BRIDGE_ADDRESS)
|
2019-05-06 14:12:53 +03:00
|
|
|
}
|
|
|
|
console.log(JSON.stringify(result))
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
initialChecks()
|
|
|
|
|
|
|
|
module.exports = initialChecks
|