Skip to content

Commit 4668233

Browse files
authored
feat: add L1 token, L1 bridge and L2 bridge contracts (#93)
* feat: add L1 token, L1 bridge and L2 bridge contracts
1 parent 38fccc4 commit 4668233

74 files changed

Lines changed: 5684 additions & 1601 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cspell.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
"Tokendecimals",
5555
"zyfi",
5656
"addrsSlot",
57-
"NODLNS"
57+
"NODLNS",
58+
"solhint",
59+
"mixedcase"
5860
]
5961
}

.devcontainer/Dockerfile

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM mcr.microsoft.com/devcontainers/base:jammy
22

33
USER vscode
44

5-
ENV NODE_VERSION=20.18.1
5+
ENV NODE_VERSION=22.13.0
66
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash && \
77
export NVM_DIR="$HOME/.nvm" && \
88
[ -s "$NVM_DIR/nvm.sh" ] && \
@@ -17,12 +17,6 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | zsh -s -- -y &&
1717

1818
ENV PATH="${PATH}:/home/vscode/.cargo/bin:/home/vscode/.yarn/bin:/home/vscode/.foundry/bin:/home/vscode/.nvm/versions/node/v${NODE_VERSION}/bin:/home/vscode/.solc"
1919

20-
ENV SOLC_VERSION=v0.8.23+commit.f704f362
21-
RUN mkdir -p /home/vscode/.solc && \
22-
curl https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-${SOLC_VERSION} -o /home/vscode/.solc/solc-linux-amd64-${SOLC_VERSION} && \
23-
chmod +x /home/vscode/.solc/solc-linux-amd64-${SOLC_VERSION} && \
24-
ln -s /home/vscode/.solc/solc-linux-amd64-${SOLC_VERSION} /home/vscode/.solc/solc
25-
2620
RUN sudo apt update && \
2721
sudo apt install --yes \
2822
pkg-config build-essential cmake \
@@ -33,12 +27,12 @@ RUN sudo apt update && \
3327

3428
RUN yarn global add zksync-cli && yarn global add @graphprotocol/graph-cli
3529

36-
ARG KNOWN_GOOD_FORGE_COMMIT=33b81acf8688f8cc1fc839b7e4a07ec58b347cb4
30+
ARG KNOWN_GOOD_FORGE_COMMIT=574943e798a1351735e6535453141fdddf123808
3731
RUN git clone https://github.com/matter-labs/foundry-zksync.git /tmp/foundry-zksync && \
3832
cd /tmp/foundry-zksync && \
3933
git checkout ${KNOWN_GOOD_FORGE_COMMIT} && \
40-
cargo install --path ./crates/forge --profile local --force --locked && \
41-
cargo install --path ./crates/cast --profile local --force --locked && \
34+
cargo install --path ./crates/forge --force --locked && \
35+
cargo install --path ./crates/cast --force --locked && \
4236
rm -rf /tmp/foundry-zksync
4337

4438
ENTRYPOINT [ "zsh" ]

.github/workflows/checks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ jobs:
3232

3333
- name: Lint
3434
run: yarn lint
35-
35+
3636
- name: Run tests
37-
run: forge test --zksync
37+
run: forge test --zksync

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22.13

.solhint.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
}
1010
],
1111
"constructor-syntax": "error",
12-
"immutable-vars-naming": "off",
13-
"gas-custom-errors": "error"
12+
"immutable-vars-naming": "warn",
13+
"gas-custom-errors": "error",
14+
"use-natspec": "off",
15+
"import-path-check": "off",
16+
"gas-struct-packing": "warn",
17+
"gas-calldata-parameters": "warn",
18+
"gas-increment-by-one": "warn",
19+
"gas-small-strings": "warn",
20+
"gas-strict-inequalities": "warn",
21+
"gas-indexed-events": "warn"
1422
}
1523
}

.vscode/mcp.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"servers": {
3+
"OpenZeppelinSolidityContracts": {
4+
"type": "http",
5+
"url": "https://mcp.openzeppelin.com/contracts/solidity/mcp"
6+
}
7+
}
8+
}

