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

cross chain contracts and scripts with LayerZero #1

Open
wants to merge 122 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
4998fdc
chore: forge init
dan13ram Sep 1, 2024
d6c9179
forge install: forge-std
dan13ram Sep 1, 2024
e6929ae
setup yarn with dependencies
dan13ram Sep 1, 2024
e189176
setup basic contracts
dan13ram Sep 1, 2024
d694c5a
importing solmate
MrDeadCe11 Sep 2, 2024
5527eea
forge install: solmate
MrDeadCe11 Sep 2, 2024
1ad0dde
added deployer
MrDeadCe11 Sep 2, 2024
78d3620
added natspec for factory
MrDeadCe11 Sep 2, 2024
88f9482
deployer can now deploy vanity addresses, added bare bones test setup…
MrDeadCe11 Sep 2, 2024
ffae22f
fixed misnamed variable
MrDeadCe11 Sep 2, 2024
9695c6c
minor fix
MrDeadCe11 Sep 2, 2024
7ced6e6
minor fix
MrDeadCe11 Sep 2, 2024
c96458a
Merge branch 'dev' of https://github.com/yieldnest/yieldnest-cross-ch…
MrDeadCe11 Sep 2, 2024
60a3b49
added cross chain deployer deployment with multiple forks
MrDeadCe11 Sep 2, 2024
4b3717c
set up, oft l1 adapter init failing
MrDeadCe11 Sep 2, 2024
493b12c
added missing files
MrDeadCe11 Sep 2, 2024
fea4880
deployment working
dan13ram Sep 3, 2024
f297c55
renamed deployer and working on importing the layer zero test helpers
MrDeadCe11 Sep 4, 2024
04237a7
added an adapter harness
MrDeadCe11 Sep 4, 2024
ef00df4
added imports for required mocks
MrDeadCe11 Sep 4, 2024
0e3dccb
fixed test dependencies
dan13ram Sep 4, 2024
83d8a51
setting peers
dan13ram Sep 4, 2024
a5624e9
sending working
dan13ram Sep 4, 2024
486a55a
testing
dan13ram Sep 4, 2024
9beec60
OFT test working as is
dan13ram Sep 4, 2024
318791b
added lint-staged
dan13ram Sep 4, 2024
1acd128
test setup complete
dan13ram Sep 4, 2024
664725f
send and receive working
dan13ram Sep 4, 2024
6421d8a
added test for rate limits
dan13ram Sep 4, 2024
19ad229
more oft tests.
MrDeadCe11 Sep 4, 2024
cf9d7c3
shrunk immutable deployer contract size, fixed tests
MrDeadCe11 Sep 5, 2024
95723f2
working on deployment scripts
MrDeadCe11 Sep 5, 2024
69d2fbe
Merge pull request #2 from yieldnest/testing-setup-deployment
MrDeadCe11 Sep 5, 2024
da1585c
working on deployment scripts
MrDeadCe11 Sep 5, 2024
041152c
working on json inputs
MrDeadCe11 Sep 5, 2024
0221acb
missing files
MrDeadCe11 Sep 5, 2024
85ba500
moved solmate to npm dependency
dan13ram Sep 5, 2024
945335c
removed unnecessary files
dan13ram Sep 5, 2024
bb20bc4
added tests for l1 oft adapter
dan13ram Sep 5, 2024
410c61a
renamed test
dan13ram Sep 5, 2024
795ce49
refactored factory code
dan13ram Sep 5, 2024
a32f240
added base script
dan13ram Sep 5, 2024
40ae302
Merge branch 'feat/deployment' into scripts
MrDeadCe11 Sep 5, 2024
0a2c882
merged feat/deployment into scripts. data loading from json.
MrDeadCe11 Sep 6, 2024
f24a103
missing files
MrDeadCe11 Sep 6, 2024
7ec0a67
missing files
MrDeadCe11 Sep 6, 2024
9a1b2ab
contract compiles"
MrDeadCe11 Sep 6, 2024
1946bc2
immutable deployer deploys and writes output
MrDeadCe11 Sep 6, 2024
571f0d0
slight refactor
MrDeadCe11 Sep 6, 2024
4f34e01
fixed compile errors
dan13ram Sep 6, 2024
de64bce
Merge pull request #4 from yieldnest/scripts
dan13ram Sep 6, 2024
43bf272
added script for l2 adapter deployment
MrDeadCe11 Sep 7, 2024
5831f9c
some clean up. added missing files
MrDeadCe11 Sep 7, 2024
f40f921
l2Adapter script deploys the erc20 first then the adapter
MrDeadCe11 Sep 7, 2024
80b0be0
updated scripts to write and read from single json for one token
dan13ram Sep 7, 2024
39b1fe5
fixed l2 oft adapter script
dan13ram Sep 7, 2024
6f4ccea
added script for setPeers
dan13ram Sep 7, 2024
0d2a4d2
added LIMITER role to oft adapter
dan13ram Sep 7, 2024
c8aa2da
Merge pull request #5 from yieldnest/script
dan13ram Sep 8, 2024
99054c1
updated readme
dan13ram Sep 8, 2024
d64144b
removes need for approval
dan13ram Sep 8, 2024
d8bc0d4
added solhint and updated readme
dan13ram Sep 8, 2024
ba3048a
fixed package.json
dan13ram Sep 8, 2024
c551521
starting bash script
MrDeadCe11 Sep 10, 2024
a0492d2
added missing files
MrDeadCe11 Sep 10, 2024
2b6d1de
added multichain deployer and adapters to bash script
MrDeadCe11 Sep 10, 2024
b0b284b
bash now will ask for the chainID only if there are multiple L2 chain…
MrDeadCe11 Sep 10, 2024
9966349
removed unneccessary require
MrDeadCe11 Sep 10, 2024
66570c9
some help
MrDeadCe11 Sep 10, 2024
1082b72
added missing files
MrDeadCe11 Sep 10, 2024
4f3f81e
updated env example
MrDeadCe11 Sep 10, 2024
5d14e5f
working on deploying in json
MrDeadCe11 Sep 15, 2024
f984ee7
added missing files
MrDeadCe11 Sep 15, 2024
6fe773b
updated solidity scripts
dan13ram Sep 15, 2024
7a28a2d
deployments working
dan13ram Sep 15, 2024
71e1fd0
updated bash script to deploy and verify
dan13ram Sep 15, 2024
046aa0e
updated readme and fixed scripts
dan13ram Sep 15, 2024
6dc2461
deployment working for adding new chain
dan13ram Sep 15, 2024
155fd8e
create set peers multi-send at the end of the l2OFTADapter deployment
MrDeadCe11 Sep 16, 2024
0788b10
console logging txs in verification scripts
MrDeadCe11 Sep 16, 2024
34177dd
forge install: forge-std
dan13ram Sep 16, 2024
d32b575
forge install: forge-safe
dan13ram Sep 16, 2024
a27b18c
forge install: LayerZero-v2
dan13ram Sep 16, 2024
fd2f832
fixed remappings
dan13ram Sep 16, 2024
08a243f
forge install: solmate
dan13ram Sep 16, 2024
29fce75
fixed remappings
dan13ram Sep 16, 2024
99bc9e8
fixed bash script to support foundry.yaml
dan13ram Sep 16, 2024
1f7a185
using forge-safe
dan13ram Sep 16, 2024
c6bb8b4
fixed scripts
dan13ram Sep 16, 2024
3c1c488
Merge pull request #6 from yieldnest/feat/bash
dan13ram Sep 16, 2024
fe3e12b
removed temp address check
dan13ram Sep 16, 2024
44db5b3
added multisend address for fraxtal testnet
dan13ram Sep 16, 2024
5ad3578
fixed verification to pass in api-key info
MrDeadCe11 Sep 17, 2024
d00d1da
fixed verify scripts
dan13ram Sep 17, 2024
3605a34
minor fix
dan13ram Sep 17, 2024
45c30b6
minor refactor of data
dan13ram Sep 17, 2024
4d022b0
added helper methods for salt creation
dan13ram Sep 18, 2024
21398ee
added natspec comments
dan13ram Sep 18, 2024
452cc07
fixed remappings
dan13ram Sep 18, 2024
539d7a8
add morph l2
danoctavian Sep 18, 2024
f407187
bump version temporarily
danoctavian Sep 19, 2024
cad2d8b
add entry in README.md
danoctavian Sep 19, 2024
9e9c05f
revert temp version change
dan13ram Sep 20, 2024
afc4446
rearranged readme
dan13ram Sep 20, 2024
1a45483
reorderd github workflow
dan13ram Sep 20, 2024
b86fbe3
added github secrets to workflow
dan13ram Sep 20, 2024
3a7fe18
Merge pull request #7 from yieldnest/feature/morph-addition
dan13ram Sep 20, 2024
807db4d
upgrade to oz 5
danoctavian Oct 8, 2024
b71a230
change verify scripts
danoctavian Oct 8, 2024
337c260
make multichain deployer deploy using TUP 5
danoctavian Oct 8, 2024
8bd2a7a
Merge pull request #9 from yieldnest/fix/oz-dependency
danoctavian Oct 8, 2024
abd88bc
add new chain ids
danoctavian Oct 8, 2024
8e14cf0
fill in __chainIdToData
danoctavian Oct 8, 2024
99c9d71
add multisend addresses
danoctavian Oct 8, 2024
bcbcb4f
add entries in deploy.sh
danoctavian Oct 8, 2024
5c1abac
enrich .env.example
danoctavian Oct 8, 2024
bb1c9b6
partially complete foundry.toml
danoctavian Oct 8, 2024
48a2627
add chain explorer api endpoints
danoctavian Oct 9, 2024
c2f685b
add 2 chains to mainnet
danoctavian Oct 9, 2024
05aaa1b
bump proxy in test
danoctavian Oct 9, 2024
1331e63
add OZ v5 contracts in repo to fix remappings issue
danoctavian Oct 9, 2024
3945ec2
Merge pull request #10 from yieldnest/feature/extra-chains
danoctavian Oct 9, 2024
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
39 changes: 39 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# for verifying contracts
ETHERSCAN_API_KEY=
OPTIMISTIC_ETHERSCAN_API_KEY=
ARBISCAN_API_KEY=
BASESCAN_API_KEY=
FRAXSCAN_API_KEY=
MORPHSCAN_API_KEY=

