编译器
0.8.16+commit.07a7930e
文件 1 的 24:AssetRetriever.sol
pragma solidity 0.8.16;
import "./TraitBase.sol";
contract AssetRetriever {
TraitBase[] internal traitBases;
constructor(TraitBase[] memory _traitBases) {
traitBases = _traitBases;
}
function getAsset(uint assetID) public view returns (string memory) {
if (assetID == 0) {
return "";
}
return traitBases[assetID / 1000 - 1].getAssetFromTrait(assetID);
}
}
文件 2 的 24:Base64.sol
pragma solidity ^0.8.4;
library Base64 {
function encode(bytes memory data, bool fileSafe, bool noPadding)
internal
pure
returns (string memory result)
{
assembly {
let dataLength := mload(data)
if dataLength {
let encodedLength := shl(2, div(add(dataLength, 2), 3))
result := mload(0x40)
mstore(0x1f, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef")
mstore(0x3f, sub("ghijklmnopqrstuvwxyz0123456789-_", mul(iszero(fileSafe), 0x0230)))
let ptr := add(result, 0x20)
let end := add(ptr, encodedLength)
for {} 1 {} {
data := add(data, 3)
let input := mload(data)
mstore8(0, mload(and(shr(18, input), 0x3F)))
mstore8(1, mload(and(shr(12, input), 0x3F)))
mstore8(2, mload(and(shr(6, input), 0x3F)))
mstore8(3, mload(and(input, 0x3F)))
mstore(ptr, mload(0x00))
ptr := add(ptr, 4)
if iszero(lt(ptr, end)) { break }
}
mstore(0x40, and(add(end, 31), not(31)))
let o := div(2, mod(dataLength, 3))
mstore(sub(ptr, o), shl(240, 0x3d3d))
o := mul(iszero(iszero(noPadding)), o)
mstore(sub(ptr, o), 0)
mstore(result, sub(encodedLength, o))
}
}
}
function encode(bytes memory data) internal pure returns (string memory result) {
result = encode(data, false, false);
}
function encode(bytes memory data, bool fileSafe)
internal
pure
returns (string memory result)
{
result = encode(data, fileSafe, false);
}
function decode(string memory data) internal pure returns (bytes memory result) {
assembly {
let dataLength := mload(data)
if dataLength {
let decodedLength := mul(shr(2, dataLength), 3)
for {} 1 {} {
if iszero(and(dataLength, 3)) {
let t := xor(mload(add(data, dataLength)), 0x3d3d)
decodedLength := sub(
decodedLength,
add(iszero(byte(30, t)), iszero(byte(31, t)))
)
break
}
decodedLength := add(decodedLength, sub(and(dataLength, 3), 1))
break
}
result := mload(0x40)
mstore(result, decodedLength)
let ptr := add(result, 0x20)
let end := add(ptr, decodedLength)
let m := 0xfc000000fc00686c7074787c8084888c9094989ca0a4a8acb0b4b8bcc0c4c8cc
mstore(0x5b, m)
mstore(0x3b, 0x04080c1014181c2024282c3034383c4044484c5054585c6064)
mstore(0x1a, 0xf8fcf800fcd0d4d8dce0e4e8ecf0f4)
for {} 1 {} {
data := add(data, 4)
let input := mload(data)
mstore(ptr, or(
and(m, mload(byte(28, input))),
shr(6, or(
and(m, mload(byte(29, input))),
shr(6, or(
and(m, mload(byte(30, input))),
shr(6, mload(byte(31, input)))
))
))
))
ptr := add(ptr, 3)
if iszero(lt(ptr, end)) { break }
}
mstore(0x40, and(add(end, 31), not(31)))
mstore(end, 0)
mstore(0x60, 0)
}
}
}
}
文件 3 的 24:Clifford.sol
pragma solidity 0.8.16;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "ERC721A/ERC721A.sol";
import "./Metadata.sol";
import "solady/utils/LibBitmap.sol";
interface ICypher {
function ownerOf(uint) external view returns (address);
}
contract Clifford is ERC721A, Ownable, VRFConsumerBaseV2 {
address private constant vrfCoordinator = 0x271682DEB8C4E0901D1a1550aD2e64D568E69909;
VRFCoordinatorV2Interface constant COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator);
LinkTokenInterface constant LINKTOKEN = LinkTokenInterface(0x514910771AF9Ca656af840dff83E8264EcF986CA);
error InvalidTokenId(uint tokenId);
error SeedNotSet(uint genId);
error TransferFailed();
error NotOwnerOfCypher(uint tokenId);
error CypherAlreadyClaimed(uint tokenId);
error CypherClaimNotActive();
error CannotBidZero();
error IncorrectBidIncrement(uint amount);
error AuctionNotActive();
error BidTooSmall(uint amount);
error AuctionAlreadyStarted();
error CypherClaimNotStarted();
error CypherClaimNotEnded();
error AuctionNotOver();
error NftsNotAllMinted();
error TransferNotSuccessful(address to);
error NoBidToClaim(address to);
error TooManyRequested();
event RandomNumberGenerated(uint256 genId, uint256 seed);
event RandomnessRequested(uint256 genId);
event UserPlacesBid(address user, uint amount);
mapping(uint256 => uint256) private requestIdToGenId;
mapping(uint256 => uint256) private genSeed;
mapping(uint256 => uint256) private genIdToTokenId;
mapping(address => uint) private allBids;
uint256 public constant MAX_SUPPLY = 6_000;
bytes32 private constant keyHash = 0xff8dedfbfa60af186cf3c830acbc32c05aae823045ae5ea7da1e45fbfaba4f92;
uint32 private constant callbackGasLimit = 100_000;
uint16 private constant requestConfirmations = 3;
uint32 private constant numWords = 1;
uint64 public constant s_subscriptionId = 747;
uint private constant BID_INCREMENT = 0.01 ether;
uint private constant AUCTION_LENGTH = 1 weeks;
uint private constant CLAIM_PERIOD = 1 weeks;
uint private constant BID_EXTENSION_LENGTH = 15 minutes;
uint private constant BID_INCREASE_PERCENT = 10;
ICypher internal constant CYPHER_CONTRACT = ICypher(0xdDA32aabBBB6c44eFC567baC5F7C35f185338456);
uint private currentGen;
uint private numOfCyphersClaimed;
LibBitmap.Bitmap private cypherClaims;
uint private startedAt;
uint private endAt;
uint private sumOfAllBids;
address[] private allBidders;
Metadata private immutable _metadata;
constructor(Metadata metadata) ERC721A("AMachineForDying", "AMFD") VRFConsumerBaseV2(vrfCoordinator) {
_metadata = metadata;
}
function reveal() external onlyOwner {
uint gen = currentGen;
genIdToTokenId[gen] = totalSupply();
currentGen++;
uint256 s_requestId = COORDINATOR.requestRandomWords(
keyHash,
s_subscriptionId,
requestConfirmations,
callbackGasLimit,
numWords
);
requestIdToGenId[s_requestId] = gen;
emit RandomnessRequested(gen);
}
function fulfillRandomWords(
uint256 requestId,
uint256[] memory randomWords
) internal override {
uint256 randomness = randomWords[0];
uint256 genId = requestIdToGenId[requestId];
delete requestIdToGenId[genId];
genSeed[genId] = randomness;
emit RandomNumberGenerated(genId, randomness);
}
function startCypherClaimPeriod() external onlyOwner {
startedAt = block.timestamp + CLAIM_PERIOD;
endAt = block.timestamp + CLAIM_PERIOD + AUCTION_LENGTH;
}
function _validateCypherClaim(uint tokenId) internal {
if (msg.sender != CYPHER_CONTRACT.ownerOf(tokenId)) revert NotOwnerOfCypher(tokenId);
if (LibBitmap.get(cypherClaims, tokenId)) revert CypherAlreadyClaimed(tokenId);
LibBitmap.set(cypherClaims, tokenId);
}
function claimCyphers(uint[] memory tokenIds) external {
if (block.timestamp >= startedAt) revert CypherClaimNotActive();
uint numOfCyphers = tokenIds.length;
numOfCyphersClaimed += numOfCyphers;
for (uint i = 0; i < numOfCyphers;) {
_validateCypherClaim(tokenIds[i]);
unchecked {
++i;
}
}
_mint(msg.sender, numOfCyphers);
}
function placeBid() external payable {
if (block.timestamp >= endAt || block.timestamp < startedAt) revert AuctionNotActive();
uint bidAmount = msg.value;
if (bidAmount == 0) revert CannotBidZero();
if (bidAmount % BID_INCREMENT != 0) revert IncorrectBidIncrement(bidAmount);
uint totalBidsFromBidder = bidAmount + allBids[msg.sender];
if (totalBidsFromBidder < getMinimumBid()) revert BidTooSmall(bidAmount);
if (block.timestamp + BID_EXTENSION_LENGTH > endAt) {
endAt = block.timestamp + BID_EXTENSION_LENGTH;
}
if (bidAmount == totalBidsFromBidder) {
allBidders.push(msg.sender);
}
sumOfAllBids += bidAmount;
allBids[msg.sender] = totalBidsFromBidder;
emit UserPlacesBid(msg.sender, totalBidsFromBidder);
}
function claimAfterAuction() external {
if (block.timestamp < endAt + BID_EXTENSION_LENGTH || block.timestamp > endAt + CLAIM_PERIOD) revert AuctionNotOver();
if (allBids[msg.sender] == 0) revert NoBidToClaim(msg.sender);
uint pricePerUnit = getCurrentPricePerUnit();
uint amount = allBids[msg.sender];
uint quantityToMint = amount / pricePerUnit;
allBids[msg.sender] = 0;
if (quantityToMint > 0) {
_mint(msg.sender, quantityToMint);
}
uint remainder = amount % pricePerUnit;
(bool success, ) = (msg.sender).call{value: remainder}("");
if (!success) revert TransferNotSuccessful(msg.sender);
}
function withdrawRemainingNFTs(uint amount) external onlyOwner {
if (startedAt == 0 || block.timestamp < endAt + CLAIM_PERIOD) revert AuctionNotOver();
if (totalSupply() + amount > MAX_SUPPLY) revert TooManyRequested();
_mint(owner(), amount);
}
function withdraw() external onlyOwner {
if (totalSupply() != MAX_SUPPLY) revert NftsNotAllMinted();
(bool success, ) = msg.sender.call{value: address(this).balance}("");
if (!success) revert TransferFailed();
}
function getSeed(uint256 tokenId) public view returns (uint256) {
if (tokenId >= totalSupply()) revert InvalidTokenId(tokenId);
for (uint i = 0; i < currentGen;) {
if (tokenId < genIdToTokenId[i]) {
uint seed = genSeed[i];
return uint256(keccak256(abi.encodePacked(seed, tokenId)));
}
unchecked {
++i;
}
}
return 0;
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
uint seed = getSeed(tokenId);
if (seed == 0) {
return "ipfs://QmTJf1jnE2E8iMtVdVvdcCUwC1D8kJ4Qktise1XM1CfvyS";
}
return _metadata.buildMetadata(tokenId, seed);
}
function getCurrentPricePerUnit() public view returns (uint) {
return sumOfAllBids / (MAX_SUPPLY - numOfCyphersClaimed);
}
function getMinimumBid() public view returns (uint) {
uint minimum = getCurrentPricePerUnit() + getCurrentPricePerUnit() / BID_INCREASE_PERCENT;
if (minimum <= BID_INCREMENT) {
return BID_INCREMENT;
} else {
return minimum - minimum % BID_INCREMENT + BID_INCREMENT;
}
}
function getAllBidders() external view returns (address[] memory) {
return allBidders;
}
function getUserBid(address bidder) external view returns (uint) {
return allBids[bidder];
}
function getStartTimestamp() external view returns(uint) {
return startedAt;
}
function getEndTimestamp() external view returns(uint) {
return endAt;
}
function getIfCypherClaimed(uint tokenId) external view returns(bool) {
return LibBitmap.get(cypherClaims, tokenId);
}
}
文件 4 的 24:CommonSVG.sol
pragma solidity 0.8.16;
import "./Environment.sol";
import "./Patterns.sol";
import "./GridHelper.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
library CommonSVG {
string internal constant SVG_START = "<svg xmlns='http://www.w3.org/2000/svg' shape-rendering='geometricPrecision' text-rendering='geometricPrecision' width='936' height='1080' xmlns:xlink='http://www.w3.org/1999/xlink'>";
string internal constant DUOTONE_DEFS = "<linearGradient id='lDT' gradientTransform='rotate(45)'><stop offset='0.2' stop-color='hsla(0, 0%, 0%, 0)'></stop><stop offset='1' stop-color='hsla(0, 0%, 0%, 0.2)'></stop></linearGradient><linearGradient id='rDT' gradientTransform='rotate(0)'><stop offset='0.2' stop-color='hsla(0, 0%, 0%, 0)'></stop><stop offset='1' stop-color='hsla(0, 0%, 0%, 0.2)'></stop></linearGradient><linearGradient id='fDT' gradientTransform='rotate(90)'><stop offset='0' stop-color='hsla(0, 0%, 0%, 0)'></stop><stop offset='1' stop-color='hsla(0, 0%, 0%, 0.2)'></stop></linearGradient>";
string internal constant SCRIPT = "<script type='text/javascript' href='https://demowebdevukssa2.z33.web.core.windows.net/html-svg/pocs/0311/anma.js' xlink:actuate='onLoad' xlink:show='other' xlink:type='simple' />";
string internal constant STYLE = "<style>";
string internal constant TEMP_STYLE = "<style> .no-animation * { animation: none !important; transition: none !important; } </style>";
string internal constant STYLE_CLOSE = "</style>";
string internal constant G_START = "<g>";
string internal constant FLIPPED = "<g style='transform:scaleX(-1);transform-origin:50% 50%;'>";
string internal constant NOT_FLIPPED = "<g style='transform:scaleX(1);transform-origin:50% 50%;'>";
string internal constant SHELL_OPEN = "<g style='transform:scaleX(";
string internal constant SHELL_CLOSE = ");transform-origin:50% 50%;' id='shell' clip-path='url(#clipPathShell)' ";
string internal constant ROTATIONS = "-40-45-45";
string internal constant OBJECT_GRADIENTS_IDS = "c0lc0bc0dc1lc1bc1dc2lc2bc2dc3lc3bc3dc4lc4bc4dc5lc5bc5d";
string internal constant LIGHTEN_PERCENTAGES = "025000025";
string internal constant GRADIENT_STYLE_OPEN = "<style id='gradient-colors'> :root { ";
string internal constant GRADIENT_STYLE_CLOSE = " } </style>";
string internal constant GLOBAL_COLOURS = "051093072042080068328072085327073074027087076025054060000000069000000050085092060082067051051093072060088081002087076000054060000000069000000050322092060322092056322092060322092056047084056046068047000000069000000050";
string internal constant GLOBAL_COLOURS_IDS = "g0g1g2g3g4g5g6g7";
string internal constant SHELL_COLOUR_IDS = "s2s1s0";
string internal constant CHARACTER_COLOUR_IDS = "r0";
string internal constant VIGNETTE_GRADIENT = "<clipPath id='clipPathShell'><polygon points='0,270 468,0 936,270 936,810 468,1080 0,810'/></clipPath><radialGradient id='vig1-u-vig1-fill' cx='0' cy='0' r='0.5' spreadMethod='pad' gradientUnits='objectBoundingBox' gradientTransform='translate(0.43 0.5)'><stop id='vig1-u-vig1-fill-0' offset='50%' stop-color='#000' stop-opacity='0'/><stop id='vig1-u-vig1-fill-1' offset='100%' stop-color='#000' stop-opacity='0.3'/></radialGradient>";
string internal constant PATTERNS_START = "<pattern id='shell-pattern' patternUnits='objectBoundingBox' x='0' y='0' width='";
string internal constant PATTERNS_HEIGHT = "' height='";
string internal constant PATTERNS_SCALE_OPEN = "' patternTransform=' scale(";
string internal constant PATTERNS_SCALE_CLOSE = ")'><use xmlns:xlink='http://www.w3.org/1999/xlink' xlink:href='#mp2-u-group-";
string internal constant PATTERNS_END = "' id='shell-pattern-use' class='pulsateInOutOld'/></pattern>";
string internal constant OPACITY_START = "<g id='leftWall'><polygon points='0,270 468,0 468,540 0,810' fill='url(#s0)' stroke='black'/><g id='leftWallPat' transform='skewY(-30)'><rect x='0' y='270' width='468' height='540' opacity='";
string internal constant OPACITY_MID_ONE = "%' style='mix-blend-mode: normal;' fill='url(#shell-pattern)'/></g><polygon points='0,270 468,0 468,540 0,810' fill='url(#lDT)' stroke='black'/></g><g id='rightWall'><polygon points='468,540 468,0 936,270 936,810' fill='url(#s1)' stroke='black'/><g id='rightWallPat' transform='skewY(30)'><rect x='468' y='-270' width='468' height='540' opacity='";
string internal constant OPACITY_MID_TWO = "%' style='mix-blend-mode: normal;' fill='url(#shell-pattern)'/></g><polygon points='468,540 468,0 936,270 936,810' fill='url(#rDT)' stroke='black'/></g><g id='floor'><polygon id='polygon-floor-border' points='0,810 468,1080 936,810 468,540' fill='url(#s2)' stroke='black'/><g id='floorPat' transform='translate(234 135) rotate(60)' transform-origin='0 540'><g transform='skewY(-30)' transform-origin='0 0'><rect id='floorPatRect' x='0' y='270' width='468' height='540' opacity='";
string internal constant OPACITY_END = "%' style='mix-blend-mode: normal;' fill='url(#shell-pattern)'/></g></g><polygon id='polygon-floor-border-DT' points='0,810 468,1080 936,810 468,540' fill='url(#fDT)' stroke='black'/></g>";
function createObjectGradient(uint[6] memory colours, string memory id) internal pure returns (string memory) {
string memory output = string.concat(
"<linearGradient id='",
id,
"' x1='0%' y1='0%' x2='100%' y2='0%'><stop offset='0%' stop-color='hsl(",
Strings.toString(colours[0]),
",",
Strings.toString(colours[1]),
"%,"
);
output = string.concat(
output,
Strings.toString(colours[2]),
"%)'/><stop offset='100%' stop-color='hsl(",
Strings.toString(colours[3]),
",",
Strings.toString(colours[4]),
"%,",
Strings.toString(colours[5]),
"%)'/></linearGradient>"
);
return output;
}
function appendToGradientStyle(string memory gradientStyle, string memory id, uint h, uint s, uint l) internal pure returns (string memory) {
return string.concat(
gradientStyle,
"--",
id,
": hsl(",
Strings.toString(h),
",",
Strings.toString(s),
"%,",
Strings.toString(l),
"%); "
);
}
function getshellColours(string memory machine, uint colourValue) external pure returns(string memory) {
uint[] memory baseColours = Environment.getColours(machine, colourValue);
string memory gradientStyle = GRADIENT_STYLE_OPEN;
string[] memory objectGradients = new string[](18);
for (uint i = 0; i < 6; ++i) {
for (uint j = 0; j < 3; ++j) {
objectGradients[i*3+j] = createObjectGradient([baseColours[i*6], baseColours[i*6+1], baseColours[i*6+2], baseColours[i*6+3], baseColours[i*6+4], baseColours[i*6+5]], string(GridHelper.slice(bytes(OBJECT_GRADIENTS_IDS), i*9+3*j, 3)));
if (j == 1) {
gradientStyle = appendToGradientStyle(gradientStyle, string(GridHelper.slice(bytes(OBJECT_GRADIENTS_IDS), i*9+3*j, 3)), baseColours[i*6], baseColours[i*6+1], baseColours[i*6+2]);
} else {
gradientStyle = appendToGradientStyle(gradientStyle, string(GridHelper.slice(bytes(OBJECT_GRADIENTS_IDS), i*9+3*j, 3)), baseColours[i*6+3], baseColours[i*6+4], baseColours[i*6+5]);
}
}
}
string[] memory shellColours = new string[](3);
for (uint i = 0; i < 3; ++i) {
shellColours[i] = createObjectGradient([baseColours[i*6], baseColours[i*6+1], baseColours[i*6+2], baseColours[i*6+3], baseColours[i*6+4], baseColours[i*6+5]], string(GridHelper.slice(bytes(SHELL_COLOUR_IDS), i*2, 2)));
}
uint[] memory globalColours = GridHelper.setUintArrayFromString(GLOBAL_COLOURS, 72, 3);
uint globalOffset = 0;
if (colourValue > 170) {
globalOffset = 48;
} else if (colourValue > 84) {
globalOffset = 24;
}
for (uint i = 0; i < 8; ++i) {
gradientStyle = appendToGradientStyle(gradientStyle, string(GridHelper.slice(bytes(GLOBAL_COLOURS_IDS), i*2, 2)), globalColours[i*3+globalOffset], globalColours[i*3+1+globalOffset], globalColours[i*3+2+globalOffset]);
}
gradientStyle = appendToGradientStyle(gradientStyle, string(GridHelper.slice(bytes(CHARACTER_COLOUR_IDS), 0, 2)), baseColours[0], baseColours[1], 90);
gradientStyle = string.concat(gradientStyle, GRADIENT_STYLE_CLOSE);
string memory returnDefs = string.concat(
gradientStyle,
"<defs>",
VIGNETTE_GRADIENT,
DUOTONE_DEFS
);
for (uint i = 0; i < 18; ++i) {
returnDefs = string.concat(returnDefs, objectGradients[i]);
}
for (uint i = 0; i < 3; ++i) {
returnDefs = string.concat(returnDefs, shellColours[i]);
}
returnDefs = string.concat(returnDefs, "</defs>");
return returnDefs;
}
function createShellPattern(uint rand, int baseline) external pure returns(string memory) {
return string.concat(
PATTERNS_START,
"0.330",
PATTERNS_HEIGHT,
"0.330",
PATTERNS_SCALE_OPEN,
Patterns.getScale(rand, baseline),
PATTERNS_SCALE_CLOSE,
Patterns.getPatternName(rand, baseline),
PATTERNS_END
);
}
function createShellOpacity(uint rand, int baseline) external pure returns(string memory) {
return string.concat(
OPACITY_START,
Patterns.getOpacity(rand, baseline, 0),
OPACITY_MID_ONE,
Patterns.getOpacity(rand, baseline, 1),
OPACITY_MID_TWO,
Patterns.getOpacity(rand, baseline, 2),
OPACITY_END
);
}
}
文件 5 的 24:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 6 的 24:ERC721A.sol
pragma solidity ^0.8.4;
import './IERC721A.sol';
interface ERC721A__IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
contract ERC721A is IERC721A {
struct TokenApprovalRef {
address value;
}
uint256 private constant _BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1;
uint256 private constant _BITPOS_NUMBER_MINTED = 64;
uint256 private constant _BITPOS_NUMBER_BURNED = 128;
uint256 private constant _BITPOS_AUX = 192;
uint256 private constant _BITMASK_AUX_COMPLEMENT = (1 << 192) - 1;
uint256 private constant _BITPOS_START_TIMESTAMP = 160;
uint256 private constant _BITMASK_BURNED = 1 << 224;
uint256 private constant _BITPOS_NEXT_INITIALIZED = 225;
uint256 private constant _BITMASK_NEXT_INITIALIZED = 1 << 225;
uint256 private constant _BITPOS_EXTRA_DATA = 232;
uint256 private constant _BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1;
uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1;
uint256 private constant _MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000;
bytes32 private constant _TRANSFER_EVENT_SIGNATURE =
0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;
uint256 private _currentIndex;
uint256 private _burnCounter;
string private _name;
string private _symbol;
mapping(uint256 => uint256) private _packedOwnerships;
mapping(address => uint256) private _packedAddressData;
mapping(uint256 => TokenApprovalRef) private _tokenApprovals;
mapping(address => mapping(address => bool)) private _operatorApprovals;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
_currentIndex = _startTokenId();
}
function _startTokenId() internal view virtual returns (uint256) {
return 0;
}
function _nextTokenId() internal view virtual returns (uint256) {
return _currentIndex;
}
function totalSupply() public view virtual override returns (uint256) {
unchecked {
return _currentIndex - _burnCounter - _startTokenId();
}
}
function _totalMinted() internal view virtual returns (uint256) {
unchecked {
return _currentIndex - _startTokenId();
}
}
function _totalBurned() internal view virtual returns (uint256) {
return _burnCounter;
}
function balanceOf(address owner) public view virtual override returns (uint256) {
if (owner == address(0)) revert BalanceQueryForZeroAddress();
return _packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY;
}
function _numberMinted(address owner) internal view returns (uint256) {
return (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) & _BITMASK_ADDRESS_DATA_ENTRY;
}
function _numberBurned(address owner) internal view returns (uint256) {
return (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) & _BITMASK_ADDRESS_DATA_ENTRY;
}
function _getAux(address owner) internal view returns (uint64) {
return uint64(_packedAddressData[owner] >> _BITPOS_AUX);
}
function _setAux(address owner, uint64 aux) internal virtual {
uint256 packed = _packedAddressData[owner];
uint256 auxCasted;
assembly {
auxCasted := aux
}
packed = (packed & _BITMASK_AUX_COMPLEMENT) | (auxCasted << _BITPOS_AUX);
_packedAddressData[owner] = packed;
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return
interfaceId == 0x01ffc9a7 ||
interfaceId == 0x80ac58cd ||
interfaceId == 0x5b5e139f;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
if (!_exists(tokenId)) revert URIQueryForNonexistentToken();
string memory baseURI = _baseURI();
return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, _toString(tokenId))) : '';
}
function _baseURI() internal view virtual returns (string memory) {
return '';
}
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
return address(uint160(_packedOwnershipOf(tokenId)));
}
function _ownershipOf(uint256 tokenId) internal view virtual returns (TokenOwnership memory) {
return _unpackedOwnership(_packedOwnershipOf(tokenId));
}
function _ownershipAt(uint256 index) internal view virtual returns (TokenOwnership memory) {
return _unpackedOwnership(_packedOwnerships[index]);
}
function _initializeOwnershipAt(uint256 index) internal virtual {
if (_packedOwnerships[index] == 0) {
_packedOwnerships[index] = _packedOwnershipOf(index);
}
}
function _packedOwnershipOf(uint256 tokenId) private view returns (uint256 packed) {
if (_startTokenId() <= tokenId) {
packed = _packedOwnerships[tokenId];
if (packed & _BITMASK_BURNED == 0) {
if (packed == 0) {
if (tokenId >= _currentIndex) revert OwnerQueryForNonexistentToken();
for (;;) {
unchecked {
packed = _packedOwnerships[--tokenId];
}
if (packed == 0) continue;
return packed;
}
}
return packed;
}
}
revert OwnerQueryForNonexistentToken();
}
function _unpackedOwnership(uint256 packed) private pure returns (TokenOwnership memory ownership) {
ownership.addr = address(uint160(packed));
ownership.startTimestamp = uint64(packed >> _BITPOS_START_TIMESTAMP);
ownership.burned = packed & _BITMASK_BURNED != 0;
ownership.extraData = uint24(packed >> _BITPOS_EXTRA_DATA);
}
function _packOwnershipData(address owner, uint256 flags) private view returns (uint256 result) {
assembly {
owner := and(owner, _BITMASK_ADDRESS)
result := or(owner, or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags))
}
}
function _nextInitializedFlag(uint256 quantity) private pure returns (uint256 result) {
assembly {
result := shl(_BITPOS_NEXT_INITIALIZED, eq(quantity, 1))
}
}
function approve(address to, uint256 tokenId) public payable virtual override {
_approve(to, tokenId, true);
}
function getApproved(uint256 tokenId) public view virtual override returns (address) {
if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken();
return _tokenApprovals[tokenId].value;
}
function setApprovalForAll(address operator, bool approved) public virtual override {
_operatorApprovals[_msgSenderERC721A()][operator] = approved;
emit ApprovalForAll(_msgSenderERC721A(), operator, approved);
}
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return
_startTokenId() <= tokenId &&
tokenId < _currentIndex &&
_packedOwnerships[tokenId] & _BITMASK_BURNED == 0;
}
function _isSenderApprovedOrOwner(
address approvedAddress,
address owner,
address msgSender
) private pure returns (bool result) {
assembly {
owner := and(owner, _BITMASK_ADDRESS)
msgSender := and(msgSender, _BITMASK_ADDRESS)
result := or(eq(msgSender, owner), eq(msgSender, approvedAddress))
}
}
function _getApprovedSlotAndAddress(uint256 tokenId)
private
view
returns (uint256 approvedAddressSlot, address approvedAddress)
{
TokenApprovalRef storage tokenApproval = _tokenApprovals[tokenId];
assembly {
approvedAddressSlot := tokenApproval.slot
approvedAddress := sload(approvedAddressSlot)
}
}
function transferFrom(
address from,
address to,
uint256 tokenId
) public payable virtual override {
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);
if (address(uint160(prevOwnershipPacked)) != from) revert TransferFromIncorrectOwner();
(uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);
if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))
if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();
if (to == address(0)) revert TransferToZeroAddress();
_beforeTokenTransfers(from, to, tokenId, 1);
assembly {
if approvedAddress {
sstore(approvedAddressSlot, 0)
}
}
unchecked {
--_packedAddressData[from];
++_packedAddressData[to];
_packedOwnerships[tokenId] = _packOwnershipData(
to,
_BITMASK_NEXT_INITIALIZED | _nextExtraData(from, to, prevOwnershipPacked)
);
if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {
uint256 nextTokenId = tokenId + 1;
if (_packedOwnerships[nextTokenId] == 0) {
if (nextTokenId != _currentIndex) {
_packedOwnerships[nextTokenId] = prevOwnershipPacked;
}
}
}
}
emit Transfer(from, to, tokenId);
_afterTokenTransfers(from, to, tokenId, 1);
}
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public payable virtual override {
safeTransferFrom(from, to, tokenId, '');
}
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public payable virtual override {
transferFrom(from, to, tokenId);
if (to.code.length != 0)
if (!_checkContractOnERC721Received(from, to, tokenId, _data)) {
revert TransferToNonERC721ReceiverImplementer();
}
}
function _beforeTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual {}
function _afterTokenTransfers(
address from,
address to,
uint256 startTokenId,
uint256 quantity
) internal virtual {}
function _checkContractOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory _data
) private returns (bool) {
try ERC721A__IERC721Receiver(to).onERC721Received(_msgSenderERC721A(), from, tokenId, _data) returns (
bytes4 retval
) {
return retval == ERC721A__IERC721Receiver(to).onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert TransferToNonERC721ReceiverImplementer();
} else {
assembly {
revert(add(32, reason), mload(reason))
}
}
}
}
function _mint(address to, uint256 quantity) internal virtual {
uint256 startTokenId = _currentIndex;
if (quantity == 0) revert MintZeroQuantity();
_beforeTokenTransfers(address(0), to, startTokenId, quantity);
unchecked {
_packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);
_packedOwnerships[startTokenId] = _packOwnershipData(
to,
_nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)
);
uint256 toMasked;
uint256 end = startTokenId + quantity;
assembly {
toMasked := and(to, _BITMASK_ADDRESS)
log4(
0,
0,
_TRANSFER_EVENT_SIGNATURE,
0,
toMasked,
startTokenId
)
for {
let tokenId := add(startTokenId, 1)
} iszero(eq(tokenId, end)) {
tokenId := add(tokenId, 1)
} {
log4(0, 0, _TRANSFER_EVENT_SIGNATURE, 0, toMasked, tokenId)
}
}
if (toMasked == 0) revert MintToZeroAddress();
_currentIndex = end;
}
_afterTokenTransfers(address(0), to, startTokenId, quantity);
}
function _mintERC2309(address to, uint256 quantity) internal virtual {
uint256 startTokenId = _currentIndex;
if (to == address(0)) revert MintToZeroAddress();
if (quantity == 0) revert MintZeroQuantity();
if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT) revert MintERC2309QuantityExceedsLimit();
_beforeTokenTransfers(address(0), to, startTokenId, quantity);
unchecked {
_packedAddressData[to] += quantity * ((1 << _BITPOS_NUMBER_MINTED) | 1);
_packedOwnerships[startTokenId] = _packOwnershipData(
to,
_nextInitializedFlag(quantity) | _nextExtraData(address(0), to, 0)
);
emit ConsecutiveTransfer(startTokenId, startTokenId + quantity - 1, address(0), to);
_currentIndex = startTokenId + quantity;
}
_afterTokenTransfers(address(0), to, startTokenId, quantity);
}
function _safeMint(
address to,
uint256 quantity,
bytes memory _data
) internal virtual {
_mint(to, quantity);
unchecked {
if (to.code.length != 0) {
uint256 end = _currentIndex;
uint256 index = end - quantity;
do {
if (!_checkContractOnERC721Received(address(0), to, index++, _data)) {
revert TransferToNonERC721ReceiverImplementer();
}
} while (index < end);
if (_currentIndex != end) revert();
}
}
}
function _safeMint(address to, uint256 quantity) internal virtual {
_safeMint(to, quantity, '');
}
function _approve(address to, uint256 tokenId) internal virtual {
_approve(to, tokenId, false);
}
function _approve(
address to,
uint256 tokenId,
bool approvalCheck
) internal virtual {
address owner = ownerOf(tokenId);
if (approvalCheck)
if (_msgSenderERC721A() != owner)
if (!isApprovedForAll(owner, _msgSenderERC721A())) {
revert ApprovalCallerNotOwnerNorApproved();
}
_tokenApprovals[tokenId].value = to;
emit Approval(owner, to, tokenId);
}
function _burn(uint256 tokenId) internal virtual {
_burn(tokenId, false);
}
function _burn(uint256 tokenId, bool approvalCheck) internal virtual {
uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);
address from = address(uint160(prevOwnershipPacked));
(uint256 approvedAddressSlot, address approvedAddress) = _getApprovedSlotAndAddress(tokenId);
if (approvalCheck) {
if (!_isSenderApprovedOrOwner(approvedAddress, from, _msgSenderERC721A()))
if (!isApprovedForAll(from, _msgSenderERC721A())) revert TransferCallerNotOwnerNorApproved();
}
_beforeTokenTransfers(from, address(0), tokenId, 1);
assembly {
if approvedAddress {
sstore(approvedAddressSlot, 0)
}
}
unchecked {
_packedAddressData[from] += (1 << _BITPOS_NUMBER_BURNED) - 1;
_packedOwnerships[tokenId] = _packOwnershipData(
from,
(_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) | _nextExtraData(from, address(0), prevOwnershipPacked)
);
if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {
uint256 nextTokenId = tokenId + 1;
if (_packedOwnerships[nextTokenId] == 0) {
if (nextTokenId != _currentIndex) {
_packedOwnerships[nextTokenId] = prevOwnershipPacked;
}
}
}
}
emit Transfer(from, address(0), tokenId);
_afterTokenTransfers(from, address(0), tokenId, 1);
unchecked {
_burnCounter++;
}
}
function _setExtraDataAt(uint256 index, uint24 extraData) internal virtual {
uint256 packed = _packedOwnerships[index];
if (packed == 0) revert OwnershipNotInitializedForExtraData();
uint256 extraDataCasted;
assembly {
extraDataCasted := extraData
}
packed = (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << _BITPOS_EXTRA_DATA);
_packedOwnerships[index] = packed;
}
function _extraData(
address from,
address to,
uint24 previousExtraData
) internal view virtual returns (uint24) {}
function _nextExtraData(
address from,
address to,
uint256 prevOwnershipPacked
) private view returns (uint256) {
uint24 extraData = uint24(prevOwnershipPacked >> _BITPOS_EXTRA_DATA);
return uint256(_extraData(from, to, extraData)) << _BITPOS_EXTRA_DATA;
}
function _msgSenderERC721A() internal view virtual returns (address) {
return msg.sender;
}
function _toString(uint256 value) internal pure virtual returns (string memory str) {
assembly {
let m := add(mload(0x40), 0xa0)
mstore(0x40, m)
str := sub(m, 0x20)
mstore(str, 0)
let end := str
for { let temp := value } 1 {} {
str := sub(str, 1)
mstore8(str, add(48, mod(temp, 10)))
temp := div(temp, 10)
if iszero(temp) { break }
}
let length := sub(end, str)
str := sub(str, 0x20)
mstore(str, length)
}
}
}
文件 7 的 24:Environment.sol
pragma solidity 0.8.16;
import "./GridHelper.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
library Environment {
uint internal constant TOTAL_BASIC_COLOURS = 5;
uint internal constant TOTAL_EMBELLISHED_COLOURS = 6;
uint internal constant TOTAL_DEGRADED_COLOURS = 8;
string internal constant EXECUTIVE_COLOUR_PERCENTAGES = "040020025000070000";
string internal constant LAB_COLOUR_PERCENTAGES = "040020025000070000";
string internal constant FACTORY_COLOUR_PERCENTAGES = "040020025000070000";
string internal constant EXECUTIVE_DEGRADED_HSL = "120001015120001035120001061120002088019068078019032045019058048002047049";
string internal constant LAB_DEGRADED_HSL = "120001015120001035120001061120002088156015049050047054276021058155037049";
string internal constant FACTORY_DEGRADED_HSL = "120001015120001035120001061120002088021042074203032059319029046243031039";
string internal constant EXECUTIVE_COLOURS_BASIC = "000000069240003029000000069240003029000000069000000069240003013000000069354100060240003013000000069240003013240003029047100050240003013240003029240003013240003029121082050240003013240003029240003013240003029221082050240003013354100060000100004000100004022100050041100050047100050021081004021081004030100013022100045221081088194090077200075078195086089200084076";
string internal constant EXECUTIVE_COLOURS_EMBELLISHED = "121082050093090004099074009095085054099075072093090004221082050194089004199074009195085054199075080194089004339082050314089004317074009313085054318075084314089004357061040040091044040091062040091044040091062040091044137093049197100052287100053347100053047100052287100053259100052184100052083100052050100050000100050083100052093063053082084048066100048053100050036100050066100048060087053061100042070100040101055042165100025070100040";
string internal constant EXECUTIVE_COLOURS_BASIC_SHADE = "000000050240003029000000050240003029000000050000000050240003029000000050000086027240003029000000050240003029240003013047100032240003029240003013240003029240003013104079046240003029240003013240003029240003013204079046240003029000086027000061010000100007013091043041100045047100032022080008022081012030100015022100040204079087196071077180054080195093089195095092";
string internal constant EXECUTIVE_COLOURS_EMBELLISHED_SHADE = "104079046096071004080054015095093054095096068096071004204079046196071004180054015195093054195096068196071004322079046316071004299054015313093054313096068316071004357078056040091062040091044040091062040091044040091062168100054257100053317100053017100052047100056317100053284100052212092052155100052068100052032100050155100052093063057093068048075100048058100050047100050075100048060100062061100044065100041081077041137055037065100041";
string internal constant LAB_COLOURS_BASIC = "185053039180055056185053039180095040181066049231095074252070052231095074210049067030100050168056095228081062168056095051093072182081087240060097253081078240060097224062081245080083352033081165032066027028078027033080037031079143014078000000100143014078237045053183099034207099060207099060040090096239066051176077048221081088194090077200075078195086089200084076";
string internal constant LAB_COLOURS_EMBELLISHED = "158100077228081062168056095051093072182081087168056095238100086253081078240060097224062081245080083253081078190054036252070052231095074210049067030100050252070052144090033040091044040091062040091044040091062040091044287100053047100052137093049347100053197100052287100053000100050050100050083100052184100052259100052083100052036100050053100050066100048082084048093063053082084048165100025101055042070100040061100042060087053070100040";
string internal constant LAB_COLOURS_BASIC_SHADE = "181085042184045075181085042180059062181062052251085079251073027251085079211053076030100050182081087229047032182081087051090084180064063242083093252047060242083093224058089244079072004029080164031070021030079022034081023028075143014068183100080143014068237045048183099028239066051207099060041090092238072019176077048204079087196071077180054080195093089195095092";
string internal constant LAB_COLOURS_EMBELLISHED_SHADE = "169048056229047032182081087051090084180064063182081087241047074252047060242083093224058089244079072252047060184021040251073027251085079211053076030100050251073027147089054040091062040091044040091062040091044040091062317100053047100056168100054017100052257100053317100053032100050068100052155100052212092052284100052155100052047100050058100050075100048093068048093063057093068048137055037081077041065100041061100044060100062065100041";
string internal constant FACTORY_COLOURS_BASIC = "232053033232052058232054032232051037232058059196085079193083063193048054193064047193089055231032035196085079231032035300085082000000085249069060196085079231032035300085082000000085266083081162085079197031035266083081000000085033098060196085068231032035196085068000000085300085082196085079231032035033100052000000085221081088194090077200075078195086089200084076";
string internal constant FACTORY_COLOURS_EMBELLISHED = "160073059280078043280077074340097062160071039280078043280094041340086057280084075340084055340087027340086057162085079266083081266083081197031035000000085266083081220067026040091044040091072040091044040091072040091044197100052287100053137093049347100053047100052287100053083100052050100050000100050259100052184100052050100050082084048066100048036100050053100050093063053082084048101055042070100040165100025060087053061100042070100040";
string internal constant FACTORY_COLOURS_BASIC_SHADE = "232066056233054034232066067232071029232091066196084068193045040193073053193067051193070044229034024193083063229034024033098060000000052243039046193083063229034024033098060000000052359097059159084063195034025266086072000000052033098044193083052229034024193083052000000052321076067193083063229034024033098060000000052204079087196071077180054080195093089195095092";
string internal constant FACTORY_COLOURS_EMBELLISHED_SHADE = "243039046300085082193083063229034024000000052300085082249069060033098060196085079231032035000000085033098060159084063359097059266086072195034025000000052359097059220096052040091072040091044040091072040091044220087032257100053317100053168100054017100052047100056317100053155100052068100052032100050284100052212092052068100052093068048075100048047100050058100050093063057093068048081077041065100041137055037060100062061100044065100041";
string internal constant DEGRADED_COLOUR_PERCENTAGES = "064115153191217237251256";
string internal constant BASIC_COLOUR_PERCENTAGES = "064115153191217237251256";
string internal constant EMBELLISHED_COLOUR_PERCENTAGES = "064115153191217237251256";
function increaseValueByPercentage(uint baseLightness, uint percentage) internal pure returns(uint) {
uint value = baseLightness + (baseLightness * percentage / 100);
if (value > 100) {
value = 100;
}
return value;
}
function decreaseValueByPercentage(uint baseLightness, uint percentage) internal pure returns (uint) {
return baseLightness - (baseLightness * percentage / 100);
}
function getColours(string memory machine, uint baseValue) external pure returns (uint[] memory) {
uint[] memory colourArray = new uint[](36);
uint colourIndex = getColourIndex(baseValue);
if (colourIndex < 8) {
colourArray = getDegradedShell(colourArray, machine, baseValue);
} else {
colourArray = getBasicEmbelishedShell(colourArray, machine, baseValue);
}
return colourArray;
}
function getColourIndex(uint baseValue) internal pure returns(uint) {
uint[] memory colourProbabilitiesArray = GridHelper.createEqualProbabilityArray(24);
uint index = 100;
for (uint i = 0; i < colourProbabilitiesArray.length; ++i) {
if (baseValue < colourProbabilitiesArray[i]) {
index = i;
break;
}
}
if (index == 100) {
index = 23;
}
return index;
}
function selectBasicEmbellishedPalette(string memory machine, uint baseValue) internal pure returns (string[] memory) {
string[] memory basicPalette = new string[](2);
uint index = getColourIndex(baseValue);
uint state = 2;
if (index < 16) {
state = 1;
}
index = index % 8;
uint size;
if (state == 1) {
size = TOTAL_BASIC_COLOURS * 9;
} else {
size = TOTAL_EMBELLISHED_COLOURS * 9;
}
if (keccak256(bytes(machine)) == keccak256(bytes("Altar"))) {
if (state == 1) {
basicPalette[0] = string(GridHelper.slice(bytes(EXECUTIVE_COLOURS_BASIC), index * size, size));
basicPalette[1] = string(GridHelper.slice(bytes(EXECUTIVE_COLOURS_BASIC_SHADE), index * size, size));
} else {
basicPalette[0] = string(GridHelper.slice(bytes(EXECUTIVE_COLOURS_EMBELLISHED), index * size, size));
basicPalette[1] = string(GridHelper.slice(bytes(EXECUTIVE_COLOURS_EMBELLISHED_SHADE), index * size, size));
}
} else if (keccak256(bytes(machine)) == keccak256(bytes("Apparatus")) || keccak256(bytes(machine)) == keccak256(bytes("Cells"))) {
if (state == 1) {
basicPalette[0] = string(GridHelper.slice(bytes(LAB_COLOURS_BASIC), index * size, size));
basicPalette[1] = string(GridHelper.slice(bytes(LAB_COLOURS_BASIC_SHADE), index * size, size));
} else {
basicPalette[0] = string(GridHelper.slice(bytes(LAB_COLOURS_EMBELLISHED), index * size, size));
basicPalette[1] = string(GridHelper.slice(bytes(LAB_COLOURS_EMBELLISHED_SHADE), index * size, size));
}
} else {
if (state == 1) {
basicPalette[0] = string(GridHelper.slice(bytes(FACTORY_COLOURS_BASIC), index * size, size));
basicPalette[1] = string(GridHelper.slice(bytes(FACTORY_COLOURS_BASIC_SHADE), index * size, size));
} else {
basicPalette[0] = string(GridHelper.slice(bytes(FACTORY_COLOURS_EMBELLISHED), index * size, size));
basicPalette[1] = string(GridHelper.slice(bytes(FACTORY_COLOURS_EMBELLISHED_SHADE), index * size, size));
}
}
return basicPalette;
}
function getDegradedShell(uint[] memory colourArray, string memory machine, uint baseValue) internal pure returns (uint[] memory) {
string memory degradedHsl;
string memory degradedPercentages;
if (keccak256(bytes(machine)) == keccak256(bytes("Altar"))) {
degradedHsl = EXECUTIVE_DEGRADED_HSL;
degradedPercentages = EXECUTIVE_COLOUR_PERCENTAGES;
} else if (keccak256(bytes(machine)) == keccak256(bytes("Apparatus")) || keccak256(bytes(machine)) == keccak256(bytes("Cells"))) {
degradedHsl = LAB_DEGRADED_HSL;
degradedPercentages = LAB_COLOUR_PERCENTAGES;
} else {
degradedHsl = FACTORY_DEGRADED_HSL;
degradedPercentages = FACTORY_COLOUR_PERCENTAGES;
}
uint index = getColourIndex(baseValue);
uint[] memory singleColour = new uint[](3);
for (uint i = 0; i < 3; ++i) {
singleColour[i] = GridHelper.stringToUint(string(GridHelper.slice(bytes(degradedHsl), (index)*9 + 3*i, 3)));
}
uint[] memory colourPercentages = GridHelper.setUintArrayFromString(degradedPercentages, 6, 3);
for (uint i = 0; i < 12; ++i) {
colourArray[i*3] = singleColour[0];
colourArray[i*3+1] = singleColour[1];
colourArray[i*3+2] = increaseValueByPercentage(singleColour[2], colourPercentages[i%6]);
}
return colourArray;
}
function getBasicEmbelishedShell(uint[] memory colourArray, string memory machine, uint baseValue) internal pure returns (uint[] memory) {
uint index = getColourIndex(baseValue);
uint state = 2;
if (index < 16) {
state = 1;
}
uint numColours;
if (state == 1) {
numColours = TOTAL_BASIC_COLOURS;
} else {
numColours = TOTAL_EMBELLISHED_COLOURS;
}
string[] memory colourAvailableStrings = selectBasicEmbellishedPalette(machine, baseValue);
uint[] memory coloursAvailable = GridHelper.setUintArrayFromString(colourAvailableStrings[0], numColours*3, 3);
uint[] memory coloursAvailableShade = GridHelper.setUintArrayFromString(colourAvailableStrings[1], numColours*3, 3);
for (uint i = 0; i < 6; ++i) {
for (uint j = 0; j < 3; ++j) {
colourArray[2*i*3+j] = coloursAvailable[3*(i % numColours) + j];
colourArray[(2*i+1)*3+j] = coloursAvailableShade[3*(i % numColours) + j];
}
}
return colourArray;
}
}
文件 8 的 24:GlobalNumbers.sol
pragma solidity 0.8.16;
import "./GridHelper.sol";
import "./Noise.sol";
library GlobalNumbers {
uint internal constant FLIPPER_WRAPPER_NUMBER = 13010;
uint internal constant CHAR_MASK_GROUP_NUMBER = 14006;
uint internal constant GROUP_CLOSE_NUMBER = 13000;
string internal constant SMALL_ASSET_NUMBERS = "0000006022060210602806014060270602606006060040601106000060250602906020";
string internal constant LARGE_ASSET_NUMBERS = "00000020020601302001020090200802004020030600806019060090602306024060300601806017";
string internal constant OUT_WALL_NUMBERS = "0000006005060070601606010";
string internal constant FLAT_WALL_NUMBERS = "00000020000201102007020060200502010";
string internal constant EXPANSION_PROPS_NUMBERS = "000000200002005020060200702002020010200302004";
string internal constant CHARACTER_LEVER_NUMBERS = "0300003001030020300303016030170301803019";
string internal constant CHARACTER_NUMBERS = "00000140021400514003140011400014004";
function getSmallAssetNumber(uint rand, int baseline) external pure returns (uint) {
uint smallAssetDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 20)] + baseline);
return GridHelper.getSingleObject(SMALL_ASSET_NUMBERS, smallAssetDigits, 14, 5);
}
function getLargeAssetNumber(uint rand, int baseline) external pure returns (uint) {
uint largeAssetDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 21)] + baseline);
return GridHelper.getSingleObject(LARGE_ASSET_NUMBERS, largeAssetDigits, 16, 5);
}
function getOutWallNumber(uint rand, int baseline) external pure returns (uint) {
uint outWallDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 22)] + baseline);
return GridHelper.getSingleObject(OUT_WALL_NUMBERS, outWallDigits, 5, 5);
}
function getFlatWallNumber(uint rand, int baseline) external pure returns (uint) {
uint flatWallDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 23)] + baseline);
return GridHelper.getSingleObject(FLAT_WALL_NUMBERS, flatWallDigits, 7, 5);
}
function getCharacterLeverNumber(uint rand, int baseline) internal pure returns (uint) {
uint characterLeverDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 30)] + baseline);
return GridHelper.getSingleObject(CHARACTER_LEVER_NUMBERS, characterLeverDigits, 8, 5);
}
function getCharacterNumber(uint rand, int baseline) internal pure returns (uint) {
uint characterDigits = GridHelper.constrainToHex(Noise.getNoiseArrayTwo()[GridHelper.getRandByte(rand, 31)] + baseline);
return GridHelper.getSingleObject(CHARACTER_NUMBERS, characterDigits, 7, 5);
}
function getCharacterNumberAndLeverNumber(uint rand, bool flip, int baseline) external pure returns (uint[5] memory) {
uint characterNumber = getCharacterNumber(rand, baseline);
uint characterLeverNumber = getCharacterLeverNumber(rand, baseline);
uint armMask = 0;
if (characterNumber == 14001 || characterNumber == 14003 || characterNumber == 14005) {
armMask = CHAR_MASK_GROUP_NUMBER;
}
uint flipOpen = 0;
uint flipClose = 0;
if (flip) {
flipOpen = FLIPPER_WRAPPER_NUMBER;
flipClose = GROUP_CLOSE_NUMBER;
}
return [flipOpen, characterLeverNumber, armMask, characterNumber, flipClose];
}
function getSingleOffset(uint rand, int baseline, string memory offsetNumbers, uint numOptions) external pure returns (string memory) {
uint offsetDigits1 = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 20)] + baseline);
uint offsetDigits2 = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 21)] + baseline);
uint offsetDigits3 = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 22)] + baseline);
uint finalOffsetDigits = (offsetDigits1 + offsetDigits2 + offsetDigits3) / 3;
return string(GridHelper.slice(bytes(offsetNumbers), (finalOffsetDigits % numOptions)*8, 8));
}
}
文件 9 的 24:GlobalSVG.sol
pragma solidity 0.8.16;
import "./CommonSVG.sol";
interface ILibrary {
function getPart() external view returns (string memory);
}
contract GlobalSVG {
constructor(address[13] memory allLibraries) {
libraryDeployments = allLibraries;
}
address[13] public libraryDeployments;
string internal constant TEXTURE_CSS_OPEN = ":root { --grey: hsl(0, 0%, 10%); --anim-speed: ";
string internal constant TEXTURE_CSS_MID = "s; --rdm-seed: 0.";
string internal constant TEXTURE_CSS_CLOSE = "; --anim-scale-0: 1; --anim-scale-50: 5; --anim-scale-100: 1; --end-rotation: calc(var(--rdm-seed) * 360); --num-rectangles: 7; } .pulsateInOutOld { animation: pulsateInOutOld var(--anim-speed) infinite linear; } @keyframes infinityWellRect { 0% { opacity: 0; transform: scale(1.1) rotate(0deg); transform-origin: 78px 90px; } 10% { opacity: 1; } 100% { opacity: 1; transform: scale(0) rotate(calc(var(--end-rotation) * 1deg)); transform-origin: 78px 90px; } } .infinityWell { animation: infinityWell var(--anim-speed) infinite linear forwards; } .infinityWellRect { animation: infinityWell var(--anim-speed) infinite linear forwards; } .rt-0 { animation: infinityWellRect var(--anim-speed) infinite linear; } .rt-1 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 1); } .rt-2 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 2); } .rt-3 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 3); } .rt-4 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 4); } .rt-5 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 5); } .rt-6 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 6); } .rt-7 { animation: infinityWellRect var(--anim-speed) infinite linear; animation-delay: calc(var(--anim-speed) / 8 * 7); } }";
string internal constant PATTERN_CSS_OPEN = ":root { --anim-speed: ";
string internal constant PATTERN_CSS_CLOSE = "s; --anim-scale-0: 1; --anim-scale-50: 2; --anim-scale-100: 1; } @keyframes pulsateInOutOld { 0% { transform: scale(var(--anim-scale-0)); transform-origin: 78px 90px; } 50% { transform: scale(var(--anim-scale-50)); transform-origin: 78px 90px; } 100% { transform: scale(var(--anim-scale-100)); transform-origin: 78px 90px; } } .pulsateInOutOld { animation: pulsateInOutOld var(--anim-speed) infinite linear; }";
function getAnimationSpeed(int baseline) internal pure returns (string memory) {
uint patternSpeed = 0;
uint textureSpeed = uint(baseline) % 30;
if (baseline > 185 || baseline < 70) {
patternSpeed = 10 + uint(baseline) % 11;
}
if (baseline < 70) {
return string.concat(
TEXTURE_CSS_OPEN,
Strings.toString(patternSpeed),
TEXTURE_CSS_MID,
Strings.toString(textureSpeed),
TEXTURE_CSS_CLOSE
);
} else {
return string.concat(
PATTERN_CSS_OPEN,
Strings.toString(patternSpeed),
PATTERN_CSS_CLOSE
);
}
}
function getClosingSVG() external pure returns (string memory) {
return string.concat(
"<g id='shell-vignette' style='mix-blend-mode:normal'><rect fill='url(#vig1-u-vig1-fill)' width='1080' height='1080'/></g>",
"</g>",
"</svg>"
);
}
function getShell(string memory flip, uint rand, int baseline, string memory dataInfo) external pure returns (string memory) {
return string.concat(
CommonSVG.SHELL_OPEN,
flip,
CommonSVG.SHELL_CLOSE,
dataInfo,
CommonSVG.createShellOpacity(rand, baseline)
);
}
function getOpeningSVG(string memory machine, uint colourValue, uint rand, int baseline) external view returns (string memory) {
string memory output = string.concat(
CommonSVG.SVG_START,
CommonSVG.getshellColours(machine, colourValue),
CommonSVG.createShellPattern(rand, baseline),
ILibrary(libraryDeployments[0]).getPart(),
ILibrary(libraryDeployments[1]).getPart()
);
output = string.concat(
output,
ILibrary(libraryDeployments[2]).getPart(),
ILibrary(libraryDeployments[3]).getPart(),
ILibrary(libraryDeployments[4]).getPart(),
ILibrary(libraryDeployments[5]).getPart(),
ILibrary(libraryDeployments[6]).getPart()
);
output = string.concat(
output,
ILibrary(libraryDeployments[7]).getPart(),
ILibrary(libraryDeployments[8]).getPart(),
CommonSVG.TEMP_STYLE,
CommonSVG.STYLE,
getAnimationSpeed(baseline)
);
return string.concat(
output,
ILibrary(libraryDeployments[9]).getPart(),
ILibrary(libraryDeployments[10]).getPart(),
ILibrary(libraryDeployments[11]).getPart(),
ILibrary(libraryDeployments[12]).getPart(),
CommonSVG.STYLE_CLOSE
);
}
}
文件 10 的 24:GridHelper.sol
pragma solidity 0.8.16;
import "@openzeppelin/contracts/utils/Strings.sol";
library GridHelper {
uint256 public constant MAX_GRID_INDEX = 8;
function slice(bytes memory data, uint256 start, uint256 len) internal pure returns (bytes memory) {
bytes memory b = new bytes(len);
for (uint256 i = 0; i < len; i++) {
b[i] = data[i + start];
}
return b;
}
function combineStringArrays(string[] memory a, string[] memory b) public pure returns (string[] memory) {
string[] memory c = new string[](a.length + b.length);
for (uint256 i = 0; i < a.length; i++) {
c[i] = a[i];
}
for (uint256 i = 0; i < b.length; i++) {
c[i + a.length] = b[i];
}
return c;
}
function combineUintArrays(uint256[] memory a, uint256[] memory b) public pure returns (uint256[] memory) {
uint256[] memory c = new uint256[](a.length + b.length);
for (uint256 i = 0; i < a.length; i++) {
c[i] = a[i];
}
for (uint256 i = 0; i < b.length; i++) {
c[i + a.length] = b[i];
}
return c;
}
function groupTransform(string memory x, string memory y, string memory data) internal pure returns (string memory) {
return string.concat("<g transform='translate(", x, ",", y, ")'>", data, "</g>");
}
function uintToBytes(uint256 x) internal pure returns (bytes memory b) {
b = new bytes(32);
assembly {
mstore(add(b, 32), x)
}
}
function bytesToUint(bytes memory value) internal pure returns(uint) {
uint256 num = uint256(bytes32(value));
return num;
}
function byteSliceToUint (bytes memory a) internal pure returns(uint) {
bytes32 padding = bytes32(0);
bytes memory formattedSlice = slice(bytes.concat(padding, a), 1, 32);
return bytesToUint(formattedSlice);
}
function getRandByte(uint rand, uint slicePosition) internal pure returns(uint) {
bytes memory bytesRand = uintToBytes(rand);
bytes memory part = slice(bytesRand, slicePosition, 1);
return byteSliceToUint(part);
}
function stringToUint(string memory s) internal pure returns (uint) {
bytes memory b = bytes(s);
uint result = 0;
for (uint256 i = 0; i < b.length; i++) {
uint256 c = uint256(uint8(b[i]));
if (c >= 48 && c <= 57) {
result = result * 10 + (c - 48);
}
}
return result;
}
function repeatGivenObject(string memory object, uint times, bytes memory offsetBytes) internal pure returns (string memory) {
require(offsetBytes.length % (times * 2) == 0, "offsetBytes length must be divisible by times * 2");
string memory output = "";
for (uint256 i = 0; i < times; i++) {
string memory xOffset = string(slice(offsetBytes, 2*i * offsetBytes.length / (times * 2), offsetBytes.length / (times * 2)));
string memory yOffset = string(slice(offsetBytes, (2*i + 1) * offsetBytes.length / (times * 2), offsetBytes.length / (times * 2)));
output = string.concat(
output,
groupTransform(xOffset, yOffset, object)
);
}
return output;
}
function setUintArrayFromString(string memory values, uint numOfValues, uint lengthOfValue) internal pure returns (uint[] memory) {
uint[] memory output = new uint[](numOfValues);
for (uint256 i = 0; i < numOfValues; i++) {
output[i] = stringToUint(string(slice(bytes(values), i*lengthOfValue, lengthOfValue)));
}
return output;
}
function getSumOfUintArray(uint[] memory arr) internal pure returns (uint) {
uint sum = 0;
for (uint i = 0; i < arr.length; i++) {
sum += arr[i];
}
return sum;
}
function constrainToHex(int value) internal pure returns (uint) {
require(value >= -255 && value <= 510, "Value out of bounds.");
if (value < 0) {
return uint(0 - value);
}
else if (value > 255) {
return uint(255 - (value - 255));
} else {
return uint(value);
}
}
function createEqualProbabilityArray(uint numOfValues) internal pure returns (uint[] memory) {
uint oneLess = numOfValues - 1;
uint[] memory probabilities = new uint[](oneLess);
for (uint256 i = 0; i < oneLess; ++i) {
probabilities[i] = 256 * (i + 1) / numOfValues;
}
return probabilities;
}
function getSingleObject(string memory objectNumbers, uint channelValue, uint numOfValues, uint valueLength) internal pure returns (uint) {
uint[] memory probabilities = createEqualProbabilityArray(numOfValues);
uint[] memory objectNumbersArray = setUintArrayFromString(objectNumbers, numOfValues, valueLength);
uint oneLess = numOfValues - 1;
for (uint256 i = 0; i < oneLess; ++i) {
if (channelValue < probabilities[i]) {
return objectNumbersArray[i];
}
}
return objectNumbersArray[oneLess];
}
}
文件 11 的 24:IERC721A.sol
pragma solidity ^0.8.4;
interface IERC721A {
error ApprovalCallerNotOwnerNorApproved();
error ApprovalQueryForNonexistentToken();
error BalanceQueryForZeroAddress();
error MintToZeroAddress();
error MintZeroQuantity();
error OwnerQueryForNonexistentToken();
error TransferCallerNotOwnerNorApproved();
error TransferFromIncorrectOwner();
error TransferToNonERC721ReceiverImplementer();
error TransferToZeroAddress();
error URIQueryForNonexistentToken();
error MintERC2309QuantityExceedsLimit();
error OwnershipNotInitializedForExtraData();
struct TokenOwnership {
address addr;
uint64 startTimestamp;
bool burned;
uint24 extraData;
}
function totalSupply() external view returns (uint256);
function supportsInterface(bytes4 interfaceId) external view returns (bool);
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external payable;
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external payable;
function transferFrom(
address from,
address to,
uint256 tokenId
) external payable;
function approve(address to, uint256 tokenId) external payable;
function setApprovalForAll(address operator, bool _approved) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function isApprovedForAll(address owner, address operator) external view returns (bool);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function tokenURI(uint256 tokenId) external view returns (string memory);
event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);
}
文件 12 的 24:LibBit.sol
pragma solidity ^0.8.4;
library LibBit {
function fls(uint256 x) internal pure returns (uint256 r) {
assembly {
r := shl(8, iszero(x))
r := or(r, shl(7, lt(0xffffffffffffffffffffffffffffffff, x)))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
x := shr(r, x)
x := or(x, shr(1, x))
x := or(x, shr(2, x))
x := or(x, shr(4, x))
x := or(x, shr(8, x))
x := or(x, shr(16, x))
r := or(r, byte(shr(251, mul(x, shl(224, 0x07c4acdd))),
0x0009010a0d15021d0b0e10121619031e080c141c0f111807131b17061a05041f))
}
}
function clz(uint256 x) internal pure returns (uint256 r) {
assembly {
let t := add(iszero(x), 255)
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
x := shr(r, x)
x := or(x, shr(1, x))
x := or(x, shr(2, x))
x := or(x, shr(4, x))
x := or(x, shr(8, x))
x := or(x, shr(16, x))
r := sub(t, or(r, byte(shr(251, mul(x, shl(224, 0x07c4acdd))),
0x0009010a0d15021d0b0e10121619031e080c141c0f111807131b17061a05041f)))
}
}
function ffs(uint256 x) internal pure returns (uint256 r) {
assembly {
r := shl(8, iszero(x))
x := and(x, add(not(x), 1))
r := or(r, shl(7, lt(0xffffffffffffffffffffffffffffffff, x)))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, byte(shr(251, mul(shr(r, x), shl(224, 0x077cb531))),
0x00011c021d0e18031e16140f191104081f1b0d17151310071a0c12060b050a09))
}
}
function popCount(uint256 x) internal pure returns (uint256 c) {
assembly {
let max := not(0)
let isMax := eq(x, max)
x := sub(x, and(shr(1, x), div(max, 3)))
x := add(and(x, div(max, 5)), and(shr(2, x), div(max, 5)))
x := and(add(x, shr(4, x)), div(max, 17))
c := or(shl(8, isMax), shr(248, mul(x, div(max, 255))))
}
}
function isPo2(uint256 x) internal pure returns (bool result) {
assembly {
result := iszero(add(and(x, sub(x, 1)), iszero(x)))
}
}
function and(bool x, bool y) internal pure returns (bool z) {
assembly {
z := and(x, y)
}
}
function or(bool x, bool y) internal pure returns (bool z) {
assembly {
z := or(x, y)
}
}
function toUint(bool b) internal pure returns (uint256 z) {
assembly {
z := b
}
}
}
文件 13 的 24:LibBitmap.sol
pragma solidity ^0.8.4;
import "./LibBit.sol";
library LibBitmap {
uint256 internal constant NOT_FOUND = type(uint256).max;
struct Bitmap {
mapping(uint256 => uint256) map;
}
function get(Bitmap storage bitmap, uint256 index) internal view returns (bool isSet) {
uint256 b = (bitmap.map[index >> 8] >> (index & 0xff)) & 1;
assembly {
isSet := b
}
}
function set(Bitmap storage bitmap, uint256 index) internal {
bitmap.map[index >> 8] |= (1 << (index & 0xff));
}
function unset(Bitmap storage bitmap, uint256 index) internal {
bitmap.map[index >> 8] &= ~(1 << (index & 0xff));
}
function toggle(Bitmap storage bitmap, uint256 index) internal returns (bool newIsSet) {
assembly {
mstore(0x00, shr(8, index))
mstore(0x20, bitmap.slot)
let storageSlot := keccak256(0x00, 0x40)
let shift := and(index, 0xff)
let storageValue := sload(storageSlot)
let mask := shl(shift, 1)
storageValue := xor(storageValue, mask)
newIsSet := iszero(iszero(and(storageValue, mask)))
sstore(storageSlot, storageValue)
}
}
function setTo(Bitmap storage bitmap, uint256 index, bool shouldSet) internal {
assembly {
mstore(0x20, bitmap.slot)
mstore(0x00, shr(8, index))
let storageSlot := keccak256(0x00, 0x40)
let storageValue := sload(storageSlot)
let shift := and(index, 0xff)
sstore(
storageSlot,
or(and(storageValue, not(shl(shift, 1))), shl(shift, iszero(iszero(shouldSet))))
)
}
}
function setBatch(Bitmap storage bitmap, uint256 start, uint256 amount) internal {
assembly {
let max := not(0)
let shift := and(start, 0xff)
mstore(0x20, bitmap.slot)
mstore(0x00, shr(8, start))
if iszero(lt(add(shift, amount), 257)) {
let storageSlot := keccak256(0x00, 0x40)
sstore(storageSlot, or(sload(storageSlot), shl(shift, max)))
let bucket := add(mload(0x00), 1)
let bucketEnd := add(mload(0x00), shr(8, add(amount, shift)))
amount := and(add(amount, shift), 0xff)
shift := 0
for {} iszero(eq(bucket, bucketEnd)) { bucket := add(bucket, 1) } {
mstore(0x00, bucket)
sstore(keccak256(0x00, 0x40), max)
}
mstore(0x00, bucket)
}
let storageSlot := keccak256(0x00, 0x40)
sstore(storageSlot, or(sload(storageSlot), shl(shift, shr(sub(256, amount), max))))
}
}
function unsetBatch(Bitmap storage bitmap, uint256 start, uint256 amount) internal {
assembly {
let shift := and(start, 0xff)
mstore(0x20, bitmap.slot)
mstore(0x00, shr(8, start))
if iszero(lt(add(shift, amount), 257)) {
let storageSlot := keccak256(0x00, 0x40)
sstore(storageSlot, and(sload(storageSlot), not(shl(shift, not(0)))))
let bucket := add(mload(0x00), 1)
let bucketEnd := add(mload(0x00), shr(8, add(amount, shift)))
amount := and(add(amount, shift), 0xff)
shift := 0
for {} iszero(eq(bucket, bucketEnd)) { bucket := add(bucket, 1) } {
mstore(0x00, bucket)
sstore(keccak256(0x00, 0x40), 0)
}
mstore(0x00, bucket)
}
let storageSlot := keccak256(0x00, 0x40)
sstore(
storageSlot, and(sload(storageSlot), not(shl(shift, shr(sub(256, amount), not(0)))))
)
}
}
function popCount(Bitmap storage bitmap, uint256 start, uint256 amount)
internal
view
returns (uint256 count)
{
unchecked {
uint256 bucket = start >> 8;
uint256 shift = start & 0xff;
if (!(amount + shift < 257)) {
count = LibBit.popCount(bitmap.map[bucket] >> shift);
uint256 bucketEnd = bucket + ((amount + shift) >> 8);
amount = (amount + shift) & 0xff;
shift = 0;
for (++bucket; bucket != bucketEnd; ++bucket) {
count += LibBit.popCount(bitmap.map[bucket]);
}
}
count += LibBit.popCount((bitmap.map[bucket] >> shift) << (256 - amount));
}
}
function findLastSet(Bitmap storage bitmap, uint256 before)
internal
view
returns (uint256 setBitIndex)
{
uint256 bucket;
uint256 bucketBits;
assembly {
setBitIndex := not(0)
bucket := shr(8, before)
mstore(0x00, bucket)
mstore(0x20, bitmap.slot)
let offset := and(0xff, not(before))
bucketBits := shr(offset, shl(offset, sload(keccak256(0x00, 0x40))))
if iszero(bucketBits) {
for {} bucket {} {
bucket := add(bucket, setBitIndex)
mstore(0x00, bucket)
bucketBits := sload(keccak256(0x00, 0x40))
if bucketBits { break }
}
}
}
if (bucketBits != 0) {
setBitIndex = (bucket << 8) | LibBit.fls(bucketBits);
assembly {
setBitIndex := or(setBitIndex, sub(0, gt(setBitIndex, before)))
}
}
}
}
文件 14 的 24:LinkTokenInterface.sol
pragma solidity ^0.8.0;
interface LinkTokenInterface {
function allowance(address owner, address spender) external view returns (uint256 remaining);
function approve(address spender, uint256 value) external returns (bool success);
function balanceOf(address owner) external view returns (uint256 balance);
function decimals() external view returns (uint8 decimalPlaces);
function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);
function increaseApproval(address spender, uint256 subtractedValue) external;
function name() external view returns (string memory tokenName);
function symbol() external view returns (string memory tokenSymbol);
function totalSupply() external view returns (uint256 totalTokensIssued);
function transfer(address to, uint256 value) external returns (bool success);
function transferAndCall(
address to,
uint256 value,
bytes calldata data
) external returns (bool success);
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool success);
}
文件 15 的 24:Machine.sol
pragma solidity 0.8.16;
import "@openzeppelin/contracts/utils/Strings.sol";
import "./GridHelper.sol";
import "./GlobalNumbers.sol";
import "./AssetRetriever.sol";
interface IMachine {
function getMachine(uint rand, int baseline) external view returns (string memory);
function getAllNumbersUsed(uint rand, int baseline) external pure returns (uint[] memory, string[] memory);
function getGlobalAssetNumber(uint rand, uint version, int baseline) external pure returns (uint);
}
contract Machine {
AssetRetriever internal immutable _assetRetriever;
string[] public allMachines = ["Altar", "Apparatus", "Cells", "Tubes", "Beast", "Conveyor"];
mapping(string => address) public machineToWorkstation;
constructor(address[6] memory workstations, AssetRetriever assetRetriever) {
_assetRetriever = assetRetriever;
for (uint i = 0; i < allMachines.length; ++i) {
machineToWorkstation[allMachines[i]] = workstations[i];
}
}
function selectMachine(uint rand) external view returns (string memory) {
return allMachines[rand % allMachines.length];
}
function machineToGetter(string memory machine, uint rand, int baseline) external view returns (string memory) {
return IMachine(machineToWorkstation[machine]).getMachine(rand, baseline);
}
function getSmallAssetName(uint rand, int baseline) external pure returns (string memory) {
uint assetNumber = GlobalNumbers.getSmallAssetNumber(rand, baseline);
if (assetNumber == 6000) {
return "Lava Lamp";
} else if (assetNumber == 6004) {
return "Martini";
} else if (assetNumber == 6006) {
return "Bong";
} else if (assetNumber == 6011) {
return "Books";
} else if (assetNumber == 6014) {
return "Dog Bowl";
} else if (assetNumber == 6020) {
return "Lizard";
} else if (assetNumber == 6021) {
return "Skull";
} else if (assetNumber == 6022) {
return "Dead Rat";
} else if (assetNumber == 6025) {
return "Pineapple";
} else if (assetNumber == 6026) {
return "Can";
} else if (assetNumber == 6027) {
return "Cracked Bottle";
} else if (assetNumber == 6028) {
return "Dead Plant";
} else if (assetNumber == 6029) {
return "Watermelon";
} else {
return "None";
}
}
function getLargeAssetName(uint rand, int baseline) external pure returns (string memory) {
uint propNumber = GlobalNumbers.getLargeAssetNumber(rand, baseline);
if (propNumber == 2001) {
return "Grate";
} else if (propNumber == 2002) {
return "Pit";
} else if (propNumber == 2003) {
return "Stairs";
} else if (propNumber == 2004) {
return "Ladder";
} else if (propNumber == 2008) {
return "Spikes A";
} else if (propNumber == 2009) {
return "Spikes B";
} else if (propNumber == 6008) {
return "Fridge";
} else if (propNumber == 6009) {
return "Rug Circle";
} else if (propNumber == 6013) {
return "Toilet";
} else if (propNumber == 6017) {
return "Harp";
} else if (propNumber == 6018) {
return "Cello";
} else if (propNumber == 6019) {
return "Stool";
} else if (propNumber == 6023) {
return "Deck Chair";
} else if (propNumber == 6024) {
return "Cactus Chunk";
} else if (propNumber == 6030) {
return "Gramophone";
} else {
return "None";
}
}
function getWallOutName(uint rand, int baseline) external pure returns (string memory) {
uint wallOutNumber = GlobalNumbers.getOutWallNumber(rand, baseline);
if (wallOutNumber == 6005) {
return "Peephole A";
} else if (wallOutNumber == 6007) {
return "Peephole B";
} else if (wallOutNumber == 6010) {
return "CCTV";
} else if (wallOutNumber == 6016) {
return "Megaphone";
} else {
return "None";
}
}
function getWallFlatName(uint rand, int baseline) external pure returns (string memory) {
uint wallFlatNumber = GlobalNumbers.getFlatWallNumber(rand, baseline);
if (wallFlatNumber == 2000) {
return "Crack";
} else if (wallFlatNumber == 2005) {
return "Recess A";
} else if (wallFlatNumber == 2006) {
return "Recess B";
} else if (wallFlatNumber == 2007) {
return "Recess C";
} else if (wallFlatNumber == 2010) {
return "Wall Rug";
} else if (wallFlatNumber == 2011) {
return "Numbers";
} else {
return "None";
}
}
function getCharacterName(uint rand, int baseline) external pure returns (string memory) {
uint characterNumber = GlobalNumbers.getCharacterNumber(rand, baseline);
if (characterNumber == 14000) {
return "Sitting";
} else if (characterNumber == 14001) {
return "Standing";
} else if (characterNumber == 14002) {
return "Collapsed";
} else if (characterNumber == 14003) {
return "Slouched";
} else if (characterNumber == 14004) {
return "Meditating";
} else if (characterNumber == 14005) {
return "Hunched";
} else {
return "None";
}
}
}
文件 16 的 24:Math.sol
pragma solidity ^0.8.0;
library Math {
enum Rounding {
Down,
Up,
Zero
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
uint256 prod0;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
require(denominator > prod1);
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (~denominator + 1);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}
文件 17 的 24:Metadata.sol
pragma solidity 0.8.16;
import "solady/utils/Base64.sol";
import "./Machine.sol";
import "./GridHelper.sol";
import "./GlobalSVG.sol";
import "./Noise.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
contract Metadata {
Machine private immutable _machine;
GlobalSVG private immutable _globalSVG;
string[3] allStates = ["Degraded", "Basic", "Embellished"];
constructor(Machine machine, GlobalSVG globalSVG) {
_machine = machine;
_globalSVG = globalSVG;
}
function getMachine(uint rand) public view returns (string memory) {
return _machine.selectMachine(rand);
}
function buildMetadata(uint256 tokenId, uint rand) public view returns (string memory) {
int baseline = getBaselineRarity(rand);
uint state = getState(baseline);
string memory jsonInitial = string.concat(
'{"name": "A Machine For Dying # ',
Strings.toString(tokenId),
'", "description": "A Machine For Dying is centred around the concept of the Worker in a Box, a trapped individual, doomed to toil forever. The collection presents the stark contrast between autonomy and individuality versus the destruction and apathy that can come from being trapped and exploited by the corporate machine.", "attributes": [{"trait_type": "Machine", "value":"',
getMachine(rand),
'"}, {"trait_type": "State", "value":"',
allStates[state],
'"}, {"trait_type": "Small Asset:", "value":"',
_machine.getSmallAssetName(rand, baseline)
);
jsonInitial = string.concat(
jsonInitial,
'"}, {"trait_type": "Large Asset:", "value":"',
_machine.getLargeAssetName(rand, baseline),
'"}, {"trait_type": "Wall Out:", "value":"',
_machine.getWallOutName(rand, baseline),
'"}, {"trait_type": "Wall Flat:", "value":"',
_machine.getWallFlatName(rand, baseline)
);
jsonInitial = string.concat(
jsonInitial,
'"}, {"trait_type": "Colour:", "value":"',
getColourIndexTier(rand, baseline),
'"}, {"trait_type": "Pattern:", "value":"',
Patterns.getPatternName(rand, baseline),
'"}, {"trait_type": "Character:", "value":"',
_machine.getCharacterName(rand, baseline),
'"}],',
'"image": "data:image/svg+xml;base64,'
);
string memory jsonFinal = Base64.encode(
bytes(string.concat(
jsonInitial,
composeSVG(rand, baseline),
'", ',
'"animation_url": "data:image/svg+xml;base64,',
composeSVG(rand, baseline),
'"}'
))
);
string memory output = string.concat("data:application/json;base64,", jsonFinal);
return output;
}
function createDataInfo(uint rand) internal view returns (string memory) {
int baseline = getBaselineRarity(rand);
uint state = getState(baseline);
string memory json = string.concat(
'data-info=\'{"RandomNumber":"',
Strings.toString(rand),
'","State":"',
allStates[state],
'","Machine":"',
getMachine(rand),
'","SmallAsset":"',
_machine.getSmallAssetName(rand, baseline)
);
json = string.concat(
json,
'","LargeAsset":"',
_machine.getLargeAssetName(rand, baseline),
'","WallOut":"',
_machine.getWallOutName(rand, baseline),
'","WallFlat":"',
_machine.getWallFlatName(rand, baseline)
);
json = string.concat(
json,
'","Colour":"',
getColourIndexTier(rand, baseline),
'","Pattern":"',
Patterns.getPatternName(rand, baseline),
'","Character":"',
_machine.getCharacterName(rand, baseline),
'"}\' >'
);
return json;
}
function getBaseColourValue(uint rand, int baseline) internal pure returns (uint) {
return GridHelper.constrainToHex(Noise.getNoiseArrayThree()[GridHelper.getRandByte(rand, 3)] + baseline);
}
function getColourIndexTier(uint rand, int baseline) public pure returns(string memory) {
uint value = Environment.getColourIndex(getBaseColourValue(rand, baseline));
if (value < 12) {
return string.concat("DEG", Strings.toString(11-value));
} else {
return string.concat("EMB", Strings.toString(value-12));
}
}
function getState(int baseline) public pure returns (uint) {
if (baseline < 85) {
return 0;
} else if (baseline < 171) {
return 1;
} else {
return 2;
}
}
function getBaselineRarity(uint rand) public pure returns (int) {
int baselineDigits = int(GridHelper.constrainToHex(Noise.getNoiseArrayZero()[GridHelper.getRandByte(rand, 2)]));
return baselineDigits;
}
function composeSVG(uint rand, int baseline) public view returns (string memory) {
return Base64.encode(bytes(composeOnlyImage(rand, baseline)));
}
function composeOnlyImage(uint rand, int baseline) public view returns (string memory) {
uint isFlipped = rand % 2;
string memory flip = "";
if (isFlipped == 0) {
flip = "1";
} else {
flip = "-1";
}
string memory machine = getMachine(rand);
uint colourValue = getBaseColourValue(rand, baseline);
string memory dataInfo = createDataInfo(rand);
string memory opening = _globalSVG.getOpeningSVG(machine, colourValue, rand, baseline);
string memory objects = _machine.machineToGetter(machine, rand, baseline);
string memory closing = _globalSVG.getClosingSVG();
return string.concat(opening, _globalSVG.getShell(flip, rand, baseline, dataInfo), objects, closing);
}
}
文件 18 的 24:Noise.sol
pragma solidity 0.8.16;
library Noise {
function getNoiseArrayZero() external pure returns (int256[256] memory) {
int[256] memory noiseArray = [int(8), 16, 24, 32, 40, 40, 48, 48, 48, 56, 56, 64, 64, 64, 64, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 80, 80, 80, 80, 80, 80, 80, 80, 88, 88, 88, 88, 88, 88, 88, 88, 88, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 152, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 168, 168, 168, 168, 168, 168, 168, 168, 168, 168, 168, 176, 176, 176, 176, 176, 176, 176, 176, 176, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 192, 192, 192, 192, 200, 200, 200, 200, 200, 200, 200, 208, 208, 216, 224, 232, 240, 248];
return noiseArray;
}
function getNoiseArrayOne() external pure returns (int256[] memory) {
return createLinearNoiseArray(128);
}
function getNoiseArrayTwo() external pure returns (int256[] memory) {
return createLinearNoiseArray(32);
}
function getNoiseArrayThree() external pure returns (int256[] memory) {
return createLinearNoiseArray(64);
}
function createLinearNoiseArray(uint range) internal pure returns (int256[] memory) {
int[] memory output = new int[](256);
require(256 % range == 0, "range must be a factor of 256");
require(range % 2 == 0, "range must be even");
uint numOfCycles = 256 / range;
int halfRange = int(range / 2);
for (uint i = 0; i < numOfCycles; i++) {
for (uint j = 0; j < range; ++j) {
output[i * range + j] = int(j) - halfRange;
}
}
return output;
}
}
文件 19 的 24:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 20 的 24:Patterns.sol
pragma solidity 0.8.16;
import "./GridHelper.sol";
import "./Noise.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
library Patterns {
string internal constant ANIMATED_TEXTURE_NUMBERS = "20.019.018.017.016.015.014.013.012.011.010.09.008.007.006.005.004.003.002.00";
string internal constant TEXTURE_SCALE_NUMBERS = "4.03.93.83.73.63.53.43.33.23.13.02.92.82.72.62.52.42.32.22.12.01.91.81.71.61.51.41.31.21.11.0";
string internal constant PATTERNS_SCALE_NUMBERS = "15.014.714.414.113.813.513.212.912.612.312.011.711.411.110.810.510.209.909.609.309.008.708.408.107.807.507.206.906.606.306.005.705.405.104.804.504.203.903.603.303.002.702.402.101.801.501.200.900.600.3";
string internal constant ANIMATED_TEXTURE_NAMES = "TEXT12TEXT14TEXT09TEXT10TEXT13TEXT11";
string internal constant TEXTURE_NAMES = "TEXT04TEXT01TEXT07TEXT05TEXT08TEXT02TEXT03TEXT06";
string internal constant PATTERNS_NAMES = "GEOM03GEOM04PIXE02AZTC10GEOM02GEOM01LOGI01GEOM05PIXE02AZTC01AZTC05AZTC03AZTC09AZTC02AZTC08AZTC04AZTC06AZTC07";
function getIsTexture(uint rand, int baseline) public pure returns (bool) {
uint textureDigits = GridHelper.constrainToHex(Noise.getNoiseArrayThree()[GridHelper.getRandByte(rand, 5)] + baseline);
return textureDigits < 128;
}
function getPatternName(uint rand, int baseline) public pure returns (string memory) {
uint patternDigits = GridHelper.constrainToHex(Noise.getNoiseArrayThree()[GridHelper.getRandByte(rand, 5)] + baseline);
bool isTexture = getIsTexture(rand, baseline);
if (!isTexture) {
patternDigits -= 128;
}
patternDigits *= 2;
bool isAnimatedTexture = baseline < 70;
uint nameLength;
uint nameCount;
string memory names;
if (isAnimatedTexture) {
nameLength = 6;
nameCount = 6;
names = ANIMATED_TEXTURE_NAMES;
} else if (isTexture && !isAnimatedTexture) {
nameLength = 6;
nameCount = 8;
names = TEXTURE_NAMES;
} else {
nameLength = 6;
nameCount = 18;
names = PATTERNS_NAMES;
}
uint[] memory nameProbabilitiesArray = GridHelper.createEqualProbabilityArray(nameCount);
uint oneLess = nameCount - 1;
for (uint i = 0; i < oneLess; ++i) {
if (patternDigits < nameProbabilitiesArray[i]) {
return string(GridHelper.slice(bytes(names), i * nameLength, nameLength));
}
}
return string(GridHelper.slice(bytes(names), oneLess * nameLength, nameLength));
}
function getSurfaceQuantity(uint rand, int baseline) public pure returns (bool[3] memory) {
uint surfaceDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 6)] + baseline);
if (baseline < 70) {
surfaceDigits += 128;
}
uint[] memory surfaceProbabilitiesArray = GridHelper.createEqualProbabilityArray(4);
if (surfaceDigits < surfaceProbabilitiesArray[0]) {
return [true, false, false];
} else if (surfaceDigits < surfaceProbabilitiesArray[1]) {
return [false, true, false];
} else if (surfaceDigits < surfaceProbabilitiesArray[2]) {
return [true, true, false];
} else {
return [true, true, true];
}
}
function getScale(uint rand, int baseline) public pure returns (string memory) {
uint scaleDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 7)] + baseline);
bool isTexture = getIsTexture(rand, baseline);
bool isAnimatedTexture = baseline < 70;
uint scaleLength;
uint scaleCount;
string memory scales;
if (isAnimatedTexture) {
scaleLength = 4;
scaleCount = 19;
scales = ANIMATED_TEXTURE_NUMBERS;
} else if (isTexture && !isAnimatedTexture) {
scaleLength = 3;
scaleCount = 31;
scales = TEXTURE_SCALE_NUMBERS;
} else {
scaleLength = 4;
scaleCount = 50;
scales = PATTERNS_SCALE_NUMBERS;
}
uint[] memory scaleProbabilitiesArray = GridHelper.createEqualProbabilityArray(scaleCount);
uint oneLess = scaleCount - 1;
if (baseline > 185) {
uint scaleValue = oneLess - (scaleDigits % 5);
return string(GridHelper.slice(bytes(scales), scaleValue * scaleLength, scaleLength));
}
for (uint i = 0; i < oneLess; ++i) {
if (scaleDigits < scaleProbabilitiesArray[i]) {
return string(GridHelper.slice(bytes(scales), i * scaleLength, scaleLength));
}
}
return string(GridHelper.slice(bytes(scales), oneLess * scaleLength, scaleLength));
}
function getOpacity(uint rand, int baseline, uint surfaceNumber) public pure returns (string memory) {
uint opacityDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 8)] + baseline);
bool[3] memory surfaceQuantity = getSurfaceQuantity(rand, baseline);
if (!surfaceQuantity[surfaceNumber]) {
return Strings.toString(0);
}
bool isTexture = getIsTexture(rand, baseline);
if (isTexture) {
return Strings.toString(100 - (opacityDigits * 80 / 255 + 20));
} else {
if (baseline > 185) {
return Strings.toString(100);
} else {
return Strings.toString(opacityDigits * 75 / 255 + 25);
}
}
}
function getRotate(uint rand, int baseline) public pure returns (uint) {
uint rotateDigits = GridHelper.constrainToHex(Noise.getNoiseArrayOne()[GridHelper.getRandByte(rand, 9)] + baseline);
return rotateDigits * 45 / 255;
}
}
文件 21 的 24:Strings.sol
pragma solidity ^0.8.0;
import "./math/Math.sol";
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
文件 22 的 24:TraitBase.sol
pragma solidity 0.8.16;
interface IAssetFromID {
function getAssetFromID(uint assetID) external view returns (string memory);
}
contract TraitBase {
address[] internal implementationAddresses;
constructor(address[] memory addresses) {
implementationAddresses = addresses;
}
function getAssetFromTrait(uint assetID) external view returns (string memory) {
string memory asset = "";
for (uint i = 0; i < implementationAddresses.length;) {
asset = IAssetFromID(implementationAddresses[i]).getAssetFromID(assetID);
if (bytes(asset).length > 0) {
return asset;
}
unchecked {
++i;
}
}
return "";
}
}
文件 23 的 24:VRFConsumerBaseV2.sol
pragma solidity ^0.8.4;
abstract contract VRFConsumerBaseV2 {
error OnlyCoordinatorCanFulfill(address have, address want);
address private immutable vrfCoordinator;
constructor(address _vrfCoordinator) {
vrfCoordinator = _vrfCoordinator;
}
function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual;
function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external {
if (msg.sender != vrfCoordinator) {
revert OnlyCoordinatorCanFulfill(msg.sender, vrfCoordinator);
}
fulfillRandomWords(requestId, randomWords);
}
}
文件 24 的 24:VRFCoordinatorV2Interface.sol
pragma solidity ^0.8.0;
interface VRFCoordinatorV2Interface {
function getRequestConfig()
external
view
returns (
uint16,
uint32,
bytes32[] memory
);
function requestRandomWords(
bytes32 keyHash,
uint64 subId,
uint16 minimumRequestConfirmations,
uint32 callbackGasLimit,
uint32 numWords
) external returns (uint256 requestId);
function createSubscription() external returns (uint64 subId);
function getSubscription(uint64 subId)
external
view
returns (
uint96 balance,
uint64 reqCount,
address owner,
address[] memory consumers
);
function requestSubscriptionOwnerTransfer(uint64 subId, address newOwner) external;
function acceptSubscriptionOwnerTransfer(uint64 subId) external;
function addConsumer(uint64 subId, address consumer) external;
function removeConsumer(uint64 subId, address consumer) external;
function cancelSubscription(uint64 subId, address to) external;
function pendingRequestExists(uint64 subId) external view returns (bool);
}
{
"compilationTarget": {
"src/Clifford.sol": "Clifford"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"details": {
"constantOptimizer": true,
"cse": true,
"deduplicate": true,
"inliner": true,
"jumpdestRemover": true,
"orderLiterals": true,
"peephole": true,
"yul": true,
"yulDetails": {
"optimizerSteps": "",
"stackAllocation": true
}
},
"runs": 200
},
"remappings": [
":@chainlink/=lib/chainlink/",
":@openzeppelin/=lib/openzeppelin-contracts/",
":ERC721A/=lib/ERC721A/contracts/",
":base64-sol/=lib/base64/",
":base64/=lib/base64/",
":chainlink/=lib/chainlink/contracts/src/v0.8/dev/vendor/@arbitrum/nitro-contracts/src/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":forge-std/=lib/forge-std/src/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":solady/=lib/solady/src/",
":solmate/=lib/solady/lib/solmate/src/"
]
}
[{"inputs":[{"internalType":"contract Metadata","name":"metadata","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ApprovalCallerNotOwnerNorApproved","type":"error"},{"inputs":[],"name":"ApprovalQueryForNonexistentToken","type":"error"},{"inputs":[],"name":"AuctionAlreadyStarted","type":"error"},{"inputs":[],"name":"AuctionNotActive","type":"error"},{"inputs":[],"name":"AuctionNotOver","type":"error"},{"inputs":[],"name":"BalanceQueryForZeroAddress","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"BidTooSmall","type":"error"},{"inputs":[],"name":"CannotBidZero","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"CypherAlreadyClaimed","type":"error"},{"inputs":[],"name":"CypherClaimNotActive","type":"error"},{"inputs":[],"name":"CypherClaimNotEnded","type":"error"},{"inputs":[],"name":"CypherClaimNotStarted","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"IncorrectBidIncrement","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"InvalidTokenId","type":"error"},{"inputs":[],"name":"MintERC2309QuantityExceedsLimit","type":"error"},{"inputs":[],"name":"MintToZeroAddress","type":"error"},{"inputs":[],"name":"MintZeroQuantity","type":"error"},{"inputs":[],"name":"NftsNotAllMinted","type":"error"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"NoBidToClaim","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"NotOwnerOfCypher","type":"error"},{"inputs":[{"internalType":"address","name":"have","type":"address"},{"internalType":"address","name":"want","type":"address"}],"name":"OnlyCoordinatorCanFulfill","type":"error"},{"inputs":[],"name":"OwnerQueryForNonexistentToken","type":"error"},{"inputs":[],"name":"OwnershipNotInitializedForExtraData","type":"error"},{"inputs":[{"internalType":"uint256","name":"genId","type":"uint256"}],"name":"SeedNotSet","type":"error"},{"inputs":[],"name":"TooManyRequested","type":"error"},{"inputs":[],"name":"TransferCallerNotOwnerNorApproved","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"inputs":[],"name":"TransferFromIncorrectOwner","type":"error"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"TransferNotSuccessful","type":"error"},{"inputs":[],"name":"TransferToNonERC721ReceiverImplementer","type":"error"},{"inputs":[],"name":"TransferToZeroAddress","type":"error"},{"inputs":[],"name":"URIQueryForNonexistentToken","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"fromTokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"toTokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"ConsecutiveTransfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"genId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"seed","type":"uint256"}],"name":"RandomNumberGenerated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"genId","type":"uint256"}],"name":"RandomnessRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"UserPlacesBid","type":"event"},{"inputs":[],"name":"MAX_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimAfterAuction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"claimCyphers","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getAllBidders","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentPricePerUnit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEndTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getIfCypherClaimed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMinimumBid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getSeed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStartTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"bidder","type":"address"}],"name":"getUserBid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"placeBid","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"uint256[]","name":"randomWords","type":"uint256[]"}],"name":"rawFulfillRandomWords","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"reveal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"s_subscriptionId","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startCypherClaimPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawRemainingNFTs","outputs":[],"stateMutability":"nonpayable","type":"function"}]