Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic reward token: Finalized test cases #4

Open
wants to merge 70 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
8d1fe5d
⚰️ remove unsed vairables
anassohail99 Jan 6, 2023
873a170
🔥 Removed commented code
anassohail99 Jan 6, 2023
5220296
♻️ code refactoring
anassohail99 Jan 7, 2023
37c81ae
🔨 Add deployment script
anassohail99 Jan 7, 2023
145ae9b
✅ Test structure
anassohail99 Jan 7, 2023
27868bd
♻️ refactor code
anassohail99 Jan 9, 2023
83add91
✅ deploy function passing test
anassohail99 Jan 9, 2023
15c0957
🧪 Deploy function failing tests
anassohail99 Jan 9, 2023
1b9de8c
✅ Update and notify function tests
anassohail99 Jan 9, 2023
3134854
🔥 Remove github workflow
anassohail99 Jan 9, 2023
5b4d54e
✅ Stake function tests
anassohail99 Jan 10, 2023
a692552
✅ Fuzz test staking fuction
anassohail99 Jan 10, 2023
51ff144
✅ Withdraw function tests
anassohail99 Jan 10, 2023
f3d8e85
🔧 Update fuzz runs
anassohail99 Jan 10, 2023
dda1855
✅ total supply function
anassohail99 Jan 10, 2023
fa88dde
🔧 Gas reporting
anassohail99 Jan 10, 2023
947861c
👷 Add build configurations
anassohail99 Jan 10, 2023
938502e
✨ Events on deploy and update
anassohail99 Jan 11, 2023
53bf548
🔨 Update deployment script
anassohail99 Jan 11, 2023
41aa386
✅ Update deploy event
anassohail99 Jan 12, 2023
06bed73
💡 remove comment
anassohail99 Jan 13, 2023
221b6c5
🔊 Error logs
anassohail99 Jan 13, 2023
ac291f0
🔨 update genesis time
anassohail99 Jan 13, 2023
04808d1
🚧 test cases in progress
anassohail99 Jan 13, 2023
1137788
🔨 update yarn scripts
anassohail99 Jan 13, 2023
a61eb10
✨ Dynamic reward token
anassohail99 Jan 13, 2023
c84beb7
🔨 Remove reward token
anassohail99 Jan 13, 2023
c0b0a5f
✅ Update testcases for reward token
anassohail99 Jan 13, 2023
52f30b8
🐛 Reward token fixes
anassohail99 Jan 13, 2023
8b056b8
🔨 Update deployment script
anassohail99 Jan 13, 2023
c2f91d0
✅ Contract variable before stake
anassohail99 Jan 16, 2023
b860e5c
✅ After first stake test
anassohail99 Jan 16, 2023
37ce2c8
✅ Test reward per token paid
anassohail99 Jan 16, 2023
fcb924c
✅ Test earned function
anassohail99 Jan 16, 2023
2f2ec01
✅ Test getReward function
anassohail99 Jan 16, 2023
cae086a
changes stake token function
anassohail99 Jan 17, 2023
4e38b19
✅ Multiple users stake
anassohail99 Jan 17, 2023
dfd713f
✅ Exit function test
anassohail99 Jan 17, 2023
40e749d
✅ Add notify function tests
anassohail99 Jan 20, 2023
6603dc4
✅ Invalid addresses test
anassohail99 Jan 20, 2023
80f8f60
✅ Notify reward amount test
anassohail99 Jan 20, 2023
7921f60
✅ Require check tests notify function
anassohail99 Jan 20, 2023
9744842
🙈 Add lcov file
anassohail99 Jan 20, 2023
16cec20
✅ Stake with permit test
anassohail99 Jan 21, 2023
07276b3
🏷️ ERC20Permit Token
anassohail99 Jan 21, 2023
528bf15
✅ CSZ test stakeWithPermit
anassohail99 Jan 21, 2023
772f75c
ERC20Permit Token
anassohail99 Jan 21, 2023
d2247c8
📸 Functions gas snapshots
anassohail99 Jan 21, 2023
45e8b49
🔥 Remove interface from contract file
anassohail99 Jan 23, 2023
e00b04e
🐛 Same addresses check
anassohail99 Jan 24, 2023
ddd1557
♻️ Refactor
anassohail99 Jan 24, 2023
f05dcca
✅ Add events strcuts and mock addresses
anassohail99 Jan 24, 2023
931bab8
✅ Staking reward info mapping
anassohail99 Jan 24, 2023
841b52b
✅ Addresses and value check test
anassohail99 Jan 24, 2023
5f83d7b
✅ Updates to preivious update function test
anassohail99 Jan 24, 2023
f927dbd
✅ Owner check test
anassohail99 Jan 24, 2023
0af1c85
✅ Notify Reward test with updating values
anassohail99 Jan 24, 2023
f862a57
✅ Deploy and Update Events
anassohail99 Jan 25, 2023
b3c1ac0
Gas snapshots
anassohail99 Feb 13, 2023
5ab3f66
added test scenarios
anassohail99 Feb 13, 2023
8724a56
udated deploy script
anassohail99 Feb 13, 2023
74bab97
🚩 dual rewards factory
anassohail99 Feb 14, 2023
c508d17
🚩 dual rewards vault
anassohail99 Feb 14, 2023
dbab78f
🚩 rewards distribution recipient
anassohail99 Feb 14, 2023
da2621f
🚩 rewards vault interface
anassohail99 Feb 14, 2023
d4aff3d
🚩pausable functionality
anassohail99 Feb 14, 2023
cb45cd3
🔨 Staking dual rewards deployement script
anassohail99 Feb 14, 2023
1cc5c7d
✏️ fix contract name
anassohail99 Feb 14, 2023
24d67a4
✅ staking dual rewards tests
anassohail99 Feb 14, 2023
a9423d1
🔨 update yarn script
anassohail99 Feb 14, 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
36 changes: 36 additions & 0 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
StakingRewardsTest:testCannotPassRequireChecksNotifyRewardAmount() (gas: 3015577)
StakingRewardsTest:testCannotStakePermitWithZero() (gas: 3746883)
StakingRewardsTest:testCannotStakeZero() (gas: 42111)
StakingRewardsTest:testCannotWithdrawZero() (gas: 32514)
StakingRewardsTest:testEarnedValue() (gas: 268493)
StakingRewardsTest:testEarnedValueWithMultipleUsers() (gas: 491204)
StakingRewardsTest:testExitFunction() (gas: 266016)
StakingRewardsTest:testGetReward() (gas: 211491)
StakingRewardsTest:testMultipleStake() (gas: 370690)
StakingRewardsTest:testRewardPerTokenPaidAfterStakes() (gas: 261057)
StakingRewardsTest:testStake() (gas: 212525)
StakingRewardsTest:testStakeFuzz(uint128) (runs: 1000, μ: 112512, ~: 115061)
StakingRewardsTest:testStakeWithPermit() (gas: 3846052)
StakingRewardsTest:testTotalSupply() (gas: 353490)
StakingRewardsTest:testValuesBeforeFirstStake() (gas: 22753)
StakingRewardsTest:testValuesFirstAfterStake() (gas: 121683)
StakingRewardsTest:testWithdraw() (gas: 120652)
StakingRewardsFactoryTest:testCannotDeployWithInvalidAddress() (gas: 1330588)
StakingRewardsFactoryTest:testCannotDeployWithSameAddresses() (gas: 16070)
StakingRewardsFactoryTest:testCannotDeployWithZeroAddress() (gas: 1311838)
StakingRewardsFactoryTest:testCannotDeployWithZeroAmount() (gas: 20296)
StakingRewardsFactoryTest:testCannotNotifyRewardAmounts() (gas: 12994)
StakingRewardsFactoryTest:testCannotTestNotifyRewardAmount() (gas: 1243472)
StakingRewardsFactoryTest:testCannotTestNotifyRewardAmountWithZeroAddress() (gas: 1245704)
StakingRewardsFactoryTest:testCannotUpdateStakingContract() (gas: 18119)
StakingRewardsFactoryTest:testCannotUpdateStakingContractWithOwner() (gas: 18511)
StakingRewardsFactoryTest:testDeployStakingRewardsContract() (gas: 1308783)
StakingRewardsFactoryTest:testEmitDeploy() (gas: 1235487)
StakingRewardsFactoryTest:testEmitUpdate() (gas: 1342066)
StakingRewardsFactoryTest:testNotifyRewardAmount() (gas: 1896349)
StakingRewardsFactoryTest:testNotifyRewardAmounts() (gas: 9284619)
StakingRewardsFactoryTest:testPullErc20RandomToken() (gas: 1932168)
StakingRewardsFactoryTest:testPullErc20RewardToken() (gas: 1315654)
StakingRewardsFactoryTest:testStakingRewardsInfo() (gas: 1211665)
StakingRewardsFactoryTest:testUpdateStakingContract() (gas: 1327606)
StakingRewardsFactoryTest:testUpdatedNotifyRewardAmount() (gas: 1968825)
36 changes: 36 additions & 0 deletions .gas-snapshot 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
StakingRewardsTest:testCannotPassRequireChecksNotifyRewardAmount() (gas: 2981890)
StakingRewardsTest:testCannotStakePermitWithZero() (gas: 3713174)
StakingRewardsTest:testCannotStakeZero() (gas: 42111)
StakingRewardsTest:testCannotWithdrawZero() (gas: 32514)
StakingRewardsTest:testEarnedValue() (gas: 250748)
StakingRewardsTest:testEarnedValueWithMultipleUsers() (gas: 473460)
StakingRewardsTest:testExitFunction() (gas: 248253)
StakingRewardsTest:testGetReward() (gas: 189310)
StakingRewardsTest:testMultipleStake() (gas: 370690)
StakingRewardsTest:testRewardPerTokenPaidAfterStakes() (gas: 243312)
StakingRewardsTest:testStake() (gas: 190344)
StakingRewardsTest:testStakeFuzz(uint128) (runs: 1000, μ: 112512, ~: 115061)
StakingRewardsTest:testStakeWithPermit() (gas: 3812343)
StakingRewardsTest:testTotalSupply() (gas: 353490)
StakingRewardsTest:testValuesBeforeFirstStake() (gas: 22731)
StakingRewardsTest:testValuesFirstAfterStake() (gas: 121661)
StakingRewardsTest:testWithdraw() (gas: 120652)
StakingRewardsFactoryTest:testCannotDeployWithInvalidAddress() (gas: 1313743)
StakingRewardsFactoryTest:testCannotDeployWithSameAddresses() (gas: 16070)
StakingRewardsFactoryTest:testCannotDeployWithZeroAddress() (gas: 1294993)
StakingRewardsFactoryTest:testCannotDeployWithZeroAmount() (gas: 20296)
StakingRewardsFactoryTest:testCannotNotifyRewardAmounts() (gas: 12994)
StakingRewardsFactoryTest:testCannotTestNotifyRewardAmount() (gas: 1226627)
StakingRewardsFactoryTest:testCannotTestNotifyRewardAmountWithZeroAddress() (gas: 1228859)
StakingRewardsFactoryTest:testCannotUpdateStakingContract() (gas: 18119)
StakingRewardsFactoryTest:testCannotUpdateStakingContractWithOwner() (gas: 18511)
StakingRewardsFactoryTest:testDeployStakingRewardsContract() (gas: 1291938)
StakingRewardsFactoryTest:testEmitDeploy() (gas: 1218642)
StakingRewardsFactoryTest:testEmitUpdate() (gas: 1325221)
StakingRewardsFactoryTest:testNotifyRewardAmount() (gas: 1879504)
StakingRewardsFactoryTest:testNotifyRewardAmounts() (gas: 9200394)
StakingRewardsFactoryTest:testPullErc20RandomToken() (gas: 1915323)
StakingRewardsFactoryTest:testPullErc20RewardToken() (gas: 1298809)
StakingRewardsFactoryTest:testStakingRewardsInfo() (gas: 1194820)
StakingRewardsFactoryTest:testUpdateStakingContract() (gas: 1310761)
StakingRewardsFactoryTest:testUpdatedNotifyRewardAmount() (gas: 1951936)
54 changes: 5 additions & 49 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
name: test

