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

refactor: Auto _setBalanceInfo #20

Merged
merged 2 commits into from
Jul 2, 2024

Conversation

deluca-mike
Copy link
Collaborator

@deluca-mike deluca-mike commented Jun 28, 2024

_setBalanceInfo now always takes the amount and index (if any) and computes the principal, so no more awkward handling of "raw balance" that is either pincipla or present amounts. Similarly, _getBalanceInfo now returns explicit principal and present amounts for the balance, saving lines elsewhere and getting rid of the awkward handling of "raw balance".

@deluca-mike deluca-mike added the enhancement New feature or request label Jun 28, 2024
@deluca-mike deluca-mike self-assigned this Jun 28, 2024
Copy link

github-actions bot commented Jun 28, 2024

Changes to gas cost

Generated at commit: 3c6c0cf19d78624b6398323cdf289dae9d4ffd65, compared to commit: 72ceab38cce6b6db88009fd9f525c896699a31ac

🧾 Summary (20% most significant diffs)

Contract Method Avg (+/-) %
WrappedMTokenHarness isEarning
setIndexOf
unwrap
+148 ❌
+463 ❌
-2,157 ✅
+19.05%
+7.82%
-13.51%
WrappedMToken accruedYieldOf
balanceOf
+163 ❌
-53 ✅
+11.07%
-5.58%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
WrappedMTokenHarness 3,037,437 (+23,999) balanceOf
implementation
indexOfTotalEarningSupply
internalBalanceOf
isEarning
mToken
principalOfTotalEarningSupply
setIndexOf
setIndexOfTotalEarningSupply
setPrincipalOfTotalEarningSupply
setTotalNonEarningSupply
startEarningFor
stopEarningFor
totalEarningSupply
totalSupply
transfer
unwrap
wrap
824 (-6)
381 (-22)
438 (+44)
874 (+11)
814 (+48)
328 (+45)
423 (+23)
6,381 (+463)
5,401 (+23)
22,445 (-22)
5,367 (-44)
8,987 (+45)
8,925 (-22)
743 (+23)
982 (-22)
5,984 (-44)
659 (0)
519 (-22)
-0.72%
-5.46%
+11.17%
+1.27%
+6.27%
+15.90%
+5.75%
+7.82%
+0.43%
-0.10%
-0.81%
+0.50%
-0.25%
+3.19%
-2.19%
-0.73%
0.00%
-4.07%
972 (+7)
381 (-22)
438 (+44)
878 (+15)
925 (+148)
328 (+45)
2,392 (+23)
6,381 (+463)
5,401 (+23)
22,445 (-22)
22,275 (-44)
25,611 (+58)
29,615 (-320)
743 (+23)
1,782 (-22)
26,725 (-64)
13,805 (-2,157)
19,426 (+156)
+0.73%
-5.46%
+11.17%
+1.74%
+19.05%
+15.90%
+0.97%
+7.82%
+0.43%
-0.10%
-0.20%
+0.23%
-1.07%
+3.19%
-1.22%
-0.24%
-13.51%
+0.81%
1,047 (-8)
381 (-22)
438 (+44)
874 (+11)
925 (+148)
328 (+45)
2,423 (+23)
6,381 (+463)
5,401 (+23)
22,445 (-22)
22,467 (-44)
18,108 (+92)
29,615 (-320)
743 (+23)
982 (-22)
25,884 (-8)
16,859 (+12)
19,758 (+149)
-0.76%
-5.46%
+11.17%
+1.27%
+19.05%
+15.90%
+0.96%
+7.82%
+0.43%
-0.10%
-0.20%
+0.51%
-1.07%
+3.19%
-2.19%
-0.03%
+0.07%
+0.76%
1,047 (-8)
381 (-22)
438 (+44)
1,097 (+211)
1,037 (+248)
328 (+45)
2,423 (+23)
6,381 (+463)
5,401 (+23)
22,445 (-22)
22,467 (-44)
49,738 (+36)
50,305 (-618)
743 (+23)
2,982 (-22)
42,984 (-8)
22,431 (-5,003)
51,192 (-10)
-0.76%
-5.46%
+11.17%
+23.81%
+31.43%
+15.90%
+0.96%
+7.82%
+0.43%
-0.10%
-0.20%
+0.07%
-1.21%
+3.19%
-0.73%
-0.02%
-18.24%
-0.02%
6 (+1)
1 (0)
260 (0)
532 (0)
2 (0)
1 (0)
263 (0)
1 (-7)
8 (0)
8 (0)
268 (0)
3 (0)
2 (0)
12 (0)
5 (0)
264 (0)
7 (0)
7 (0)
WrappedMToken 2,838,513 (-26,274) accruedYieldOf
balanceOf
claimExcess
claimFor
excess
startEarningFor
stopEarningFor
transfer
unwrap
wrap
930 (+6)
779 (-51)
16,363 (-104)
27,672 (+500)
3,864 (-104)
32,552 (-9)
42,237 (+123)
44,572 (+908)
16,807 (+12)
23,442 (+890)
+0.65%
-6.14%
-0.63%
+1.84%
-2.62%
-0.03%
+0.29%
+2.08%
+0.07%
+3.95%
1,635 (+163)
897 (-53)
16,363 (-104)
27,672 (+500)
3,876 (-104)
40,062 (-9)
42,237 (+123)
44,575 (+901)
25,362 (+443)
37,054 (+272)
+11.07%
-5.58%
-0.63%
+1.84%
-2.61%
-0.02%
+0.29%
+2.06%
+1.78%
+0.74%
2,294 (+416)
1,002 (-53)
16,363 (-104)
27,672 (+500)
3,880 (-104)
43,817 (-9)
42,237 (+123)
44,575 (+901)
25,362 (+443)
36,817 (+92)
+22.15%
-5.02%
-0.63%
+1.84%
-2.61%
-0.02%
+0.29%
+2.06%
+1.78%
+0.25%
2,294 (+187)
1,002 (-53)
16,363 (-104)
27,672 (+500)
3,880 (-104)
43,817 (-9)
42,237 (+123)
44,578 (+893)
33,918 (+875)
51,140 (+12)
+8.88%
-5.02%
-0.63%
+1.84%
-2.61%
-0.02%
+0.29%
+2.04%
+2.65%
+0.02%
29 (0)
30 (0)
1 (0)
1 (0)
18 (0)
3 (0)
1 (0)
2 (0)
4 (0)
4 (0)

