95 lines
2.9 KiB
JavaScript
95 lines
2.9 KiB
JavaScript
require('../env')
|
|
|
|
const { toBN } = require('web3').utils
|
|
const { web3Home, web3Foreign } = require('../src/services/web3')
|
|
const { privateKeyToAddress } = require('../src/utils/utils')
|
|
|
|
const homeNativeErcAbi = require('../../contracts/build/contracts/HomeBridgeNativeToErc').abi
|
|
const foreignNativeErcAbi = require('../../contracts/build/contracts/ForeignBridgeNativeToErc').abi
|
|
|
|
const homeErcErcAbi = require('../../contracts/build/contracts/HomeBridgeErcToErc').abi
|
|
const foreignErc677Erc677Abi = require('../../contracts/build/contracts/ForeignBridgeErc677ToErc677')
|
|
.abi
|
|
|
|
const homeErcNativeAbi = require('../../contracts/build/contracts/HomeBridgeErcToNative').abi
|
|
const foreignErcNativeAbi = require('../../contracts/build/contracts/ForeignBridgeErcToNative').abi
|
|
|
|
const { VALIDATOR_ADDRESS, VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env
|
|
|
|
let homeAbi
|
|
let foreignAbi
|
|
let id
|
|
|
|
switch (process.env.BRIDGE_MODE) {
|
|
case 'NATIVE_TO_ERC':
|
|
homeAbi = homeNativeErcAbi
|
|
foreignAbi = foreignNativeErcAbi
|
|
id = 'native-erc'
|
|
break
|
|
case 'ERC_TO_ERC':
|
|
homeAbi = homeErcErcAbi
|
|
foreignAbi = foreignErc677Erc677Abi
|
|
id = 'erc-erc'
|
|
break
|
|
case 'ERC_TO_NATIVE':
|
|
homeAbi = homeErcNativeAbi
|
|
foreignAbi = foreignErcNativeAbi
|
|
id = 'erc-native'
|
|
break
|
|
default:
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
throw new Error(`Bridge Mode: ${process.env.BRIDGE_MODE} not supported.`)
|
|
} else {
|
|
homeAbi = homeErcNativeAbi
|
|
foreignAbi = foreignErcNativeAbi
|
|
id = 'erc-native'
|
|
}
|
|
}
|
|
|
|
let maxProcessingTime = null
|
|
if (String(process.env.MAX_PROCESSING_TIME) === '0') {
|
|
maxProcessingTime = 0
|
|
} else if (!process.env.MAX_PROCESSING_TIME) {
|
|
maxProcessingTime =
|
|
4 * Math.max(process.env.HOME_POLLING_INTERVAL, process.env.FOREIGN_POLLING_INTERVAL)
|
|
} else {
|
|
maxProcessingTime = Number(process.env.MAX_PROCESSING_TIME)
|
|
}
|
|
|
|
const bridgeConfig = {
|
|
homeBridgeAddress: process.env.HOME_BRIDGE_ADDRESS,
|
|
homeBridgeAbi: homeAbi,
|
|
foreignBridgeAddress: process.env.FOREIGN_BRIDGE_ADDRESS,
|
|
foreignBridgeAbi: foreignAbi,
|
|
eventFilter: {},
|
|
validatorAddress: VALIDATOR_ADDRESS || privateKeyToAddress(VALIDATOR_ADDRESS_PRIVATE_KEY),
|
|
maxProcessingTime
|
|
}
|
|
|
|
const homeConfig = {
|
|
eventContractAddress: process.env.HOME_BRIDGE_ADDRESS,
|
|
eventAbi: homeAbi,
|
|
bridgeContractAddress: process.env.HOME_BRIDGE_ADDRESS,
|
|
bridgeAbi: homeAbi,
|
|
pollingInterval: process.env.HOME_POLLING_INTERVAL,
|
|
startBlock: toBN(process.env.HOME_START_BLOCK || 0),
|
|
web3: web3Home
|
|
}
|
|
|
|
const foreignConfig = {
|
|
eventContractAddress: process.env.FOREIGN_BRIDGE_ADDRESS,
|
|
eventAbi: foreignAbi,
|
|
bridgeContractAddress: process.env.FOREIGN_BRIDGE_ADDRESS,
|
|
bridgeAbi: foreignAbi,
|
|
pollingInterval: process.env.FOREIGN_POLLING_INTERVAL,
|
|
startBlock: toBN(process.env.FOREIGN_START_BLOCK || 0),
|
|
web3: web3Foreign
|
|
}
|
|
|
|
module.exports = {
|
|
bridgeConfig,
|
|
homeConfig,
|
|
foreignConfig,
|
|
id
|
|
}
|