Skip to content

Commit

Permalink
feat(StakeManager): add capabilities to register vaults
Browse files Browse the repository at this point in the history
This commit introduces changes related to vault registrations in the
stake manager.

The stake manager needs to keep track of the vaults a users creates so
it can aggregate accumulated MP across vaults for any given user.

The `StakeVault` now comes with a `register()` function which needs to
be called to register itself with the stake manager. `StakeManager` has
a new `onlyRegisteredVault` modifier that ensures only registered vaults
can actually `stake` and `unstake`.

Closes #70
  • Loading branch information
0x-r4bbit committed Dec 1, 2024
1 parent 4968ad4 commit e6774d8
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 111 deletions.
106 changes: 56 additions & 50 deletions .gas-report
Original file line number Diff line number Diff line change
Expand Up @@ -15,77 +15,83 @@
| src/RewardsStreamerMP.sol:RewardsStreamerMP contract | | | | | |
|------------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 2134697 | 9822 | | | | |
| 2479347 | 11426 | | | | |
| Function Name | min | avg | median | max | # calls |
| MAX_LOCKUP_PERIOD | 272 | 272 | 272 | 272 | 23 |
| MAX_LOCKUP_PERIOD | 294 | 294 | 294 | 294 | 23 |
| MAX_MULTIPLIER | 273 | 273 | 273 | 273 | 30 |
| MIN_LOCKUP_PERIOD | 274 | 274 | 274 | 274 | 11 |
| MP_RATE_PER_YEAR | 230 | 230 | 230 | 230 | 3 |
| SCALE_FACTOR | 294 | 294 | 294 | 294 | 41 |
| STAKING_TOKEN | 2381 | 2381 | 2381 | 2381 | 198 |
| accountedRewards | 373 | 970 | 373 | 2373 | 77 |
| MP_RATE_PER_YEAR | 253 | 253 | 253 | 253 | 3 |
| SCALE_FACTOR | 251 | 251 | 251 | 251 | 41 |
| STAKING_TOKEN | 2404 | 2404 | 2404 | 2404 | 294 |
| accountedRewards | 350 | 947 | 350 | 2350 | 77 |
| emergencyModeEnabled | 2398 | 2398 | 2398 | 2398 | 7 |
| enableEmergencyMode | 2460 | 19367 | 24652 | 24652 | 8 |
| getAccount | 1621 | 1621 | 1621 | 1621 | 72 |
| getStakedBalance | 2567 | 2567 | 2567 | 2567 | 1 |
| initialize | 137773 | 137773 | 137773 | 137773 | 51 |
| isTrustedCodehash | 563 | 1078 | 563 | 2563 | 198 |
| leave | 62061 | 62061 | 62061 | 62061 | 1 |
| lock | 9839 | 33584 | 14168 | 76747 | 3 |
| proxiableUUID | 363 | 363 | 363 | 363 | 3 |
| rewardIndex | 394 | 419 | 394 | 2394 | 77 |
| setTrustedCodehash | 26226 | 26226 | 26226 | 26226 | 51 |
| stake | 134677 | 171411 | 176279 | 196758 | 61 |
| totalMP | 329 | 329 | 329 | 329 | 80 |
| enableEmergencyMode | 2482 | 19389 | 24674 | 24674 | 8 |
| getAccount | 1615 | 1615 | 1615 | 1615 | 72 |
| getStakedBalance | 2583 | 2583 | 2583 | 2583 | 1 |
| getUserVaults | 5197 | 5197 | 5197 | 5197 | 36 |
| initialize | 137782 | 137782 | 137782 | 137782 | 60 |
| isTrustedCodehash | 563 | 563 | 563 | 563 | 232 |
| leave | 62106 | 62106 | 62106 | 62106 | 1 |
| lock | 12029 | 35774 | 16358 | 78937 | 3 |
| proxiableUUID | 320 | 320 | 320 | 320 | 3 |
| registerVault | 72848 | 72848 | 72848 | 72848 | 234 |
| rewardIndex | 350 | 375 | 350 | 2350 | 77 |
| setTrustedCodehash | 26203 | 26203 | 26203 | 26203 | 60 |
| stake | 136867 | 173601 | 178469 | 198948 | 61 |
| totalMP | 374 | 374 | 374 | 374 | 80 |
| totalMaxMP | 373 | 373 | 373 | 373 | 80 |
| totalStaked | 329 | 329 | 329 | 329 | 81 |
| unstake | 63997 | 84793 | 63997 | 120464 | 13 |
| updateAccountMP | 15353 | 17591 | 17855 | 17855 | 19 |
| totalStaked | 374 | 374 | 374 | 374 | 81 |
| unstake | 66209 | 87005 | 66209 | 122676 | 13 |
| updateAccountMP | 15347 | 17585 | 17849 | 17849 | 19 |
| updateGlobalState | 11066 | 41310 | 30530 | 63481 | 28 |
| upgradeToAndCall | 3124 | 9263 | 10809 | 10809 | 5 |
| upgradeToAndCall | 3140 | 9257 | 10782 | 10803 | 5 |


