Skip to content

Commit

Permalink
Move bridge data setting functions to setup-bridging-contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Aug 10, 2024
1 parent 05e9cbe commit edd1cee
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 41 deletions.
2 changes: 2 additions & 0 deletions helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -140,4 +141,5 @@ module.exports = {
MAINNET_CHAINID,
FORKED_MAINNET_CHAINID,
CREATEX_ADDRESS,
NETWORK_ADDRESS,
};
67 changes: 65 additions & 2 deletions scripts/setup-bridging-contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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)}`;
Expand Down Expand Up @@ -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 };
42 changes: 3 additions & 39 deletions test/cross-chain/cross-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 } =
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit edd1cee

Please sign in to comment.