MANTASCAN_API_KEY=
TAIKOSCAN_API_KEY=
SCROLLSCAN_API_KEY=
FANTOMSCAN_API_KEY=
MANTLESCAN_API_KEY=
BLASTSCAN_API_KEY=
LINEASCAN_API_KEY=


# for testing and deploying the contracts please use full arhcival nodes
BASE_RPC_URL=
ARBITRUM_RPC_URL=
FRAX_RPC_URL=
OPTIMISM_RPC_URL=
HOLESKY_RPC_URL=
SEPOLIA_RPC_URL=
MAINNET_RPC_URL=
FRAX_TESTNET_RPC_URL=
MORPH_TESTNET_RPC_URL=
MANTA_RPC_URL=
TAIKO_RPC_URL=
SCROLL_RPC_URL=
FANTOM_RPC_URL=
MANTLE_RPC_URL=
BLAST_RPC_URL=
LINEA_RPC_URL=


# for use with cast wallet. store the deployer private key in the keystore and put the public address here.
DEPLOYER_ACCOUNT_NAME=
DEPLOYER_ADDRESS=
55 changes: 55 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: test

on:
pull_request:
branches:
- main
push:

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20.x

- uses: actions/cache@v4
with:
path: '**/node_modules'
key: cached-node-modules-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Install Dependencies
run: |
yarn install --frozen-lockfile

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
env:
CI: true
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
ARBITRUM_RPC_URL: ${{ secrets.ARBITRUM_RPC_URL }}
OPTIMISM_RPC_URL: ${{ secrets.OPTIMISM_RPC_URL }}

