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 case optimization #41

Merged
merged 34 commits into from
Feb 16, 2024
Merged

Test case optimization #41

merged 34 commits into from
Feb 16, 2024

Conversation

TechnoGeek01
Copy link
Contributor

@TechnoGeek01 TechnoGeek01 commented Feb 5, 2024

  • Use fuzz pattern/for loops pattern, for lockup and nonLockup farms.
  • Code reuse using helper functions.
  • Remove redundant code.
  • Naming convention.

Copy link

github-actions bot commented Feb 5, 2024

Changes to gas cost

Generated at commit: 4cb3e61f08a3c222593389d53cacd1c68b93a773, compared to commit: 448842e0d1b56081c957b08e0f85a96b4564288f

🧾 Summary (10% most significant diffs)

Contract Method Avg (+/-) %
Demeter_CamelotFarm getRewardRates
withdraw
-2,941 ✅
-47,649 ✅
-58.32%
-19.08%
BaseE20Farm getRewardRates
withdraw
-2,648 ✅
-68,066 ✅
-56.21%
-26.55%
BaseUniV3ActiveLiquidityFarm getRewardFundInfo
getRewardRates
withdraw
-5,162 ✅
-2,941 ✅
-77,015 ✅
-47.40%
-58.84%
-28.57%
BaseUniV3Farm getRewardRates -2,941 ✅ -58.59%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
Demeter_CamelotFarm 4,741,798 (+3,009) addRewards
claimRewards
closeFarm
computeRewards
cooldownPeriod
extendFarmDuration
farmEndTime
farmPauseSwitch
getDepositInfo
getRewardBalance
getRewardRates
initialize
onERC721Received
recoverERC20
recoverRewardFunds
rewardTokens
setRewardRate
totalDeposits
updateFarmStartTime
withdraw
22,623 (0)
894 (0)
915 (0)
14,018 (0)
387 (0)
1,057 (0)
386 (0)
824 (0)
531 (0)
2,559 (-375)
1,869 (0)
30,940 (0)
2,966 (0)
26,997 (+18)
18,096 (-13,322)
748 (0)
1,213 (0)
362 (0)
1,229 (0)
1,631 (0)
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
-12.78%
0.00%
0.00%
0.00%
+0.07%
-42.40%
0.00%
0.00%
0.00%
0.00%
0.00%
48,148 (+422)
188,695 (-400)
122,626 (-876)
20,026 (-817)
2,351 (-6)
25,597 (-2)
497 (-31)
52,171 (-436)
2,447 (+152)
4,331 (-247)
2,102 (-2,941)
398,516 (+357)
279,651 (+336)
42,250 (+21)
38,041 (-7,967)
2,349 (+14)
39,197 (+970)
962 (+600)
4,495 (+115)
202,071 (-47,649)
+0.88%
-0.21%
-0.71%
-3.92%
-0.25%
-0.01%
-5.87%
-0.83%
+6.62%
-5.40%
-58.32%
+0.09%
+0.12%
+0.05%
-17.32%
+0.60%
+2.54%
+165.75%
+2.63%
-19.08%
36,080 (0)
254,140 (-2,800)
102,867 (-1,047)
17,191 (-299)
2,387 (0)
28,221 (0)
386 (0)
28,450 (0)
2,528 (0)
4,036 (-250)
1,869 (-2,349)
367,341 (0)
261,844 (0)
39,825 (+18)
36,707 (-7,293)
2,748 (0)
30,964 (0)
362 (0)
3,481 (0)
142,990 (-157,099)
0.00%
-1.09%
-1.01%
-1.71%
0.00%
0.00%
0.00%
0.00%
0.00%
-5.83%
-55.69%
0.00%
0.00%
+0.05%
-16.57%
0.00%
0.00%
0.00%
0.00%
-52.35%
68,071 (+8,065)
392,641 (0)
235,466 (0)
29,024 (0)
2,387 (0)
39,764 (-12)
2,386 (0)
164,381 (0)
2,528 (0)
6,286 (0)
2,568 (-7,301)
446,330 (0)
402,194 (0)
59,930 (+28)
61,318 (0)
4,748 (0)
55,983 (-8,000)
2,362 (+2,000)
9,469 (0)
396,368 (0)
+13.44%
0.00%
0.00%
0.00%
0.00%
-0.03%
0.00%
0.00%
0.00%
0.00%
-73.98%
0.00%
0.00%
+0.05%
0.00%
0.00%
-12.50%
+552.49%
0.00%
0.00%
116 (-24)
7 (0)
21 (-7)
9 (+1)
57 (-11)
6 (-6)
18 (-10)
11 (0)
155 (-65)
32 (0)
6 (-10)
221 (-116)
120 (-10)
3 (0)
12 (+6)
266 (-44)
118 (-24)
10 (+4)
18 (-16)
24 (0)
BaseE20Farm 3,805,748 (+3,609) addRewards
claimRewards
closeFarm
computeRewards
cooldownPeriod
deposit
extendFarmDuration
farmEndTime
farmPauseSwitch
getDepositInfo
getRewardBalance
getRewardRates
increaseDeposit
initialize
recoverERC20
recoverRewardFunds
rewardTokens
setRewardRate
totalDeposits
updateFarmStartTime
withdraw
22,645 (0)
836 (0)
946 (0)
13,066 (0)
364 (0)
1,016 (0)
956 (0)
429 (0)
767 (0)
509 (0)
3,474 (-375)
1,889 (0)
1,201 (0)
46,947 (0)
24,874 (-2,083)
13,478 (-17,908)
682 (0)
1,156 (0)
385 (0)
1,032 (0)
1,730 (0)
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
-9.74%
0.00%
0.00%
0.00%
-7.73%
-57.06%
0.00%
0.00%
0.00%
0.00%
0.00%
48,169 (+550)
131,072 (-3,717)
121,702 (+6,967)
17,269 (-228)
2,321 (-3)
277,860 (+2,347)
25,501 (-2)
554 (-28)
53,471 (-480)
2,418 (+157)
5,060 (-194)
2,063 (-2,648)
68,124 (+6,880)
395,809 (-2,109)
39,484 (-4,190)
38,009 (-7,967)
2,246 (+4)
40,252 (-162)
1,385 (+624)
4,295 (+116)
188,290 (-68,066)
+1.16%
-2.76%
+6.07%
-1.30%
-0.13%
+0.85%
-0.01%
-4.81%
-0.89%
+6.94%
-3.69%
-56.21%
+11.23%
-0.53%
-9.59%
-17.33%
+0.18%
-0.40%
+82.00%
+2.78%
-26.55%
32,108 (0)
110,100 (0)
102,902 (0)
15,391 (-1,701)
2,364 (0)
293,892 (+30,750)
28,124 (0)
429 (0)
27,397 (0)
2,506 (0)
4,951 (0)
1,889 (-699)
2,024 (-12,411)
361,135 (0)
35,519 (-6,404)
34,675 (-707)
2,682 (0)
49,930 (0)
1,385 (+1,000)
3,288 (0)
183,728 (-139,310)
0.00%
0.00%
0.00%
-9.95%
0.00%
+11.69%
0.00%
0.00%
0.00%
0.00%
0.00%
-27.01%
-85.98%
0.00%
-15.28%
-2.00%
0.00%
0.00%
+259.74%
0.00%
-43.12%
72,016 (+8,034)
414,450 (0)
235,466 (0)
28,871 (0)
2,364 (0)
429,392 (+4,000)
39,678 (-12)
2,429 (0)
164,313 (0)
2,506 (0)
7,201 (0)
2,588 (-7,301)
297,294 (0)
440,124 (0)
62,027 (-117)
69,872 (0)
4,682 (0)
55,930 (-8,000)
2,385 (0)
9,276 (0)
372,091 (0)
+12.56%
0.00%
0.00%
0.00%
0.00%
+0.94%
-0.03%
0.00%
0.00%
0.00%
0.00%
-73.83%
0.00%
0.00%
-0.19%
0.00%
0.00%
-12.51%
0.00%
0.00%
0.00%
96 (-8)
12 (0)
18 (-4)
18 (+1)
47 (-3)
110 (-1)
6 (-6)
16 (-10)
10 (0)
143 (-66)
32 (0)
8 (-10)
5 (-1)
190 (-75)
4 (+1)
12 (+6)
234 (-12)
98 (-8)
6 (-265)
18 (-16)
18 (0)
BaseUniV3ActiveLiquidityFarm 4,962,702 (+3,000) addRewards
claimRewards
closeFarm
computeRewards
cooldownPeriod
extendFarmDuration
farmEndTime
farmPauseSwitch
getDepositInfo
getRewardBalance
getRewardFundInfo
getRewardRates
initialize
initiateCooldown
isFarmActive
onERC721Received
recoverERC20
rewardTokens
setRewardRate
totalDeposits
updateCooldownPeriod
updateFarmStartTime
withdraw
22,645 (0)
894 (0)
937 (0)
18,975 (0)
387 (-2,000)
1,013 (0)
407 (0)
846 (0)
532 (-1,456)
3,474 (-375)
2,632 (0)
1,824 (0)
146,668 (0)
4,008 (0)
497 (0)
2,966 (-22,531)
26,952 (+18)
703 (0)
1,235 (0)
406 (0)
762 (0)
1,251 (0)
3,859 (0)
0.00%
0.00%
0.00%
0.00%
-83.79%
0.00%
0.00%
0.00%
-73.24%
-9.74%
0.00%
0.00%
0.00%
0.00%
0.00%
-88.37%
+0.07%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
59,366 (+169)
172,269 (-1,284)
129,997 (+1,239)
30,874 (-656)
2,350 (-37)
25,553 (-2)
518 (-42)
51,778 (-6,976)
2,444 (+127)
5,935 (-569)
5,728 (-5,162)
2,057 (-2,941)
471,099 (-254)
133,295 (-13,362)
9,550 (-563)
298,008 (+394)
42,205 (+21)
2,307 (-23)
46,705 (+1,607)
812 (+70)
8,690 (+507)
4,517 (+245)
192,518 (-77,015)
+0.29%
-0.74%
+0.96%
-2.08%
-1.55%
-0.01%
-7.50%
-11.87%
+5.48%
-8.75%
-47.40%
-58.84%
-0.05%
-9.11%
-5.57%
+0.13%
+0.05%
-0.99%
+3.56%
+9.43%
+6.20%
+5.74%
-28.57%
36,345 (+503)
195,166 (-2,800)
125,103 (0)
26,187 (-4,414)
2,387 (0)
28,177 (0)
407 (0)
38,186 (-6,795)
2,529 (0)
5,201 (-1,750)
3,148 (-7,742)
1,824 (-2,349)
438,962 (0)
59,807 (0)
13,268 (-2,250)
323,323 (+8,826)
39,780 (+18)
2,703 (0)
53,719 (0)
406 (0)
9,069 (+5)
3,503 (+211)
150,894 (-189,153)
+1.40%
-1.41%
0.00%
-14.42%
0.00%
0.00%
0.00%
-15.11%
0.00%
-25.18%
-71.09%
-56.29%
0.00%
0.00%
-14.50%
+2.81%
+0.05%
0.00%
0.00%
0.00%
+0.06%
+6.41%
-55.63%
91,785 (+7,569)
388,460 (0)
249,107 (0)
42,227 (0)
2,387 (0)
39,720 (-12)
2,407 (0)
178,020 (0)
2,529 (0)
9,201 (0)
19,148 (0)
2,523 (-7,301)
517,951 (0)
428,331 (0)
15,518 (0)
434,023 (0)
59,885 (+28)
4,703 (0)
59,719 (-24,500)
2,406 (0)
13,014 (0)
9,491 (0)
389,092 (0)
+8.99%
0.00%
0.00%
0.00%
0.00%
-0.03%
0.00%
0.00%
0.00%
0.00%
0.00%
-74.32%
0.00%
0.00%
0.00%
0.00%
+0.05%
0.00%
-29.09%
0.00%
0.00%
0.00%
0.00%
112 (+30)
6 (0)
21 (+1)
15 (+1)
55 (+17)
6 (-6)
18 (-8)
11 (+2)
149 (-56)
32 (0)
6 (+4)
6 (-10)
230 (-5)
13 (+2)
8 (0)
121 (+23)
3 (0)
258 (+70)
114 (+30)
290 (+52)
8 (+3)
18 (-14)
26 (+6)
BaseUniV3Farm 4,776,443 (+3,000) addRewards
claimRewards
closeFarm
computeRewards
cooldownPeriod
decreaseDeposit
extendFarmDuration
farmEndTime
farmPauseSwitch
getDepositInfo
getRewardBalance
getRewardRates
initialize
onERC721Received
owner
recoverERC20
rewardTokens
setRewardRate
totalDeposits
updateCooldownPeriod
updateFarmStartTime
withdraw
22,667 (0)
894 (0)
959 (0)
13,147 (0)
387 (0)
1,018 (0)
1,013 (0)
429 (0)
868 (0)
554 (-1,456)
3,474 (-375)
1,846 (0)
34,048 (0)
2,966 (0)
443 (0)
26,974 (+18)
725 (0)
1,169 (0)
428 (0)
784 (0)
1,206 (0)
1,609 (0)
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
-72.44%
-9.74%
0.00%
0.00%
0.00%
0.00%
+0.07%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
48,201 (+532)
162,957 (-466)
114,637 (+4,806)
19,910 (-805)
2,293 (-54)
30,433 (+865)
25,553 (-2)
540 (-31)
43,696 (-437)
2,466 (+122)
5,060 (-194)
2,079 (-2,941)
449,470 (-11,745)
294,190 (-650)
1,585 (-191)
42,227 (+21)
2,334 (+8)
42,325 (-554)
1,178 (+371)
8,712 (+507)
4,472 (+245)
190,106 (-44,333)
+1.12%
-0.29%
+4.38%
-3.89%
-2.30%
+2.93%
-0.01%
-5.43%
-0.99%
+5.20%
-3.69%
-58.59%
-2.55%
-0.22%
-10.75%
+0.05%
+0.34%
-1.29%
+45.97%
+6.18%
+5.80%
-18.91%
32,150 (0)
181,898 (-1,400)
102,911 (0)
17,169 (-299)
2,387 (0)
1,813 (0)
28,177 (0)
429 (0)
26,494 (0)
2,551 (0)
4,951 (0)
1,846 (-2,349)
431,984 (-7,000)
317,356 (0)
2,443 (0)
39,802 (+18)
2,725 (0)
49,939 (0)
428 (0)
9,091 (+5)
3,458 (+211)
139,743 (-137,199)
0.00%
-0.76%
0.00%
-1.71%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
-56.00%
-1.59%
0.00%
0.00%
+0.05%
0.00%
0.00%
0.00%
+0.06%
+6.50%
-49.54%
72,089 (+8,065)
372,741 (0)
235,510 (0)
29,002 (0)
2,387 (0)
118,492 (+4,325)
39,720 (-12)
2,429 (0)
164,425 (0)
2,551 (0)
7,201 (0)
2,545 (-7,301)
517,973 (0)
428,056 (0)
2,443 (0)
59,907 (+28)
4,725 (0)
55,939 (-8,000)
2,428 (0)
13,036 (0)
9,446 (0)
373,221 (0)
+12.60%
0.00%
0.00%
0.00%
0.00%
+3.79%
-0.03%
0.00%
0.00%
0.00%
0.00%
-74.15%
0.00%
0.00%
0.00%
+0.05%
0.00%
-12.51%
0.00%
0.00%
0.00%
0.00%
212 (0)
12 (0)
42 (-6)
18 (+2)
107 (+5)
10 (0)
12 (-12)
36 (-20)
22 (0)
298 (-122)
64 (0)
12 (-20)
471 (-113)
236 (+4)
7 (+1)
6 (0)
492 (+20)
216 (0)
16 (-532)
16 (+6)
36 (-28)
48 (0)
FarmFactory 753,449 (0) getFeeParams
initialize
registerFarm
registerFarmDeployer
1,060 (0)
47,538 (0)
2,682 (0)
628 (0)
0.00%
0.00%
0.00%
0.00%
2,655 (-195)
138,968 (-67)
57,875 (+86)
68,214 (-86)
-6.84%
-0.05%
+0.15%
-0.13%
3,259 (0)
139,305 (0)
53,941 (0)
68,636 (0)
0.00%
0.00%
0.00%
0.00%
11,259 (0)
139,305 (0)
69,041 (0)
68,636 (0)
0.00%
0.00%
0.00%
0.00%
1,080 (-320)
546 (-135)
1,071 (-315)
530 (-135)
Demeter_CamelotFarm_Deployer 5,848,568 (+3,009) createFarm 115,700 (0) 0.00% 540,813 (-3,190) -0.59% 541,911 (0) 0.00% 620,900 (0) 0.00% 220 (-113)
Demeter_BalancerFarm_Deployer 4,856,235 (+3,609) createFarm 161,487 (0) 0.00% 537,160 (-2,925) -0.54% 535,551 (0) 0.00% 614,540 (0) 0.00% 190 (-75)
Demeter_BaseUniV3FarmDeployer 5,893,362 (+3,009) createFarm 203,945 (0) 0.00% 608,590 (-2,741) -0.45% 608,233 (0) 0.00% 687,222 (0) 0.00% 444 (-122)
Demeter_BaseUniV3ActiveLiquidityDeployer 6,079,883 (+3,009) createFarm 203,923 (0) 0.00% 608,521 (-1,477) -0.24% 608,211 (0) 0.00% 687,200 (0) 0.00% 230 (-5)
BalancerFarmTest 26,995,903 (-5,894,797) createFarm 200,354 (-88) -0.04% 314,921 (-88) -0.03% 273,929 (-88) -0.03% 470,480 (-88) -0.02% 3 (0)
DemeterCamelotFarmInheritTest 36,962,937 (-1,405,326) createFarm 169,898 (+42) +0.02% 284,650 (+42) +0.01% 243,916 (+42) +0.02% 440,136 (+42) +0.01% 3 (0)

@TechnoGeek01 TechnoGeek01 self-assigned this Feb 5, 2024
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/uniswapv3/uniswap/Demeter_UniV3Farm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Show resolved Hide resolved
test/BaseFarm.t.sol Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
@parv3213 parv3213 marked this pull request as ready for review February 8, 2024 06:44
@parv3213 parv3213 mentioned this pull request Feb 9, 2024
5 tasks
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
test/BaseFarm.t.sol Outdated Show resolved Hide resolved
@YashP16 YashP16 merged commit e721f6a into dev Feb 16, 2024
1 check passed
@YashP16 YashP16 deleted the test/optimization branch February 16, 2024 08:37
YashP16 added a commit that referenced this pull request Jul 12, 2024
* moved uniswap and balancer under e20 farms

* Added FARM_ID

* Initiated BaseFarm Test

* small update

* Improvements

* Improvements

* fix: Deployment artifacts file naming convention

* fix: Deployment artifacts file naming convention

* Make BaseFarm abstract

* used custom errors instead of require statements

* Add CI and husky. Other setup like USDsV2.

* Upper case constant variables

* Use forge fmt to format files
- Although skipping pre-commit for this commit, as formatted files may cause conflicts later

* Update solhint and fix solhint warnings

* Update CI

* optimized greater than zero checks for unsigned integers

