Skip to content

Commit

Permalink
docs(unifi): testnet
Browse files Browse the repository at this point in the history
* feat: add initial unifi testnet documentation

* fix: redact pages and fix link styling

* fix: redact and put placeholders

* fix: redact contract deployment tutorials

* feat: add bridge ui guide

* feat: add manual claim docs

* fix: contract addresses

* fix: json rpc support

* feat: refactor rpc endpoints page

* fix: block explorer endpoint

* style: code format

* fix: addresses and link

* fix: placeholders and tweaks

* style: formatting; urls

* nit: formatting

---------

Co-authored-by: failfmi <[email protected]>
  • Loading branch information
vikinatora and failfmi authored Nov 5, 2024
1 parent 4f37710 commit a9b1200
Show file tree
Hide file tree
Showing 19 changed files with 538 additions and 6 deletions.
12 changes: 12 additions & 0 deletions docs/developers/getting-started/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Getting Started
slug: /developers/getting-started/index
---

# Building on UniFi

UniFi is mostly EVM equivalent, which means that developers can use familiar EVM tools and frameworks, such as Hardhat, Truffle, and Remix, to interact with and develop on UniFi. This compatibility significantly reduces the learning curve, allowing developers to leverage existing skills and knowledge.

:::info
For exact differences between UniFi and EVM behaviour, see [Opcode reference](../reference/opcodes.md) page.
:::
33 changes: 33 additions & 0 deletions docs/developers/reference/contract-addresses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: Smart Contract Addresses
slug: /developers/rollup/reference/contract-addresses
---

## Testnet

### L1 Addresses

