Skip to content

Commit f722857

Browse files
authored
feat(Foundry): zkSync support (#1097)
* feat(Foundry): zkSync support Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com> * Added forge sksync script Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com> * Added forge zksync command Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com> * Added foundry zksync profile check in deployment utils Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com> * Removed redundant check Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com> * Fixed zksync profile Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com> * Added zkout to clean script Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com> * Added zksync rpc and readme Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com> --------- Signed-off-by: Faisal Usmani <faisal.of.usmani@gmail.com>
1 parent d04dfd3 commit f722857

File tree

6 files changed

+74
-5
lines changed

6 files changed

+74
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ artifacts-zk
2828

2929
# Foundry files
3030
out
31+
zkout
3132

3233
# Upgradeability files
3334
.openzeppelin

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ forge script script/001DeployHubPool.s.sol:DeployHubPool --rpc-url ethereum --br
7777

7878
```
7979

80+
#### Foundry (ZKSync)
81+
82+
To enable ZKSync support, the zksync fork of foundry must be installed (see [here](https://foundry-book.zksync.io/introduction/installation#using-foundryup-zksync) for instructions).
83+
84+
Also, the `FOUNDRY_PROFILE` environment variable must be set to `zksync`.
85+
86+
```shell
87+
export FOUNDRY_PROFILE=zksync
88+
89+
forge script script/016DeployZkSyncSpokePool.s.sol:DeployZkSyncSpokePool --rpc-url zksync --broadcast --verify -vvvv
90+
```
91+
92+
Alternatively, the `yarn forge-script-zksync` command can be used to deploy the contract.
93+
94+
```shell
95+
yarn forge-script-zksync script/016DeployZkSyncSpokePool.s.sol:DeployZkSyncSpokePool --rpc-url zksync --broadcast --verify -vvvv
96+
```
97+
8098
### SVM
8199

82100
Before deploying for the first time make sure all program IDs in `lib.rs` and `Anchor.toml` are the same as listed when running `anchor keys list`. If not, update them to match the deployment keypairs under `target/deploy/` and commit the changes.

foundry.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,31 @@ fs_permissions = [{ access = "read", path = "./"}]
3535
solc = "0.8.23"
3636
evm_version = "prague"
3737

38+
[profile.zksync.zksync]
39+
compile = true
40+
fallback_oz = true
41+
mode = '3'
42+
zksolc = "1.5.7"
43+
3844
[rpc_endpoints]
45+
arbitrum = "${NODE_URL_42161}"
46+
base = "${NODE_URL_8453}"
47+
bsc = "${NODE_URL_56}"
3948
ethereum = "${NODE_URL_1}"
49+
ink = "${NODE_URL_57073}"
50+
lens = "${NODE_URL_262}"
51+
linea = "${NODE_URL_59144}"
52+
lisk = "${NODE_URL_1135}"
53+
mode = "${NODE_URL_34443}"
54+
optimism = "${NODE_URL_10}"
55+
polygon = "${NODE_URL_137}"
56+
redstone = "${NODE_URL_690}"
57+
scroll = "${NODE_URL_534352}"
58+
soneium = "${NODE_URL_1868}"
59+
unichain = "${NODE_URL_130}"
60+
world-chain = "${NODE_URL_480}"
61+
zksync = "${NODE_URL_324}"
62+
4063

4164
[etherscan]
4265
ethereum = { key = "${ETHERSCAN_API_KEY}" }

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
"main": "dist/index.js",
2020
"scripts": {
2121
"compile-zksync": "COMPILE_ZK=true yarn hardhat compile",
22+
"forge-script-zksync": " FOUNDRY_PROFILE=zksync forge script --zksync --suppress-errors sendtransfer",
2223
"lint": "yarn lint-solidity && yarn lint-js && yarn lint-rust",
2324
"lint-solidity": "yarn solhint ./contracts/**/*.sol",
2425
"lint-js": "yarn prettier --list-different **/*.js **/*.ts",
2526
"lint-rust": "cargo +nightly fmt --all -- --check && cargo clippy",
2627
"lint-fix": "yarn prettier --write **/*.js **/*.ts ./programs/**/*.rs ./contracts**/*.sol && cargo +nightly fmt --all && cargo clippy",
27-
"clean-fast": "for dir in node_modules cache cache-zk artifacts artifacts-zk dist typechain out; do mv \"${dir}\" \"_${dir}\"; rm -rf \"_${dir}\" &; done",
28-
"clean": "rm -rf node_modules cache cache-zk artifacts artifacts-zk dist typechain out",
28+
"clean-fast": "for dir in node_modules cache cache-zk artifacts artifacts-zk dist typechain out zkout; do mv \"${dir}\" \"_${dir}\"; rm -rf \"_${dir}\" &; done",
29+
"clean": "rm -rf node_modules cache cache-zk artifacts artifacts-zk dist typechain out zkout",
2930
"generate-svm-artifacts": "bash ./scripts/svm/buildHelpers/buildIdl.sh && sh ./scripts/svm/buildHelpers/generateSvmAssets.sh && yarn generate-svm-clients",
3031
"generate-svm-clients": "yarn ts-node ./scripts/svm/buildHelpers/generateSvmClients.ts && yarn ts-node ./scripts/svm/buildHelpers/renameClientsImports.ts",
3132
"build-evm": "hardhat compile",

script/059DeployLensSpokePool.s.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import { DeploymentUtils } from "./utils/DeploymentUtils.sol";
1111

1212
// How to run:
1313
// 1. `source .env` where `.env` has MNEMONIC="x x x ... x"
14-
// 2. forge script script/059DeployLensSpokePool.s.sol:DeployLensSpokePool --rpc-url $NODE_URL_1 -vvvv
14+
// 2. yarn forge-script-zksync script/059DeployLensSpokePool.s.sol:DeployLensSpokePool --rpc-url lens -vvvv
1515
// 3. Verify the above works in simulation mode.
1616
// 4. Deploy with:
17-
// forge script script/059DeployLensSpokePool.s.sol:DeployLensSpokePool --rpc-url \
18-
// $NODE_URL_1 --broadcast --verify --verifier blockscout --verifier-url https://verify.lens.xyz/contract_verification
17+
// yarn forge-script-zksync script/059DeployLensSpokePool.s.sol:DeployLensSpokePool --rpc-url lens \
18+
// --broadcast --verify --verifier blockscout --verifier-url https://verify.lens.xyz/contract_verification
1919

2020
contract DeployLensSpokePool is Script, Test, DeploymentUtils {
2121
function run() external {

script/utils/DeploymentUtils.sol

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ contract DeploymentUtils is Script, Test, Constants, DeployedAddresses {
3030
bool isNewProxy;
3131
}
3232

33+
constructor() {
34+
checkZkSyncChain(block.chainid);
35+
}
36+
3337
/**
3438
* @notice Get deployment information for SpokePool deployment
3539
* @dev This function mimics getSpokePoolDeploymentInfo from utils.hre.ts
@@ -190,4 +194,26 @@ contract DeploymentUtils is Script, Test, Constants, DeployedAddresses {
190194
chainId == getChainId("LISK_SEPOLIA") ||
191195
chainId == getChainId("MODE_SEPOLIA");
192196
}
197+
198+
/**
199+
* @notice Check if a chain ID is a ZkSync chain
200+
* @dev This function will revert if the chain ID is a ZkSync chain but the FOUNDRY_PROFILE is not zksync
201+
* @param chainId Chain ID to check
202+
*/
203+
function checkZkSyncChain(uint256 chainId) internal view {
204+
bool isZkSyncChain = chainId == getChainId("ZK_SYNC") ||
205+
chainId == getChainId("ZK_SYNC_SEPOLIA") ||
206+
chainId == getChainId("LENS") ||
207+
chainId == getChainId("LENS_TESTNET");
208+
209+
string memory foundryProfile = vm.envOr("FOUNDRY_PROFILE", string("default"));
210+
211+
if (isZkSyncChain) {
212+
vm.assertEq(
213+
foundryProfile,
214+
string("zksync"),
215+
"Chain is a ZkSync chain but FOUNDRY_PROFILE is not zksync. Use yarn forge-script-zksync to deploy"
216+
);
217+
}
218+
}
193219
}

0 commit comments

Comments
 (0)