Oracle amb merge fix

This commit is contained in:
Gerardo Nardelli 2019-07-17 11:47:25 -03:00
parent 0694fc24e9
commit 70d03c1a93
8 changed files with 92 additions and 70 deletions

@ -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 BLOCK_REWARD_ABI = require('../contracts/build/contracts/IBlockReward').abi
const BRIDGE_VALIDATORS_ABI = require('../contracts/build/contracts/BridgeValidators').abi const BRIDGE_VALIDATORS_ABI = require('../contracts/build/contracts/BridgeValidators').abi
const REWARDABLE_VALIDATORS_ABI = require('../contracts/build/contracts/RewardableValidators').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 { homeV1Abi, foreignViAbi } = require('./v1Abis')
const { BRIDGE_MODES } = require('./constants') const { BRIDGE_MODES } = require('./constants')
@ -52,5 +55,8 @@ module.exports = {
ERC677_BRIDGE_TOKEN_ABI, ERC677_BRIDGE_TOKEN_ABI,
BLOCK_REWARD_ABI, BLOCK_REWARD_ABI,
BRIDGE_VALIDATORS_ABI, BRIDGE_VALIDATORS_ABI,
REWARDABLE_VALIDATORS_ABI REWARDABLE_VALIDATORS_ABI,
HOME_AMB_ABI,
FOREIGN_AMB_ABI,
BOX_ABI
} }

