Forkchoice Ethereum Mainnet

Address Contract Verified

Address 0x48cB121Fa84b7C08692e74872D044B15369977CD
Balance 0 ETH
Nonce 1
Code Size 9267 bytes
Indexed Transactions 0 (1 on-chain, 1.6% indexed)
External Etherscan · Sourcify

Contract Bytecode

9267 bytes
Copy Bytecode
0x608060405234801561000f575f5ffd5b506004361061011f575f3560e01c80638da5cb5b116100ab578063cf564e2f1161006f578063cf564e2f14610317578063e2098e8414610333578063eec23d2114610363578063f2fde38b14610393578063f9c5cd4f146103af5761011f565b80638da5cb5b1461024b57806390c2b820146102695780639b8eb18b1461029b578063afc42d9d146102b7578063c6c669d1146102e75761011f565b8063358df334116100f2578063358df334146101bd5780636d2e6de3146101d9578063715018a6146101f5578063825142da146101ff5780638d6f82aa1461022f5761011f565b80630832c26f14610123578063092ec016146101535780630facebea1461017157806328eacbcf146101a1575b5f5ffd5b61013d600480360381019061013891906116b8565b6103df565b60405161014a91906116f2565b60405180910390f35b61015b6103f4565b6040516101689190611785565b60405180910390f35b61018b600480360381019061018691906116b8565b610419565b604051610198919061180e565b60405180910390f35b6101bb60048036038101906101b69190611869565b6104bc565b005b6101d760048036038101906101d291906119c0565b610507565b005b6101f360048036038101906101ee91906116b8565b610534565b005b6101fd6106a1565b005b610219600480360381019061021491906116b8565b6106b4565b6040516102269190611a6c565b60405180910390f35b61024960048036038101906102449190611c0c565b610a82565b005b610253610c53565b6040516102609190611cb7565b60405180910390f35b610283600480360381019061027e91906116b8565b610c7a565b60405161029293929190611cd0565b60405180910390f35b6102b560048036038101906102b09190611d0c565b610d45565b005b6102d160048036038101906102cc91906116b8565b611124565b6040516102de9190611d64565b60405180910390f35b61030160048036038101906102fc91906116b8565b611135565b60405161030e91906116f2565b60405180910390f35b610331600480360381019061032c9190611d7d565b611152565b005b61034d600480360381019061034891906116b8565b61119b565b60405161035a91906116f2565b60405180910390f35b61037d60048036038101906103789190611d0c565b6111bb565b60405161038a9190611a6c565b60405180910390f35b6103ad60048036038101906103a89190611869565b611393565b005b6103c960048036038101906103c491906116b8565b611417565b6040516103d691906116f2565b60405180910390f35b6003602052805f5260405f205f915090505481565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b606060025f8381526020019081526020015f205f01805461043990611e16565b80601f016020809104026020016040519081016040528092919081815260200182805461046590611e16565b80156104b05780601f10610487576101008083540402835291602001916104b0565b820191905f5260205f20905b81548152906001019060200180831161049357829003601f168201915b50505050509050919050565b6104c461142c565b8060015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b61050f61142c565b8060025f8481526020019081526020015f205f01908161052f9190611fdd565b505050565b61053c61142c565b610545816114b3565b61057b576040517f87feed6c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f60035f8381526020019081526020015f205490505f60016005805490506105a391906120d9565b9050808214610605575f600582815481106105c1576105c061210c565b5b905f5260205f200154905080600584815481106105e1576105e061210c565b5b905f5260205f2001819055508260035f8381526020019081526020015f2081905550505b600580548061061757610616612139565b5b600190038181905f5260205f20015f9055905560035f8481526020019081526020015f205f905560025f8481526020019081526020015f205f5f82015f61065e919061159e565b600182015f61066d91906115db565b600282015f9055600382015f6101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690555050505050565b6106a961142c565b6106b25f6114d6565b565b60605f60025f8481526020019081526020015f20905060015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166340fc15c9846040518263ffffffff1660e01b815260040161072491906116f2565b602060405180830381865afa15801561073f573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107639190612190565b1561080e57806003015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663563dc14b846040518263ffffffff1660e01b81526004016107c491906116f2565b5f60405180830381865afa1580156107de573d5f5f3e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906108069190612229565b915050610a7d565b5f8160010190505f818054905090505f810361083d5760405180602001604052805f8152509350505050610a7d565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637c7e2a28866040518263ffffffff1660e01b815260040161089791906116f2565b602060405180830381865afa1580156108b2573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108d69190612190565b61098657815f815481106108ed576108ec61210c565b5b905f5260205f2001805461090090611e16565b80601f016020809104026020016040519081016040528092919081815260200182805461092c90611e16565b80156109775780601f1061094e57610100808354040283529160200191610977565b820191905f5260205f20905b81548152906001019060200180831161095a57829003601f168201915b50505050509350505050610a7d565b5f60045f8781526020019081526020015f205490505f81036109a6578190505b818111156109c85760405180602001604052805f815250945050505050610a7d565b826001826109d691906120d9565b815481106109e7576109e661210c565b5b905f5260205f200180546109fa90611e16565b80601f0160208091040260200160405190810160405280929190818152602001828054610a2690611e16565b8015610a715780601f10610a4857610100808354040283529160200191610a71565b820191905f5260205f20905b815481529060010190602001808311610a5457829003601f168201915b50505050509450505050505b919050565b610a8a61142c565b8383511115610ac5576040517f38aa8a6000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610ace846114b3565b15610b05576040517fffeddc4c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f5f90505b8351811015610b7e5760025f8681526020019081526020015f20600101848281518110610b3a57610b3961210c565b5b6020026020010151908060018154018082558091505060019003905f5260205f20015f909190919091509081610b7091906122c8565b508080600101915050610b0a565b508060025f8681526020019081526020015f205f019081610b9f9190611fdd565b508160025f8681526020019081526020015f206003015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550825160025f8681526020019081526020015f206002018190555060058054905060035f8681526020019081526020015f2081905550600584908060018154018082558091505060019003905f5260205f20015f909190919091505550505050565b5f5f5f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6002602052805f5260405f205f91509050805f018054610c9990611e16565b80601f0160208091040260200160405190810160405280929190818152602001828054610cc590611e16565b8015610d105780601f10610ce757610100808354040283529160200191610d10565b820191905f5260205f20905b815481529060010190602001808311610cf357829003601f168201915b505050505090806002015490806003015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905083565b815f60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b8152600401610da191906116f2565b602060405180830381865afa158015610dbc573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610de091906123ab565b90505f60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663c86833f9846040518263ffffffff1660e01b8152600401610e3d91906116f2565b602060405180830381865afa158015610e58573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e7c91906123ab565b90508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614158015610ee657508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614155b15610f1d576040517f5634af6f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637c7e2a28866040518263ffffffff1660e01b8152600401610f7791906116f2565b602060405180830381865afa158015610f92573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fb69190612190565b610fec576040517feab19d6b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f841480611010575060025f8681526020019081526020015f206001018054905084115b15611047576040517f52581d0a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8360045f8781526020019081526020015f208190555060015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d95ba42f866040518263ffffffff1660e01b81526004016110b791906116f2565b5f604051808303815f87803b1580156110ce575f5ffd5b505af11580156110e0573d5f5f3e3d5ffd5b505050507fa950deed19835b0df517e56ef396484bf4548f6491f712ba63959e13233a923685856040516111159291906123d6565b60405180910390a15050505050565b5f61112e826114b3565b9050919050565b5f60025f8381526020019081526020015f20600201549050919050565b61115a61142c565b8160025f8581526020019081526020015f2060010182815481106111815761118061210c565b5b905f5260205f2001908161119591906122c8565b50505050565b600581815481106111aa575f80fd5b905f5260205f20015f915090505481565b606060015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637c7e2a28846040518263ffffffff1660e01b815260040161121791906116f2565b602060405180830381865afa158015611232573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112569190612190565b61128c576040517feab19d6b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61129583611124565b6112ca576040517efb7b0700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60025f8481526020019081526020015f206001016001836112eb91906120d9565b815481106112fc576112fb61210c565b5b905f5260205f2001805461130f90611e16565b80601f016020809104026020016040519081016040528092919081815260200182805461133b90611e16565b80156113865780601f1061135d57610100808354040283529160200191611386565b820191905f5260205f20905b81548152906001019060200180831161136957829003601f168201915b5050505050905092915050565b61139b61142c565b5f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361140b575f6040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081526004016114029190611cb7565b60405180910390fd5b611414816114d6565b50565b6004602052805f5260405f205f915090505481565b611434611597565b73ffffffffffffffffffffffffffffffffffffffff16611452610c53565b73ffffffffffffffffffffffffffffffffffffffff16146114b157611475611597565b6040517f118cdaa70000000000000000000000000000000000000000000000000000000081526004016114a89190611cb7565b60405180910390fd5b565b5f5f60025f8481526020019081526020015f206001018054905014159050919050565b5f5f5f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050815f5f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b5f33905090565b5080546115aa90611e16565b5f825580601f106115bb57506115d8565b601f0160209004905f5260205f20908101906115d791906115f9565b5b50565b5080545f8255905f5260205f20908101906115f69190611614565b50565b5b80821115611610575f815f9055506001016115fa565b5090565b5b80821115611633575f818161162a9190611637565b50600101611615565b5090565b50805461164390611e16565b5f825580601f106116545750611671565b601f0160209004905f5260205f209081019061167091906115f9565b5b50565b5f604051905090565b5f5ffd5b5f5ffd5b5f819050919050565b61169781611685565b81146116a1575f5ffd5b50565b5f813590506116b28161168e565b92915050565b5f602082840312156116cd576116cc61167d565b5b5f6116da848285016116a4565b91505092915050565b6116ec81611685565b82525050565b5f6020820190506117055f8301846116e3565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f819050919050565b5f61174d6117486117438461170b565b61172a565b61170b565b9050919050565b5f61175e82611733565b9050919050565b5f61176f82611754565b9050919050565b61177f81611765565b82525050565b5f6020820190506117985f830184611776565b92915050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f6117e08261179e565b6117ea81856117a8565b93506117fa8185602086016117b8565b611803816117c6565b840191505092915050565b5f6020820190508181035f83015261182681846117d6565b905092915050565b5f6118388261170b565b9050919050565b6118488161182e565b8114611852575f5ffd5b50565b5f813590506118638161183f565b92915050565b5f6020828403121561187e5761187d61167d565b5b5f61188b84828501611855565b91505092915050565b5f5ffd5b5f5ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6118d2826117c6565b810181811067ffffffffffffffff821117156118f1576118f061189c565b5b80604052505050565b5f611903611674565b905061190f82826118c9565b919050565b5f67ffffffffffffffff82111561192e5761192d61189c565b5b611937826117c6565b9050602081019050919050565b828183375f83830152505050565b5f61196461195f84611914565b6118fa565b9050828152602081018484840111156119805761197f611898565b5b61198b848285611944565b509392505050565b5f82601f8301126119a7576119a6611894565b5b81356119b7848260208601611952565b91505092915050565b5f5f604083850312156119d6576119d561167d565b5b5f6119e3858286016116a4565b925050602083013567ffffffffffffffff811115611a0457611a03611681565b5b611a1085828601611993565b9150509250929050565b5f81519050919050565b5f82825260208201905092915050565b5f611a3e82611a1a565b611a488185611a24565b9350611a588185602086016117b8565b611a61816117c6565b840191505092915050565b5f6020820190508181035f830152611a848184611a34565b905092915050565b5f67ffffffffffffffff821115611aa657611aa561189c565b5b602082029050602081019050919050565b5f5ffd5b5f67ffffffffffffffff821115611ad557611ad461189c565b5b611ade826117c6565b9050602081019050919050565b5f611afd611af884611abb565b6118fa565b905082815260208101848484011115611b1957611b18611898565b5b611b24848285611944565b509392505050565b5f82601f830112611b4057611b3f611894565b5b8135611b50848260208601611aeb565b91505092915050565b5f611b6b611b6684611a8c565b6118fa565b90508083825260208201905060208402830185811115611b8e57611b8d611ab7565b5b835b81811015611bd557803567ffffffffffffffff811115611bb357611bb2611894565b5b808601611bc08982611b2c565b85526020850194505050602081019050611b90565b5050509392505050565b5f82601f830112611bf357611bf2611894565b5b8135611c03848260208601611b59565b91505092915050565b5f5f5f5f60808587031215611c2457611c2361167d565b5b5f611c31878288016116a4565b945050602085013567ffffffffffffffff811115611c5257611c51611681565b5b611c5e87828801611bdf565b9350506040611c6f87828801611855565b925050606085013567ffffffffffffffff811115611c9057611c8f611681565b5b611c9c87828801611993565b91505092959194509250565b611cb18161182e565b82525050565b5f602082019050611cca5f830184611ca8565b92915050565b5f6060820190508181035f830152611ce881866117d6565b9050611cf760208301856116e3565b611d046040830184611ca8565b949350505050565b5f5f60408385031215611d2257611d2161167d565b5b5f611d2f858286016116a4565b9250506020611d40858286016116a4565b9150509250929050565b5f8115159050919050565b611d5e81611d4a565b82525050565b5f602082019050611d775f830184611d55565b92915050565b5f5f5f60608486031215611d9457611d9361167d565b5b5f611da1868287016116a4565b935050602084013567ffffffffffffffff811115611dc257611dc1611681565b5b611dce86828701611b2c565b9250506040611ddf868287016116a4565b9150509250925092565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f6002820490506001821680611e2d57607f821691505b602082108103611e4057611e3f611de9565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302611ea27fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82611e67565b611eac8683611e67565b95508019841693508086168417925050509392505050565b5f611ede611ed9611ed484611685565b61172a565b611685565b9050919050565b5f819050919050565b611ef783611ec4565b611f0b611f0382611ee5565b848454611e73565b825550505050565b5f5f905090565b611f22611f13565b611f2d818484611eee565b505050565b5b81811015611f5057611f455f82611f1a565b600181019050611f33565b5050565b601f821115611f9557611f6681611e46565b611f6f84611e58565b81016020851015611f7e578190505b611f92611f8a85611e58565b830182611f32565b50505b505050565b5f82821c905092915050565b5f611fb55f1984600802611f9a565b1980831691505092915050565b5f611fcd8383611fa6565b9150826002028217905092915050565b611fe68261179e565b67ffffffffffffffff811115611fff57611ffe61189c565b5b6120098254611e16565b612014828285611f54565b5f60209050601f831160018114612045575f8415612033578287015190505b61203d8582611fc2565b8655506120a4565b601f19841661205386611e46565b5f5b8281101561207a57848901518255600182019150602085019450602081019050612055565b868310156120975784890151612093601f891682611fa6565b8355505b6001600288020188555050505b505050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f6120e382611685565b91506120ee83611685565b9250828203905081811115612106576121056120ac565b5b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603160045260245ffd5b61216f81611d4a565b8114612179575f5ffd5b50565b5f8151905061218a81612166565b92915050565b5f602082840312156121a5576121a461167d565b5b5f6121b28482850161217c565b91505092915050565b5f6121cd6121c884611abb565b6118fa565b9050828152602081018484840111156121e9576121e8611898565b5b6121f48482856117b8565b509392505050565b5f82601f8301126122105761220f611894565b5b81516122208482602086016121bb565b91505092915050565b5f6020828403121561223e5761223d61167d565b5b5f82015167ffffffffffffffff81111561225b5761225a611681565b5b612267848285016121fc565b91505092915050565b5f819050815f5260205f209050919050565b601f8211156122c35761229481612270565b61229d84611e58565b810160208510156122ac578190505b6122c06122b885611e58565b830182611f32565b50505b505050565b6122d182611a1a565b67ffffffffffffffff8111156122ea576122e961189c565b5b6122f48254611e16565b6122ff828285612282565b5f60209050601f831160018114612330575f841561231e578287015190505b6123288582611fc2565b86555061238f565b601f19841661233e86612270565b5f5b8281101561236557848901518255600182019150602085019450602081019050612340565b86831015612382578489015161237e601f891682611fa6565b8355505b6001600288020188555050505b505050505050565b5f815190506123a58161183f565b92915050565b5f602082840312156123c0576123bf61167d565b5b5f6123cd84828501612397565b91505092915050565b5f6040820190506123e95f8301856116e3565b6123f660208301846116e3565b939250505056fea2646970667358221220020bcd1532c3cadca3240d3b696f02890e11e138212417992b98ce5dfc6a8a1764736f6c634300081f0033

