-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [v0.8-develop, experimental] default validation (#63)
- Loading branch information
Showing
22 changed files
with
499 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[profile.default] | ||
solc = '0.8.25' | ||
solc = '0.8.26' | ||
via_ir = false | ||
src = 'src' | ||
test = 'test' | ||
|
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,68 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.25; | ||
|
||
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; | ||
|
||
import {IPlugin} from "../interfaces/IPlugin.sol"; | ||
import {FunctionReference} from "../interfaces/IPluginManager.sol"; | ||
import {FunctionReferenceLib} from "../helpers/FunctionReferenceLib.sol"; | ||
import {AccountStorage, getAccountStorage, toSetValue} from "./AccountStorage.sol"; | ||
|
||
// Temporary additional functions for a user-controlled install flow for validation functions. | ||
abstract contract PluginManager2 { | ||
using EnumerableSet for EnumerableSet.Bytes32Set; | ||
|
||
error DefaultValidationAlreadySet(address plugin, uint8 functionId); | ||
error ValidationAlreadySet(bytes4 selector, address plugin, uint8 functionId); | ||
error ValidationNotSet(bytes4 selector, address plugin, uint8 functionId); | ||
|
||
function _installValidation( | ||
address plugin, | ||
uint8 functionId, | ||
bool isDefault, | ||
bytes4[] memory selectors, | ||
bytes calldata installData | ||
) internal { | ||
FunctionReference validationFunction = FunctionReferenceLib.pack(plugin, functionId); | ||
|
||
AccountStorage storage _storage = getAccountStorage(); | ||
|
||
if (isDefault) { | ||
if (!_storage.defaultValidations.add(toSetValue(validationFunction))) { | ||
revert DefaultValidationAlreadySet(plugin, functionId); | ||
} | ||
} | ||
|
||
for (uint256 i = 0; i < selectors.length; ++i) { | ||
bytes4 selector = selectors[i]; | ||
if (!_storage.selectorData[selector].validations.add(toSetValue(validationFunction))) { | ||
revert ValidationAlreadySet(selector, plugin, functionId); | ||
} | ||
} | ||
|
||
IPlugin(plugin).onInstall(installData); | ||
} | ||
|
||
function _uninstallValidation( | ||
address plugin, | ||
uint8 functionId, | ||
bytes4[] calldata selectors, | ||
bytes calldata uninstallData | ||
) internal { | ||
FunctionReference validationFunction = FunctionReferenceLib.pack(plugin, functionId); | ||
|
||
AccountStorage storage _storage = getAccountStorage(); | ||
|
||
// Ignore return value - remove if present, do nothing otherwise. | ||
_storage.defaultValidations.remove(toSetValue(validationFunction)); | ||
|
||
for (uint256 i = 0; i < selectors.length; ++i) { | ||
bytes4 selector = selectors[i]; | ||
if (!_storage.selectorData[selector].validations.remove(toSetValue(validationFunction))) { | ||
revert ValidationNotSet(selector, plugin, functionId); | ||
} | ||
} | ||
|
||
IPlugin(plugin).onUninstall(uninstallData); | ||
} | ||
} |
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
Oops, something went wrong.