-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProvenanceGateway.sol
More file actions
265 lines (222 loc) · 9.06 KB
/
ProvenanceGateway.sol
File metadata and controls
265 lines (222 loc) · 9.06 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IProvenanceGateway} from "./interfaces/IProvenanceGateway.sol";
import {IProvenanceRegistry} from "./interfaces/IProvenanceRegistry.sol";
import {IIdRegistry} from "./interfaces/IIdRegistry.sol";
import {Withdrawable} from "./abstract/Withdrawable.sol";
import {Signatures} from "./abstract/Signatures.sol";
import {EIP712} from "./abstract/EIP712.sol";
import {Nonces} from "./abstract/Nonces.sol";
import {Initializable} from "solady/utils/Initializable.sol";
import {UUPSUpgradeable} from "solady/utils/UUPSUpgradeable.sol";
/**
* @title RoyalProtocol ProvenanceGateway
*
* @notice An abstraction layer around registration for the ProvenanceRegistry.
* Having this abstraction layer allows for switching registration logic in the future if needed.
*/
contract ProvenanceGateway is
IProvenanceGateway,
Withdrawable,
Signatures,
EIP712,
Nonces,
Initializable,
UUPSUpgradeable
{
// =============================================================
// CONSTANTS
// =============================================================
/* solhint-disable gas-small-strings */
/// @inheritdoc IProvenanceGateway
string public constant VERSION = "2024-09-07";
/// @inheritdoc IProvenanceGateway
bytes32 public constant REGISTER_TYPEHASH = keccak256(
"Register(uint256 originatorId,bytes32 contentHash,address nftContract,uint256 nftTokenId,uint256 nonce,uint256 deadline)"
);
/// @inheritdoc IProvenanceGateway
bytes32 public constant ASSIGN_NFT_TYPEHASH = keccak256(
"AssignNft(uint256 provenanceClaimId,address nftContract,uint256 nftTokenId,uint256 nonce,uint256 deadline)"
);
/* solhint-enable gas-small-strings */
// =============================================================
// STORAGE
// =============================================================
/// @inheritdoc IProvenanceGateway
IProvenanceRegistry public provenanceRegistry;
/// @inheritdoc IProvenanceGateway
IIdRegistry public idRegistry;
/// @inheritdoc IProvenanceGateway
uint256 public registerFee;
// =============================================================
// CONSTRUCTOR / INITIALIZATION
// =============================================================
constructor() {
_disableInitializers();
}
/**
* @notice Configure ProvenanceRegistry and ownership of the contract.
*
* @param provenanceRegistry_ The RoyalProtocol ProvenanceRegistry contract address.
* @param idRegistry_ The RoyalProtocol IdRegistry contract address.
* @param initialOwner_ The initial owner of the contract.
*/
function initialize(IProvenanceRegistry provenanceRegistry_, IIdRegistry idRegistry_, address initialOwner_)
external
override
initializer
{
provenanceRegistry = provenanceRegistry_;
idRegistry = idRegistry_;
_initializeOwner(initialOwner_);
}
// =============================================================
// EIP712
// =============================================================
/// @dev Configure the EIP712 name and version for the domain separator.
function _domainNameAndVersion() internal pure override returns (string memory name, string memory version) {
name = "RoyalProtocol_ProvenanceGateway";
version = "1";
}
// =============================================================
// REGISTRATION
// =============================================================
/// @inheritdoc IProvenanceGateway
function register(uint256 originatorId, bytes32 contentHash, address nftContract, uint256 nftTokenId)
external
payable
override
whenNotPaused
returns (uint256 id)
{
if (msg.value < registerFee) revert InsufficientFee();
uint256 registrarId = idRegistry.idOf(msg.sender);
// Check that the registrar has permission to register provenance on behalf of the originator.
if (!idRegistry.canAct(originatorId, registrarId, address(this), "registerProvenance")) {
revert Unauthorized();
}
id = provenanceRegistry.register({
originatorId: originatorId,
registrarId: registrarId,
contentHash: contentHash,
nftContract: nftContract,
nftTokenId: nftTokenId
});
}
/// @inheritdoc IProvenanceGateway
function registerFor(
uint256 originatorId,
bytes32 contentHash,
address nftContract,
uint256 nftTokenId,
uint256 deadline,
bytes calldata sig
) external payable override whenNotPaused returns (uint256 id) {
if (msg.value < registerFee) revert InsufficientFee();
uint256 registrarId = idRegistry.idOf(msg.sender);
_verifyRegisterSig({
originatorId: originatorId,
contentHash: contentHash,
nftContract: nftContract,
nftTokenId: nftTokenId,
deadline: deadline,
sig: sig
});
id = provenanceRegistry.register({
originatorId: originatorId,
registrarId: registrarId,
contentHash: contentHash,
nftContract: nftContract,
nftTokenId: nftTokenId
});
}
// =============================================================
// ASSIGNING NFTs
// =============================================================
/// @inheritdoc IProvenanceGateway
function assignNft(uint256 provenanceClaimId, address nftContract, uint256 nftTokenId)
external
payable
override
whenNotPaused
{
uint256 originatorId = provenanceRegistry.provenanceClaim(provenanceClaimId).originatorId;
uint256 registrarId = idRegistry.idOf(msg.sender);
// Check that the assigner has permission to assign an NFT to a ProvenanceClaim on behalf of the originator.
if (!idRegistry.canAct(originatorId, registrarId, address(this), "assignNft")) {
revert Unauthorized();
}
provenanceRegistry.assignNft(provenanceClaimId, nftContract, nftTokenId);
}
/// @inheritdoc IProvenanceGateway
function assignNftFor(
uint256 provenanceClaimId,
address nftContract,
uint256 nftTokenId,
uint256 deadline,
bytes calldata sig
) external payable override whenNotPaused {
_verifyAssignNftSig({
provenanceClaimId: provenanceClaimId,
nftContract: nftContract,
nftTokenId: nftTokenId,
deadline: deadline,
sig: sig
});
provenanceRegistry.assignNft(provenanceClaimId, nftContract, nftTokenId);
}
// =============================================================
// SIGNATURE HELPERS
// =============================================================
/// @dev Verify the EIP712 signature for a registerFor transaction.
function _verifyRegisterSig(
uint256 originatorId,
bytes32 contentHash,
address nftContract,
uint256 nftTokenId,
uint256 deadline,
bytes calldata sig
) internal {
address custody = idRegistry.custodyOf(originatorId);
bytes32 digest = _hashTypedData(
keccak256(
abi.encode(
REGISTER_TYPEHASH, originatorId, contentHash, nftContract, nftTokenId, _useNonce(custody), deadline
)
)
);
_verifySig(digest, custody, deadline, sig);
}
/// @dev Verify the EIP712 signature for a assignNftFor transaction.
function _verifyAssignNftSig(
uint256 provenanceClaimId,
address nftContract,
uint256 nftTokenId,
uint256 deadline,
bytes calldata sig
) internal {
uint256 originatorId = provenanceRegistry.provenanceClaim(provenanceClaimId).originatorId;
address custody = idRegistry.custodyOf(originatorId);
bytes32 digest = _hashTypedData(
keccak256(
abi.encode(
ASSIGN_NFT_TYPEHASH, provenanceClaimId, nftContract, nftTokenId, _useNonce(custody), deadline
)
)
);
_verifySig(digest, custody, deadline, sig);
}
// =============================================================
// FEE MANAGEMENT
// =============================================================
/// @inheritdoc IProvenanceGateway
function setRegisterFee(uint256 fee) external override onlyOwner {
registerFee = fee;
emit RegisterFeeSet(fee);
}
// =============================================================
// UUPS
// =============================================================
// solhint-disable-next-line no-empty-blocks
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
}