-
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] update SingleOwnerPlugin to use installValidatio…
…n [1/2] (#91)
- Loading branch information
Showing
20 changed files
with
368 additions
and
350 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,92 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.25; | ||
|
||
import {FunctionReference, ValidationConfig} from "../interfaces/IPluginManager.sol"; | ||
|
||
// Validation config is a packed representation of a validation function and flags for its configuration. | ||
// Layout: | ||
// 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA________________________ // Address | ||
// 0x________________________________________BB______________________ // Function ID | ||
// 0x__________________________________________CC____________________ // isGlobal | ||
// 0x____________________________________________DD__________________ // isSignatureValidation | ||
// 0x______________________________________________000000000000000000 // unused | ||
|
||
library ValidationConfigLib { | ||
function pack(FunctionReference _validationFunction, bool _isGlobal, bool _isSignatureValidation) | ||
internal | ||
pure | ||
returns (ValidationConfig) | ||
{ | ||
return ValidationConfig.wrap( | ||
bytes23( | ||
bytes23(FunctionReference.unwrap(_validationFunction)) | ||
// isGlobal flag stored in the 22nd byte | ||
| bytes23(bytes32(_isGlobal ? uint256(1) << 80 : 0)) | ||
// isSignatureValidation flag stored in the 23rd byte | ||
| bytes23(bytes32(_isSignatureValidation ? uint256(1) << 72 : 0)) | ||
) | ||
); | ||
} | ||
|
||
function pack(address _plugin, uint8 _functionId, bool _isGlobal, bool _isSignatureValidation) | ||
internal | ||
pure | ||
returns (ValidationConfig) | ||
{ | ||
return ValidationConfig.wrap( | ||
bytes23( | ||
// plugin address stored in the first 20 bytes | ||
bytes23(bytes20(_plugin)) | ||
// functionId stored in the 21st byte | ||
| bytes23(bytes32(uint256(_functionId) << 168)) | ||
// isGlobal flag stored in the 22nd byte | ||
| bytes23(bytes32(_isGlobal ? uint256(1) << 80 : 0)) | ||
// isSignatureValidation flag stored in the 23rd byte | ||
| bytes23(bytes32(_isSignatureValidation ? uint256(1) << 72 : 0)) | ||
) | ||
); | ||
} | ||
|
||
function unpackUnderlying(ValidationConfig config) | ||
internal | ||
pure | ||
returns (address _plugin, uint8 _functionId, bool _isGlobal, bool _isSignatureValidation) | ||
{ | ||
bytes23 configBytes = ValidationConfig.unwrap(config); | ||
_plugin = address(bytes20(configBytes)); | ||
_functionId = uint8(configBytes[20]); | ||
_isGlobal = uint8(configBytes[21]) == 1; | ||
_isSignatureValidation = uint8(configBytes[22]) == 1; | ||
} | ||
|
||
function unpack(ValidationConfig config) | ||
internal | ||
pure | ||
returns (FunctionReference _validationFunction, bool _isGlobal, bool _isSignatureValidation) | ||
{ | ||
bytes23 configBytes = ValidationConfig.unwrap(config); | ||
_validationFunction = FunctionReference.wrap(bytes21(configBytes)); | ||
_isGlobal = uint8(configBytes[21]) == 1; | ||
_isSignatureValidation = uint8(configBytes[22]) == 1; | ||
} | ||
|
||
function plugin(ValidationConfig config) internal pure returns (address) { | ||
return address(bytes20(ValidationConfig.unwrap(config))); | ||
} | ||
|
||
function functionId(ValidationConfig config) internal pure returns (uint8) { | ||
return uint8(ValidationConfig.unwrap(config)[20]); | ||
} | ||
|
||
function functionReference(ValidationConfig config) internal pure returns (FunctionReference) { | ||
return FunctionReference.wrap(bytes21(ValidationConfig.unwrap(config))); | ||
} | ||
|
||
function isGlobal(ValidationConfig config) internal pure returns (bool) { | ||
return uint8(ValidationConfig.unwrap(config)[21]) == 1; | ||
} | ||
|
||
function isSignatureValidation(ValidationConfig config) internal pure returns (bool) { | ||
return uint8(ValidationConfig.unwrap(config)[22]) == 1; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.