Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zkcarter committed Nov 27, 2023
1 parent 05f9dae commit 699b7bf
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 288 deletions.
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ You can find the docs [here](docs/setup_environment.md)

## Work with `zklink-starknet-contracts`

First of all, you should active the cairo python virtual environment before you work with `zklink-starknet-contracts`.

```bash
pyenv active cairo_env
```

### Install Dependencies

`zklink-starknet-contracts` use [starknet.js](https://github.com/0xs34n/starknet.js) as SDK. You should run follow command to install dependencies:
Expand All @@ -40,10 +34,10 @@ To build an test `zklink-starknet-contracts`, you should run the following comma
scarb build

# test
scarb run test
scarb test
```

### Deploy

- [setting up an account](docs/setup_account.md)
- [deploy zklink contract](docs/deploy.md)
- [Setting up an account](https://book.starkli.rs/accounts)
- [Deploy zklink contract](docs/deploy.md)
150 changes: 113 additions & 37 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

- [Deploy zkLink Starknet Contracts](#deploy-zklink-starknet-contracts)
- [Config deployment](#config-deployment)
- [Start Starknet Devnet Node(Option)](#start-starknet-devnet-nodeoption)
- [Deploy command](#deploy-command)
- [Deploy ZkLink](#deploy-zklink)
- [Deploy zkLink main contract](#deploy-zklink-main-contract)
- [Upgrade zkLink](#upgrade-zklink)
- [Deploy zkLink L2 gateway contract](#deploy-zklink-l2-gateway-contract)
- [Upgrade zkLink L2 gateway](#upgrade-zklink-l2-gateway)
- [Deploy zkLink Lzbridge](#deploy-zklink-lzbridge)
- [Deploy zkLink multicall](#deploy-zklink-multicall)
- [Deploy facucet token(testnet only)](#deploy-facucet-tokentestnet-only)
- [Interacting with zkLink contracts](#interacting-with-zklink-contracts)

## Config deployment

Expand All @@ -13,16 +19,18 @@ The example configuration file path is `etc/example.json`
```json
{
"network": {
"name": "testnet",
"url": "https://alpha4.starknet.io",
"name": "devnet",
"url": "http://127.0.0.1",
"accounts": {
"deployer": {
"address": "",
"privateKey": ""
"privateKey": "",
"cairoVersion": ""
},
"governor": {
"address": "",
"privateKey": ""
"privateKey": "",
"cairoVersion": ""
}
}
},
Expand All @@ -31,35 +39,31 @@ The example configuration file path is `etc/example.json`
"UPGRADE_NOTICE_PERIOD": 0,
"PRIORITY_EXPIRATION": 0,
"CHAIN_ID": 1,
"ENABLE_COMMIT_COMPRESSED_BLOCK": true,
"MIN_CHAIN_ID": 1,
"MAX_CHAIN_ID": 4,
"ALL_CHAINS": 15
"ALL_CHAINS": 15,
"MASTER_CHAIN_ID": 2
}
}
```

`macro` is an object and define some macro variables which will replace in zkLink starknet contract.

- `CHAIN_ID` is the id defined in zkLink network(not the blockchain id). You need to set the `CHAIN_ID` according to the actual deployment situation.
- `ENABLE_COMMIT_COMPRESSED_BLOCK` is switch to enable block committed with compressed mode.
- `BLOCK_PERIOD` is average the block generation time, for example, in ethereum mainnet its value is `12 seconds`.
- `UPGRADE_NOTICE_PERIOD` is the contract upgrade lock time, when deploy in local development you could set this value to zero, and then we can upgrade contract immediately.
- `PRIORITY_EXPIRATION` is how long we wait for priority operation to handle by zklink.

`macro` also has three variables about constraints on `CHAIN_ID`:

- MIN_CHAIN_ID, the min chain id of zkLink network, and **SHOULD** be 1.
- MAX_CHAIN_ID, the max chain id of zkLink network.
- ALL_CHAINS, the supported chain ids flag.
- MASTER_CHAIN_ID, the chain id of master chain.

You should set `MAX_CHAIN_ID` and `ALL_CHAINS` according to the actual deployment situation. For example, the initial deployment we support two chains: 1 and 2, so `MAX_CHAIN_ID` should be 2 and `ALL_CHAINS` should be 3(`1 << 0 | 1 << 2`). The second deployment we support another chain: 3, and `MAX_CHAIN_ID` should be updated to 3 and `ALL_CHAINS` should be updated to 7(`1 << 0 | 1 << 1 | 1 << 2`).
You should set `MAX_CHAIN_ID` and `MASTER_CHAIN_ID` according to the actual deployment situation. For example, the initial deployment we support two chains: 1 and 2, so `MAX_CHAIN_ID` should be 2 and `ALL_CHAINS` should be 3(`1 << 0 | 1 << 2`). The second deployment we support another chain: 3, and `MAX_CHAIN_ID` should be updated to 3 and `ALL_CHAINS` should be updated to 7(`1 << 0 | 1 << 1 | 1 << 2`).

`network` contains Starknet network configurations:

- `name`: Starknet networknet, includes `devnet/testnet/mainnet`;
- `url` : Starknet rpc url that scripts connected to. You can find the url [here](https://docs.starknet.io/documentation/tools/CLI/commands/#setting_custom_endpoints)
- `accounts` : infomations about `deployer` and `governor`, which is needed by deployment. Thus Starknet account is AA, so you should put `privateKey` and `address` at the same time. You may need to set `deployer` different with `governor` when deploying to testnet to do some authority tests.
- `accounts` : infomations about `deployer` and `governor`, which is needed by deployment. Thus Starknet account is AA, so you should put `privateKey` and `address` at the same time. You may need to set `deployer` different with `governor` when deploying to testnet to do some authority tests. `cairoVersion` is the contract Cairo version of account, option is `0` or `1`.
- `deployer`: who deploying contracts, can same with `governor`.
- `governor`: who has the management authority of the contract.

Expand All @@ -70,42 +74,114 @@ cd etc
cp -f example.json devnet.json
```