.vscode/settings.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
"solidity.formatter": "forge",
55
"github.copilot.chat.scopeSelection": true,
66
"github.copilot.chat.localeOverride": "en",
7-
"github.copilot.chat.temporalContext.enabled": true,
87
"github.copilot.chat.generateTests.codeLens": true,
98
"github.copilot.chat.inlineChatCompletionTrigger.enabled": true,
109
"github.copilot.chat.inlineChatHint.enabled": true,
1110
"github.copilot.chat.search.semanticTextResults": true,
12-
"editor.defaultFormatter": null
11+
"editor.defaultFormatter": null,
12+
"github.copilot.chat.editor.temporalContext.enabled": true,
13+
"editor.formatOnSave": true,
14+
"[solidity]": {
15+
"editor.defaultFormatter": "JuanBlanco.solidity"
16+
}
1317
}

README.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
# Nodle's Eth L2 rollup powered by zkSync stack
2+
23
![Banner](https://github.com/NodleCode/rollup/assets/10683430/b50803ff-41d1-4faa-99eb-72c9eeaf3194)
34

45
# Development setup
6+
57
> [!NOTE]
68
> We recommend you run within the provided [devcontainer](https://code.visualstudio.com/remote/advancedcontainers/overview) to ensure you have all the necessary tooling installed such `zksync-cli`, and `forge`.
79
810
For subquery utilization refer to [Nodle-zksync-subquery](/subquery/README.md)
911

1012
## Repo organization
11-
- `./` contains foundry contracts for Nodle and Click on ZkSync:
13+
14+
- `./` contains Nodle's constellation of smart contracts, tools and services for L1 Ethereum and L2 ZkSync operations.
1215
- `./lib` contains libraries we depend on.
1316
- `./src` contains contract sources.
14-
- `./script` contains deployment scripts.
17+
- `./script` contains forge scripts.
18+
- `./hardhat-deploy` contains typescript deployment scripts compiled and run by hardhat.
1519
- `./test` contains unit tests.
16-
- `./subquery` contains a custom subquery for this project.
17-
- ...more to come
20+
- `./subquery` contains a custom subquery for this project.
21+
- `./utils` contains typescript utilities such as batch-register for clk names.
22+
- `./ops` contains shell scripts for operational tasks like deployment orchestration, maintenance, and chain interaction
1823

1924
## Conventions
25+
2026
- all files should be licensed under the BSD 3 Clear Clause license with the required file header `// SPDX-License-Identifier: BSD-3-Clause-Clear`
2127
- when writing scripts, ensure that:
2228
- input environment variables are prefixed with `N_` to differentiate them from `forge` environment variables
@@ -59,6 +65,7 @@ Please see scripts in `./scripts` and refer to the [forge documentation](https:/
5965
### Deploying Click contracts
6066

6167
Please define the following environment variables:
68+
6269
- `N_WHITELIST_ADMIN`: address of the whitelist admin on the paymaster whitelist contract (typically the onboard or sponsorship API address).
6370
- `N_WITHDRAWER`: address of the account allowed to withdraw ETH from the paymaster contract.
6471
- deployer address will be set as super admin.
@@ -83,12 +90,14 @@ If you wish to simulate on-chain transactions pass a RPC URL.
8390
### Deploying ContentSign Enterprise contracts
8491

8592
Please define the following environment variables:
93+
8694
- `N_NAME`: name of the NFT contract deployed.
8795
- `N_SYMBOL`: symbol of the NFT contract deployed.
8896

8997
Here is a full example for a Sepolia deployment: `N_NAME=ExampleContentSign N_SYMBOL=ECS forge script script/DeployContentSignEnterprise.s.sol --zksync --rpc-url https://sepolia.era.zksync.dev --zk-optimizer -i 1 --broadcast`.
9098

9199
Once deployed, the script will output the contract address, and the account you deployed with will be set as the administrator of this contract with the possibility to grant other users minting access. You may onboard a new user with `cast` via the following command template:
100+
92101
```shell
93102
export ETH_RPC_URL=https://sepolia.era.zksync.dev # use the appropriate RPC here
94103
export NFT=0x195e4E251c41e8Ae9E9E961366C73e2CFbfB115A # use your own contract address here
@@ -100,10 +109,12 @@ cast send -i $NFT "grantRole(bytes32,address)" $ROLE 0x68e3981280792A19cC03B5A77
100109
```
101110

102111
### Deploying NODL and NODLMigration contract
112+
103113
In the following example `N_VOTER1_ADDR` is the public address of the bridge oracle whose role is going to be a voter for funds coming from
104-
the parachain side. Similarly `N_VOTER2_ADDR` and `N_VOTER3_ADDR` are addresses of the other two voter oracles.
114+
the parachain side. Similarly `N_VOTER2_ADDR` and `N_VOTER3_ADDR` are addresses of the other two voter oracles.
105115
The closer oracle does not need special permissions and thus need not to be mentioned.
106116
NOTE: `i` flag in the command will make the tool prompt you for the private key of the deployer. So remember to have that handy but you don't need to define it in your environment.
117+
107118
```shell
108119
N_VOTER1_ADDR="0x18AB6B4310d89e9cc5521D33D5f24Fb6bc6a215E" \
109120
N_VOTER2_ADDR="0x571C969688991C6A35420C62d44666c47eB3F752" \
@@ -114,16 +125,19 @@ forge script script/DeployNodlMigration.sol --zksync --rpc-url https://sepolia.e
114125
Afterwards the user you onboarded should be able to mint NFTs as usual via the `safeMint(ownerAddress, metadataUri)` function.
115126

116127
### Deploying MigrationNFT contract
128+
117129
The `MigrationNFT` contract allows the minting of a reward SoulBound NFT when users bridge enough tokens through `NODLMigration`. Users can "level up" depending on the amount of tokens they bring in, with each levels being a sorted list of bridged amounts.
118130

119131
You will need to set the following environment variables:
132+
120133
- `N_MIGRATION`: address of the `NODLMigration` contract
121134
- `N_MAX_HOLDERS`: maximum number of participants
122135
- `N_LEVELS`: number of levels to set
123136
- `N_LEVELS_x` where `x` is an integer from `0` to `N_LEVELS - 1`: actual number of tokens for each level
124137
- `N_LEVELS_URI_x` where `x` is an integer from `0` to `N_LEVELS - 1`: actual metadata URL for the NFTs
125138

126139
You can then run the script `script/DeployMigrationNFT.s.sol` very similarly to the below:
140+
127141
```shell
128142
N_MIGRATION=0x1427d38B967435a3F8f476Cda0bc4F51fe66AF4D \
129143
N_MAX_HOLDERS=10000 \
@@ -140,15 +154,19 @@ forge script script/DeployMigrationNFT.s.sol --zksync --rpc-url https://sepolia.
140154
## Scripts
141155

142156
### Checking on bridging proposals
157+
143158
Given a tracker id (`proposal`) and the bridge address you may run the script available in `./script/CheckBridge.s.sol`. The script will output proposal details and outline expectations as to the proposal's execution timeline. Here is a simple example:
159+
144160
```shell
145161
N_PROPOSAL_ID=c43005c880cad7b699122b403607187a78251b9850d387521ffb123c473e3392 \
146162
N_BRIDGE=0x5de7fe085ee66Fb48447e75AA8fb0598a080AEe0 \
147163
forge script script/CheckBridge.s.sol --zksync --rpc-url https://mainnet.era.zksync.io
148164
```
149165

150166
### Whitelisting new users on ContentSign contracts
167+
151168
Given a user and contract address, you can whitelist new users on contracts derived from `EnterpriseContentSign` with the `ContentSignWhitelist` script. Note that this assumes your own key has been granted admin permissions on this same contract. Here is a simple example for a testnet contract:
169+
152170
```shell
153171
N_CONTENTSIGN=0x195e4E251c41e8Ae9E9E961366C73e2CFbfB115A \
154172
N_WHITELIST=0x732e40223f57d7a1dbf340f5c0cc5b363b60428b \
@@ -161,22 +179,25 @@ forge script script/ContentSignWhitelist.s.sol -i 1 --zksync --rpc-url https://s
161179
> The below steps are **not** for the faint of heart. Contract verification is technically not supported yet by the zkSync foundry fork, and the instructions below are likely to break (in which case feel free to update them via a PR).
162180
163181
Verification on Etherscan is best done via the Solidity Json Input method as it is the least error prone and most reliable. To do so, you will need a few elements:
182+
164183
1. Contract address, which you typically get from script outputs.
165184
2. `solc` and `zksolc` versions, which you can identify based on the pragma header of the solidity contracts, or by checking what binaries are on your system:
166-
```shell
167-
$ ls ~/.zksync/
168-
solc-macosx-arm64-0.8.23-1.0.0 zksolc-macosx-arm64-v1.4.1
169-
```
170-
In the sample case above, we are using `solc` `0.8.23` and `zksolc` `1.4.1`.
171-
3. The Solidity Json Input file, which you can get by following the below instructions
172-
1. Build the contracts and ask for the `build-info` via `forge build --zksync --zk-optimizer --build-info`
173-
2. Access the said `build-info` at path `./out/build-info`, you will find there a JSON file (if you have more than one, take the most recent one)
174-
3. Open the JSON file and select the value under the `input` key
175-
4. Due to some incompatibilities, normalize the JSON value by removing the keys `settings.metadata` and `settings.viaIR`
176-
4. The contract inputs, which you can regenerate if you know the input values you deployed the contract with. Or that you can fetch by viewing your deployment transaction on [explorer.zksync.io](https://explorer.zksync.io). To do, you will need to:
177-
1. Open your deployment transaction on [explorer.zksync.io](https://explorer.zksync.io) (make sure to select the testnet if you are using the zkSync Era testnet)
178-
2. Look for the input data variable named `_input`
179-
3. Copy paste its value and **strip the `0x prefix** as Etherscan will throw an error otherwise
185+
186+
```shell
187+
$ ls ~/.zksync/
188+
solc-macosx-arm64-0.8.23-1.0.0 zksolc-macosx-arm64-v1.4.1
189+
```
190+
191+
In the sample case above, we are using `solc` `0.8.23` and `zksolc` `1.4.1`. 3. The Solidity Json Input file, which you can get by following the below instructions
192+
193+
1. Build the contracts and ask for the `build-info` via `forge build --zksync --zk-optimizer --build-info`
194+
2. Access the said `build-info` at path `./out/build-info`, you will find there a JSON file (if you have more than one, take the most recent one)
195+
3. Open the JSON file and select the value under the `input` key
196+
4. Due to some incompatibilities, normalize the JSON value by removing the keys `settings.metadata` and `settings.viaIR`
197+
5. The contract inputs, which you can regenerate if you know the input values you deployed the contract with. Or that you can fetch by viewing your deployment transaction on [explorer.zksync.io](https://explorer.zksync.io). To do, you will need to:
198+
6. Open your deployment transaction on [explorer.zksync.io](https://explorer.zksync.io) (make sure to select the testnet if you are using the zkSync Era testnet)
199+
7. Look for the input data variable named `_input`
200+
8. Copy paste its value and **strip the `0x prefix** as Etherscan will throw an error otherwise
180201

181202
Use all these artifacts on the contract verification page on Etherscan for your given contract (open your contract on Etherscan, select `Contract` and the link starting with `Verify`). When prompted, enter the compiler versions, the license (we use BSD-3 Clause Clear). Then on the next page, enter your normalized JSON input file, and the contract constructor inputs.
182203

foundry.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
src = "src"
33
out = "out"
44
libs = ["lib"]
5-
solc = "0.8.23"
5+
solc = "0.8.26"
66

77
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
88

99
# necessary as some of the zksync contracts are big
10-
via_ir = true
10+
via_ir = true

0 commit comments

Comments
 (0)