-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
74 additions
and
73 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
contracts/src/mocks/plugin/extensions/metadata/MetadataContractMock.sol
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
contracts/src/mocks/plugin/extensions/metadata/MetadataContractUpgradeableMock.sol
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
contracts/src/mocks/utils/metadata/MetadataExtensionMock.sol
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,13 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.8; | ||
|
||
import {MetadataExtension} from "../../../utils/metadata/MetadataExtension.sol"; | ||
import {IDAO} from "../../../dao/IDAO.sol"; | ||
import {DaoAuthorizable} from "../../../permission/auth/DaoAuthorizable.sol"; | ||
|
||
/// @notice A mock contract. | ||
/// @dev DO NOT USE IN PRODUCTION! | ||
contract MetadataExtensionMock is MetadataExtension { | ||
constructor(IDAO dao) DaoAuthorizable(dao) {} | ||
} |
15 changes: 15 additions & 0 deletions
15
contracts/src/mocks/utils/metadata/MetadataExtensionUpgradeableMock.sol
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,15 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.8; | ||
|
||
import {MetadataExtensionUpgradeable} from "../../../utils/metadata/MetadataExtensionUpgradeable.sol"; | ||
|
||
import {IDAO} from "../../../dao/IDAO.sol"; | ||
|
||
/// @notice A mock contract. | ||
/// @dev DO NOT USE IN PRODUCTION! | ||
contract MetadataExtensionUpgradeableMock is MetadataExtensionUpgradeable { | ||
function initialize(IDAO _dao) public initializer { | ||
__DaoAuthorizableUpgradeable_init(_dao); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,12 +4,12 @@ pragma solidity ^0.8.8; | |
|
||
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol"; | ||
|
||
import {DaoAuthorizable} from "../../../permission/auth/DaoAuthorizable.sol"; | ||
import {DaoAuthorizable} from "../../permission/auth/DaoAuthorizable.sol"; | ||
|
||
/// @title MetadataContract | ||
/// @title MetadataExtension | ||
/// @author Aragon X - 2024 | ||
/// @custom:security-contact [email protected] | ||
abstract contract MetadataContract is ERC165, DaoAuthorizable { | ||
abstract contract MetadataExtension is ERC165, DaoAuthorizable { | ||
/// @notice The ID of the permission required to call the `updateMetadata` function. | ||
bytes32 public constant UPDATE_METADATA_PERMISSION_ID = keccak256("UPDATE_METADATA_PERMISSION"); | ||
|
||
|
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 |
---|---|---|
|
@@ -4,28 +4,40 @@ pragma solidity ^0.8.8; | |
|
||
import {ERC165Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol"; | ||
|
||
import {DaoAuthorizableUpgradeable} from "../../../permission/auth/DaoAuthorizableUpgradeable.sol"; | ||
import {DaoAuthorizableUpgradeable} from "../../permission/auth/DaoAuthorizableUpgradeable.sol"; | ||
|
||
/// @title MetadataContract | ||
/// @title MetadataExtensionUpgradeable | ||
/// @dev Due to the requirements that already existing upgradeable plugins need to start inheritting from this, | ||
/// we're required to use hardcoded/specific slots for storage instead of sequential slots with gaps. | ||
/// @author Aragon X - 2024 | ||
/// @custom:security-contact [email protected] | ||
abstract contract MetadataContractUpgradeable is ERC165Upgradeable, DaoAuthorizableUpgradeable { | ||
abstract contract MetadataExtensionUpgradeable is ERC165Upgradeable, DaoAuthorizableUpgradeable { | ||
/// @notice The ID of the permission required to call the `updateMetadata` function. | ||
bytes32 public constant UPDATE_METADATA_PERMISSION_ID = keccak256("UPDATE_METADATA_PERMISSION"); | ||
|
||
// keccak256("osx-commons.storage.MetadataContractUpgradeable") | ||
bytes32 private constant MetadataStorageLocation = | ||
0x99da6c69991bd6a0d70d0c3817ab9bd9d4d7e3090d51c182be2cf851bfab8d70; | ||
// keccak256(abi.encode(uint256(keccak256("osx-commons.storage.MetadataExtension")) - 1)) & ~bytes32(uint256(0xff)) | ||
bytes32 private constant MetadataExtensionStorageLocation = | ||
0x47ff9796f72d439c6e5c30a24b9fad985a00c85a9f2258074c400a94f8746b00; | ||
|
||
/// @notice Emitted when metadata is updated. | ||
event MetadataUpdated(bytes metadata); | ||
|
||
/// @notice Thrown if metadata is set empty. | ||
error EmptyMetadata(); | ||
|
||
bytes private metadata; | ||
struct MetadataExtensionStorage { | ||
bytes metadata; | ||
} | ||
|
||
function _getMetadataExtensionStorage() | ||
private | ||
pure | ||
returns (MetadataExtensionStorage storage $) | ||
{ | ||
assembly { | ||
$.slot := MetadataExtensionStorageLocation | ||
} | ||
} | ||
|
||
/// @notice Checks if this or the parent contract supports an interface by its ID. | ||
/// @param _interfaceId The ID of the interface. | ||
|
@@ -47,7 +59,8 @@ abstract contract MetadataContractUpgradeable is ERC165Upgradeable, DaoAuthoriza | |
/// @notice Returns the metadata currently applied. | ||
/// @return The The utf8 bytes of a content addressing cid. | ||
function getMetadata() public view returns (bytes memory) { | ||
return _getMetadata(); | ||
MetadataExtensionStorage storage $ = _getMetadataExtensionStorage(); | ||
return $.metadata; | ||
} | ||
|
||
/// @notice Internal function to update metadata. | ||
|
@@ -57,22 +70,9 @@ abstract contract MetadataContractUpgradeable is ERC165Upgradeable, DaoAuthoriza | |
revert EmptyMetadata(); | ||
} | ||
|
||
_storeMetadata(_metadata); | ||
emit MetadataUpdated(_metadata); | ||
} | ||
|
||
/// @notice Gets the currently set metadata. | ||
/// @return _metadata The current metadata. | ||
function _getMetadata() private view returns (bytes memory _metadata) { | ||
assembly { | ||
_metadata := sload(MetadataStorageLocation) | ||
} | ||
} | ||
MetadataExtensionStorage storage $ = _getMetadataExtensionStorage(); | ||
$.metadata = _metadata; | ||
|
||
/// @notice Stores the metadata on a specific slot. | ||
function _storeMetadata(bytes memory _metadata) private { | ||
assembly { | ||
sstore(MetadataStorageLocation, _metadata) | ||
} | ||
emit MetadataUpdated(_metadata); | ||
} | ||
} |
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