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

feat: add factory stake script #326

Merged
merged 1 commit into from
Dec 17, 2024
Merged

Conversation

adamegyed
Copy link
Contributor

Motivation

We need to stake the factory after deployment.

Solution

Add a factory staking script and a corresponding test.

Unfortunately, this revealed an issue with how foundry treats setEnv while running multiple tests: each cheatcode affects global state, so there's a race condition between tests that use the same env var. This results in tests passing when running just invidual tests (via --mt or --mc), but failing when running all tests at once.

To solve this, I adjusted all instances of vm.setEnv("ENTRYPOINT", ...) to use the canonical v0.7.0 entrypoint address, and defined a new env var for ACCOUNT_FACTORY_TO_STAKE. In the majority of cases this will be the same as ACCOUNT_FACTORY, but it was too cumbersome to cause the deployment target of the factory deploy script's test and the setup scenario in the staking script test to line up.

The script also checks whether or not the stake amount needs to be topped up, if it was previously insufficient. It does not do this style of check for the unstakeDelay or the bool staked - it assumes that the provided unstake delay will be equal to or greater than the current value. This is reasonable because if we ever have to lower the stake time, we would need to go through the unstake and restake process anyways, which would require new scripts.

@adamegyed adamegyed requested a review from a team December 16, 2024 23:50
Copy link

Summary by Octane

New Contracts

  • StakeFactory.s.sol: The smart contract manages staking for an AccountFactory using user-defined parameters, checks current stake, and adds necessary stake if needed.

Updated Contracts

No contracts were updated in this PR.


🔗 Commit Hash: 62c24e9

Copy link

Overview

Octane AI analysis has finished. No vulnerabilities were found. Cheers! 🎉🎉🎉


🔗 Commit Hash: 62c24e9

Copy link

Contract sizes:

| Contract                      | Runtime Size (B) | Initcode Size (B) | Runtime Margin (B) | Initcode Margin (B) |
| AccountFactory                | 6,661            | 7,135             | 17,915             | 42,017              |
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
| AllowlistModule               | 10,262           | 10,289            | 14,314             | 38,863              |
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
| ExecutionInstallDelegate      | 5,947            | 5,993             | 18,629             | 43,159              |
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
| ModularAccount                | 23,273           | 23,672            | 1,303              | 25,480              |
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
| NativeTokenLimitModule        | 5,093            | 5,120             | 19,483             | 44,032              |
|-------------------------------+------------------+-------------------+--------------------+---------------------|
| PaymasterGuardModule          | 2,097            | 2,124             | 22,479             | 47,028              |
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
| SemiModularAccount7702        | 23,741           | 24,133            | 835                | 25,019              |
|-------------------------------+------------------+-------------------+--------------------+---------------------|
| SemiModularAccountBytecode    | 24,223           | 24,622            | 353                | 24,530              |
|-------------------------------+------------------+-------------------+--------------------+---------------------|
| SemiModularAccountStorageOnly | 24,756           | 25,155            | -180               | 23,997              |
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
| SingleSignerValidationModule  | 3,976            | 4,003             | 20,600             | 45,149              |
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
| TimeRangeModule               | 2,504            | 2,531             | 22,072             | 46,621              |
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
|-------------------------------+------------------+-------------------+--------------------+---------------------|
| WebAuthnValidationModule      | 9,462            | 9,489             | 15,114             | 39,663              |