Verified Source Code Full Match

Compiler: v0.8.31+commit.fd3a2265 EVM: osaka Optimization: No
vessel_relics.sol 178 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "./base64.sol";
import "./LibString.sol";
import "@openzeppelin/[email protected]/access/Ownable.sol";

interface IMachine {
    function craftToPayload(uint _tokenId) external view returns (bytes memory);
    function name() external view returns (string memory);
}

interface IVesselToken {
    function craftToPayload(uint _tokenId) external view returns (bytes memory);
    function craftToVaultStatus(uint _tokenId) external view returns (bool);
    function craftToRole(uint _tokenId) external view returns (role);
    function craftToMachine(uint _tokenId) external view returns (IMachine);
    function craftToColorMode(uint256 tokenId) external view returns (uint8);
    function craftToLockBlock(uint _tokenId) external view returns (uint);
    function craftToLocked(uint _tokenId) external view returns (bool);
    function craftToEntry(uint _tokenId) external view returns (uint);
    function craftToClaimBlock(uint _tokenId) external view returns (uint);
    function craftToClaimed(uint _tokenId) external view returns (bool);    
    function craftToMachineStatus(uint _tokenId) external view returns (bool);
    function craftToType(uint _tokenId) external view returns (string memory);
    function craftToChosenEntry(uint _tokenId) external view returns (uint);
    function craftToDelegate(uint _tokenId) external view returns (address);
    function lockStart() external view returns (uint);
    function ownerOf(uint _tokenId) external view returns (address);
    function refreshMetadata(uint _tokenId) external;
    enum role {
        undefined,
        navigator,
        steward,
        merchant
    }
}

