Skip to content

Commit d1b6b67

Browse files
committed
first commit
0 parents  commit d1b6b67

820 files changed

Lines changed: 219886 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

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

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
!/broadcast
7+
/broadcast/*/31337/
8+
/broadcast/**/dry-run/
9+
10+
# Docs
11+
docs/
12+
13+
# Dotenv file
14+
.env

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "lib/forge-std"]
2+
path = lib/forge-std
3+
url = https://github.com/foundry-rs/forge-std

.prettierrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"printWidth": 500,
3+
"tabWidth": 4,
4+
"overrides": [
5+
{
6+
"files": "*.sol",
7+
"options": {
8+
"printWidth": 500
9+
}
10+
}
11+
]
12+
}

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+
```

RootHashSwapERC20.sol

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import "../interfaces/IRootHashSwapERC20.sol";
5+
6+
contract RootHashSwapERC20 is IRootHashSwapERC20 {
7+
string public constant name = "RootHashSwap V2";
8+
string public constant symbol = "UNI-V2";
9+
uint8 public constant decimals = 18;
10+
uint256 public totalSupply;
11+
mapping(address => uint256) public balanceOf;
12+
mapping(address => mapping(address => uint256)) public allowance;
13+
14+
bytes32 public DOMAIN_SEPARATOR;
15+
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
16+
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
17+
mapping(address => uint256) public nonces;
18+
19+
constructor() {
20+
uint256 chainId;
21+
chainId = block.chainid;
22+
DOMAIN_SEPARATOR = keccak256(abi.encode(keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), keccak256(bytes(name)), keccak256(bytes("1")), chainId, address(this)));
23+
}
24+
25+
function _mint(address to, uint256 value) internal {
26+
totalSupply += value;
27+
balanceOf[to] += value;
28+
emit Transfer(address(0), to, value);
29+
}
30+
31+
function _burn(address from, uint256 value) internal {
32+
balanceOf[from] -= value;
33+
totalSupply -= value;
34+
emit Transfer(from, address(0), value);
35+
}
36+
37+
function _approve(address owner, address spender, uint256 value) private {
38+
allowance[owner][spender] = value;
39+
emit Approval(owner, spender, value);
40+
}
41+
42+
function _transfer(address from, address to, uint256 value) private {
43+
balanceOf[from] -= value;
44+
balanceOf[to] += value;
45+
emit Transfer(from, to, value);
46+
}
47+
48+
function approve(address spender, uint256 value) external returns (bool) {
49+
_approve(msg.sender, spender, value);
50+
return true;
51+
}
52+
53+
function transfer(address to, uint256 value) external returns (bool) {
54+
_transfer(msg.sender, to, value);
55+
return true;
56+
}
57+
58+
function transferFrom(address from, address to, uint256 value) external returns (bool) {
59+
if (allowance[from][msg.sender] != type(uint256).max) {
60+
allowance[from][msg.sender] -= value;
61+
}
62+
_transfer(from, to, value);
63+
return true;
64+
}
65+
66+
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external {
67+
require(deadline >= block.timestamp, "RootHashSwap: EXPIRED");
68+
bytes32 digest = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))));
69+
address recoveredAddress = ecrecover(digest, v, r, s);
70+
require(recoveredAddress != address(0) && recoveredAddress == owner, "RootHashSwap: INVALID_SIGNATURE");
71+
_approve(owner, spender, value);
72+
}
73+
}

foundry.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"lib/forge-std": {
3+
"tag": {
4+
"name": "v1.11.0",
5+
"rev": "8e40513d678f392f398620b3ef2b418648b33e89"
6+
}
7+
}
8+
}

foundry.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[profile.default]
2+
src = "src"
3+
out = "out"
4+
libs = ["lib"]
5+
6+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
7+
solc = "0.8.22"
8+
# https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
9+
ffi = true
10+
ast = true
11+
build_info = true
12+
extra_output = ["storageLayout"]
13+
fs_permissions = [{ access = "read-write", path = "./"}]
14+
15+
[rpc_endpoints]
16+
sepolia = "${SEPOLIA_RPC_URL}"
17+
18+
[fmt]
19+
line_length = 500
20+
tab_width = 4
21+

lib/forge-std

Submodule forge-std added at 8e40513

node_modules/.bin/prettier

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)