diff --git a/commons/abis.js b/commons/abis.js index 655c785f..ade171d6 100644 --- a/commons/abis.js +++ b/commons/abis.js @@ -13,6 +13,9 @@ const ERC677_BRIDGE_TOKEN_ABI = require('../contracts/build/contracts/ERC677Brid const BLOCK_REWARD_ABI = require('../contracts/build/contracts/IBlockReward').abi const BRIDGE_VALIDATORS_ABI = require('../contracts/build/contracts/BridgeValidators').abi const REWARDABLE_VALIDATORS_ABI = require('../contracts/build/contracts/RewardableValidators').abi +const HOME_AMB_ABI = require('../contracts/build/contracts/HomeAMB').abi +const FOREIGN_AMB_ABI = require('../contracts/build/contracts/ForeignAMB').abi +const BOX_ABI = require('../contracts/build/contracts/Box').abi const { homeV1Abi, foreignViAbi } = require('./v1Abis') const { BRIDGE_MODES } = require('./constants') @@ -52,5 +55,8 @@ module.exports = { ERC677_BRIDGE_TOKEN_ABI, BLOCK_REWARD_ABI, BRIDGE_VALIDATORS_ABI, - REWARDABLE_VALIDATORS_ABI + REWARDABLE_VALIDATORS_ABI, + HOME_AMB_ABI, + FOREIGN_AMB_ABI, + BOX_ABI } diff --git a/e2e-commons/constants.json b/e2e-commons/constants.json index 0f5e87f2..61f18815 100644 --- a/e2e-commons/constants.json +++ b/e2e-commons/constants.json @@ -30,6 +30,12 @@ "foreignToken": "0x3C665A31199694Bf723fD08844AD290207B5797f", "ui": "http://localhost:3002" }, + "amb": { + "home": "0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0", + "foreign": "0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0", + "homeBox": "0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1", + "foreignBox": "0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1" + }, "homeRPC": { "URL": "http://parity1:8545", "ID": "77" diff --git a/e2e-commons/docker-compose.yml b/e2e-commons/docker-compose.yml index 06689717..7d620ae6 100644 --- a/e2e-commons/docker-compose.yml +++ b/e2e-commons/docker-compose.yml @@ -109,6 +109,34 @@ services: - FOREIGN_POLLING_INTERVAL=500 - ALLOW_HTTP=yes command: "true" + oracle-amb: + build: + context: .. + dockerfile: oracle/Dockerfile + environment: + - NODE_ENV=production + - BRIDGE_MODE=ARBITRARY_MESSAGE + - QUEUE_URL=amqp://rabbit + - REDIS_URL=redis://redis + - HOME_RPC_URL=http://parity1:8545 + - FOREIGN_RPC_URL=http://parity2:8545 + - HOME_BRIDGE_ADDRESS=0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0 + - FOREIGN_BRIDGE_ADDRESS=0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0 + - VALIDATOR_ADDRESS_PRIVATE_KEY=8e829f695aed89a154550f30262f1529582cc49dc30eff74a6b491359e0230f9 + - HOME_GAS_PRICE_ORACLE_URL=https://gasprice.poa.network/ + - HOME_GAS_PRICE_SPEED_TYPE=standard + - HOME_GAS_PRICE_FALLBACK=1000000000 + - HOME_GAS_PRICE_UPDATE_INTERVAL=600000 + - HOME_GAS_PRICE_FACTOR=1 + - FOREIGN_GAS_PRICE_ORACLE_URL=https://gasprice.poa.network/ + - FOREIGN_GAS_PRICE_SPEED_TYPE=standard + - FOREIGN_GAS_PRICE_FALLBACK=10000000000 + - FOREIGN_GAS_PRICE_UPDATE_INTERVAL=600000 + - FOREIGN_GAS_PRICE_FACTOR=1 + - HOME_POLLING_INTERVAL=500 + - FOREIGN_POLLING_INTERVAL=500 + - ALLOW_HTTP=yes + command: "true" ui: build: context: .. diff --git a/oracle-e2e/envs/amb-contract-deploy.env b/e2e-commons/envs/amb.env similarity index 100% rename from oracle-e2e/envs/amb-contract-deploy.env rename to e2e-commons/envs/amb.env diff --git a/e2e-commons/scripts/deploy.sh b/e2e-commons/scripts/deploy.sh index 7feb2062..ebbca25e 100755 --- a/e2e-commons/scripts/deploy.sh +++ b/e2e-commons/scripts/deploy.sh @@ -29,3 +29,14 @@ cp "$ENVS_PATH/erc-to-native.env" "$DEPLOY_PATH/.env" cd "$DEPLOY_PATH" node deploy.js cd - > /dev/null + +echo -e "\n\n############ Deploying amb ############\n" +cp "$ENVS_PATH/amb.env" "$DEPLOY_PATH/.env" +cd "$DEPLOY_PATH" +node deploy.js +cd - > /dev/null + +echo -e "\n\n############ Deploying test contract for amb ############\n" +cd "$DEPLOY_PATH" +node src/utils/deployTestBox.js +cd - > /dev/null diff --git a/e2e-commons/up.sh b/e2e-commons/up.sh index 5820f156..68cf8302 100755 --- a/e2e-commons/up.sh +++ b/e2e-commons/up.sh @@ -24,6 +24,9 @@ while [ "$1" != "" ]; do docker-compose run -d oracle-erc20-native yarn watcher:signature-request docker-compose run -d oracle-erc20-native yarn watcher:collected-signatures docker-compose run -d oracle-erc20-native yarn watcher:affirmation-request + docker-compose run -d oracle-amb yarn watcher:signature-request + docker-compose run -d oracle-amb yarn watcher:collected-signatures + docker-compose run -d oracle-amb yarn watcher:affirmation-request docker-compose run -d oracle yarn sender:home docker-compose run -d oracle yarn sender:foreign fi diff --git a/oracle-e2e/test/amb.js b/oracle-e2e/test/amb.js index 0ce1af59..518dce5a 100644 --- a/oracle-e2e/test/amb.js +++ b/oracle-e2e/test/amb.js @@ -1,21 +1,14 @@ -const path = require('path') const Web3 = require('web3') const assert = require('assert') const promiseRetry = require('promise-retry') -const { user, validator, contractsPath } = require('../constants.json') -const { generateNewBlock } = require('../utils/utils') +const { user, validator, homeRPC, foreignRPC, amb } = require('../../e2e-commons/constants.json') +const { generateNewBlock } = require('../../e2e-commons/utils') +const { HOME_AMB_ABI, FOREIGN_AMB_ABI, BOX_ABI } = require('../../commons') + const { toBN } = Web3.utils -const abisDir = path.join(__dirname, '..', contractsPath, 'build/contracts') - -const homeWeb3 = new Web3(new Web3.providers.HttpProvider('http://parity1:8545')) -const foreignWeb3 = new Web3(new Web3.providers.HttpProvider('http://parity2:8545')) - -const homeBridgeAddress = '0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0' -const foreignBridgeAddress = '0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0' - -const homeBoxAddress = '0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1' -const foreignBoxAddress = '0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1' +const homeWeb3 = new Web3(new Web3.providers.HttpProvider(homeRPC.URL)) +const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(foreignRPC.URL)) homeWeb3.eth.accounts.wallet.add(user.privateKey) foreignWeb3.eth.accounts.wallet.add(user.privateKey) @@ -23,15 +16,11 @@ foreignWeb3.eth.accounts.wallet.add(user.privateKey) homeWeb3.eth.accounts.wallet.add(validator.privateKey) foreignWeb3.eth.accounts.wallet.add(validator.privateKey) -const homeAbi = require(path.join(abisDir, 'HomeAMB.json')).abi -const foreignAbi = require(path.join(abisDir, 'ForeignAMB.json')).abi -const boxAbi = require(path.join(abisDir, 'Box.json')).abi +const homeAMB = new homeWeb3.eth.Contract(HOME_AMB_ABI, amb.home) +const homeBox = new homeWeb3.eth.Contract(BOX_ABI, amb.homeBox) -const homeAMB = new homeWeb3.eth.Contract(homeAbi, homeBridgeAddress) -const homeBox = new homeWeb3.eth.Contract(boxAbi, homeBoxAddress) - -const foreignAMB = new foreignWeb3.eth.Contract(foreignAbi, foreignBridgeAddress) -const foreignBox = new foreignWeb3.eth.Contract(boxAbi, foreignBoxAddress) +const foreignAMB = new foreignWeb3.eth.Contract(FOREIGN_AMB_ABI, amb.foreign) +const foreignBox = new foreignWeb3.eth.Contract(BOX_ABI, amb.foreignBox) const oneEther = foreignWeb3.utils.toWei('1', 'ether') const subsidizedHash = homeWeb3.utils.toHex('AMB-subsidized-mode') @@ -40,16 +29,16 @@ describe('arbitrary message bridging', () => { describe('Home to Foreign', () => { describe('Defrayal Mode', () => { it('should be able to deposit funds for home sender', async () => { - const initialBalance = await foreignAMB.methods.balanceOf(homeBoxAddress).call() + const initialBalance = await foreignAMB.methods.balanceOf(amb.homeBox).call() assert(toBN(initialBalance).isZero(), 'Balance should be zero') - await foreignAMB.methods.depositForContractSender(homeBoxAddress).send({ + await foreignAMB.methods.depositForContractSender(amb.homeBox).send({ from: user.address, gas: '1000000', value: oneEther }) - const balance = await foreignAMB.methods.balanceOf(homeBoxAddress).call() + const balance = await foreignAMB.methods.balanceOf(amb.homeBox).call() assert(toBN(balance).eq(toBN(oneEther)), 'Balance should be one ether') }) it('should bridge message and take fees', async () => { @@ -58,16 +47,11 @@ describe('arbitrary message bridging', () => { const initialValue = await foreignBox.methods.value().call() assert(toBN(initialValue).isZero(), 'Value should be zero') - const initialBalance = await foreignAMB.methods.balanceOf(homeBoxAddress).call() + const initialBalance = await foreignAMB.methods.balanceOf(amb.homeBox).call() assert(!toBN(initialBalance).isZero(), 'Balance should not be zero') const setValueTx = await homeBox.methods - .setValueOnOtherNetworkGasPrice( - newValue, - homeBridgeAddress, - foreignBoxAddress, - '1000000000' - ) + .setValueOnOtherNetworkGasPrice(newValue, amb.home, amb.foreignBox, '1000000000') .send({ from: user.address, gas: '1000000' @@ -101,14 +85,14 @@ describe('arbitrary message bridging', () => { // check that value changed and balance decreased await promiseRetry(async retry => { const value = await foreignBox.methods.value().call() - const balance = await foreignAMB.methods.balanceOf(homeBoxAddress).call() + const balance = await foreignAMB.methods.balanceOf(amb.homeBox).call() if (!toBN(value).eq(toBN(newValue)) || toBN(balance).gte(toBN(oneEther))) { retry() } }) }) it('should be able to withdraw from deposit', async () => { - const initialBalance = await foreignAMB.methods.balanceOf(homeBoxAddress).call() + const initialBalance = await foreignAMB.methods.balanceOf(amb.homeBox).call() assert(!toBN(initialBalance).isZero(), 'Balance should not be zero') const initialUserBalance = toBN(await foreignWeb3.eth.getBalance(user.address)) @@ -116,8 +100,8 @@ describe('arbitrary message bridging', () => { const tx = await homeBox.methods .withdrawFromDepositOnOtherNetworkGasPrice( user.address, - homeBridgeAddress, - foreignBridgeAddress, + amb.home, + amb.foreign, '1000000000' ) .send({ @@ -153,7 +137,7 @@ describe('arbitrary message bridging', () => { // check that value changed and balance decreased await promiseRetry(async retry => { const userBalance = toBN(await foreignWeb3.eth.getBalance(user.address)) - const boxBalance = toBN(await foreignAMB.methods.balanceOf(homeBoxAddress).call()) + const boxBalance = toBN(await foreignAMB.methods.balanceOf(amb.homeBox).call()) if (!boxBalance.isZero() || userBalance.lte(initialUserBalance)) { retry() } @@ -186,12 +170,7 @@ describe('arbitrary message bridging', () => { ) const setValueTx = await homeBox.methods - .setValueOnOtherNetworkGasPrice( - newValue, - homeBridgeAddress, - foreignBoxAddress, - '1000000000' - ) + .setValueOnOtherNetworkGasPrice(newValue, amb.home, amb.foreignBox, '1000000000') .send({ from: user.address, gas: '1000000' @@ -235,16 +214,16 @@ describe('arbitrary message bridging', () => { describe('Foreign to Home', () => { describe('Defrayal Mode', () => { it('should be able to deposit funds for foreign sender', async () => { - const initialBalance = await homeAMB.methods.balanceOf(foreignBoxAddress).call() + const initialBalance = await homeAMB.methods.balanceOf(amb.foreignBox).call() assert(toBN(initialBalance).isZero(), 'Balance should be zero') - await homeAMB.methods.depositForContractSender(homeBoxAddress).send({ + await homeAMB.methods.depositForContractSender(amb.homeBox).send({ from: user.address, gas: '1000000', value: oneEther }) - const balance = await homeAMB.methods.balanceOf(foreignBoxAddress).call() + const balance = await homeAMB.methods.balanceOf(amb.foreignBox).call() assert(toBN(balance).eq(toBN(oneEther)), 'Balance should be one ether') }) it('should bridge message and take fees', async () => { @@ -253,16 +232,11 @@ describe('arbitrary message bridging', () => { const initialValue = await homeBox.methods.value().call() assert(toBN(initialValue).isZero(), 'Value should be zero') - const initialBalance = await homeAMB.methods.balanceOf(foreignBoxAddress).call() + const initialBalance = await homeAMB.methods.balanceOf(amb.foreignBox).call() assert(!toBN(initialBalance).isZero(), 'Balance should not be zero') await foreignBox.methods - .setValueOnOtherNetworkGasPrice( - newValue, - foreignBridgeAddress, - homeBoxAddress, - '1000000000' - ) + .setValueOnOtherNetworkGasPrice(newValue, amb.foreign, amb.homeBox, '1000000000') .send({ from: user.address, gas: '1000000' @@ -278,14 +252,14 @@ describe('arbitrary message bridging', () => { // check that value changed and balance decreased await promiseRetry(async retry => { const value = await homeBox.methods.value().call() - const balance = await homeAMB.methods.balanceOf(foreignBoxAddress).call() + const balance = await homeAMB.methods.balanceOf(amb.foreignBox).call() if (!toBN(value).eq(toBN(newValue)) || toBN(balance).gte(toBN(oneEther))) { retry() } }) }) it('should be able to withdraw from deposit', async () => { - const initialBalance = await homeAMB.methods.balanceOf(foreignBoxAddress).call() + const initialBalance = await homeAMB.methods.balanceOf(amb.foreignBox).call() assert(!toBN(initialBalance).isZero(), 'Balance should not be zero') const initialUserBalance = toBN(await homeWeb3.eth.getBalance(user.address)) @@ -293,8 +267,8 @@ describe('arbitrary message bridging', () => { await foreignBox.methods .withdrawFromDepositOnOtherNetworkGasPrice( user.address, - foreignBridgeAddress, - homeBridgeAddress, + amb.foreign, + amb.home, '1000000000' ) .send({ @@ -312,7 +286,7 @@ describe('arbitrary message bridging', () => { // check that value changed and balance decreased await promiseRetry(async retry => { const userBalance = toBN(await homeWeb3.eth.getBalance(user.address)) - const boxBalance = toBN(await homeAMB.methods.balanceOf(foreignBoxAddress).call()) + const boxBalance = toBN(await homeAMB.methods.balanceOf(amb.foreignBox).call()) if (!boxBalance.isZero() || userBalance.lte(initialUserBalance)) { retry() } @@ -347,12 +321,7 @@ describe('arbitrary message bridging', () => { ) await foreignBox.methods - .setValueOnOtherNetworkGasPrice( - newValue, - homeBridgeAddress, - foreignBoxAddress, - '1000000000' - ) + .setValueOnOtherNetworkGasPrice(newValue, amb.home, amb.foreignBox, '1000000000') .send({ from: user.address, gas: '1000000' diff --git a/oracle/config/base.config.js b/oracle/config/base.config.js index 5a42abf1..2a7998b4 100644 --- a/oracle/config/base.config.js +++ b/oracle/config/base.config.js @@ -8,14 +8,13 @@ const { HOME_ERC_TO_ERC_ABI, FOREIGN_ERC_TO_ERC_ABI, HOME_ERC_TO_NATIVE_ABI, - FOREIGN_ERC_TO_NATIVE_ABI + FOREIGN_ERC_TO_NATIVE_ABI, + HOME_AMB_ABI, + FOREIGN_AMB_ABI } = require('../../commons') const { web3Home, web3Foreign } = require('../src/services/web3') const { privateKeyToAddress } = require('../src/utils/utils') -const homeAMBAbi = require('../../contracts/build/contracts/HomeAMB').abi -const foreignAMBAbi = require('../../contracts/build/contracts/ForeignAMB').abi - const { VALIDATOR_ADDRESS, VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env let homeAbi @@ -39,8 +38,8 @@ switch (process.env.BRIDGE_MODE) { id = 'erc-native' break case 'ARBITRARY_MESSAGE': - homeAbi = homeAMBAbi - foreignAbi = foreignAMBAbi + homeAbi = HOME_AMB_ABI + foreignAbi = FOREIGN_AMB_ABI id = 'amb' break default: