-
Notifications
You must be signed in to change notification settings - Fork 2
/
contract.sol
3245 lines (2829 loc) · 117 KB
/
contract.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
///////////////////////////////////////////
// File: /app/contracts/Indelible.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "erc721a/contracts/ERC721A.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Base64.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import {DefaultOperatorFilterer} from "./DefaultOperatorFilterer.sol";
import "./SSTORE2.sol";
import "./DynamicBuffer.sol";
import "./HelperLib.sol";
contract Indelible is ERC721A, DefaultOperatorFilterer, ReentrancyGuard, Ownable {
using HelperLib for uint;
using DynamicBuffer for bytes;
struct LinkedTraitDTO {
uint[] traitA;
uint[] traitB;
}
struct TraitDTO {
string name;
string mimetype;
bytes data;
bool hide;
bool useExistingData;
uint existingDataIndex;
}
struct Trait {
string name;
string mimetype;
bool hide;
}
struct ContractData {
string name;
string description;
string image;
string banner;
string website;
uint royalties;
string royaltiesRecipient;
}
struct WithdrawRecipient {
string name;
string imageUrl;
address recipientAddress;
uint percentage;
}
mapping(uint => address[]) internal _traitDataPointers;
mapping(uint => mapping(uint => Trait)) internal _traitDetails;
mapping(uint => bool) internal _renderTokenOffChain;
mapping(uint => mapping(uint => uint[])) internal _linkedTraits;
uint[15] private PRIME_NUMBERS;
uint private constant DEVELOPER_FEE = 250; // of 10,000 = 2.5%
uint private constant NUM_LAYERS = 9;
uint private constant MAX_BATCH_MINT = 20;
uint[][NUM_LAYERS] private TIERS;
string[] private LAYER_NAMES = [unicode"1 of 1's", unicode"Accessory", unicode"Eye Accessory", unicode"Hair", unicode"Mouth", unicode"Eyes", unicode"Body", unicode"Outfit", unicode"Background"];
bool private shouldWrapSVG = true;
string private backgroundColor = "transparent";
uint private randomSeedData;
WithdrawRecipient[] public withdrawRecipients;
bool public isContractSealed;
uint public constant maxSupply = 2540;
uint public maxPerAddress = 3;
uint public publicMintPrice = 0.0069 ether;
string public baseURI = "";
bool public isPublicMintActive;
bytes32 private merkleRoot = 0;
uint public allowListPrice = 0.000 ether;
uint public maxPerAllowList = 1;
bool public isAllowListActive;
ContractData public contractData = ContractData(unicode"OnChainPeople", unicode"OnChainPeople will forget what you said, what you did, but they won't forget how you made them feel. Building a community for people On-Chain 1BIT at a time.", "https://indeliblelabs-prod.s3.us-east-2.amazonaws.com/profile/250908c7-295d-4bce-84c3-84a026632b29", "https://indeliblelabs-prod.s3.us-east-2.amazonaws.com/banner/250908c7-295d-4bce-84c3-84a026632b29", "", 600, "0xAf7a60900bF698814B7D4F5E3995361F9CEE9150");
constructor() ERC721A(unicode"OnChainPeople", unicode"OCP") {
TIERS[0] = [1,1,1,1,1,1,1,2533];
TIERS[1] = [0,0,38,43,52,68,81,84,84,89,98,122,129,137,148,165,167,177,189,220,224,225];
TIERS[2] = [0,25,47,63,146,217,224,363,638,817];
TIERS[3] = [0,21,28,33,44,64,73,102,108,141,150,161,254,279,305,357,420];
TIERS[4] = [0,38,69,88,100,125,149,657,657,657];
TIERS[5] = [0,11,21,36,126,171,276,276,361,382,411,469];
TIERS[6] = [0,30,200,400,955,955];
TIERS[7] = [0,33,54,66,70,98,107,108,113,125,126,133,135,137,195,196,198,207,219,220];
TIERS[8] = [0,21,24,58,62,131,132,154,191,213,219,238,272,275,275,275];
PRIME_NUMBERS = [
823147169916224825307391528014949069340357622154256148689191,
239439210107002209100408342483681304951633794994177274881807,
931147417701026196725981216508189527323460133287836248716671,
881620940286709375756927686087073151589884188606081093706959,
655243881460218654410017181868621550334352057041656691604337,
308043264033071943254647080990150144301849302687707544552767,
577511032852311313897393410587293046739400234012091068864039,
691768493742031397614199039242108474419560046070176392220443,
197636338835913099229515612260127815566058069514897730698607
];
randomSeedData = uint(
keccak256(
abi.encodePacked(
tx.gasprice,
block.number,
block.timestamp,
block.difficulty,
blockhash(block.number - 1),
msg.sender
)
)
);
}
modifier whenMintActive() {
require(isMintActive(), "Minting is not active");
_;
}
modifier whenUnsealed() {
require(!isContractSealed, "Contract is sealed");
_;
}
receive() external payable {
require(isPublicMintActive, "Public minting is not active");
handleMint(msg.value / publicMintPrice, msg.sender);
}
function rarityGen(uint randinput, uint rarityTier)
internal
view
returns (uint)
{
uint currentLowerBound = 0;
for (uint i = 0; i < TIERS[rarityTier].length; i++) {
uint thisPercentage = TIERS[rarityTier][i];
if (
randinput >= currentLowerBound &&
randinput < currentLowerBound + thisPercentage
) return i;
currentLowerBound = currentLowerBound + thisPercentage;
}
revert();
}
function entropyForExtraData() internal view returns (uint24) {
uint randomNumber = uint(
keccak256(
abi.encodePacked(
tx.gasprice,
block.number,
block.timestamp,
block.difficulty,
blockhash(block.number - 1),
msg.sender
)
)
);
return uint24(randomNumber);
}
function stringCompare(string memory a, string memory b) internal pure returns (bool) {
return keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b));
}
function tokensAreDuplicates(uint tokenIdA, uint tokenIdB) public view returns (bool) {
return stringCompare(
tokenIdToHash(tokenIdA),
tokenIdToHash(tokenIdB)
);
}
function reRollDuplicate(
uint tokenIdA,
uint tokenIdB
) public whenUnsealed {
require(tokensAreDuplicates(tokenIdA, tokenIdB), "All tokens must be duplicates");
uint largerTokenId = tokenIdA > tokenIdB ? tokenIdA : tokenIdB;
if (msg.sender != owner()) {
require(msg.sender == ownerOf(largerTokenId), "Only the token owner or contract owner can re-roll");
}
_initializeOwnershipAt(largerTokenId);
if (_exists(largerTokenId + 1)) {
_initializeOwnershipAt(largerTokenId + 1);
}
_setExtraDataAt(largerTokenId, entropyForExtraData());
}
function _extraData(
address from,
address,
uint24 previousExtraData
) internal view virtual override returns (uint24) {
return from == address(0) ? 0 : previousExtraData;
}
function getTokenSeed(uint tokenId) internal view returns (uint24) {
return _ownershipOf(tokenId).extraData;
}
function tokenIdToHash(
uint tokenId
) public view returns (string memory) {
require(_exists(tokenId), "Invalid token");
// This will generate a NUM_LAYERS * 3 character string.
bytes memory hashBytes = DynamicBuffer.allocate(NUM_LAYERS * 4);
uint[] memory hash = new uint[](NUM_LAYERS);
bool[] memory modifiedLayers = new bool[](NUM_LAYERS);
uint traitSeed = randomSeedData % maxSupply;
for (uint i = 0; i < NUM_LAYERS; i++) {
uint traitIndex = hash[i];
if (modifiedLayers[i] == false) {
uint tokenExtraData = getTokenSeed(tokenId);
uint traitRangePosition;
if (tokenExtraData == 0) {
traitRangePosition = ((tokenId + i + traitSeed) * PRIME_NUMBERS[i]) % maxSupply;
} else {
traitRangePosition = uint(
keccak256(
abi.encodePacked(
tokenExtraData,
tokenId,
tokenId + i
)
)
) % maxSupply;
}
traitIndex = rarityGen(traitRangePosition, i);
hash[i] = traitIndex;
}
if (_linkedTraits[i][traitIndex].length > 0) {
hash[_linkedTraits[i][traitIndex][0]] = _linkedTraits[i][traitIndex][1];
modifiedLayers[_linkedTraits[i][traitIndex][0]] = true;
}
}
for (uint i = 0; i < hash.length; i++) {
if (hash[i] < 10) {
hashBytes.appendSafe("00");
} else if (hash[i] < 100) {
hashBytes.appendSafe("0");
}
if (hash[i] > 999) {
hashBytes.appendSafe("999");
} else {
hashBytes.appendSafe(bytes(_toString(hash[i])));
}
}
return string(hashBytes);
}
function handleMint(uint256 count, address recipient) internal whenMintActive returns (uint256) {
uint256 totalMinted = _totalMinted();
require(count > 0, "Invalid token count");
require(totalMinted + count <= maxSupply, "All tokens are gone");
if (isPublicMintActive) {
if (msg.sender != owner()) {
require(_numberMinted(msg.sender) + count <= maxPerAddress, "Exceeded max mints allowed");
require(count * publicMintPrice == msg.value, "Incorrect amount of ether sent");
}
require(msg.sender == tx.origin, "EOAs only");
}
uint256 batchCount = count / MAX_BATCH_MINT;
uint256 remainder = count % MAX_BATCH_MINT;
for (uint256 i = 0; i < batchCount; i++) {
_mint(recipient, MAX_BATCH_MINT);
}
if (remainder > 0) {
_mint(recipient, remainder);
}
return totalMinted;
}
function mint(uint256 count, bytes32[] calldata merkleProof)
external
payable
nonReentrant
whenMintActive
returns (uint)
{
if (!isPublicMintActive && msg.sender != owner()) {
require(onAllowList(msg.sender, merkleProof), "Not on allow list");
require(_numberMinted(msg.sender) + count <= maxPerAllowList, "Exceeded max mints allowed");
require(count * allowListPrice == msg.value, "Incorrect amount of ether sent");
}
return handleMint(count, msg.sender);
}
function airdrop(uint256 count, address recipient)
external
payable
nonReentrant
whenMintActive
returns (uint)
{
require(isPublicMintActive || msg.sender == owner(), "Public minting is not active");
return handleMint(count, recipient);
}
function isMintActive() public view returns (bool) {
return _totalMinted() < maxSupply && (isPublicMintActive || isAllowListActive || msg.sender == owner());
}
function hashToSVG(string memory _hash)
public
view
returns (string memory)
{
uint thisTraitIndex;
bytes memory svgBytes = DynamicBuffer.allocate(1024 * 128);
svgBytes.appendSafe('<svg width="1200" height="1200" viewBox="0 0 1200 1200" version="1.2" xmlns="http://www.w3.org/2000/svg" style="background-color:');
svgBytes.appendSafe(
abi.encodePacked(
backgroundColor,
";background-image:url("
)
);
for (uint i = 0; i < NUM_LAYERS - 1; i++) {
thisTraitIndex = HelperLib.parseInt(
HelperLib._substring(_hash, (i * 3), (i * 3) + 3)
);
svgBytes.appendSafe(
abi.encodePacked(
"data:",
_traitDetails[i][thisTraitIndex].mimetype,
";base64,",
Base64.encode(SSTORE2.read(_traitDataPointers[i][thisTraitIndex])),
"),url("
)
);
}
thisTraitIndex = HelperLib.parseInt(
HelperLib._substring(_hash, (NUM_LAYERS * 3) - 3, NUM_LAYERS * 3)
);
svgBytes.appendSafe(
abi.encodePacked(
"data:",
_traitDetails[NUM_LAYERS - 1][thisTraitIndex].mimetype,
";base64,",
Base64.encode(SSTORE2.read(_traitDataPointers[NUM_LAYERS - 1][thisTraitIndex])),
');background-repeat:no-repeat;background-size:contain;background-position:center;image-rendering:-webkit-optimize-contrast;-ms-interpolation-mode:nearest-neighbor;image-rendering:-moz-crisp-edges;image-rendering:pixelated;"></svg>'
)
);
return string(
abi.encodePacked(
"data:image/svg+xml;base64,",
Base64.encode(svgBytes)
)
);
}
function hashToMetadata(string memory _hash)
public
view
returns (string memory)
{
bytes memory metadataBytes = DynamicBuffer.allocate(1024 * 128);
metadataBytes.appendSafe("[");
bool afterFirstTrait;
for (uint i = 0; i < NUM_LAYERS; i++) {
uint thisTraitIndex = HelperLib.parseInt(
HelperLib._substring(_hash, (i * 3), (i * 3) + 3)
);
if (_traitDetails[i][thisTraitIndex].hide == false) {
if (afterFirstTrait) {
metadataBytes.appendSafe(",");
}
metadataBytes.appendSafe(
abi.encodePacked(
'{"trait_type":"',
LAYER_NAMES[i],
'","value":"',
_traitDetails[i][thisTraitIndex].name,
'"}'
)
);
if (afterFirstTrait == false) {
afterFirstTrait = true;
}
}
if (i == NUM_LAYERS - 1) {
metadataBytes.appendSafe("]");
}
}
return string(metadataBytes);
}
function onAllowList(address addr, bytes32[] calldata merkleProof) public view returns (bool) {
return MerkleProof.verify(merkleProof, merkleRoot, keccak256(abi.encodePacked(addr)));
}
function tokenURI(uint tokenId)
public
view
override
returns (string memory)
{
require(_exists(tokenId), "Invalid token");
require(_traitDataPointers[0].length > 0, "Traits have not been added");
string memory tokenHash = tokenIdToHash(tokenId);
bytes memory jsonBytes = DynamicBuffer.allocate(1024 * 128);
jsonBytes.appendSafe(unicode"{\"name\":\"OnChainPeople #");
jsonBytes.appendSafe(
abi.encodePacked(
_toString(tokenId),
"\",\"description\":\"",
contractData.description,
"\","
)
);
if (bytes(baseURI).length > 0 && _renderTokenOffChain[tokenId]) {
jsonBytes.appendSafe(
abi.encodePacked(
'"image":"',
baseURI,
_toString(tokenId),
"?dna=",
tokenHash,
'&network=mainnet",'
)
);
} else {
string memory svgCode = "";
if (shouldWrapSVG) {
string memory svgString = hashToSVG(tokenHash);
svgCode = string(
abi.encodePacked(
"data:image/svg+xml;base64,",
Base64.encode(
abi.encodePacked(
'<svg width="100%" height="100%" viewBox="0 0 1200 1200" version="1.2" xmlns="http://www.w3.org/2000/svg"><image width="1200" height="1200" href="',
svgString,
'"></image></svg>'
)
)
)
);
jsonBytes.appendSafe(
abi.encodePacked(
'"svg_image_data":"',
svgString,
'",'
)
);
} else {
svgCode = hashToSVG(tokenHash);
}
jsonBytes.appendSafe(
abi.encodePacked(
'"image_data":"',
svgCode,
'",'
)
);
}
jsonBytes.appendSafe(
abi.encodePacked(
'"attributes":',
hashToMetadata(tokenHash),
"}"
)
);
return string(
abi.encodePacked(
"data:application/json;base64,",
Base64.encode(jsonBytes)
)
);
}
function contractURI()
public
view
returns (string memory)
{
return string(
abi.encodePacked(
"data:application/json;base64,",
Base64.encode(
abi.encodePacked(
'{"name":"',
contractData.name,
'","description":"',
contractData.description,
'","image":"',
contractData.image,
'","banner":"',
contractData.banner,
'","external_link":"',
contractData.website,
'","seller_fee_basis_points":',
_toString(contractData.royalties),
',"fee_recipient":"',
contractData.royaltiesRecipient,
'"}'
)
)
)
);
}
function tokenIdToSVG(uint tokenId)
public
view
returns (string memory)
{
return hashToSVG(tokenIdToHash(tokenId));
}
function traitDetails(uint layerIndex, uint traitIndex)
public
view
returns (Trait memory)
{
return _traitDetails[layerIndex][traitIndex];
}
function traitData(uint layerIndex, uint traitIndex)
public
view
returns (string memory)
{
return string(SSTORE2.read(_traitDataPointers[layerIndex][traitIndex]));
}
function getLinkedTraits(uint layerIndex, uint traitIndex)
public
view
returns (uint[] memory)
{
return _linkedTraits[layerIndex][traitIndex];
}
function addLayer(uint layerIndex, TraitDTO[] memory traits)
public
onlyOwner
whenUnsealed
{
require(TIERS[layerIndex].length == traits.length, "Traits size does not match tiers for this index");
address[] memory dataPointers = new address[](traits.length);
for (uint i = 0; i < traits.length; i++) {
if (traits[i].useExistingData) {
dataPointers[i] = dataPointers[traits[i].existingDataIndex];
} else {
dataPointers[i] = SSTORE2.write(traits[i].data);
}
_traitDetails[layerIndex][i] = Trait(traits[i].name, traits[i].mimetype, traits[i].hide);
}
_traitDataPointers[layerIndex] = dataPointers;
return;
}
function addTrait(uint layerIndex, uint traitIndex, TraitDTO memory trait)
public
onlyOwner
whenUnsealed
{
_traitDetails[layerIndex][traitIndex] = Trait(trait.name, trait.mimetype, trait.hide);
address[] memory dataPointers = _traitDataPointers[layerIndex];
if (trait.useExistingData) {
dataPointers[traitIndex] = dataPointers[trait.existingDataIndex];
} else {
dataPointers[traitIndex] = SSTORE2.write(trait.data);
}
_traitDataPointers[layerIndex] = dataPointers;
return;
}
function setLinkedTraits(LinkedTraitDTO[] memory linkedTraits)
public
onlyOwner
whenUnsealed
{
for (uint i = 0; i < linkedTraits.length; i++) {
_linkedTraits[linkedTraits[i].traitA[0]][linkedTraits[i].traitA[1]] = [linkedTraits[i].traitB[0],linkedTraits[i].traitB[1]];
}
}
function setContractData(ContractData memory data) external onlyOwner whenUnsealed {
contractData = data;
}
function setMaxPerAddress(uint max) external onlyOwner {
maxPerAddress = max;
}
function setBaseURI(string memory uri) external onlyOwner {
baseURI = uri;
}
function setBackgroundColor(string memory color) external onlyOwner whenUnsealed {
backgroundColor = color;
}
function setRenderOfTokenId(uint tokenId, bool renderOffChain) external {
require(msg.sender == ownerOf(tokenId), "Only the token owner can set the render method");
_renderTokenOffChain[tokenId] = renderOffChain;
}
function setMerkleRoot(bytes32 newMerkleRoot) external onlyOwner {
merkleRoot = newMerkleRoot;
}
function setMaxPerAllowList(uint max) external onlyOwner {
maxPerAllowList = max;
}
function setAllowListPrice(uint price) external onlyOwner {
allowListPrice = price;
}
function toggleAllowListMint() external onlyOwner {
isAllowListActive = !isAllowListActive;
}
function toggleOperatorFilter() external onlyOwner {
isOperatorFilterEnabled = !isOperatorFilterEnabled;
}
function toggleWrapSVG() external onlyOwner {
shouldWrapSVG = !shouldWrapSVG;
}
function togglePublicMint() external onlyOwner {
isPublicMintActive = !isPublicMintActive;
}
function sealContract() external whenUnsealed onlyOwner {
isContractSealed = true;
}
function withdraw() external onlyOwner nonReentrant {
uint balance = address(this).balance;
uint amount = (balance * (10000 - DEVELOPER_FEE)) / 10000;
uint distAmount = 0;
uint totalDistributionPercentage = 0;
address payable receiver = payable(owner());
address payable dev = payable(0xEA208Da933C43857683C04BC76e3FD331D7bfdf7);
Address.sendValue(dev, balance - amount);
if (withdrawRecipients.length > 0) {
for (uint i = 0; i < withdrawRecipients.length; i++) {
totalDistributionPercentage = totalDistributionPercentage + withdrawRecipients[i].percentage;
address payable currRecepient = payable(withdrawRecipients[i].recipientAddress);
distAmount = (amount * (10000 - withdrawRecipients[i].percentage)) / 10000;
Address.sendValue(currRecepient, amount - distAmount);
}
}
balance = address(this).balance;
Address.sendValue(receiver, balance);
}
function transferFrom(address from, address to, uint256 tokenId)
public
payable
override
onlyAllowedOperator(from)
{
super.transferFrom(from, to, tokenId);
}
function safeTransferFrom(address from, address to, uint256 tokenId)
public
payable
override
onlyAllowedOperator(from)
{
super.safeTransferFrom(from, to, tokenId);
}
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data)
public
payable
override
onlyAllowedOperator(from)
{
super.safeTransferFrom(from, to, tokenId, data);
}
}
///////////////////////////////////////////
// File: /app/contracts/DefaultOperatorFilterer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {OperatorFilterer} from "./OperatorFilterer.sol";
abstract contract DefaultOperatorFilterer is OperatorFilterer {
address constant DEFAULT_SUBSCRIPTION = address(0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6);
constructor() OperatorFilterer(DEFAULT_SUBSCRIPTION, true) {}
}
///////////////////////////////////////////
// File: /app/contracts/DynamicBuffer.sol
// SPDX-License-Identifier: MIT
// Copyright (c) 2021 the ethier authors (github.com/divergencetech/ethier)
pragma solidity >=0.8.0;
/// @title DynamicBuffer
/// @author David Huber (@cxkoda) and Simon Fremaux (@dievardump). See also
/// https://raw.githubusercontent.com/dievardump/solidity-dynamic-buffer
/// @notice This library is used to allocate a big amount of container memory
// which will be subsequently filled without needing to reallocate
/// memory.
/// @dev First, allocate memory.
/// Then use `buffer.appendUnchecked(theBytes)` or `appendSafe()` if
/// bounds checking is required.
library DynamicBuffer {
/// @notice Allocates container space for the DynamicBuffer
/// @param capacity The intended max amount of bytes in the buffer
/// @return buffer The memory location of the buffer
/// @dev Allocates `capacity + 0x60` bytes of space
/// The buffer array starts at the first container data position,
/// (i.e. `buffer = container + 0x20`)
function allocate(uint256 capacity)
internal
pure
returns (bytes memory buffer)
{
assembly {
// Get next-free memory address
let container := mload(0x40)
// Allocate memory by setting a new next-free address
{
// Add 2 x 32 bytes in size for the two length fields
// Add 32 bytes safety space for 32B chunked copy
let size := add(capacity, 0x60)
let newNextFree := add(container, size)
mstore(0x40, newNextFree)
}
// Set the correct container length
{
let length := add(capacity, 0x40)
mstore(container, length)
}
// The buffer starts at idx 1 in the container (0 is length)
buffer := add(container, 0x20)
// Init content with length 0
mstore(buffer, 0)
}
return buffer;
}
/// @notice Appends data to buffer, and update buffer length
/// @param buffer the buffer to append the data to
/// @param data the data to append
/// @dev Does not perform out-of-bound checks (container capacity)
/// for efficiency.
function appendUnchecked(bytes memory buffer, bytes memory data)
internal
pure
{
assembly {
let length := mload(data)
for {
data := add(data, 0x20)
let dataEnd := add(data, length)
let copyTo := add(buffer, add(mload(buffer), 0x20))
} lt(data, dataEnd) {
data := add(data, 0x20)
copyTo := add(copyTo, 0x20)
} {
// Copy 32B chunks from data to buffer.
// This may read over data array boundaries and copy invalid
// bytes, which doesn't matter in the end since we will
// later set the correct buffer length, and have allocated an
// additional word to avoid buffer overflow.
mstore(copyTo, mload(data))
}
// Update buffer length
mstore(buffer, add(mload(buffer), length))
}
}
/// @notice Appends data to buffer, and update buffer length
/// @param buffer the buffer to append the data to
/// @param data the data to append
/// @dev Performs out-of-bound checks and calls `appendUnchecked`.
function appendSafe(bytes memory buffer, bytes memory data) internal pure {
uint256 capacity;
uint256 length;
assembly {
capacity := sub(mload(sub(buffer, 0x20)), 0x40)
length := mload(buffer)
}
require(
length + data.length <= capacity,
"DynamicBuffer: Appending out of bounds."
);
appendUnchecked(buffer, data);
}
}
///////////////////////////////////////////
// File: /app/contracts/HelperLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;
library HelperLib {
function parseInt(string memory _a)
internal
pure
returns (uint8 _parsedInt)
{
bytes memory bresult = bytes(_a);
uint8 mint = 0;
for (uint8 i = 0; i < bresult.length; i++) {
if (
(uint8(uint8(bresult[i])) >= 48) &&
(uint8(uint8(bresult[i])) <= 57)
) {
mint *= 10;
mint += uint8(bresult[i]) - 48;
}
}
return mint;
}
function _substring(
string memory str,
uint256 startIndex,
uint256 endIndex
) internal pure returns (string memory) {
bytes memory strBytes = bytes(str);
bytes memory result = new bytes(endIndex - startIndex);
for (uint256 i = startIndex; i < endIndex; i++) {
result[i - startIndex] = strBytes[i];
}
return string(result);
}
}
///////////////////////////////////////////
// File: /app/contracts/IOperatorFilterRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
interface IOperatorFilterRegistry {
function isOperatorAllowed(address registrant, address operator) external view returns (bool);
function register(address registrant) external;
function registerAndSubscribe(address registrant, address subscription) external;
function registerAndCopyEntries(address registrant, address registrantToCopy) external;
function updateOperator(address registrant, address operator, bool filtered) external;
function updateOperators(address registrant, address[] calldata operators, bool filtered) external;
function updateCodeHash(address registrant, bytes32 codehash, bool filtered) external;
function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered) external;
function subscribe(address registrant, address registrantToSubscribe) external;
function unsubscribe(address registrant, bool copyExistingEntries) external;
function subscriptionOf(address addr) external returns (address registrant);
function subscribers(address registrant) external returns (address[] memory);
function subscriberAt(address registrant, uint256 index) external returns (address);
function copyEntriesOf(address registrant, address registrantToCopy) external;
function isOperatorFiltered(address registrant, address operator) external returns (bool);
function isCodeHashOfFiltered(address registrant, address operatorWithCode) external returns (bool);
function isCodeHashFiltered(address registrant, bytes32 codeHash) external returns (bool);
function filteredOperators(address addr) external returns (address[] memory);
function filteredCodeHashes(address addr) external returns (bytes32[] memory);
function filteredOperatorAt(address registrant, uint256 index) external returns (address);
function filteredCodeHashAt(address registrant, uint256 index) external returns (bytes32);
function isRegistered(address addr) external returns (bool);
function codeHashOf(address addr) external returns (bytes32);
}
///////////////////////////////////////////
// File: /app/contracts/OperatorFilterer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {IOperatorFilterRegistry} from "./IOperatorFilterRegistry.sol";
abstract contract OperatorFilterer {
error OperatorNotAllowed(address operator);
bool public isOperatorFilterEnabled = true;
IOperatorFilterRegistry constant operatorFilterRegistry =
IOperatorFilterRegistry(0x000000000000AAeB6D7670E522A718067333cd4E);
constructor(address subscriptionOrRegistrantToCopy, bool subscribe) {
// If an inheriting token contract is deployed to a network without the registry deployed, the modifier
// will not revert, but the contract will need to be registered with the registry once it is deployed in
// order for the modifier to filter addresses.
if (address(operatorFilterRegistry).code.length > 0) {
if (subscribe) {
operatorFilterRegistry.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
} else {
if (subscriptionOrRegistrantToCopy != address(0)) {
operatorFilterRegistry.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
} else {
operatorFilterRegistry.register(address(this));
}
}
}
}
modifier onlyAllowedOperator(address from) virtual {
// Check if filter operator is enabled
if (!isOperatorFilterEnabled) {
_;
return;
}
// Check registry code length to facilitate testing in environments without a deployed registry.
if (address(operatorFilterRegistry).code.length > 0) {
// Allow spending tokens from addresses with balance
// Note that this still allows listings and marketplaces with escrow to transfer tokens if transferred
// from an EOA.
if (from == msg.sender) {
_;
return;
}
if (
!(
operatorFilterRegistry.isOperatorAllowed(address(this), msg.sender)
&& operatorFilterRegistry.isOperatorAllowed(address(this), from)
)
) {
revert OperatorNotAllowed(msg.sender);
}
}
_;
}
}
///////////////////////////////////////////
// File: /app/contracts/SSTORE2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./utils/Bytecode.sol";
/**
@title A key-value storage with auto-generated keys for storing chunks of data with a lower write & read cost.
@author Agustin Aguilar <[email protected]>
Readme: https://github.com/0xsequence/sstore2#readme
*/
library SSTORE2 {
error WriteError();
/**
@notice Stores `_data` and returns `pointer` as key for later retrieval
@dev The pointer is a contract address with `_data` as code