-
Notifications
You must be signed in to change notification settings - Fork 35
feat: add erc7779 support #40
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0231f0a
feat: init erc7779 support
kopy-kat 709dbe0
feat: add into msa advanced
kopy-kat b2b5cd3
7779 bases management + use in MSA
dafb83d
clean package.json
c9e07a7
rm _addBase from using w/o module flow
fe0f49a
apply 7779 for 7702 only
e999763
lint
e0a663b
clean
9cf07e8
add naive onRedelegation
60a18bb
Merge pull request #41 from erc7579/stacked/draft7779-methods
kopy-kat fdc0a54
chore: update lockfile
kopy-kat 8fb61e4
fix: ep updates
kopy-kat cd41b54
chore: lint
kopy-kat f10a2cd
check
498695d
ep etch fix
b47ea56
chore: lint
kopy-kat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| shamefully-hoist=true | ||
| shamefully-hoist=true | ||
| package-manager-strict=false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.27; | ||
|
|
||
| import { IERC7779 } from "../interfaces/IERC7779.sol"; | ||
|
|
||
| abstract contract ERC7779Adapter is IERC7779 { | ||
| error NonAuthorizedOnRedelegationCaller(); | ||
|
|
||
| // keccak256(abi.encode(uint256(keccak256(bytes("InteroperableDelegatedAccount.ERC.Storage"))) - | ||
| // 1)) & ~bytes32(uint256(0xff)); | ||
| bytes32 internal constant ERC7779_STORAGE_BASE = | ||
| 0xc473de86d0138e06e4d4918a106463a7cc005258d2e21915272bcb4594c18900; | ||
|
|
||
| struct ERC7779Storage { | ||
| bytes32[] storageBases; | ||
| } | ||
| /* | ||
| * @dev Externally shares the storage bases that has been used throughout the account. | ||
| * Majority of 7702 accounts will have their distinctive storage base to reduce the | ||
| chance of storage collision. | ||
| * This allows the external entities to know what the storage base is of the account. | ||
| * Wallets willing to redelegate already-delegated accounts should call | ||
| accountStorageBase() to check if it confirms with the account it plans to redelegate. | ||
| * | ||
| * The bytes32 array should be stored at the storage slot: | ||
| keccak(keccak('InteroperableDelegatedAccount.ERC.Storage')-1) & ~0xff | ||
| * This is an append-only array so newly redelegated accounts should not overwrite the | ||
| storage at this slot, but just append their base to the array. | ||
| * This append operation should be done during the initialization of the account. | ||
| */ | ||
|
|
||
| function accountStorageBases() external view returns (bytes32[] memory) { | ||
| ERC7779Storage storage $; | ||
| assembly { | ||
| $.slot := ERC7779_STORAGE_BASE | ||
| } | ||
| return $.storageBases; | ||
| } | ||
|
|
||
| function _addStorageBase(bytes32 storageBase) internal { | ||
| ERC7779Storage storage $; | ||
| assembly { | ||
| $.slot := ERC7779_STORAGE_BASE | ||
| } | ||
| $.storageBases.push(storageBase); | ||
| } | ||
|
|
||
| /* | ||
| * @dev Function called before redelegation. | ||
| * This function should prepare the account for a delegation to a different | ||
| implementation. | ||
| * This function could be triggered by the new wallet that wants to redelegate an already | ||
| delegated EOA. | ||
| * It should uninitialize storages if needed and execute wallet-specific logic to prepare | ||
| for redelegation. | ||
| * msg.sender should be the owner of the account. | ||
| */ | ||
| function onRedelegation() external returns (bool) { | ||
| require(msg.sender == address(this), NonAuthorizedOnRedelegationCaller()); | ||
| _onRedelegation(); | ||
| return true; | ||
| } | ||
|
|
||
| /// @dev This function is called before redelegation. | ||
| /// @dev Account should override this function to implement the specific logic. | ||
| function _onRedelegation() internal virtual; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,9 @@ abstract contract ModuleManager is AccountBase, Receiver { | |
| error NoFallbackHandler(bytes4 selector); | ||
| error CannotRemoveLastValidator(); | ||
|
|
||
| event ValidatorUninstallFailed(address validator, bytes data); | ||
| event ExecutorUninstallFailed(address executor, bytes data); | ||
|
|
||
| // forgefmt: disable-next-line | ||
| // keccak256(abi.encode(uint256(keccak256("modulemanager.storage.msa")) - 1)) & ~bytes32(uint256(0xff)); | ||
| bytes32 internal constant MODULEMANAGER_STORAGE_LOCATION = | ||
|
|
@@ -92,6 +95,40 @@ abstract contract ModuleManager is AccountBase, Receiver { | |
| IValidator(validator).onUninstall(disableModuleData); | ||
| } | ||
|
|
||
| /* | ||
| function _tryUninstallValidators(bytes[] calldata data) internal { | ||
| SentinelListLib.SentinelList storage $valdiators = $moduleManager().$valdiators; | ||
| uint256 length = data.length; | ||
| uint256 index; | ||
| address validator = $valdiators.getNext(SENTINEL); | ||
| while (validator != SENTINEL) { | ||
| bytes memory uninstallData; | ||
| if (index < length) { | ||
| uninstallData = data[index]; | ||
| } | ||
| try IValidator(validator).onUninstall(uninstallData) {} catch { | ||
| emit ValidatorUninstallFailed(validator, uninstallData); | ||
| } | ||
| validator = $valdiators.getNext(validator); | ||
| index++; | ||
| } | ||
| $valdiators.popAll(); | ||
| } | ||
| */ | ||
|
|
||
| function _tryUninstallValidators() internal { | ||
| SentinelListLib.SentinelList storage $valdiators = $moduleManager().$valdiators; | ||
| address validator = $valdiators.getNext(SENTINEL); | ||
| while (validator != SENTINEL) { | ||
| try IValidator(validator).onUninstall("") { } | ||
| catch { | ||
| emit ValidatorUninstallFailed(validator, ""); | ||
| } | ||
| validator = $valdiators.getNext(validator); | ||
| } | ||
| $valdiators.popAll(); | ||
| } | ||
|
|
||
| function _isValidatorInstalled(address validator) internal view virtual returns (bool) { | ||
| SentinelListLib.SentinelList storage $valdiators = $moduleManager().$valdiators; | ||
| return $valdiators.contains(validator); | ||
|
|
@@ -131,6 +168,40 @@ abstract contract ModuleManager is AccountBase, Receiver { | |
| IExecutor(executor).onUninstall(disableModuleData); | ||
| } | ||
|
|
||
| /* | ||
| function _tryUninstallExecutors(bytes[] calldata data) internal { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this left commented out? |
||
| SentinelListLib.SentinelList storage $executors = $moduleManager().$executors; | ||
| uint256 length = data.length; | ||
| uint256 index; | ||
| address executor = $executors.getNext(SENTINEL); | ||
| while (executor != SENTINEL) { | ||
| bytes memory uninstallData; | ||
| if (index < length) { | ||
| uninstallData = data[index]; | ||
| } | ||
| try IExecutor(executor).onUninstall(uninstallData) {} catch { | ||
| emit ExecutorUninstallFailed(executor, uninstallData); | ||
| } | ||
| executor = $executors.getNext(executor); | ||
| index++; | ||
| } | ||
| $executors.popAll(); | ||
| } | ||
| */ | ||
|
|
||
| function _tryUninstallExecutors() internal { | ||
| SentinelListLib.SentinelList storage $executors = $moduleManager().$executors; | ||
| address executor = $executors.getNext(SENTINEL); | ||
| while (executor != SENTINEL) { | ||
| try IExecutor(executor).onUninstall("") { } | ||
| catch { | ||
| emit ExecutorUninstallFailed(executor, ""); | ||
| } | ||
| executor = $executors.getNext(executor); | ||
| } | ||
| $executors.popAll(); | ||
| } | ||
|
|
||
| function _isExecutorInstalled(address executor) internal view virtual returns (bool) { | ||
| SentinelListLib.SentinelList storage $executors = $moduleManager().$executors; | ||
| return $executors.contains(executor); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.27; | ||
|
|
||
| interface IERC7779 { | ||
| /* | ||
| * @dev Externally shares the storage bases that has been used throughout the account. | ||
| * Majority of 7702 accounts will have their distinctive storage base to reduce the | ||
| chance of storage collision. | ||
| * This allows the external entities to know what the storage base is of the account. | ||
| * Wallets willing to redelegate already-delegated accounts should call | ||
| accountStorageBase() to check if it confirms with the account it plans to redelegate. | ||
| * | ||
| * The bytes32 array should be stored at the storage slot: | ||
| keccak(keccak('InteroperableDelegatedAccount.ERC.Storage')-1) & ~0xff | ||
| * This is an append-only array so newly redelegated accounts should not overwrite the | ||
| storage at this slot, but just append their base to the array. | ||
| * This append operation should be done during the initialization of the account. | ||
| */ | ||
| function accountStorageBases() external view returns (bytes32[] memory); | ||
|
|
||
| /* | ||
| * @dev Function called before redelegation. | ||
| * This function should prepare the account for a delegation to a different | ||
| implementation. | ||
| * This function could be triggered by the new wallet that wants to redelegate an already | ||
| delegated EOA. | ||
| * It should uninitialize storages if needed and execute wallet-specific logic to prepare | ||
| for redelegation. | ||
| * msg.sender should be the owner of the account. | ||
| */ | ||
| function onRedelegation() external returns (bool); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this left commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently, we dont clear storage so it can persist multiple delegations to this impl