And run the following command:
And run the following command will compiling zklink starknet contracts:

```shell
NET=devnet npm run deploy
NET=devnet npm run build
```

### Start Starknet Devnet Node(Option)
## Deploy command

### Deploy zkLink main contract

If you want to deploy zkLink starknet contract on devnet, you should start the starknet devnet node.
```sh
NET=<network name> npm run deployZklink -- --help
```

The follow command will fork Testnet data when you start devnet node, and you can use the testnet account in the environment.
### Upgrade zkLink

```shell
starknet-devnet --seed 0 --accounts 0 --fork-network alpha-goerli
```sh
NET=<network name> npm run upgradeZklink -- --help
```

> If your computer's CPU architecture is **NOT** x86, you should add argument `--sierra-compiler-path` with above command
>
> ```bash
> starknet-devnet --seed 0 --accounts 0 --fork-network alpha-goerli --sierra-compiler-path ~/.cairo/target/release
> ```
### Deploy zkLink L2 gateway contract

Devnet network config looks like this:
```sh
NET=<network name> npm run deployL2Gateway -- --help
```

```json
"network": {
"name": "devnet",
"url": "http://127.0.0.1:5050",
...
}
### Upgrade zkLink L2 gateway

```sh
NET=<network name> npm run upgradeL2Gateway -- --help
```

## Deploy command
### Deploy zkLink Lzbridge

```sh
NET=<network name> npm run deployLZBridge -- --help
```

### Deploy zkLink multicall

```sh
NET=<network name> npm run deployMulticall -- --help
```

### Deploy facucet token(testnet only)

```sh
NET=<network name> npm run deployFaucetToken -- --help
```

### Interacting with zkLink contracts

- Add Token

```sh
NET=<network name> npm run addToken -- --help
```

### Deploy ZkLink
- Add Bridge

```sh
NET=<network name> npm run addBridge -- --help
```
NET=<network name> npm run deploy

- Set L1 gateway to zkLink

```sh
NET=<network name> npm run setL1RemoteGateway -- --help
```

- Set L2 gateway to zkLink

```sh
NET=<network name> npm run setL2RemoteGateway -- --help
```

- Set zkLink to L2 gatway

```sh
NET=<network name> npm run setL2GatewayToZkLink -- --help
```

- Set destinations

```sh
NET=<network name> npm run setDestinations -- --help
```

- Set chain id map

```sh
NET=<network name> npm run setChainIdMap -- --help
```

- Mint faucet token(testnet only)

```sh
NET=<network name> npm run mintFaucetToken -- --help
```

- Transfer ownership of UpgradeGatekeeper

```sh
NET=<network name> npm run transferMastershipOfUpgradeGatekeeper -- --help
```

- Change zkLink governor

```sh
NET=<network name> npm run changeGovernorOfZkLink -- --help
```
72 changes: 0 additions & 72 deletions docs/setup_account.md

This file was deleted.

Loading

0 comments on commit 699b7bf

Please sign in to comment.