run: |
forge test -vvv
id: test
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env

# Node Modules
node_modules/
13 changes: 13 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/LayerZero-v2"]
path = lib/LayerZero-v2
url = https://github.com/JorgeAtPaladin/LayerZero-v2
branch = lz-upgrade
[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/transmissions11/solmate
[submodule "lib/surl"]
path = lib/surl
url = https://github.com/memester-xyz/surl
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn lint-staged
3 changes: 3 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "solhint:default"
}
240 changes: 238 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,239 @@
# Yieldnest Cross Chain
# Yieldnest Cross-Chain Contracts
dan13ram marked this conversation as resolved.
Show resolved Hide resolved

Contracts and scripts for deploying cross chain yieldnest tokens using LayerZero.
This project contains the smart contracts and scripts for deploying cross-chain Yieldnest tokens using LayerZero technology. It leverages the Foundry development toolkit for testing, building, and deploying contracts, and uses Yarn to manage dependencies.

## Project Overview

This repository includes:

- **Smart Contracts**: Contracts for Yieldnest's cross-chain tokens.
- **Deployment Scripts**: Scripts for deploying and configuring the contracts across multiple chains.
- **Testing Framework**: Tests using Foundry's Forge tool.

### Key Contracts and Scripts

- **Main Contracts**:
- `L2YnERC20Upgradeable.sol`: Layer 2 upgradeable ERC20 token contract.
- `ImmutableMultiChainDeployer.sol`: Handles multi-chain deployment of contracts.
- `L1YnOFTAdapterUpgradeable.sol`: Adapter for Layer 1 OFT (Omnichain Fungible Token).
- `L2YnOFTAdapterUpgradeable.sol`: Adapter for Layer 2 OFT.

