diff --git a/helpers/constants.js b/helpers/constants.js index 6f8789fb73..41a24005ad 100644 --- a/helpers/constants.js +++ b/helpers/constants.js @@ -82,6 +82,7 @@ const MAINNET_CHAINID = 1; const FORKED_MAINNET_CHAINID = 2656691; const CREATEX_ADDRESS = "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed"; +const NETWORK_ADDRESS = "0x777760996135F0791E2e1a74aFAa060711197777"; module.exports = { UINT256_MAX, @@ -140,4 +141,5 @@ module.exports = { MAINNET_CHAINID, FORKED_MAINNET_CHAINID, CREATEX_ADDRESS, + NETWORK_ADDRESS, }; diff --git a/scripts/setup-bridging-contracts.js b/scripts/setup-bridging-contracts.js index f9a634d02d..1c06580cfc 100644 --- a/scripts/setup-bridging-contracts.js +++ b/scripts/setup-bridging-contracts.js @@ -10,7 +10,7 @@ const fs = require("fs"); const ethers = require("ethers"); const { spawn } = require("child_process"); const { TruffleLoader } = require("../packages/package-utils"); -const { WAD } = require("../helpers/constants"); +const { WAD, NETWORK_ADDRESS } = require("../helpers/constants"); const loader = new TruffleLoader({ contractRoot: path.resolve(__dirname, "..", `artifacts${process.env.SOLIDITY_COVERAGE ? "-coverage" : ""}`, "contracts"), @@ -199,9 +199,72 @@ async function setupBridging(homeRpcUrl, foreignRpcUrl) { console.log(`Zodiac Bridge module address: ${zodiacBridge.address}`); console.log(`ERC721 address: ${erc721.address}`); console.log(`Token address: ${token.address}`); + + await setForeignBridgeData(homeColonyBridge.address, foreignColonyBridge.address, ethersHomeSigner, ethersForeignSigner); + await setHomeBridgeData(homeColonyBridge.address, foreignColonyBridge.address, ethersHomeSigner, ethersForeignSigner); + return { gnosisSafe, resetRelayer, bridgeMonitor: guardianSpy, zodiacBridge, homeBridge, foreignBridge, homeColonyBridge, foreignColonyBridge }; } +async function setForeignBridgeData(homeColonyBridgeAddress, foreignColonyBridgeAddress, ethersHomeSigner, ethersForeignSigner) { + const contractDir = path.resolve(__dirname, "..", "artifacts", "contracts", "bridging"); + const WormholeBridgeForColony = await loader.load({ contractDir, contractName: "WormholeBridgeForColony" }); + const ProxyColonyNetwork = await loader.load({ contractDir, contractName: "ProxyColonyNetwork" }); + + const bridge = new ethers.Contract(foreignColonyBridgeAddress, WormholeBridgeForColony.abi, ethersForeignSigner); + + const homeChainId = (await ethersHomeSigner.provider.getNetwork()).chainId; + const foreignChainId = (await ethersForeignSigner.provider.getNetwork()).chainId; + + let tx = await bridge.setColonyBridgeAddress(foreignChainId, foreignColonyBridgeAddress); + await tx.wait(); + tx = await bridge.setColonyBridgeAddress(homeChainId, homeColonyBridgeAddress); + await tx.wait(); + + tx = await bridge.setColonyNetworkAddress(NETWORK_ADDRESS); + await tx.wait(); + + // TODO: Figure out a better way of setting / controlling this? + console.log("setting foreign colony bridge address", foreignColonyBridgeAddress); + const foreignColonyNetwork = new ethers.Contract(NETWORK_ADDRESS, ProxyColonyNetwork.abi, ethersForeignSigner); + tx = await foreignColonyNetwork.setColonyBridgeAddress(foreignColonyBridgeAddress); + await tx.wait(); + tx = await foreignColonyNetwork.setHomeChainId(homeChainId); + await tx.wait(); + console.log("done"); +} + +async function setHomeBridgeData(homeColonyBridgeAddress, foreignColonyBridgeAddress, ethersHomeSigner, ethersForeignSigner) { + let contractDir = path.resolve(__dirname, "..", "artifacts", "contracts", "bridging"); + const WormholeBridgeForColony = await loader.load({ contractDir, contractName: "WormholeBridgeForColony" }); + + contractDir = path.resolve(__dirname, "..", "artifacts", "contracts", "colonyNetwork"); + const IColonyNetwork = await loader.load({ contractDir, contractName: "IColonyNetwork" }); + + const bridge = new ethers.Contract(homeColonyBridgeAddress, WormholeBridgeForColony.abi, ethersHomeSigner); + const homeChainId = (await ethersHomeSigner.provider.getNetwork()).chainId; + const foreignChainId = (await ethersForeignSigner.provider.getNetwork()).chainId; + + let tx = await bridge.setColonyBridgeAddress(foreignChainId, foreignColonyBridgeAddress); + await tx.wait(); + tx = await bridge.setColonyBridgeAddress(homeChainId, homeColonyBridgeAddress); + await tx.wait(); + + tx = await bridge.setColonyNetworkAddress(NETWORK_ADDRESS); + await tx.wait(); + + const homeColonyNetwork = new ethers.Contract(NETWORK_ADDRESS, IColonyNetwork.abi, ethersHomeSigner); + const mcAddress = await homeColonyNetwork.getMetaColony(); + + contractDir = path.resolve(__dirname, "..", "artifacts", "contracts", "colony"); + const IMetaColony = await loader.load({ contractDir, contractName: "IMetaColony" }); + + const homeMetacolony = new ethers.Contract(mcAddress, IMetaColony.abi, ethersHomeSigner); + + tx = await homeMetacolony.setColonyBridgeAddress(homeColonyBridgeAddress); + await tx.wait(); +} + async function getSig(provider, account, dataHash) { const sig = await provider.send("eth_sign", [account, dataHash]); const r = `${sig.substring(2, 66)}`; @@ -241,4 +304,4 @@ if (process.argv.includes("start-bridging-environment")) { setupBridging("http://127.0.0.1:8545", "http://127.0.0.1:8546"); } -module.exports = { setupBridging, deployBridge }; +module.exports = { setupBridging, deployBridge, setHomeBridgeData, setForeignBridgeData }; diff --git a/test/cross-chain/cross-chain.js b/test/cross-chain/cross-chain.js index e0d85fdfad..ea45180aba 100644 --- a/test/cross-chain/cross-chain.js +++ b/test/cross-chain/cross-chain.js @@ -36,7 +36,7 @@ const ProxyColonyNetwork = artifacts.require("ProxyColonyNetwork"); const ProxyColony = artifacts.require("ProxyColony"); const MetaTxToken = artifacts.require("MetaTxToken"); // const { assert } = require("console"); -const { setupBridging, deployBridge } = require("../../scripts/setup-bridging-contracts"); +const { setupBridging, deployBridge, setForeignBridgeData, setHomeBridgeData } = require("../../scripts/setup-bridging-contracts"); const { MINING_CYCLE_DURATION, @@ -108,41 +108,6 @@ contract("Cross-chain", (accounts) => { const ethersForeignSigner2 = new ethers.providers.StaticJsonRpcProvider(foreignRpcUrl).getSigner(1); const ethersHomeSigner2 = new ethers.providers.StaticJsonRpcProvider(homeRpcUrl).getSigner(1); - async function setForeignBridgeData(foreignColonyBridgeForColony) { - const bridge = new ethers.Contract(foreignColonyBridge.address, WormholeBridgeForColony.abi, ethersForeignSigner); - - let tx = await bridge.setColonyBridgeAddress(foreignChainId, foreignColonyBridge.address); - await tx.wait(); - tx = await bridge.setColonyBridgeAddress(homeChainId, homeColonyBridge.address); - await tx.wait(); - - tx = await bridge.setColonyNetworkAddress(foreignColonyNetwork.address); - await tx.wait(); - - // TODO: Figure out a better way of setting / controlling this? - console.log("setting foreign colony bridge address", foreignColonyBridgeForColony); - tx = await foreignColonyNetwork.setColonyBridgeAddress(foreignColonyBridgeForColony); - await tx.wait(); - tx = await foreignColonyNetwork.setHomeChainId(homeChainId); - await tx.wait(); - console.log("done"); - } - - async function setHomeBridgeData(homeColonyBridgeAddressForColony) { - const bridge = new ethers.Contract(homeColonyBridge.address, WormholeBridgeForColony.abi, ethersHomeSigner); - - let tx = await bridge.setColonyBridgeAddress(foreignChainId, foreignColonyBridge.address); - await tx.wait(); - tx = await bridge.setColonyBridgeAddress(homeChainId, homeColonyBridge.address); - await tx.wait(); - - tx = await bridge.setColonyNetworkAddress(homeColonyNetwork.address); - await tx.wait(); - - tx = await homeMetacolony.setColonyBridgeAddress(homeColonyBridgeAddressForColony); - await tx.wait(); - } - before(async () => { await exec(`PORT=${FOREIGN_PORT} bash ./scripts/setup-foreign-chain.sh`); ({ bridgeMonitor, resetRelayer, gnosisSafe, zodiacBridge, homeBridge, foreignBridge, foreignColonyBridge, homeColonyBridge } = @@ -249,9 +214,8 @@ contract("Cross-chain", (accounts) => { console.log("got mc"); homeMetacolony = await new ethers.Contract(homeMCAddress, IMetaColony.abi, ethersHomeSigner); - await setForeignBridgeData(foreignColonyBridge.address); - await setHomeBridgeData(homeColonyBridge.address); - + await setForeignBridgeData(homeColonyBridge.address, foreignColonyBridge.address, ethersHomeSigner, ethersForeignSigner); + await setHomeBridgeData(homeColonyBridge.address, foreignColonyBridge.address, ethersHomeSigner, ethersForeignSigner); // Bridge over skills that have been created on the foreign chain // const latestSkillId = await foreignColonyNetwork.getSkillCount();