/
IShellFramework.sol
285 lines (229 loc) · 7.24 KB
/
IShellFramework.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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/interfaces/IERC165.sol";
import "@openzeppelin/contracts/interfaces/IERC2981.sol";
import "./libraries/IOwnable.sol";
import "./IEngine.sol";
// storage flag
enum StorageLocation {
INVALID,
// set by the engine at any time, mutable
ENGINE,
// set by the engine during minting, immutable
MINT_DATA,
// set by the framework during minting or collection creation, immutable
FRAMEWORK
}
// string key / value
struct StringStorage {
string key;
string value;
}
// int key / value
struct IntStorage {
string key;
uint256 value;
}
// data provided when minting a new token
struct MintEntry {
address to;
uint256 amount;
MintOptions options;
}
// Data provided by engine when minting a new token
struct MintOptions {
bool storeEngine;
bool storeMintedTo;
bool storeTimestamp;
bool storeBlockNumber;
StringStorage[] stringData;
IntStorage[] intData;
}
// Information about a fork
struct Fork {
IEngine engine;
address owner;
}
// Interface for every collection launched by shell.
// Concrete implementations must return true on ERC165 checks for this interface
// (as well as erc165 / 2981)
// interfaceId = TBD
interface IShellFramework is IERC165, IERC2981 {
// ---
// Framework errors
// ---
// an engine was provided that did no pass the expected erc165 checks
error InvalidEngine();
// a write was attempted that is not allowed
error WriteNotAllowed();
// an operation was attempted but msg.sender was not the expected engine
error SenderNotEngine();
// an operation was attempted but msg.sender was not the fork owner
error SenderNotForkOwner();
// a token fork was attempted by an invalid msg.sender
error SenderCannotFork();
// ---
// Framework events
// ---
// a fork was created
event ForkCreated(uint256 forkId, IEngine engine, address owner);
// a fork had a new engine installed
event ForkEngineUpdated(uint256 forkId, IEngine engine);
// a fork had a new owner set
event ForkOwnerUpdated(uint256 forkId, address owner);
// a token has been set to a new fork
event TokenForkUpdated(uint256 tokenId, uint256 forkId);
// ---
// Storage events
// ---
// A fork string was stored
event ForkStringUpdated(
StorageLocation location,
uint256 forkId,
string key,
string value
);
// A fork int was stored
event ForkIntUpdated(
StorageLocation location,
uint256 forkId,
string key,
uint256 value
);
// A token string was stored
event TokenStringUpdated(
StorageLocation location,
uint256 tokenId,
string key,
string value
);
// A token int was stored
event TokenIntUpdated(
StorageLocation location,
uint256 tokenId,
string key,
uint256 value
);
// ---
// Collection base
// ---
// called immediately after cloning
function initialize(
string calldata name,
string calldata symbol,
IEngine engine,
address owner
) external;
// ---
// General collection info / metadata
// ---
// collection owner (fork 0 owner)
function owner() external view returns (address);
// collection name
function name() external view returns (string memory);
// collection name
function symbol() external view returns (string memory);
// next token id serial number
function nextTokenId() external view returns (uint256);
// next fork id serial number
function nextForkId() external view returns (uint256);
// ---
// Fork functionality
// ---
// Create a new fork with a specific engine, fork all the tokenIds to the
// new engine, and return the fork ID
function createFork(
IEngine engine,
address owner,
uint256[] calldata tokenIds
) external returns (uint256);
// Set the engine for a specific fork. Must be fork owner
function setForkEngine(uint256 forkId, IEngine engine) external;
// Set the fork owner. Must be fork owner
function setForkOwner(uint256 forkId, address owner) external;
// Set the fork of a specific token. Must be token owner
function setTokenFork(uint256 tokenId, uint256 forkId) external;
// Set the fork for several tokens. Must own all tokens
function setTokenForks(uint256[] memory tokenIds, uint256 forkId) external;
// ---
// Fork views
// ---
// Get information about a fork
function getFork(uint256 forkId) external view returns (Fork memory);
// Get a fork's engine
function getForkEngine(uint256 forkId) external view returns (IEngine);
// Get a fork's owner
function getForkOwner(uint256 forkId) external view returns (address);
// Get a token's fork ID
function getTokenForkId(uint256 tokenId) external view returns (uint256);
// Get a token's engine. getFork(getTokenForkId(tokenId)).engine
function getTokenEngine(uint256 tokenId) external view returns (IEngine);
// Determine if a given msg.sender can fork a token
function canSenderForkToken(address sender, uint256 tokenId)
external
view
returns (bool);
// ---
// Engine functionality
// ---
// mint new tokens. Only callable by collection engine
function mint(MintEntry calldata entry) external returns (uint256);
// ---
// Storage writes
// ---
// Write a string to collection storage. Only callable by collection engine
function writeForkString(
StorageLocation location,
uint256 forkId,
string calldata key,
string calldata value
) external;
// Write a string to collection storage. Only callable by collection engine
function writeForkInt(
StorageLocation location,
uint256 forkId,
string calldata key,
uint256 value
) external;
// Write a string to token storage. Only callable by token engine
function writeTokenString(
StorageLocation location,
uint256 tokenId,
string calldata key,
string calldata value
) external;
// Write a string to token storage. Only callable by token engine
function writeTokenInt(
StorageLocation location,
uint256 tokenId,
string calldata key,
uint256 value
) external;
// ---
// Storage reads
// ---
// Read a string from collection storage
function readForkString(
StorageLocation location,
uint256 forkId,
string calldata key
) external view returns (string memory);
// Read a uint256 from collection storage
function readForkInt(
StorageLocation location,
uint256 forkId,
string calldata key
) external view returns (uint256);
// Read a string from token storage
function readTokenString(
StorageLocation location,
uint256 tokenId,
string calldata key
) external view returns (string memory);
// Read a uint256 from token storage
function readTokenInt(
StorageLocation location,
uint256 tokenId,
string calldata key
) external view returns (uint256);
}