- **Deployment Scripts**:
- `deploy.sh`: The main deployment script that handles deployments across multiple chains.
- `DeployL2OFTAdapter.s.sol`: Deploys the Layer 2 ERC20 token and OFT Adapter.
- `DeployL1OFTAdapter.s.sol`: Deploys the Layer 1 OFT Adapter.
- `VerifyL2OFTAdapter.s.sol`: Verifys the Layer 2 ERC20 token and OFT Adapter.
- `VerifyL1OFTAdapter.s.sol`: Verifys the Layer 1 OFT Adapter.

## Prerequisites

- **Foundry**: A fast, portable, and modular toolkit for Ethereum development.
- **Yarn**: Dependency management tool used in this project.
- **Solidity**: For developing smart contracts.

## Installation

### 1. Clone the Repository

```bash
git clone https://github.com/yieldnest/yieldnest-cross-chain.git
cd yieldnest-cross-chain
```

### 2. Install Dependencies

This project uses `yarn` to manage dependencies

```bash
yarn install
```

## Usage

### Build

To build the project, use the following command. This will compile all Solidity contracts:

```bash
yarn build
```

### Compile

You can compile contracts using Foundry's `forge`:

```bash
forge compile
```

### Test

Run the tests with the following command:

```bash
yarn test
```

### Lint

To lint Solidity files using `solhint`, run:

```bash
yarn lint
```

This will check all Solidity files in the `src/`, `test/`, and `scripts/` directories for issues, adhering to the project's `solhint` configuration.

### Format

You can format your Solidity code using:

```bash
yarn format
```

### Scripts

For most users, it is recommended to use the `yarn deploy` command (outlined in the following section), as it simplifies the deployment process and ensures all necessary configurations are handled across multiple chains. Running the Forge scripts manually should only be done if you have a deep understanding of the deployment steps.

However, if you need to run a script manually (e.g., `DeployL1OFTAdapter`), you can use the following command pattern:

```bash
forge script script/DeployL1OFTAdapter.s.sol:DeployL1OFTAdapter \
--rpc-url ${rpc} --sig "run(string calldata)" ${path} \
--account ${deployerAccountName} --sender ${deployer} \
--broadcast --etherscan-api-key ${api} --verify
```

Replace `DeployL1OFTAdapter` with the relevant contract name for other scripts if needed. But again, for ease and accuracy, the `yarn deploy` command is recommended.

### Deployment

To deploy Yieldnest tokens to new chains, you can use the `yarn deploy` command, which runs the `script/deploy.sh` script. This script accepts an input JSON file that specifies the token and chain configurations for deployment.

For example, to deploy the `ynETH` token to the specified networks, use the following command:

```bash
yarn deploy script/inputs/mainnet-ynETH.json
```