@ -30,6 +30,12 @@
"foreignToken": "0x3C665A31199694Bf723fD08844AD290207B5797f", "foreignToken": "0x3C665A31199694Bf723fD08844AD290207B5797f",
"ui": "http://localhost:3002" "ui": "http://localhost:3002"
}, },
"amb": {
"home": "0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0",
"foreign": "0x0AEe1FCD12dDFab6265F7f8956e6E012A9Fe4Aa0",
"homeBox": "0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1",
"foreignBox": "0x6C4EaAb8756d53Bf599FFe2347FAFF1123D6C8A1"
},
"homeRPC": { "homeRPC": {
"URL": "http://parity1:8545", "URL": "http://parity1:8545",
"ID": "77" "ID": "77"

@ -109,6 +109,34 @@ services:
- FOREIGN_POLLING_INTERVAL=500 - FOREIGN_POLLING_INTERVAL=500
- ALLOW_HTTP=yes - ALLOW_HTTP=yes
command: "true" 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: ui:
build: build:
context: .. context: ..

@ -29,3 +29,14 @@ cp "$ENVS_PATH/erc-to-native.env" "$DEPLOY_PATH/.env"
cd "$DEPLOY_PATH" cd "$DEPLOY_PATH"
node deploy.js node deploy.js
cd - > /dev/null 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

@ -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:signature-request
docker-compose run -d oracle-erc20-native yarn watcher:collected-signatures 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-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:home
docker-compose run -d oracle yarn sender:foreign docker-compose run -d oracle yarn sender:foreign
fi fi

@ -1,21 +1,14 @@
const path = require('path')
const Web3 = require('web3') const Web3 = require('web3')
const assert = require('assert') const assert = require('assert')
const promiseRetry = require('promise-retry') const promiseRetry = require('promise-retry')
const { user, validator, contractsPath } = require('../constants.json') const { user, validator, homeRPC, foreignRPC, amb } = require('../../e2e-commons/constants.json')
const { generateNewBlock } = require('../utils/utils') const { generateNewBlock } = require('../../e2e-commons/utils')
const { HOME_AMB_ABI, FOREIGN_AMB_ABI, BOX_ABI } = require('../../commons')
const { toBN } = Web3.utils const { toBN } = Web3.utils
const abisDir = path.join(__dirname, '..', contractsPath, 'build/contracts') const homeWeb3 = new Web3(new Web3.providers.HttpProvider(homeRPC.URL))
const foreignWeb3 = new Web3(new Web3.providers.HttpProvider(foreignRPC.URL))
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'
homeWeb3.eth.accounts.wallet.add(user.privateKey) homeWeb3.eth.accounts.wallet.add(user.privateKey)
foreignWeb3.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) homeWeb3.eth.accounts.wallet.add(validator.privateKey)
foreignWeb3.eth.accounts.wallet.add(validator.privateKey) foreignWeb3.eth.accounts.wallet.add(validator.privateKey)
const homeAbi = require(path.join(abisDir, 'HomeAMB.json')).abi const homeAMB = new homeWeb3.eth.Contract(HOME_AMB_ABI, amb.home)
const foreignAbi = require(path.join(abisDir, 'ForeignAMB.json')).abi const homeBox = new homeWeb3.eth.Contract(BOX_ABI, amb.homeBox)
const boxAbi = require(path.join(abisDir, 'Box.json')).abi
const homeAMB = new homeWeb3.eth.Contract(homeAbi, homeBridgeAddress) const foreignAMB = new foreignWeb3.eth.Contract(FOREIGN_AMB_ABI, amb.foreign)
const homeBox = new homeWeb3.eth.Contract(boxAbi, homeBoxAddress) const foreignBox = new foreignWeb3.eth.Contract(BOX_ABI, amb.foreignBox)
const foreignAMB = new foreignWeb3.eth.Contract(foreignAbi, foreignBridgeAddress)
const foreignBox = new foreignWeb3.eth.Contract(boxAbi, foreignBoxAddress)
const oneEther = foreignWeb3.utils.toWei('1', 'ether') const oneEther = foreignWeb3.utils.toWei('1', 'ether')
const subsidizedHash = homeWeb3.utils.toHex('AMB-subsidized-mode') const subsidizedHash = homeWeb3.utils.toHex('AMB-subsidized-mode')
@ -40,16 +29,16 @@ describe('arbitrary message bridging', () => {
describe('Home to Foreign', () => { describe('Home to Foreign', () => {
describe('Defrayal Mode', () => { describe('Defrayal Mode', () => {
it('should be able to deposit funds for home sender', async () => { 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') assert(toBN(initialBalance).isZero(), 'Balance should be zero')
await foreignAMB.methods.depositForContractSender(homeBoxAddress).send({ await foreignAMB.methods.depositForContractSender(amb.homeBox).send({
from: user.address, from: user.address,
gas: '1000000', gas: '1000000',
value: oneEther 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') assert(toBN(balance).eq(toBN(oneEther)), 'Balance should be one ether')
}) })
it('should bridge message and take fees', async () => { it('should bridge message and take fees', async () => {
@ -58,16 +47,11 @@ describe('arbitrary message bridging', () => {
const initialValue = await foreignBox.methods.value().call() const initialValue = await foreignBox.methods.value().call()
assert(toBN(initialValue).isZero(), 'Value should be zero') 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') assert(!toBN(initialBalance).isZero(), 'Balance should not be zero')
const setValueTx = await homeBox.methods const setValueTx = await homeBox.methods
.setValueOnOtherNetworkGasPrice( .setValueOnOtherNetworkGasPrice(newValue, amb.home, amb.foreignBox, '1000000000')
newValue,
homeBridgeAddress,
foreignBoxAddress,
'1000000000'
)
.send({ .send({
from: user.address, from: user.address,
gas: '1000000' gas: '1000000'
@ -101,14 +85,14 @@ describe('arbitrary message bridging', () => {
// check that value changed and balance decreased // check that value changed and balance decreased
await promiseRetry(async retry => { await promiseRetry(async retry => {
const value = await foreignBox.methods.value().call() 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))) { if (!toBN(value).eq(toBN(newValue)) || toBN(balance).gte(toBN(oneEther))) {
retry() retry()
} }
}) })
}) })
it('should be able to withdraw from deposit', async () => { 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') assert(!toBN(initialBalance).isZero(), 'Balance should not be zero')
const initialUserBalance = toBN(await foreignWeb3.eth.getBalance(user.address)) const initialUserBalance = toBN(await foreignWeb3.eth.getBalance(user.address))
@ -116,8 +100,8 @@ describe('arbitrary message bridging', () => {
const tx = await homeBox.methods const tx = await homeBox.methods
.withdrawFromDepositOnOtherNetworkGasPrice( .withdrawFromDepositOnOtherNetworkGasPrice(
user.address, user.address,
homeBridgeAddress, amb.home,
foreignBridgeAddress, amb.foreign,
'1000000000' '1000000000'
) )
.send({ .send({
@ -153,7 +137,7 @@ describe('arbitrary message bridging', () => {
// check that value changed and balance decreased // check that value changed and balance decreased
await promiseRetry(async retry => { await promiseRetry(async retry => {
const userBalance = toBN(await foreignWeb3.eth.getBalance(user.address)) 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)) { if (!boxBalance.isZero() || userBalance.lte(initialUserBalance)) {
retry() retry()
} }
@ -186,12 +170,7 @@ describe('arbitrary message bridging', () => {
) )
const setValueTx = await homeBox.methods const setValueTx = await homeBox.methods
.setValueOnOtherNetworkGasPrice( .setValueOnOtherNetworkGasPrice(newValue, amb.home, amb.foreignBox, '1000000000')
newValue,
homeBridgeAddress,
foreignBoxAddress,
'1000000000'
)
.send({ .send({
from: user.address, from: user.address,
gas: '1000000' gas: '1000000'
@ -235,16 +214,16 @@ describe('arbitrary message bridging', () => {
describe('Foreign to Home', () => { describe('Foreign to Home', () => {
describe('Defrayal Mode', () => { describe('Defrayal Mode', () => {
it('should be able to deposit funds for foreign sender', async () => { 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') assert(toBN(initialBalance).isZero(), 'Balance should be zero')
await homeAMB.methods.depositForContractSender(homeBoxAddress).send({ await homeAMB.methods.depositForContractSender(amb.homeBox).send({
from: user.address, from: user.address,
gas: '1000000', gas: '1000000',
value: oneEther 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') assert(toBN(balance).eq(toBN(oneEther)), 'Balance should be one ether')
}) })
it('should bridge message and take fees', async () => { it('should bridge message and take fees', async () => {
@ -253,16 +232,11 @@ describe('arbitrary message bridging', () => {
const initialValue = await homeBox.methods.value().call() const initialValue = await homeBox.methods.value().call()
assert(toBN(initialValue).isZero(), 'Value should be zero') 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') assert(!toBN(initialBalance).isZero(), 'Balance should not be zero')
await foreignBox.methods await foreignBox.methods
.setValueOnOtherNetworkGasPrice( .setValueOnOtherNetworkGasPrice(newValue, amb.foreign, amb.homeBox, '1000000000')
newValue,
foreignBridgeAddress,
homeBoxAddress,
'1000000000'
)
.send({ .send({
from: user.address, from: user.address,
gas: '1000000' gas: '1000000'
@ -278,14 +252,14 @@ describe('arbitrary message bridging', () => {
// check that value changed and balance decreased // check that value changed and balance decreased
await promiseRetry(async retry => { await promiseRetry(async retry => {
const value = await homeBox.methods.value().call() 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))) { if (!toBN(value).eq(toBN(newValue)) || toBN(balance).gte(toBN(oneEther))) {
retry() retry()
} }
}) })
}) })
it('should be able to withdraw from deposit', async () => { 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') assert(!toBN(initialBalance).isZero(), 'Balance should not be zero')
const initialUserBalance = toBN(await homeWeb3.eth.getBalance(user.address)) const initialUserBalance = toBN(await homeWeb3.eth.getBalance(user.address))
@ -293,8 +267,8 @@ describe('arbitrary message bridging', () => {
await foreignBox.methods await foreignBox.methods
.withdrawFromDepositOnOtherNetworkGasPrice( .withdrawFromDepositOnOtherNetworkGasPrice(
user.address, user.address,
foreignBridgeAddress, amb.foreign,
homeBridgeAddress, amb.home,
'1000000000' '1000000000'
) )
.send({ .send({
@ -312,7 +286,7 @@ describe('arbitrary message bridging', () => {
// check that value changed and balance decreased // check that value changed and balance decreased
await promiseRetry(async retry => { await promiseRetry(async retry => {
const userBalance = toBN(await homeWeb3.eth.getBalance(user.address)) 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)) { if (!boxBalance.isZero() || userBalance.lte(initialUserBalance)) {
retry() retry()
} }
@ -347,12 +321,7 @@ describe('arbitrary message bridging', () => {
) )
await foreignBox.methods await foreignBox.methods
.setValueOnOtherNetworkGasPrice( .setValueOnOtherNetworkGasPrice(newValue, amb.home, amb.foreignBox, '1000000000')
newValue,
homeBridgeAddress,
foreignBoxAddress,
'1000000000'
)
.send({ .send({
from: user.address, from: user.address,
gas: '1000000' gas: '1000000'

@ -8,14 +8,13 @@ const {
HOME_ERC_TO_ERC_ABI, HOME_ERC_TO_ERC_ABI,
FOREIGN_ERC_TO_ERC_ABI, FOREIGN_ERC_TO_ERC_ABI,
HOME_ERC_TO_NATIVE_ABI, HOME_ERC_TO_NATIVE_ABI,
FOREIGN_ERC_TO_NATIVE_ABI FOREIGN_ERC_TO_NATIVE_ABI,
HOME_AMB_ABI,
FOREIGN_AMB_ABI
} = require('../../commons') } = require('../../commons')
const { web3Home, web3Foreign } = require('../src/services/web3') const { web3Home, web3Foreign } = require('../src/services/web3')
const { privateKeyToAddress } = require('../src/utils/utils') 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 const { VALIDATOR_ADDRESS, VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env
let homeAbi let homeAbi
@ -39,8 +38,8 @@ switch (process.env.BRIDGE_MODE) {
id = 'erc-native' id = 'erc-native'
break break
case 'ARBITRARY_MESSAGE': case 'ARBITRARY_MESSAGE':
homeAbi = homeAMBAbi homeAbi = HOME_AMB_ABI
foreignAbi = foreignAMBAbi foreignAbi = FOREIGN_AMB_ABI
id = 'amb' id = 'amb'
break break
default: default: