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

Remove claimRewards double call #228

Merged
merged 7 commits into from Dec 19, 2022
Merged

Conversation

Rubilmax
Copy link
Contributor

@Rubilmax Rubilmax commented Dec 15, 2022

Pull Request

Issue(s) fixed

This pull request fixes #220

It also harmonizes the way we manage rewards, so that most of the code of morpho-compound's tokenized vaults is duplicated in morpho-aave-v3's vault, with an additional dimension: rewardToken

Look at the gas diff below (they are not broken @MathisGD)! 🚀

@Rubilmax Rubilmax changed the base branch from main to upgrade-0 December 15, 2022 11:21
@Rubilmax Rubilmax force-pushed the fix/claim-rewards-called-twice branch from 2304cf4 to ed732e5 Compare December 15, 2022 11:22
@github-actions
Copy link

github-actions bot commented Dec 15, 2022

Morpho-compound-eth-mainnet gas diffs

Generated at commit: 3bf57c799ca1c496bc25a1db9f0649ad68809129, compared to commit: 355adbcc54b58da1b536afc60c6938e53ecbace5

🧾 Summary (20% most significant diffs)

Contract Method Avg (+/-) %
SupplyVault contract mint
redeem
transfer
transferFrom
withdraw
-25,891 ✅
-30,960 ✅
-16,005 ✅
-16,207 ✅
-36,465 ✅
-7.04%
-8.90%
-8.70%
-7.96%
-8.29%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
SupplyVault contract 3,068,158 (+5,808) claimRewards
deposit
mint
redeem
transfer
transferFrom
withdraw
14,978 (-1,904)
278,424 (-34,564)
151,062 (-8,961)
3,766 (0)
88,165 (-18,800)
90,229 (-17,807)
20,909 (0)
-11.28%
-11.04%
-5.60%
0.00%
-17.58%
-16.48%
0.00%
61,640 (-921)
522,585 (-18,289)
341,817 (-25,891)
316,989 (-30,960)
167,863 (-16,005)
187,446 (-16,207)
403,361 (-36,465)
-1.47%
-3.38%
-7.04%
-8.90%
-8.70%
-7.96%
-8.29%
33,011 (+96)
571,812 (-8,978)
336,444 (-42,811)
371,980 (-34,568)
132,825 (-14,607)
187,446 (-16,207)
398,404 (-34,567)
+0.29%
-1.55%
-11.29%
-8.50%
-9.91%
-7.96%
-7.98%
250,553 (+96)
575,212 (-8,978)
543,321 (-8,978)
571,884 (-51,052)
282,600 (-14,607)
284,664 (-14,607)
585,715 (-51,052)
+0.04%
-1.54%
-1.63%
-8.20%
-4.91%
-4.88%
-8.02%
21 (0)
38 (0)
4 (0)
19 (0)
3 (0)
2 (0)
7 (0)

@morpho-org morpho-org deleted a comment from github-actions bot Dec 15, 2022
@morpho-org morpho-org deleted a comment from github-actions bot Dec 15, 2022
@codecov-commenter
Copy link

codecov-commenter commented Dec 15, 2022

Codecov Report

Merging #228 (ad7d519) into upgrade-0 (36b26a4) will increase coverage by 0.42%.
The diff coverage is 100.00%.

@@              Coverage Diff              @@
##           upgrade-0     #228      +/-   ##
=============================================
+ Coverage      46.79%   47.22%   +0.42%     
=============================================
  Files             15       15              
  Lines            359      360       +1     
  Branches          12       11       -1     
=============================================
+ Hits             168      170       +2     
  Misses           189      189              
