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

Test/demeter balancer #17

Merged
merged 67 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
e14d16e
Initiated BaseFarm Test
bayou020 Sep 29, 2023
8f7d5af
small update
bayou020 Sep 29, 2023
f01fce3
started testing
bayou020 Oct 13, 2023
6723e0b
Merge branch 'wip/demeter-balancer' into test/demeter-balancer
bayou020 Oct 13, 2023
c507af9
created farms
bayou020 Oct 16, 2023
824c35a
added more test cases
bayou020 Oct 17, 2023
ad131e0
added coverage-minimum command
bayou020 Oct 17, 2023
4c7d346
Added more test cases
bayou020 Oct 18, 2023
0f06663
Added deposit tests
bayou020 Oct 18, 2023
e940d4a
Merge branch 'wip/demeter-balancer' into test/demeter-balancer
bayou020 Oct 18, 2023
de6ac9c
(test:Balancer E20 Farms) Coverage 80%
bayou020 Oct 18, 2023
f0d5fb9
added more BaseFarm tests
bayou020 Oct 25, 2023
aed1d66
Added Withdraw test cases
bayou020 Oct 27, 2023
4e9280a
Merge branch 'dev' into test/demeter-balancer
bayou020 Oct 31, 2023
6422afc
Merge branch 'dev' into test/demeter-balancer
bayou020 Nov 1, 2023
1e4b5f0
Update .gitignore
bayou020 Nov 1, 2023
fe62345
Resolved @parv3213 Comments
bayou020 Nov 1, 2023
68d18e5
PR Fixes
bayou020 Nov 1, 2023
1d0ce5b
Fix package.json
parv3213 Nov 1, 2023
f29735b
Format contracts
parv3213 Nov 1, 2023
9407aaf
Add husky to dev dependencies
parv3213 Nov 1, 2023
98007c2
fix(Demeter Base Farm): Updated Test Cases
bayou020 Nov 1, 2023
61a8103
fix: removed Console from imports
bayou020 Nov 1, 2023
72e1a14
fix: Removed Console import from BaseFarm test file
bayou020 Nov 1, 2023
d0790a6
Fix file paths
parv3213 Nov 2, 2023
fefa338
Format code
parv3213 Nov 2, 2023
24cf6a2
Fix CI
parv3213 Nov 2, 2023
03990e2
Fix gitignore
parv3213 Nov 2, 2023
f3437b9
forge install: forge-std
parv3213 Nov 2, 2023
4743b03
Simplify `foundry.toml`
parv3213 Nov 2, 2023
b4aa77e
Fix file import
parv3213 Nov 2, 2023
2a337e2
test(Balancer Test Cases): Added Missing test cases
bayou020 Nov 2, 2023
69fef42
Merge remote-tracking branch 'origin/dev' into test/demeter-balancer
parv3213 Nov 3, 2023
6f9dcf8
fix(BaseFarm Test Files): Fixed Repeated GetPoolAddress Method on Tes…
bayou020 Nov 3, 2023
bfd9849
Fix forge lib and removing unnecessary file
parv3213 Nov 3, 2023
57aeb9f
Fix solhint errors
parv3213 Nov 3, 2023
2ce2519
forge install: forge-std
parv3213 Nov 3, 2023
1bd337f
Merge remote-tracking branch 'origin/dev' into test/demeter-balancer
parv3213 Nov 3, 2023
8fdff76
Format code using `prettier` script
parv3213 Nov 3, 2023
d2a8a06
refactor(contracts): Make initiateCooldown and withdraw() accessible …
YashP16 Nov 3, 2023
b3b5d8f
test(utils): Add network configuration for tests
YashP16 Nov 3, 2023
75b4b73
test: Restructure test cases to make them modular
YashP16 Nov 3, 2023
cf26593
test: Remove old test cases
YashP16 Nov 3, 2023
479ed18
Fix import path in BaseE20Farm.t.sol
parv3213 Nov 4, 2023
b58db9a
test: Add setup modifier for tests
YashP16 Nov 6, 2023
356db8f
feat(BaseFarm): Added a Non Zero Amount Check
bayou020 Nov 6, 2023
d5762f9
test(BalancerFarm): Fixed not working test cases
bayou020 Nov 6, 2023
a7d24bf
Solhint Functions ordering fixes
bayou020 Nov 6, 2023
20c1b53
fix(Commit Conflicts): Fixed Commit Conflicts on test Cases
bayou020 Nov 6, 2023
e95d426
feat(Fuzzing tests): added fuzzing amounts tests
bayou020 Nov 9, 2023
3fe92aa
feat(Balancer Farm): Added Test Cases Imports
bayou020 Nov 10, 2023
fb9036b
feat(Base Farm): Added Missing test cases
bayou020 Nov 10, 2023
c897696
feat(BaseE20Farm): Added Reverting Test Cases
bayou020 Nov 10, 2023
19a3060
feat(BaseSetup): Fixed Owner= User Bug, Added More Actors , Added Fac…
bayou020 Nov 13, 2023
4023803
fix(BaseFarm): Owner actor shouldn't be user
bayou020 Nov 13, 2023
feb60b6
fix(FarmFactory): Added test cases for Farm Factory
bayou020 Nov 13, 2023
4db2fbb
fix(BaseE20Farm): Fixed test cases when User Prank is not owner
bayou020 Nov 13, 2023
dce3ff2
fix(BaseFarm): Minor Prank Fix
bayou020 Nov 13, 2023
ba1457d
Check for `_isNonZeroAmt` before `_farmNotClosed`
parv3213 Nov 14, 2023
8f5cdcd
Fix/improve tests
parv3213 Nov 14, 2023
3f388c3
fix(FarmFactory test cases): Solved Mehul's comments
bayou020 Nov 14, 2023
82f170f
fix(BaseFarm.t.sol ): Fix Parv's comments
bayou020 Nov 16, 2023
600ddcd
fix(BaseE20Farm.t.sol ): Added Maths tests
bayou020 Nov 16, 2023
cd905ee
fix(BalancerFarn.t.sol ): Fixed Parv's Comment
bayou020 Nov 16, 2023
8b8944d
fix(BaseFarm.t.sol ): Typo fix
bayou020 Nov 16, 2023
629e031
fix(BaseFarm.t.sol BaseFarm.t.sol): Fixes Parv's Comments
bayou020 Nov 16, 2023
5c5d25b
fix(BaseFarm.sol): Removed 0 amount Function check
bayou020 Nov 16, 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
Binary file added .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,6 @@ artifacts/