* used unchecked in places where underflows are not possible. The if statements enclosing the calculations make sure they don't underflow

* Fix valid token check

* Remove `farmStartTime`

* Make `claimRewards(uint256 _depositId)` call `claimRewards(address _account, uint256 _depositId)` internally

* Add `_farmNotClosed` to `updateFarmStartTime` and `closeFarm`

* removed oldRewardRate from RewardRateUpdated event as it can be calculated from subgraph

* cached array length to save gas

* Lint fix

* Remove `getRewardTokens`

* Make `factory` immutable

* RewardAdded event in BaseFarm might require account which added the rewards. Added it as comments. Need to review

* Added depositId and removed tokenid,expirydate from CooldownInitiated event as they can be processed

* added depositId and removed tokenId,starttime in PoolUnsubscribed event as they can be processed

* optimized RewardsClaimed event to make it emit only once instead of twice in the _claimRewards function

* fixed rewardsForEachSubs nested array as mentioned in previous commit's comment. Also removed fundIds array from the RewardsClaimed event as fundId values are 0 and 1

* format of if statement condition is updated in updateFarmStartTime function for consistency. No change in functionality.

Co-authored-by: Parv Garg <parv3213@gmail.com>

* caching msg.sender will cost more gas than directly using it

* caching msg.sender will cost more gas than directly using it

* Added farm token check in recover erc20

* started testing

* created farms

* Added two directories in gitignore

* Added contributing.md

* Added engineering dev room

* Updated README.md

* Added farm factory registration requirement

* added more test cases

* added coverage-minimum command

* Added farm id in e20 farm

* Updated discounted fees

* removed initialization of loop vars

* Update contracts/e20-farms/BaseE20Farm.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

* perf(deposit fn): code optimisation

* replaced memory var account with msg.sender

* Updated userDeposit from memory to storage

* Update variables storage spaces to save gas

* Added more test cases

* Added deposit tests

* (test:Balancer E20 Farms) Coverage 80%

* integrated sushiswap V3 into demeter

* added more BaseFarm tests

* Fix failing build due to merge

* change filename to avoid conflicts with windows

* Added Withdraw test cases

* removed a unnecessary comment in the RewardAdded emit

* used custom errors instead of require statements

* removed duplicate custom error

* reused files from uniswapV3

* fixed arguments in Demeter_SushiV3FarmDeployer's constructor

* formatted Demeter_SushiV3FarmDeployer.sol to make it consistent with other files

