Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
968ba28
chore: init repo with template
Theo6890 Jan 12, 2023
758281f
docs: prettier on README
Theo6890 Jan 12, 2023
43d34d1
chore: exclude foundry from prettier
Theo6890 Jan 12, 2023
1a3a093
chore: delete `Token` contract from template
Theo6890 Jan 12, 2023
290b2b7
feat: define `ETHPool` attributes according to doc
Theo6890 Jan 12, 2023
783dd84
feat: use `Address` library from OZ
Theo6890 Jan 12, 2023
10500ba
feat: make `ETHPool` inherit from `Ownable`
Theo6890 Jan 12, 2023
1b34a9f
test: file to test `ETHPool`
Theo6890 Jan 12, 2023
dcb9678
test: default owner is the deployer
Theo6890 Jan 12, 2023
3bd1412
refactor: re-order variables and add comments to cut sections
Theo6890 Jan 12, 2023
8b08376
test: create a file to set up common attributes for `ETHPool`
Theo6890 Jan 12, 2023
0553457
refactor: `ETHPoolTest` only test `owner` with set up file
Theo6890 Jan 12, 2023
20dfc3b
feat: use a set to manage team members
Theo6890 Jan 12, 2023
bde2635
test: fixtures file for `Users` & `TeamMembers`
Theo6890 Jan 12, 2023
69ae9a4
feat: add team member with function call restriction
Theo6890 Jan 12, 2023
7675526
test: add team member, restrictions & event emittance
Theo6890 Jan 12, 2023
5a98f5e
feat: getter `_teamMembers.length()`
Theo6890 Jan 12, 2023
4d4ee7a
feat: getter `isTeamMember(...)`
Theo6890 Jan 12, 2023
1bf789b
feat: remove a team member
Theo6890 Jan 12, 2023
68bd8ee
test: remove team member, restrictions & event emittance
Theo6890 Jan 12, 2023
f1ffb9c
test: comment out Foundry's buggy tests
Theo6890 Jan 12, 2023
b08d20a
chore: add `@nomicfoundation/hardhat-foundry` package
Theo6890 Jan 12, 2023
ff7648c
chore: specify forge test path in .toml
Theo6890 Jan 12, 2023
7f43ee1
refactor: only use `msg.sender` in `canUpdateTeam`
Theo6890 Jan 12, 2023
5748406
test: file to for `canUpdateTeam` testing with Hardhat
Theo6890 Jan 12, 2023
e69b3b9
test: unverified user can't add a team member
Theo6890 Jan 12, 2023
790b5b1
test: unverified user can't remove a team member
Theo6890 Jan 12, 2023
96c4306
feat: require member absence/presence to update the set
Theo6890 Jan 12, 2023
36cde32
test(revert): when adding an existsing member
Theo6890 Jan 12, 2023
f2b8da2
test(revert): when removing non existent member
Theo6890 Jan 12, 2023
b92d42c
refactor: rename modifier `canUpdateTeam`
Theo6890 Jan 12, 2023
1be25a9
test: owner deposits rewards and RewardsDeposit emittance
Theo6890 Jan 12, 2023
8ff9135
feat: deposit rewards logic from owner or team
Theo6890 Jan 12, 2023
bb4e678
test(helper): wei & ether conversion
Theo6890 Jan 12, 2023
b7825d1
test: verifies deposit data including UsersDeposit
Theo6890 Jan 13, 2023
bc7d837
feat: implement deposit for dApp users
Theo6890 Jan 13, 2023
181d2de
refactor: group snapshot vars and update struct name
Theo6890 Jan 13, 2023
44d9175
refactor(test): variables names in depositRewards
Theo6890 Jan 13, 2023
9d0297d
test: add test on snapshotDeposits value in depositRewards
Theo6890 Jan 13, 2023
e7bb49c
test(revert): userDeposit fails on DEPOSIT_ONCE_WEEK
Theo6890 Jan 13, 2023
6e41636
test: verifies users can deposit again after 1 week
Theo6890 Jan 13, 2023
ab725f4
test: description of tests to add in depositRewards
Theo6890 Jan 13, 2023
e59c6ad
refactor: sperate contract `TeamManagement`
Theo6890 Jan 13, 2023
4d50db0
refactor: separate contract for `Rewards`
Theo6890 Jan 13, 2023
ed88a89
refactor: separate contract `UserData`
Theo6890 Jan 13, 2023
7ae417b
feat: pending rewards
Theo6890 Jan 13, 2023
32f6ad0
refactor: rename SnapshotReward last parameter
Theo6890 Jan 13, 2023
63c0f86
feat: get ether balance from using hardhat task
Theo6890 Jan 13, 2023
a64134f
test: pending rewards with multiple users
Theo6890 Jan 13, 2023
77b62da
chore: update deploy script with `ETHPool` contract
Theo6890 Jan 13, 2023
8acdcc0
chore: add goerli in apiKey
Theo6890 Jan 13, 2023
b555ac3
chore: add address to verify in `verify.js`
Theo6890 Jan 13, 2023
20812b1
docs: update README.md with results
Theo6890 Jan 13, 2023
21c9a6d
chore: use ETHPool address to retrieve its ETH balance
Theo6890 Jan 13, 2023
cd55635
fix: prototype only for `pendingRewards` in Rewards
Theo6890 Jan 13, 2023
2346cf4
fix: shadow declaration
Theo6890 Jan 13, 2023
23c3de2
test: pending rewards withdrawl
Theo6890 Jan 13, 2023
392c99f
test: full withdrawl
Theo6890 Jan 13, 2023
90e9260
fix(test): deposited rewards
Theo6890 Jan 13, 2023
0526b38
fix: call to `withdrawPendingRewards`
Theo6890 Jan 13, 2023
7c8a18e
refactor: add withdraw logic into `UserData` contract
Theo6890 Jan 13, 2023
e67f80a
fix: file naming
Theo6890 Jan 13, 2023
f88250c
refactor: nextWeek to nextDepositWeek
Theo6890 Jan 13, 2023
97f85fb
refactor: oz Address library in `UserData`
Theo6890 Jan 13, 2023
d81e18e
feat: withdraw pending rewards logic
Theo6890 Jan 13, 2023
c2b86fa
test: withdraw data, including UserWithdrawal(...)
Theo6890 Jan 13, 2023
0eafce1
test(revert): fail on: NO_REWARDS_FOR_USER
Theo6890 Jan 13, 2023
5612b85
feat: revert when if user tries to withdraw 0 rewards
Theo6890 Jan 13, 2023
0e48ab4
test(revert): fails on `WITHDRAW_ONCE_WEEK`
Theo6890 Jan 13, 2023
fd8c70e
test: fails on `NO_REWARDS_DEPOSITED`
Theo6890 Jan 13, 2023
1ee9f7c
feat(revert): pending rewards calculation if no user deposit
Theo6890 Jan 13, 2023
7997ba6
feat(revert): if team deposit when no user deposits
Theo6890 Jan 13, 2023
7df44c6
test(revert): if team deposit when no user deposits
Theo6890 Jan 13, 2023
34e2e53
refactor: internal `_depositRewards`
Theo6890 Jan 13, 2023
8f4f780
refactor: revert message `NO_USERS_DEPOSITS`
Theo6890 Jan 13, 2023
bc71a6a
refactor: single `_withdraw` function
Theo6890 Jan 13, 2023
2c3db3c
feat: withdrawAll
Theo6890 Jan 13, 2023
5c80f85
test: withdrawAll including data and event
Theo6890 Jan 13, 2023
4d59114
refactor(docs): delete useless comments
Theo6890 Jan 13, 2023
c271df9
feat: team can deposit rewards only once a week
Theo6890 Jan 13, 2023
0438358
test(revert): ails on `WEEKLY_REWARDS_DEPOSIT`
Theo6890 Jan 13, 2023
f7fad5a
fix: test name
Theo6890 Jan 13, 2023
c200b84
test(revert): fails on `Pool_OWNER_TEAM_ONLY`
Theo6890 Jan 13, 2023
f07b9b2
test(revert): fails on `DEPOSIT_REWARDS_ZERO`
Theo6890 Jan 13, 2023
3de3592
test(revert): fails on `USER_DEPOSIT_ZERO`
Theo6890 Jan 13, 2023
a7a960a
refactor(docs): delete useless comment
Theo6890 Jan 13, 2023
f8adf4f
refactor: nextDepositWeek to `weekCounter`
Theo6890 Jan 13, 2023
64d6c2c
refactor: rename `snapshotDeposits`
Theo6890 Jan 13, 2023
a2d9859
refactor: weekly rewards deposit restriction to internal function
Theo6890 Jan 13, 2023
a330d80
refactor(visibility): depositRewards `external`
Theo6890 Jan 13, 2023
cb44ae0
test: create a deposit helper
Theo6890 Jan 13, 2023
3c54801
refactor(withdraw): instanciate pool in `beforeEach`
Theo6890 Jan 13, 2023
3b6ed71
chore: getBalance helper
Theo6890 Jan 13, 2023
345d426
refactor: withdrawAll to use helpers
Theo6890 Jan 13, 2023
fa25e88
chore: helper to get pending rewards
Theo6890 Jan 13, 2023
bec4d25
test(wthdrawAll): use pending rewards helper
Theo6890 Jan 13, 2023
07ff292
feat: reset deposit on withdrawAll and total counters
Theo6890 Jan 13, 2023
1322b11
test: verify deposit reset on withdrawAll + counters
Theo6890 Jan 13, 2023
4cb575c
fix(helper): missing import
Theo6890 Jan 13, 2023
08d3dd0
refactor(withdraw): use created helpers
Theo6890 Jan 13, 2023
3272f18
test(withdraw): total counter updates on rewards withdrawls
Theo6890 Jan 13, 2023
2235dcc
feat: update total counter on rewards withdrawls
Theo6890 Jan 13, 2023
220df6e
chore: add `solidity-coverage`
Theo6890 Jan 13, 2023
9870d10
chore: update `verify` script with latest deployed version
Theo6890 Jan 13, 2023
3ca2d9d
docs: update `Results` section
Theo6890 Jan 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/foundry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: foundry actions