on:
push:
branches:
- master
pull_request:
on: [push]

env:
FOUNDRY_PROFILE: ci
name: test

jobs:
foundry:
strategy:
fail-fast: true

check:
name: Foundry project
runs-on: ubuntu-latest
steps:
Expand All @@ -26,39 +16,5 @@ jobs:
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

hardhat:
strategy:
fail-fast: true

name: Hardhat project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Node 16
uses: actions/setup-node@v3
with:
node-version: '16.x'
cache: 'npm'

- name: Install Node dependencies
run: |
npm ci

- name: Run Hardhat tests
run: |
npm run test
id: hardhat-test
- name: Run tests
run: forge test -vvv
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cache/
out/
lib
broadcast/
bin/

# JS
node_modules/
Expand All @@ -14,4 +15,5 @@ artifacts/
#Hardhat plugin files
typechain-types/

.env
.env
lcov.info
4 changes: 4 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ src = 'src'
solc = "0.7.6"
out = 'out'
libs = ['lib']
[fuzz]
runs = 1000
gas_reports = ["StakingRewards", "StakingRewardsFactory"]


# See more config options https://github.com/foundry-rs/foundry/tree/master/config

Expand Down
2 changes: 0 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import "@typechain/hardhat";
import "hardhat-preprocessor";
import { HardhatUserConfig, task } from "hardhat/config";