# Foundry
out/
forge-cache/
forge-cache/
parv3213 marked this conversation as resolved.
Show resolved Hide resolved
tests/
parv3213 marked this conversation as resolved.
Show resolved Hide resolved
coverage/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
Binary file added contracts/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions contracts/BaseFarm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ abstract contract BaseFarm is Ownable, ReentrancyGuard, Initializable {
external
onlyOwner
{
//@audit-info: Check CooldownPeriod before ClosedFarm
_farmNotClosed();
uint256 oldCooldownPeriod = cooldownPeriod;
if (oldCooldownPeriod == 0) {
Expand Down
68 changes: 38 additions & 30 deletions contracts/e20-farms/BaseE20Farm.sol
parv3213 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ contract BaseE20Farm is BaseFarm {
address _farmToken,
RewardTokenData[] memory _rwdTokenData
) external initializer {
// Initialize farm global params
tokenNum = 0;

// initialize farmToken related data
farmToken = _farmToken;
_setupFarm(_farmStartTime, _cooldownPeriod, _rwdTokenData);
Expand All @@ -60,11 +63,13 @@ contract BaseE20Farm is BaseFarm {
/// @param _amount Amount of farmToken to be deposited
/// @param _lockup The lockup flag (bool).
function deposit(uint256 _amount, bool _lockup) external nonReentrant {
address account = msg.sender;
uint256 tokenId = ++tokenNum;
// Execute common deposit logic.
_deposit(msg.sender, _lockup, ++tokenNum, _amount);
_deposit(account, _lockup, tokenId, _amount);

// Transfer the lp tokens to the farm
IERC20(farmToken).safeTransferFrom(msg.sender, address(this), _amount);
IERC20(farmToken).safeTransferFrom(account, address(this), _amount);
}

/// @notice Allow user to increase liquidity for a deposit
Expand All @@ -75,6 +80,7 @@ contract BaseE20Farm is BaseFarm {
external
nonReentrant
{
address account = msg.sender;
// Validations
_farmNotClosed();
_isValidDeposit(msg.sender, _depositId);
Expand All @@ -87,14 +93,14 @@ contract BaseE20Farm is BaseFarm {
}

// claim the pending rewards for the deposit
_claimRewards(msg.sender, _depositId);
_claimRewards(account, _depositId);

// Update deposit Information
_updateSubscriptionForIncrease(userDeposit.tokenId, _amount);
deposits[msg.sender][_depositId].liquidity += _amount;
deposits[account][_depositId].liquidity += _amount;

// Transfer the lp tokens to the farm
IERC20(farmToken).safeTransferFrom(msg.sender, address(this), _amount);
IERC20(farmToken).safeTransferFrom(account, address(this), _amount);
}

/// @notice Withdraw liquidity partially from an existing deposit.
Expand All @@ -105,6 +111,7 @@ contract BaseE20Farm is BaseFarm {
external
nonReentrant
{
address account = msg.sender;
//Validations
_farmNotClosed();
_isValidDeposit(msg.sender, _depositId);
Expand All @@ -119,14 +126,14 @@ contract BaseE20Farm is BaseFarm {
}

// claim the pending rewards for the deposit
_claimRewards(msg.sender, _depositId);
_claimRewards(account, _depositId);

// Update deposit info
_updateSubscriptionForDecrease(userDeposit.tokenId, _amount);
userDeposit.liquidity -= _amount;
deposits[account][_depositId].liquidity -= _amount;

// Transfer the lp tokens to the user
IERC20(farmToken).safeTransfer(msg.sender, _amount);
IERC20(farmToken).safeTransfer(account, _amount);
}

/// @notice Function to lock a staked deposit
Expand All @@ -139,13 +146,14 @@ contract BaseE20Farm is BaseFarm {
/// @notice Function to withdraw a deposit from the farm.
/// @param _depositId The id of the deposit to be withdrawn
function withdraw(uint256 _depositId) external nonReentrant {
_isValidDeposit(msg.sender, _depositId);
Deposit memory userDeposit = deposits[msg.sender][_depositId];
address account = msg.sender;
_isValidDeposit(account, _depositId);
Deposit memory userDeposit = deposits[account][_depositId];

_withdraw(msg.sender, _depositId, userDeposit);
_withdraw(account, _depositId, userDeposit);

// Transfer the farmTokens to the user.
IERC20(farmToken).safeTransfer(msg.sender, userDeposit.liquidity);
IERC20(farmToken).safeTransfer(account, userDeposit.liquidity);
}

// --------------------- Admin Functions ---------------------
Expand Down Expand Up @@ -180,20 +188,20 @@ contract BaseE20Farm is BaseFarm {
function _updateSubscriptionForIncrease(uint256 _tokenId, uint256 _amount)
private
{
Subscription[] storage depositSubs = subscriptions[_tokenId];
uint256 numRewards = rewardTokens.length;
uint256 numSubs = subscriptions[_tokenId].length;
for (uint256 iSub; iSub < numSubs; ) {
uint256[] storage _rewardDebt = subscriptions[_tokenId][iSub]
.rewardDebt;
uint8 _fundId = subscriptions[_tokenId][iSub].fundId;
for (uint8 iRwd; iRwd < numRewards; ) {
_rewardDebt[iRwd] += ((_amount *
rewardFunds[_fundId].accRewardPerShare[iRwd]) / PREC);
uint256 numSubs = depositSubs.length;
for (uint256 iSub = 0; iSub < numSubs; ) {
for (uint8 iRwd = 0; iRwd < numRewards; ) {
depositSubs[iSub].rewardDebt[iRwd] += ((_amount *
rewardFunds[depositSubs[iSub].fundId].accRewardPerShare[
iRwd
]) / PREC);
unchecked {
++iRwd;
}
}
rewardFunds[_fundId].totalLiquidity += _amount;
rewardFunds[depositSubs[iSub].fundId].totalLiquidity += _amount;
unchecked {
++iSub;
}
Expand All @@ -206,20 +214,20 @@ contract BaseE20Farm is BaseFarm {
function _updateSubscriptionForDecrease(uint256 _tokenId, uint256 _amount)
private
{
Subscription[] storage depositSubs = subscriptions[_tokenId];
uint256 numRewards = rewardTokens.length;
uint256 numSubs = subscriptions[_tokenId].length;
for (uint256 iSub; iSub < numSubs; ) {
uint256[] storage _rewardDebt = subscriptions[_tokenId][iSub]
.rewardDebt;
uint8 _fundId = subscriptions[_tokenId][iSub].fundId;
for (uint8 iRwd; iRwd < numRewards; ) {
_rewardDebt[iRwd] -= ((_amount *
rewardFunds[_fundId].accRewardPerShare[iRwd]) / PREC);
uint256 numSubs = depositSubs.length;
for (uint256 iSub = 0; iSub < numSubs; ) {
for (uint8 iRwd = 0; iRwd < numRewards; ) {
depositSubs[iSub].rewardDebt[iRwd] -= ((_amount *
rewardFunds[depositSubs[iSub].fundId].accRewardPerShare[
iRwd
]) / PREC);
unchecked {
++iRwd;
}
}
rewardFunds[_fundId].totalLiquidity -= _amount;
rewardFunds[depositSubs[iSub].fundId].totalLiquidity -= _amount;
unchecked {
++iSub;
}
Expand Down
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ libs = ["node_modules", "lib"]
test = "test"
cache_path = "forge-cache"


parv3213 marked this conversation as resolved.
Show resolved Hide resolved
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
Loading
Loading