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

Fixed Lens withdrawable calculation #1253

Merged
merged 4 commits into from
Aug 29, 2022
Merged

Fixed Lens withdrawable calculation #1253

merged 4 commits into from
Aug 29, 2022

Conversation

Rubilmax
Copy link
Collaborator

Pull Request

Issue(s) fixed

The test added was failing before

Copy link
Collaborator

@julien-devatom julien-devatom left a comment

Choose a reason for hiding this comment

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

A quick win test is to check if you withdraw a bit more than withdrawable, It should revert

@github-actions
Copy link

github-actions bot commented Aug 26, 2022

Morpho-aave-v2 gas impacts (eth-mainnet)

Generated at commit: 05cbc9b50dcd70f98ddc33ca04bdbacae1198080, compared to commit: bb9ae204bf8e39db019bb50d6d8511687b881480

🧾 Summary

Contract Method Avg (+/-) %
Lens getUserMaxCapacitiesForAsset +8,100 ❌ +6.31%
ExitPositionsManager withdrawLogic -2,242 ✅ -1.10%
Morpho borrow(address,uint256)
withdraw
-295 ✅
-1,862 ✅
-0.07%
-0.96%
InterestRatesManager updateIndexes -9 ✅ -0.07%
EntryPositionsManager borrowLogic -260 ✅ -0.07%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
Lens 4,059,856 (+48,059) getUserMaxCapacitiesForAsset 90,911 (+8,142) +9.84% 136,410 (+8,100) +6.31% 129,081 (+4,065) +3.25% 198,664 (+21,395) +12.07% 23 (0)
ExitPositionsManager 3,623,029 (0) withdrawLogic 724 (0) 0.00% 202,210 (-2,242) -1.10% 121,707 (0) 0.00% 2,111,229 (0) 0.00% 79 (+1)
Morpho 3,242,553 (0) borrow(address,uint256)
withdraw
4,076 (0)
4,101 (0)
0.00%
0.00%
401,540 (-295)
192,953 (-1,862)
-0.07%
-0.96%
385,464 (0)
125,667 (0)
0.00%
0.00%
1,896,576 (0)
2,118,789 (0)
0.00%
0.00%
245 (0)
85 (+1)
InterestRatesManager 803,602 (0) updateIndexes 634 (0) 0.00% 12,923 (-9) -0.07% 14,185 (0) 0.00% 51,585 (0) 0.00% 2,709 (+2)
EntryPositionsManager 2,795,405 (0) borrowLogic 490 (0) 0.00% 380,105 (-260) -0.07% 253,176 (0) 0.00% 1,892,655 (0) 0.00% 279 (0)

@github-actions
Copy link

github-actions bot commented Aug 26, 2022

Morpho-aave-v2 gas impacts (polygon-mainnet)

Generated at commit: 05cbc9b50dcd70f98ddc33ca04bdbacae1198080, compared to commit: bb9ae204bf8e39db019bb50d6d8511687b881480

🧾 Summary

Contract Method Avg (+/-) %
Lens getUserMaxCapacitiesForAsset +10,467 ❌ +8.15%
ExitPositionsManager withdrawLogic -2,227 ✅ -1.10%
Morpho borrow(address,uint256)
withdraw
-373 ✅
-1,847 ✅
-0.09%
-0.95%
EntryPositionsManager borrowLogic -328 ✅ -0.09%
InterestRatesManager updateIndexes -9 ✅ -0.07%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
Lens 4,059,856 (+48,059) getUserMaxCapacitiesForAsset 91,048 (+8,189) +9.88% 138,881 (+10,467) +8.15% 131,787 (+6,681) +5.34% 196,497 (+19,138) +10.79% 23 (0)
ExitPositionsManager 3,623,029 (0) withdrawLogic 724 (0) 0.00% 201,055 (-2,227) -1.10% 113,376 (-456) -0.40% 2,098,211 (0) 0.00% 79 (+1)
Morpho 3,242,553 (0) borrow(address,uint256)
withdraw
4,076 (0)
4,101 (0)
0.00%
0.00%
403,599 (-373)
191,881 (-1,847)
-0.09%
-0.95%
386,387 (0)
117,336 (0)
0.00%
0.00%
1,902,240 (0)
2,105,771 (0)
0.00%
0.00%
245 (0)
85 (+1)
EntryPositionsManager 2,795,405 (0) borrowLogic 490 (0) 0.00% 381,800 (-328) -0.09% 244,807 (0) 0.00% 1,898,319 (0) 0.00% 279 (0)
InterestRatesManager 803,602 (0) updateIndexes 634 (0) 0.00% 12,923 (-9) -0.07% 14,185 (0) 0.00% 51,585 (0) 0.00% 2,709 (+2)

@github-actions
Copy link

github-actions bot commented Aug 26, 2022

Morpho-aave-v2 gas impacts (avalanche-mainnet)

Generated at commit: 05cbc9b50dcd70f98ddc33ca04bdbacae1198080, compared to commit: bb9ae204bf8e39db019bb50d6d8511687b881480

🧾 Summary