on: [push, pull_request]

env:
FOUNDRY_PROFILE: ci

jobs:
foundry:
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: forge test -vvv
id: forge-test
39 changes: 39 additions & 0 deletions .github/workflows/prettier_n_linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: prettier & linters

on: [push, pull_request]

jobs:
prettier:
name: Prettier check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actionsx/prettier@v2
with:
args: --check .

commitlint:
name: Commit-lint check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 5
- uses: wagoid/commitlint-github-action@v5
with:
failOnWarnings: true

solhint:
name: Solhint check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node 16
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: 'npm'
- name: Install Node dependencies
run: rm -rf node_modules && yarn install --immutable --immutable-cache --check-cache # equivalent of `npm ci`
- name: Solhint check
run: npx solhint src/*.sol
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Foundry
cache/
out/

# JS
node_modules/

#Hardhat files
cache_hardhat/
artifacts/

#Hardhat plugin files
typechain-types/

.DS_Store

.bash_history
.env
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "project/lib/forge-std"]
path = project/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "project/lib/solmate"]
path = project/lib/solmate
url = https://github.com/rari-capital/solmate
[submodule "project/lib/openzeppelin-contracts"]
path = project/lib/openzeppelin-contracts
url = https://github.com/Openzeppelin/openzeppelin-contracts
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit "$1"
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx solhint src/*.sol test/*.sol --fix
npx prettier --check .
19 changes: 19 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Foundry
cache/
out/

#JS
node_modules
.next
build
coverage

# Import
lib

#Hardhat files
cache_hardhat/
artifacts/

#Hardhat plugin files
typechain-types/
17 changes: 17 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"semi": true,
"tabWidth": 4,
"printWidth": 79,
"singleQuote": true,
"trailingComma": "es5",
"overrides": [
{
"files": "*.sol",
"options": {
"useTabs": false,
"singleQuote": false,
"explicitTypes": "always"
}
}
]
}
20 changes: 20 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"code-complexity": ["error", 8],
"compiler-version": ["error", ">=0.8.0"],
"constructor-syntax": "error",
"func-visibility": ["error", { "ignoreConstructors": true }],
"state-visibility": "error",
"max-line-length": ["error", 120],
"not-rely-on-time": "off",
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
],
"reason-string": ["warn", { "maxLength": 64 }]
}
}
1 change: 1 addition & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Add files to exclude from solhint
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ ETHPool provides a service where people can deposit ETH and they will receive we

#### Requirements

- Only the team can deposit rewards.
- Deposited rewards go to the pool of users, not to individual users.
- Users should be able to withdraw their deposits along with their share of rewards considering the time when they deposited.
- Only the team can deposit rewards.
- Deposited rewards go to the pool of users, not to individual users.
- Users should be able to withdraw their deposits along with their share of rewards considering the time when they deposited.

Example:

Expand All @@ -32,9 +32,9 @@ You can use any development tools you prefer: Hardhat, Truffle, Brownie, Solidit

Useful resources:

- Solidity Docs: https://docs.soliditylang.org/en/v0.8.4
- Educational Resource: https://github.com/austintgriffith/scaffold-eth
- Project Starter: https://github.com/abarmat/solidity-starter
- Solidity Docs: https://docs.soliditylang.org/en/v0.8.4
- Educational Resource: https://github.com/austintgriffith/scaffold-eth
- Project Starter: https://github.com/abarmat/solidity-starter

### 2) Write tests

Expand All @@ -46,7 +46,7 @@ Deploy the contract to any Ethereum testnet of your preference. Keep record of t

Bonus:

- Verify the contract in Etherscan
- Verify the contract in Etherscan

### 4) Interact with the contract

Expand All @@ -55,8 +55,15 @@ Create a script (or a Hardhat task) to query the total amount of ETH held in the
_You can use any library you prefer: Ethers.js, Web3.js, Web3.py, eth-brownie_

### 5) Contact
- Using this repository, work on the challenge by creating a branch with your name (example: name-surname).

- On your project, create a repository called 'project'. All files that you create must be inside this folder.
- Using this repository, work on the challenge by creating a branch with your name (example: name-surname).

- When you're done with your challenge, open a Merge Request with your changes.
- On your project, create a repository called 'project'. All files that you create must be inside this folder.

- When you're done with your challenge, open a Merge Request with your changes.

## Results

- First version deployed on Goerli and verified [here](https://goerli.etherscan.io/address/0xF9C1b8AC4873117ABDB5e18d25B3f66CE8282397#code)
- Second and final version on Goerli (https://goerli.etherscan.io/address/0x7aC2a52959D780d6ADBE970f3e0B36F1642Ca470#code)
- 2 JS scripts in `project/scripts`: `deploy`, `verify` and `ethBalanceInPool`
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "hardhat-foundry-template",
"version": "1.0.0",
"description": "The harmony between Foundry and Hardhat.",
"directories": {
"lib": "lib",
"test": "test"
},
"scripts": {
"test": "hardhat test",
"prepare": "husky install"
},
"author": "Devan Non <devanon@chainstride.capital>",
"license": "Apache-2.0",
"devDependencies": {
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@nomicfoundation/hardhat-foundry": "^1.0.0",
"@nomiclabs/hardhat-ethers": "^2.0.6",
"@nomiclabs/hardhat-etherscan": "^3.1.3",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@typechain/ethers-v5": "^10.0.0",
"@typechain/hardhat": "^6.0.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.35",
"chai": "^4.3.6",
"dotenv": "^16.0.3",
"ethereum-waffle": "^3.2.0",
"ethers": "^5.6.6",
"hardhat": "^2.9.5",
"hardhat-preprocessor": "^0.1.4",
"husky": "^8.0.0",
"prettier": "^2.6.2",
"prettier-plugin-solidity": "1.1.0",
"solhint": "3.3.7",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.8.2",
"ts-node": "^10.7.0",
"typechain": "^8.0.0",
"typescript": "^4.6.4"
}
}
3 changes: 3 additions & 0 deletions project/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RPC_URL="see https://chainlist.org"
SEED="word1 word2 ... word12"
EXPLORER_KEY=
18 changes: 18 additions & 0 deletions project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Foundry
cache/
out/

# JS
node_modules/

#Hardhat files
cache_hardhat/
artifacts/

#Hardhat plugin files
typechain-types/

.DS_Store

.bash_history
.env
4 changes: 4 additions & 0 deletions project/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Foundry
cache/
out/
lib/
21 changes: 21 additions & 0 deletions project/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"emmet.excludeLanguages": ["markdown"],
"workbench.colorTheme": "Darcula - WebStorm Edition",
"files.autoSave": "afterDelay",
"workbench.startupEditor": "newUntitledFile",
"todo-tree.tree.showScanModeButton": false,
"javascript.updateImportsOnFileMove.enabled": "always",
"workbench.colorCustomizations": {},
"todo-tree.general.tags": ["BUG", "HACK", "FIXME", "TODO", "TEST"],
"git.autofetch": true,
"window.menuBarVisibility": "compact",
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"workbench.editor.untitled.hint": "hidden",
"diffEditor.ignoreTrimWhitespace": false,
"[terraform]": {
"editor.defaultFormatter": "hashicorp.terraform"
}
}
Loading