-
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
0 parents
commit e72af5c
Showing
19 changed files
with
654 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# EditorConfig http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# All files | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.sol] | ||
indent_size = 4 | ||
|
||
[*.tree] | ||
indent_size = 1 |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export API_KEY_ALCHEMY="YOUR_API_KEY_ALCHEMY" | ||
export API_KEY_ETHERSCAN="YOUR_API_KEY_ETHERSCAN" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
name: "CI" | ||
|
||
env: | ||
API_KEY_ALCHEMY: ${{ secrets.API_KEY_ALCHEMY }} | ||
FOUNDRY_PROFILE: "ci" | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- "main" | ||
|
||
jobs: | ||
lint: | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: "Check out the repo" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: "Install Foundry" | ||
uses: "foundry-rs/foundry-toolchain@v1" | ||
|
||
- name: Use Node.js 21 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 21 | ||
cache: 'npm' | ||
|
||
- name: "Install the Node.js dependencies" | ||
run: "npm install" | ||
|
||
- name: "Lint the code" | ||
run: "npm run lint" | ||
|
||
- name: "Add lint summary" | ||
run: | | ||
echo "## Lint result" >> $GITHUB_STEP_SUMMARY | ||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY | ||
build: | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: "Check out the repo" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: "Install Foundry" | ||
uses: "foundry-rs/foundry-toolchain@v1" | ||
|
||
- name: Use Node.js 21 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 21 | ||
cache: 'npm' | ||
|
||
- name: "Install the Node.js dependencies" | ||
run: "npm install" | ||
|
||
- name: "Build the contracts and print their size" | ||
run: "forge build --sizes" | ||
|
||
- name: "Add build summary" | ||
run: | | ||
echo "## Build result" >> $GITHUB_STEP_SUMMARY | ||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY | ||
test: | ||
needs: ["lint", "build"] | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: "Check out the repo" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: "Install Foundry" | ||
uses: "foundry-rs/foundry-toolchain@v1" | ||
|
||
- name: Use Node.js 21 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 21 | ||
cache: 'npm' | ||
|
||
- name: "Install the Node.js dependencies" | ||
run: "npm install" | ||
|
||
- name: "Show the Foundry config" | ||
run: "forge config" | ||
|
||
- name: "Generate a fuzz seed that changes weekly to avoid burning through RPC allowance" | ||
run: > | ||
echo "FOUNDRY_FUZZ_SEED=$( | ||
echo $(($EPOCHSECONDS - $EPOCHSECONDS % 604800)) | ||
)" >> $GITHUB_ENV | ||
- name: "Run the tests" | ||
run: "forge test" | ||
|
||
- name: "Add test summary" | ||
run: | | ||
echo "## Tests result" >> $GITHUB_STEP_SUMMARY | ||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: "Create" | ||
|
||
# The workflow will run when the "Use this template" button is used | ||
on: | ||
push: | ||
|
||
jobs: | ||
create: | ||
# We only run this action when the repository isn't the template repository. References: | ||
# - https://docs.github.com/en/actions/learn-github-actions/contexts | ||
# - https://docs.github.com/en/actions/learn-github-actions/expressions | ||
if: ${{ !github.event.repository.is_template }} | ||
permissions: "write-all" | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: "Check out the repo" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: "Update package.json" | ||
env: | ||
GITHUB_REPOSITORY_DESCRIPTION: ${{ github.event.repository.description }} | ||
run: | ||
./.github/scripts/rename.sh "$GITHUB_REPOSITORY" "$GITHUB_REPOSITORY_OWNER" "$GITHUB_REPOSITORY_DESCRIPTION" | ||
|
||
- name: "Add rename summary" | ||
run: | | ||
echo "## Commit result" >> $GITHUB_STEP_SUMMARY | ||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY | ||
- name: "Remove files not needed in the user's copy of the template" | ||
run: | | ||
rm -f "./.github/FUNDING.yml" | ||
rm -f "./.github/scripts/rename.sh" | ||
rm -f "./.github/workflows/create.yml" | ||
- name: "Add remove summary" | ||
run: | | ||
echo "## Remove result" >> $GITHUB_STEP_SUMMARY | ||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY | ||
- name: "Update commit" | ||
uses: "stefanzweifel/git-auto-commit-action@v4" | ||
with: | ||
commit_message: "feat: initial commit" | ||
commit_options: "--amend" | ||
push_options: "--force" | ||
skip_fetch: true | ||
|
||
- name: "Add commit summary" | ||
run: | | ||
echo "## Commit result" >> $GITHUB_STEP_SUMMARY | ||
echo "✅ Passed" >> $GITHUB_STEP_SUMMARY |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# directories | ||
cache | ||
coverage | ||
node_modules | ||
out | ||
|
||
# files | ||
*.env | ||
*.log | ||
.DS_Store | ||
.pnp.* | ||
lcov.info | ||
package-lock.json | ||
pnpm-lock.yaml | ||
yarn.lock | ||
|
||
# broadcasts | ||
!broadcast | ||
broadcast/* | ||
broadcast/*/31337/ |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# directories | ||
broadcast | ||
cache | ||
coverage | ||
node_modules | ||
out | ||
|
||
# files | ||
*.env | ||
*.log | ||
.DS_Store | ||
.pnp.* | ||
lcov.info | ||
package-lock.json | ||
pnpm-lock.yaml | ||
yarn.lock |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
bracketSpacing: true | ||
printWidth: 120 | ||
proseWrap: "always" | ||
singleQuote: false | ||
tabWidth: 2 | ||
trailingComma: "all" | ||
useTabs: false |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "solhint:recommended", | ||
"rules": { | ||
"code-complexity": ["error", 8], | ||
"compiler-version": ["error", ">=0.8.25"], | ||
"func-name-mixedcase": "off", | ||
"func-visibility": ["error", { "ignoreConstructors": true }], | ||
"max-line-length": ["error", 120], | ||
"named-parameters-mapping": "warn", | ||
"no-console": "off", | ||
"not-rely-on-time": "off", | ||
"one-contract-per-file": "off" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"[solidity]": { | ||
"editor.defaultFormatter": "JuanBlanco.solidity" | ||
}, | ||
"[toml]": { | ||
"editor.defaultFormatter": "tamasfe.even-better-toml" | ||
}, | ||
"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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Paul Razvan Berg | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit | ||
persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | ||
Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Token Vendor Machine Challenge | ||
|
||
This project is designed to test your skills in smart contract development using Solidity. | ||
|
||
## Project Overview | ||
|
||
You are tasked with implementing a token vendor machine that allows users to buy and sell tokens. The project consists of two main contracts: | ||
|
||
1. `BlockfulToken.sol`: An ERC20 token contract | ||
2. `TokenVendor.sol`: A vendor contract for buying and selling tokens | ||
|
||
## Getting Started | ||
|
||
To get started with this project, follow these steps: | ||
|
||
1. Clone this repository. | ||
2. Run `npm install` to install Node.js dependencies | ||
|
||
## Your Tasks | ||
|
||
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. | ||
|
||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
## Bonus Tasks | ||
|
||
If you complete the main tasks and want to demonstrate more advanced skills: | ||
|
||
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 | ||
|
||
Here are some common commands you'll need: | ||
|
||
### Build | ||
|
||
```sh | ||
npm run build | ||
``` | ||
|
||
### Test | ||
|
||
```sh | ||
npm run test | ||
``` | ||
|
||
### Coverage | ||
|
||
```sh | ||
npm run test:coverage | ||
``` | ||
|
||
## Evaluation Criteria | ||
|
||
Your submission will be evaluated based on: | ||
|
||
- 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 | ||
|
||
## Submission | ||
|
||
Please submit your completed project as a Git repository. Make sure to include: | ||
|
||
- All source code files | ||
- Complete test suite | ||
- Updated README with your notes and explanations | ||
|
||
## Note | ||
|
||
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. | ||
|
||
Good luck with the challenge! We're excited to see your implementation. |
Oops, something went wrong.