-
Notifications
You must be signed in to change notification settings - Fork 28
/
GenArt721CoreV3.sol
1972 lines (1855 loc) · 79.6 KB
/
GenArt721CoreV3.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity 0.8.19;
// Created By: Art Blocks Inc.
import "./interfaces/v0.8.x/IRandomizer_V3CoreBase.sol";
import "./interfaces/v0.8.x/IAdminACLV0.sol";
import "./interfaces/v0.8.x/IGenArt721CoreContractV3.sol";
import "./interfaces/v0.8.x/IGenArt721CoreContractExposesHashSeed.sol";
import "./interfaces/v0.8.x/IManifold.sol";
import "@openzeppelin-4.7/contracts/utils/Strings.sol";
import "@openzeppelin-4.7/contracts/access/Ownable.sol";
import "./libs/v0.8.x/ERC721_PackedHashSeed.sol";
import "./libs/v0.8.x/BytecodeStorageV1.sol";
import "./libs/v0.8.x/Bytes32Strings.sol";
/**
* @title Art Blocks ERC-721 core contract, V3.
* @author Art Blocks Inc.
* @notice Privileged Roles and Ownership:
* This contract is designed to be managed, with progressively limited powers
* as a project progresses from active to locked.
* Privileged roles and abilities are controlled by the admin ACL contract and
* artists. Both of these roles hold extensive power and can arbitrarily
* control and modify portions of projects, dependent upon project state. After
* a project is locked, important project metadata fields are locked including
* the project name, artist name, and script and display details. Edition size
* can never be increased.
* Care must be taken to ensure that the admin ACL contract and artist
* addresses are secure behind a multi-sig or other access control mechanism.
* ----------------------------------------------------------------------------
* The following functions are restricted to the Admin ACL contract:
* - updateArtblocksCurationRegistryAddress
* - updateArtblocksDependencyRegistryAddress
* - updateArtblocksPrimarySalesAddress
* - updateArtblocksSecondarySalesAddress
* - updateArtblocksPrimarySalesPercentage (up to 25%)
* - updateArtblocksSecondarySalesBPS (up to 100%)
* - updateMinterContract
* - updateRandomizerAddress
* - toggleProjectIsActive
* - addProject
* - forbidNewProjects (forever forbidding new projects)
* - updateDefaultBaseURI (used to initialize new project base URIs)
* ----------------------------------------------------------------------------
* The following functions are restricted to either the Artist address or
* the Admin ACL contract, only when the project is not locked:
* - updateProjectName
* - updateProjectArtistName
* - updateProjectLicense
* - Change project script via addProjectScript, updateProjectScript,
* and removeProjectLastScript
* - updateProjectScriptType
* - updateProjectAspectRatio
* ----------------------------------------------------------------------------
* The following functions are restricted to only the Artist address:
* - proposeArtistPaymentAddressesAndSplits (Note that this has to be accepted
* by adminAcceptArtistAddressesAndSplits to take effect, which is restricted
* to the Admin ACL contract, or the artist if the core contract owner has
* renounced ownership. Also note that a proposal will be automatically
* accepted if the artist only proposes changed payee percentages without
* modifying any payee addresses, or is only removing payee addresses.)
* - toggleProjectIsPaused (note the artist can still mint while paused)
* - updateProjectSecondaryMarketRoyaltyPercentage (up to
ARTIST_MAX_SECONDARY_ROYALTY_PERCENTAGE percent)
* - updateProjectWebsite
* - updateProjectMaxInvocations (to a number greater than or equal to the
* current number of invocations, and less than current project maximum
* invocations)
* - updateProjectBaseURI (controlling the base URI for tokens in the project)
* ----------------------------------------------------------------------------
* The following function is restricted to either the Admin ACL contract, or
* the Artist address if the core contract owner has renounced ownership:
* - adminAcceptArtistAddressesAndSplits
* - updateProjectArtistAddress (owner ultimately controlling the project and
* its and-on revenue, unless owner has renounced ownership)
* ----------------------------------------------------------------------------
* The following function is restricted to the artist when a project is
* unlocked, and only callable by Admin ACL contract when a project is locked:
* - updateProjectDescription
* ----------------------------------------------------------------------------
* The following function is restricted to owner calling directly:
* - transferOwnership
* - renounceOwnership
* ----------------------------------------------------------------------------
* Additional admin and artist privileged roles may be described on minters,
* registries, and other contracts that may interact with this core contract.
*/
contract GenArt721CoreV3 is
ERC721_PackedHashSeed,
Ownable,
IGenArt721CoreContractV3,
IGenArt721CoreContractExposesHashSeed
{
using BytecodeStorageWriter for string;
using Bytes32Strings for bytes32;
using Strings for uint256;
uint256 constant ONE_HUNDRED = 100;
uint256 constant ONE_MILLION = 1_000_000;
uint24 constant ONE_MILLION_UINT24 = 1_000_000;
uint256 constant FOUR_WEEKS_IN_SECONDS = 2_419_200;
uint8 constant AT_CHARACTER_CODE = uint8(bytes1("@")); // 0x40
// numeric constants
uint256 constant ART_BLOCKS_MAX_PRIMARY_SALES_PERCENTAGE = 25; // 25%
uint256 constant ART_BLOCKS_MAX_SECONDARY_SALES_BPS = 10000; // 10_000 BPS = 100%
uint256 constant ARTIST_MAX_SECONDARY_ROYALTY_PERCENTAGE = 95; // 95%
// This contract emits generic events that contain fields that indicate
// which parameter has been updated. This is sufficient for application
// state management, while also simplifying the contract and indexing code.
// This was done as an alternative to having custom events that emit what
// field-values have changed for each event, given that changed values can
// be introspected by indexers due to the design of this smart contract
// exposing these state changes via publicly viewable fields.
//
// The following fields are used to indicate which contract-level parameter
// has been updated in the `PlatformUpdated` event:
bytes32 constant FIELD_NEXT_PROJECT_ID = "nextProjectId";
bytes32 constant FIELD_NEW_PROJECTS_FORBIDDEN = "newProjectsForbidden";
bytes32 constant FIELD_DEFAULT_BASE_URI = "defaultBaseURI";
bytes32 constant FIELD_ARTBLOCKS_PRIMARY_SALES_ADDRESS =
"artblocksPrimarySalesAddress";
bytes32 constant FIELD_ARTBLOCKS_SECONDARY_SALES_ADDRESS =
"artblocksSecondarySalesAddress";
bytes32 constant FIELD_RANDOMIZER_ADDRESS = "randomizerAddress";
bytes32 constant FIELD_ARTBLOCKS_CURATION_REGISTRY_ADDRESS =
"curationRegistryAddress";
bytes32 constant FIELD_ARTBLOCKS_DEPENDENCY_REGISTRY_ADDRESS =
"dependencyRegistryAddress";
bytes32 constant FIELD_ARTBLOCKS_PRIMARY_SALES_PERCENTAGE =
"artblocksPrimaryPercentage";
bytes32 constant FIELD_ARTBLOCKS_SECONDARY_SALES_BPS =
"artblocksSecondaryBPS";
// The following fields are used to indicate which project-level parameter
// has been updated in the `ProjectUpdated` event:
bytes32 constant FIELD_PROJECT_COMPLETED = "completed";
bytes32 constant FIELD_PROJECT_ACTIVE = "active";
bytes32 constant FIELD_PROJECT_ARTIST_ADDRESS = "artistAddress";
bytes32 constant FIELD_PROJECT_PAUSED = "paused";
bytes32 constant FIELD_PROJECT_CREATED = "created";
bytes32 constant FIELD_PROJECT_NAME = "name";
bytes32 constant FIELD_PROJECT_ARTIST_NAME = "artistName";
bytes32 constant FIELD_PROJECT_SECONDARY_MARKET_ROYALTY_PERCENTAGE =
"royaltyPercentage";
bytes32 constant FIELD_PROJECT_DESCRIPTION = "description";
bytes32 constant FIELD_PROJECT_WEBSITE = "website";
bytes32 constant FIELD_PROJECT_LICENSE = "license";
bytes32 constant FIELD_PROJECT_MAX_INVOCATIONS = "maxInvocations";
bytes32 constant FIELD_PROJECT_SCRIPT = "script";
bytes32 constant FIELD_PROJECT_SCRIPT_TYPE = "scriptType";
bytes32 constant FIELD_PROJECT_ASPECT_RATIO = "aspectRatio";
bytes32 constant FIELD_PROJECT_BASE_URI = "baseURI";
// Art Blocks previous flagship ERC721 token addresses (for reference)
/// Art Blocks Project ID range: [0-2]
address public constant ART_BLOCKS_ERC721TOKEN_ADDRESS_V0 =
0x059EDD72Cd353dF5106D2B9cC5ab83a52287aC3a;
/// Art Blocks Project ID range: [3-373]
address public constant ART_BLOCKS_ERC721TOKEN_ADDRESS_V1 =
0xa7d8d9ef8D8Ce8992Df33D8b8CF4Aebabd5bD270;
/// Curation registry managed by Art Blocks
address public artblocksCurationRegistryAddress;
/// Dependency registry managed by Art Blocks
address public artblocksDependencyRegistryAddress;
/// current randomizer contract
IRandomizer_V3CoreBase public randomizerContract;
/// append-only array of all randomizer contract addresses ever used by
/// this contract
address[] private _historicalRandomizerAddresses;
/// admin ACL contract
IAdminACLV0 public adminACLContract;
struct Project {
uint24 invocations;
uint24 maxInvocations;
uint24 scriptCount;
// max uint64 ~= 1.8e19 sec ~= 570 billion years
uint64 completedTimestamp;
bool active;
bool paused;
string name;
string artist;
address descriptionAddress;
string website;
string license;
string projectBaseURI;
bytes32 scriptTypeAndVersion;
string aspectRatio;
// mapping from script index to address storing script in bytecode
mapping(uint256 => address) scriptBytecodeAddresses;
}
mapping(uint256 => Project) projects;
/// packed struct containing project financial information
struct ProjectFinance {
address payable additionalPayeePrimarySales;
// packed uint: max of 95, max uint8 = 255
uint8 secondaryMarketRoyaltyPercentage;
address payable additionalPayeeSecondarySales;
// packed uint: max of 100, max uint8 = 255
uint8 additionalPayeeSecondarySalesPercentage;
address payable artistAddress;
// packed uint: max of 100, max uint8 = 255
uint8 additionalPayeePrimarySalesPercentage;
}
// Project financials mapping
mapping(uint256 => ProjectFinance) projectIdToFinancials;
/// hash of artist's proposed payment updates to be approved by admin
mapping(uint256 => bytes32) public proposedArtistAddressesAndSplitsHash;
/// Art Blocks payment address for all primary sales revenues (packed)
address payable public artblocksPrimarySalesAddress;
/// Percentage of primary sales revenue allocated to Art Blocks (packed)
// packed uint: max of 25, max uint8 = 255
uint8 private _artblocksPrimarySalesPercentage = 10;
/// Art Blocks payment address for all secondary sales royalty revenues
address payable public artblocksSecondarySalesAddress;
/// Basis Points of secondary sales royalties allocated to Art Blocks
uint256 public artblocksSecondarySalesBPS = 250;
/// single minter allowed for this core contract
address public minterContract;
/// starting (initial) project ID on this contract
uint256 public immutable startingProjectId;
/// next project ID to be created
uint248 private _nextProjectId;
/// bool indicating if adding new projects is forbidden;
/// default behavior is to allow new projects
bool public newProjectsForbidden;
/// version & type of this core contract
string public constant coreVersion = "v3.2.2";
string public constant coreType = "GenArt721CoreV3";
/// default base URI to initialize all new project projectBaseURI values to
string public defaultBaseURI;
function _onlyNonZeroAddress(address _address) internal pure {
require(_address != address(0), "Must input non-zero address");
}
function _onlyNonEmptyString(string memory _string) internal pure {
require(bytes(_string).length != 0, "Must input non-empty string");
}
function _onlyValidTokenId(uint256 _tokenId) internal view {
require(_exists(_tokenId), "Token ID does not exist");
}
function _onlyValidProjectId(uint256 _projectId) internal view {
require(
(_projectId >= startingProjectId) && (_projectId < _nextProjectId),
"Project ID does not exist"
);
}
function _onlyUnlocked(uint256 _projectId) internal view {
// Note: calling `_projectUnlocked` enforces that the `_projectId`
// passed in is valid.`
require(_projectUnlocked(_projectId), "Only if unlocked");
}
function _onlyAdminACL(bytes4 _selector) internal {
require(
adminACLAllowed(msg.sender, address(this), _selector),
"Only Admin ACL allowed"
);
}
function _onlyArtist(uint256 _projectId) internal view {
require(
msg.sender == projectIdToFinancials[_projectId].artistAddress,
"Only artist"
);
}
function _onlyArtistOrAdminACL(
uint256 _projectId,
bytes4 _selector
) internal {
require(
msg.sender == projectIdToFinancials[_projectId].artistAddress ||
adminACLAllowed(msg.sender, address(this), _selector),
"Only artist or Admin ACL allowed"
);
}
/**
* This modifier allows the artist of a project to call a function if the
* owner of the contract has renounced ownership. This is to allow the
* contract to continue to function if the owner decides to renounce
* ownership.
*/
function _onlyAdminACLOrRenouncedArtist(
uint256 _projectId,
bytes4 _selector
) internal {
require(
adminACLAllowed(msg.sender, address(this), _selector) ||
(owner() == address(0) &&
msg.sender ==
projectIdToFinancials[_projectId].artistAddress),
"Only Admin ACL allowed, or artist if owner has renounced"
);
}
/**
* @notice Initializes contract.
* @param _tokenName Name of token.
* @param _tokenSymbol Token symbol.
* @param _randomizerContract Randomizer contract.
* @param _adminACLContract Address of admin access control contract, to be
* set as contract owner.
* @param _startingProjectId The initial next project ID.
* @dev _startingProjectId should be set to a value much, much less than
* max(uint248), but an explicit input type of `uint248` is used as it is
* safer to cast up to `uint256` than it is to cast down for the purposes
* of setting `_nextProjectId`.
*/
constructor(
string memory _tokenName,
string memory _tokenSymbol,
address _randomizerContract,
address _adminACLContract,
uint248 _startingProjectId
) ERC721_PackedHashSeed(_tokenName, _tokenSymbol) {
_onlyNonZeroAddress(_randomizerContract);
// record contracts starting project ID
// casting-up is safe
startingProjectId = uint256(_startingProjectId);
_updateArtblocksPrimarySalesAddress(msg.sender);
_updateArtblocksSecondarySalesAddress(msg.sender);
_updateRandomizerAddress(_randomizerContract);
// set AdminACL management contract as owner
_transferOwnership(_adminACLContract);
// initialize default base URI
_updateDefaultBaseURI("https://token.artblocks.io/");
// initialize next project ID
_nextProjectId = _startingProjectId;
emit PlatformUpdated(FIELD_NEXT_PROJECT_ID);
}
/**
* @notice Mints a token from project `_projectId` and sets the
* token's owner to `_to`. Hash may or may not be assigned to the token
* during the mint transaction, depending on the randomizer contract.
* @param _to Address to be the minted token's owner.
* @param _projectId Project ID to mint a token on.
* @param _by Purchaser of minted token.
* @return _tokenId The ID of the minted token.
* @dev sender must be the allowed minterContract
* @dev name of function is optimized for gas usage
*/
function mint_Ecf(
address _to,
uint256 _projectId,
address _by
) external returns (uint256 _tokenId) {
// CHECKS
require(msg.sender == minterContract, "Must mint from minter contract");
Project storage project = projects[_projectId];
// load invocations into memory
uint24 invocationsBefore = project.invocations;
uint24 invocationsAfter;
unchecked {
// invocationsBefore guaranteed <= maxInvocations <= 1_000_000,
// 1_000_000 << max uint24, so no possible overflow
invocationsAfter = invocationsBefore + 1;
}
uint24 maxInvocations = project.maxInvocations;
require(
invocationsBefore < maxInvocations,
"Must not exceed max invocations"
);
require(
project.active ||
_by == projectIdToFinancials[_projectId].artistAddress,
"Project must exist and be active"
);
require(
!project.paused ||
_by == projectIdToFinancials[_projectId].artistAddress,
"Purchases are paused."
);
// EFFECTS
// increment project's invocations
project.invocations = invocationsAfter;
uint256 thisTokenId;
unchecked {
// invocationsBefore is uint24 << max uint256. In production use,
// _projectId * ONE_MILLION must be << max uint256, otherwise
// tokenIdToProjectId function become invalid.
// Therefore, no risk of overflow
thisTokenId = (_projectId * ONE_MILLION) + invocationsBefore;
}
// mark project as completed if hit max invocations
if (invocationsAfter == maxInvocations) {
_completeProject(_projectId);
}
// INTERACTIONS
_mint(_to, thisTokenId);
// token hash is updated by the randomizer contract on V3
randomizerContract.assignTokenHash(thisTokenId);
// Do not need to also log `projectId` in event, as the `projectId` for
// a given token can be derived from the `tokenId` with:
// projectId = tokenId / 1_000_000
emit Mint(_to, thisTokenId);
return thisTokenId;
}
/**
* @notice Sets the hash seed for a given token ID `_tokenId`.
* May only be called by the current randomizer contract.
* May only be called for tokens that have not already been assigned a
* non-zero hash.
* @param _tokenId Token ID to set the hash for.
* @param _hashSeed Hash seed to set for the token ID. Only last 12 bytes
* will be used.
* @dev gas-optimized function name because called during mint sequence
* @dev if a separate event is required when the token hash is set, e.g.
* for indexing purposes, it must be emitted by the randomizer. This is to
* minimize gas when minting.
*/
function setTokenHash_8PT(uint256 _tokenId, bytes32 _hashSeed) external {
_onlyValidTokenId(_tokenId);
OwnerAndHashSeed storage ownerAndHashSeed = _ownersAndHashSeeds[
_tokenId
];
require(
msg.sender == address(randomizerContract),
"Only randomizer may set"
);
require(
ownerAndHashSeed.hashSeed == bytes12(0),
"Token hash already set"
);
require(_hashSeed != bytes12(0), "No zero hash seed");
ownerAndHashSeed.hashSeed = bytes12(_hashSeed);
}
/**
* @notice Allows owner (AdminACL) to revoke ownership of the contract.
* Note that the contract is intended to continue to function after the
* owner renounces ownership, but no new projects will be able to be added.
* Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the
* owner/AdminACL contract. The same is true for any dependent contracts
* that also integrate with the owner/AdminACL contract (e.g. potentially
* minter suite contracts, registry contracts, etc.).
* After renouncing ownership, artists will be in control of updates to
* their payment addresses and splits (see modifier
* onlyAdminACLOrRenouncedArtist`).
* While there is no currently intended reason to call this method based on
* defined Art Blocks business practices, this method exists to allow
* artists to continue to maintain the limited set of contract
* functionality that exists post-project-lock in an environment in which
* there is no longer an admin maintaining this smart contract.
* @dev This function is intended to be called directly by the AdminACL,
* not by an address allowed by the AdminACL contract.
*/
function renounceOwnership() public override onlyOwner {
// broadcast that new projects are no longer allowed (if not already)
_forbidNewProjects();
// renounce ownership viw Ownable
Ownable.renounceOwnership();
}
/**
* @notice Updates reference to Art Blocks Curation Registry contract.
* @param _artblocksCurationRegistryAddress Address of new Curation
* Registry.
*/
function updateArtblocksCurationRegistryAddress(
address _artblocksCurationRegistryAddress
) external {
_onlyAdminACL(this.updateArtblocksCurationRegistryAddress.selector);
_onlyNonZeroAddress(_artblocksCurationRegistryAddress);
artblocksCurationRegistryAddress = _artblocksCurationRegistryAddress;
emit PlatformUpdated(FIELD_ARTBLOCKS_CURATION_REGISTRY_ADDRESS);
}
/**
* @notice Updates reference to Art Blocks Dependency Registry contract.
* @param _artblocksDependencyRegistryAddress Address of new Dependency
* Registry.
*/
function updateArtblocksDependencyRegistryAddress(
address _artblocksDependencyRegistryAddress
) external {
_onlyAdminACL(this.updateArtblocksDependencyRegistryAddress.selector);
_onlyNonZeroAddress(_artblocksDependencyRegistryAddress);
artblocksDependencyRegistryAddress = _artblocksDependencyRegistryAddress;
emit PlatformUpdated(FIELD_ARTBLOCKS_DEPENDENCY_REGISTRY_ADDRESS);
}
/**
* @notice Updates artblocksPrimarySalesAddress to
* `_artblocksPrimarySalesAddress`.
* @param _artblocksPrimarySalesAddress Address of new primary sales
* payment address.
*/
function updateArtblocksPrimarySalesAddress(
address payable _artblocksPrimarySalesAddress
) external {
_onlyAdminACL(this.updateArtblocksPrimarySalesAddress.selector);
_onlyNonZeroAddress(_artblocksPrimarySalesAddress);
_updateArtblocksPrimarySalesAddress(_artblocksPrimarySalesAddress);
}
/**
* @notice Updates Art Blocks secondary sales royalty payment address to
* `_artblocksSecondarySalesAddress`.
* @param _artblocksSecondarySalesAddress Address of new secondary sales
* payment address.
*/
function updateArtblocksSecondarySalesAddress(
address payable _artblocksSecondarySalesAddress
) external {
_onlyAdminACL(this.updateArtblocksSecondarySalesAddress.selector);
_onlyNonZeroAddress(_artblocksSecondarySalesAddress);
_updateArtblocksSecondarySalesAddress(_artblocksSecondarySalesAddress);
}
/**
* @notice Updates Art Blocks primary sales revenue percentage to
* `artblocksPrimarySalesPercentage_`.
* @param artblocksPrimarySalesPercentage_ New primary sales revenue
* percentage.
*/
function updateArtblocksPrimarySalesPercentage(
uint256 artblocksPrimarySalesPercentage_
) external {
_onlyAdminACL(this.updateArtblocksPrimarySalesPercentage.selector);
require(
artblocksPrimarySalesPercentage_ <=
ART_BLOCKS_MAX_PRIMARY_SALES_PERCENTAGE,
"Max of ART_BLOCKS_MAX_PRIMARY_SALES_PERCENTAGE percent"
);
_artblocksPrimarySalesPercentage = uint8(
artblocksPrimarySalesPercentage_
);
emit PlatformUpdated(FIELD_ARTBLOCKS_PRIMARY_SALES_PERCENTAGE);
}
/**
* @notice Updates Art Blocks secondary sales royalty Basis Points to
* `_artblocksSecondarySalesBPS`.
* @param _artblocksSecondarySalesBPS New secondary sales royalty Basis
* points.
* @dev Due to secondary royalties being ultimately enforced via social
* consensus, no hard upper limit is imposed on the BPS value, other than
* <= 100% royalty, which would not make mathematical sense. Realistically,
* changing this value is expected to either never occur, or be a rare
* occurrence.
*/
function updateArtblocksSecondarySalesBPS(
uint256 _artblocksSecondarySalesBPS
) external {
_onlyAdminACL(this.updateArtblocksSecondarySalesBPS.selector);
require(
_artblocksSecondarySalesBPS <= ART_BLOCKS_MAX_SECONDARY_SALES_BPS,
"Max of ART_BLOCKS_MAX_SECONDARY_SALES_BPS BPS"
);
artblocksSecondarySalesBPS = _artblocksSecondarySalesBPS;
emit PlatformUpdated(FIELD_ARTBLOCKS_SECONDARY_SALES_BPS);
}
/**
* @notice Updates minter to `_address`.
* @param _address Address of new minter.
*/
function updateMinterContract(address _address) external {
_onlyAdminACL(this.updateMinterContract.selector);
_onlyNonZeroAddress(_address);
minterContract = _address;
emit MinterUpdated(_address);
}
/**
* @notice Updates randomizer to `_randomizerAddress`.
* @param _randomizerAddress Address of new randomizer.
*/
function updateRandomizerAddress(address _randomizerAddress) external {
_onlyAdminACL(this.updateRandomizerAddress.selector);
_onlyNonZeroAddress(_randomizerAddress);
_updateRandomizerAddress(_randomizerAddress);
}
/**
* @notice Toggles project `_projectId` as active/inactive.
* @param _projectId Project ID to be toggled.
*/
function toggleProjectIsActive(uint256 _projectId) external {
_onlyAdminACL(this.toggleProjectIsActive.selector);
_onlyValidProjectId(_projectId);
projects[_projectId].active = !projects[_projectId].active;
emit ProjectUpdated(_projectId, FIELD_PROJECT_ACTIVE);
}
/**
* @notice Artist proposes updated set of artist address, additional payee
* addresses, and percentage splits for project `_projectId`. Addresses and
* percentages do not have to all be changed, but they must all be defined
* as a complete set.
* Note that if the artist is only proposing a change to the payee percentage
* splits, without modifying the payee addresses, the proposal will be
* automatically approved and the new splits will become active immediately.
* Automatic approval will also be granted if the artist is only removing
* additional payee addresses, without adding any new ones.
* Also note that if the artist is proposing sending funds to the zero
* address, this function will revert and the proposal will not be created.
* @param _projectId Project ID.
* @param _artistAddress Artist address that controls the project, and may
* receive payments.
* @param _additionalPayeePrimarySales Address that may receive a
* percentage split of the artist's primary sales revenue.
* @param _additionalPayeePrimarySalesPercentage Percent of artist's
* portion of primary sale revenue that will be split to address
* `_additionalPayeePrimarySales`.
* @param _additionalPayeeSecondarySales Address that may receive a percentage
* split of the secondary sales royalties.
* @param _additionalPayeeSecondarySalesPercentage Percent of artist's portion
* of secondary sale royalties that will be split to address
* `_additionalPayeeSecondarySales`.
* @dev `_artistAddress` must be a valid address (non-zero-address), but it
* is intentionally allowable for `_additionalPayee{Primary,Secondaary}Sales`
* and their associated percentages to be zero'd out by the controlling artist.
*/
function proposeArtistPaymentAddressesAndSplits(
uint256 _projectId,
address payable _artistAddress,
address payable _additionalPayeePrimarySales,
uint256 _additionalPayeePrimarySalesPercentage,
address payable _additionalPayeeSecondarySales,
uint256 _additionalPayeeSecondarySalesPercentage
) external {
_onlyValidProjectId(_projectId);
_onlyArtist(_projectId);
_onlyNonZeroAddress(_artistAddress);
ProjectFinance storage projectFinance = projectIdToFinancials[
_projectId
];
// checks
require(
_additionalPayeePrimarySalesPercentage <= ONE_HUNDRED &&
_additionalPayeeSecondarySalesPercentage <= ONE_HUNDRED,
"Max of 100%"
);
require(
_additionalPayeePrimarySalesPercentage == 0 ||
_additionalPayeePrimarySales != address(0),
"Primary payee is zero address"
);
require(
_additionalPayeeSecondarySalesPercentage == 0 ||
_additionalPayeeSecondarySales != address(0),
"Secondary payee is zero address"
);
// effects
// emit event for off-chain indexing
// note: always emit a proposal event, even in the pathway of
// automatic approval, to simplify indexing expectations
emit ProposedArtistAddressesAndSplits(
_projectId,
_artistAddress,
_additionalPayeePrimarySales,
_additionalPayeePrimarySalesPercentage,
_additionalPayeeSecondarySales,
_additionalPayeeSecondarySalesPercentage
);
// automatically accept if no proposed addresses modifications, or if
// the proposal only removes payee addresses.
// store proposal hash on-chain, only if not automatic accept
bool automaticAccept;
{
// block scope to avoid stack too deep error
bool artistUnchanged = _artistAddress ==
projectFinance.artistAddress;
bool additionalPrimaryUnchangedOrRemoved = (_additionalPayeePrimarySales ==
projectFinance.additionalPayeePrimarySales) ||
(_additionalPayeePrimarySales == address(0));
bool additionalSecondaryUnchangedOrRemoved = (_additionalPayeeSecondarySales ==
projectFinance.additionalPayeeSecondarySales) ||
(_additionalPayeeSecondarySales == address(0));
automaticAccept =
artistUnchanged &&
additionalPrimaryUnchangedOrRemoved &&
additionalSecondaryUnchangedOrRemoved;
}
if (automaticAccept) {
// clear any previously proposed values
proposedArtistAddressesAndSplitsHash[_projectId] = bytes32(0);
// update storage
// (artist address cannot change during automatic accept)
projectFinance
.additionalPayeePrimarySales = _additionalPayeePrimarySales;
// safe to cast as uint8 as max is 100%, max uint8 is 255
projectFinance.additionalPayeePrimarySalesPercentage = uint8(
_additionalPayeePrimarySalesPercentage
);
projectFinance
.additionalPayeeSecondarySales = _additionalPayeeSecondarySales;
// safe to cast as uint8 as max is 100%, max uint8 is 255
projectFinance.additionalPayeeSecondarySalesPercentage = uint8(
_additionalPayeeSecondarySalesPercentage
);
// emit event for off-chain indexing
emit AcceptedArtistAddressesAndSplits(_projectId);
} else {
proposedArtistAddressesAndSplitsHash[_projectId] = keccak256(
abi.encode(
_artistAddress,
_additionalPayeePrimarySales,
_additionalPayeePrimarySalesPercentage,
_additionalPayeeSecondarySales,
_additionalPayeeSecondarySalesPercentage
)
);
}
}
/**
* @notice Admin accepts a proposed set of updated artist address,
* additional payee addresses, and percentage splits for project
* `_projectId`. Addresses and percentages do not have to all be changed,
* but they must all be defined as a complete set.
* @param _projectId Project ID.
* @param _artistAddress Artist address that controls the project, and may
* receive payments.
* @param _additionalPayeePrimarySales Address that may receive a
* percentage split of the artist's primary sales revenue.
* @param _additionalPayeePrimarySalesPercentage Percent of artist's
* portion of primary sale revenue that will be split to address
* `_additionalPayeePrimarySales`.
* @param _additionalPayeeSecondarySales Address that may receive a percentage
* split of the secondary sales royalties.
* @param _additionalPayeeSecondarySalesPercentage Percent of artist's portion
* of secondary sale royalties that will be split to address
* `_additionalPayeeSecondarySales`.
* @dev this must be called by the Admin ACL contract, and must only accept
* the most recent proposed values for a given project (validated on-chain
* by comparing the hash of the proposed and accepted values).
* @dev `_artistAddress` must be a valid address (non-zero-address), but it
* is intentionally allowable for `_additionalPayee{Primary,Secondaary}Sales`
* and their associated percentages to be zero'd out by the controlling artist.
*/
function adminAcceptArtistAddressesAndSplits(
uint256 _projectId,
address payable _artistAddress,
address payable _additionalPayeePrimarySales,
uint256 _additionalPayeePrimarySalesPercentage,
address payable _additionalPayeeSecondarySales,
uint256 _additionalPayeeSecondarySalesPercentage
) external {
_onlyValidProjectId(_projectId);
_onlyAdminACLOrRenouncedArtist(
_projectId,
this.adminAcceptArtistAddressesAndSplits.selector
);
_onlyNonZeroAddress(_artistAddress);
// checks
require(
proposedArtistAddressesAndSplitsHash[_projectId] ==
keccak256(
abi.encode(
_artistAddress,
_additionalPayeePrimarySales,
_additionalPayeePrimarySalesPercentage,
_additionalPayeeSecondarySales,
_additionalPayeeSecondarySalesPercentage
)
),
"Must match artist proposal"
);
// effects
ProjectFinance storage projectFinance = projectIdToFinancials[
_projectId
];
projectFinance.artistAddress = _artistAddress;
projectFinance
.additionalPayeePrimarySales = _additionalPayeePrimarySales;
projectFinance.additionalPayeePrimarySalesPercentage = uint8(
_additionalPayeePrimarySalesPercentage
);
projectFinance
.additionalPayeeSecondarySales = _additionalPayeeSecondarySales;
projectFinance.additionalPayeeSecondarySalesPercentage = uint8(
_additionalPayeeSecondarySalesPercentage
);
// clear proposed values
proposedArtistAddressesAndSplitsHash[_projectId] = bytes32(0);
// emit event for off-chain indexing
emit AcceptedArtistAddressesAndSplits(_projectId);
}
/**
* @notice Updates artist of project `_projectId` to `_artistAddress`.
* This is to only be used in the event that the artist address is
* compromised or sanctioned.
* @param _projectId Project ID.
* @param _artistAddress New artist address.
*/
function updateProjectArtistAddress(
uint256 _projectId,
address payable _artistAddress
) external {
_onlyValidProjectId(_projectId);
_onlyAdminACLOrRenouncedArtist(
_projectId,
this.updateProjectArtistAddress.selector
);
_onlyNonZeroAddress(_artistAddress);
projectIdToFinancials[_projectId].artistAddress = _artistAddress;
emit ProjectUpdated(_projectId, FIELD_PROJECT_ARTIST_ADDRESS);
}
/**
* @notice Toggles paused state of project `_projectId`.
* @param _projectId Project ID to be toggled.
*/
function toggleProjectIsPaused(uint256 _projectId) external {
_onlyArtist(_projectId);
projects[_projectId].paused = !projects[_projectId].paused;
emit ProjectUpdated(_projectId, FIELD_PROJECT_PAUSED);
}
/**
* @notice Adds new project `_projectName` by `_artistAddress`.
* @param _projectName Project name.
* @param _artistAddress Artist's address.
* @dev token price now stored on minter
*/
function addProject(
string memory _projectName,
address payable _artistAddress
) external {
_onlyAdminACL(this.addProject.selector);
_onlyNonEmptyString(_projectName);
_onlyNonZeroAddress(_artistAddress);
require(!newProjectsForbidden, "New projects forbidden");
uint256 projectId = _nextProjectId;
projectIdToFinancials[projectId].artistAddress = _artistAddress;
projects[projectId].name = _projectName;
projects[projectId].paused = true;
projects[projectId].maxInvocations = ONE_MILLION_UINT24;
projects[projectId].projectBaseURI = defaultBaseURI;
_nextProjectId = uint248(projectId) + 1;
emit ProjectUpdated(projectId, FIELD_PROJECT_CREATED);
}
/**
* @notice Forever forbids new projects from being added to this contract.
*/
function forbidNewProjects() external {
_onlyAdminACL(this.forbidNewProjects.selector);
require(!newProjectsForbidden, "Already forbidden");
_forbidNewProjects();
}
/**
* @notice Updates name of project `_projectId` to be `_projectName`.
* @param _projectId Project ID.
* @param _projectName New project name.
*/
function updateProjectName(
uint256 _projectId,
string memory _projectName
) external {
_onlyUnlocked(_projectId);
_onlyArtistOrAdminACL(_projectId, this.updateProjectName.selector);
_onlyNonEmptyString(_projectName);
projects[_projectId].name = _projectName;
emit ProjectUpdated(_projectId, FIELD_PROJECT_NAME);
}
/**
* @notice Updates artist name for project `_projectId` to be
* `_projectArtistName`.
* @param _projectId Project ID.
* @param _projectArtistName New artist name.
*/
function updateProjectArtistName(
uint256 _projectId,
string memory _projectArtistName
) external {
_onlyUnlocked(_projectId);
_onlyArtistOrAdminACL(
_projectId,
this.updateProjectArtistName.selector
);
_onlyNonEmptyString(_projectArtistName);
projects[_projectId].artist = _projectArtistName;
emit ProjectUpdated(_projectId, FIELD_PROJECT_ARTIST_NAME);
}
/**
* @notice Updates artist secondary market royalties for project
* `_projectId` to be `_secondMarketRoyalty` percent.
* This DOES NOT include the secondary market royalty percentages collected
* by Art Blocks; this is only the total percentage of royalties that will
* be split to artist and additionalSecondaryPayee.
* @param _projectId Project ID.
* @param _secondMarketRoyalty Percent of secondary sales revenue that will
* be split to artist and additionalSecondaryPayee. This must be less than
* or equal to ARTIST_MAX_SECONDARY_ROYALTY_PERCENTAGE percent.
*/
function updateProjectSecondaryMarketRoyaltyPercentage(
uint256 _projectId,
uint256 _secondMarketRoyalty
) external {
_onlyArtist(_projectId);
require(
_secondMarketRoyalty <= ARTIST_MAX_SECONDARY_ROYALTY_PERCENTAGE,
"Max of ARTIST_MAX_SECONDARY_ROYALTY_PERCENTAGE percent"
);
projectIdToFinancials[_projectId]
.secondaryMarketRoyaltyPercentage = uint8(_secondMarketRoyalty);
emit ProjectUpdated(
_projectId,
FIELD_PROJECT_SECONDARY_MARKET_ROYALTY_PERCENTAGE
);
}
/**
* @notice Updates description of project `_projectId`.
* Only artist may call when unlocked, only admin may call when locked.
* Note: The BytecodeStorage library is used to store the description to
* reduce initial upload cost, however, even minor edits will require an
* expensive, entirely new bytecode storage contract to be deployed instead
* of relatively cheap updates to already-warm storage slots. This results
* in an increased gas cost for minor edits to the description after the
* initial upload, but an overall decrease in gas cost for projects with
* less than ~3-5 edits (depending on the length of the description).
* @param _projectId Project ID.
* @param _projectDescription New project description.
*/
function updateProjectDescription(
uint256 _projectId,
string memory _projectDescription
) external {
// checks
require(
_projectUnlocked(_projectId)
? msg.sender == projectIdToFinancials[_projectId].artistAddress
: adminACLAllowed(
msg.sender,
address(this),
this.updateProjectDescription.selector
),
"Only artist when unlocked, owner when locked"
);
// effects
// store description in contract bytecode, replacing reference address from
// the old storage description with the newly created one
projects[_projectId].descriptionAddress = _projectDescription
.writeToBytecode();
emit ProjectUpdated(_projectId, FIELD_PROJECT_DESCRIPTION);
}
/**
* @notice Updates website of project `_projectId` to be `_projectWebsite`.
* @param _projectId Project ID.
* @param _projectWebsite New project website.
* @dev It is intentionally allowed for this to be set to the empty string.
*/
function updateProjectWebsite(
uint256 _projectId,
string memory _projectWebsite
) external {
_onlyArtist(_projectId);
projects[_projectId].website = _projectWebsite;
emit ProjectUpdated(_projectId, FIELD_PROJECT_WEBSITE);
}
/**
* @notice Updates license for project `_projectId`.
* @param _projectId Project ID.
* @param _projectLicense New project license.
*/
function updateProjectLicense(