bridge: move evm state setup into a separate contract
Change-Id: Ibc790ba971be5144c0af65870d424c9c62b52039
This commit is contained in:
parent
a055af1416
commit
45d22ce84f
|
@ -10,27 +10,6 @@ import "./Bridge.sol";
|
||||||
|
|
||||||
|
|
||||||
contract BridgeImplementation is Bridge {
|
contract BridgeImplementation is Bridge {
|
||||||
|
|
||||||
function initialize(
|
|
||||||
uint16 chainId,
|
|
||||||
address wormhole,
|
|
||||||
uint16 governanceChainId,
|
|
||||||
bytes32 governanceContract,
|
|
||||||
address tokenImplementation,
|
|
||||||
address WETH
|
|
||||||
) initializer public {
|
|
||||||
setChainId(chainId);
|
|
||||||
|
|
||||||
setWormhole(wormhole);
|
|
||||||
|
|
||||||
setGovernanceChainId(governanceChainId);
|
|
||||||
setGovernanceContract(governanceContract);
|
|
||||||
|
|
||||||
setTokenImplementation(tokenImplementation);
|
|
||||||
|
|
||||||
setWETH(WETH);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Beacon getter for the token contracts
|
// Beacon getter for the token contracts
|
||||||
function implementation() public view returns (address) {
|
function implementation() public view returns (address) {
|
||||||
return tokenImplementation();
|
return tokenImplementation();
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
// contracts/BridgeSetup.sol
|
||||||
|
// SPDX-License-Identifier: Apache 2
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import "./BridgeGovernance.sol";
|
||||||
|
|
||||||
|
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol";
|
||||||
|
|
||||||
|
contract BridgeSetup is BridgeSetters, ERC1967Upgrade {
|
||||||
|
function setup(
|
||||||
|
address implementation,
|
||||||
|
uint16 chainId,
|
||||||
|
address wormhole,
|
||||||
|
uint16 governanceChainId,
|
||||||
|
bytes32 governanceContract,
|
||||||
|
address tokenImplementation,
|
||||||
|
address WETH
|
||||||
|
) public {
|
||||||
|
setChainId(chainId);
|
||||||
|
|
||||||
|
setWormhole(wormhole);
|
||||||
|
|
||||||
|
setGovernanceChainId(governanceChainId);
|
||||||
|
setGovernanceContract(governanceContract);
|
||||||
|
|
||||||
|
setTokenImplementation(tokenImplementation);
|
||||||
|
|
||||||
|
setWETH(WETH);
|
||||||
|
|
||||||
|
_upgradeTo(implementation);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ require('dotenv').config({ path: "../.env" });
|
||||||
|
|
||||||
const TokenBridge = artifacts.require("TokenBridge");
|
const TokenBridge = artifacts.require("TokenBridge");
|
||||||
const BridgeImplementation = artifacts.require("BridgeImplementation");
|
const BridgeImplementation = artifacts.require("BridgeImplementation");
|
||||||
|
const BridgeSetup = artifacts.require("BridgeSetup");
|
||||||
const TokenImplementation = artifacts.require("TokenImplementation");
|
const TokenImplementation = artifacts.require("TokenImplementation");
|
||||||
const Wormhole = artifacts.require("Wormhole");
|
const Wormhole = artifacts.require("Wormhole");
|
||||||
|
|
||||||
|
@ -14,12 +15,16 @@ module.exports = async function (deployer) {
|
||||||
// deploy token implementation
|
// deploy token implementation
|
||||||
await deployer.deploy(TokenImplementation);
|
await deployer.deploy(TokenImplementation);
|
||||||
|
|
||||||
|
// deploy setup
|
||||||
|
await deployer.deploy(BridgeSetup);
|
||||||
|
|
||||||
// deploy implementation
|
// deploy implementation
|
||||||
await deployer.deploy(BridgeImplementation);
|
await deployer.deploy(BridgeImplementation);
|
||||||
|
|
||||||
// encode initialisation data
|
// encode initialisation data
|
||||||
const impl = new web3.eth.Contract(BridgeImplementation.abi, BridgeImplementation.address);
|
const setup = new web3.eth.Contract(BridgeSetup.abi, BridgeSetup.address);
|
||||||
const initData = impl.methods.initialize(
|
const initData = setup.methods.setup(
|
||||||
|
BridgeImplementation.address,
|
||||||
chainId,
|
chainId,
|
||||||
(await Wormhole.deployed()).address,
|
(await Wormhole.deployed()).address,
|
||||||
governanceChainId,
|
governanceChainId,
|
||||||
|
@ -29,5 +34,5 @@ module.exports = async function (deployer) {
|
||||||
).encodeABI();
|
).encodeABI();
|
||||||
|
|
||||||
// deploy proxy
|
// deploy proxy
|
||||||
await deployer.deploy(TokenBridge, BridgeImplementation.address, initData);
|
await deployer.deploy(TokenBridge, BridgeSetup.address, initData);
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,27 +53,6 @@ contract("Bridge", function () {
|
||||||
assert.equal(governanceContract, testGovernanceContract);
|
assert.equal(governanceContract, testGovernanceContract);
|
||||||
})
|
})
|
||||||
|
|
||||||
it("initialize should be non-reentrant", async function(){
|
|
||||||
const initialized = new web3.eth.Contract(BridgeImplementationFullABI, TokenBridge.address);
|
|
||||||
|
|
||||||
try{
|
|
||||||
await initialized.methods.initialize(
|
|
||||||
1,
|
|
||||||
Wormhole.address,
|
|
||||||
1,
|
|
||||||
testGovernanceContract,
|
|
||||||
TokenImplementation.address,
|
|
||||||
WETH
|
|
||||||
).estimateGas();
|
|
||||||
} catch (error) {
|
|
||||||
assert.equal(error.message, "Returned error: VM Exception while processing transaction: revert already initialized")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.fail("did not fail")
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
it("should register a foreign bridge implementation correctly", async function() {
|
it("should register a foreign bridge implementation correctly", async function() {
|
||||||
const initialized = new web3.eth.Contract(BridgeImplementationFullABI, TokenBridge.address);
|
const initialized = new web3.eth.Contract(BridgeImplementationFullABI, TokenBridge.address);
|
||||||
const accounts = await web3.eth.getAccounts();
|
const accounts = await web3.eth.getAccounts();
|
||||||
|
|
Loading…
Reference in New Issue