2019-06-07 14:19:12 +03:00
|
|
|
require('../env')
|
2019-05-06 14:12:53 +03:00
|
|
|
|
|
|
|
const { toBN } = require('web3').utils
|
2019-07-12 15:37:41 +03:00
|
|
|
const {
|
|
|
|
BRIDGE_MODES,
|
|
|
|
HOME_NATIVE_TO_ERC_ABI,
|
|
|
|
FOREIGN_NATIVE_TO_ERC_ABI,
|
|
|
|
HOME_ERC_TO_ERC_ABI,
|
|
|
|
FOREIGN_ERC_TO_ERC_ABI,
|
|
|
|
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')
|
2019-05-06 14:12:53 +03:00
|
|
|
const { web3Home, web3Foreign } = require('../src/services/web3')
|
|
|
|
const { privateKeyToAddress } = require('../src/utils/utils')
|
|
|
|
|
2019-09-13 10:11:38 +03:00
|
|
|
const { ORACLE_VALIDATOR_ADDRESS, ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env
|
2019-05-06 14:12:53 +03:00
|
|
|
|
|
|
|
let homeAbi
|
|
|
|
let foreignAbi
|
|
|
|
let id
|
|
|
|
|
2019-09-13 10:11:38 +03:00
|
|
|
switch (process.env.ORACLE_BRIDGE_MODE) {
|
2019-07-12 15:37:41 +03:00
|
|
|
case BRIDGE_MODES.NATIVE_TO_ERC:
|
|
|
|
homeAbi = HOME_NATIVE_TO_ERC_ABI
|
|
|
|
foreignAbi = FOREIGN_NATIVE_TO_ERC_ABI
|
2019-05-06 14:12:53 +03:00
|
|
|
id = 'native-erc'
|
|
|
|
break
|
2019-07-12 15:37:41 +03:00
|
|
|
case BRIDGE_MODES.ERC_TO_ERC:
|
|
|
|
homeAbi = HOME_ERC_TO_ERC_ABI
|
|
|
|
foreignAbi = FOREIGN_ERC_TO_ERC_ABI
|
2019-05-06 14:12:53 +03:00
|
|
|
id = 'erc-erc'
|
|
|
|
break
|
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') {
|
2019-09-13 10:11:38 +03:00
|
|
|
throw new Error(`Bridge Mode: ${process.env.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'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let maxProcessingTime = null
|
2019-09-13 10:11:38 +03:00
|
|
|
if (String(process.env.ORACLE_MAX_PROCESSING_TIME) === '0') {
|
2019-05-06 14:12:53 +03:00
|
|
|
maxProcessingTime = 0
|
2019-09-13 10:11:38 +03:00
|
|
|
} else if (!process.env.ORACLE_MAX_PROCESSING_TIME) {
|
|
|
|
maxProcessingTime =
|
|
|
|
4 * Math.max(process.env.ORACLE_HOME_RPC_POLLING_INTERVAL, process.env.ORACLE_FOREIGN_RPC_POLLING_INTERVAL)
|
2019-05-06 14:12:53 +03:00
|
|
|
} else {
|
2019-09-13 10:11:38 +03:00
|
|
|
maxProcessingTime = Number(process.env.ORACLE_MAX_PROCESSING_TIME)
|
2019-05-06 14:12:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const bridgeConfig = {
|
2019-09-13 10:11:38 +03:00
|
|
|
homeBridgeAddress: process.env.COMMON_HOME_BRIDGE_ADDRESS,
|
2019-05-06 14:12:53 +03:00
|
|
|
homeBridgeAbi: homeAbi,
|
2019-09-13 10:11:38 +03:00
|
|
|
foreignBridgeAddress: process.env.COMMON_FOREIGN_BRIDGE_ADDRESS,
|
2019-05-06 14:12:53 +03:00
|
|
|
foreignBridgeAbi: foreignAbi,
|
|
|
|
eventFilter: {},
|
2019-09-13 10:11:38 +03:00
|
|
|
validatorAddress: ORACLE_VALIDATOR_ADDRESS || privateKeyToAddress(ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY),
|
2019-05-06 14:12:53 +03:00
|
|
|
maxProcessingTime
|
|
|
|
}
|
|
|
|
|
|
|
|
const homeConfig = {
|
2020-09-12 17:01:37 +03:00
|
|
|
chain: 'home',
|
2019-09-13 10:11:38 +03:00
|
|
|
eventContractAddress: process.env.COMMON_HOME_BRIDGE_ADDRESS,
|
2019-05-06 14:12:53 +03:00
|
|
|
eventAbi: homeAbi,
|
2019-09-13 10:11:38 +03:00
|
|
|
bridgeContractAddress: process.env.COMMON_HOME_BRIDGE_ADDRESS,
|
2019-05-06 14:12:53 +03:00
|
|
|
bridgeAbi: homeAbi,
|
2019-09-13 10:11:38 +03:00
|
|
|
pollingInterval: process.env.ORACLE_HOME_RPC_POLLING_INTERVAL,
|
|
|
|
startBlock: toBN(process.env.ORACLE_HOME_START_BLOCK || 0),
|
2019-05-06 14:12:53 +03:00
|
|
|
web3: web3Home
|
|
|
|
}
|
|
|
|
|
|
|
|
const foreignConfig = {
|
2020-09-12 17:01:37 +03:00
|
|
|
chain: 'foreign',
|
2019-09-13 10:11:38 +03:00
|
|
|
eventContractAddress: process.env.COMMON_FOREIGN_BRIDGE_ADDRESS,
|
2019-05-06 14:12:53 +03:00
|
|
|
eventAbi: foreignAbi,
|
2019-09-13 10:11:38 +03:00
|
|
|
bridgeContractAddress: process.env.COMMON_FOREIGN_BRIDGE_ADDRESS,
|
2019-05-06 14:12:53 +03:00
|
|
|
bridgeAbi: foreignAbi,
|
2019-09-13 10:11:38 +03:00
|
|
|
pollingInterval: process.env.ORACLE_FOREIGN_RPC_POLLING_INTERVAL,
|
|
|
|
startBlock: toBN(process.env.ORACLE_FOREIGN_START_BLOCK || 0),
|
2019-05-06 14:12:53 +03:00
|
|
|
web3: web3Foreign
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
bridgeConfig,
|
|
|
|
homeConfig,
|
|
|
|
foreignConfig,
|
|
|
|
id
|
|
|
|
}
|