* naming convention fix. CoolDown changed to Cooldown

* in RewardRateUpdated event marked rwdToken as indexed

* in CooldownInitiated event included indexed tokenid and expiry instead of depositid as tokenid is unique

* Added chore

* Update .gitignore

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Resolved @parv3213 Comments

* PR Fixes

* Fix package.json

* Format contracts

* Add husky to dev dependencies

* fix(Demeter Base Farm): Updated Test Cases

Updated Test Cases According to the new Contract Architecture,

BREAKING CHANGE:

* fix: removed Console from imports

* fix: Removed Console import from BaseFarm test file

* Fix file paths

* Format code

* Fix CI

* Fix gitignore

* forge install: forge-std

v1.7.1

* Simplify `foundry.toml`

* Fix file import

* test(Balancer Test Cases): Added Missing test cases

Added Claim Rewards and some view Functions test cases

* modularized sushi v3 and uni v3 codes

* fix: Resolve review comments

* sushiswapv3 FARM_ID name fix

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* uniswapv3 FARM_ID name fix

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* NPFM() return type fix

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Revert "NPFM() return type fix"

This reverts commit c2cb9a9.

* fix(BaseFarm Test Files): Fixed Repeated GetPoolAddress Method on Test Files

* Fix forge lib and removing unnecessary file

* Fix solhint errors

* forge install: forge-std

v1.7.1

* Fix lint error

* Add solhint checks to CI

* Remove prettier dependencies

* Update PR-CI and and

* Format code from `prettier` script

* Format code using `prettier` script

* Turn `contract-name-camelcase` off in solhint

* Fix solhint warnings

* Remove comment

* refactor(contracts): Make initiateCooldown and withdraw() accessible from BaseFarm

* test(utils): Add network configuration for tests

* test: Restructure test cases to make them modular

* test: Remove old test cases

* Fix import path in BaseE20Farm.t.sol

* test: Add setup modifier for tests

* feat(BaseFarm): Added a Non Zero Amount Check

Added a non Zero amount check in Add Rewards function

* test(BalancerFarm): Fixed not working test cases

* Solhint Functions ordering fixes

* fix(Commit Conflicts): Fixed Commit  Conflicts on test Cases

* Multiple fixes

- Uniswap pool initialization order in
BaseUniV3Farm
- Make `NFPM` and `UNIV3_FACTORY` public view
- Add required interfaces for UniswapV3
- Rename `Demeter_UniV3FarmDeployer` to `Demeter_SushiV3FarmDeployer`

* Add UniV3 Farm tests

* feat(Fuzzing tests): added fuzzing amounts tests

* Rename by adding `.t.sol` to tests

* feat(Balancer Farm): Added Test Cases Imports

* feat(Base Farm): Added Missing test cases

* feat(BaseE20Farm): Added Reverting Test Cases

* Updated BaseFarmDeployer

* Updated other deployers

* Updated farm factory

* Updated param in function getFees

* feat(BaseSetup): Fixed Owner= User Bug, Added More Actors , Added Factory Variable

* fix(BaseFarm): Owner actor shouldn't be user

* fix(FarmFactory): Added test cases for Farm Factory

* fix(BaseE20Farm): Fixed test cases when User Prank is not owner

* fix(BaseFarm): Minor Prank Fix

* Check for `_isNonZeroAmt` before `_farmNotClosed`

* Fix/improve tests

* fix(FarmFactory test cases): Solved Mehul's comments

* Updated Readme

* Add Multicall functionality to BaseFarm contract with tests

* fix(BaseFarm.t.sol ): Fix Parv's comments

- Fixed RevertsWhen Naming convetion
- Fixed ExpectEmit Failed assertions
- Added Maths tests

* fix(BaseE20Farm.t.sol ): Added Maths tests

Added Maths tests for increase Deposit and withdraw Partially functions

* fix(BalancerFarn.t.sol ): Fixed Parv's Comment

- Added a check on Farm ID
- Added Deposit Maths check

* fix(BaseFarm.t.sol ): Typo fix

test_deposit_noLockupFarm_revertsWhen_NoLiquidityInPosition fix

* fix(BaseFarm.t.sol BaseFarm.t.sol): Fixes Parv's Comments

* fix(BaseFarm.sol): Removed 0 amount Function check

* Fix solhint errors in tests

* Fix tests failing after merge

* getFeeParams external call updates

* Fixed test cases

* feat(BaseFarm.t.sol): Fixed ERC20Recover Coverage, Added two edge cases

- Fixed erc20Recover coverage
- Added two claim rewards edge cases

* feat(BaseE20Farm.t.sol): Added ERC20Recover Specific Logic

* feat(BalancerFarm.t.sol): Fixed ERC20Recover Specific Import

* feat(SushiV3Farm.t.sol): added ERC20Recover Import

* Merge remote-tracking branch 'origin/dev' into test/demeter-uniV3Farm

* Resolve solhint errors

* Rearrange _SetupFarmTest in BalancerFarm.t.sol

* Fix stack-too-deep error by adding NonfungiblePositionManagerUtils

- Sperax/Utility#2

* Add more MultiCall tests

* Add tests supporting BaseFarm coverage

* feat(BaseFarm): Remove Redundant check

- Remove Redundant check on  _subscribeRewardFund  & _unsubscribeRewardFund

* Refactor: Remove `uniswapUtils` & `nfpmUtils` from `UniswapPoolData`.

* Remove coverage-minimum script from package.json

* test(BaseFarm): Added Assertions

Added Claim Rewards Balances Assertions

