Contract Name:
LedgerMarketPass
Contract Source Code:
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
import {ERC721} from "@rari-capital/solmate/src/tokens/ERC721.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "./ReentrancyGuard.sol";
import "./Signable.sol";
import "./IProxyTracking.sol";
import "./Helpers.sol";
import "./Errors.sol";
contract LedgerMarketPass is ERC721, ReentrancyGuard, Signable {
// Phase States: None - can't mint, Pre Sale - only mint with sign, Main Sale - only regular mint
enum Phase {
NONE,
PRE_SALE,
MAIN_SALE
}
// Current phase of the contract
Phase private _phase;
// Constants
// Maximum number of NFTs can be allocated
uint256 public immutable maxSupply;
// ETH value should be sent with mint (owner mint is free)
uint256 public mintPrice = 0.3 ether;
// Address where all money from the contract will go if the owner of the contract will call withdraw function
address private constant _withdrawalAddress =
0xC55dA65c626Bad25532bE0d4f6B44aBFD733A152;
// Counter used for token number in minting
uint256 private _nextTokenCount = 1;
// Base token and contract URI
string private baseTokenURI;
string private baseContractURI;
// Proxy contract for tracking afterTokenTransfer call
IProxyTracking public proxyTrackingContract;
// Has the account used minting already
mapping(address => bool) public minted;
// Modifier is used to check if the phase rule is met
modifier phaseRequired(Phase phase_) {
if (phase_ != _phase) revert Errors.MintNotAvailable();
_;
}
// Modifier is used to check if at least a minimal amount of money was sent
modifier costs() {
if (msg.value < mintPrice) revert Errors.InsufficientFunds();
_;
}
constructor(
uint256 _maxSupply,
string memory _baseTokenURI,
string memory _baseContractURI,
string memory _name,
string memory _symbol
) ERC721(_name, _symbol) {
maxSupply = _maxSupply;
baseTokenURI = _baseTokenURI;
baseContractURI = _baseContractURI;
}
// Contract owner can call this function to mint `amount` of tokens into account with the address `to`
function ownerMint(address to, uint256 amount) external onlyOwner lock {
if (_nextTokenCount + amount - 1 > maxSupply)
revert Errors.SupplyLimitReached();
for (uint256 i; i < amount; ) {
_safeMint(to, _nextTokenCount);
unchecked {
++_nextTokenCount;
++i;
}
}
}
// Function used to do minting on pre-sale phase (with signature)
function preSaleMint(bytes calldata signature)
external
payable
costs
phaseRequired(Phase.PRE_SALE)
{
if (!_verify(signer(), _hash(msg.sender), signature))
revert Errors.InvalidSignature();
_mintLogic();
}
// Function used to do minting on main-sale phase
function mint() external payable costs phaseRequired(Phase.MAIN_SALE) {
_mintLogic();
}
// Contract owner can call this function to withdraw all money from the contract into a defined wallet
function withdrawAll() external onlyOwner {
uint256 balance = address(this).balance;
if (balance == 0) revert Errors.NothingToWithdraw();
(bool success, ) = _withdrawalAddress.call{value: balance}("");
if (!success) revert Errors.WithdrawFailed();
}
// Contract owner can call this function to set minting price on pre-sale and main-sale
function setMintPrice(uint256 mintPrice_) external onlyOwner {
if (mintPrice_ == 0) revert Errors.InvalidMintPrice();
// only allow to change price once
if (mintPrice != 0.3 ether) revert Errors.MintPriceAlreadyUpdated();
mintPrice = mintPrice_;
}
// Contract owner can call this function to set the proxy tracking contract address (which gets a call of afterTokenTransfer function of the original contract)
function setProxyTrackingContract(IProxyTracking proxyTrackingContract_)
external
onlyOwner
{
proxyTrackingContract = proxyTrackingContract_;
}
function setContractURI(string calldata baseContractURI_)
external
onlyOwner
{
if (bytes(baseContractURI_).length == 0)
revert Errors.InvalidBaseContractURL();
baseContractURI = baseContractURI_;
}
function setBaseURI(string calldata baseURI_) external onlyOwner {
if (bytes(baseURI_).length == 0) revert Errors.InvalidBaseURI();
baseTokenURI = baseURI_;
}
function setPhase(Phase phase_) external onlyOwner {
_phase = phase_;
}
function totalSupply() external view returns (uint256) {
return _nextTokenCount - 1;
}
function contractURI() external view returns (string memory) {
return baseContractURI;
}
function phase() external view returns (Phase) {
return _phase;
}
function _baseURI() internal view virtual returns (string memory) {
return baseTokenURI;
}
function _mint(address to, uint256 id) internal virtual override {
super._mint(to, id);
_afterTokenTransfer(address(0), to, id);
}
function _burn(uint256 id) internal virtual override {
address owner = _ownerOf[id];
super._burn(id);
_afterTokenTransfer(owner, address(0), id);
}
function transferFrom(
address from,
address to,
uint256 id
) public virtual override {
super.transferFrom(from, to, id);
_afterTokenTransfer(from, to, id);
}
// Function is overridden to do a proxy call into the proxy tracking contract if it is not zero
function _afterTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual {
if (address(proxyTrackingContract) != address(0)) {
proxyTrackingContract.afterTokenTransfer(from, to, tokenId);
}
}
function _mintLogic() private {
if (msg.sender.code.length > 0) revert Errors.ContractCantMint();
if (_nextTokenCount > maxSupply) revert Errors.SupplyLimitReached();
if (minted[msg.sender]) revert Errors.AccountAlreadyMintedMax();
minted[msg.sender] = true;
// smart-contracts are not allowed to call the method -- that means safeMint is useless
_mint(msg.sender, _nextTokenCount);
unchecked {
++_nextTokenCount;
}
}
function _verify(
address signer,
bytes32 hash,
bytes calldata signature
) private pure returns (bool) {
return signer == ECDSA.recover(hash, signature);
}
function _hash(address account) private pure returns (bytes32) {
return
ECDSA.toEthSignedMessageHash(keccak256(abi.encodePacked(account)));
}
function tokenURI(uint256 tokenId)
public
view
override
returns (string memory)
{
if (ownerOf(tokenId) == address(0)) revert Errors.TokenDoesNotExist();
string memory baseURI = _baseURI();
return
bytes(baseURI).length > 0
? string(
abi.encodePacked(baseURI, Helpers.uint2string(tokenId))
)
: "";
}
function burn(uint256 id) external {
if (msg.sender != ownerOf(id)) revert Errors.NotOwner();
_burn(id);
}
}
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern, minimalist, and gas efficient ERC-721 implementation.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC721.sol)
abstract contract ERC721 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 indexed id);
event Approval(address indexed owner, address indexed spender, uint256 indexed id);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE/LOGIC
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
function tokenURI(uint256 id) public view virtual returns (string memory);
/*//////////////////////////////////////////////////////////////
ERC721 BALANCE/OWNER STORAGE
//////////////////////////////////////////////////////////////*/
mapping(uint256 => address) internal _ownerOf;
mapping(address => uint256) internal _balanceOf;
function ownerOf(uint256 id) public view virtual returns (address owner) {
require((owner = _ownerOf[id]) != address(0), "NOT_MINTED");
}
function balanceOf(address owner) public view virtual returns (uint256) {
require(owner != address(0), "ZERO_ADDRESS");
return _balanceOf[owner];
}
/*//////////////////////////////////////////////////////////////
ERC721 APPROVAL STORAGE
//////////////////////////////////////////////////////////////*/
mapping(uint256 => address) public getApproved;
mapping(address => mapping(address => bool)) public isApprovedForAll;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(string memory _name, string memory _symbol) {
name = _name;
symbol = _symbol;
}
/*//////////////////////////////////////////////////////////////
ERC721 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 id) public virtual {
address owner = _ownerOf[id];
require(msg.sender == owner || isApprovedForAll[owner][msg.sender], "NOT_AUTHORIZED");
getApproved[id] = spender;
emit Approval(owner, spender, id);
}
function setApprovalForAll(address operator, bool approved) public virtual {
isApprovedForAll[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
function transferFrom(
address from,
address to,
uint256 id
) public virtual {
require(from == _ownerOf[id], "WRONG_FROM");
require(to != address(0), "INVALID_RECIPIENT");
require(
msg.sender == from || isApprovedForAll[from][msg.sender] || msg.sender == getApproved[id],
"NOT_AUTHORIZED"
);
// Underflow of the sender's balance is impossible because we check for
// ownership above and the recipient's balance can't realistically overflow.
unchecked {
_balanceOf[from]--;
_balanceOf[to]++;
}
_ownerOf[id] = to;
delete getApproved[id];
emit Transfer(from, to, id);
}
function safeTransferFrom(
address from,
address to,
uint256 id
) public virtual {
transferFrom(from, to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, "") ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
function safeTransferFrom(
address from,
address to,
uint256 id,
bytes calldata data
) public virtual {
transferFrom(from, to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, data) ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
/*//////////////////////////////////////////////////////////////
ERC165 LOGIC
//////////////////////////////////////////////////////////////*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return
interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165
interfaceId == 0x80ac58cd || // ERC165 Interface ID for ERC721
interfaceId == 0x5b5e139f; // ERC165 Interface ID for ERC721Metadata
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 id) internal virtual {
require(to != address(0), "INVALID_RECIPIENT");
require(_ownerOf[id] == address(0), "ALREADY_MINTED");
// Counter overflow is incredibly unrealistic.
unchecked {
_balanceOf[to]++;
}
_ownerOf[id] = to;
emit Transfer(address(0), to, id);
}
function _burn(uint256 id) internal virtual {
address owner = _ownerOf[id];
require(owner != address(0), "NOT_MINTED");
// Ownership check above ensures no underflow.
unchecked {
_balanceOf[owner]--;
}
delete _ownerOf[id];
delete getApproved[id];
emit Transfer(owner, address(0), id);
}
/*//////////////////////////////////////////////////////////////
INTERNAL SAFE MINT LOGIC
//////////////////////////////////////////////////////////////*/
function _safeMint(address to, uint256 id) internal virtual {
_mint(to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, "") ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
function _safeMint(
address to,
uint256 id,
bytes memory data
) internal virtual {
_mint(to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, data) ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
}
/// @notice A generic interface for a contract which properly accepts ERC721 tokens.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC721.sol)
abstract contract ERC721TokenReceiver {
function onERC721Received(
address,
address,
uint256,
bytes calldata
) external virtual returns (bytes4) {
return ERC721TokenReceiver.onERC721Received.selector;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
} else if (error == RecoverError.InvalidSignatureV) {
revert("ECDSA: invalid signature 'v' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return tryRecover(hash, r, vs);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
if (v != 27 && v != 28) {
return (address(0), RecoverError.InvalidSignatureV);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
import "./Errors.sol";
abstract contract ReentrancyGuard {
uint256 private unlocked = 1;
modifier lock() {
if (unlocked == 0) revert Errors.ContractLocked();
unlocked = 0;
_;
unlocked = 1;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@rari-capital/solmate/src/auth/Owned.sol";
import "./Errors.sol";
/// @title Contract that manages the signer/owner roles
abstract contract Signable is Owned {
address private _signer;
constructor() Owned(msg.sender) {
_signer = msg.sender;
}
function signer() public view returns (address) {
return _signer;
}
/// @notice This method allow the owner change the signer role
/// @dev At first, the signer role and the owner role is associated to the same address
/// @param newSigner The address of the new signer
function transferSigner(address newSigner) external onlyOwner {
if (newSigner == address(0)) revert Errors.NewSignerCantBeZero();
_signer = newSigner;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
interface IProxyTracking {
/**
* @dev Called by original contract on _afterTokenTransfer ERC721 event.
*
* WARNING: Good practice will be to check that msg.sender is original contract, for example: require(msg.sender == _originalContract, "Only original contract can call this");
*
*/
function afterTokenTransfer(
address from,
address to,
uint256 tokenId
) external;
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
library Helpers {
function uint2string(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
library Errors {
/* LedgerNFT.sol */
error MintNotAvailable();
error InsufficientFunds();
error SupplyLimitReached();
error ContractCantMint();
error InvalidSignature();
error AccountAlreadyMintedMax();
error TokenDoesNotExist();
error NotOwner();
error NothingToWithdraw();
error WithdrawFailed();
error InvalidMintPrice();
error MintPriceAlreadyUpdated();
error InvalidBaseContractURL();
error InvalidBaseURI();
/* ReentrancyGuard.sol */
error ContractLocked();
/* Signable.sol */
error NewSignerCantBeZero();
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Simple single owner authorization mixin.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/Owned.sol)
abstract contract Owned {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event OwnerUpdated(address indexed user, address indexed newOwner);
/*//////////////////////////////////////////////////////////////
OWNERSHIP STORAGE
//////////////////////////////////////////////////////////////*/
address public owner;
modifier onlyOwner() virtual {
require(msg.sender == owner, "UNAUTHORIZED");
_;
}
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(address _owner) {
owner = _owner;
emit OwnerUpdated(address(0), _owner);
}
/*//////////////////////////////////////////////////////////////
OWNERSHIP LOGIC
//////////////////////////////////////////////////////////////*/
function setOwner(address newOwner) public virtual onlyOwner {
owner = newOwner;
emit OwnerUpdated(msg.sender, newOwner);
}
}