Skip to content

Commit

Permalink
Proxy contracts deployment (#1663)
Browse files Browse the repository at this point in the history
* Minimal proxy deployment.

* added a proxy for contract deployment.

* Dumping progress.

* Dump progress.

* Working version of contract deployments through proxies.

* Fix for hardhat tests.

* Fix for sim tests.

* Fixed linter issues.

* waiting for receipt for initialization.

* Use initializers.

* Generated ABI bindings.

---------

Co-authored-by: StefanIliev545 <[email protected]>
  • Loading branch information
StefanIliev545 and StefanIliev545 authored Nov 27, 2023
1 parent f6c7c1b commit 1d08a78
Show file tree
Hide file tree
Showing 22 changed files with 268 additions and 52 deletions.
5 changes: 3 additions & 2 deletions contracts/config/networks.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"localGeth": {
"url": "http://127.0.0.1:37000",
"url": "http://127.0.0.1:8025",
"deploy": [
"deployment_scripts/core/layer1/",
"deployment_scripts/testnet/layer1/",
Expand All @@ -14,11 +14,12 @@
"localObscuro": {
"chainId": 443,
"url": "http://127.0.0.1:3000/v1/",
"obscuroEncRpcUrl": "ws://127.0.0.1:37901",
"obscuroEncRpcUrl": "ws://127.0.0.1:13011",
"companionNetworks" : {
"layer1" : "localGeth"
},
"deploy": [
"deployment_scripts/core/",
"deployment_scripts/funding/layer1",
"deployment_scripts/messenger/layer1",
"deployment_scripts/messenger/layer2",
Expand Down
20 changes: 18 additions & 2 deletions contracts/deployment_scripts/bridge/001_deploy_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// We deploy the layer 1 part of the bridge.
const layer1BridgeDeployment = await hre.companionNetworks.layer1.deployments.deploy('ObscuroBridge', {
from: accountsL1.deployer,
args: [ messengerL1.address ],
log: true,
proxy: {
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
init: {
methodName: "initialize",
args: [ messengerL1.address ]
}
}
}
});

// get management contract and write the L1 bridge address to it
Expand All @@ -44,8 +52,16 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// and be subordinate of the L1 ObscuroBridge
const layer2BridgeDeployment = await deployments.deploy('EthereumBridge', {
from: accountsL2.deployer,
args: [ messengerL2.address, layer1BridgeDeployment.address ],
log: true,
proxy: {
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
init: {
methodName: "initialize",
args: [ messengerL2.address, layer1BridgeDeployment.address ]
}
}
}
});

await hre.companionNetworks.layer1.deployments.execute("ObscuroBridge", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,23 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
contract: contractArtifact,
args: [],
log: true,
proxy: {
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
init: {
methodName: "initialize",
args: []
}
}
}
});

const busAddress = await deployments.read('ManagementContract', 'messageBus');
const busAddressImpl = await deployments.read('ManagementContract_Implementation', 'messageBus');
console.log(`Implementation_MessageBus = ${busAddressImpl}`);


console.log(`ManagementContractAddress= ${mgmtContractDeployment.address}`);
// This is required in CI/CD - look at testnet-deploy-contracts.sh for more information.
// depends on grep -e MessageBusAddress and a positional cut of the address
console.log(`MessageBusAddress= ${busAddress}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
value: prefundAmount
});


console.log(`Sending ${prefundAmount} to ${deployer}`);
console.log(`Sending ${prefundAmount} to ${deployer} through MessageBus ${messageBusAddress}`);

const receipt = await layer1.deployments.rawTx({
from: l1Accs.deployer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployer} = await hre.getNamedAccounts();
const l1Accs = await layer1.getNamedAccounts();

const messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!!
const prefundAmountStr = process.env.PREFUND_FAUCET_AMOUNT!!
const messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!!// || "0xFD03804faCA2538F4633B3EBdfEfc38adafa259B"
const prefundAmountStr = process.env.PREFUND_FAUCET_AMOUNT!!// || "1"

if (prefundAmountStr == "0") {
return;
Expand All @@ -22,7 +22,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
});


console.log(`Sending ${prefundAmount} to ${deployer}`);
console.log(`Sending ${prefundAmount} to ${deployer} through ${messageBusAddress}`);

const receipt = await layer1.deployments.rawTx({
from: l1Accs.deployer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// Use the contract addresses from the management contract deployment.
const mgmtContractAddress = process.env.MGMT_CONTRACT_ADDRESS!!
const messageBusAddress : string = process.env.MESSAGE_BUS_ADDRESS!!
console.log(`Management Contract address ${mgmtContractAddress}`);
console.log(`Message Bus address ${messageBusAddress}`);

// Setup the cross chain messenger and point it to the message bus from the management contract to be used for validation
const crossChainDeployment = await deployments.deploy('CrossChainMessenger', {
from: deployer,
args: [ messageBusAddress ],
log: true,
proxy: {
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
init: {
methodName: "initialize",
args: [ messageBusAddress ]
}
}
}
});

// get management contract and write the cross chain messenger address to it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// Get the prefunded L2 deployer account to use for deploying.
const {deployer} = await getNamedAccounts();

console.log(`Deployer acc ${deployer}`);
console.log(`Script: 001_deploy_cross_chain_messenger.ts - address used: ${deployer}`);

// TODO: Remove hardcoded L2 message bus address when properly exposed.
const busAddress = hre.ethers.utils.getAddress("0x526c84529b2b8c11f57d93d3f5537aca3aecef9b")

console.log(`Beginning deploy of cross chain messenger`);

const messageBusAddress = hre.ethers.utils.getAddress("0x526c84529b2b8c11f57d93d3f5537aca3aecef9b");
// Deploy the L2 Cross chain messenger and use the L2 bus for validation
await deployments.deploy('CrossChainMessenger', {
from: deployer,
args: [ busAddress ],
log: true,
proxy: {
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
init: {
methodName: "initialize",
args: [ messageBusAddress ]
}
}
}
});
console.log("Deployed!")
};

export default func;
func.tags = ['CrossChainMessenger', 'CrossChainMessenger_deploy'];
func.tags = ['CrossChainMessenger', 'CrossChainMessenger_deploy'];
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {


const gasConsumerBalance = await hre.ethers.getContractAt("GasConsumerBalance", gcb.address)
const gasEstimation = await gasConsumerBalance.estimateGas.get_balance({from: deployer});
const gasEstimation = await gasConsumerBalance.estimateGas.get_balance({
from: deployer,
gasPrice: 2,
});

await hre.deployments.execute("GasConsumerBalance", {
from: deployer,
gasLimit: gasEstimation.div(2),
gasLimit: gasEstimation,
log: true
}, "get_balance");
};
Expand Down
Loading

0 comments on commit 1d08a78

Please sign in to comment.