Skip to content

Commit 713a707

Browse files
committed
wip: no compiler version available
1 parent 77b4006 commit 713a707

17 files changed

Lines changed: 1504 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
env:
9+
FOUNDRY_PROFILE: ci
10+
11+
jobs:
12+
check:
13+
strategy:
14+
fail-fast: true
15+
16+
name: Foundry project
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
submodules: recursive
22+
23+
- name: Install Foundry
24+
uses: foundry-rs/foundry-toolchain@v1
25+
with:
26+
version: nightly
27+
28+
- name: Show Forge version
29+
run: |
30+
forge --version
31+
32+
- name: Run Forge fmt
33+
run: |
34+
forge fmt --check
35+
id: fmt
36+
37+
- name: Run Forge build
38+
run: |
39+
forge build --sizes
40+
id: build
41+
42+
- name: Run Forge tests
43+
run: |
44+
forge test -vvv
45+
id: test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
wallets/
33
.env
4+
lib/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "core/src/contracts/lib/forge-std"]
22
path = core/src/contracts/lib/forge-std
33
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/forge-std"]
5+
path = lib/forge-std
6+
url = https://github.com/foundry-rs/forge-std

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## Foundry
2+
3+
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
4+
5+
Foundry consists of:
6+
7+
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
8+
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
9+
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
10+
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
11+
12+
## Documentation
13+
14+
https://book.getfoundry.sh/
15+
16+
## Usage
17+
18+
### Build
19+
20+
```shell
21+
$ forge build
22+
```
23+
24+
### Test
25+
26+
```shell
27+
$ forge test
28+
```
29+
30+
### Format
31+
32+
```shell
33+
$ forge fmt
34+
```
35+
36+
### Gas Snapshots
37+
38+
```shell
39+
$ forge snapshot
40+
```
41+
42+
### Anvil
43+
44+
```shell
45+
$ anvil
46+
```
47+
48+
### Deploy
49+
50+
```shell
51+
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
52+
```
53+
54+
### Cast
55+
56+
```shell
57+
$ cast <subcommand>
58+
```
59+
60+
### Help
61+
62+
```shell
63+
$ forge --help
64+
$ anvil --help
65+
$ cast --help
66+
```

cli/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::{Parser, Subcommand};
2+
use core::compiler::compile_contract;
23
use core::{client, deployer};
34
use ethers::providers::{Http, Middleware, Provider};
45
use ethers::signers::Signer;
@@ -30,6 +31,7 @@ enum Commands {
3031
password: Option<String>,
3132
contract: String,
3233
},
34+
Compile,
3335
}
3436

3537
#[derive(Subcommand)]
@@ -113,6 +115,13 @@ async fn main() -> anyhow::Result<()> {
113115
let addr = deployer::deploy_contract(&contract, provider, wallet).await?;
114116
println!("Deployed `{}` at {}\n", contract, addr);
115117
}
118+
Commands::Compile => {
119+
println!("Compiling contract...");
120+
match compile_contract() {
121+
Ok(_) => println!("Compilation complete"),
122+
Err(e) => println!("Compilation failed: {}", e),
123+
};
124+
}
116125
}
117126

118127
Ok(())

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ serde = { version = "1", features = ["derive"] }
99
serde_json = "1"
1010
anyhow = "1"
1111
tokio = { version = "1", features = ["full"] }
12-
foundry-compilers = "0.10"
12+
foundry-compilers = "0.10.1"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_format":"","paths":{"artifacts":"artifacts","build_infos":"artifacts/build-info","sources":"contracts","tests":"test","scripts":"script","libraries":["node_modules"]},"files":{},"builds":[]}

core/src/compiler.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::path::{Path, PathBuf};
2+
3+
use foundry_compilers::{solc::Solc, Project, ProjectPathsConfig};
4+
5+
pub fn compile_contract() -> Result<(), anyhow::Error> {
6+
// configure the project with all its paths, solc, cache etc.
7+
let project = Project::builder()
8+
.paths(
9+
ProjectPathsConfig::hardhat(
10+
&Path::new(env!("CARGO_MANIFEST_DIR"))
11+
.to_owned()
12+
.join(PathBuf::from("src/contracts")),
13+
)
14+
.unwrap(),
15+
)
16+
.build(Default::default())
17+
.unwrap();
18+
// https://github.com/foundry-rs/compilers/blob/main/crates/compilers/tests/project.rs#L2627
19+
20+
println!("{:?}", project);
21+
let output = project.compile().unwrap();
22+
23+
println!("{:?}\n", output);
24+
Ok(())
25+
}

core/src/contracts/foundry.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ src = "src"
33
out = "out"
44
libs = ["lib"]
55

6-
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
6+
solc = "0.8.22"
7+
8+
remappings = ['@layerzerolabs/=node_modules/@layerzerolabs/']

core/src/contracts/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "contracts",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"@layerzerolabs/lz-evm-protocol-v2": "^3.0.83",
14+
"@layerzerolabs/oapp-evm": "^0.3.2",
15+
"install": "^0.13.0",
16+
"pnpm": "^10.7.0"
17+
}
18+
}

0 commit comments

Comments
 (0)