Проверенный контрактТочноеMIT
Assayer
Адрес0xb5c57a73beb59ecf4de9aa55dc8a16778bcebd4d
- Баланс
0 ETH
- Транзакций
1
- Компилятор
solc 0.8.36
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.36+commit.8a079791
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- cancun
- Через IR
- да
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 307 394
- Транзакция создания
- 0xbdfb260b8b…6de02e5991
3 файла
- src/art/Assayer.solглавный3,63 КБ
- src/art/Stencil.sol10,58 КБ
- src/interfaces/IEtcher.sol850 Б
src/art/Assayer.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.36;
import { IAssayer } from "../interfaces/IEtcher.sol";
import { ArtPage, Stencil } from "./Stencil.sol";
/// @dev Decoding and validation of a raw stencil image.
library Unpacking {
error InvalidMagic(bytes4 actual);
error InvalidTraitCount(uint256 actual);
error InvalidTraitValues(uint256 trait, uint256 actual);
error InvalidGlyphCount(uint256 actual);
error InvalidPaletteBytes(uint256 actual);
uint256 internal constant TRAIT_COUNT = 11;
uint256 internal constant GLYPH_COUNT = 13;
uint256 internal constant GLYPH_SIZES = 4;
uint256 internal constant PALETTE_COUNT = 17;
uint256 internal constant PALETTE_BYTES = 9;
function parse(bytes memory raw) internal pure returns (ArtPage memory page) {
if (raw.length < 4) revert InvalidMagic(bytes4(0));
bytes4 magic = bytes4(raw);
if (magic != Stencil.MAGIC) revert InvalidMagic(magic);
bytes memory body = new bytes(raw.length - 4);
assembly ("memory-safe") {
mcopy(add(body, 0x20), add(raw, 0x24), mload(body))
}
page = abi.decode(body, (ArtPage));
}
function checkTraits(ArtPage memory page) internal pure {
if (page.traitNames.length != TRAIT_COUNT || page.traitValues.length != TRAIT_COUNT) {
revert InvalidTraitCount(page.traitNames.length);
}
for (uint256 trait; trait < TRAIT_COUNT; ++trait) {
uint256 count = page.traitValues[trait].length;
if (count == 0 || count > 255) revert InvalidTraitValues(trait, count);
}
if (page.traitValues[0].length != PALETTE_COUNT) revert InvalidTraitValues(0, page.traitValues[0].length);
for (uint256 trait = 2; trait <= 6; ++trait) {
if (page.traitValues[trait].length != GLYPH_COUNT) {
revert InvalidTraitValues(trait, page.traitValues[trait].length);
}
}
}
function checkAssets(ArtPage memory page) internal pure {
if (page.glyphPaths.length != GLYPH_COUNT * GLYPH_SIZES) revert InvalidGlyphCount(page.glyphPaths.length);
if (page.palettes.length != PALETTE_COUNT * PALETTE_BYTES) revert InvalidPaletteBytes(page.palettes.length);
}
}
/// @notice Reads and assays a stored stencil; the toolkit id pins the asset vocabulary an etcher expects.
contract Assayer is IAssayer {
error EmptyPage(address page);
bytes32 private constant TOOLKIT_ID = keccak256("sqk.dotgrid-asset-set.v1");
function toolkitId() external pure returns (bytes32) {
return TOOLKIT_ID;
}
function assay(address stencil) external view returns (bytes32 stencilHash, bytes32 toolkitHash) {
bytes memory raw = peel(stencil);
ArtPage memory page = Unpacking.parse(raw);
Unpacking.checkTraits(page);
Unpacking.checkAssets(page);
stencilHash = keccak256(raw);
toolkitHash = keccak256(abi.encode(TOOLKIT_ID, page.glyphPaths, page.palettes));
}
function unpack(address stencil) external view returns (ArtPage memory page) {
page = Unpacking.parse(peel(stencil));
Unpacking.checkTraits(page);
Unpacking.checkAssets(page);
}
/// @dev Runtime code of the stencil without its leading STOP byte.
function peel(address stencil) public view returns (bytes memory raw) {
uint256 size = stencil.code.length;
if (size < 2) revert EmptyPage(stencil);
raw = new bytes(size - 1);
assembly ("memory-safe") {
extcodecopy(stencil, add(raw, 0x20), 1, sub(size, 1))
}
}
}
src/art/Stencil.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.36;
struct ArtPage {
string name;
string description;
string[] traitNames;
string[][] traitValues;
string[] glyphPaths;
bytes palettes;
}
/// @dev Immutable art stencil: trait vocabulary, glyph paths and palettes, abi-encoded behind a magic prefix.
library Stencil {
bytes4 internal constant MAGIC = 0x44475047;
function build() internal pure returns (bytes memory) {
ArtPage memory page;
page.name = "Squeek";
page.description = "Squeek is a dot-grid character rendered fully onchain from an immutable art page.";
page.traitNames = _attributeNames();
page.traitValues = _attributeValues();
page.glyphPaths = _glyphPaths();
page.palettes = _palettes();
return abi.encodePacked(MAGIC, abi.encode(page));
}
function _attributeNames() private pure returns (string[] memory names) {
names = new string[](11);
names[0] = "Palette";
names[1] = "Color Pattern";
names[2] = "Body Glyph";
names[3] = "Face Glyph";
names[4] = "Eye Glyph";
names[5] = "Muzzle Glyph";
names[6] = "Ear Glyph";
names[7] = "Illumination";
names[8] = "Eyes";
names[9] = "Ears";
names[10] = "Background";
}
function _attributeValues() private pure returns (string[][] memory values) {
values = new string[][](11);
values[0] = _palettesNames();
values[1] = _list6("Solid", "Vertical Split", "Horizontal Split", "Radial Core", "Checker", "Spectral Noise");
string[] memory glyphs = _glyphNames();
values[2] = glyphs;
values[3] = glyphs;
values[4] = glyphs;
values[5] = glyphs;
values[6] = glyphs;
values[7] = _list5("Balanced Field", "Core Pulse", "Rim Trace", "Phase Sweep", "Overdrive");
values[8] = _featureE();
values[9] = _list6("Canonical Round", "Compact Round", "Wide Round", "Soft Square", "Notched", "Hollow Ring");
values[10] = _list5("Dot Grid", "Micro Dots", "Wide Dots", "Scanlines", "Cross Grid");
}
function _palettesNames() private pure returns (string[] memory names) {
names = new string[](17);
names[0] = "Void Violet";
names[1] = "Electric Cyan";
names[2] = "Acid Lime";
names[3] = "Orange CRT";
names[4] = "Hot Magenta";
names[5] = "Reactor Red";
names[6] = "Ice White";
names[7] = "Spectral RGB";
names[8] = "Gold";
names[9] = "Spectral Void Violet";
names[10] = "Spectral Electric Cyan";
names[11] = "Spectral Acid Lime";
names[12] = "Spectral Orange CRT";
names[13] = "Spectral Hot Magenta";
names[14] = "Spectral Reactor Red";
names[15] = "Spectral Ice White";
names[16] = "Spectral Gold";
}
function _glyphNames() private pure returns (string[] memory names) {
names = new string[](13);
names[0] = "Circle";
names[1] = "Rounded Square";
names[2] = "Triangle";
names[3] = "Diamond";
names[4] = "Cross";
names[5] = "Sparkle";
names[6] = "Shield";
names[7] = "Capsule";
names[8] = "Crown";
names[9] = "Heart";
names[10] = "Teardrop";
names[11] = "Lightning Bolt";
names[12] = "Clover";
}
function _featureE() private pure returns (string[] memory names) {
names = new string[](12);
names[0] = "Standard Capsules";
names[1] = "Wide Blocks";
names[2] = "Tiny Pixels";
names[3] = "Sleepy Bars";
names[4] = "X Expression";
names[5] = "Reticle";
names[6] = "Vertical Slits";
names[7] = "Focused Chevrons";
names[8] = "Happy Arcs";
names[9] = "Broken Signal";
names[10] = "Wink";
names[11] = "Orbit Rings";
}
function _glyphPaths() private pure returns (string[] memory paths) {
paths = new string[](52);
paths[0] = "M0-2.5A2.5 2.5 0 1 1 0 2.5A2.5 2.5 0 1 1 0-2.5Z";
paths[1] = "M0-4.5A4.5 4.5 0 1 1 0 4.5A4.5 4.5 0 1 1 0-4.5Z";
paths[2] = "M0-7A7 7 0 1 1 0 7A7 7 0 1 1 0-7Z";
paths[3] = "M0-9.5A9.5 9.5 0 1 1 0 9.5A9.5 9.5 0 1 1 0-9.5Z";
paths[4] = "M-1.136-2.272H1.136A1.136 1.136 0 0 1 2.272-1.136V1.136A1.136 1.136 0 0 1 1.136 2.272H-1.136A1.136 1.136 0 0 1-2.272 1.136V-1.136A1.136 1.136 0 0 1-1.136-2.272Z";
paths[5] = "M-2.045-4.089H2.045A2.045 2.045 0 0 1 4.089-2.045V2.045A2.045 2.045 0 0 1 2.045 4.089H-2.045A2.045 2.045 0 0 1-4.089 2.045V-2.045A2.045 2.045 0 0 1-2.045-4.089Z";
paths[6] = "M-3.18-6.361H3.18A3.18 3.18 0 0 1 6.361-3.18V3.18A3.18 3.18 0 0 1 3.18 6.361H-3.18A3.18 3.18 0 0 1-6.361 3.18V-3.18A3.18 3.18 0 0 1-3.18-6.361Z";
paths[7] = "M-4.316-8.633H4.316A4.316 4.316 0 0 1 8.633-4.316V4.316A4.316 4.316 0 0 1 4.316 8.633H-4.316A4.316 4.316 0 0 1-8.633 4.316V-4.316A4.316 4.316 0 0 1-4.316-8.633Z";
paths[8] = "M0-3.131L3.131 3.131L-3.131 3.131Z";
paths[9] = "M0-5.636L5.636 5.636L-5.636 5.636Z";
paths[10] = "M0-8.767L8.767 8.767L-8.767 8.767Z";
paths[11] = "M0-11.898L11.898 11.898L-11.898 11.898Z";
paths[12] = "M0-3.115L3.115 0L0 3.115L-3.115 0Z";
paths[13] = "M0-5.607L5.607 0L0 5.607L-5.607 0Z";
paths[14] = "M0-8.722L8.722 0L0 8.722L-8.722 0Z";
paths[15] = "M0-11.837L11.837 0L0 11.837L-11.837 0Z";
paths[16] = "M-2.985-1H-1V-2.985H1V-1H2.985V1H1V2.985H-1V1H-2.985Z";
paths[17] = "M-5.373-1.791H-1.791V-5.373H1.791V-1.791H5.373V1.791H1.791V5.373H-1.791V1.791H-5.373Z";
paths[18] = "M-8.358-2.786H-2.786V-8.358H2.786V-2.786H8.358V2.786H2.786V8.358H-2.786V2.786H-8.358Z";
paths[19] = "M-11.343-3.781H-3.781V-11.343H3.781V-3.781H11.343V3.781H3.781V11.343H-3.781V3.781H-11.343Z";
paths[20] = "M0-3.824L1.275-1.275L3.824 0L1.275 1.275L0 3.824L-1.275 1.275L-3.824 0L-1.275-1.275Z";
paths[21] = "M0-6.883L2.294-2.294L6.883 0L2.294 2.294L0 6.883L-2.294 2.294L-6.883 0L-2.294-2.294Z";
paths[22] = "M0-10.706L3.569-3.569L10.707 0L3.569 3.569L0 10.707L-3.569 3.569L-10.706 0L-3.569-3.569Z";
paths[23] = "M0-14.53L4.843-4.843L14.53 0L4.843 4.843L0 14.53L-4.843 4.843L-14.53 0L-4.843-4.843Z";
paths[24] = "M-2.558-2.558H2.558V0L0 2.558L-2.558 0Z";
paths[25] = "M-4.605-4.605H4.605V0L0 4.605L-4.605 0Z";
paths[26] = "M-7.163-7.163H7.163V0L0 7.163L-7.163 0Z";
paths[27] = "M-9.721-9.721H9.721V0L0 9.721L-9.721 0Z";
paths[28] = "M-1.655-1.655H1.655A1.655 1.655 0 0 1 1.655 1.655H-1.655A1.655 1.655 0 0 1-1.655-1.655Z";
paths[29] = "M-2.979-2.979H2.979A2.979 2.979 0 0 1 2.979 2.979H-2.979A2.979 2.979 0 0 1-2.979-2.979Z";
paths[30] = "M-4.634-4.634H4.634A4.634 4.634 0 0 1 4.634 4.634H-4.634A4.634 4.634 0 0 1-4.634-4.634Z";
paths[31] = "M-6.289-6.289H6.289A6.289 6.289 0 0 1 6.289 6.289H-6.289A6.289 6.289 0 0 1-6.289-6.289Z";
paths[32] = "M-2.427 2.427V-1L-2-2.427L-1-1L0-2.427L1-1L2-2.427L2.427-1V2.427Z";
paths[33] = "M-4.369 4.369V-1.456L-2.912-4.369L-1.456-1.456L0-4.369L1.456-1.456L2.912-4.369L4.369-1.456V4.369Z";
paths[34] = "M-6.796 6.796V-2.265L-4.53-6.796L-2.265-2.265L0-6.796L2.265-2.265L4.53-6.796L6.796-2.265V6.796Z";
paths[35] = "M-9.223 9.223V-3.074L-6.148-9.223L-3.074-3.074L0-9.223L3.074-3.074L6.148-9.223L9.223-3.074V9.223Z";
paths[36] = "M0 3.008L-3.008 0Q-3.008-3.008 0-1.504Q3.008-3.008 3.008 0Z";
paths[37] = "M0 5.414L-5.413 0Q-5.413-5.413 0-2.707Q5.414-5.413 5.414 0Z";
paths[38] = "M0 8.421L-8.421 0Q-8.421-8.421 0-4.211Q8.421-8.421 8.421 0Z";
paths[39] = "M0 11.429L-11.429 0Q-11.429-11.429 0-5.714Q11.429-11.429 11.429 0Z";
paths[40] = "M0-2.906Q2.906 0 1.453 2.906Q0 5.813-1.453 2.906Q-2.906 0 0-2.906Z";
paths[41] = "M0-5.231Q5.231 0 2.616 5.231Q0 10.463-2.616 5.231Q-5.231 0 0-5.231Z";
paths[42] = "M0-8.138Q8.138 0 4.069 8.138Q0 16.275-4.069 8.138Q-8.138 0 0-8.138Z";
paths[43] = "M0-11.044Q11.044 0 5.522 11.044Q0 22.088-5.522 11.044Q-11.044 0 0-11.044Z";
paths[44] = "M1.307-3.922L-3.922 1.307H-1.307L-1.961 3.923L3.923-1.307H1.307Z";
paths[45] = "M2.354-7.06L-7.06 2.354H-2.353L-3.53 7.06L7.06-2.353H2.354Z";
paths[46] = "M3.661-10.983L-10.983 3.661H-3.661L-5.491 10.983L10.983-3.661H3.661Z";
paths[47] = "M4.969-14.905L-14.905 4.969H-4.968L-7.453 14.906L14.906-4.968H4.969Z";
paths[48] = "M0 0Q-2.73-2.73 0-2.73T0 0Q2.73-2.73 2.73 0T0 0Q2.73 2.73 0 2.73T0 0Q-2.73 2.73-2.73 0T0 0Z";
paths[49] = "M0 0Q-4.914-4.914 0-4.914T0 0Q4.914-4.914 4.914 0T0 0Q4.914 4.914 0 4.914T0 0Q-4.914 4.914-4.914 0T0 0Z";
paths[50] = "M0 0Q-7.644-7.644 0-7.644T0 0Q7.644-7.644 7.644 0T0 0Q7.644 7.644 0 7.644T0 0Q-7.644 7.644-7.644 0T0 0Z";
paths[51] = "M0 0Q-10.374-10.374 0-10.374T0 0Q10.374-10.374 10.374 0T0 0Q10.374 10.374 0 10.374T0 0Q-10.374 10.374-10.374 0T0 0Z";
}
function _palettes() private pure returns (bytes memory) {
return abi.encodePacked(
hex"7C3AED_A78BFA_4C1D95",
hex"22D3EE_67E8F9_0E7490",
hex"A3E635_D9F99D_4D7C0F",
hex"FB923C_FDBA74_C2410C",
hex"F472B6_FBCFE8_BE185D",
hex"EF4444_FCA5A5_991B1B",
hex"F8FAFC_CBD5E1_94A3B8",
hex"FF3B30_34C759_0A84FF",
hex"F5C542_FFE08A_B8860B",
hex"7C3AED_22D3EE_F472B6",
hex"22D3EE_A3E635_7C3AED",
hex"A3E635_FB923C_22D3EE",
hex"FB923C_F472B6_F5C542",
hex"F472B6_7C3AED_22D3EE",
hex"EF4444_F5C542_7C3AED",
hex"F8FAFC_22D3EE_F472B6",
hex"F5C542_EF4444_A3E635"
);
}
function _list5(string memory a, string memory b, string memory c, string memory d, string memory e)
private
pure
returns (string[] memory list)
{
list = new string[](5);
list[0] = a;
list[1] = b;
list[2] = c;
list[3] = d;
list[4] = e;
}
function _list6(
string memory a,
string memory b,
string memory c,
string memory d,
string memory e,
string memory f
) private pure returns (string[] memory list) {
list = new string[](6);
list[0] = a;
list[1] = b;
list[2] = c;
list[3] = d;
list[4] = e;
list[5] = f;
}
}
src/interfaces/IEtcher.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.36;
interface IEtcher {
function etchName() external pure returns (string memory);
function etchId() external pure returns (bytes32);
function assayer() external view returns (address);
function assay(address stencil) external view returns (bytes32 stencilHash, bytes32 toolkitHash);
function genome(address stencil, bytes32 salt, uint256 tokenId) external view returns (bytes32);
function genomeHash(address stencil, bytes32 salt, uint256 tokenId) external view returns (bytes32);
function etch(address stencil, bytes32 salt, uint256 tokenId) external view returns (string memory);
}
interface IAssayer {
function toolkitId() external pure returns (bytes32);
function assay(address stencil) external view returns (bytes32 stencilHash, bytes32 toolkitHash);
}
Настройки компилятораПоказать
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"viaSSACFG": false,
"evmVersion": "cancun",
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@uniswap/v3-core/=lib/v3-core/",
"forge-std/=lib/forge-std/src/",
"ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"v3-core/=lib/v3-core/contracts/"
],
"experimental": false
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.