-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
282 additions
and
317 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 |
---|---|---|
@@ -1,11 +1,3 @@ | ||
export API_KEY_ALCHEMY="YOUR_API_KEY_ALCHEMY" | ||
export API_KEY_ARBISCAN="YOUR_API_KEY_ARBISCAN" | ||
export API_KEY_BSCSCAN="YOUR_API_KEY_BSCSCAN" | ||
export API_KEY_ETHERSCAN="YOUR_API_KEY_ETHERSCAN" | ||
export API_KEY_GNOSISSCAN="YOUR_API_KEY_GNOSISSCAN" | ||
export API_KEY_INFURA="YOUR_API_KEY_INFURA" | ||
export API_KEY_OPTIMISTIC_ETHERSCAN="YOUR_API_KEY_OPTIMISTIC_ETHERSCAN" | ||
export API_KEY_POLYGONSCAN="YOUR_API_KEY_POLYGONSCAN" | ||
export API_KEY_SNOWTRACE="YOUR_API_KEY_SNOWTRACE" | ||
export MNEMONIC="YOUR_MNEMONIC" | ||
export FOUNDRY_PROFILE="default" |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -10,7 +10,6 @@ out | |
*.log | ||
.DS_Store | ||
.pnp.* | ||
bun.lockb | ||
lcov.info | ||
package-lock.json | ||
pnpm-lock.yaml | ||
|
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,9 +1,10 @@ | ||
{ | ||
"[solidity]": { | ||
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity" | ||
"editor.defaultFormatter": "JuanBlanco.solidity" | ||
}, | ||
"[toml]": { | ||
"editor.defaultFormatter": "tamasfe.even-better-toml" | ||
}, | ||
"solidity.formatter": "forge" | ||
} | ||
"solidity.formatter": "forge", | ||
"solidity.compileUsingRemoteVersion": "v0.8.25+commit.b61c2a91" | ||
} |
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,96 @@ | ||
# Foundry Template [![Open in Gitpod][gitpod-badge]][gitpod] [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] [![License: MIT][license-badge]][license] | ||
# Token Vendor Machine Challenge | ||
|
||
[gitpod]: https://gitpod.io/#https://github.com/PaulRBerg/foundry-template | ||
[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 | ||
[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 | ||
This project is designed to test your skills in smart contract development using Solidity. | ||
|
||
A Foundry-based template for developing Solidity smart contracts, with sensible defaults. | ||
## Project Overview | ||
|
||
## What's Inside | ||
You are tasked with implementing a token vendor machine that allows users to buy and sell tokens. The project consists of two main contracts: | ||
|
||
- [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 | ||
1. `BlockfulToken.sol`: An ERC20 token contract | ||
2. `TokenVendor.sol`: A vendor contract for buying and selling tokens | ||
|
||
## Getting Started | ||
|
||
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. | ||
To get started with this project, follow these steps: | ||
|
||
Or, if you prefer to install the template manually: | ||
1. Clone this repository. | ||
2. Run `npm install` to install Node.js dependencies | ||
|
||
```sh | ||
$ mkdir my-project | ||
$ cd my-project | ||
$ forge init --template PaulRBerg/foundry-template | ||
$ bun install # install Solhint, Prettier, and other Node.js deps | ||
``` | ||
|
||
If this is your first time with Foundry, check out the | ||
[installation](https://github.com/foundry-rs/foundry#installation) instructions. | ||
|
||
## Features | ||
|
||
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 | ||
|
||
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 | ||
``` | ||
|
||
### VSCode Integration | ||
|
||
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). | ||
|
||
### GitHub Actions | ||
|
||
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. | ||
## Your Tasks | ||
|
||
You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml). | ||
1. Implement the `BlockfulToken` contract: | ||
- It should be an ERC20 token with a name, symbol, and 18 decimals. | ||
- Initial supply should be 1,000,000 tokens. | ||
|
||
## Installing Dependencies | ||
2. Implement the `TokenVendor` contract with the following functionality: | ||
- Allow users to buy tokens with ETH (1 ETH = 100 tokens) | ||
- Allow users to sell tokens back to the contract | ||
- Allow the owner to withdraw ETH from the contract | ||
- Implement proper access control (only owner can withdraw) | ||
- Emit events for token purchases, sales, and ETH withdrawals | ||
|
||
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). | ||
3. Complete the test file `test/TokenVendor.t.sol`: | ||
- We've provided some basic "happy path" tests | ||
- Implement additional tests for edge cases and potential failure scenarios | ||
- Aim for at least 90% test coverage | ||
|
||
This is how to install dependencies: | ||
4. Update this README with: | ||
- Any additional setup or testing instructions | ||
- An explanation of your design decisions | ||
- Any potential improvements or considerations for a real-world deployment | ||
|
||
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` | ||
## Bonus Tasks | ||
|
||
Note that OpenZeppelin Contracts is pre-installed, so you can follow that as an example. | ||
If you complete the main tasks and want to demonstrate more advanced skills: | ||
|
||
## 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) | ||
1. Implement a simple dynamic pricing mechanism (e.g., price increases as supply decreases) | ||
2. Add a feature to pause/unpause the contract (owner only) | ||
3. Implement a whitelist system for early access to token sales | ||
|
||
## Usage | ||
|
||
This is a list of the most frequently needed commands. | ||
Here are some common commands you'll need: | ||
|
||
### Build | ||
|
||
Build the contracts: | ||
|
||
```sh | ||
$ forge build | ||
``` | ||
|
||
### Clean | ||
|
||
Delete the build artifacts and cache directories: | ||
|
||
```sh | ||
$ forge clean | ||
npm run build | ||
``` | ||
|
||
### Compile | ||
|
||
Compile the contracts: | ||
### Test | ||
|
||
```sh | ||
$ forge build | ||
npm run test | ||
``` | ||
|
||
### Coverage | ||
|
||
Get a test coverage report: | ||
|
||
```sh | ||
$ forge coverage | ||
npm run test:coverage | ||
``` | ||
|
||
### Deploy | ||
## Evaluation Criteria | ||
|
||
Deploy to Anvil: | ||
|
||
```sh | ||
$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545 | ||
``` | ||
Your submission will be evaluated based on: | ||
|
||
For this script to work, you need to have a `MNEMONIC` environment variable set to a valid | ||
[BIP39 mnemonic](https://iancoleman.io/bip39/). | ||
- Correctness of the implementation | ||
- Code quality and organization | ||
- Test coverage and quality | ||
- Security considerations | ||
- Testnet deployment | ||
- Documentation and comments | ||
- (For bonus tasks) Creativity and effectiveness of additional features | ||
|
||
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. | ||
## Submission | ||
|
||
### Format | ||
|
||
Format the contracts: | ||
|
||
```sh | ||
$ forge fmt | ||
``` | ||
|
||
### Gas Usage | ||
|
||
Get a gas report: | ||
|
||
```sh | ||
$ forge test --gas-report | ||
``` | ||
|
||
### Lint | ||
|
||
Lint the contracts: | ||
|
||
```sh | ||
$ bun run lint | ||
``` | ||
|
||
### Test | ||
|
||
Run the tests: | ||
|
||
```sh | ||
$ forge test | ||
``` | ||
|
||
Generate test coverage and output result to the terminal: | ||
|
||
```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): | ||
|
||
```sh | ||
$ bun run test:coverage:report | ||
``` | ||
Please submit your completed project as a Git repository. Make sure to include: | ||
|
||
## Related Efforts | ||
- All source code files | ||
- Complete test suite | ||
- Updated README with your notes and explanations | ||
|
||
- [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) | ||
## Note | ||
|
||
## License | ||
This project uses [Foundry](https://getfoundry.sh/). If you're new to Foundry, check out the [Foundry Book](https://book.getfoundry.sh/) for detailed instructions and tutorials. | ||
|
||
This project is licensed under MIT. | ||
Good luck with the challenge! We're excited to see your implementation. |
Oops, something went wrong.