Code coverage:
| File | % Lines | % Statements | % Branches | % Funcs |
| script/Artifacts.sol | 100.00% (48/48) | 100.00% (29/29) | 100.00% (0/0) | 100.00% (24/24) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| script/DeployAccounts.s.sol | 87.88% (29/33) | 89.29% (25/28) | 33.33% (1/3) | 100.00% (6/6) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| script/DeployFactory.s.sol | 71.43% (30/42) | 71.05% (27/38) | 45.45% (5/11) | 100.00% (4/4) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| script/DeploySmaStorage.s.sol | 81.82% (18/22) | 83.33% (15/18) | 33.33% (1/3) | 100.00% (4/4) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| script/DeployStandalones.s.sol | 100.00% (29/29) | 100.00% (27/27) | 100.00% (0/0) | 100.00% (2/2) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| script/GetInitcodeHash.s.sol | 0.00% (0/58) | 0.00% (0/72) | 0.00% (0/16) | 0.00% (0/2) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| script/PredictAddresses.s.sol | 0.00% (0/53) | 0.00% (0/55) | 0.00% (0/6) | 0.00% (0/2) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| script/ScriptBase.sol | 70.59% (36/51) | 71.70% (38/53) | 37.50% (3/8) | 100.00% (12/12) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| script/StakeFactory.s.sol | 77.14% (27/35) | 76.47% (26/34) | 20.00% (1/5) | 100.00% (4/4) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/account/AccountBase.sol | 100.00% (12/12) | 100.00% (7/7) | 100.00% (2/2) | 100.00% (4/4) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/account/AccountStorageInitializable.sol | 100.00% (21/21) | 100.00% (26/26) | 100.00% (5/5) | 100.00% (2/2) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/account/ModularAccount.sol | 100.00% (6/6) | 100.00% (6/6) | 100.00% (0/0) | 100.00% (3/3) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/account/ModularAccountBase.sol | 99.09% (326/329) | 96.24% (358/372) | 77.59% (45/58) | 100.00% (36/36) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/account/ModularAccountView.sol | 100.00% (32/32) | 100.00% (31/31) | 100.00% (3/3) | 100.00% (5/5) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/account/ModuleManagerInternals.sol | 94.03% (63/67) | 95.06% (77/81) | 63.64% (7/11) | 100.00% (4/4) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/account/SemiModularAccount7702.sol | 22.22% (2/9) | 16.67% (1/6) | 0.00% (0/1) | 33.33% (1/3) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/account/SemiModularAccountBase.sol | 90.48% (76/84) | 91.84% (90/98) | 64.71% (11/17) | 100.00% (16/16) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/account/SemiModularAccountBytecode.sol | 100.00% (8/8) | 100.00% (7/7) | 100.00% (1/1) | 100.00% (2/2) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/account/SemiModularAccountStorageOnly.sol | 77.78% (7/9) | 60.00% (6/10) | 100.00% (0/0) | 66.67% (2/3) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/account/TokenReceiver.sol | 33.33% (2/6) | 33.33% (1/3) | 100.00% (0/0) | 33.33% (1/3) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/factory/AccountFactory.sol | 82.26% (51/62) | 88.71% (55/62) | 50.00% (3/6) | 68.75% (11/16) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/helpers/ExecutionInstallDelegate.sol | 89.39% (59/66) | 89.47% (68/76) | 25.00% (2/8) | 100.00% (7/7) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/libraries/ExecutionLib.sol | 99.66% (297/298) | 98.89% (268/271) | 90.91% (30/33) | 100.00% (24/24) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/libraries/KnownSelectorsLib.sol | 100.00% (18/18) | 100.00% (34/34) | 100.00% (0/0) | 100.00% (2/2) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/libraries/LinkedListSetLib.sol | 94.83% (55/58) | 96.25% (77/80) | 66.67% (4/6) | 100.00% (8/8) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/libraries/MemManagementLib.sol | 100.00% (66/66) | 100.00% (70/70) | 100.00% (0/0) | 100.00% (12/12) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/libraries/ModuleInstallCommonsLib.sol | 64.71% (11/17) | 42.11% (8/19) | 75.00% (3/4) | 100.00% (3/3) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/libraries/ValidationLocatorLib.sol | 70.59% (72/102) | 71.74% (66/92) | 47.83% (11/23) | 85.00% (17/20) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/modules/ModuleBase.sol | 100.00% (16/16) | 94.12% (16/17) | 100.00% (2/2) | 100.00% (3/3) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/modules/permissions/AllowlistModule.sol | 81.90% (86/105) | 86.73% (98/113) | 78.26% (18/23) | 55.56% (10/18) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/modules/permissions/NativeTokenLimitModule.sol | 88.14% (52/59) | 92.06% (58/63) | 100.00% (13/13) | 75.00% (9/12) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/modules/permissions/PaymasterGuardModule.sol | 85.71% (18/21) | 84.21% (16/19) | 33.33% (1/3) | 85.71% (6/7) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/modules/permissions/TimeRangeModule.sol | 88.89% (24/27) | 85.19% (23/27) | 100.00% (5/5) | 87.50% (7/8) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/modules/validation/SingleSignerValidationModule.sol | 87.80% (36/41) | 84.21% (32/38) | 62.50% (5/8) | 100.00% (10/10) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| src/modules/validation/WebAuthnValidationModule.sol | 69.70% (23/33) | 70.37% (19/27) | 100.00% (3/3) | 70.00% (7/10) |
|---------------------------------------------------------+--------------------+--------------------+------------------+------------------|
| Total | 85.23% (1656/1943) | 84.87% (1705/2009) | 64.46% (185/287) | 89.04% (268/301) |

@adamegyed adamegyed merged commit a9c7829 into develop Dec 17, 2024
6 checks passed
@adamegyed adamegyed deleted the adam/add-factory-stake-script branch December 17, 2024 17:01
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.

2 participants