You can find template JSON files for reference in the `script/inputs/` directory. Below is an example of a typical input file:

```json
{
"erc20Name": "ynETH",
"erc20Symbol": "ynETH",
"l1ChainId": 1,
"l2ChainIds": [
10,
8453
],
"l1ERC20Address": "0x09db87A538BD693E9d08544577d5cCfAA6373A48",
"rateLimitConfig": {
"limit": "100000000000000000000",
"window": "86400"
}
}
```

This script will deploy all the necessary contracts across the chains specified in the JSON file, including both the Layer 1 and all Layer 2 chains.

### Adding a New L2 Chain

To add a new L2 chain to an existing deployment, follow these steps using Morph Testnet as an example:

1. Update the `BaseData.s.sol` file:
- Add the new testnet chain's ID to the `ChainIds` struct:
```solidity
struct ChainIds {
// ... existing chain IDs
uint256 morphTestnet;
}
```
- Initialize the new testnet chain ID in the `__chainIds` variable:
```solidity
__chainIds = ChainIds({
// ... existing chain IDs
morphTestnet: 2810
});
```
- Add the testnet chain-specific data to the `setUp()` function:
```solidity
__chainIdToData[__chainIds.morphTestnet] = Data({
OFT_OWNER: TEMP_GNOSIS_SAFE,
TOKEN_ADMIN: TEMP_GNOSIS_SAFE,
PROXY_ADMIN: TEMP_PROXY_CONTROLLER,
LZ_ENDPOINT: 0x1a44076050125825900e736c501f859c50fE728c,
LZ_EID: 30210 // LayerZero Endpoint ID for Morph Testnet
});
```

2. Update the deployment input JSON file for testnets (e.g., `script/inputs/holesky-ynETH.json`):
- Add the new testnet chain ID to the `l2ChainIds` array:
```json
{
"l2ChainIds": [
2522,
2810
],
// ... other existing configuration
}
```

3. Add the new testnet chain's RPC URL to the `.env` file:
```
MORPH_TESTNET_RPC_URL=https://rpc-testnet.morphl2.io
```

4. Update the `foundry.toml` file to include the new testnet RPC endpoint:
```toml
[rpc_endpoints]
morph_testnet = "${MORPH_TESTNET_RPC_URL}"
```

5. Run the deployment script for the testnet environment:
```bash
yarn deploy script/inputs/holesky-ynETH.json
```

This will deploy the necessary contracts on the new Morph Testnet chain and update the existing contracts on other testnet chains to recognize the new L2 testnet.

6. After deployment, verify that the new testnet chain has been properly added:
- Check that the L2YnOFTAdapter on Morph Testnet has the correct peers set for all other testnet chains.
- Verify that all other L2YnOFTAdapters and the L1YnOFTAdapter on testnets have been updated to include Morph Testnet as a peer.

7. Update any front-end applications or scripts to include support for the new Morph Testnet chain, such as adding it to the list of supported testnet networks and including its contract addresses.

By following these steps, you can successfully add Morph Testnet (or any other new L2 testnet chain) to your existing multi-chain testnet deployment.

### Gas Snapshots

To generate gas usage reports for the contracts, run:

```bash
forge snapshot
```

## Project Structure

- `src/`: Contains the core smart contracts for the project.
- `script/`: Contains deployment scripts for the contracts.
- `test/`: Contains tests for the contracts, utilizing Forge.
- `deployments/`: Contains deployment artifacts and configuration files for different environments.
- `foundry.toml`: Foundry configuration file.
- `package.json`: Yarn configuration file for managing dependencies.
- `remappings.txt`: Foundry remappings for import resolution.

## Linting

This project uses `husky` for Git hooks and `forge fmt` for Solidity file formatting. Pre-commit hooks are set up using `lint-staged` to automatically format `.sol` files on commit.

In addition, `solhint` is used to lint Solidity files. You can run `yarn lint` to manually check the code for common issues and enforce style guidelines.

## Documentation

For more information on Foundry and how to use it, please refer to the [Foundry Book](https://book.getfoundry.sh/).

## License

This project is licensed under the MIT License.
Loading