2019-06-07 14:19:12 +03:00
|
|
|
require('../env')
|
2019-05-06 14:12:53 +03:00
|
|
|
|
2019-07-12 15:37:41 +03:00
|
|
|
const {
|
|
|
|
BRIDGE_MODES,
|
|
|
|
HOME_ERC_TO_NATIVE_ABI,
|
2019-10-21 15:57:28 +03:00
|
|
|
FOREIGN_ERC_TO_NATIVE_ABI,
|
|
|
|
HOME_AMB_ABI,
|
|
|
|
FOREIGN_AMB_ABI
|
2019-07-12 15:37:41 +03:00
|
|
|
} = require('../../commons')
|
2022-05-25 13:54:47 +03:00
|
|
|
const {
|
|
|
|
web3Home,
|
|
|
|
web3Foreign,
|
|
|
|
web3HomeRedundant,
|
|
|
|
web3HomeFallback,
|
|
|
|
web3ForeignRedundant,
|
|
|
|
web3ForeignFallback,
|
|
|
|
web3ForeignArchive
|
|
|
|
} = require('../src/services/web3')
|
2021-07-08 09:38:55 +03:00
|
|
|
const { add0xPrefix, privateKeyToAddress } = require('../src/utils/utils')
|
|
|
|
const { EXIT_CODES } = require('../src/utils/constants')
|
2019-05-06 14:12:53 +03:00
|
|
|
|
2021-05-09 16:34:19 +03:00
|
|
|
const {
|
|
|
|
ORACLE_BRIDGE_MODE,
|
|
|
|
ORACLE_VALIDATOR_ADDRESS,
|
|
|
|
ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY,
|
|
|
|
ORACLE_MAX_PROCESSING_TIME,
|
|
|
|
COMMON_HOME_BRIDGE_ADDRESS,
|
|
|
|
COMMON_FOREIGN_BRIDGE_ADDRESS,
|
|
|
|
ORACLE_HOME_RPC_POLLING_INTERVAL,
|
|
|
|
ORACLE_FOREIGN_RPC_POLLING_INTERVAL,
|
|
|
|
ORACLE_HOME_START_BLOCK,
|
|
|
|
ORACLE_FOREIGN_START_BLOCK,
|
|
|
|
ORACLE_HOME_RPC_BLOCK_POLLING_LIMIT,
|
2022-01-03 15:32:38 +03:00
|
|
|
ORACLE_FOREIGN_RPC_BLOCK_POLLING_LIMIT,
|
|
|
|
ORACLE_HOME_EVENTS_REPROCESSING,
|
|
|
|
ORACLE_HOME_EVENTS_REPROCESSING_BATCH_SIZE,
|
|
|
|
ORACLE_HOME_EVENTS_REPROCESSING_BLOCK_DELAY,
|
2022-05-25 13:54:47 +03:00
|
|
|
ORACLE_HOME_RPC_SYNC_STATE_CHECK_INTERVAL,
|
2022-01-03 15:32:38 +03:00
|
|
|
ORACLE_FOREIGN_EVENTS_REPROCESSING,
|
|
|
|
ORACLE_FOREIGN_EVENTS_REPROCESSING_BATCH_SIZE,
|
2022-05-25 13:54:47 +03:00
|
|
|
ORACLE_FOREIGN_EVENTS_REPROCESSING_BLOCK_DELAY,
|
|
|
|
ORACLE_FOREIGN_RPC_SYNC_STATE_CHECK_INTERVAL
|
2021-05-09 16:34:19 +03:00
|
|
|
} = process.env
|
2019-05-06 14:12:53 +03:00
|
|
|
|
|
|
|
let homeAbi
|
|
|
|
let foreignAbi
|
|
|
|
let id
|
|
|
|
|
2021-05-09 16:34:19 +03:00
|
|
|
switch (ORACLE_BRIDGE_MODE) {
|
2019-07-12 15:37:41 +03:00
|
|
|
case BRIDGE_MODES.ERC_TO_NATIVE:
|
|
|
|
homeAbi = HOME_ERC_TO_NATIVE_ABI
|
|
|
|
foreignAbi = FOREIGN_ERC_TO_NATIVE_ABI
|
2019-05-06 14:12:53 +03:00
|
|
|
id = 'erc-native'
|
|
|
|
break
|
2019-10-21 15:57:28 +03:00
|
|
|
case BRIDGE_MODES.ARBITRARY_MESSAGE:
|
|
|
|
homeAbi = HOME_AMB_ABI
|
|
|
|
foreignAbi = FOREIGN_AMB_ABI
|
|
|
|
id = 'amb'
|
|
|
|
break
|
2019-05-06 14:12:53 +03:00
|
|
|
default:
|
|
|
|
if (process.env.NODE_ENV !== 'test') {
|
2021-05-09 16:34:19 +03:00
|
|
|
throw new Error(`Bridge Mode: ${ORACLE_BRIDGE_MODE} not supported.`)
|
2019-05-06 14:12:53 +03:00
|
|
|
} else {
|
2019-07-12 15:37:41 +03:00
|
|
|
homeAbi = HOME_ERC_TO_NATIVE_ABI
|
|
|
|
foreignAbi = FOREIGN_ERC_TO_NATIVE_ABI
|
2019-05-06 14:12:53 +03:00
|
|
|
id = 'erc-native'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-09 16:34:19 +03:00
|
|
|
const homeContract = new web3Home.eth.Contract(homeAbi, COMMON_HOME_BRIDGE_ADDRESS)
|
2019-05-06 14:12:53 +03:00
|
|
|
const homeConfig = {
|
2020-09-12 17:01:37 +03:00
|
|
|
chain: 'home',
|
2021-05-09 16:34:19 +03:00
|
|
|
bridgeAddress: COMMON_HOME_BRIDGE_ADDRESS,
|
|
|
|
bridgeABI: homeAbi,
|
|
|
|
pollingInterval: parseInt(ORACLE_HOME_RPC_POLLING_INTERVAL, 10),
|
2022-05-25 13:54:47 +03:00
|
|
|
syncCheckInterval: parseInt(ORACLE_HOME_RPC_SYNC_STATE_CHECK_INTERVAL, 10) || 60000,
|
2021-05-09 16:34:19 +03:00
|
|
|
startBlock: parseInt(ORACLE_HOME_START_BLOCK, 10) || 0,
|
|
|
|
blockPollingLimit: parseInt(ORACLE_HOME_RPC_BLOCK_POLLING_LIMIT, 10),
|
|
|
|
web3: web3Home,
|
2022-05-25 13:54:47 +03:00
|
|
|
web3Redundant: web3HomeRedundant,
|
|
|
|
web3Fallback: web3HomeFallback,
|
2021-05-09 16:34:19 +03:00
|
|
|
bridgeContract: homeContract,
|
2022-01-03 15:32:38 +03:00
|
|
|
eventContract: homeContract,
|
|
|
|
reprocessingOptions: {
|
|
|
|
enabled: ORACLE_HOME_EVENTS_REPROCESSING === 'true',
|
|
|
|
batchSize: parseInt(ORACLE_HOME_EVENTS_REPROCESSING_BATCH_SIZE, 10) || 1000,
|
|
|
|
blockDelay: parseInt(ORACLE_HOME_EVENTS_REPROCESSING_BLOCK_DELAY, 10) || 500
|
|
|
|
}
|
2019-05-06 14:12:53 +03:00
|
|
|
}
|
|
|
|
|
2021-05-09 16:34:19 +03:00
|
|
|
const foreignContract = new web3Foreign.eth.Contract(foreignAbi, COMMON_FOREIGN_BRIDGE_ADDRESS)
|
2019-05-06 14:12:53 +03:00
|
|
|
const foreignConfig = {
|
2020-09-12 17:01:37 +03:00
|
|
|
chain: 'foreign',
|
2021-05-09 16:34:19 +03:00
|
|
|
bridgeAddress: COMMON_FOREIGN_BRIDGE_ADDRESS,
|
|
|
|
bridgeABI: foreignAbi,
|
|
|
|
pollingInterval: parseInt(ORACLE_FOREIGN_RPC_POLLING_INTERVAL, 10),
|
2022-05-25 13:54:47 +03:00
|
|
|
syncCheckInterval: parseInt(ORACLE_FOREIGN_RPC_SYNC_STATE_CHECK_INTERVAL, 10) || 60000,
|
2021-05-09 16:34:19 +03:00
|
|
|
startBlock: parseInt(ORACLE_FOREIGN_START_BLOCK, 10) || 0,
|
|
|
|
blockPollingLimit: parseInt(ORACLE_FOREIGN_RPC_BLOCK_POLLING_LIMIT, 10),
|
|
|
|
web3: web3Foreign,
|
2022-05-25 13:54:47 +03:00
|
|
|
web3Redundant: web3ForeignRedundant,
|
|
|
|
web3Fallback: web3ForeignFallback,
|
|
|
|
web3Archive: web3ForeignArchive || web3Foreign,
|
2021-05-09 16:34:19 +03:00
|
|
|
bridgeContract: foreignContract,
|
2022-01-03 15:32:38 +03:00
|
|
|
eventContract: foreignContract,
|
|
|
|
reprocessingOptions: {
|
|
|
|
enabled: ORACLE_FOREIGN_EVENTS_REPROCESSING === 'true',
|
|
|
|
batchSize: parseInt(ORACLE_FOREIGN_EVENTS_REPROCESSING_BATCH_SIZE, 10) || 500,
|
|
|
|
blockDelay: parseInt(ORACLE_FOREIGN_EVENTS_REPROCESSING_BLOCK_DELAY, 10) || 250
|
|
|
|
}
|
2019-05-06 14:12:53 +03:00
|
|
|
}
|
|
|
|
|
2021-05-09 16:34:19 +03:00
|
|
|
const maxProcessingTime =
|
|
|
|
parseInt(ORACLE_MAX_PROCESSING_TIME, 10) || 4 * Math.max(homeConfig.pollingInterval, foreignConfig.pollingInterval)
|
|
|
|
|
2021-07-08 09:38:55 +03:00
|
|
|
let validatorPrivateKey
|
|
|
|
if (ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY) {
|
|
|
|
validatorPrivateKey = add0xPrefix(ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY)
|
|
|
|
const derived = privateKeyToAddress(validatorPrivateKey)
|
|
|
|
if (ORACLE_VALIDATOR_ADDRESS && derived.toLowerCase() !== ORACLE_VALIDATOR_ADDRESS.toLowerCase()) {
|
|
|
|
console.error(
|
|
|
|
`Derived address from private key - ${derived} is different from ORACLE_VALIDATOR_ADDRESS=${ORACLE_VALIDATOR_ADDRESS}`
|
|
|
|
)
|
|
|
|
process.exit(EXIT_CODES.INCOMPATIBILITY)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-06 14:12:53 +03:00
|
|
|
module.exports = {
|
2021-05-09 16:34:19 +03:00
|
|
|
eventFilter: {},
|
2021-07-08 09:38:55 +03:00
|
|
|
validatorPrivateKey,
|
|
|
|
validatorAddress: ORACLE_VALIDATOR_ADDRESS || privateKeyToAddress(validatorPrivateKey),
|
2021-05-09 16:34:19 +03:00
|
|
|
maxProcessingTime,
|
|
|
|
shutdownKey: 'oracle-shutdown',
|
|
|
|
home: homeConfig,
|
|
|
|
foreign: foreignConfig,
|
2019-05-06 14:12:53 +03:00
|
|
|
id
|
|
|
|
}
|