Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeframLou authored Feb 3, 2023
0 parents commit af9881a
Show file tree
Hide file tree
Showing 14 changed files with 878 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Network and account info
RPC_URL_MAINNET=XXX
RPC_URL_GOERLI=XXX

PRIVATE_KEY=XXX

ETHERSCAN_KEY=XXX

# Deploy configs
VERSION="1.0.0"
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test

on: workflow_dispatch

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

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

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

- name: Run Forge tests
run: |
FOUNDRY_PROFILE=ci forge test -vvv
id: test
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Compiler files
cache/
out/

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

# Dotenv file
.env

.vscode
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/rari-capital/solmate
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/create3-factory"]
path = lib/create3-factory
url = https://github.com/zeframlou/create3-factory
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Foundry template

This is a template for a Foundry project.

## Installation

To install with [DappTools](https://github.com/dapphub/dapptools):

```
dapp install [user]/[repo]
```

To install with [Foundry](https://github.com/gakonst/foundry):

```
forge install [user]/[repo]
```

## Local development

This project uses [Foundry](https://github.com/gakonst/foundry) as the development framework.

### Dependencies

```
forge install
```

### Compilation

```
forge build
```

### Testing

```
forge test
```

### Contract deployment

Please create a `.env` file before deployment. An example can be found in `.env.example`.

#### Dryrun

```
forge script script/Deploy.s.sol -f [network]
```

### Live

```
forge script script/Deploy.s.sol -f [network] --verify --broadcast
```
16 changes: 16 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[profile.default]
optimizer_runs = 1000000
verbosity = 1

# Extreme Fuzzing CI Profile :P
[profile.ci]
fuzz_runs = 100_000
verbosity = 4

[rpc_endpoints]
goerli = "${RPC_URL_GOERLI}"
mainnet = "${RPC_URL_MAINNET}"

[etherscan]
goerli = {key = "${ETHERSCAN_KEY}", url = "https://api-goerli.etherscan.io/api"}
mainnet = {key = "${ETHERSCAN_KEY}"}
1 change: 1 addition & 0 deletions lib/create3-factory
Submodule create3-factory added at d68b7b
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at eb980e
1 change: 1 addition & 0 deletions lib/solmate
Submodule solmate added at 3a752b
26 changes: 26 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.13;

import {CREATE3Script} from "./base/CREATE3Script.sol";
import {Contract} from "../src/Contract.sol";

contract DeployScript is CREATE3Script {
constructor() CREATE3Script(vm.envString("VERSION")) {}

function run() external returns (Contract c) {
uint256 deployerPrivateKey = uint256(vm.envBytes32("PRIVATE_KEY"));

uint256 param = 123;

vm.startBroadcast(deployerPrivateKey);

c = Contract(
create3.deploy(
getCreate3ContractSalt("Contract"),
bytes.concat(type(Contract).creationCode, abi.encode(param))
)
);

vm.stopBroadcast();
}
}
27 changes: 27 additions & 0 deletions script/base/CREATE3Script.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.13;

import {CREATE3Factory} from "create3-factory/CREATE3Factory.sol";

import "forge-std/Script.sol";

abstract contract CREATE3Script is Script {
CREATE3Factory internal constant create3 = CREATE3Factory(0x9fBB3DF7C40Da2e5A0dE984fFE2CCB7C47cd0ABf);

string internal version;

constructor(string memory version_) {
version = version_;
}

function getCreate3Contract(string memory name) internal view virtual returns (address) {
uint256 deployerPrivateKey = uint256(vm.envBytes32("PRIVATE_KEY"));
address deployer = vm.addr(deployerPrivateKey);

return create3.getDeployed(deployer, getCreate3ContractSalt(name));
}

function getCreate3ContractSalt(string memory name) internal view virtual returns (bytes32) {
return keccak256(bytes(string.concat(name, "-v", version)));
}
}
10 changes: 10 additions & 0 deletions src/Contract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.4;

contract Contract {
uint256 public immutable param;

constructor(uint256 param_) {
param = param_;
}
}
14 changes: 14 additions & 0 deletions test/Contract.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.4;

import "forge-std/Test.sol";

contract ContractTest is Test {
function setUp() public {}

function testExample() public {
vm.startPrank(address(0xB0B));
console2.log("Hello world!");
assertTrue(true);
}
}

0 comments on commit af9881a

Please sign in to comment.