-
Notifications
You must be signed in to change notification settings - Fork 33
/
MetadataProvider.sol
58 lines (46 loc) · 2 KB
/
MetadataProvider.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.20;
import { Multicall } from "../utils/Multicall.sol";
import { MetadataRegistry } from "./MetadataRegistry.sol";
import { IMetadataProvider } from "./IMetadataProvider.sol";
import { IGlobals } from "../globals/IGlobals.sol";
import { LibGlobals } from "../globals/LibGlobals.sol";
/// @notice A contract that provides custom metadata for Party Cards.
contract MetadataProvider is IMetadataProvider, Multicall {
event MetadataSet(address indexed instance, bytes metadata);
error NotAuthorized(address caller, address instance);
// The `Globals` contract storing global configuration values. This contract
// is immutable and it’s address will never change.
IGlobals internal immutable _GLOBALS;
/// @inheritdoc IMetadataProvider
bool public constant supportsRegistrars = true;
// The metadata for each Party instance.
mapping(address instance => bytes metadata) internal _metadata;
// Set the `Globals` contract.
constructor(IGlobals globals) {
_GLOBALS = globals;
}
/// @inheritdoc IMetadataProvider
function getMetadata(
address instance,
uint256
) external view virtual override returns (bytes memory) {
return _metadata[instance];
}
/// @notice Set the metadata for a Party instance.
/// @param instance The address of the instance.
/// @param metadata The encoded metadata.
function setMetadata(address instance, bytes memory metadata) external virtual {
if (instance != msg.sender) {
MetadataRegistry registry = MetadataRegistry(
_GLOBALS.getAddress(LibGlobals.GLOBAL_METADATA_REGISTRY)
);
// Check if the caller is authorized to set metadata for the instance.
if (!registry.isRegistrar(msg.sender, instance)) {
revert NotAuthorized(msg.sender, instance);
}
}
_metadata[instance] = metadata;
emit MetadataSet(instance, metadata);
}
}