import example from "./tasks/example";

function getRemappings() {
return fs
Expand All @@ -14,7 +13,6 @@ function getRemappings() {
.map((line) => line.trim().split("="));
}

task("example", "Example task").setAction(example);

const config: HardhatUserConfig = {
solidity: {
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
"test": "test"
},
"scripts": {
"test": "hardhat test",
"deploy-stakingRewardsFactory":"forge script script/StakingRewardsFactory.s.sol:StakingRewardsFactory --rpc-url $GOERLI_RPC_URL --broadcast --verify -vvvv"
"test": "clear && forge test -vv",
"test-mainnet": "forge test --fork-url $ETH_RPC_URL -vv",
"logtest": "clear && forge test -vvvv",
"deploy-stakingRewardsFactory": "./bin/deployStakingRewardsFactory.sh",
"deploy-stakingDualRewardsFactory": "./bin/deployStakingDualRewardsFactory.sh"

},
"author": "Devan Non <[email protected]>",
"license": "Apache-2.0",
Expand All @@ -22,7 +26,7 @@
"@types/node": "^17.0.35",
"chai": "^4.3.6",
"ethereum-waffle": "^3.2.0",
"ethers": "^5.6.6",
"ethers": "^5.7.2",
"hardhat": "^2.9.5",
"hardhat-preprocessor": "^0.1.4",
"ts-node": "^10.7.0",
Expand Down
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
forge-std/=lib/forge-std/src/
solmate/=lib/solmate/src/
ds-test/=lib/forge-std/lib/ds-test/src/
openzeppelin/=lib/openzeppelin-contracts/
openzeppelin-contracts/=lib/openzeppelin-contracts/
34 changes: 34 additions & 0 deletions script/StakingDualRewardsFactory.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.6;

import "forge-std/Script.sol";
import "../src/StakingDualRewardsFactory.sol";
import "../src/interfaces/IERC20.sol";

contract DeployStakingDualRewardsFactoryScript is Script {
// Vm hevm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
address rewardsTokenA = 0x1837d2285980853b0fe02AaD766a9403e311a4f4;
address rewardsTokenB = 0xd056Deaa25C6D5C7A93D5EAC37Bb78b5265D2e15;
address stakingToken = 0x0737593086022272629670bBd207918ea9189484;
uint256 stakingRewardsGenesis = block.timestamp + 1 minutes;

function run() external {
uint256 deployerPrivateKey = vm.envUint("PKEY");
vm.startBroadcast(deployerPrivateKey);

StakingDualRewardsFactory stakingDualRewardsFactory = new StakingDualRewardsFactory(
stakingRewardsGenesis
);

IERC20(rewardsTokenA).transfer(
address(stakingDualRewardsFactory),
100e18
);
IERC20(rewardsTokenB).transfer(
address(stakingDualRewardsFactory),
100e18
);

vm.stopBroadcast();
}
}
47 changes: 21 additions & 26 deletions script/StakingRewardsFactory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,35 @@ pragma solidity ^0.7.6;

import "forge-std/Script.sol";
import "../src/StakingRewardsFactory.sol";
import "../src/interfaces/IERC20.sol";

contract DeployStakingRewardsFactoryScript is Script {
// Vm hevm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
address rewardsToken = 0x4fC1263815Ab1E8fD97EC5010A7B4694dA6F593F;
uint stakingRewardsGenesis = block.timestamp + 5 minutes;
address stakingToken = 0xfBB9a726ed78631b7766E02f84cf2e40345D8083;
uint256 stakingRewardsGenesis = block.timestamp + 1 minutes;

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
uint256 deployerPrivateKey = vm.envUint("PKEY");
vm.startBroadcast(deployerPrivateKey);

StakingRewardsFactory stakingRewardsFactory = new StakingRewardsFactory(rewardsToken, stakingRewardsGenesis);
StakingRewardsFactory stakingRewardsFactory = new StakingRewardsFactory(
stakingRewardsGenesis
);

vm.stopBroadcast();
}
}

// contract DeployStakingRewardsScript is Script {
// address rewardsToken = 0x4fC1263815Ab1E8fD97EC5010A7B4694dA6F593F;
// uint stakingRewardsGenesis = 0;
// IERC20(rewardsToken).transfer(address(stakingRewardsFactory), 100e18);

// function run() external {
// uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
// vm.startBroadcast(deployerPrivateKey);
// vm.stopBroadcast();

// StakingRewardsFactory stakingRewardsFactory = new StakingRewardsFactory(rewardsToken, stakingRewardsGenesis);
// vm.startBroadcast(deployerPrivateKey);
// stakingRewardsFactory.deploy(
// stakingToken,
// rewardsToken,
// 100e18,
// block.timestamp + 10 days
// );

// vm.stopBroadcast();
// }
// }

// forge create --rpc-url https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161
// --private-key 4ef58c0f2dfe941a2c8c173ef3c98ea2f7575be2c7e67341e0e0b27464859dc7
// src/StakingRewardsFactory.sol:StakingRewards
// --constructor-args 0x97ff40b5678d2234b1e5c894b5f39b8ba8535431
// 0x4fC1263815Ab1E8fD97EC5010A7B4694dA6F593F
// 0xfBB9a726ed78631b7766E02f84cf2e40345D8083
// --etherscan-api-key GSWUYPSZGBKJ168A2M78TF7VUA97AP6G22
// --verify
// stakingRewardsFactory.notifyRewardAmounts();
vm.stopBroadcast();
}
}
Loading