Skip to content

Commit bd99dde

Browse files
committed
Primeiro commit - Token ERC-20 com funcionalidades pausable e blacklist
0 parents  commit bd99dde

File tree

12 files changed

+278
-0
lines changed

12 files changed

+278
-0
lines changed

.github/workflows/test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
26+
- name: Show Forge version
27+
run: |
28+
forge --version
29+
30+
- name: Run Forge fmt
31+
run: |
32+
forge fmt --check
33+
id: fmt
34+
35+
- name: Run Forge build
36+
run: |
37+
forge build --sizes
38+
id: build
39+
40+
- name: Run Forge tests
41+
run: |
42+
forge test -vvv
43+
id: test

.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

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

foundry.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[profile.default]
2+
src = "src"
3+
out = "out"
4+
libs = ["lib"]
5+
6+
remappings = ["@openzeppelin/=lib/openzeppelin-contracts/contracts/"]
7+
8+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

lib/forge-std

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 77041d2ce690e692d6e03cc812b57d1ddaa4d505

lib/openzeppelin-contracts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit fd81a96f01cc42ef1c9a5399364968d0e07e9e90

remappings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@openzeppelin/=lib/openzeppelin-contracts/

script/Counter.s.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.13;
3+
4+
import {Script, console} from "forge-std/Script.sol";
5+
import {Counter} from "../src/Counter.sol";
6+
7+
contract CounterScript is Script {
8+
Counter public counter;
9+
10+
function setUp() public {}
11+
12+
function run() public {
13+
vm.startBroadcast();
14+
15+
counter = new Counter();
16+
17+
vm.stopBroadcast();
18+
}
19+
}

src/Counter.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.13;
3+
4+
contract Counter {
5+
uint256 public number;
6+
7+
function setNumber(uint256 newNumber) public {
8+
number = newNumber;
9+
}
10+
11+
function increment() public {
12+
number++;
13+
}
14+
}

src/MyToken.sol

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.13;
3+
4+
import "@openzeppelin/contracts/security/Pausable.sol";
5+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
6+
import "@openzeppelin/contracts/access/Ownable.sol";
7+
8+
contract MyToken is ERC20, Pausable, Ownable {
9+
mapping(address => bool) private blacklist;
10+
11+
constructor() ERC20("MyToken", "MTK") {
12+
_mint(msg.sender, 1000000 * 10 ** decimals());
13+
}
14+
15+
function pause() public onlyOwner {
16+
_pause();
17+
}
18+
19+
function unpause() public onlyOwner {
20+
_unpause();
21+
}
22+
23+
function addToBlacklist(address account) public onlyOwner {
24+
blacklist[account] = true;
25+
}
26+
27+
function removeFromBlacklist(address account) public onlyOwner {
28+
blacklist[account] = false;
29+
}
30+
31+
function isBlacklisted(address account) public view returns (bool) {
32+
return blacklist[account];
33+
}
34+
35+
function _beforeTokenTransfer(address from, address to, uint256 amount)
36+
internal
37+
override
38+
{
39+
require(!paused(), "Token: paused");
40+
require(!blacklist[from], "Sender is blacklisted");
41+
require(!blacklist[to], "Recipient is blacklisted");
42+
super._beforeTokenTransfer(from, to, amount);
43+
}
44+
}

0 commit comments

Comments
 (0)