Contract Method Avg (+/-) %
Lens computeLiquidationRepayAmount
getUserMaxCapacitiesForAsset
+6,194 ❌
+8,227 ❌
+6.35%
+6.41%
ExitPositionsManager withdrawLogic -2,165 ✅ -1.09%
Morpho borrow(address,uint256)
borrowBalanceInOf
deltas
market
p2pBorrowIndex
p2pSupplyIndex
poolIndexes
supplyBalanceInOf
withdraw
-282 ✅
-2 ✅
-4 ✅
-1 ✅
-1 ✅
-1 ✅
-2 ✅
-2 ✅
-1,794 ✅
-0.07%
-0.11%
-0.24%
-0.09%
-0.12%
-0.13%
-0.20%
-0.13%
-0.95%
InterestRatesManager updateIndexes -9 ✅ -0.07%
EntryPositionsManager borrowLogic -248 ✅ -0.07%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
Lens 4,059,856 (+48,059) computeLiquidationRepayAmount
getUserMaxCapacitiesForAsset
73,735 (0)
90,712 (+7,853)
0.00%
+9.48%
103,814 (+6,194)
136,641 (+8,227)
+6.35%
+6.41%
117,097 (+30,098)
130,212 (+5,106)
+34.60%
+4.08%
125,046 (0)
191,465 (+14,106)
0.00%
+7.95%
7 (0)
23 (0)
ExitPositionsManager 3,623,029 (0) withdrawLogic 724 (0) 0.00% 196,203 (-2,165) -1.09% 112,148 (0) 0.00% 2,110,183 (0) 0.00% 79 (+1)
Morpho 3,242,553 (0) borrow(address,uint256)
borrowBalanceInOf
deltas
market
p2pBorrowIndex
p2pSupplyIndex
poolIndexes
supplyBalanceInOf
withdraw
4,076 (0)
894 (0)
1,028 (0)
964 (0)
637 (0)
591 (0)
764 (0)
936 (0)
4,101 (0)
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
396,120 (-282)
1,803 (-2)
1,629 (-4)
1,141 (-1)
835 (-1)
789 (-1)
985 (-2)
1,480 (-2)
187,371 (-1,794)
-0.07%
-0.11%
-0.24%
-0.09%
-0.12%
-0.13%
-0.20%
-0.13%
-0.95%
385,422 (0)
894 (0)
1,028 (0)
964 (0)
637 (0)
591 (0)
764 (0)
936 (0)
116,108 (0)
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
1,895,848 (0)
4,894 (0)
9,028 (0)
2,964 (0)
2,637 (0)
2,591 (0)
2,764 (0)
4,936 (0)
2,117,743 (0)
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
0.00%
245 (0)
330 (+1)
359 (+2)
315 (+2)
232 (+1)
232 (+1)
244 (+2)
316 (+1)
85 (+1)
InterestRatesManager 803,602 (0) updateIndexes 634 (0) 0.00% 12,923 (-9) -0.07% 14,185 (0) 0.00% 51,585 (0) 0.00% 2,709 (+2)
EntryPositionsManager 2,795,405 (0) borrowLogic 490 (0) 0.00% 375,066 (-248) -0.07% 243,216 (0) 0.00% 1,891,928 (0) 0.00% 279 (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 one question but overall agree with the change

contracts/aave-v2/lens/UsersLens.sol Outdated Show resolved Hide resolved
Copy link
Collaborator

@QGarchery QGarchery left a comment

Choose a reason for hiding this comment

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

Great work ! Some changes to do. Also maybe you can decompose the code into smaller part, for example with the _testShouldRepayMarketP2PAndFromPool test

Makefile Outdated Show resolved Hide resolved
test-foundry/prod/compound/setup/TestSetup.sol Outdated Show resolved Hide resolved
config/eth-mainnet/compound/Config.sol Outdated Show resolved Hide resolved
contracts/aave-v2/lens/UsersLens.sol Outdated Show resolved Hide resolved
test-foundry/prod/compound/TestBorrow.t.sol Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Aug 29, 2022

Morpho-compound gas impacts (eth-mainnet)

Generated at commit: 05cbc9b50dcd70f98ddc33ca04bdbacae1198080, compared to commit: bb9ae204bf8e39db019bb50d6d8511687b881480

🧾 Summary

Contract Method Avg (+/-) %
Morpho cEth -1,740 ✅ -72.35%
Lens getUserMaxCapacitiesForAsset +4,026 ❌ +4.07%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
Morpho 3,103,978 (0) cEth 405 (-2,000) -83.16% 665 (-1,740) -72.35% 405 (-2,000) -83.16% 2,405 (0) 0.00% 23 (+21)
Lens 4,875,711 (+77,508) getUserMaxCapacitiesForAsset 11,860 (0) 0.00% 102,825 (+4,026) +4.07% 91,300 (+4,474) +5.15% 165,899 (+3,915) +2.42% 22 (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.

LGTM

@Rubilmax Rubilmax changed the base branch from dev to main August 29, 2022 08:27
@Rubilmax Rubilmax changed the base branch from main to dev August 29, 2022 08:28
@Rubilmax Rubilmax changed the base branch from dev to main August 29, 2022 08:46
Copy link
Collaborator

@QGarchery QGarchery left a comment

Choose a reason for hiding this comment

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

LGTM

contracts/aave-v2/lens/UsersLens.sol Outdated Show resolved Hide resolved
contracts/aave-v2/lens/UsersLens.sol Outdated Show resolved Hide resolved
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

@Rubilmax Rubilmax merged commit c50f273 into main Aug 29, 2022
@Rubilmax Rubilmax deleted the fix/lens-withdrawable branch August 29, 2022 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants