diff --git a/oracle/Dockerfile b/oracle/Dockerfile index f152ec61..44a2e2f8 100644 --- a/oracle/Dockerfile +++ b/oracle/Dockerfile @@ -10,6 +10,7 @@ RUN apt-get clean WORKDIR /mono COPY package.json . COPY contracts/package.json ./contracts/ +COPY commons/package.json ./commons/ COPY oracle/package.json ./oracle/ COPY yarn.lock . RUN yarn install --production --frozen-lockfile @@ -18,6 +19,8 @@ COPY ./contracts ./contracts RUN yarn run compile:contracts RUN mv ./contracts/build ./ && rm -rf ./contracts/* ./contracts/.[!.]* && mv ./build ./contracts/ +COPY ./commons ./commons + COPY ./oracle ./oracle WORKDIR /mono/oracle CMD echo "To start a bridge process run:" \ diff --git a/oracle/config/affirmation-request-watcher.config.js b/oracle/config/affirmation-request-watcher.config.js index 1acd26b6..f93fc8c4 100644 --- a/oracle/config/affirmation-request-watcher.config.js +++ b/oracle/config/affirmation-request-watcher.config.js @@ -1,5 +1,5 @@ const baseConfig = require('./base.config') -const erc20Abi = require('../../contracts/build/contracts/ERC20').abi +const { ERC20_ABI } = require('../../commons') const { ERC_TYPES } = require('../src/utils/constants') const initialChecksJson = process.argv[3] @@ -29,7 +29,7 @@ module.exports = ...baseConfig.foreignConfig, event: 'Transfer', eventContractAddress: process.env.ERC20_TOKEN_ADDRESS, - eventAbi: erc20Abi, + eventAbi: ERC20_ABI, eventFilter: { to: process.env.FOREIGN_BRIDGE_ADDRESS }, queue: 'home', name: `watcher-${id}`, diff --git a/oracle/config/base.config.js b/oracle/config/base.config.js index 089c6c45..898ca64b 100644 --- a/oracle/config/base.config.js +++ b/oracle/config/base.config.js @@ -1,19 +1,18 @@ require('../env') const { toBN } = require('web3').utils +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, + FOREIGN_ERC_TO_NATIVE_ABI +} = require('../../commons') 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 @@ -21,27 +20,27 @@ let foreignAbi let id switch (process.env.BRIDGE_MODE) { - case 'NATIVE_TO_ERC': - homeAbi = homeNativeErcAbi - foreignAbi = foreignNativeErcAbi + case BRIDGE_MODES.NATIVE_TO_ERC: + homeAbi = HOME_NATIVE_TO_ERC_ABI + foreignAbi = FOREIGN_NATIVE_TO_ERC_ABI id = 'native-erc' break - case 'ERC_TO_ERC': - homeAbi = homeErcErcAbi - foreignAbi = foreignErc677Erc677Abi + case BRIDGE_MODES.ERC_TO_ERC: + homeAbi = HOME_ERC_TO_ERC_ABI + foreignAbi = FOREIGN_ERC_TO_ERC_ABI id = 'erc-erc' break - case 'ERC_TO_NATIVE': - homeAbi = homeErcNativeAbi - foreignAbi = foreignErcNativeAbi + case BRIDGE_MODES.ERC_TO_NATIVE: + homeAbi = HOME_ERC_TO_NATIVE_ABI + foreignAbi = FOREIGN_ERC_TO_NATIVE_ABI 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 + homeAbi = HOME_ERC_TO_NATIVE_ABI + foreignAbi = FOREIGN_ERC_TO_NATIVE_ABI id = 'erc-native' } } diff --git a/oracle/scripts/erc20_to_erc20/sendForeign.js b/oracle/scripts/erc20_to_erc20/sendForeign.js index d292f8d3..27f55c39 100644 --- a/oracle/scripts/erc20_to_erc20/sendForeign.js +++ b/oracle/scripts/erc20_to_erc20/sendForeign.js @@ -3,6 +3,7 @@ const Web3 = require('web3') const Web3Utils = require('web3-utils') const rpcUrlsManager = require('../../src/services/getRpcUrlsManager') const { sendTx, sendRawTx } = require('../../src/tx/sendTx') +const { ERC20_ABI } = require('../../../commons') const { USER_ADDRESS, @@ -14,15 +15,14 @@ const { const NUMBER_OF_DEPOSITS_TO_SEND = process.argv[2] || process.env.NUMBER_OF_DEPOSITS_TO_SEND || 1 -const ERC20_ABI = require('../../../contracts/build/contracts/ERC20').abi -const BRIDGE_ABI = require('../../../contracts/build/contracts/ForeignBridgeErcToErc').abi +const { FOREIGN_ERC_TO_ERC_ABI } = require('../../../commons') const foreignRpcUrl = rpcUrlsManager.foreignUrls[0] const foreignProvider = new Web3.providers.HttpProvider(foreignRpcUrl) const web3Foreign = new Web3(foreignProvider) async function main() { - const bridge = new web3Foreign.eth.Contract(BRIDGE_ABI, FOREIGN_BRIDGE_ADDRESS) + const bridge = new web3Foreign.eth.Contract(FOREIGN_ERC_TO_ERC_ABI, FOREIGN_BRIDGE_ADDRESS) const ERC20_TOKEN_ADDRESS = await bridge.methods.erc20token().call() const poa20 = new web3Foreign.eth.Contract(ERC20_ABI, ERC20_TOKEN_ADDRESS) diff --git a/oracle/scripts/erc20_to_erc20/sendHome.js b/oracle/scripts/erc20_to_erc20/sendHome.js index bc89fb93..cdbf2ebb 100644 --- a/oracle/scripts/erc20_to_erc20/sendHome.js +++ b/oracle/scripts/erc20_to_erc20/sendHome.js @@ -4,6 +4,7 @@ const Web3Utils = require('web3-utils') const rpcUrlsManager = require('../../src/services/getRpcUrlsManager') const { sendTx, sendRawTx } = require('../../src/tx/sendTx') const { isValidAmount } = require('../utils/utils') +const { HOME_ERC_TO_ERC_ABI } = require('../../../commons') const { USER_ADDRESS, @@ -46,14 +47,12 @@ const BRIDGEABLE_TOKEN_ABI = [ } ] -const BRIDGE_ABI = require('../../../contracts/build/contracts/HomeBridgeErcToErc').abi - const homeRpcUrl = rpcUrlsManager.homeUrls[0] const homeProvider = new Web3.providers.HttpProvider(homeRpcUrl) const web3Home = new Web3(homeProvider) async function main() { - const bridge = new web3Home.eth.Contract(BRIDGE_ABI, HOME_BRIDGE_ADDRESS) + const bridge = new web3Home.eth.Contract(HOME_ERC_TO_ERC_ABI, HOME_BRIDGE_ADDRESS) const BRIDGEABLE_TOKEN_ADDRESS = await bridge.methods.erc677token().call() const erc677 = new web3Home.eth.Contract(BRIDGEABLE_TOKEN_ABI, BRIDGEABLE_TOKEN_ADDRESS) diff --git a/oracle/scripts/erc20_to_native/sendForeign.js b/oracle/scripts/erc20_to_native/sendForeign.js index 0b728322..a0213b57 100644 --- a/oracle/scripts/erc20_to_native/sendForeign.js +++ b/oracle/scripts/erc20_to_native/sendForeign.js @@ -14,15 +14,14 @@ const { const NUMBER_OF_DEPOSITS_TO_SEND = process.argv[2] || process.env.NUMBER_OF_DEPOSITS_TO_SEND || 1 -const ERC20_ABI = require('../../../contracts/build/contracts/ERC20').abi -const BRIDGE_ABI = require('../../../contracts/build/contracts/ForeignBridgeErcToNative').abi +const { ERC20_ABI, FOREIGN_ERC_TO_NATIVE_ABI } = require('../../../commons') const foreignRpcUrl = rpcUrlsManager.foreignUrls[0] const foreignProvider = new Web3.providers.HttpProvider(foreignRpcUrl) const web3Foreign = new Web3(foreignProvider) async function main() { - const bridge = new web3Foreign.eth.Contract(BRIDGE_ABI, FOREIGN_BRIDGE_ADDRESS) + const bridge = new web3Foreign.eth.Contract(FOREIGN_ERC_TO_NATIVE_ABI, FOREIGN_BRIDGE_ADDRESS) const ERC20_TOKEN_ADDRESS = await bridge.methods.erc20token().call() const poa20 = new web3Foreign.eth.Contract(ERC20_ABI, ERC20_TOKEN_ADDRESS) diff --git a/oracle/scripts/erc20_to_native/sendHome.js b/oracle/scripts/erc20_to_native/sendHome.js index 530c6a8c..68d6b21e 100644 --- a/oracle/scripts/erc20_to_native/sendHome.js +++ b/oracle/scripts/erc20_to_native/sendHome.js @@ -3,7 +3,7 @@ const Web3Utils = require('web3-utils') const { web3Home } = require('../../src/services/web3') const { sendTx, sendRawTx } = require('../../src/tx/sendTx') const { isValidAmount } = require('../utils/utils') -const BRIDGE_ABI = require('../../../contracts/build/contracts/HomeBridgeErcToNative').abi +const { HOME_ERC_TO_NATIVE_ABI } = require('../../../commons') const { USER_ADDRESS, @@ -16,7 +16,7 @@ const { const NUMBER_OF_DEPOSITS_TO_SEND = process.argv[2] || 1 async function main() { - const bridge = new web3Home.eth.Contract(BRIDGE_ABI, HOME_BRIDGE_ADDRESS) + const bridge = new web3Home.eth.Contract(HOME_ERC_TO_NATIVE_ABI, HOME_BRIDGE_ADDRESS) try { await isValidAmount(HOME_MIN_AMOUNT_PER_TX, bridge) diff --git a/oracle/scripts/getValidatorStartBlocks.js b/oracle/scripts/getValidatorStartBlocks.js index 8d97ddb4..7bf48b70 100644 --- a/oracle/scripts/getValidatorStartBlocks.js +++ b/oracle/scripts/getValidatorStartBlocks.js @@ -1,9 +1,8 @@ require('../env') const Web3 = require('web3') -const bridgeValidatorsABI = require('../../contracts/build/contracts/BridgeValidators').abi +const { BRIDGE_VALIDATORS_ABI } = require('../../commons') const rpcUrlsManager = require('../src/services/getRpcUrlsManager') - const { bridgeConfig } = require('../config/base.config') const homeABI = bridgeConfig.homeBridgeAbi @@ -19,7 +18,7 @@ async function getStartBlock(rpcUrl, bridgeAddress, bridgeAbi) { const validatorContractAddress = await bridgeContract.methods.validatorContract().call() const validatorContract = new web3Instance.eth.Contract( - bridgeValidatorsABI, + BRIDGE_VALIDATORS_ABI, validatorContractAddress ) diff --git a/oracle/scripts/initialChecks.js b/oracle/scripts/initialChecks.js index 741c0de2..94d7e71f 100644 --- a/oracle/scripts/initialChecks.js +++ b/oracle/scripts/initialChecks.js @@ -1,6 +1,6 @@ require('../env') const Web3 = require('web3') -const ERC677BridgeTokenABI = require('../../contracts/build/contracts/ERC677BridgeToken').abi +const { ERC677_BRIDGE_TOKEN_ABI } = require('../../commons') const { ERC_TYPES } = require('../src/utils/constants') async function initialChecks() { @@ -9,7 +9,7 @@ async function initialChecks() { if (BRIDGE_MODE === 'ERC_TO_ERC') { const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(FOREIGN_RPC_URL)) - const tokenContract = new foreignWeb3.eth.Contract(ERC677BridgeTokenABI, ERC20_TOKEN_ADDRESS) + const tokenContract = new foreignWeb3.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, ERC20_TOKEN_ADDRESS) try { const bridgeContract = await tokenContract.methods.bridgeContract().call() if (bridgeContract === FOREIGN_BRIDGE_ADDRESS) { diff --git a/oracle/scripts/native_to_erc20/sendForeign.js b/oracle/scripts/native_to_erc20/sendForeign.js index 56d773ab..14d95143 100644 --- a/oracle/scripts/native_to_erc20/sendForeign.js +++ b/oracle/scripts/native_to_erc20/sendForeign.js @@ -3,6 +3,7 @@ const Web3Utils = require('web3-utils') const { web3Foreign } = require('../../src/services/web3') const { sendTx, sendRawTx } = require('../../src/tx/sendTx') const { isValidAmount } = require('../utils/utils') +const { FOREIGN_NATIVE_TO_ERC_ABI } = require('../../../commons') const { USER_ADDRESS, @@ -44,10 +45,9 @@ const ERC677_ABI = [ type: 'function' } ] -const BRIDGE_ABI = require('../../../contracts/build/contracts/ForeignBridgeNativeToErc').abi async function main() { - const bridge = new web3Foreign.eth.Contract(BRIDGE_ABI, FOREIGN_BRIDGE_ADDRESS) + const bridge = new web3Foreign.eth.Contract(FOREIGN_NATIVE_TO_ERC_ABI, FOREIGN_BRIDGE_ADDRESS) const ERC20_TOKEN_ADDRESS = await bridge.methods.erc677token().call() const poa20 = new web3Foreign.eth.Contract(ERC677_ABI, ERC20_TOKEN_ADDRESS) diff --git a/oracle/scripts/native_to_erc20/sendHome.js b/oracle/scripts/native_to_erc20/sendHome.js index 6f02747b..439fb1b1 100644 --- a/oracle/scripts/native_to_erc20/sendHome.js +++ b/oracle/scripts/native_to_erc20/sendHome.js @@ -3,7 +3,7 @@ const Web3Utils = require('web3-utils') const { web3Home } = require('../../src/services/web3') const { sendTx, sendRawTx } = require('../../src/tx/sendTx') const { isValidAmount } = require('../utils/utils') -const BRIDGE_ABI = require('../../../contracts/build/contracts/HomeBridgeNativeToErc').abi +const { HOME_NATIVE_TO_ERC_ABI } = require('../../../commons') const { USER_ADDRESS, @@ -16,7 +16,7 @@ const { const NUMBER_OF_DEPOSITS_TO_SEND = process.argv[2] || 1 async function main() { - const bridge = new web3Home.eth.Contract(BRIDGE_ABI, HOME_BRIDGE_ADDRESS) + const bridge = new web3Home.eth.Contract(HOME_NATIVE_TO_ERC_ABI, HOME_BRIDGE_ADDRESS) try { await isValidAmount(HOME_MIN_AMOUNT_PER_TX, bridge) diff --git a/oracle/src/events/processAffirmationRequests/index.js b/oracle/src/events/processAffirmationRequests/index.js index 09996c6f..57d36a0d 100644 --- a/oracle/src/events/processAffirmationRequests/index.js +++ b/oracle/src/events/processAffirmationRequests/index.js @@ -4,7 +4,7 @@ const { HttpListProviderError } = require('http-list-provider') const rootLogger = require('../../services/logger') const { web3Home } = require('../../services/web3') -const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi +const { BRIDGE_VALIDATORS_ABI } = require('../../../../commons') const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants') const estimateGas = require('./estimateGas') const { @@ -28,7 +28,7 @@ function processAffirmationRequestsBuilder(config) { const validatorContractAddress = await homeBridge.methods.validatorContract().call() rootLogger.debug({ validatorContractAddress }, 'Validator contract address obtained') - validatorContract = new web3Home.eth.Contract(bridgeValidatorsABI, validatorContractAddress) + validatorContract = new web3Home.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorContractAddress) } rootLogger.debug(`Processing ${affirmationRequests.length} AffirmationRequest events`) diff --git a/oracle/src/events/processCollectedSignatures/index.js b/oracle/src/events/processCollectedSignatures/index.js index db83a20b..288f57f3 100644 --- a/oracle/src/events/processCollectedSignatures/index.js +++ b/oracle/src/events/processCollectedSignatures/index.js @@ -1,7 +1,7 @@ require('../../../env') const promiseLimit = require('promise-limit') const { HttpListProviderError } = require('http-list-provider') -const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi +const { BRIDGE_VALIDATORS_ABI } = require('../../../../commons') const rootLogger = require('../../services/logger') const { web3Home, web3Foreign } = require('../../services/web3') const { signatureToVRS } = require('../../utils/message') @@ -34,7 +34,7 @@ function processCollectedSignaturesBuilder(config) { rootLogger.debug({ validatorContractAddress }, 'Validator contract address obtained') validatorContract = new web3Foreign.eth.Contract( - bridgeValidatorsABI, + BRIDGE_VALIDATORS_ABI, validatorContractAddress ) } diff --git a/oracle/src/events/processSignatureRequests/index.js b/oracle/src/events/processSignatureRequests/index.js index 309a810a..a90f9da6 100644 --- a/oracle/src/events/processSignatureRequests/index.js +++ b/oracle/src/events/processSignatureRequests/index.js @@ -1,7 +1,7 @@ require('../../../env') const promiseLimit = require('promise-limit') const { HttpListProviderError } = require('http-list-provider') -const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi +const { BRIDGE_VALIDATORS_ABI } = require('../../../../commons') const rootLogger = require('../../services/logger') const { web3Home } = require('../../services/web3') const { createMessage } = require('../../utils/message') @@ -35,7 +35,7 @@ function processSignatureRequestsBuilder(config) { const validatorContractAddress = await homeBridge.methods.validatorContract().call() rootLogger.debug({ validatorContractAddress }, 'Validator contract address obtained') - validatorContract = new web3Home.eth.Contract(bridgeValidatorsABI, validatorContractAddress) + validatorContract = new web3Home.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorContractAddress) } rootLogger.debug(`Processing ${signatureRequests.length} SignatureRequest events`) diff --git a/oracle/src/events/processTransfers/index.js b/oracle/src/events/processTransfers/index.js index 4ac75608..3354fecb 100644 --- a/oracle/src/events/processTransfers/index.js +++ b/oracle/src/events/processTransfers/index.js @@ -1,7 +1,7 @@ require('../../../env') const promiseLimit = require('promise-limit') const { HttpListProviderError } = require('http-list-provider') -const bridgeValidatorsABI = require('../../../../contracts/build/contracts/BridgeValidators').abi +const { BRIDGE_VALIDATORS_ABI } = require('../../../../commons') const rootLogger = require('../../services/logger') const { web3Home } = require('../../services/web3') const { @@ -27,7 +27,7 @@ function processTransfersBuilder(config) { const validatorContractAddress = await homeBridge.methods.validatorContract().call() rootLogger.debug({ validatorContractAddress }, 'Validator contract address obtained') - validatorContract = new web3Home.eth.Contract(bridgeValidatorsABI, validatorContractAddress) + validatorContract = new web3Home.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorContractAddress) } rootLogger.debug(`Processing ${transfers.length} Transfer events`)