Skip to content

Commit

Permalink
Merge branch 'main' into kiriyaga-txfusion-deploy-run-node-wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
kiriyaga committed Sep 27, 2024
2 parents 7d6f67d + 8c27074 commit d34d3a6
Show file tree
Hide file tree
Showing 102 changed files with 4,134 additions and 786 deletions.
4 changes: 2 additions & 2 deletions .github/release-please/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"packages/hardhat-zksync-deploy": "1.5.0",
"packages/hardhat-zksync-solc": "1.2.4",
"packages/hardhat-zksync-upgradable": "1.5.2",
"packages/hardhat-zksync-upgradable": "1.6.0",
"packages/hardhat-zksync-vyper": "1.1.0",
"packages/hardhat-zksync-verify": "1.6.0",
"packages/hardhat-zksync": "1.1.0",
"packages/hardhat-zksync-node": "1.1.1",
"packages/hardhat-zksync-ethers": "1.1.0",
"packages/hardhat-zksync-ethers": "1.2.1",
"packages/hardhat-zksync-verify-vyper": "0.0.1-alpha.6"
}
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@ jobs:
pnpm hardhat run scripts/deploy-box-uups.ts
pnpm hardhat run scripts/upgrade-box-beacon.ts
pnpm hardhat run scripts/upgrade-box-uups.ts
pnpm hardhat run scripts/upgrade-box.ts
pnpm hardhat run scripts/deploy-box-beacon-factory.ts
pnpm hardhat run scripts/deploy-box-proxy-factory.ts
pnpm hardhat run scripts/deploy-box-uups-factory.ts
pnpm hardhat run scripts/upgrade-box-uups-factory.ts
pnpm hardhat run scripts/upgrade-box-beacon-factory.ts
pnpm hardhat run scripts/upgrade-box-factory.ts
- name: Test upgradable example
run: |
cd examples/upgradable-example-l1
pnpm hardhat compile
pnpm hardhat run scripts/deploy-box-beacon.ts
pnpm hardhat run scripts/deploy-box-proxy.ts
pnpm hardhat run scripts/deploy-box-uups.ts
pnpm hardhat run scripts/upgrade-box-beacon.ts
pnpm hardhat run scripts/upgrade-box-uups.ts
pnpm hardhat run scripts/upgrade-box.ts
- name: Test zksync-ethers example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function main() {
'Something went wrong during deployment of a Factory contract. Initialize functions is probably not called.',
);
}
console.info("Successfully deployed upgradable factor contract.")
console.info("Successfully deployed upgradable factory contract.")
}

main().catch((error) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"chalk": "^4.1.2",
"hardhat": "^2.22.5",
"ethers": "^6.12.2",
"zksync-ethers": "^6.8.0",
"zksync-ethers": "^6.11.2",
"@matterlabs/zksync-contracts": "^0.6.1",
"@openzeppelin/contracts": "^4.9.2",
"@openzeppelin/contracts-upgradeable": "^4.9.2"
Expand Down
2 changes: 1 addition & 1 deletion examples/deploy-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"chalk": "^4.1.2",
"hardhat": "^2.22.5",
"ethers": "^6.12.2",
"zksync-ethers": "^6.8.0"
"zksync-ethers": "^6.11.2"
},
"prettier": {
"tabWidth": 4,
Expand Down
2 changes: 1 addition & 1 deletion examples/download-with-compiler-origin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"chalk": "^4.1.2",
"hardhat": "^2.22.5",
"ethers": "^6.12.2",
"zksync-ethers": "^6.8.0"
"zksync-ethers": "^6.11.2"
},
"prettier": {
"tabWidth": 4,
Expand Down
2 changes: 1 addition & 1 deletion examples/node-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"chalk": "^4.1.2",
"hardhat": "^2.22.5",
"ethers": "^6.12.2",
"zksync-ethers": "^6.8.0",
"zksync-ethers": "^6.11.2",
"@matterlabs/zksync-contracts": "^0.6.1",
"@openzeppelin/contracts": "^4.9.2",
"@openzeppelin/contracts-upgradeable": "^4.9.2"
Expand Down
2 changes: 1 addition & 1 deletion examples/noninline-libraries-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"chalk": "^4.1.2",
"hardhat": "^2.22.5",
"ethers": "^6.12.2",
"zksync-ethers": "^6.8.0",
"zksync-ethers": "^6.11.2",
"@matterlabs/zksync-contracts": "^0.6.1",
"@openzeppelin/contracts": "^4.9.2",
"@openzeppelin/contracts-upgradeable": "^4.9.2"
Expand Down
7 changes: 7 additions & 0 deletions examples/upgradable-example-l1/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: [`${__dirname}/../../config/eslint/eslintrc.cjs`],
parserOptions: {
project: `${__dirname}/tsconfig.json`,
sourceType: "module",
},
};
67 changes: 67 additions & 0 deletions examples/upgradable-example-l1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# ZKsync Era upgradable example

This project demonstrates how to compile and deploy upgradable smart contracts in ZKsync Era using the Hardhat plugins.

## Prerequisites

- node.js 14.x or later.
- yarn.

## Configuration

Plugin configuration is located in [`hardhat.config.ts`](./hardhat.config.ts).
You should only change the ZKsync network configuration.

`hardhat.config.ts` example with ZKsync network configured with the name `zkTestnet` and `sepolia` used as the underlying layer 1 network:
```ts
import '@matterlabs/hardhat-zksync-solc';
import '@matterlabs/hardhat-zksync-deploy';
import '@matterlabs/hardhat-zksync-upgradable';

import { HardhatUserConfig } from 'hardhat/types';

const config: HardhatUserConfig = {
networks: {
sepolia: {
url: 'https://sepolia.infura.io/v3/<API_KEY>' // you can use either the URL of the Ethereum Web3 RPC, or the identifier of the network (e.g. `mainnet` or `rinkeby`)
},
zkTestnet: {
url: 'https://sepolia.era.zksync.dev', // you should use the URL of the ZKsync network RPC
ethNetwork: 'sepolia',
zksync: true
},
}
};

export default config;
```

