Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve example #53

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/contracts/Lock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ contract Lock {

event Withdrawal(uint amount, uint when);

constructor(uint _unlockTime) payable {
constructor(address _owner, uint _unlockTime) payable {
require(
block.timestamp < _unlockTime,
"Unlock time should be in the future"
);

unlockTime = _unlockTime;
owner = payable(msg.sender);
owner = payable(_owner);
}

function withdraw() public {
Expand Down
1 change: 1 addition & 0 deletions example/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {HardhatUserConfig, vars} from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@chainsafe/hardhat-ts-artifact-plugin";
import "@nomicfoundation/hardhat-web3-v4";

import "@chainsafe/hardhat-plugin-multichain-deploy";
import {Environment} from "@buildwithsygma/sygma-sdk-core";
Expand Down
4 changes: 3 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@nomicfoundation/hardhat-network-helpers": "^1.0.10",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.4",
"@nomicfoundation/hardhat-web3-v4": "^1.0.0",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.2.0",
Expand All @@ -34,6 +35,7 @@
"solidity-coverage": "^0.8.7",
"ts-node": ">=8.0.0",
"typechain": "^8.3.2",
"typescript": ">=4.5.0"
"typescript": ">=4.5.0",
"web3": "^4.5.0"
}
}
9 changes: 5 additions & 4 deletions example/scripts/deployMultichain.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { multichain } from "hardhat";
import { multichain, web3 } from "hardhat";
import { NetworkArguments } from "@chainsafe/hardhat-plugin-multichain-deploy";

async function main(): Promise<void> {
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
const unlockTime = BigInt(currentTimestampInSeconds + 60);
const [deployer] = await web3.eth.getAccounts();

const networkArguments: NetworkArguments = {
sepolia: {
args: [unlockTime],
args: [deployer, unlockTime],
initData: {
initMethodName: "setName",
initMethodArgs: ["sepolia"],
},
},
mumbai: {
args: [unlockTime],
args: [deployer, unlockTime],
initData: {
initMethodName: "setName",
initMethodArgs: ["mumbai"],
},
},
holesky: {
args: [unlockTime],
args: [deployer, unlockTime],
initData: {
initMethodName: "setName",
initMethodArgs: ["holesky"],
Expand Down
9 changes: 5 additions & 4 deletions example/scripts/deployMultichainBytecode.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { multichain } from "hardhat";
import { multichain, web3 } from "hardhat";
import { NetworkArguments } from "@chainsafe/hardhat-plugin-multichain-deploy";
import artifact from "../artifacts/contracts/Lock.sol/Lock";

async function main(): Promise<void> {
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
const unlockTime = BigInt(currentTimestampInSeconds + 60);
const [deployer] = await web3.eth.getAccounts();

const networkArguments: NetworkArguments = {
sepolia: {
args: [unlockTime],
args: [deployer, unlockTime],
initData: {
initMethodName: "setName",
initMethodArgs: ["sepolia"],
},
},
mumbai: {
args: [unlockTime],
args: [deployer, unlockTime],
initData: {
initMethodName: "setName",
initMethodArgs: ["mumbai"],
},
},
holesky: {
args: [unlockTime],
args: [deployer, unlockTime],
initData: {
initMethodName: "setName",
initMethodArgs: ["holesky"],
Expand Down
37 changes: 24 additions & 13 deletions example/scripts/localhost.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
import { multichain } from "hardhat";
import { multichain, web3 } from "hardhat";
import { NetworkArguments } from "@chainsafe/hardhat-plugin-multichain-deploy";

async function main(): Promise<void> {
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
const unlockTime = BigInt(currentTimestampInSeconds + 60);
const [deployer] = await web3.eth.getAccounts();

const { adapterAddress } = await multichain.initLocalEnvironment();

const networkArguments = ["sepolia", "mumbai", "holesky"].reduce(
(args, networkName) => {
args[networkName] = {
args: [unlockTime],
initData: {
initMethodName: "setName",
initMethodArgs: [networkName],
},
};
return args;
const networkArguments: NetworkArguments = {
sepolia: {
args: [deployer, unlockTime],
initData: {
initMethodName: "setName",
initMethodArgs: ["sepolia"],
},
},
{} as NetworkArguments
);
mumbai: {
args: [deployer, unlockTime],
initData: {
initMethodName: "setName",
initMethodArgs: ["mumbai"],
},
},
holesky: {
args: [deployer, unlockTime],
initData: {
initMethodName: "setName",
initMethodArgs: ["holesky"],
},
},
};

await multichain.deployMultichain("Lock", networkArguments, {
adapterAddress,
Expand Down
4 changes: 3 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7707,6 +7707,7 @@ __metadata:
"@nomicfoundation/hardhat-network-helpers": ^1.0.10
"@nomicfoundation/hardhat-toolbox": ^4.0.0
"@nomicfoundation/hardhat-verify": ^2.0.4
"@nomicfoundation/hardhat-web3-v4": ^1.0.0
"@typechain/ethers-v6": ^0.5.1
"@typechain/hardhat": ^9.1.0
"@types/chai": ^4.2.0
Expand All @@ -7722,6 +7723,7 @@ __metadata:
ts-node: ">=8.0.0"
typechain: ^8.3.2
typescript: ">=4.5.0"
web3: ^4.5.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -10374,7 +10376,7 @@ __metadata:
languageName: node
linkType: hard

"web3@npm:4, web3@npm:^4.3.0":
"web3@npm:4, web3@npm:^4.3.0, web3@npm:^4.5.0":
version: 4.5.0
resolution: "web3@npm:4.5.0"
dependencies:
Expand Down
Loading