Skip to content

Commit

Permalink
[Hardhat] Use Ten Hardhat Plugin instead of baked in registration. (#…
Browse files Browse the repository at this point in the history
…1812)

* Separate gateway startup from hardhat tasks.

* Upgrade to plugin.

* Enabled gateway...

* Using gateway.

* Added missing file.

* Increased timeout.

* added generated contract bindings.

* Some logs.

* Revert "change mempool validation function (#1800)"

This reverts commit 3a74586.

* Revert "Revert "change mempool validation function (#1800)""

This reverts commit 380aa52.

* Some bits and bobs.

* Disabled caching.

* Added ten-hardhat-plugin.

* Fixes.

---------

Co-authored-by: StefanIliev545 <[email protected]>
  • Loading branch information
StefanIliev545 and StefanIliev545 authored Mar 7, 2024
1 parent b52a7a4 commit 9931529
Show file tree
Hide file tree
Showing 26 changed files with 125 additions and 249 deletions.
6 changes: 3 additions & 3 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:8025",
"url": "http://127.0.0.1:26000",
"deploy": [
"deployment_scripts/core/layer1/",
"deployment_scripts/testnet/layer1/",
Expand All @@ -13,8 +13,8 @@
},
"localObscuro": {
"chainId": 443,
"url": "http://127.0.0.1:3000/v1/",
"obscuroEncRpcUrl": "ws://127.0.0.1:13011",
"url": "http://127.0.0.1:11180/v1/",
"useGateway": true,
"companionNetworks" : {
"layer1" : "localGeth"
},
Expand Down
5 changes: 2 additions & 3 deletions contracts/deployment_scripts/bridge/001_deploy_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

// get management contract and write the L1 bridge address to it
const mgmtContract = (await hre.ethers.getContractFactory('ManagementContract')).attach(mgmtContractAddress)
const recordL1AddressTx = await mgmtContract.populateTransaction.SetImportantContractAddress("L1Bridge", layer1BridgeDeployment.address);

const recordL1AddressTx = await mgmtContract.getFunction("SetImportantContractAddress").populateTransaction("L1Bridge", layer1BridgeDeployment.address);
const receipt = await hre.companionNetworks.layer1.deployments.rawTx({
from: accountsL1.deployer,
to: mgmtContractAddress,
Expand Down Expand Up @@ -77,7 +76,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
}, "setRemoteBridge", layer2BridgeDeployment.address);

const recordL2AddressTx = await mgmtContract.populateTransaction.SetImportantContractAddress("L2Bridge", layer2BridgeDeployment.address);
const recordL2AddressTx = await mgmtContract.getFunction("SetImportantContractAddress").populateTransaction("L2Bridge", layer2BridgeDeployment.address);
const receipt2 = await hre.companionNetworks.layer1.deployments.rawTx({
from: accountsL1.deployer,
to: mgmtContractAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// 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}`);
console.log(`L1Start= ${mgmtContractDeployment.receipt.blockHash}`)
console.log(`L1Start= ${mgmtContractDeployment.receipt!!.blockHash}`)
};

export default func;
Expand Down
10 changes: 6 additions & 4 deletions contracts/deployment_scripts/funding/layer1/001_fund_accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const messageBusAddress = process.env.MESSAGE_BUS_ADDRESS!!

const messageBus = (await hre.ethers.getContractFactory('MessageBus')).attach(messageBusAddress)
const prefundAmount = hre.ethers.utils.parseEther("0.5");
const tx = await messageBus.populateTransaction.sendValueToL2(deployer, prefundAmount, {
value: prefundAmount
const prefundAmount = hre.ethers.parseEther("0.5");
console.log(`Prefund amount ${prefundAmount}; MB = ${messageBus}`);

const tx = await messageBus.getFunction("sendValueToL2").populateTransaction(deployer, prefundAmount, {
value: prefundAmount.toString()
});

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

const receipt = await layer1.deployments.rawTx({
from: l1Accs.deployer,
to: messageBusAddress,
value: prefundAmount,
value: prefundAmount.toString(),
data: tx.data,
log: true,
waitConfirmations: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}

const messageBus = (await hre.ethers.getContractFactory('MessageBus')).attach(messageBusAddress)
const prefundAmount = hre.ethers.utils.parseEther(prefundAmountStr);
const tx = await messageBus.populateTransaction.sendValueToL2("0xA58C60cc047592DE97BF1E8d2f225Fc5D959De77", prefundAmount, {
const prefundAmount = hre.ethers.parseEther(prefundAmountStr);
const tx = await messageBus.getFunction("sendValueToL2").populateTransaction("0xA58C60cc047592DE97BF1E8d2f225Fc5D959De77", prefundAmount, {
value: prefundAmount
});

Expand All @@ -27,7 +27,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const receipt = await layer1.deployments.rawTx({
from: l1Accs.deployer,
to: messageBusAddress,
value: prefundAmount,
value: prefundAmount.toString(),
data: tx.data,
log: true,
waitConfirmations: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

// get management contract and write the cross chain messenger address to it
const mgmtContract = (await hre.ethers.getContractFactory('ManagementContract')).attach(mgmtContractAddress)
const tx = await mgmtContract.populateTransaction.SetImportantContractAddress("L1CrossChainMessenger", crossChainDeployment.address);
const tx = await mgmtContract.getFunction("SetImportantContractAddress").populateTransaction("L1CrossChainMessenger", crossChainDeployment.address);
const receipt = await hre.companionNetworks.layer1.deployments.rawTx({
from: deployer,
to: mgmtContractAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`Script: 001_deploy_cross_chain_messenger.ts - address used: ${deployer}`);

// TODO: Remove hardcoded L2 message bus address when properly exposed.
const messageBusAddress = hre.ethers.utils.getAddress("0x526c84529b2b8c11f57d93d3f5537aca3aecef9b");
const messageBusAddress = hre.ethers.getAddress("0x526c84529b2b8c11f57d93d3f5537aca3aecef9b");
console.log(`Deploying l2 cross chain messenger.`)
// Deploy the L2 Cross chain messenger and use the L2 bus for validation
const crossChainDeployment = await deployments.deploy('CrossChainMessenger', {
from: deployer,
Expand All @@ -39,9 +40,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}
}
});
console.log(`Setting L2 Cross chain messenger`)
// get L1 management contract and write the cross chain messenger address to it
const mgmtContract = (await hre.ethers.getContractFactory('ManagementContract')).attach(mgmtContractAddress);
const tx = await mgmtContract.populateTransaction.SetImportantContractAddress("L2CrossChainMessenger", crossChainDeployment.address);
const tx = await mgmtContract.getFunction("SetImportantContractAddress").populateTransaction("L2CrossChainMessenger", crossChainDeployment.address);
const receipt = await companionNetworks.layer1.deployments.rawTx({
from: l1Accounts.deployer,
to: mgmtContractAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +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({
const gasEstimation = await gasConsumerBalance.getFunction('get_balance').estimateGas({
from: deployer,
gasPrice: 2,
});

await hre.deployments.execute("GasConsumerBalance", {
from: deployer,
gasLimit: gasEstimation,
gasLimit: gasEstimation.toString(),
log: true
}, "get_balance");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Receipt } from 'hardhat-deploy/dist/types';
*/


async function sleep(ms) {
async function sleep(ms: number) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
Expand Down Expand Up @@ -51,10 +51,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const eventSignature = "LogMessagePublished(address,uint64,uint32,uint32,bytes,uint8)";
// Get the hash id of the event signature
const topic = hre.ethers.utils.id(eventSignature)
const topic = hre.ethers.id(eventSignature)

// Get the interface for the event in order to convert it to cross chain message.
let eventIface = new hre.ethers.utils.Interface([ `event ${eventSignature}`]);
let eventIface = new hre.ethers.Interface([ `event ${eventSignature}`]);

// This function converts the logs from transaction receipts into cross chain messages
function getXChainMessages(result: Receipt) {
Expand All @@ -69,7 +69,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const decodedEvent = eventIface.parseLog({
topics: event!.topics!,
data: event!.data
});
})!!;

//Construct the cross chain message.
const xchainMessage = {
Expand All @@ -96,13 +96,13 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
await new Promise(async (resolve, fail)=> {
setTimeout(fail, 30_000)
const messageBusContract = (await hre.ethers.getContractAt('MessageBus', '0x526c84529b2b8c11f57d93d3f5537aca3aecef9b'));
const gasLimit = await messageBusContract.estimateGas.verifyMessageFinalized(messages[1], {
const gasLimit = await messageBusContract.getFunction('verifyMessageFinalized').estimateGas(messages[1], {
maxFeePerGas: 1000000001,
})
try {
while (await messageBusContract.callStatic.verifyMessageFinalized(messages[1], {
while (await messageBusContract.getFunction('verifyMessageFinalized').staticCall(messages[1], {
maxFeePerGas: 1000000001,
gasLimit: gasLimit.add(gasLimit.div(2)),
gasLimit: gasLimit + (gasLimit/BigInt(2)),
from: l2Accounts.deployer
}) != true) {
console.log(`Messages not stored on L2 yet, retrying...`);
Expand All @@ -126,10 +126,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}, "relayMessage", msg);
};

console.log(`Relaying message - ${JSON.stringify(messages[0])}`);
console.log(`Relaying message - 0`);
let results = [await relayMsg(messages[0])];

console.log(`Relaying message - ${JSON.stringify(messages[1])}`);
console.log(`Relaying message - 1`);
results = results.concat(await relayMsg(messages[1]))

results.forEach(res=>{
Expand Down
Loading

0 comments on commit 9931529

Please sign in to comment.