If you don't specify ZKsync network (`--network`), `local-setup` with <http://localhost:8545> (Ethereum RPC URL) and <http://localhost:3050> (ZKsync RPC URL) will be used.

## Usage

Before using plugins, you need to build them first

```sh
# Run the following in the *root* of the repo.
yarn
yarn build
```

After that you should be able to run plugins:

```sh
# Run the following in `examples/upgradable-example` folder.
yarn
yarn hardhat compile
```

- `yarn hardhat compile`: compiles all the contracts in the `contracts` folder.

To run a specific end-to-end script in the `scripts` folder, use the following command

```
yarn hardhat run ./scripts/<SCRIPT_NAME>
```

- Example: `yarn hardhat run ./scripts/deploy-box-proxy.ts`
27 changes: 27 additions & 0 deletions examples/upgradable-example-l1/contracts/Box.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract Box is Initializable {
uint256 private value;
uint256 private secondValue;
uint256 private thirdValue;

function initialize(uint256 initValue) public initializer {
value = initValue;
}

// Reads the last stored value
function retrieve() public view returns (uint256) {
return value;
}

// Stores a new value in the contract
function store(uint256 newValue) public {
value = newValue;
emit ValueChanged(newValue);
}
// Emitted when the stored value changes
event ValueChanged(uint256 newValue);
}
33 changes: 33 additions & 0 deletions examples/upgradable-example-l1/contracts/BoxUups.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';

contract BoxUups is Initializable, UUPSUpgradeable, OwnableUpgradeable {
uint256 private value;
uint256 private secondValue;
uint256 private thirdValue;

function initialize(uint256 initValue) public initializer {
value = initValue;
__Ownable_init();
__UUPSUpgradeable_init();
}

// Reads the last stored value
function retrieve() public view returns (uint256) {
return value;
}

// Stores a new value in the contract
function store(uint256 newValue) public {
value = newValue;
emit ValueChanged(newValue);
}

function _authorizeUpgrade(address) internal override onlyOwner {}

// Emitted when the stored value changes
event ValueChanged(uint256 newValue);
}
54 changes: 54 additions & 0 deletions examples/upgradable-example-l1/contracts/BoxUupsV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';

contract BoxUupsV2 is Initializable, UUPSUpgradeable, OwnableUpgradeable {
uint256 private value;
uint256 private secondValue;
uint256 private thirdValue;

function initialize(uint256 initValue) public initializer {
value = initValue;
}

// Reads the last stored value and returns it with a prefix
function retrieve() public view returns (string memory) {
return string(abi.encodePacked('V2: ', uint2str(value)));
}

// Converts a uint to a string
function uint2str(uint _i) internal pure returns (string memory) {
if (_i == 0) {
return '0';
}
uint j = _i;
uint len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint k = len;
while (_i != 0) {
k = k - 1;
uint8 temp = (48 + uint8(_i - (_i / 10) * 10));
bytes1 b1 = bytes1(temp);
bstr[k] = b1;
_i /= 10;
}
return string(bstr);
}

// Stores a new value in the contract
function store(uint256 newValue) public {
value = newValue;
emit ValueChanged(newValue);
}

function _authorizeUpgrade(address) internal override onlyOwner {}

// Emitted when the stored value changes
event ValueChanged(uint256 newValue);
}
51 changes: 51 additions & 0 deletions examples/upgradable-example-l1/contracts/BoxV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract BoxV2 is Initializable{
uint256 private value;
uint256 private secondValue;
uint256 private thirdValue;

// Emitted when the stored value changes
event ValueChanged(uint256 newValue);

function initialize(uint256 initValue) public initializer {
value = initValue;
}

// Stores a new value in the contract
function store(uint256 newValue) public {
value = newValue;
emit ValueChanged(newValue);
}

// Reads the last stored value and returns it with a prefix
function retrieve() public view returns (string memory) {
return string(abi.encodePacked("V2: ", uint2str(value)));
}

// Converts a uint to a string
function uint2str(uint _i) internal pure returns (string memory) {
if (_i == 0) {
return "0";
}
uint j = _i;
uint len;
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint k = len;
while (_i != 0) {
k = k - 1;
uint8 temp = (48 + uint8(_i - (_i / 10) * 10));
bytes1 b1 = bytes1(temp);
bstr[k] = b1;
_i /= 10;
}
return string(bstr);
}
}
16 changes: 16 additions & 0 deletions examples/upgradable-example-l1/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
pragma abicoder v2;

contract Greeter {
string greeting;

function greet() public view returns (string memory) {
return greeting;
}

function setGreeting(string memory _greeting) public {
greeting = _greeting;
}
}
35 changes: 35 additions & 0 deletions examples/upgradable-example-l1/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import '@matterlabs/hardhat-zksync-upgradable';
import "@matterlabs/hardhat-zksync-ethers"

import { HardhatUserConfig } from 'hardhat/config';

const config: HardhatUserConfig = {
zksolc: {
version: 'latest',
compilerSource: 'binary',
settings: {
optimizer: {
enabled: true,
},
},
},
networks: {
hardhat: {
zksync: false,
},
eth: {
zksync: true,
url: 'http://0.0.0.0:8545',
},
zkSyncNetwork: {
zksync: true,
ethNetwork: 'eth',
url: 'http://0.0.0.0:3050',
},
},
solidity: {
version: '0.8.20',
},
};

export default config;
Loading

0 comments on commit d34d3a6

Please sign in to comment.