diff --git a/oracle/scripts/initialChecks.js b/oracle/scripts/initialChecks.js index 3e2ad574..45b9bded 100644 --- a/oracle/scripts/initialChecks.js +++ b/oracle/scripts/initialChecks.js @@ -8,6 +8,11 @@ const { getTokenType } = require('../../commons') +const emptyLogger = { + debug: () => {}, + info: () => {} +} + async function initialChecks() { const { ORACLE_BRIDGE_MODE, COMMON_FOREIGN_RPC_URL, COMMON_FOREIGN_BRIDGE_ADDRESS } = process.env let result = {} @@ -18,7 +23,7 @@ async function initialChecks() { 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) - result = await getTokensState(bridge) + result = await getTokensState(bridge, emptyLogger) } if (ORACLE_BRIDGE_MODE === 'ERC_TO_ERC') { diff --git a/oracle/src/utils/tokenState.js b/oracle/src/utils/tokenState.js index 36e4c648..8d2d9863 100644 --- a/oracle/src/utils/tokenState.js +++ b/oracle/src/utils/tokenState.js @@ -1,14 +1,25 @@ -async function getTokensState(bridgeContract) { +async function getTokensState(bridgeContract, logger) { const context = {} - context.bridgeableTokenAddress = await bridgeContract.methods.erc20token().call() try { + logger.debug('Getting bridgeable token address') + context.bridgeableTokenAddress = await bridgeContract.methods.erc20token().call() + logger.debug({ address: context.bridgeableTokenAddress }, 'Token address obtained') + } catch (e) { + throw new Error(`Bridgeable token address cannot be obtained`) + } + + try { + logger.debug('Getting Half Duplex token address') const halfDuplexErc20tokenAddress = await bridgeContract.methods.halfDuplexErc20token().call() + logger.debug({ address: halfDuplexErc20tokenAddress }, 'Half Duplex token address obtained') if (halfDuplexErc20tokenAddress !== context.bridgeableTokenAddress) { context.halfDuplexTokenAddress = halfDuplexErc20tokenAddress } else { + logger.info('Migration to support two tokens was not applied') context.idle = true } } catch (e) { + logger.info('Old version of contracts is used') context.idle = true } diff --git a/oracle/src/watcher.js b/oracle/src/watcher.js index fd202d8d..37a9fd36 100644 --- a/oracle/src/watcher.js +++ b/oracle/src/watcher.js @@ -125,11 +125,13 @@ async function checkConditions() { let state switch (config.id) { case 'erc-native-transfer': - state = await getTokensState(bridgeContract) + logger.debug('Getting token address to listen Transfer events') + state = await getTokensState(bridgeContract, logger) updateEventContract(state.bridgeableTokenAddress) break case 'erc-native-half-duplex-transfer': - state = await getTokensState(bridgeContract) + logger.debug('Getting Half Duplex token address to listen Transfer events') + state = await getTokensState(bridgeContract, logger) skipEvents = state.idle updateEventContract(state.halfDuplexTokenAddress) break