| Contract | Address |
|---------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| UniFi L1 | [0x12d30f3584ee969C4131b7d5dCAEe763A378AfD9](https://holesky.etherscan.io/address/0x12d30f3584ee969C4131b7d5dCAEe763A378AfD9) |
| Rollup Address Manager | [0x540B8d82e6E11F0a9438fB19f33c85b2B53B49d8](https://holesky.etherscan.io/address/0x540B8d82e6E11F0a9438fB19f33c85b2B53B49d8) |
| Shared Address Manager | [0x0F3dD9461Ccf086cC32D38eC8673e541Fc86279d](https://holesky.etherscan.io/address/0x0F3dD9461Ccf086cC32D38eC8673e541Fc86279d) |
| Attestation Verifier | [0xCB848506bcB28C86Dd0CCb5905BaBD80CC0277E4](https://holesky.etherscan.io/address/0xCB848506bcB28C86Dd0CCb5905BaBD80CC0277E4) |
| Automata DCAP Attestation | [0x133303659F51d75ED216FD98a0B70CbCD75339b2](https://holesky.etherscan.io/address/0x133303659F51d75ED216FD98a0B70CbCD75339b2) |
| Bridge | [0x81bfCf0f7196C1772279846625F619f691755120](https://holesky.etherscan.io/address/0x81bfCf0f7196C1772279846625F619f691755120) |
| Prover Set | [0x3a4e7187720420FF208AfC4EA2602d3DE2C80E1d](https://holesky.etherscan.io/address/0x3a4e7187720420FF208AfC4EA2602d3DE2C80E1d) |
| Signal Service | [0x60646983250313B750D3657C648823d665305299](https://holesky.etherscan.io/address/0x60646983250313B750D3657C648823d665305299) |
| UniFi Token | [0x4543168F4C5b3EcDdeF36E15DbCD6914e3f585BD](https://holesky.etherscan.io/address/0x4543168F4C5b3EcDdeF36E15DbCD6914e3f585BD) |
| TDXVerifier | [0x7c2B88Bb08467669e6ee3ed604f07aB0D5E78F1a](https://holesky.etherscan.io/address/0x7c2B88Bb08467669e6ee3ed604f07aB0D5E78F1a) |
| GuardianProver | [0xdE0e5FefE21af1C46F63c0Ee6381b512B95085F7](https://holesky.etherscan.io/address/0xdE0e5FefE21af1C46F63c0Ee6381b512B95085F7) |
| GuardianProverMinority | [0x51940246968853F696ab7761eA5Af86c542C0894](https://holesky.etherscan.io/address/0x51940246968853F696ab7761eA5Af86c542C0894) |

### L2 Addresses

| Contract | Address |
|-----------------------------|--------------------------------------------|
| UniFi L2 | 0x9A7fe8e9852c684DD03ce9caEa003F5Fc0a3135b |
| Bridge | 0x511a232eaef7aA4633BAc8E406a7886e46492AFC |
| Signal Service | 0x80d0AFe646Ba22e5E557F1dCC209e75b07e1b1BA |
| Rollup Address Manager | 0x91e75542D9da7C52089b71094e327307C51D6deD |
| Shared Address Manager Impl | 0x6a23ea44177735E3700721817A181375A8afdb47 |
26 changes: 26 additions & 0 deletions docs/developers/reference/opcodes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Opcodes

Since UniFi is based on Taiko, it inherits the same opcode behaviour as Taiko. Unless listed below, all opcodes are supported in UniFi and are EVM equivalent. The execution of some Opcodes is not verified by the circuits and its not part of the validity proofs.

# Unsupported Opcodes

:::warning
If an unsupported opcode is encountered during execution that is not supported in UniFi, the transaction will revert.
:::
The following opcodes are not supported in UniFi:
| Opcode | Name | Solidity Equivalent |
|--------|-------------|---------------------|
| 49 | BLOBHASH | blobhash(index) |
| 4A | BLOBBASEFEE | block.blobasefee |
| 5C | TLOAD | tload(key) |
| 5D | TSTORE | tstore(key, value) |
| 5E | MCOPY | mcopy() |

# Modified Opcodes

| Opcode | Name | Solidity Equivalent | Rollup Behaviour | Ethereum L1 Behaviour |
|--------|-----------|---------------------|----------------------------------------------|--------------------------------------|
| 41 | COINBASE | block.coinbase | Returns the address of the L2 block proposer | Gets the block’s beneficiary address |
| 42 | TIMESTAMP | block.timestamp | Timestamp of the L2 block | Timestamp of the L1 block |
| 43 | NUMBER | block.number | L2 block number | Gets the L1 block number |
| 48 | BASEFEE | block.basefee | Returns the L2 base fee | Returns the base fee |
15 changes: 15 additions & 0 deletions docs/developers/reference/rpc-endpoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Network & RPC Endpoints
slug: /developers/rollup/reference/rpc-endpoints
---

## UniFi Testnet

| Parameter | Value |
|--------------------|--------------------------------------------------------|
| Network Name | `UniFi Testnet` |
| Chain ID | `8787` |
| Currency Symbol | ETH |
| Block Explorer | TODO: |
| Sequencer URL | TODO: |
| Contract Addresses | See [Contract addresses](./contract-addresses.md) page |
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: Deploy a Smart Contract on UniFi using Foundry
slug: /developers/rollup/smart-contracts/foundry
---

## Prerequisite

Before you begin, ensure you've:

1. [Set up your wallet and have bridged UniFi tokens successfully](../../../unifi-rollup-move-funds.md).
2. Downloaded and installed Foundry:

```bash
curl -L https://foundry.paradigm.xyz | bash
```

Then, open a new terminal, and call `foundryup` to install the latest release.
:::info
Running `foundryup` will automatically install the latest (nightly) versions of the precompiled binaries: forge, cast, anvil, and chisel. For additional options, such as installing a specific version or commit, run `foundryup --help`
:::

## Create a Foundry project

To create a Foundry project, run:

```bash
forge init unifi-smart-contract-tutorial
```

Running `forge init` sets up a sample contract, test, and script for `Counter.sol`.

Now change into the directory:

```bash
cd unifi-smart-contract-tutorial
```

## Deploy a smart contract

:::warning
Directly pasting your private key into the command line poses security risks. The examples below are instructional and don't adhere to good security practices. To avoid exposing sensitive information such as wallet private keys, use `.env` files to store private data. Create a `.env` file, then add the file to the `.gitignore` file to prevent committing it. Populate the `.env` file with the private information.
:::

Deploy your contract using the following syntax:

```bash
forge create --rpc-url <rpc_https_endpoint> src/Counter.sol:Counter --private-key <your_private_key>
```

In the command:

- `rpc_https_endpoint` is a RPC Endpoint for the UniFi network. You can find the endpoints in the [RPC Endpoints Reference](../../reference/rpc-endpoints.md).
- `your_private_key` is your wallet's private key.

Your output should look similar to:

```bash
Deployer: YOUR_WALLET_ADDRESS
Deployed to: 0xFCc25885bDcF17A0BF1C0E529100B6420e237Cbe
Transaction hash: 0x734c59643232b61b560da2c750d7ad808267fbc28331ee59102e431ec9559097
```

For more deployment options, see the [forge-create documentation](https://book.getfoundry.sh/reference/forge/forge-create).

## Verify your smart contract

Optionally, you can verify your contract on the network. This makes the source code publicly available.

### Deploy and verify a contract in one go

To deploy and verify a contract in a single command, run:

```bash
forge create --rpc-url <rpc_https_endpoint> --private-key <your_private_key> src/Counter.sol:Counter --verify --verifier blockscout --verifier-url <blockscout_homepage_explorer_url>/api
```

In the command:

- `rpc_https_endpoint` is a RPC Endpoint for the UniFi network. You can find the endpoints in the [RPC Endpoints Reference](../../reference/rpc-endpoints.md).
- `your_private_key` is your wallet's private key.
- `blockscout_homepage_explorer_url` is the URL of the block explorer explorer you're using. You can find the endpoints in the [RPC Endpoints Reference](../../reference/rpc-endpoints.md).

For more contract verification options, see the [verify-contract documentation](https://book.getfoundry.sh/reference/forge/forge-verify-contract).
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
---
title: Deploy a Smart Contract using Hardhat
slug: /developers/rollup/smart-contracts/hardhat
---

## Prerequisites

Before you begin, ensure you:

1. [Set up your wallet and have bridged UniFi tokens successfully](../../../unifi-rollup-move-funds.md).
2. [Set up your Hardhat environment](https://hardhat.org/tutorial/setting-up-the-environment#2.-setting-up-the-environment).

## Create a Hardhat project

To create an empty Hardhat project:

1. Create your project directory:

```bash
mkdir unifi-smart-contract-tutorial
cd unifi-smart-contract-tutorial
```

2. Initialize your Node.js project:

```bash
npm init
```

3. Install Hardhat:

```bash
npm install --save-dev hardhat
```

4. Initialize the Hardhat project:

```bash
npx hardhat init
```

In the menu that appears, select **Create a JavaScript project** and press **Enter**. Accept all
the default values in the questionnaire.

You should now have a sample HardHat project with a `Lock` contract, that locks funds for a set time, and a few smart contract tests.

:::note

The default script in `ignition/modules/Lock.js` locks 1 GWEI in the contract upon deployment, you can modify this
value in the script.

:::

## Deploy the contract

The sample project already includes the deployment script. To deploy on UniFi, you'll just need to make
a few modifications to the `hardhat.config.js` file:

1. Create a `.env` file in the root folder with your wallet's private key and [RPC Endpoint](../../reference/rpc-endpoints.md).

```
PRIVATE_KEY=<your_private_key>
RPC_ENDPOINT=<rpc_https_endpoint>
```

:::warning
Please do not commit your private keys into source control. Double check that `.env` is contained in your `.gitignore`
:::

2. Download and install `dotenv`

```
npm i -D dotenv
```

3. Add UniFi to your `hardhat.config.js` file. The following example shows how to add a RPC endpoint to the configuration file.

```javascript
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
const { PRIVATE_KEY, RPC_ENDPOINT } = process.env;

module.exports = {
solidity: "0.8.27",
networks: {
unifi_testnet: {
url: RPC_ENDPOINT,
accounts: [PRIVATE_KEY],
},
},
};
```

4. Deploy your contract.

```bash
npx hardhat ignition deploy ./ignition/modules/Lock.js --network <network_name>
```

In the command:

- `<network_name>` is the name of the network from `hardhat.config.js` you want to deploy on f.e. `unifi_testnet`.

Your output should look something like this:

```bash
Deployed Addresses

LockModule#Lock - 0xA72022A83654E794B8e9FD7217ADF7378f3e985d
```

## Verify your smart contract

Optionally, you can verify your contract on the network. This makes the source code publicly available.

### Verify an already existing contract contract

To verify a contract, you need to make a few modifications the project.

1. In your project directory, install `hardhat-verify`
```bash
npm install --save-dev @nomicfoundation/hardhat-verify
```
2. Add blockscout url and chain id to the .env file
```
BLOCKSCOUT_URL=<blockscout_homepage_explorer_url>
CHAIN_ID=<chain_id>
```
3. Import `hardhat-verify` in your `hardhat.config.js`:

```javascript
require("@nomicfoundation/hardhat-verify");
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
const { PRIVATE_KEY, RPC_ENDPOINT, BLOCKSCOUT_URL, CHAIN_ID } = process.env;

module.exports = {
solidity: "0.8.27",
networks: {
unifi_testnet: {
url: RPC_ENDPOINT,
accounts: [PRIVATE_KEY],
},
},
etherscan: {
apiKey: {
unifi_testnet: "empty",
},
customChains: [
{
network: "unifi_testnet",
chainId: CHAIN_ID,
urls: {
apiURL: `${BLOCKSCOUT_URL}/api`,
browserURL: BLOCKSCOUT_URL,
},
},
],
},
sourcify: {
enabled: false,
},
};
```

4. Execute the `hardhat verify` command:

```bash
npx hardhat verify --network <network_name> <contract_address> "constructor_argument_1" "constructor_argument_2" ...
```

In our example, the full command should look something like this:

```bash
npx hardhat verify --network unifi_testnet 0x545D79cAace91bB8A710Ad2ee4e50B01d87bB6Ff 123456
```

In the command:

- `<network_name>` is the name of the network you want to verify on.
- `<contract_address>` is the address where your contract was deployed.
- `constructor_argument_1`, `constructor_argument_2`, etc., are the arguments passed to your contract's constructor (if any).

For more contract verification options, refer to the [Hardhat verification documentation](https://hardhat.org/plugins/nomiclabs-hardhat-etherscan.html).
Loading

0 comments on commit a9b1200

Please sign in to comment.