d656025378
* Moved audit to root directory. * Moved code of conduct, contributing and licence files. * Removed travis config and badge. * Updated repository links in CONTRIBUTING. * Moved Gitter badge to main readme. Updated links to contributing and licence. * Updated main readme. * Moved references to main readme. * Renamed token-bridge to oracle. * Update README.md Co-Authored-By: rzadp <rzadp@student.mini.pw.edu.pl>
94 lines
2.7 KiB
JavaScript
94 lines
2.7 KiB
JavaScript
require('dotenv').config()
|
|
|
|
const { toBN } = require('web3').utils
|
|
const { web3Home, web3Foreign } = require('../src/services/web3')
|
|
const { privateKeyToAddress } = require('../src/utils/utils')
|
|
|
|
const homeNativeErcAbi = require('../abis/HomeBridgeNativeToErc.abi')
|
|
const foreignNativeErcAbi = require('../abis/ForeignBridgeNativeToErc.abi')
|
|
|
|
const homeErcErcAbi = require('../abis/HomeBridgeErcToErc.abi')
|
|
const foreignErc677Erc677Abi = require('../abis/ForeignBridgeErc677ToErc677.abi')
|
|
|
|
const homeErcNativeAbi = require('../abis/HomeBridgeErcToNative.abi')
|
|
const foreignErcNativeAbi = require('../abis/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
|
|
}
|