+ Partials           2        1       -1     
Impacted Files Coverage Δ
src/aave-v3/SupplyVault.sol 82.75% <100.00%> (+2.75%) ⬆️
src/compound/SupplyVault.sol 92.59% <100.00%> (-0.52%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@MerlinEgalite MerlinEgalite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Can we do it for Aave V3 as well?

@Rubilmax Rubilmax marked this pull request as draft December 15, 2022 14:10
@Rubilmax Rubilmax marked this pull request as ready for review December 15, 2022 15:01
@github-actions
Copy link

github-actions bot commented Dec 15, 2022

Morpho-aave-v3-avalanche-mainnet gas diffs

Generated at commit: 3bf57c799ca1c496bc25a1db9f0649ad68809129, compared to commit: 355adbcc54b58da1b536afc60c6938e53ecbace5

🧾 Summary (20% most significant diffs)

Contract Method Avg (+/-) %
SupplyVault contract mint
redeem
transfer
transferFrom
withdraw
-103,617 ✅
-81,622 ✅
-44,935 ✅
-41,655 ✅
-76,300 ✅
-19.98%
-32.25%
-28.30%
-25.42%
-28.90%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
SupplyVault contract 3,669,134 (-50,881) claimRewards
deposit
mint
redeem
transfer
transferFrom
withdraw
53,557 (-2,907)
191,940 (-84,731)
253,724 (-106,022)
3,793 (0)
66,679 (-42,435)
68,760 (-41,012)
10,756 (0)
-5.15%
-30.63%
-29.47%
0.00%
-38.89%
-37.36%
0.00%
72,078 (-3,697)
575,541 (-103,355)
415,019 (-103,617)
171,437 (-81,622)
113,870 (-44,935)
122,196 (-41,655)
187,677 (-76,300)
-4.88%
-15.22%
-19.98%
-32.25%
-28.30%
-25.42%
-28.90%
67,368 (-3,954)
670,630 (-102,425)
324,635 (-102,406)
179,700 (-88,255)
100,592 (-42,298)
122,196 (-41,655)
184,670 (-84,734)
-5.54%
-13.25%
-23.98%
-32.94%
-29.60%
-25.42%
-31.45%
140,510 (-3,755)
675,430 (-102,425)
666,699 (-102,423)
278,028 (-126,919)
174,340 (-50,072)
175,633 (-42,298)
282,774 (-106,016)
-2.60%
-13.17%
-13.32%
-31.34%
-22.31%
-19.41%
-27.27%
15 (0)
33 (0)
3 (0)
21 (0)
3 (0)
2 (0)
5 (0)

Copy link
Contributor

@MerlinEgalite MerlinEgalite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion

_accrueUnclaimedRewardsFromRewardsIndex(from, newRewardsIndex);
_accrueUnclaimedRewardsFromRewardsIndex(to, newRewardsIndex);

super._beforeTokenTransfer(from, to, amount);
}

function _claimRewards() internal returns (uint256 newRewardsIndex) {
function _claimVaultRewards() internal returns (uint256 newRewardsIndex) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change the name? IMO it's clear enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there's the external function claimRewards and it may suggest that this internal function is the implementation to claimRewards

src/aave-v3/SupplyVault.sol Outdated Show resolved Hide resolved
@@ -469,21 +469,6 @@ contract TestSupplyVault is TestSetupVaults {
assertApproxEqAbs(uint256(userReward1_1), userReward1_2, 1);
}

// TODO: fix this test by using updated indexes in previewMint
// function testShouldMintCorrectAmountWhenMorphoPoolIndexesOutdated() public {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you re-try this test? Perhaps redundant to new tests though..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is redundant yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it is passing, except on aave-v3 on which the lens was not added

src/compound/SupplyVault.sol Show resolved Hide resolved
src/aave-v3/SupplyVault.sol Outdated Show resolved Hide resolved
@Rubilmax Rubilmax merged commit 046f8bf into upgrade-0 Dec 19, 2022
@Rubilmax Rubilmax deleted the fix/claim-rewards-called-twice branch December 19, 2022 15:02
@MathisGD
Copy link
Contributor

Wow the gas diff 🕺

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.

Morpho.claimRewards is called twice on transfer
5 participants