contract THE_VESSEL_relics is Ownable {

    IVesselToken public vessel;

    struct relic {
        string kind;
        bytes[] data;
        uint entries;
        address machine;
    }

    mapping (uint => relic) public  RELICS;
    mapping(uint => uint) public    relicIdToIndex;
    mapping(uint => uint) public    relicToChosenEntry;

    uint[] public relicIds;

    error RelicAlreadyExists();
    error RelicDoesNotExist();
    error BytesTooLong();
    error NotRelic();
    error MustBeHolderOrDelegate();
    error WrongType();
    error OutOfRangeEntry();

    event RelicEntrySet(uint tokenId, uint entry);

    modifier onlyHolderOrDelegate(uint tokenId) {
        address owner = vessel.ownerOf(tokenId);
        address del = vessel.craftToDelegate(tokenId);
        if (msg.sender != owner && msg.sender != del) revert MustBeHolderOrDelegate();
        _;
    }
    
    constructor()  Ownable(msg.sender) {
        vessel =     IVesselToken    (0xECb92Cc7112b80A2234936315BbB493fb48d1463);
    }

    function addRelic(uint _tokenId, bytes[] memory _bytes, address _machine, string memory _kind) public onlyOwner {
        if (_bytes.length > _tokenId) revert BytesTooLong();
        if (_exists(_tokenId)) revert RelicAlreadyExists();

        for (uint i = 0; i < _bytes.length; i++) {
            RELICS[_tokenId].data.push(_bytes[i]);
        }

        RELICS[_tokenId].kind = _kind;
        RELICS[_tokenId].machine = _machine;
        RELICS[_tokenId].entries = _bytes.length;

        relicIdToIndex[_tokenId] = relicIds.length;
        relicIds.push(_tokenId);
    }

    function editRelic(uint _tokenId, bytes memory _bytes, uint _index) public onlyOwner {
        RELICS[_tokenId].data[_index] = _bytes;
    }

    function editKind(uint _tokenId, string memory _kind) public onlyOwner {
        RELICS[_tokenId].kind = _kind;
    }

    function removeRelic(uint _tokenId) public onlyOwner {
        if (!_exists(_tokenId)) revert RelicDoesNotExist();

        uint256 index = relicIdToIndex[_tokenId];
        uint256 lastIndex = relicIds.length - 1;

        if (index != lastIndex) {
            uint256 lastId = relicIds[lastIndex];
            relicIds[index] = lastId;
            relicIdToIndex[lastId] = index;
        }

        relicIds.pop();
        delete relicIdToIndex[_tokenId];
        delete RELICS[_tokenId]; // clears kind + data array storage
    }

    function relicToPayload(uint _tokenId) external view returns (bytes memory payload) {
        relic storage t = RELICS[_tokenId];

        if (vessel.craftToMachineStatus(_tokenId)) {
            return IMachine(t.machine).craftToPayload(_tokenId);
        }

        bytes[] storage arr = t.data;
        uint len = arr.length;
        if (len == 0) return "";

        // Capsule (non-vault, non-machine): always first entry
        if (!vessel.craftToVaultStatus(_tokenId)) {
            return arr[0];
        }

        // Vault: chosen entry is 1-based. If 0, default to latest (len).
        uint entry = relicToChosenEntry[_tokenId];
        if (entry == 0) entry = len;

        // entry must be in [1..len]
        if (entry > len) return "";

        // convert 1-based entry -> 0-based index
        return arr[entry - 1];
    }

    function vaultRelicToEntry(uint _tokenId, uint _entry) public view returns (bytes memory) {
        if (!vessel.craftToVaultStatus(_tokenId)) {revert WrongType();}
        if (!isRelic(_tokenId)) {revert NotRelic();}
        return RELICS[_tokenId].data[_entry - 1];
    }

    function setVaultEntryHolder(uint _tokenId, uint _entry) public onlyHolderOrDelegate(_tokenId) {
        if (!vessel.craftToVaultStatus(_tokenId)) revert WrongType();
        if (_entry == 0 ||_entry > RELICS[_tokenId].data.length) revert OutOfRangeEntry();
        relicToChosenEntry[_tokenId] = _entry;
        vessel.refreshMetadata(_tokenId);
        emit RelicEntrySet(_tokenId, _entry);
    }

    function setVesselContract(address _a) public onlyOwner {
        vessel = IVesselToken(_a);
    }

    function getTokenKind(uint _tokenId) external view returns (string memory) {
        return RELICS[_tokenId].kind;
    }

    function getTokenEntries(uint _tokenId) external view returns (uint) {
        return RELICS[_tokenId].entries;
    }
    function isRelic(uint _tokenId) public view returns (bool) {
        return _exists(_tokenId);
    }

    function _exists(uint256 tokenId) internal view returns (bool) {
        return RELICS[tokenId].data.length != 0;
    }

}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
LibString.sol 1194 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Library for converting numbers into strings and other string operations.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibString.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/LibString.sol)
///
/// @dev Note:
/// For performance and bytecode compactness, most of the string operations are restricted to
/// byte strings (7-bit ASCII), except where otherwise specified.
/// Usage of byte string operations on charsets with runes spanning two or more bytes
/// can lead to undefined behavior.
library LibString {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                        CUSTOM ERRORS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The length of the output is too small to contain all the hex digits.
    error HexLengthInsufficient();

    /// @dev The length of the string is more than 32 bytes.
    error TooBigForSmallString();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         CONSTANTS                          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The constant returned when the `search` is not found in the string.
    uint256 internal constant NOT_FOUND = type(uint256).max;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                     DECIMAL OPERATIONS                     */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns the base 10 decimal representation of `value`.
    function toString(uint256 value) internal pure returns (string memory str) {
        /// @solidity memory-safe-assembly
        assembly {
            // The maximum value of a uint256 contains 78 digits (1 byte per digit), but
            // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned.
            // We will need 1 word for the trailing zeros padding, 1 word for the length,
            // and 3 words for a maximum of 78 digits.
            str := add(mload(0x40), 0x80)
            // Update the free memory pointer to allocate.
            mstore(0x40, add(str, 0x20))
            // Zeroize the slot after the string.
            mstore(str, 0)

            // Cache the end of the memory to calculate the length later.
            let end := str

            let w := not(0) // Tsk.
            // We write the string from rightmost digit to leftmost digit.
            // The following is essentially a do-while loop that also handles the zero case.
            for { let temp := value } 1 {} {
                str := add(str, w) // `sub(str, 1)`.
                // Write the character to the pointer.
                // The ASCII index of the '0' character is 48.
                mstore8(str, add(48, mod(temp, 10)))
                // Keep dividing `temp` until zero.
                temp := div(temp, 10)
                if iszero(temp) { break }
            }

            let length := sub(end, str)
            // Move the pointer 32 bytes leftwards to make room for the length.
            str := sub(str, 0x20)
            // Store the length.
            mstore(str, length)
        }
    }

    /// @dev Returns the base 10 decimal representation of `value`.
    function toString(int256 value) internal pure returns (string memory str) {
        if (value >= 0) {
            return toString(uint256(value));
        }
        unchecked {
            str = toString(~uint256(value) + 1);
        }
        /// @solidity memory-safe-assembly
        assembly {
            // We still have some spare memory space on the left,
            // as we have allocated 3 words (96 bytes) for up to 78 digits.
            let length := mload(str) // Load the string length.
            mstore(str, 0x2d) // Store the '-' character.
            str := sub(str, 1) // Move back the string pointer by a byte.
            mstore(str, add(length, 1)) // Update the string length.
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   HEXADECIMAL OPERATIONS                   */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns the hexadecimal representation of `value`,
    /// left-padded to an input length of `length` bytes.
    /// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte,
    /// giving a total length of `length * 2 + 2` bytes.
    /// Reverts if `length` is too small for the output to contain all the digits.
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory str) {
        str = toHexStringNoPrefix(value, length);
        /// @solidity memory-safe-assembly
        assembly {
            let strLength := add(mload(str), 2) // Compute the length.
            mstore(str, 0x3078) // Write the "0x" prefix.
            str := sub(str, 2) // Move the pointer.
            mstore(str, strLength) // Write the length.
        }
    }

    /// @dev Returns the hexadecimal representation of `value`,
    /// left-padded to an input length of `length` bytes.
    /// The output is prefixed with "0x" encoded using 2 hexadecimal digits per byte,
    /// giving a total length of `length * 2` bytes.
    /// Reverts if `length` is too small for the output to contain all the digits.
    function toHexStringNoPrefix(uint256 value, uint256 length)
        internal
        pure
        returns (string memory str)
    {
        /// @solidity memory-safe-assembly
        assembly {
            // We need 0x20 bytes for the trailing zeros padding, `length * 2` bytes
            // for the digits, 0x02 bytes for the prefix, and 0x20 bytes for the length.
            // We add 0x20 to the total and round down to a multiple of 0x20.
            // (0x20 + 0x20 + 0x02 + 0x20) = 0x62.
            str := add(mload(0x40), and(add(shl(1, length), 0x42), not(0x1f)))
            // Allocate the memory.
            mstore(0x40, add(str, 0x20))
            // Zeroize the slot after the string.
            mstore(str, 0)

            // Cache the end to calculate the length later.
            let end := str
            // Store "0123456789abcdef" in scratch space.
            mstore(0x0f, 0x30313233343536373839616263646566)

            let start := sub(str, add(length, length))
            let w := not(1) // Tsk.
            let temp := value
            // We write the string from rightmost digit to leftmost digit.
            // The following is essentially a do-while loop that also handles the zero case.
            for {} 1 {} {
                str := add(str, w) // `sub(str, 2)`.
                mstore8(add(str, 1), mload(and(temp, 15)))
                mstore8(str, mload(and(shr(4, temp), 15)))
                temp := shr(8, temp)
                if iszero(xor(str, start)) { break }
            }

            if temp {
                mstore(0x00, 0x2194895a) // `HexLengthInsufficient()`.
                revert(0x1c, 0x04)
            }

            // Compute the string's length.
            let strLength := sub(end, str)
            // Move the pointer and write the length.
            str := sub(str, 0x20)
            mstore(str, strLength)
        }
    }

    /// @dev Returns the hexadecimal representation of `value`.
    /// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte.
    /// As address are 20 bytes long, the output will left-padded to have
    /// a length of `20 * 2 + 2` bytes.
    function toHexString(uint256 value) internal pure returns (string memory str) {
        str = toHexStringNoPrefix(value);
        /// @solidity memory-safe-assembly
        assembly {
            let strLength := add(mload(str), 2) // Compute the length.
            mstore(str, 0x3078) // Write the "0x" prefix.
            str := sub(str, 2) // Move the pointer.
            mstore(str, strLength) // Write the length.
        }
    }

    /// @dev Returns the hexadecimal representation of `value`.
    /// The output is prefixed with "0x".
    /// The output excludes leading "0" from the `toHexString` output.
    /// `0x00: "0x0", 0x01: "0x1", 0x12: "0x12", 0x123: "0x123"`.
    function toMinimalHexString(uint256 value) internal pure returns (string memory str) {
        str = toHexStringNoPrefix(value);
        /// @solidity memory-safe-assembly
        assembly {
            let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present.
            let strLength := add(mload(str), 2) // Compute the length.
            mstore(add(str, o), 0x3078) // Write the "0x" prefix, accounting for leading zero.
            str := sub(add(str, o), 2) // Move the pointer, accounting for leading zero.
            mstore(str, sub(strLength, o)) // Write the length, accounting for leading zero.
        }
    }

    /// @dev Returns the hexadecimal representation of `value`.
    /// The output excludes leading "0" from the `toHexStringNoPrefix` output.
    /// `0x00: "0", 0x01: "1", 0x12: "12", 0x123: "123"`.
    function toMinimalHexStringNoPrefix(uint256 value) internal pure returns (string memory str) {
        str = toHexStringNoPrefix(value);
        /// @solidity memory-safe-assembly
        assembly {
            let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present.
            let strLength := mload(str) // Get the length.
            str := add(str, o) // Move the pointer, accounting for leading zero.
            mstore(str, sub(strLength, o)) // Write the length, accounting for leading zero.
        }
    }

    /// @dev Returns the hexadecimal representation of `value`.
    /// The output is encoded using 2 hexadecimal digits per byte.
    /// As address are 20 bytes long, the output will left-padded to have
    /// a length of `20 * 2` bytes.
    function toHexStringNoPrefix(uint256 value) internal pure returns (string memory str) {
        /// @solidity memory-safe-assembly
        assembly {
            // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length,
            // 0x02 bytes for the prefix, and 0x40 bytes for the digits.
            // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x40) is 0xa0.
            str := add(mload(0x40), 0x80)
            // Allocate the memory.
            mstore(0x40, add(str, 0x20))
            // Zeroize the slot after the string.
            mstore(str, 0)

            // Cache the end to calculate the length later.
            let end := str
            // Store "0123456789abcdef" in scratch space.
            mstore(0x0f, 0x30313233343536373839616263646566)

            let w := not(1) // Tsk.
            // We write the string from rightmost digit to leftmost digit.
            // The following is essentially a do-while loop that also handles the zero case.
            for { let temp := value } 1 {} {
                str := add(str, w) // `sub(str, 2)`.
                mstore8(add(str, 1), mload(and(temp, 15)))
                mstore8(str, mload(and(shr(4, temp), 15)))
                temp := shr(8, temp)
                if iszero(temp) { break }
            }

            // Compute the string's length.
            let strLength := sub(end, str)
            // Move the pointer and write the length.
            str := sub(str, 0x20)
            mstore(str, strLength)
        }
    }

    /// @dev Returns the hexadecimal representation of `value`.
    /// The output is prefixed with "0x", encoded using 2 hexadecimal digits per byte,
    /// and the alphabets are capitalized conditionally according to
    /// https://eips.ethereum.org/EIPS/eip-55
    function toHexStringChecksummed(address value) internal pure returns (string memory str) {
        str = toHexString(value);
        /// @solidity memory-safe-assembly
        assembly {
            let mask := shl(6, div(not(0), 255)) // `0b010000000100000000 ...`
            let o := add(str, 0x22)
            let hashed := and(keccak256(o, 40), mul(34, mask)) // `0b10001000 ... `
            let t := shl(240, 136) // `0b10001000 << 240`
            for { let i := 0 } 1 {} {
                mstore(add(i, i), mul(t, byte(i, hashed)))
                i := add(i, 1)
                if eq(i, 20) { break }
            }
            mstore(o, xor(mload(o), shr(1, and(mload(0x00), and(mload(o), mask)))))
            o := add(o, 0x20)
            mstore(o, xor(mload(o), shr(1, and(mload(0x20), and(mload(o), mask)))))
        }
    }

    /// @dev Returns the hexadecimal representation of `value`.
    /// The output is prefixed with "0x" and encoded using 2 hexadecimal digits per byte.
    function toHexString(address value) internal pure returns (string memory str) {
        str = toHexStringNoPrefix(value);
        /// @solidity memory-safe-assembly
        assembly {
            let strLength := add(mload(str), 2) // Compute the length.
            mstore(str, 0x3078) // Write the "0x" prefix.
            str := sub(str, 2) // Move the pointer.
            mstore(str, strLength) // Write the length.
        }
    }

    /// @dev Returns the hexadecimal representation of `value`.
    /// The output is encoded using 2 hexadecimal digits per byte.
    function toHexStringNoPrefix(address value) internal pure returns (string memory str) {
        /// @solidity memory-safe-assembly
        assembly {
            str := mload(0x40)

            // Allocate the memory.
            // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length,
            // 0x02 bytes for the prefix, and 0x28 bytes for the digits.
            // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x28) is 0x80.
            mstore(0x40, add(str, 0x80))

            // Store "0123456789abcdef" in scratch space.
            mstore(0x0f, 0x30313233343536373839616263646566)

            str := add(str, 2)
            mstore(str, 40)

            let o := add(str, 0x20)
            mstore(add(o, 40), 0)

            value := shl(96, value)

            // We write the string from rightmost digit to leftmost digit.
            // The following is essentially a do-while loop that also handles the zero case.
            for { let i := 0 } 1 {} {
                let p := add(o, add(i, i))
                let temp := byte(i, value)
                mstore8(add(p, 1), mload(and(temp, 15)))
                mstore8(p, mload(shr(4, temp)))
                i := add(i, 1)
                if eq(i, 20) { break }
            }
        }
    }

    /// @dev Returns the hex encoded string from the raw bytes.
    /// The output is encoded using 2 hexadecimal digits per byte.
    function toHexString(bytes memory raw) internal pure returns (string memory str) {
        str = toHexStringNoPrefix(raw);
        /// @solidity memory-safe-assembly
        assembly {
            let strLength := add(mload(str), 2) // Compute the length.
            mstore(str, 0x3078) // Write the "0x" prefix.
            str := sub(str, 2) // Move the pointer.
            mstore(str, strLength) // Write the length.
        }
    }

    /// @dev Returns the hex encoded string from the raw bytes.
    /// The output is encoded using 2 hexadecimal digits per byte.
    function toHexStringNoPrefix(bytes memory raw) internal pure returns (string memory str) {
        /// @solidity memory-safe-assembly
        assembly {
            let length := mload(raw)
            str := add(mload(0x40), 2) // Skip 2 bytes for the optional prefix.
            mstore(str, add(length, length)) // Store the length of the output.

            // Store "0123456789abcdef" in scratch space.
            mstore(0x0f, 0x30313233343536373839616263646566)

            let o := add(str, 0x20)
            let end := add(raw, length)

            for {} iszero(eq(raw, end)) {} {
                raw := add(raw, 1)
                mstore8(add(o, 1), mload(and(mload(raw), 15)))
                mstore8(o, mload(and(shr(4, mload(raw)), 15)))
                o := add(o, 2)
            }
            mstore(o, 0) // Zeroize the slot after the string.
            mstore(0x40, add(o, 0x20)) // Allocate the memory.
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   RUNE STRING OPERATIONS                   */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns the number of UTF characters in the string.
    function runeCount(string memory s) internal pure returns (uint256 result) {
        /// @solidity memory-safe-assembly
        assembly {
            if mload(s) {
                mstore(0x00, div(not(0), 255))
                mstore(0x20, 0x0202020202020202020202020202020202020202020202020303030304040506)
                let o := add(s, 0x20)
                let end := add(o, mload(s))
                for { result := 1 } 1 { result := add(result, 1) } {
                    o := add(o, byte(0, mload(shr(250, mload(o)))))
                    if iszero(lt(o, end)) { break }
                }
            }
        }
    }

    /// @dev Returns if this string is a 7-bit ASCII string.
    /// (i.e. all characters codes are in [0..127])
    function is7BitASCII(string memory s) internal pure returns (bool result) {
        /// @solidity memory-safe-assembly
        assembly {
            let mask := shl(7, div(not(0), 255))
            result := 1
            let n := mload(s)
            if n {
                let o := add(s, 0x20)
                let end := add(o, n)
                let last := mload(end)
                mstore(end, 0)
                for {} 1 {} {
                    if and(mask, mload(o)) {
                        result := 0
                        break
                    }
                    o := add(o, 0x20)
                    if iszero(lt(o, end)) { break }
                }
                mstore(end, last)
            }
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   BYTE STRING OPERATIONS                   */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    // For performance and bytecode compactness, byte string operations are restricted
    // to 7-bit ASCII strings. All offsets are byte offsets, not UTF character offsets.
    // Usage of byte string operations on charsets with runes spanning two or more bytes
    // can lead to undefined behavior.

    /// @dev Returns `subject` all occurrences of `search` replaced with `replacement`.
    function replace(string memory subject, string memory search, string memory replacement)
        internal
        pure
        returns (string memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let subjectLength := mload(subject)
            let searchLength := mload(search)
            let replacementLength := mload(replacement)

            subject := add(subject, 0x20)
            search := add(search, 0x20)
            replacement := add(replacement, 0x20)
            result := add(mload(0x40), 0x20)

            let subjectEnd := add(subject, subjectLength)
            if iszero(gt(searchLength, subjectLength)) {
                let subjectSearchEnd := add(sub(subjectEnd, searchLength), 1)
                let h := 0
                if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) }
                let m := shl(3, sub(0x20, and(searchLength, 0x1f)))
                let s := mload(search)
                for {} 1 {} {
                    let t := mload(subject)
                    // Whether the first `searchLength % 32` bytes of
                    // `subject` and `search` matches.
                    if iszero(shr(m, xor(t, s))) {
                        if h {
                            if iszero(eq(keccak256(subject, searchLength), h)) {
                                mstore(result, t)
                                result := add(result, 1)
                                subject := add(subject, 1)
                                if iszero(lt(subject, subjectSearchEnd)) { break }
                                continue
                            }
                        }
                        // Copy the `replacement` one word at a time.
                        for { let o := 0 } 1 {} {
                            mstore(add(result, o), mload(add(replacement, o)))
                            o := add(o, 0x20)
                            if iszero(lt(o, replacementLength)) { break }
                        }
                        result := add(result, replacementLength)
                        subject := add(subject, searchLength)
                        if searchLength {
                            if iszero(lt(subject, subjectSearchEnd)) { break }
                            continue
                        }
                    }
                    mstore(result, t)
                    result := add(result, 1)
                    subject := add(subject, 1)
                    if iszero(lt(subject, subjectSearchEnd)) { break }
                }
            }

            let resultRemainder := result
            result := add(mload(0x40), 0x20)
            let k := add(sub(resultRemainder, result), sub(subjectEnd, subject))
            // Copy the rest of the string one word at a time.
            for {} lt(subject, subjectEnd) {} {
                mstore(resultRemainder, mload(subject))
                resultRemainder := add(resultRemainder, 0x20)
                subject := add(subject, 0x20)
            }
            result := sub(result, 0x20)
            let last := add(add(result, 0x20), k) // Zeroize the slot after the string.
            mstore(last, 0)
            mstore(0x40, add(last, 0x20)) // Allocate the memory.
            mstore(result, k) // Store the length.
        }
    }

    /// @dev Returns the byte index of the first location of `search` in `subject`,
    /// searching from left to right, starting from `from`.
    /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.
    function indexOf(string memory subject, string memory search, uint256 from)
        internal
        pure
        returns (uint256 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            for { let subjectLength := mload(subject) } 1 {} {
                if iszero(mload(search)) {
                    if iszero(gt(from, subjectLength)) {
                        result := from
                        break
                    }
                    result := subjectLength
                    break
                }
                let searchLength := mload(search)
                let subjectStart := add(subject, 0x20)

                result := not(0) // Initialize to `NOT_FOUND`.

                subject := add(subjectStart, from)
                let end := add(sub(add(subjectStart, subjectLength), searchLength), 1)

                let m := shl(3, sub(0x20, and(searchLength, 0x1f)))
                let s := mload(add(search, 0x20))

                if iszero(and(lt(subject, end), lt(from, subjectLength))) { break }

                if iszero(lt(searchLength, 0x20)) {
                    for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} {
                        if iszero(shr(m, xor(mload(subject), s))) {
                            if eq(keccak256(subject, searchLength), h) {
                                result := sub(subject, subjectStart)
                                break
                            }
                        }
                        subject := add(subject, 1)
                        if iszero(lt(subject, end)) { break }
                    }
                    break
                }
                for {} 1 {} {
                    if iszero(shr(m, xor(mload(subject), s))) {
                        result := sub(subject, subjectStart)
                        break
                    }
                    subject := add(subject, 1)
                    if iszero(lt(subject, end)) { break }
                }
                break
            }
        }
    }

    /// @dev Returns the byte index of the first location of `search` in `subject`,
    /// searching from left to right.
    /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.
    function indexOf(string memory subject, string memory search)
        internal
        pure
        returns (uint256 result)
    {
        result = indexOf(subject, search, 0);
    }

    /// @dev Returns the byte index of the first location of `search` in `subject`,
    /// searching from right to left, starting from `from`.
    /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.
    function lastIndexOf(string memory subject, string memory search, uint256 from)
        internal
        pure
        returns (uint256 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            for {} 1 {} {
                result := not(0) // Initialize to `NOT_FOUND`.
                let searchLength := mload(search)
                if gt(searchLength, mload(subject)) { break }
                let w := result

                let fromMax := sub(mload(subject), searchLength)
                if iszero(gt(fromMax, from)) { from := fromMax }

                let end := add(add(subject, 0x20), w)
                subject := add(add(subject, 0x20), from)
                if iszero(gt(subject, end)) { break }
                // As this function is not too often used,
                // we shall simply use keccak256 for smaller bytecode size.
                for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} {
                    if eq(keccak256(subject, searchLength), h) {
                        result := sub(subject, add(end, 1))
                        break
                    }
                    subject := add(subject, w) // `sub(subject, 1)`.
                    if iszero(gt(subject, end)) { break }
                }
                break
            }
        }
    }

    /// @dev Returns the byte index of the first location of `search` in `subject`,
    /// searching from right to left.
    /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.
    function lastIndexOf(string memory subject, string memory search)
        internal
        pure
        returns (uint256 result)
    {
        result = lastIndexOf(subject, search, uint256(int256(-1)));
    }

    /// @dev Returns true if `search` is found in `subject`, false otherwise.
    function contains(string memory subject, string memory search) internal pure returns (bool) {
        return indexOf(subject, search) != NOT_FOUND;
    }

    /// @dev Returns whether `subject` starts with `search`.
    function startsWith(string memory subject, string memory search)
        internal
        pure
        returns (bool result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let searchLength := mload(search)
            // Just using keccak256 directly is actually cheaper.
            // forgefmt: disable-next-item
            result := and(
                iszero(gt(searchLength, mload(subject))),
                eq(
                    keccak256(add(subject, 0x20), searchLength),
                    keccak256(add(search, 0x20), searchLength)
                )
            )
        }
    }

    /// @dev Returns whether `subject` ends with `search`.
    function endsWith(string memory subject, string memory search)
        internal
        pure
        returns (bool result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let searchLength := mload(search)
            let subjectLength := mload(subject)
            // Whether `search` is not longer than `subject`.
            let withinRange := iszero(gt(searchLength, subjectLength))
            // Just using keccak256 directly is actually cheaper.
            // forgefmt: disable-next-item
            result := and(
                withinRange,
                eq(
                    keccak256(
                        // `subject + 0x20 + max(subjectLength - searchLength, 0)`.
                        add(add(subject, 0x20), mul(withinRange, sub(subjectLength, searchLength))),
                        searchLength
                    ),
                    keccak256(add(search, 0x20), searchLength)
                )
            )
        }
    }

    /// @dev Returns `subject` repeated `times`.
    function repeat(string memory subject, uint256 times)
        internal
        pure
        returns (string memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let subjectLength := mload(subject)
            if iszero(or(iszero(times), iszero(subjectLength))) {
                subject := add(subject, 0x20)
                result := mload(0x40)
                let output := add(result, 0x20)
                for {} 1 {} {
                    // Copy the `subject` one word at a time.
                    for { let o := 0 } 1 {} {
                        mstore(add(output, o), mload(add(subject, o)))
                        o := add(o, 0x20)
                        if iszero(lt(o, subjectLength)) { break }
                    }
                    output := add(output, subjectLength)
                    times := sub(times, 1)
                    if iszero(times) { break }
                }
                mstore(output, 0) // Zeroize the slot after the string.
                let resultLength := sub(output, add(result, 0x20))
                mstore(result, resultLength) // Store the length.
                // Allocate the memory.
                mstore(0x40, add(result, add(resultLength, 0x20)))
            }
        }
    }

    /// @dev Returns a copy of `subject` sliced from `start` to `end` (exclusive).
    /// `start` and `end` are byte offsets.
    function slice(string memory subject, uint256 start, uint256 end)
        internal
        pure
        returns (string memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let subjectLength := mload(subject)
            if iszero(gt(subjectLength, end)) { end := subjectLength }
            if iszero(gt(subjectLength, start)) { start := subjectLength }
            if lt(start, end) {
                result := mload(0x40)
                let resultLength := sub(end, start)
                mstore(result, resultLength)
                subject := add(subject, start)
                let w := not(0x1f)
                // Copy the `subject` one word at a time, backwards.
                for { let o := and(add(resultLength, 0x1f), w) } 1 {} {
                    mstore(add(result, o), mload(add(subject, o)))
                    o := add(o, w) // `sub(o, 0x20)`.
                    if iszero(o) { break }
                }
                // Zeroize the slot after the string.
                mstore(add(add(result, 0x20), resultLength), 0)
                // Allocate memory for the length and the bytes,
                // rounded up to a multiple of 32.
                mstore(0x40, add(result, and(add(resultLength, 0x3f), w)))
            }
        }
    }

    /// @dev Returns a copy of `subject` sliced from `start` to the end of the string.
    /// `start` is a byte offset.
    function slice(string memory subject, uint256 start)
        internal
        pure
        returns (string memory result)
    {
        result = slice(subject, start, uint256(int256(-1)));
    }

    /// @dev Returns all the indices of `search` in `subject`.
    /// The indices are byte offsets.
    function indicesOf(string memory subject, string memory search)
        internal
        pure
        returns (uint256[] memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let subjectLength := mload(subject)
            let searchLength := mload(search)

            if iszero(gt(searchLength, subjectLength)) {
                subject := add(subject, 0x20)
                search := add(search, 0x20)
                result := add(mload(0x40), 0x20)

                let subjectStart := subject
                let subjectSearchEnd := add(sub(add(subject, subjectLength), searchLength), 1)
                let h := 0
                if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) }
                let m := shl(3, sub(0x20, and(searchLength, 0x1f)))
                let s := mload(search)
                for {} 1 {} {
                    let t := mload(subject)
                    // Whether the first `searchLength % 32` bytes of
                    // `subject` and `search` matches.
                    if iszero(shr(m, xor(t, s))) {
                        if h {
                            if iszero(eq(keccak256(subject, searchLength), h)) {
                                subject := add(subject, 1)
                                if iszero(lt(subject, subjectSearchEnd)) { break }
                                continue
                            }
                        }
                        // Append to `result`.
                        mstore(result, sub(subject, subjectStart))
                        result := add(result, 0x20)
                        // Advance `subject` by `searchLength`.
                        subject := add(subject, searchLength)
                        if searchLength {
                            if iszero(lt(subject, subjectSearchEnd)) { break }
                            continue
                        }
                    }
                    subject := add(subject, 1)
                    if iszero(lt(subject, subjectSearchEnd)) { break }
                }
                let resultEnd := result
                // Assign `result` to the free memory pointer.
                result := mload(0x40)
                // Store the length of `result`.
                mstore(result, shr(5, sub(resultEnd, add(result, 0x20))))
                // Allocate memory for result.
                // We allocate one more word, so this array can be recycled for {split}.
                mstore(0x40, add(resultEnd, 0x20))
            }
        }
    }

    /// @dev Returns a arrays of strings based on the `delimiter` inside of the `subject` string.
    function split(string memory subject, string memory delimiter)
        internal
        pure
        returns (string[] memory result)
    {
        uint256[] memory indices = indicesOf(subject, delimiter);
        /// @solidity memory-safe-assembly
        assembly {
            let w := not(0x1f)
            let indexPtr := add(indices, 0x20)
            let indicesEnd := add(indexPtr, shl(5, add(mload(indices), 1)))
            mstore(add(indicesEnd, w), mload(subject))
            mstore(indices, add(mload(indices), 1))
            let prevIndex := 0
            for {} 1 {} {
                let index := mload(indexPtr)
                mstore(indexPtr, 0x60)
                if iszero(eq(index, prevIndex)) {
                    let element := mload(0x40)
                    let elementLength := sub(index, prevIndex)
                    mstore(element, elementLength)
                    // Copy the `subject` one word at a time, backwards.
                    for { let o := and(add(elementLength, 0x1f), w) } 1 {} {
                        mstore(add(element, o), mload(add(add(subject, prevIndex), o)))
                        o := add(o, w) // `sub(o, 0x20)`.
                        if iszero(o) { break }
                    }
                    // Zeroize the slot after the string.
                    mstore(add(add(element, 0x20), elementLength), 0)
                    // Allocate memory for the length and the bytes,
                    // rounded up to a multiple of 32.
                    mstore(0x40, add(element, and(add(elementLength, 0x3f), w)))
                    // Store the `element` into the array.
                    mstore(indexPtr, element)
                }
                prevIndex := add(index, mload(delimiter))
                indexPtr := add(indexPtr, 0x20)
                if iszero(lt(indexPtr, indicesEnd)) { break }
            }
            result := indices
            if iszero(mload(delimiter)) {
                result := add(indices, 0x20)
                mstore(result, sub(mload(indices), 2))
            }
        }
    }

    /// @dev Returns a concatenated string of `a` and `b`.
    /// Cheaper than `string.concat()` and does not de-align the free memory pointer.
    function concat(string memory a, string memory b)
        internal
        pure
        returns (string memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let w := not(0x1f)
            result := mload(0x40)
            let aLength := mload(a)
            // Copy `a` one word at a time, backwards.
            for { let o := and(add(aLength, 0x20), w) } 1 {} {
                mstore(add(result, o), mload(add(a, o)))
                o := add(o, w) // `sub(o, 0x20)`.
                if iszero(o) { break }
            }
            let bLength := mload(b)
            let output := add(result, aLength)
            // Copy `b` one word at a time, backwards.
            for { let o := and(add(bLength, 0x20), w) } 1 {} {
                mstore(add(output, o), mload(add(b, o)))
                o := add(o, w) // `sub(o, 0x20)`.
                if iszero(o) { break }
            }
            let totalLength := add(aLength, bLength)
            let last := add(add(result, 0x20), totalLength)
            // Zeroize the slot after the string.
            mstore(last, 0)
            // Stores the length.
            mstore(result, totalLength)
            // Allocate memory for the length and the bytes,
            // rounded up to a multiple of 32.
            mstore(0x40, and(add(last, 0x1f), w))
        }
    }

    /// @dev Returns a copy of the string in either lowercase or UPPERCASE.
    /// WARNING! This function is only compatible with 7-bit ASCII strings.
    function toCase(string memory subject, bool toUpper)
        internal
        pure
        returns (string memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let length := mload(subject)
            if length {
                result := add(mload(0x40), 0x20)
                subject := add(subject, 1)
                let flags := shl(add(70, shl(5, toUpper)), 0x3ffffff)
                let w := not(0)
                for { let o := length } 1 {} {
                    o := add(o, w)
                    let b := and(0xff, mload(add(subject, o)))
                    mstore8(add(result, o), xor(b, and(shr(b, flags), 0x20)))
                    if iszero(o) { break }
                }
                result := mload(0x40)
                mstore(result, length) // Store the length.
                let last := add(add(result, 0x20), length)
                mstore(last, 0) // Zeroize the slot after the string.
                mstore(0x40, add(last, 0x20)) // Allocate the memory.
            }
        }
    }

    /// @dev Returns a string from a small bytes32 string.
    /// `s` must be null-terminated, or behavior will be undefined.
    function fromSmallString(bytes32 s) internal pure returns (string memory result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := mload(0x40)
            let n := 0
            for {} byte(n, s) { n := add(n, 1) } {} // Scan for '\0'.
            mstore(result, n)
            let o := add(result, 0x20)
            mstore(o, s)
            mstore(add(o, n), 0)
            mstore(0x40, add(result, 0x40))
        }
    }

    /// @dev Returns the small string, with all bytes after the first null byte zeroized.
    function normalizeSmallString(bytes32 s) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            for {} byte(result, s) { result := add(result, 1) } {} // Scan for '\0'.
            mstore(0x00, s)
            mstore(result, 0x00)
            result := mload(0x00)
        }
    }

    /// @dev Returns the string as a normalized null-terminated small string.
    function toSmallString(string memory s) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := mload(s)
            if iszero(lt(result, 33)) {
                mstore(0x00, 0xec92f9a3) // `TooBigForSmallString()`.
                revert(0x1c, 0x04)
            }
            result := shl(shl(3, sub(32, result)), mload(add(s, result)))
        }
    }

    /// @dev Returns a lowercased copy of the string.
    /// WARNING! This function is only compatible with 7-bit ASCII strings.
    function lower(string memory subject) internal pure returns (string memory result) {
        result = toCase(subject, false);
    }

    /// @dev Returns an UPPERCASED copy of the string.
    /// WARNING! This function is only compatible with 7-bit ASCII strings.
    function upper(string memory subject) internal pure returns (string memory result) {
        result = toCase(subject, true);
    }

    /// @dev Escapes the string to be used within HTML tags.
    function escapeHTML(string memory s) internal pure returns (string memory result) {
        /// @solidity memory-safe-assembly
        assembly {
            let end := add(s, mload(s))
            result := add(mload(0x40), 0x20)
            // Store the bytes of the packed offsets and strides into the scratch space.
            // `packed = (stride << 5) | offset`. Max offset is 20. Max stride is 6.
            mstore(0x1f, 0x900094)
            mstore(0x08, 0xc0000000a6ab)
            // Store "&quot;&amp;&#39;&lt;&gt;" into the scratch space.
            mstore(0x00, shl(64, 0x2671756f743b26616d703b262333393b266c743b2667743b))
            for {} iszero(eq(s, end)) {} {
                s := add(s, 1)
                let c := and(mload(s), 0xff)
                // Not in `["\"","'","&","<",">"]`.
                if iszero(and(shl(c, 1), 0x500000c400000000)) {
                    mstore8(result, c)
                    result := add(result, 1)
                    continue
                }
                let t := shr(248, mload(c))
                mstore(result, mload(and(t, 0x1f)))
                result := add(result, shr(5, t))
            }
            let last := result
            mstore(last, 0) // Zeroize the slot after the string.
            result := mload(0x40)
            mstore(result, sub(last, add(result, 0x20))) // Store the length.
            mstore(0x40, add(last, 0x20)) // Allocate the memory.
        }
    }

    /// @dev Escapes the string to be used within double-quotes in a JSON.
    /// If `addDoubleQuotes` is true, the result will be enclosed in double-quotes.
    function escapeJSON(string memory s, bool addDoubleQuotes)
        internal
        pure
        returns (string memory result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let end := add(s, mload(s))
            result := add(mload(0x40), 0x20)
            if addDoubleQuotes {
                mstore8(result, 34)
                result := add(1, result)
            }
            // Store "\\u0000" in scratch space.
            // Store "0123456789abcdef" in scratch space.
            // Also, store `{0x08:"b", 0x09:"t", 0x0a:"n", 0x0c:"f", 0x0d:"r"}`.
            // into the scratch space.
            mstore(0x15, 0x5c75303030303031323334353637383961626364656662746e006672)
            // Bitmask for detecting `["\"","\\"]`.
            let e := or(shl(0x22, 1), shl(0x5c, 1))
            for {} iszero(eq(s, end)) {} {
                s := add(s, 1)
                let c := and(mload(s), 0xff)
                if iszero(lt(c, 0x20)) {
                    if iszero(and(shl(c, 1), e)) {
                        // Not in `["\"","\\"]`.
                        mstore8(result, c)
                        result := add(result, 1)
                        continue
                    }
                    mstore8(result, 0x5c) // "\\".
                    mstore8(add(result, 1), c)
                    result := add(result, 2)
                    continue
                }
                if iszero(and(shl(c, 1), 0x3700)) {
                    // Not in `["\b","\t","\n","\f","\d"]`.
                    mstore8(0x1d, mload(shr(4, c))) // Hex value.
                    mstore8(0x1e, mload(and(c, 15))) // Hex value.
                    mstore(result, mload(0x19)) // "\\u00XX".
                    result := add(result, 6)
                    continue
                }
                mstore8(result, 0x5c) // "\\".
                mstore8(add(result, 1), mload(add(c, 8)))
                result := add(result, 2)
            }
            if addDoubleQuotes {
                mstore8(result, 34)
                result := add(1, result)
            }
            let last := result
            mstore(last, 0) // Zeroize the slot after the string.
            result := mload(0x40)
            mstore(result, sub(last, add(result, 0x20))) // Store the length.
            mstore(0x40, add(last, 0x20)) // Allocate the memory.
        }
    }

    /// @dev Escapes the string to be used within double-quotes in a JSON.
    function escapeJSON(string memory s) internal pure returns (string memory result) {
        result = escapeJSON(s, false);
    }

    /// @dev Returns whether `a` equals `b`.
    function eq(string memory a, string memory b) internal pure returns (bool result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := eq(keccak256(add(a, 0x20), mload(a)), keccak256(add(b, 0x20), mload(b)))
        }
    }

    /// @dev Returns whether `a` equals `b`, where `b` is a null-terminated small string.
    function eqs(string memory a, bytes32 b) internal pure returns (bool result) {
        /// @solidity memory-safe-assembly
        assembly {
            // These should be evaluated on compile time, as far as possible.
            let m := not(shl(7, div(not(iszero(b)), 255))) // `0x7f7f ...`.
            let x := not(or(m, or(b, add(m, and(b, m)))))
            let r := shl(7, iszero(iszero(shr(128, x))))
            r := or(r, shl(6, iszero(iszero(shr(64, shr(r, x))))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(r, shl(3, lt(0xff, shr(r, x))))
            // forgefmt: disable-next-item
            result := gt(eq(mload(a), add(iszero(x), xor(31, shr(3, r)))),
                xor(shr(add(8, r), b), shr(add(8, r), mload(add(a, 0x20)))))
        }
    }

    /// @dev Packs a single string with its length into a single word.
    /// Returns `bytes32(0)` if the length is zero or greater than 31.
    function packOne(string memory a) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            // We don't need to zero right pad the string,
            // since this is our own custom non-standard packing scheme.
            result :=
                mul(
                    // Load the length and the bytes.
                    mload(add(a, 0x1f)),
                    // `length != 0 && length < 32`. Abuses underflow.
                    // Assumes that the length is valid and within the block gas limit.
                    lt(sub(mload(a), 1), 0x1f)
                )
        }
    }

    /// @dev Unpacks a string packed using {packOne}.
    /// Returns the empty string if `packed` is `bytes32(0)`.
    /// If `packed` is not an output of {packOne}, the output behavior is undefined.
    function unpackOne(bytes32 packed) internal pure returns (string memory result) {
        /// @solidity memory-safe-assembly
        assembly {
            // Grab the free memory pointer.
            result := mload(0x40)
            // Allocate 2 words (1 for the length, 1 for the bytes).
            mstore(0x40, add(result, 0x40))
            // Zeroize the length slot.
            mstore(result, 0)
            // Store the length and bytes.
            mstore(add(result, 0x1f), packed)
            // Right pad with zeroes.
            mstore(add(add(result, 0x20), mload(result)), 0)
        }
    }

    /// @dev Packs two strings with their lengths into a single word.
    /// Returns `bytes32(0)` if combined length is zero or greater than 30.
    function packTwo(string memory a, string memory b) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let aLength := mload(a)
            // We don't need to zero right pad the strings,
            // since this is our own custom non-standard packing scheme.
            result :=
                mul(
                    // Load the length and the bytes of `a` and `b`.
                    or(
                        shl(shl(3, sub(0x1f, aLength)), mload(add(a, aLength))),
                        mload(sub(add(b, 0x1e), aLength))
                    ),
                    // `totalLength != 0 && totalLength < 31`. Abuses underflow.
                    // Assumes that...

// [truncated — 51990 bytes total]
base64.sol 120 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.2) (utils/Base64.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides a set of functions to operate with Base64 strings.
 */
library Base64 {
    /**
     * @dev Base64 Encoding/Decoding Table
     * See sections 4 and 5 of https://datatracker.ietf.org/doc/html/rfc4648
     */
    string internal constant _TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    string internal constant _TABLE_URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";

    /**
     * @dev Converts a `bytes` to its Bytes64 `string` representation.
     */
    function encode(bytes memory data) internal pure returns (string memory) {
        return _encode(data, _TABLE, true);
    }

    /**
     * @dev Converts a `bytes` to its Bytes64Url `string` representation.
     */
    function encodeURL(bytes memory data) internal pure returns (string memory) {
        return _encode(data, _TABLE_URL, false);
    }

    /**
     * @dev Internal table-agnostic conversion
     */
    function _encode(bytes memory data, string memory table, bool withPadding) private pure returns (string memory) {
        /**
         * Inspired by Brecht Devos (Brechtpd) implementation - MIT licence
         * https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol
         */
        if (data.length == 0) return "";

        // If padding is enabled, the final length should be `bytes` data length divided by 3 rounded up and then
        // multiplied by 4 so that it leaves room for padding the last chunk
        // - `data.length + 2`  -> Round up
        // - `/ 3`              -> Number of 3-bytes chunks
        // - `4 *`              -> 4 characters for each chunk
        // If padding is disabled, the final length should be `bytes` data length multiplied by 4/3 rounded up as
        // opposed to when padding is required to fill the last chunk.
        // - `4 *`              -> 4 characters for each chunk
        // - `data.length + 2`  -> Round up
        // - `/ 3`              -> Number of 3-bytes chunks
        uint256 resultLength = withPadding ? 4 * ((data.length + 2) / 3) : (4 * data.length + 2) / 3;

        string memory result = new string(resultLength);

        /// @solidity memory-safe-assembly
        assembly {
            // Prepare the lookup table (skip the first "length" byte)
            let tablePtr := add(table, 1)

            // Prepare result pointer, jump over length
            let resultPtr := add(result, 0x20)
            let dataPtr := data
            let endPtr := add(data, mload(data))

            // In some cases, the last iteration will read bytes after the end of the data. We cache the value, and
            // set it to zero to make sure no dirty bytes are read in that section.
            let afterPtr := add(endPtr, 0x20)
            let afterCache := mload(afterPtr)
            mstore(afterPtr, 0x00)

            // Run over the input, 3 bytes at a time
            for {

            } lt(dataPtr, endPtr) {

            } {
                // Advance 3 bytes
                dataPtr := add(dataPtr, 3)
                let input := mload(dataPtr)

                // To write each character, shift the 3 byte (24 bits) chunk
                // 4 times in blocks of 6 bits for each character (18, 12, 6, 0)
                // and apply logical AND with 0x3F to bitmask the least significant 6 bits.
                // Use this as an index into the lookup table, mload an entire word
                // so the desired character is in the least significant byte, and
                // mstore8 this least significant byte into the result and continue.

                mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))
                resultPtr := add(resultPtr, 1) // Advance

                mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))
                resultPtr := add(resultPtr, 1) // Advance

                mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))
                resultPtr := add(resultPtr, 1) // Advance

                mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))
                resultPtr := add(resultPtr, 1) // Advance
            }

            // Reset the value that was cached
            mstore(afterPtr, afterCache)

            if withPadding {
                // When data `bytes` is not exactly 3 bytes long
                // it is padded with `=` characters at the end
                switch mod(mload(data), 3)
                case 1 {
                    mstore8(sub(resultPtr, 1), 0x3d)
                    mstore8(sub(resultPtr, 2), 0x3d)
                }
                case 2 {
                    mstore8(sub(resultPtr, 1), 0x3d)
                }
            }
        }

        return result;
    }
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