Copy link

github-actions bot commented Jun 28, 2024

LCOV of commit 67a75a7 during Forge Coverage #88

Summary coverage rate:
  lines......: 95.1% (135 of 142 lines)
  functions..: 93.6% (44 of 47 functions)
  branches...: no data found

Files changed coverage rate:
                           |Lines       |Functions  |Branches    
  Filename                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================
  src/WrappedMToken.sol    |98.3%    118|97.1%    35|    -      0

src/WrappedMToken.sol Outdated Show resolved Hide resolved
src/WrappedMToken.sol Outdated Show resolved Hide resolved
src/WrappedMToken.sol Show resolved Hide resolved
_setBalanceInfo(account_, true, currentIndex_, rawBalance_);
if (currentIndex_ == index_) return 0;

_updateIndex(account_, currentIndex_);
Copy link
Contributor

@toninorair toninorair Jul 1, 2024

Choose a reason for hiding this comment

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

different suggestion: move yield calculation inside updateIndex. Rename updateIndex into updateEarnerIndex to improve comprehension and readability.

uint256 yield_ = updateEarnerIndex(account_, currentIndex_);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I prefer not to since it will result in a cleaner change to the next PR that tackles start/stop (as well as more complex upgrades). Further, since _updateIndex never needs to compute yield, doing this creates unnecessary coupling to overcomplicate an otherwise straightforward and single-task _updateIndex.

@toninorair toninorair self-requested a review July 1, 2024 19:25
@deluca-mike deluca-mike merged commit cbfd935 into feat/fixes-suggestions Jul 2, 2024
2 checks passed
@deluca-mike deluca-mike deleted the refactor/auto-setBalanceInfo branch July 2, 2024 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants