Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localnet #2

Merged
merged 9 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @lumtis @skosito @fbac @fadeev
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build

on:
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "21"
registry-url: "https://registry.npmjs.org"

- name: Install Dependencies
run: yarn

- name: Build
run: yarn build
29 changes: 29 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Lint

on:
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "21"
registry-url: "https://registry.npmjs.org"

- name: Install Dependencies
run: yarn

- name: Lint
run: yarn lint
40 changes: 40 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish to NPM

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "21"
registry-url: "https://registry.npmjs.org"

- name: Install Dependencies
run: yarn

- name: Generate Files
run: yarn build

- name: Determine NPM Tag
id: determine-npm-tag
run: |
VERSION_TAG="${{ github.event.inputs.version }}"
if [[ $VERSION_TAG == *"-"* ]]; then
echo "NPM_TAG=${VERSION_TAG#*-}" >> $GITHUB_ENV
else
echo "NPM_TAG=latest" >> $GITHUB_ENV
fi

- name: Publish to NPM
run: yarn publish --new-version ${{ github.event.inputs.version }} --tag ${{ env.NPM_TAG }} --no-git-tag-version
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Yarn
node_modules
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Hardhat
artifacts
cache

# Typescript
dist
tsconfig.tsbuildinfo

# Misc
.env
.DS_Store
.secrets
.wallet.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Meta Protocol, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
163 changes: 162 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,162 @@
# localnet
# Local Development Environment

Important Notice: The new architecture (V2) is currently in active development.
While the high-level interface presented in this document is expected to remain
stable, some aspects of the architecture may change.

## Introduction

The new architecture aims to streamline the developer experience for building
Universal Apps. Developers will primarily interact with two contracts:
GatewayZEVM and GatewayEVM.

- `GatewayEVM`: Deployed on each connected chain to interact with ZetaChain.
- `GatewayZEVM`: Deployed on ZetaChain to interact with connected chains.

V2 contracts source code is currently located in
[prototypes](/contracts/prototypes/)

## Contract Interfaces

The interface of the gateway contracts is centered around the deposit, withdraw,
and call terminology:

- Deposit: Transfer of assets from a connected chain to ZetaChain.
- Withdraw: Transfer of assets from ZetaChain to a connected chain.
- Call: Smart contract call involved in cross-chain transactions.

In consequence, the interface is as follow:

- `GatewayEVM`: `deposit`, `depositAndCall`, and `call`
- `GatewayZEVM`: `withdraw`, `withdrawAndCall`, and `call`

The motivation behind this interface is intuitiveness and simplicity. We support
different asset types by using function overloading.

### `GatewayEVM`

- Deposit of native tokens to addresses on ZetaChain:

```solidity
function deposit(address receiver) payable
```

- Deposit of ERC-20 tokens to addresses on ZetaChain:

```solidity
function deposit(address receiver, uint256 amount, address asset)
```

- Deposit of native tokens and smart contract call on ZetaChain:

```solidity
function depositAndCall(address receiver, bytes calldata payload) payable
```

- Deposit of ERC-20 tokens and smart contract call on ZetaChain:

```solidity
depositAndCall(address receiver, uint256 amount, address asset, bytes calldata payload)
```

- Simple Universal App contract call:

```solidity
function call(address receiver, bytes calldata payload)
```

### `GatewayZEVM`

- Withdraw of ZRC-20 tokens to its native connected chain:

```solidity
function withdraw(bytes memory receiver, uint256 amount, address zrc20)
```

- Withdraw of ZRC-20 tokens and smart contract call on connected chain:

```solidity
function withdrawAndCall(bytes memory receiver, uint256 amount, address zrc20, bytes calldata message)
```

- Simple call to a contract on a connected chain:

```solidity
function call(bytes memory receiver, bytes calldata message) external
```

## Experimenting with the New Architecture

To experiment with the new architecture, you can deploy a local network using
Hardhat and test the gateways using the following commands:

Clone the repository

```
git clone https://github.com/zeta-chain/protocol-contracts.git
cd protocol-contracts
```

Start the local environment network Note: `--hide="NODE"` is used to prevent
verbose logging

```
yarn
yarn localnet --hide="NODE"
```

The `localnet` command launches two processes:

- A local Ethereum network (using Hardhat) with the two gateway contracts
deployed
- A background worker that relay messages between the two gateway contracts. It
simulates the cross-chain message relaying that would normally happen between
live networks with the
[observers/signers](https://www.zetachain.com/docs/developers/architecture/observers/)
mechanism. This allows to simulate a cross-chain environment on a single local
chain.

Running the command will deploy the two gateway contracts:

```
[WORKER] GatewayEVM: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
[WORKER] GatewayZEVM: 0x0165878A594ca255338adfa4d48449f69242Eb8F
```

The developers can develop application using these addresses, the messages will
automatically be relayed by the worker.

The local environment uses Hardhat localnet. Therefore, the default Hardhat
localnet accounts can be used to interact with the network.

```
Account #0: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000 ETH)
Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Account #1: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (10000 ETH)
Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d

Account #2: 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC (10000 ETH)
Private Key: 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
```

### Examples

The example contracts demonstrate how the V2 interface can be leveraged to build
Universal Apps.

- [TestZContract](/contracts/prototypes/zevm/TestZContract.sol): ZetaChain
contract (Universal App) that can be called from a connected chains
- [SenderZEVM](/contracts/prototypes/zevm/SenderZEVM.sol): ZetaChain contract
calling a smart contract on a connected chains
- [ReceiverEVM](/contracts/prototypes/evm/ReceiverEVM.sol): contract on
connected chain that can be called from ZetaChain

The following commands can be used to test interactions between these contracts:

```
npx hardhat zevm-call --network localhost
npx hardhat zevm-withdraw-and-call --network localhost
npx hardhat evm-call --network localhost
npx hardhat evm-deposit-and-call --network localhost
```
13 changes: 13 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = [
{
ignores: [".yarn", "artifacts", "cache", "dist", "node_modules"],
languageOptions: {
ecmaVersion: 2020,
sourceType: "module",
parser: require("@typescript-eslint/parser"),
},
plugins: {
"@typescript-eslint": require("@typescript-eslint/eslint-plugin"),
},
},
];
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@zetachain/localnet",
"version": "0.0.0-set-on-publish",
"description": "",
"scripts": {
"build": "tsc",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
"keywords": [],
"author": "ZetaChain",
"license": "MIT",
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^8.0.1",
"del-cli": "^5.1.0",
"eslint": "^9.8.0",
"typescript": "^5.5.4"
},
"dependencies": {
"@zetachain/protocol-contracts": "10.0.0-rc5",
"ethers": "^6.13.2"
}
}
Loading
Loading