| src/StakeManagerProxy.sol:StakeManagerProxy contract | | | | | |
|------------------------------------------------------|-----------------|-------|--------|-------|---------|
| Deployment Cost | Deployment Size | | | | |
| 278629 | 1263 | | | | |
| 278638 | 1263 | | | | |
| Function Name | min | avg | median | max | # calls |
| MAX_LOCKUP_PERIOD | 699 | 1481 | 699 | 5199 | 23 |
| MAX_LOCKUP_PERIOD | 721 | 1503 | 721 | 5221 | 23 |
| MAX_MULTIPLIER | 700 | 1600 | 700 | 5200 | 30 |
| MIN_LOCKUP_PERIOD | 701 | 3973 | 5201 | 5201 | 11 |
| MP_RATE_PER_YEAR | 657 | 657 | 657 | 657 | 3 |
| SCALE_FACTOR | 721 | 721 | 721 | 721 | 41 |
| STAKING_TOKEN | 7308 | 7308 | 7308 | 7308 | 198 |
| accountedRewards | 800 | 1397 | 800 | 2800 | 77 |
| MP_RATE_PER_YEAR | 680 | 680 | 680 | 680 | 3 |
| SCALE_FACTOR | 678 | 678 | 678 | 678 | 41 |
| STAKING_TOKEN | 7331 | 7331 | 7331 | 7331 | 294 |
| accountedRewards | 777 | 1374 | 777 | 2777 | 77 |
| emergencyModeEnabled | 7325 | 7325 | 7325 | 7325 | 7 |
| enableEmergencyMode | 28455 | 45356 | 50640 | 50640 | 8 |
| getAccount | 2075 | 2075 | 2075 | 2075 | 72 |
| getStakedBalance | 7497 | 7497 | 7497 | 7497 | 1 |
| implementation | 343 | 936 | 343 | 2343 | 283 |
| isTrustedCodehash | 993 | 1508 | 993 | 2993 | 198 |
| rewardIndex | 821 | 846 | 821 | 2821 | 77 |
| setTrustedCodehash | 52872 | 52872 | 52872 | 52872 | 51 |
| totalMP | 756 | 756 | 756 | 756 | 80 |
| enableEmergencyMode | 28477 | 45378 | 50662 | 50662 | 8 |
| getAccount | 2069 | 2069 | 2069 | 2069 | 72 |
| getStakedBalance | 7513 | 7513 | 7513 | 7513 | 1 |
| getUserVaults | 5633 | 6758 | 5633 | 10133 | 36 |
| implementation | 343 | 786 | 343 | 2343 | 379 |
| isTrustedCodehash | 993 | 993 | 993 | 993 | 232 |
| rewardIndex | 777 | 802 | 777 | 2777 | 77 |
| setTrustedCodehash | 52849 | 52849 | 52849 | 52849 | 60 |
| totalMP | 801 | 801 | 801 | 801 | 80 |
| totalMaxMP | 800 | 800 | 800 | 800 | 80 |
| totalStaked | 756 | 756 | 756 | 756 | 81 |
| updateAccountMP | 41712 | 43950 | 44214 | 44214 | 19 |
| totalStaked | 801 | 801 | 801 | 801 | 81 |
| updateAccountMP | 41706 | 43944 | 44208 | 44208 | 19 |
| updateGlobalState | 37054 | 67298 | 56518 | 89469 | 28 |
| upgradeToAndCall | 29767 | 35900 | 37445 | 37445 | 5 |
| upgradeToAndCall | 29783 | 35895 | 37418 | 37439 | 5 |


| src/StakeVault.sol:StakeVault contract | | | | | |
|----------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 1374543 | 6483 | | | | |
| 1420401 | 6695 | | | | |
| Function Name | min | avg | median | max | # calls |
| STAKING_TOKEN | 216 | 216 | 216 | 216 | 1 |
| emergencyExit | 36353 | 48857 | 48091 | 65191 | 7 |
| leave | 33507 | 132602 | 62962 | 370978 | 4 |
| lock | 33245 | 60236 | 48577 | 110544 | 4 |
| stake | 33454 | 242541 | 250826 | 271353 | 62 |
| trustStakeManager | 28997 | 28997 | 28997 | 28997 | 1 |
| unstake | 33260 | 117303 | 113502 | 156376 | 14 |
| withdraw | 42227 | 42227 | 42227 | 42227 | 1 |
| leave | 33507 | 132611 | 62980 | 370978 | 4 |
| lock | 33245 | 61878 | 50767 | 112734 | 4 |
| owner | 2339 | 2339 | 2339 | 2339 | 234 |
| register | 103997 | 103997 | 103997 | 103997 | 234 |
| stake | 33411 | 244653 | 252973 | 273500 | 62 |
| stakeManager | 368 | 368 | 368 | 368 | 234 |
| trustStakeManager | 28953 | 28953 | 28953 | 28953 | 1 |
| unstake | 33282 | 119315 | 115736 | 158610 | 14 |
| withdraw | 42243 | 42243 | 42243 | 42243 | 1 |


| src/XPNFTToken.sol:XPNFTToken contract | | | | | |
Expand Down Expand Up @@ -161,19 +167,19 @@
| Deployment Cost | Deployment Size | | | | |
| 625454 | 3260 | | | | |
| Function Name | min | avg | median | max | # calls |
| approve | 46330 | 46339 | 46342 | 46342 | 252 |
| approve | 46330 | 46339 | 46342 | 46342 | 297 |
| balanceOf | 558 | 1395 | 558 | 2558 | 351 |
| mint | 51279 | 58806 | 51279 | 68379 | 268 |
| mint | 51279 | 58707 | 51279 | 68379 | 313 |
| transfer | 34384 | 48853 | 51484 | 51484 | 13 |


| test/mocks/StackOverflowStakeManager.sol:StackOverflowStakeManager contract | | | | | |
|-----------------------------------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 1033443 | 4615 | | | | |
| 1038658 | 4639 | | | | |
| Function Name | min | avg | median | max | # calls |
| leave | 391 | 161316 | 161316 | 322322 | 334 |
| proxiableUUID | 319 | 319 | 319 | 319 | 1 |
| proxiableUUID | 341 | 341 | 341 | 341 | 1 |


| test/mocks/XPProviderMock.sol:XPProviderMock contract | | | | | |
Expand Down
Loading

0 comments on commit e6774d8

Please sign in to comment.