* updated vault address in Arbitrum.t.sol (#30)

* Unique deposit ID and event data optimisation (#27)

* Code changes for unique depositId

* Updated test cases

* Added indexed parameter depositId

* Added a view function to get deposits of a user

* Removed getMyDeposit and deposit updates

* event data optimizations

* Code doc improvements

* Test cases compilation error fixes

* subscription to depend on deposit id

* Added deposits assignment before sub reward fund

* fix(deposit): storage write instead of memory

* Updated test cases

* fixed events in test files

* fix(event data): totalRewardsClaimed to refer from storage instead of memory

* Removed logs

* Added revert in getDeposit function

* updated test cases as per latest change in code

* fixed test cases

* Added PoolSubscribed event

* added miscellaneous test cases to check if one user's withdrawal of deposit affects other user's deposit

* added test cases in initiatecooldowntest to make sure someone else other than the depositor cannot initiate cooldown

* added missing emit event tests

* added missing event test in test_initiateCooldown_LockupFarm test case.

* added test cases to make sure one user's withdraw doesn't affect other users' subscriptions and deposits

* fixed a test case

* Gas optimisations

* Fixed review comments

* updated variable name

* Removed tokenId and simplified further

* Fixed test cases

* renamed mapping and updated _deposit function

* updated variable names instead of integer literals

* renamed test function names

* fixed a redundancy in test case

* optimized event testing

* fixed a event testing

* Updated updateTokenManager function and event name

* gas optimisations and code improvements

* Gas optimisation and function name change

* renamed updateRewardData function name

* Added mistakenly removed test case back

---------

Co-authored-by: mehultuteja <reachmehultuteja@gmail.com>
Co-authored-by: TechnoGeek01 <rsudharsangames@gmail.com>
Co-authored-by: YashP16 <yash.pitroda786@gmail.com>

* ci(github): Update CI to report gas difference (#34)

Using Rubilmax/foundry-gas-diff

* Revert "ci(github): Update CI to report gas difference (#34)" (#35)

This reverts commit 778bdc8.

* Feature to increase/ decrease liquidity from Camelot position while being staked in Demeter. (#26)

* Added increase and decrease liquidity func

* Fixed deployment and base errors

* Fixed errors

* Fixed all the pending test cases

* Added onNFTAddToPosition

* Added a view function for getting amounts

* Added onNFTWithdraw function

* test(BaseFarm): Added DepositIncreased/Decreased Events

* fix(CamelotFarm): Small Bug Fix

* test(CamelotFarm): Added test cases

Increase/ Decrease Deposit test cases

* Updated test case to fix failure

* test(CamelotFarm): Added test cases

Increase/ Decrease Deposit test cases

* Merge branch 'dev' into feat/camelot-farm-liq

* test(CamelotFarm): Added test cases

Increase/ Decrease Deposit test cases

* test(CamelotFarm): Added Test Cases

- Coverage is 98%
- Checked Maths on increase / Decrease Deposit

* Added Camelot Addresses

* fix(CamelotFarm.t.sol): Fixed Assets Naming

- Fixed Assets Naming
- Removed Constants from the test file

* Fix RecoverERC20E20FarmTest

* Updated Camelot interface file name

* Update contracts/camelot/Demeter_CamelotFarm.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Added update call and removed comments

* Removed redundant calls

* fix(Fix commented Tests): Fixed commented tests

* Updated test cases

* Refactor removeLiquidity function to use named parameters

* Moved subscriptions updater in abstract contract

* Updated tests for OperableDeposit changes

* updated docs for OperableDeposit changes

* fix(Test Cases): Fix function names to use proper capitalization

* perf(test): approval and naming conventions

* perf(Farms): approval function call and naming convention

* Fix function names to use proper capitalization

* Refactor deposit tests in Demeter_CamelotFarmTest

* refactor(CamelotFarm Testing): refractored test cases

* Add GetDepositTest and MulticallTest to DemeterCamelotFarmInheritTest

* Remove unused test cases in BaseE20Farm.t.sol

---------

Co-authored-by: mehultuteja <reachmehultuteja@gmail.com>
Co-authored-by: Dayaa <m.d.e.boutalbi@me.com>
Co-authored-by: Parv3213 <parv3213@gmail.com>

* ci(github): Update CI to report gas difference (#36)

Using Rubilmax/foundry-gas-diff

* feat/basefarm-upgrades (#25)

* added farm expiry and extension feature with extension fees

* standardization

* reordered functions as per solhint standards and errors

* fixed a bug in extendFarmEndTime function

* fixed a bug in extendFarmEndTime function

* updated function name for collecting extension fee

* optimization

* added some test cases

* updated test case

* added farm extension test cases

* added ExtensionFeeCollected event test case

* optimized updateFarmStartTime function

* optimized FarmEndTimeUpdated emit

* changed visibility of _collectExtensionFee in BaseFarm as private

* added constant for initial farm extension

* removed getFees function in BaseFarmDeployer as it's redundant

* removed FarmEndTimeUpdated emit in updateFarmStartTime function as it can be processed until farm starts

* added nonReentrant modifier to extendFarmEndTime function

* optimization

* fixed test cases

* function reordering to fix solhint errors

* added some missing assertions in FarmFactory.t.sol test cases

* removed unnecessary logs and comments

* event optimization

* updateFarmStartTime function optimization

* destructured farmInstance.iniitialize parameters

* extendFarmEndTime function gas optimization

* renamed the function extendFarmEndTime to extendFarmDuration

* removed creator field in ExtensionFeeCollected event

* fixed a bug

* renamed the function _farmNotClosedOrExpired to _farmNotClosedOrNotExpired

* added more test cases

* added some missing closeFarm test cases.

* updated missing natspec

* renamed the function _farmNotClosedOrNotExpired to _isFarmActive

* removed unnecessary fuzzing

* updated usds vault address to the latest one

* added internal function for farm expiry validation

* added test cases for some edge cases

* decoupled farm expiry feature in a separate abstract contract

* fixed solhint warnings

* decoupled farm expiry status function

* comment cleanup

* decoupled farmFactory state variable

* fixed some solhint errors

* fixed solhint warnings

* moved FarmNotYetStarted from BaseFarm to BaseFarmExpiry

* improved test cases

* made fee variables configurable in FarmFactory.t.sol

* fixed test_claimRewards_max_rewards test case

* renamed contract BaseFarmExpiry to BaseFarmWithExpiry

* removed logs

* added internal function _updateFarmStartTime

* update

* added missing test inheritances

* natspec update

* abstracted farm expiry test cases

* added constants instead of hardcoded values

* update

* Natspec update

Co-authored-by: arcantheon <140178288+arcantheon@users.noreply.github.com>

* Natspec update

Co-authored-by: arcantheon <140178288+arcantheon@users.noreply.github.com>

* added zero checks in updateFeeParams function of FarmFactory.sol

* updated natspec

* Revert "added zero checks in updateFeeParams function of FarmFactory.sol"

This reverts commit 9c080d3.

* added some missing test cases

* fixed fuzz runs in foundry.toml

* expiry test cases restructure

* updated natspec

* updated natspec

* updated natspec

* test case optimization and redundancy removal

* improved test cases

---------

Co-authored-by: arcantheon <140178288+arcantheon@users.noreply.github.com>

* Draft changes for chain agnostic contracts (#32)

* Draft changes for chain agnostic contracts

* fix(contracts): Fix problems

* fix: Bug fixes

* fix: Optimisation fixes

* fix(tests): fix failing tests

* fixed BaseE20Farm.t.sol test cases

* test fix

* fixed Demeter_CamelotFarm.t.sol test cases

---------

Co-authored-by: TechnoGeek01 <rsudharsangames@gmail.com>

* Storage, DataTypes separation and OperableDeposit simplification (#38)

* Storage, DataTypes separation and OperableDeposit simplification

* updated test cases to support separated DataTypes

* Usage of storage variables for gas optimization

* Using named imports instead of default

* abstracted contract BaseFarmStorage

* Moved OperableDeposit under features

* Removed constant parameters

* Restructured computeRewards function's return data in BaseFarm.sol (#39)

* restructured computeRewards return data

* updated natspec

* function naming convention fix and restructuring (#40)

* function naming convention changes

* restructured functions

* updated natspec

* bug fix

* functions rename

* function restructuring

* unused variable cleanup in test file

* function restructuring

* Demeter UniswapV3 Farm upgrades (#21)

* Add liquidity management functions to UniswapV3
interface

* Remove DepositInCooldown error and reuse
DepositIsInCooldown

* Add increaseDeposit and withdrawPartially
functions for UniV3 Farm

* Add ActiveLiquidityBaseV3Farm

- Farm that distributes rewards only for active liquidity
- Withdraw from locked position is allowed when liquidity is not active

* Fix tests after merge

* Rename `ActiveLiquidityBaseUniV3Farm` to `BaseUniV3ActiveLiquidityFarm`

* refactor(BaseUniV3Farm): Use NFPM utils to resolve stack-too-deep error

* test(BaseUniV3): add tests for increase/decrease liquidity

* test: bugfix and tests for BaseUniV3ActiveLiquidityFarm

* refactor: modularize BaseFarm and reduce duplicate code in BaseUniV3ActiveLiquidityFarm

* refactor and natspec fix

* Optimise contracts/uniswapV3/BaseUniV3ActiveLiquidityFarm.sol

Co-authored-by: Sudharsan R <34187497+TechnoGeek01@users.noreply.github.com>

* test: add missing test

* bug fix

* refactor: remove unchecked

* Update lastSecondsInside data type to uint32

* Update contracts/camelot/Demeter_CamelotFarm.sol

Co-authored-by: arcantheon <140178288+arcantheon@users.noreply.github.com>

* Update contracts/camelot/Demeter_CamelotFarm.sol

Co-authored-by: arcantheon <140178288+arcantheon@users.noreply.github.com>

* Refactor deposit token ID usage in Demeter_CamelotFarm.sol

---------

Co-authored-by: Sudharsan R <34187497+TechnoGeek01@users.noreply.github.com>
Co-authored-by: arcantheon <140178288+arcantheon@users.noreply.github.com>

* Abstracting NFT farms (BaseE721Farm.sol) (#42)

* refactor(farms): moved initiateCooldown to BaseFarm

* refactor(camelot): uncommented interface and override in contract

* Removed unused variables

* Added BaseE721Farm.sol

* Updated tests to reflect nftContract name update

* Moved common functionality to base and documentation update

* Updated test cases to support the changes

* moved _validateDeposit check under _withdraw()

* updated inheritance hierarchy

* updated natspec and removed virtual keyword

* Moved camelot and uniV3 under e721 farms

* moved nft tests under e721-farms and added BaseE721Farm

* removed unneeded typecasting

* refactored tests and moved common ones under BaseE721Farm.t.sol

* fixed imports related issues

* Merge branch 'dev' into feat/e721-farms

* fix: Fix imports

* fix: Fix imports

---------

Co-authored-by: mehultuteja <reachmehultuteja@gmail.com>
Co-authored-by: Parv3213 <parv3213@gmail.com>

* BaseFarm Optimizations (#33)

* perf(BaseFarm): Optimizations

* perf(BaseFarm): Optimizations

* Test case optimization (#41)

* test case optimization

* test case optimization

* test case optimization

* fix

* naming convention fix

* removed unnecessary fuzz in negative test cases

* rename and restructure of test cases

* removed asserts and emit tests from deposit helper function and wrote separate tests

* helper function optimization

* added camelot deposit test

* cleanup

* added missing test contract inheritance

* rename

* remove unnecessary fuzz for negative cases

* fuzz functions rename

* update

* test optimization

* optimization

* optimization

* cleanup

* optimization

* rename

* optimization

* rename

* cleanup

* update

* rename revert tests for consistency

* refactor(test): Remove redundant code from uniV3 test files

* refactor(contracts/BaseE20Farm): Remove redundancy in `recoverERC20` function

* refactor(test): Simplify test hierarchy

---------

Co-authored-by: Parv3213 <parv3213@gmail.com>
Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* fix(BaseFarm._setupFarm): Updated check for rwdTokens.length (#47)

* fix(BaseFarm._setupFarm): Fixed the check for rwdTokens.length

* Updated test cases for reward token data check bug fix

---------

Co-authored-by: mehultuteja <reachmehultuteja@gmail.com>

* optimized cooldown period (#45)

* optimized cooldown period

* refactor

Co-authored-by: Parv Garg <parv3213@gmail.com>

* updated natspec

* fix

* rename

* restructure

* updated _validateCooldownPeriod

* variable name simplification

* optimization

---------

Co-authored-by: Parv Garg <parv3213@gmail.com>

* code reuse optimization. (#48)

* optimization

* optimization

* rename

* optimization

* removed redundant check and did optimization

* rename

* decrease deposit further abstraction

* increase deposit further abstraction

* fix

* rename of contracts, files, variables, etc (#46)

* renamed BaseFarmWithExpiry to ExpirableFarm

* Removed Base from all the farm names

* renamed factory to registry

* rename

* update

* renamed camelot farms similar to univ2 and univ3

* natspec update

* natspec update

* removed forge docs

* removed Demeter_ from farm names

* added Demeter ascii logo in our contracts

* name fix

* rename

* name standardization

* Enabling fixed APR reward tokens for Demeter Protocol (#50)

* Initial version of DemeterRewarder contract

* Added fixed APR struct in DataTypes

* Added farmRegistered in farm registry's interface

* Added USDs oracle's interface

* Added apr description

* Demeter rewarder contract all functionalities

* First draft of DemeterRewarder

* Updated IFarmFactory -> IFarmRegistry

* Updated logo

* Added getTokenAmounts function for DemeterRewarder

* Implemented getTokenAmounts for CamelotV2

* Refactored from reward pool to individual rewarder

* Added natspec

* Implemented getTokenAmounts for univ2 and univ3

* Added call to _transferOwnership()

* Added rewards budget functionality

* Added a sample test script to test the functionality

* removed redundant variable declaration

* Removed farm registered function from interface

* removed redundant transfer ownership call

* Reconfigured _normalizeAmount to cache decimals

* Updated isFarmValid check

* Removed adjustment of rewardsPerSec

* Updated variable names introduced a constant for 1 weeks

* Added to farm validation logic

* Updated naming convention

* Made E20Farm abstract

* Fixed rewardRate bug

* Renamed struct and event name

* Added FixedAPRRewarderSPA

* Final version of FixedAPRRewarderSPA

* Rewarder improvisation updated and bug fixes

* Fixed APR rewarder for Legacy farms with simulation script

* Added recover erc20 and updated calibrateRewards

* Added total reward rate

* Added FarmRewardConfigParams

* Fixed failing test case

* Cached baseTokens indexes in farm's asset tokens

* Updated test script

* file restructuring, improved naming

* Arch change in Rewarder and legacy rewarder

* Added getRewardTokens test

* Added _isConfigured check and updateAPR function

* Updated function name

* Naming convention improvement and gas optimization.

* Update contracts/rewarder/RewarderFactory.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Update contracts/rewarder/RewarderFactory.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Added nonReentrant and made rewardTokens internal

* Added Average price consultation instead of spot

* Updated Uniswap utils

* Added test cases for rewarder

* Added isConfigured check in calibrateReward

* feat(calibrateReward): Added calibration restriction functionality

* Added a dependency comment

* Added update config test cases

---------

Co-authored-by: mehultuteja <reachmehultuteja@gmail.com>
Co-authored-by: Parv Garg <parv3213@gmail.com>

* optimized Uni V3 claim fee (#54)

* optimized claim fee

* asserted claim swap fee for uniswap v3

* added asserts for claim swap fee

* named imports

* Camelot V3 (#52)

* added Camelot V3

* initial test setup

* added camelot v3 nfpm utils contract address

* test fix

* added test cases

* update

* optimization -> removed unnecessary dependency contract

* update

* tested edge cases -> farm functionality after tickspacing change

* update

* fix

* update

* cleanup

* removed unnecessary nfpmutils contract

* Revert "removed unnecessary nfpmutils contract"

This reverts commit 1a53eb8.

* reintroduced camelot utils as it's required later

* update

* added rewarder functionality for camelot v3

* fix

* updated camelot utils contract address

* cleanup

* removed unused package

* rename

* cleanup

* cleanup

* added gettokenamounts test

* update

* improved camelot fee test case

* removed redundant test cases

* code reuse

* removed redundant code

* updated initialize with a single struct param

* named imports

* natspec update

* natspec update

---------

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Perf/solidity version to 0.8.24 (#55)

* Updated openzeppelin version

* Upgraded version and fixed ReentrancyGuard path

* Ownable constructor param added

* Updated UniV3 initialize params

* Updated solhint compiler version

* Fixed breaking changes and solhint warnings

* Removed underscores from struct member's definition

* perf: minor changes

* Updated OZ dependencies

---------

Co-authored-by: Parv3213 <parv3213@gmail.com>

* fixed a test case (#56)

* fixed a test case

* update naming

* testing improvement (#59)

* fixed a camelot v3 test case

* test optimization

* Test/demeter rewarder (#57)

* Initial version of DemeterRewarder contract

* Added fixed APR struct in DataTypes

* Added farmRegistered in farm registry's interface

* Added USDs oracle's interface

* Added apr description

* Demeter rewarder contract all functionalities

* First draft of DemeterRewarder

* Updated IFarmFactory -> IFarmRegistry

* Updated logo

* Added getTokenAmounts function for DemeterRewarder

* Implemented getTokenAmounts for CamelotV2

* Refactored from reward pool to individual rewarder

* Added natspec

* Implemented getTokenAmounts for univ2 and univ3

* Added call to _transferOwnership()

* Added rewards budget functionality

* Added a sample test script to test the functionality

* removed redundant variable declaration

* Removed farm registered function from interface

* removed redundant transfer ownership call

* Reconfigured _normalizeAmount to cache decimals

* Updated isFarmValid check

* Removed adjustment of rewardsPerSec

* Updated variable names introduced a constant for 1 weeks

* Added to farm validation logic

* Updated naming convention

* Made E20Farm abstract

* Fixed rewardRate bug

* Renamed struct and event name

* Added FixedAPRRewarderSPA

* Final version of FixedAPRRewarderSPA

* Rewarder improvisation updated and bug fixes

* Fixed APR rewarder for Legacy farms with simulation script

* Added recover erc20 and updated calibrateRewards

* Added total reward rate

* Added FarmRewardConfigParams

* Fixed failing test case

* Cached baseTokens indexes in farm's asset tokens

* Updated test script

* file restructuring, improved naming

* Arch change in Rewarder and legacy rewarder

* Added getRewardTokens test

* Added _isConfigured check and updateAPR function

* Updated function name

* Naming convention improvement and gas optimization.

* Update contracts/rewarder/RewarderFactory.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Update contracts/rewarder/RewarderFactory.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Added nonReentrant and made rewardTokens internal

* Added Average price consultation instead of spot

* Updated Uniswap utils

* Added test cases for rewarder

* Added isConfigured check in calibrateReward

* feat(calibrateReward): Added calibration restriction functionality

* Added a dependency comment

* Added update config test cases

* Merge branch 'dev' into test/Demeter-rewarder

* Completed rewarder test cases

* variable naming updated

* Updated var names

---------

Co-authored-by: mehultuteja <reachmehultuteja@gmail.com>
Co-authored-by: Parv Garg <parv3213@gmail.com>
Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Natspec update for demeter protocol. (#58)

* updated natspec

* updated natspec for TokenUtils.sol

* correction

* update

* update

* natspec consistency update

* Update contracts/e20-farms/E20Farm.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Update contracts/e721-farms/E721Farm.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Update contracts/e721-farms/camelotV2/CamelotV2Farm.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

* added demeter logo in TokenUtils.sol

* update

* update

---------

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Farm optimisations (#60)

* Optimised Farm

* Updated test cases

* Update contracts/Farm.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Update contracts/Farm.sol

---------

Co-authored-by: Parv Garg <parv3213@gmail.com>

* feat: Use OpenZeppelin SafeCast for preventing unexpected cases (#62)

* Audit Fixes: QS-1 (#61)

* feat: Add failing test for deposit before farm start time

* bug: if `lastFundUpdateTime` is greater than block time, return 0. Instead of underflow.

* fix: Fix multiple time related problem:

1. Add `farmStartTime` in place of `lastFundUpdateTime`
2. Change logic when `lastFundUpdateTime` is updated. This is added to fix problems in UniV3ActiveFarm
3. Fixed testcases for the changes

* chore: better comments

* chore: rename `_currentFarmStartTime` to `currentFarmStartTime`

* bug: add check if `lastFundUpdateTime == 0`, if so return 0.

This will update lastFundUpdateTime = block.timestamp in the same transaction, and will start accruing rewards from from the next tx onwards

* Audit Fixes: QS-9 (#63)

* refactor: Update privilege address mapping name in FarmRegistry.sol for clarity

* chore: rename `_userAddress` to `_user`

---------

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* fix(Rewarder): consider acculumated rewards instead of balance (#65)

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Audit Fixes QS-7 (#66)

* perf(Reward rate calculation): Fixed precision loss

* Added formula in comment for rewardRate calculation

---------

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Audit Fixes QS-8 (#67)

* feat(RewarderFactory): added a function to update the rewarderImplementation

* Added rewarder factory test cases

* Moved ORACLE declaration to Arbitrum.t.sol

---------

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Audit Fixes QS-13 (#68)

* fix(Rewarder): added a function to call farm.recoverRewardFunds

* Added test cases for recoverRewardFundsOfFarm of Rewarder contract

---------

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Audit Fixes: QS-3 (#64)

* QS-3: Introduced depositTs to prevent rewards inflation

* Used variable to access depositTs

* Updated test cases

* perf(test): Removed redundant test

* Renamed error

---------

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Audit Fixes QS-17 and rewardRate precision bug (#70)

* fix(Rewarder): added a function to call farm.recoverRewardFunds

* Added test cases for recoverRewardFundsOfFarm of Rewarder contract

* fix(NormalizeAmountRewarder): handle >18 precision and adjusts total value

* Added and updated test cases

* refactor(formatting): Rewarder

* refactor(Rewarder): _normalizeAmount does not need to check decimals as it is added while configuration

* perf(Rewarder): _normalizeAmount uses REWARD_TOKEN_DECIMALS directly from storage

* Revert "perf(Rewarder): _normalizeAmount uses REWARD_TOKEN_DECIMALS directly from storage"

This reverts commit c86cf2c401d0d7cfa1f5e35c65c6a41fbd17db24.

* Updated test cases

* perf(Rewarder): _normalizeAmount uses REWARD_TOKEN_DECIMALS directly from storage

---------

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Moved transfer at the end (#71)

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Audit Fixes QS-16 (#73)

* Updated precision assignment to make it consistent with APR_PRECISION

* Fixed implementation contract's meaningful state

* Revert "Fixed implementation contract's meaningful state"

This reverts commit cd42a5b.

* fix: make `_updateFarmRewardData` public and rename to `updateFarmRewardData` (#74)

1. `updateFarmRewardData` will allow users/dapp to call this function externally to accrue rewards.
2. `updateFarmRewardData` function can now also be triggered externally before `farmEndTime` to accrue user rewards. Which otherwise cannot be accrued after farm expiry.

Co-authored-by: arcantheon <140178288+arcantheon@users.noreply.github.com>

* feat: remove LegacyFarmRewarder (#81)

* Audit Fixed QS-14 (#72)

* perf(Farms): removed repetitive inheritence

* fix(state of implementation contracts)

* fix: make `_updateFarmRewardData` public and rename to `updateFarmRewardData` (#74)

1. `updateFarmRewardData` will allow users/dapp to call this function externally to accrue rewards.
2. `updateFarmRewardData` function can now also be triggered externally before `farmEndTime` to accrue user rewards. Which otherwise cannot be accrued after farm expiry.

Co-authored-by: arcantheon <140178288+arcantheon@users.noreply.github.com>

* feat: remove LegacyFarmRewarder (#81)

* atomic inheritence, operable deposit and expirable farms

* revert: reverting all changes related to changing initializer modifier

- This change is better suited for another PR

* refactor(recoverERC20): internal function instead of external function

* Moved onlyOwner modifier to the lower level function call

* refactor(E20 farms): initialization

* Update contracts/Farm.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

---------

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Audit Fixes QS-11 (#77)

* perf: Add error for insufficient liquidity in OperableDeposit contract

* perf: Validate reward token before accessing reward rates and balance

* feat: Add error for already registered farm

* feat: Add input validations for `updateFarmImplementation`

* bug: fix `computeRewards` calculations to include rewards already accrued in previous subscriptions

- This bug was noticed when rewardRates are high. So `test_claimRewards` is modified to test with max reward rates.
- Max reward rates can only be upto uint128, this will be enforced in coming commits

* fix: limit reward rate to `uint128`

- This is to ensure other logical error do not occur with an exceptionally large value of rewardRate
- One test  case is failing

* feat: Add input validation for registerFarm function

---------

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Audit Fixes QS-10 (#75)

* perf(Farms): removed repetitive inheritence

* fix(state of implementation contracts)

* Commented unneeded contracts

* Updated dependencies

* Moved transfer at the end (#71)

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Audit Fixes QS-17 and rewardRate precision bug (#70)

* fix(Rewarder): added a function to call farm.recoverRewardFunds

* Added test cases for recoverRewardFundsOfFarm of Rewarder contract

* fix(NormalizeAmountRewarder): handle >18 precision and adjusts total value

* Added and updated test cases

* refactor(formatting): Rewarder

* refactor(Rewarder): _normalizeAmount does not need to check decimals as it is added while configuration

* perf(Rewarder): _normalizeAmount uses REWARD_TOKEN_DECIMALS directly from storage

* Revert "perf(Rewarder): _normalizeAmount uses REWARD_TOKEN_DECIMALS directly from storage"

This reverts commit c86cf2c401d0d7cfa1f5e35c65c6a41fbd17db24.

* Updated test cases

* perf(Rewarder): _normalizeAmount uses REWARD_TOKEN_DECIMALS directly from storage

---------

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Moved initializer modifier in the external initialize function

* Removed unneeded code

* fix: Add ExpirableFarm to CamelotV2Farm, CamelotV3Farm, and UniV3Farm

---------

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>
Co-authored-by: Parv3213 <parv3213@gmail.com>

* Audit Fixes QS-S-2 (#78)

* perf: use existing `PREC` in place of `PRECISION`

* perf: rename `PREC` to `PRECISION` for clarity

* perf: caching lpToken, token0 and token1 for further gas-optimization

* Revert "perf: caching lpToken, token0 and token1 for further gas-optimization"

This reverts commit ff5646a.

* fix: rebase missed changes

* feat: Make `farms` and `deployerList` internal

The code changes add two internal arrays, `farms` and `deployerList`, to the `FarmRegistry` contract. These arrays will be used to track the registered farms and deployers respectively. This change is necessary to improve the efficiency and organization of the contract.

* Improved code documentation (#79)

* fix: limit farm extension duration to prevent exceeding maximum extension limit (#82)

The commit fixes a bug where the farm extension duration was not being properly limited, allowing it to exceed the maximum extension limit. The code now checks if the new farm end time exceeds the maximum extension limit and reverts the transaction with the "DurationExceeded" error if it does. This ensures that the farm extension duration stays within the allowed range.

* Audit Fixes: QS-S-5 (#83)

* Added FarmEndTimeUpdated to updateFarmStartTime

* Updated test cases

* Update contracts/features/ExpirableFarm.sol

Co-authored-by: Parv Garg <parv3213@gmail.com>

* Added a space

---------

Co-authored-by: Parv Garg <parv3213@gmail.com>
Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Audit Fixed: Best Practices (#80)

* perf: remove Unchecked loop increments recommended by QS

* perf: remove Unchecked loop increments from other places

* chore: Update tick range validation to use constants

* perf: caching lpToken, token0 and token1 for further gas-optimization

* perf: mark all address parameters as indexed

* fix: use events definitions directly from contracts

- this ensures we have the events dynamically updated

* fix: resolve solhint warnings

---------

Co-authored-by: arcantheon <140178288+arcantheon@users.noreply.github.com>
Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

* Audit Fixes QS-S-3 (#84)

* feat: Farm inherits for IFarm.

* feat: use IFarm or other abstract import to call functions on Farm in test files

* feat: FarmRegistry inherits for IFarmRegistry. Use IFarmRegistry for calling functions from FarmRegistry in tests.

* feat: RewarderFactory inherits for IRewarderFactory. Use IRewarderFactory for calling functions from RewarderFactory in tests.

* feat: Rewarder inherits for IRewarder. Use IRewarder for calling functions from Rewarder in tests.

* Solc upgrade to 0.8.26 (#85)

* chore(all-contracts): upgraded solc to 0.8.26

* Updated solc version for IRewarder

* Added a functionality to claimRewardsTo another account (#86)

* feat(claimRewards): Added an option to send rewards to another account

* Updated test cases

* Updated test cases

* Move claimPoolFee from UniV3Farm and CamelotV3Farm to E721Farm (#87)

* Moved claimPoolFee from Uni, Camelot farms to E721 Farm

* Updated test cases

* refactor(UniV3 and CamelotV3): Moved claimPoolFee as a separate feature

* Updated test cases

* Deploy/demeter (#88)

* feat(CamelotV3Farm): Non expirable version

* Updated test cases for Camelot v3 non expirable farms

* Removed commented code

* Added brownie utils contracts

* Added configuration for FarmRegistry, Rewarder and CamelotV3Deployer

* refactor(contracts): Make TokenUtils functions internal

* refactor(scripts ): Use oz packages in deployment script

* Brownie config changes

* Deployment data for Demeter v2 initial deployment

* Removed useless py files and tests

* Added audit report

* Added preset script and farm creation constant

* Removed comments and added farm in preset

* Removed unneeded line

---------

Co-authored-by: Yash Pitroda <yash.pitroda786@gmail.com>

---------

Co-authored-by: mehultuteja <arcantheon@gmail.com>
Co-authored-by: Dayaa <m.d.e.boutalbi@me.com>
Co-authored-by: Parv3213 <parv3213@gmail.com>
Co-authored-by: TechnoGeek01 <rsudharsangames@gmail.com>
Co-authored-by: Sudharsan R <34187497+TechnoGeek01@users.noreply.github.com>
Co-authored-by: arcantheon <140178288+arcantheon@users.noreply.github.com>
Co-authored-by: mehultuteja <reachmehultuteja@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants