-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from bcnmy/feat/erc-7779-support
ERC-7779 support v 0.1
- Loading branch information
Showing
11 changed files
with
316 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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,62 @@ | ||
// 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 when the account is redelegated. | ||
/// @dev This function should be overridden by the account to implement wallet-specific logic. | ||
function _onRedelegation() internal virtual; | ||
} |
This file contains 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 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 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,26 @@ | ||
// 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 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 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 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,16 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.27; | ||
|
||
import { ERC7779Adapter } from "../base/ERC7779Adapter.sol"; | ||
|
||
contract MockERC7779 is ERC7779Adapter { | ||
|
||
function addStorageBase(bytes32 storageBase) external { | ||
_addStorageBase(storageBase); | ||
} | ||
|
||
function _onRedelegation() internal override { | ||
// do nothing | ||
} | ||
|
||
} |
Oops, something went wrong.