-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from lukso-network/master
Delete `master` branch and to use `main` as base
- Loading branch information
Showing
16 changed files
with
269 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,205 +1,189 @@ | ||
# Foundry Template [![Open in Gitpod][gitpod-badge]][gitpod] [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license] | ||
# Hyperlane LSP7 version - `HypLSP7` [![Open in Gitpod][gitpod-badge]][gitpod] [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license] | ||
|
||
[gitpod]: https://gitpod.io/#https://github.com/PaulRBerg/foundry-template | ||
[gitpod]: https://gitpod.io/#https://github.com/lukso-network/lsp-bridge-HypLSP7 | ||
[gitpod-badge]: https://img.shields.io/badge/Gitpod-Open%20in%20Gitpod-FFB45B?logo=gitpod | ||
[gha]: https://github.com/PaulRBerg/foundry-template/actions | ||
[gha-badge]: https://github.com/PaulRBerg/foundry-template/actions/workflows/ci.yml/badge.svg | ||
[gha]: https://github.com/lukso-network/lsp-bridge-HypLSP7/actions | ||
[gha-badge]: https://github.com/lukso-network/lsp-bridge-HypLSP7/actions/workflows/ci.yml/badge.svg | ||
[foundry]: https://getfoundry.sh/ | ||
[foundry-badge]: https://img.shields.io/badge/Built%20with-Foundry-FFDB1C.svg | ||
[license]: https://opensource.org/licenses/MIT | ||
[license-badge]: https://img.shields.io/badge/License-MIT-blue.svg | ||
|
||
A Foundry-based template for developing Solidity smart contracts, with sensible defaults. | ||
## Architecture & Workflow | ||
|
||
## What's Inside | ||
The flow for bridging tokens is generally as follow: | ||
|
||
- [Forge](https://github.com/foundry-rs/foundry/blob/master/forge): compile, test, fuzz, format, and deploy smart | ||
contracts | ||
- [Forge Std](https://github.com/foundry-rs/forge-std): collection of helpful contracts and utilities for testing | ||
- [Prettier](https://github.com/prettier/prettier): code formatter for non-Solidity files | ||
- [Solhint](https://github.com/protofire/solhint): linter for Solidity code | ||
- if the token is originally from ETH, the token is locked on ETHEREUM, and minted on LUKSO. | ||
- if the token is originally from LUKSO, the token is burnt on LUKSO, minted on ETHEREUM. | ||
|
||
## Getting Started | ||
### Ethereum -> LUKSO | ||
|
||
Click the [`Use this template`](https://github.com/PaulRBerg/foundry-template/generate) button at the top of the page to | ||
create a new repository with this repo as the initial state. | ||
![Ethereum to LUKSO bridge flow](./assets/flow-ethereum-lukso-hashi-bridge.png) | ||
|
||
Or, if you prefer to install the template manually: | ||
|
||
```sh | ||
$ mkdir my-project | ||
$ cd my-project | ||
$ forge init --template PaulRBerg/foundry-template | ||
$ bun install # install Solhint, Prettier, and other Node.js deps | ||
``` | ||
**on Ethereum chain** | ||
|
||
If this is your first time with Foundry, check out the | ||
[installation](https://github.com/foundry-rs/foundry#installation) instructions. | ||
1. User transfer ERC20 tokens to [`HypERC20Collateral`]. This locks the tokens in the collateral contract. | ||
2. `HypERC20Collateral` contract call [`Mailbox`] to pass the message. | ||
3. The `Mailbox` calls: | ||
3.1. the default Hook (created by Hyperlane), | ||
3.2. and the Hashi Hook (created by CCIA team). | ||
4. Hashi Hook dispatch the token relaying message from `Yaho` contracts. | ||
|
||
## Features | ||
> In the architecture diagram above: | ||
> - The `Yaho` contracts handle the dispatching and batching of messages across chains. | ||
> - The `Yaru` contracts ensures that the messages are properly executed on the destination chain by calling relevant functions like `onMessage`. | ||
This template builds upon the frameworks and libraries mentioned above, so please consult their respective documentation | ||
for details about their specific features. | ||
|
||
For example, if you're interested in exploring Foundry in more detail, you should look at the | ||
[Foundry Book](https://book.getfoundry.sh/). In particular, you may be interested in reading the | ||
[Writing Tests](https://book.getfoundry.sh/forge/writing-tests.html) tutorial. | ||
|
||
### Sensible Defaults | ||
**Off chain** | ||
|
||
This template comes with a set of sensible default configurations for you to use. These defaults can be found in the | ||
following files: | ||
5. Hashi relayer (managed by CCIA team) listen for events from `Yaho` contracts and request the reporter contracts to relay token relaying message. | ||
6. Hashi executor (managed by CCIA team) listen to event from each Hashi adapter contracts and call `Yaru.executeMessages`. **This step checks whether the Hashi adapters agree on a specify message id** (a threshold number of hash is stored), and set the message Id to verified status. | ||
7. Validator (run by Hyperlane & LUKSO team) will sign the Merkle root when new dispatches happen in Mailbox. | ||
8. Hyperlane relayer (run by Hyperlane team) relays the message by calling Mailbox.process(). | ||
|
||
```text | ||
├── .editorconfig | ||
├── .gitignore | ||
├── .prettierignore | ||
├── .prettierrc.yml | ||
├── .solhint.json | ||
├── foundry.toml | ||
└── remappings.txt | ||
``` | ||
**on LUKSO chain** | ||
|
||
### VSCode Integration | ||
8. When [`Mailbox.process(...)`](https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/3d116132b87d36af9576d6b116f31a53d680db4a/solidity/contracts/Mailbox.sol#L188-L197) is called, it will: | ||
8.1. check with Multisig ISM (includes Hashi ISM), whether the message is signed by validators & verified by Hashi ISM. | ||
8.2. If so, it will mint [HypLSP7](./src/HypLSP7.sol) tokens to the receiver. | ||
|
||
This template is IDE agnostic, but for the best user experience, you may want to use it in VSCode alongside Nomic | ||
Foundation's [Solidity extension](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity). | ||
|
||
For guidance on how to integrate a Foundry project in VSCode, please refer to this | ||
[guide](https://book.getfoundry.sh/config/vscode). | ||
### LUKSO -> Ethereum | ||
|
||
### GitHub Actions | ||
![LUKSO to Ethereum bridge flow](./assets/flow-lukso-ethereum-hashi-bridge.png) | ||
|
||
This template comes with GitHub Actions pre-configured. Your contracts will be linted and tested on every push and pull | ||
request made to the `main` branch. | ||
**on LUKSO chain** | ||
|
||
You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml). | ||
> _Step 1 to 3 needs to be confirmed_ | ||
## Installing Dependencies | ||
1. User transfer LSP7 token to HypLSP7 contract and the tokens are burnt. | ||
2. HypLSP7 contract calls `Mailbox` to pass the message. | ||
3. `Mailbox` calls Default Hook (created by Hyperlane) and Hashi Hook (created by CCIA team). | ||
4. Hashi Hook dispatch the token relaying message from Yaho contracts. | ||
|
||
Foundry typically uses git submodules to manage dependencies, but this template uses Node.js packages because | ||
[submodules don't scale](https://twitter.com/PaulRBerg/status/1736695487057531328). | ||
**Off chain** | ||
|
||
This is how to install dependencies: | ||
4. Off chain process remains the same as before, _except there is no Light Client support for Hashi from LUKSO → Ethereum_. | ||
|
||
1. Install the dependency using your preferred package manager, e.g. `bun install dependency-name` | ||
- Use this syntax to install from GitHub: `bun install github:username/repo-name` | ||
2. Add a remapping for the dependency in [remappings.txt](./remappings.txt), e.g. | ||
`dependency-name=node_modules/dependency-name` | ||
**on Ethereum chain** | ||
|
||
Note that OpenZeppelin Contracts is pre-installed, so you can follow that as an example. | ||
5. When `Mailbox.process()` is called: | ||
5.1. it will check with Multisig ISM (includes Hashi ISM), whether the message is signed by validators & verified by Hashi ISM. | ||
5.2. If so, it will unlock ERC20 token to the receiver on the Ethereum chain. | ||
|
||
## Writing Tests | ||
|
||
To write a new test contract, you start by importing `Test` from `forge-std`, and then you inherit it in your test | ||
contract. Forge Std comes with a pre-instantiated [cheatcodes](https://book.getfoundry.sh/cheatcodes/) environment | ||
accessible via the `vm` property. If you would like to view the logs in the terminal output, you can add the `-vvv` flag | ||
and use [console.log](https://book.getfoundry.sh/faq?highlight=console.log#how-do-i-use-consolelog). | ||
|
||
This template comes with an example test contract [Foo.t.sol](./test/Foo.t.sol) | ||
### Examples of bridged tokens | ||
|
||
## Usage | ||
- ETH -> LUKSO: https://explorer.hyperlane.xyz/message/0x53a383e32fdb68748c8af5c86be3669e58eadc377db2a9f420826cb9474dd55c | ||
|
||
This is a list of the most frequently needed commands. | ||
- LUKSO -> ETH: https://explorer.hyperlane.xyz/message/0xf9c86a22e7b5584fc87a9d4ffc39f967a8745cd28b98ed2eaeb220c43996c4ca | ||
|
||
### Build | ||
|
||
Build the contracts: | ||
### Relevant links & resources | ||
|
||
```sh | ||
$ forge build | ||
``` | ||
- [Cross Chain Alliance - Hashi](https://crosschain-alliance.gitbook.io/hashi) | ||
- [Hyperlane smart contracts monorepo](https://github.com/hyperlane-xyz/hyperlane-monorepo) | ||
|
||
### Clean | ||
## Getting Started | ||
|
||
Delete the build artifacts and cache directories: | ||
This project is based on the Foundry template by PaulRBerg. | ||
|
||
```sh | ||
$ forge clean | ||
bun install # install Solhint, Prettier, and other Node.js deps | ||
``` | ||
|
||
### Compile | ||
If this is your first time with Foundry, check out the | ||
[installation](https://github.com/foundry-rs/foundry#installation) instructions. | ||
|
||
Compile the contracts: | ||
### Installing Dependencies | ||
|
||
```sh | ||
$ forge build | ||
``` | ||
Foundry typically uses git submodules to manage dependencies, but this template uses Node.js packages because | ||
[submodules don't scale](https://twitter.com/PaulRBerg/status/1736695487057531328). | ||
|
||
### Coverage | ||
This is how to install dependencies: | ||
|
||
Get a test coverage report: | ||
1. Install the dependency using your preferred package manager, e.g. `bun install dependency-name` | ||
- Use this syntax to install from GitHub: `bun install github:username/repo-name` | ||
2. Add a remapping for the dependency in [remappings.txt](./remappings.txt), e.g. | ||
`dependency-name=node_modules/dependency-name` | ||
|
||
```sh | ||
$ forge coverage | ||
``` | ||
Note that OpenZeppelin Contracts is pre-installed, so you can follow that as an example. | ||
|
||
### Deploy | ||
|
||
Deploy to Anvil: | ||
|
||
```sh | ||
$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545 | ||
### Sensible Defaults | ||
|
||
This template comes with a set of sensible default configurations for you to use. These defaults can be found in the | ||
following files: | ||
|
||
```text | ||
├── .editorconfig | ||
├── .gitignore | ||
├── .prettierignore | ||
├── .prettierrc.yml | ||
├── .solhint.json | ||
├── foundry.toml | ||
└── remappings.txt | ||
``` | ||
|
||
For this script to work, you need to have a `MNEMONIC` environment variable set to a valid | ||
[BIP39 mnemonic](https://iancoleman.io/bip39/). | ||
|
||
For instructions on how to deploy to a testnet or mainnet, check out the | ||
[Solidity Scripting](https://book.getfoundry.sh/tutorials/solidity-scripting.html) tutorial. | ||
|
||
### Format | ||
|
||
Format the contracts: | ||
## Usage | ||
|
||
```sh | ||
$ forge fmt | ||
``` | ||
This is a list of the most frequently needed commands. | ||
|
||
### Gas Usage | ||
### Build & Compile | ||
|
||
Get a gas report: | ||
|
||
```sh | ||
$ forge test --gas-report | ||
``` | ||
# Build the contracts: | ||
forge build | ||
|
||
### Lint | ||
# Delete the build artifacts and cache directories: | ||
forge clean | ||
|
||
Lint the contracts: | ||
# Get a test coverage report: | ||
forge coverage | ||
|
||
```sh | ||
$ bun run lint | ||
``` | ||
# Format the contracts: | ||
forge fmt | ||
|
||
### Test | ||
# Get a gas report: | ||
forge test --gas-report | ||
|
||
Run the tests: | ||
# Lint the contracts: | ||
bun run lint | ||
|
||
```sh | ||
$ forge test | ||
``` | ||
# Run the tests: | ||
forge test | ||
|
||
Generate test coverage and output result to the terminal: | ||
# Generate test coverage and output result to the terminal: | ||
bun run test:coverage | ||
|
||
```sh | ||
$ bun run test:coverage | ||
# Generate test coverage with lcov report (you'll have to open the `./coverage/index.html` file in your browser, | ||
# to do so simply copy paste the path): | ||
bun run test:coverage:report | ||
``` | ||
|
||
Generate test coverage with lcov report (you'll have to open the `./coverage/index.html` file in your browser, to do so | ||
simply copy paste the path): | ||
### GitHub Actions | ||
|
||
```sh | ||
$ bun run test:coverage:report | ||
``` | ||
This repository uses pre-configured GitHub Actions. The contracts are linted and tested on every push and pull requests. | ||
|
||
You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml). | ||
|
||
## Related Efforts | ||
|
||
- [abigger87/femplate](https://github.com/abigger87/femplate) | ||
- [cleanunicorn/ethereum-smartcontract-template](https://github.com/cleanunicorn/ethereum-smartcontract-template) | ||
- [foundry-rs/forge-template](https://github.com/foundry-rs/forge-template) | ||
- [FrankieIsLost/forge-template](https://github.com/FrankieIsLost/forge-template) | ||
## Foundry Resources | ||
|
||
This template builds upon the frameworks and libraries mentioned above, so please consult their respective documentation for details about their specific features. | ||
|
||
For example, if you're interested in exploring Foundry in more detail, you should look at the | ||
[Foundry Book](https://book.getfoundry.sh/). In particular, you may be interested in reading the | ||
[Writing Tests](https://book.getfoundry.sh/forge/writing-tests.html) tutorial. | ||
|
||
## License | ||
|
||
This project is licensed under MIT. | ||
[`HypERC20Collateral`]: https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/%40hyperlane-xyz/core%405.2.0/solidity/contracts/token/HypERC20Collateral.sol | ||
[`Mailbox`]: https://github.com/hyperlane-xyz/hyperlane-monorepo/blob/%40hyperlane-xyz/core%405.2.0/solidity/contracts/Mailbox.sol |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/ | ||
@/=node_modules/@ | ||
forge-std/=node_modules/forge-std/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.25 <0.9.0; | ||
|
||
import { Foo } from "../src/Foo.sol"; | ||
|
||
import { BaseScript } from "./Base.s.sol"; | ||
|
||
/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting | ||
contract Deploy is BaseScript { | ||
function run() public broadcast returns (Foo foo) { | ||
foo = new Foo(); | ||
} | ||
// function run() public broadcast returns (Foo foo) { | ||
// foo = new Foo(); | ||
// } | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.