Read Contract

RELICS 0x90c2b820 → string, uint256, address
getTokenEntries 0xc6c669d1 → uint256
getTokenKind 0x0facebea → string
isRelic 0xafc42d9d → bool
owner 0x8da5cb5b → address
relicIdToIndex 0x0832c26f → uint256
relicIds 0xe2098e84 → uint256
relicToChosenEntry 0xf9c5cd4f → uint256
relicToPayload 0x825142da → bytes
vaultRelicToEntry 0xeec23d21 → bytes
vessel 0x092ec016 → address

Write Contract 8 functions

These functions modify contract state and require a wallet transaction to execute.

addRelic 0x8d6f82aa
uint256 _tokenId
bytes[] _bytes
address _machine
string _kind
editKind 0x358df334
uint256 _tokenId
string _kind
editRelic 0xcf564e2f
uint256 _tokenId
bytes _bytes
uint256 _index
removeRelic 0x6d2e6de3
uint256 _tokenId
renounceOwnership 0x715018a6
No parameters
setVaultEntryHolder 0x9b8eb18b
uint256 _tokenId
uint256 _entry
setVesselContract 0x28eacbcf
address _a
transferOwnership 0xf2fde38b
address newOwner

Recent Transactions

This address has 1 on-chain transactions, but only 1.6% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →