Source Code
Overview
MON Balance
MON Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
ArchetypeErc1155
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 1 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
// Archetype v0.8.1 - ERC1155
//
// d8888 888 888
// d88888 888 888
// d88P888 888 888
// d88P 888 888d888 .d8888b 88888b. .d88b. 888888 888 888 88888b. .d88b.
// d88P 888 888P" d88P" 888 "88b d8P Y8b 888 888 888 888 "88b d8P Y8b
// d88P 888 888 888 888 888 88888888 888 888 888 888 888 88888888
// d8888888888 888 Y88b. 888 888 Y8b. Y88b. Y88b 888 888 d88P Y8b.
// d88P 888 888 "Y8888P 888 888 "Y8888 "Y888 "Y88888 88888P" "Y8888
// 888 888
// Y8b d88P 888
// "Y88P" 888
pragma solidity ^0.8.20;
import "./ArchetypeLogicErc1155.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/common/ERC2981Upgradeable.sol";
import "solady/src/utils/LibString.sol";
contract ArchetypeErc1155 is Initializable, ERC1155Upgradeable, OwnableUpgradeable, ERC2981Upgradeable {
//
// EVENTS
//
event Invited(bytes32 indexed key, bytes32 indexed cid);
event Referral(address indexed affiliate, address token, uint128 wad, uint256 numMints);
event Withdrawal(address indexed src, address token, uint128 wad);
//
// VARIABLES
//
mapping(bytes32 => AdvancedInvite) public invites;
mapping(bytes32 => uint256) public packedBonusDiscounts;
mapping(address => mapping(bytes32 => uint256)) private _minted;
mapping(bytes32 => uint256) private _listSupply;
mapping(address => uint128) private _ownerBalance;
mapping(address => mapping(address => uint128)) private _affiliateBalance;
uint256[] private _tokenSupply;
Config public config;
PayoutConfig public payoutConfig;
Options public options;
string public name;
string public symbol;
//
// METHODS
//
function initialize(
string memory _name,
string memory _symbol,
Config calldata config_,
PayoutConfig calldata payoutConfig_,
address _receiver
) external initializer {
name = _name;
symbol = _symbol;
__ERC1155_init("");
// check max bps not reached and min platform fee.
if (
config_.affiliateFee > MAXBPS ||
config_.affiliateDiscount > MAXBPS ||
config_.affiliateSigner == address(0) ||
config_.maxBatchSize == 0
) {
revert InvalidConfig();
}
config = config_;
_tokenSupply = new uint256[](config_.maxSupply.length);
__Ownable_init();
uint256 totalShares = payoutConfig_.ownerBps +
payoutConfig_.platformBps +
payoutConfig_.partnerBps +
payoutConfig_.superAffiliateBps;
if (payoutConfig_.platformBps < 250 || totalShares != 10000) {
revert InvalidSplitShares();
}
payoutConfig = payoutConfig_;
setDefaultRoyalty(_receiver, config.defaultRoyalty);
}
//
// PUBLIC
//
function mintToken(
Auth calldata auth,
uint256 quantity,
uint256 tokenId,
address affiliate,
bytes calldata signature
) external payable {
mintTo(auth, quantity, _msgSender(), tokenId, affiliate, signature);
}
function batchMintTo(
Auth calldata auth,
address[] calldata toList,
uint256[] calldata quantityList,
uint256[] calldata tokenIdList,
address affiliate,
bytes calldata signature
) external payable {
if (quantityList.length != toList.length || quantityList.length != tokenIdList.length) {
revert InvalidConfig();
}
uint256 quantity;
for (uint256 i = 0; i < quantityList.length; i++) {
quantity += quantityList[i];
}
ValidationArgs memory args;
{
args = ValidationArgs({
owner: owner(),
affiliate: affiliate,
quantities: quantityList,
tokenIds: tokenIdList,
totalQuantity: quantity,
listSupply: _listSupply[auth.key]
});
}
AdvancedInvite storage invite = invites[auth.key];
if (invite.unitSize > 1) {
revert NotSupported();
}
validateAndCreditMint(invite, auth, args, affiliate, signature);
for (uint256 i = 0; i < toList.length; i++) {
bytes memory _data;
_mint(toList[i], tokenIdList[i], quantityList[i], _data);
_tokenSupply[tokenIdList[i] - 1] += quantityList[i];
}
}
function mintTo(
Auth calldata auth,
uint256 quantity,
address to,
uint256 tokenId,
address affiliate,
bytes calldata signature
) public payable {
if (to == address(0)) {
revert MintToZeroAddress();
}
AdvancedInvite storage invite = invites[auth.key];
if (invite.unitSize > 1) {
quantity = quantity * invite.unitSize;
}
ValidationArgs memory args;
{
uint256[] memory tokenIds = new uint256[](1);
tokenIds[0] = tokenId;
uint256[] memory quantities = new uint256[](1);
quantities[0] = quantity;
args = ValidationArgs({
owner: owner(),
affiliate: affiliate,
quantities: quantities,
tokenIds: tokenIds,
totalQuantity: quantity,
listSupply: _listSupply[auth.key]
});
}
validateAndCreditMint(invite, auth, args, affiliate, signature);
for (uint256 j = 0; j < args.tokenIds.length; j++) {
bytes memory _data;
_mint(to, args.tokenIds[j], args.quantities[j], _data);
_tokenSupply[args.tokenIds[j] - 1] += args.quantities[j];
}
}
function validateAndCreditMint(
AdvancedInvite storage invite,
Auth calldata auth,
ValidationArgs memory args,
address affiliate,
bytes calldata signature
) internal {
uint128 cost = uint128(
ArchetypeLogicErc1155.computePrice(
invite,
config.affiliateDiscount,
args.totalQuantity,
args.listSupply,
args.affiliate != address(0)
)
);
ArchetypeLogicErc1155.validateMint(
invite,
config,
auth,
_minted,
_tokenSupply,
signature,
args,
cost
);
if (invite.limit < invite.maxSupply) {
_minted[_msgSender()][auth.key] += args.totalQuantity;
}
if (invite.maxSupply < 2**32 - 1) {
_listSupply[auth.key] += args.totalQuantity;
}
ArchetypeLogicErc1155.updateBalances(
invite,
config,
_ownerBalance,
_affiliateBalance,
affiliate,
args.totalQuantity,
cost
);
if (msg.value > cost) {
_refund(_msgSender(), msg.value - cost);
}
}
function uri(uint256 tokenId) public view override returns (string memory) {
return
bytes(config.baseUri).length != 0
? string(abi.encodePacked(config.baseUri, LibString.toString(tokenId)))
: "";
}
function withdraw() external {
address[] memory tokens = new address[](1);
tokens[0] = address(0);
withdrawTokens(tokens);
}
function withdrawTokens(address[] memory tokens) public {
ArchetypeLogicErc1155.withdrawTokens(payoutConfig, _ownerBalance, owner(), tokens);
}
function withdrawAffiliate() external {
address[] memory tokens = new address[](1);
tokens[0] = address(0);
withdrawTokensAffiliate(tokens);
}
function withdrawTokensAffiliate(address[] memory tokens) public {
ArchetypeLogicErc1155.withdrawTokensAffiliate(_affiliateBalance, tokens);
}
function ownerBalance() external view returns (uint128) {
return _ownerBalance[address(0)];
}
function ownerBalanceToken(address token) external view returns (uint128) {
return _ownerBalance[token];
}
function affiliateBalance(address affiliate) external view returns (uint128) {
return _affiliateBalance[affiliate][address(0)];
}
function affiliateBalanceToken(address affiliate, address token) external view returns (uint128) {
return _affiliateBalance[affiliate][token];
}
function minted(address minter, bytes32 key) external view returns (uint256) {
return _minted[minter][key];
}
function listSupply(bytes32 key) external view returns (uint256) {
return _listSupply[key];
}
function platform() external pure returns (address) {
return PLATFORM;
}
function tokenSupply(uint256 tokenId) external view returns (uint256) {
if (!_exists(tokenId)) revert URIQueryForNonexistentToken();
return _tokenSupply[tokenId - 1];
}
function totalSupply() external view returns (uint256) {
uint256 supply = 0;
for (uint256 i = 0; i < _tokenSupply.length; i++) {
supply += _tokenSupply[i];
}
return supply;
}
function maxSupply() external view returns (uint32[] memory) {
return config.maxSupply;
}
function computePrice(
bytes32 key,
uint256 quantity,
bool affiliateUsed
) external view returns (uint256) {
AdvancedInvite storage i = invites[key];
uint256 listSupply_ = _listSupply[key];
return ArchetypeLogicErc1155.computePrice(i, config.affiliateDiscount, quantity, listSupply_, affiliateUsed);
}
//
// OWNER ONLY
//
function setBaseURI(string memory baseUri) external onlyOwner {
if (options.uriLocked) {
revert LockedForever();
}
config.baseUri = baseUri;
}
/// @notice the password is "forever"
function lockURI(string memory password) external _onlyOwner {
_checkPassword(password);
options.uriLocked = true;
}
/// @notice the password is "forever"
// max supply cannot subceed total supply. Be careful changing.
function setMaxSupply(uint32[] memory newMaxSupply, string memory password) external onlyOwner {
if (keccak256(abi.encodePacked(password)) != keccak256(abi.encodePacked("forever"))) {
revert WrongPassword();
}
if (options.maxSupplyLocked) {
revert LockedForever();
}
for (uint256 i = 0; i < _tokenSupply.length; i++) {
if (newMaxSupply[i] < _tokenSupply[i]) {
revert MaxSupplyExceeded();
}
}
// increase size of token supply array to match new max supply
for (uint256 i = _tokenSupply.length; i < newMaxSupply.length; i++) {
_tokenSupply.push(0);
}
config.maxSupply = newMaxSupply;
}
/// @notice the password is "forever"
function lockMaxSupply(string memory password) external _onlyOwner {
_checkPassword(password);
options.maxSupplyLocked = true;
}
function setAffiliateFee(uint16 affiliateFee) external _onlyOwner {
if (options.affiliateFeeLocked) {
revert LockedForever();
}
if (affiliateFee > MAXBPS) {
revert InvalidConfig();
}
config.affiliateFee = affiliateFee;
}
function setAffiliateDiscount(uint16 affiliateDiscount) external _onlyOwner {
if (options.affiliateFeeLocked) {
revert LockedForever();
}
if (affiliateDiscount > MAXBPS) {
revert InvalidConfig();
}
config.affiliateDiscount = affiliateDiscount;
}
/// @notice the password is "forever"
function lockAffiliateFee(string memory password) external _onlyOwner {
_checkPassword(password);
options.affiliateFeeLocked = true;
}
function setOwnerAltPayout(address ownerAltPayout) external _onlyOwner {
if (options.ownerAltPayoutLocked) {
revert LockedForever();
}
payoutConfig.ownerAltPayout = ownerAltPayout;
}
/// @notice the password is "forever"
function lockOwnerAltPayout(string memory password) external _onlyOwner {
_checkPassword(password);
options.ownerAltPayoutLocked = true;
}
function setMaxBatchSize(uint16 maxBatchSize) external _onlyOwner {
config.maxBatchSize = maxBatchSize;
}
function setInvite(
bytes32 _key,
bytes32 _cid,
Invite calldata _invite
) external _onlyOwner {
setAdvancedInvite(_key, _cid, AdvancedInvite({
price: _invite.price,
reservePrice: _invite.price,
delta: 0,
start: _invite.start,
end: _invite.end,
limit: _invite.limit,
maxSupply: _invite.maxSupply,
interval: 0,
unitSize: _invite.unitSize,
tokenIds: _invite.tokenIds,
tokenAddress: _invite.tokenAddress
}));
}
function setAdvancedInvite(
bytes32 _key,
bytes32 _cid,
AdvancedInvite memory _AdvancedInvite
) public _onlyOwner {
// approve token for withdrawals if erc20 list
if (_AdvancedInvite.tokenAddress != address(0)) {
bool success = IERC20(_AdvancedInvite.tokenAddress).approve(PAYOUTS, 2**256 - 1);
if (!success) {
revert NotApprovedToTransfer();
}
}
if (_AdvancedInvite.start < block.timestamp) {
_AdvancedInvite.start = uint32(block.timestamp);
}
invites[_key] = _AdvancedInvite;
emit Invited(_key, _cid);
}
//
// INTERNAL
//
function _startTokenId() internal view virtual returns (uint256) {
return 1;
}
function _exists(uint256 tokenId) internal view returns (bool) {
return tokenId > 0 && tokenId <= _tokenSupply.length;
}
function _msgSender() internal view override returns (address) {
return msg.sender == BATCH ? tx.origin : msg.sender;
}
function _checkPassword(string memory password) internal pure {
if (keccak256(abi.encodePacked(password)) != keccak256(abi.encodePacked("forever"))) {
revert WrongPassword();
}
}
function _isOwner() internal view {
if (_msgSender() != owner()) {
revert NotOwner();
}
}
modifier _onlyPlatform() {
if (_msgSender() != PLATFORM) {
revert NotPlatform();
}
_;
}
modifier _onlyOwner() {
_isOwner();
_;
}
function _refund(address to, uint256 refund) internal {
(bool success, ) = payable(to).call{ value: refund }("");
if (!success) {
revert TransferFailed();
}
}
//ERC2981 ROYALTY
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC1155Upgradeable, ERC2981Upgradeable)
returns (bool)
{
// Supports the following `interfaceId`s:
// - IERC165: 0x01ffc9a7
// - IERC721: 0x80ac58cd
// - IERC721Metadata: 0x5b5e139f
// - IERC2981: 0x2a55205a
return
ERC1155Upgradeable.supportsInterface(interfaceId) ||
ERC2981Upgradeable.supportsInterface(interfaceId);
}
function setDefaultRoyalty(address receiver, uint16 feeNumerator) public _onlyOwner {
config.defaultRoyalty = feeNumerator;
_setDefaultRoyalty(receiver, feeNumerator);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.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.
*
* By default, the owner account will be the one that deploys the contract. 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 OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @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 {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @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 {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_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);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC2981.sol)
pragma solidity ^0.8.0;
import "../utils/introspection/IERC165Upgradeable.sol";
/**
* @dev Interface for the NFT Royalty Standard.
*
* A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal
* support for royalty payments across all NFT marketplaces and ecosystem participants.
*
* _Available since v4.5._
*/
interface IERC2981Upgradeable is IERC165Upgradeable {
/**
* @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
* exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
*/
function royaltyInfo(
uint256 tokenId,
uint256 salePrice
) external view returns (address receiver, uint256 royaltyAmount);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/common/ERC2981.sol)
pragma solidity ^0.8.0;
import "../../interfaces/IERC2981Upgradeable.sol";
import "../../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information.
*
* Royalty information can be specified globally for all token ids via {_setDefaultRoyalty}, and/or individually for
* specific token ids via {_setTokenRoyalty}. The latter takes precedence over the first.
*
* Royalty is specified as a fraction of sale price. {_feeDenominator} is overridable but defaults to 10000, meaning the
* fee is specified in basis points by default.
*
* IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See
* https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the EIP. Marketplaces are expected to
* voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
*
* _Available since v4.5._
*/
abstract contract ERC2981Upgradeable is Initializable, IERC2981Upgradeable, ERC165Upgradeable {
struct RoyaltyInfo {
address receiver;
uint96 royaltyFraction;
}
RoyaltyInfo private _defaultRoyaltyInfo;
mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo;
function __ERC2981_init() internal onlyInitializing {
}
function __ERC2981_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165Upgradeable, ERC165Upgradeable) returns (bool) {
return interfaceId == type(IERC2981Upgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @inheritdoc IERC2981Upgradeable
*/
function royaltyInfo(uint256 tokenId, uint256 salePrice) public view virtual override returns (address, uint256) {
RoyaltyInfo memory royalty = _tokenRoyaltyInfo[tokenId];
if (royalty.receiver == address(0)) {
royalty = _defaultRoyaltyInfo;
}
uint256 royaltyAmount = (salePrice * royalty.royaltyFraction) / _feeDenominator();
return (royalty.receiver, royaltyAmount);
}
/**
* @dev The denominator with which to interpret the fee set in {_setTokenRoyalty} and {_setDefaultRoyalty} as a
* fraction of the sale price. Defaults to 10000 so fees are expressed in basis points, but may be customized by an
* override.
*/
function _feeDenominator() internal pure virtual returns (uint96) {
return 10000;
}
/**
* @dev Sets the royalty information that all ids in this contract will default to.
*
* Requirements:
*
* - `receiver` cannot be the zero address.
* - `feeNumerator` cannot be greater than the fee denominator.
*/
function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: invalid receiver");
_defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator);
}
/**
* @dev Removes default royalty information.
*/
function _deleteDefaultRoyalty() internal virtual {
delete _defaultRoyaltyInfo;
}
/**
* @dev Sets the royalty information for a specific token id, overriding the global default.
*
* Requirements:
*
* - `receiver` cannot be the zero address.
* - `feeNumerator` cannot be greater than the fee denominator.
*/
function _setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) internal virtual {
require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
require(receiver != address(0), "ERC2981: Invalid parameters");
_tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator);
}
/**
* @dev Resets royalty information for the token id back to the global default.
*/
function _resetTokenRoyalty(uint256 tokenId) internal virtual {
delete _tokenRoyaltyInfo[tokenId];
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[48] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/ERC1155.sol)
pragma solidity ^0.8.0;
import "./IERC1155Upgradeable.sol";
import "./IERC1155ReceiverUpgradeable.sol";
import "./extensions/IERC1155MetadataURIUpgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the basic standard multi-token.
* See https://eips.ethereum.org/EIPS/eip-1155
* Originally based on code by Enjin: https://github.com/enjin/erc-1155
*
* _Available since v3.1._
*/
contract ERC1155Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC1155Upgradeable, IERC1155MetadataURIUpgradeable {
using AddressUpgradeable for address;
// Mapping from token ID to account balances
mapping(uint256 => mapping(address => uint256)) private _balances;
// Mapping from account to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
string private _uri;
/**
* @dev See {_setURI}.
*/
function __ERC1155_init(string memory uri_) internal onlyInitializing {
__ERC1155_init_unchained(uri_);
}
function __ERC1155_init_unchained(string memory uri_) internal onlyInitializing {
_setURI(uri_);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) {
return
interfaceId == type(IERC1155Upgradeable).interfaceId ||
interfaceId == type(IERC1155MetadataURIUpgradeable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC1155MetadataURI-uri}.
*
* This implementation returns the same URI for *all* token types. It relies
* on the token type ID substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* Clients calling this function must replace the `\{id\}` substring with the
* actual token type ID.
*/
function uri(uint256) public view virtual override returns (string memory) {
return _uri;
}
/**
* @dev See {IERC1155-balanceOf}.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), "ERC1155: address zero is not a valid owner");
return _balances[id][account];
}
/**
* @dev See {IERC1155-balanceOfBatch}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] memory accounts,
uint256[] memory ids
) public view virtual override returns (uint256[] memory) {
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
uint256[] memory batchBalances = new uint256[](accounts.length);
for (uint256 i = 0; i < accounts.length; ++i) {
batchBalances[i] = balanceOf(accounts[i], ids[i]);
}
return batchBalances;
}
/**
* @dev See {IERC1155-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC1155-isApprovedForAll}.
*/
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
return _operatorApprovals[account][operator];
}
/**
* @dev See {IERC1155-safeTransferFrom}.
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not token owner or approved"
);
_safeTransferFrom(from, to, id, amount, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not token owner or approved"
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
emit TransferSingle(operator, from, to, id, amount);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; ++i) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
unchecked {
_balances[id][from] = fromBalance - amount;
}
_balances[id][to] += amount;
}
emit TransferBatch(operator, from, to, ids, amounts);
_afterTokenTransfer(operator, from, to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
}
/**
* @dev Sets a new URI for all token types, by relying on the token type ID
* substitution mechanism
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
*
* By this mechanism, any occurrence of the `\{id\}` substring in either the
* URI or any of the amounts in the JSON file at said URI will be replaced by
* clients with the token type ID.
*
* For example, the `https://token-cdn-domain/\{id\}.json` URI would be
* interpreted by clients as
* `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
* for token type ID 0x4cce0.
*
* See {uri}.
*
* Because these URIs cannot be meaningfully represented by the {URI} event,
* this function emits no events.
*/
function _setURI(string memory newuri) internal virtual {
_uri = newuri;
}
/**
* @dev Creates `amount` tokens of token type `id`, and assigns them to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _mint(address to, uint256 id, uint256 amount, bytes memory data) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
_balances[id][to] += amount;
emit TransferSingle(operator, address(0), to, id, amount);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function _mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {
require(to != address(0), "ERC1155: mint to the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
for (uint256 i = 0; i < ids.length; i++) {
_balances[ids[i]][to] += amounts[i];
}
emit TransferBatch(operator, address(0), to, ids, amounts);
_afterTokenTransfer(operator, address(0), to, ids, amounts, data);
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
}
/**
* @dev Destroys `amount` tokens of token type `id` from `from`
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `from` must have at least `amount` tokens of token type `id`.
*/
function _burn(address from, uint256 id, uint256 amount) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
address operator = _msgSender();
uint256[] memory ids = _asSingletonArray(id);
uint256[] memory amounts = _asSingletonArray(amount);
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
emit TransferSingle(operator, from, address(0), id, amount);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
*/
function _burnBatch(address from, uint256[] memory ids, uint256[] memory amounts) internal virtual {
require(from != address(0), "ERC1155: burn from the zero address");
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
address operator = _msgSender();
_beforeTokenTransfer(operator, from, address(0), ids, amounts, "");
for (uint256 i = 0; i < ids.length; i++) {
uint256 id = ids[i];
uint256 amount = amounts[i];
uint256 fromBalance = _balances[id][from];
require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
unchecked {
_balances[id][from] = fromBalance - amount;
}
}
emit TransferBatch(operator, from, address(0), ids, amounts);
_afterTokenTransfer(operator, from, address(0), ids, amounts, "");
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
require(owner != operator, "ERC1155: setting approval status for self");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning, as well as batched variants.
*
* The same hook is called on both single and batched variants. For single
* transfers, the length of the `ids` and `amounts` arrays will be 1.
*
* Calling conditions (for each `id` and `amount` pair):
*
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* of token type `id` will be transferred to `to`.
* - When `from` is zero, `amount` tokens of token type `id` will be minted
* for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
* will be burned.
* - `from` and `to` are never both zero.
* - `ids` and `amounts` have the same, non-zero length.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
/**
* @dev Hook that is called after any token transfer. This includes minting
* and burning, as well as batched variants.
*
* The same hook is called on both single and batched variants. For single
* transfers, the length of the `id` and `amount` arrays will be 1.
*
* Calling conditions (for each `id` and `amount` pair):
*
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* of token type `id` will be transferred to `to`.
* - When `from` is zero, `amount` tokens of token type `id` will be minted
* for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
* will be burned.
* - `from` and `to` are never both zero.
* - `ids` and `amounts` have the same, non-zero length.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal virtual {}
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155ReceiverUpgradeable(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
if (response != IERC1155ReceiverUpgradeable.onERC1155Received.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non-ERC1155Receiver implementer");
}
}
}
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) private {
if (to.isContract()) {
try IERC1155ReceiverUpgradeable(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
bytes4 response
) {
if (response != IERC1155ReceiverUpgradeable.onERC1155BatchReceived.selector) {
revert("ERC1155: ERC1155Receiver rejected tokens");
}
} catch Error(string memory reason) {
revert(reason);
} catch {
revert("ERC1155: transfer to non-ERC1155Receiver implementer");
}
}
}
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
uint256[] memory array = new uint256[](1);
array[0] = element;
return array;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[47] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol)
pragma solidity ^0.8.0;
import "../IERC1155Upgradeable.sol";
/**
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
*
* _Available since v3.1._
*/
interface IERC1155MetadataURIUpgradeable is IERC1155Upgradeable {
/**
* @dev Returns the URI for token type `id`.
*
* If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/
function uri(uint256 id) external view returns (string memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165Upgradeable.sol";
/**
* @dev _Available since v3.1._
*/
interface IERC1155ReceiverUpgradeable is IERC165Upgradeable {
/**
* @dev Handles the receipt of a single ERC1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/IERC1155.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165Upgradeable.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*
* _Available since v3.1._
*/
interface IERC1155Upgradeable is IERC165Upgradeable {
/**
* @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the amount of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(
address[] calldata accounts,
uint256[] calldata ids
) external view returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @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 ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
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;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165Upgradeable.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165Upgradeable).interfaceId;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165Upgradeable {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// ArchetypePayouts v0.7.0
//
// d8888 888 888
// d88888 888 888
// d88P888 888 888
// d88P 888 888d888 .d8888b 88888b. .d88b. 888888 888 888 88888b. .d88b.
// d88P 888 888P" d88P" 888 "88b d8P Y8b 888 888 888 888 "88b d8P Y8b
// d88P 888 888 888 888 888 88888888 888 888 888 888 888 88888888
// d8888888888 888 Y88b. 888 888 Y8b. Y88b. Y88b 888 888 d88P Y8b.
// d88P 888 888 "Y8888P 888 888 "Y8888 "Y888 "Y88888 88888P" "Y8888
// 888 888
// Y8b d88P 888
//
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
using SafeERC20 for IERC20;
error InvalidLength();
error InvalidSplitShares();
error TransferFailed();
error BalanceEmpty();
error NotApprovedToWithdraw();
contract ArchetypePayouts {
event Withdrawal(address indexed src, address token, uint256 wad);
event FundsAdded(address indexed recipient, address token, uint256 amount);
mapping(address => mapping(address => uint256)) private _balance;
mapping(address => mapping(address => bool)) private _approvals;
function updateBalances(
uint256 totalAmount,
address token,
address[] calldata recipients,
uint16[] calldata splits
) public payable {
if (recipients.length != splits.length) {
revert InvalidLength();
}
uint256 totalShares = 0;
for (uint256 i = 0; i < splits.length; i++) {
totalShares += splits[i];
}
if (totalShares != 10000) {
revert InvalidSplitShares();
}
if (token == address(0)) {
// ETH payments
uint256 totalReceived = msg.value;
for (uint256 i = 0; i < recipients.length; i++) {
if (splits[i] > 0) {
uint256 amountToAdd = (totalReceived * splits[i]) / 10000;
_balance[recipients[i]][token] += amountToAdd;
emit FundsAdded(recipients[i], token, amountToAdd);
}
}
} else {
// ERC20 payments
IERC20 paymentToken = IERC20(token);
paymentToken.safeTransferFrom(msg.sender, address(this), totalAmount);
for (uint256 i = 0; i < recipients.length; i++) {
if (splits[i] > 0) {
uint256 amountToAdd = (totalAmount * splits[i]) / 10000;
_balance[recipients[i]][token] += amountToAdd;
emit FundsAdded(recipients[i], token, amountToAdd);
}
}
}
}
function withdraw() external {
address msgSender = msg.sender;
_withdraw(msgSender, msgSender, address(0));
}
function withdrawTokens(address[] memory tokens) external {
address msgSender = msg.sender;
for (uint256 i = 0; i < tokens.length; i++) {
_withdraw(msgSender, msgSender, tokens[i]);
}
}
function withdrawFrom(address from, address to) public {
if (from != msg.sender && !_approvals[from][to]) {
revert NotApprovedToWithdraw();
}
_withdraw(from, to, address(0));
}
function withdrawTokensFrom(
address from,
address to,
address[] memory tokens
) public {
if (from != msg.sender && !_approvals[from][to]) {
revert NotApprovedToWithdraw();
}
for (uint256 i = 0; i < tokens.length; i++) {
_withdraw(from, to, tokens[i]);
}
}
function _withdraw(
address from,
address to,
address token
) internal {
uint256 wad;
wad = _balance[from][token];
_balance[from][token] = 0;
if (wad == 0) {
revert BalanceEmpty();
}
if (token == address(0)) {
bool success = false;
(success, ) = to.call{ value: wad }("");
if (!success) {
revert TransferFailed();
}
} else {
IERC20 erc20Token = IERC20(token);
erc20Token.safeTransfer(to, wad);
}
emit Withdrawal(from, token, wad);
}
function approveWithdrawal(address delegate, bool approved) external {
_approvals[msg.sender][delegate] = approved;
}
function isApproved(address from, address delegate) external view returns (bool) {
return _approvals[from][delegate];
}
function balance(address recipient) external view returns (uint256) {
return _balance[recipient][address(0)];
}
function balanceToken(address recipient, address token) external view returns (uint256) {
return _balance[recipient][token];
}
}// SPDX-License-Identifier: MIT
// ArchetypeLogic v0.8.1 - ERC1155
//
// d8888 888 888
// d88888 888 888
// d88P888 888 888
// d88P 888 888d888 .d8888b 88888b. .d88b. 888888 888 888 88888b. .d88b.
// d88P 888 888P" d88P" 888 "88b d8P Y8b 888 888 888 888 "88b d8P Y8b
// d88P 888 888 888 888 888 88888888 888 888 888 888 888 88888888
// d8888888888 888 Y88b. 888 888 Y8b. Y88b. Y88b 888 888 d88P Y8b.
// d88P 888 888 "Y8888P 888 888 "Y8888 "Y888 "Y88888 88888P" "Y8888
// 888 888
// Y8b d88P 888
// "Y88P" 888
pragma solidity ^0.8.20;
import "../ArchetypePayouts.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "solady/src/utils/MerkleProofLib.sol";
import "solady/src/utils/ECDSA.sol";
using SafeERC20 for IERC20;
error InvalidConfig();
error MintNotYetStarted();
error MintEnded();
error WalletUnauthorizedToMint();
error InsufficientEthSent();
error ExcessiveEthSent();
error Erc20BalanceTooLow();
error MaxSupplyExceeded();
error ListMaxSupplyExceeded();
error NumberOfMintsExceeded();
error MintingPaused();
error InvalidReferral();
error InvalidSignature();
error MaxBatchSizeExceeded();
error NotTokenOwner();
error NotPlatform();
error NotOwner();
error NotShareholder();
error NotApprovedToTransfer();
error InvalidAmountOfTokens();
error WrongPassword();
error LockedForever();
error URIQueryForNonexistentToken();
error InvalidTokenId();
error MintToZeroAddress();
error NotSupported();
//
// STRUCTS
//
struct Auth {
bytes32 key;
bytes32[] proof;
}
struct Config {
string baseUri;
address affiliateSigner;
uint32[] maxSupply; // max supply for each mintable tokenId
uint16 maxBatchSize;
uint16 affiliateFee; //BPS
uint16 affiliateDiscount; //BPS
uint16 defaultRoyalty; //BPS
}
struct PayoutConfig {
uint16 ownerBps;
uint16 platformBps;
uint16 partnerBps;
uint16 superAffiliateBps;
address partner;
address superAffiliate;
address ownerAltPayout;
}
struct Options {
bool uriLocked;
bool maxSupplyLocked;
bool affiliateFeeLocked;
bool ownerAltPayoutLocked;
}
struct AdvancedInvite {
uint128 price;
uint128 reservePrice;
uint128 delta;
uint32 start;
uint32 end;
uint32 limit;
uint32 maxSupply;
uint32 interval;
uint32 unitSize; // mint 1 get x
uint32[] tokenIds; // token ids mintable from this list
address tokenAddress;
}
struct Invite {
uint128 price;
uint32 start;
uint32 end;
uint32 limit;
uint32 maxSupply;
uint32 unitSize; // mint 1 get x
uint32[] tokenIds; // token ids mintable from this list
address tokenAddress;
}
struct ValidationArgs {
address owner;
address affiliate;
uint256[] quantities;
uint256[] tokenIds;
uint256 totalQuantity;
uint256 listSupply;
}
// UPDATE CONSTANTS BEFORE DEPLOY
address constant PLATFORM = 0x86B82972282Dd22348374bC63fd21620F7ED847B;
address constant BATCH = 0xEa49e7bE310716dA66725c84a5127d2F6A202eAf;
address constant PAYOUTS = 0xaAfdfA4a935d8511bF285af11A0544ce7e4a1199;
uint16 constant MAXBPS = 5000; // max fee or discount is 50%
uint32 constant UINT32_MAX = 2**32 - 1;
library ArchetypeLogicErc1155 {
//
// EVENTS
//
event Invited(bytes32 indexed key, bytes32 indexed cid);
event Referral(address indexed affiliate, address token, uint128 wad, uint256 numMints);
event Withdrawal(address indexed src, address token, uint128 wad);
// calculate price based on affiliate usage and mint discounts
function computePrice(
AdvancedInvite storage invite,
uint16 affiliateDiscount,
uint256 numTokens,
uint256 listSupply,
bool affiliateUsed
) public view returns (uint256) {
uint256 price = invite.price;
uint256 cost;
if (invite.interval > 0 && invite.delta > 0) {
// Apply dutch pricing
uint256 diff = (((block.timestamp - invite.start) / invite.interval) * invite.delta);
if (price > invite.reservePrice) {
if (diff > price - invite.reservePrice) {
price = invite.reservePrice;
} else {
price = price - diff;
}
} else if (price < invite.reservePrice) {
if (diff > invite.reservePrice - price) {
price = invite.reservePrice;
} else {
price = price + diff;
}
}
cost = price * numTokens;
} else if (invite.interval == 0 && invite.delta > 0) {
// Apply linear curve
uint256 lastPrice = price + invite.delta * listSupply;
cost = lastPrice * numTokens + (invite.delta * numTokens * (numTokens - 1)) / 2;
} else {
cost = price * numTokens;
}
if (affiliateUsed) {
cost = cost - ((cost * affiliateDiscount) / 10000);
}
return cost;
}
function validateMint(
AdvancedInvite storage i,
Config storage config,
Auth calldata auth,
mapping(address => mapping(bytes32 => uint256)) storage minted,
uint256[] storage tokenSupply,
bytes calldata signature,
ValidationArgs memory args,
uint256 cost
) public view {
address msgSender = _msgSender();
if (args.affiliate != address(0)) {
if (
args.affiliate == PLATFORM || args.affiliate == args.owner || args.affiliate == msgSender
) {
revert InvalidReferral();
}
validateAffiliate(args.affiliate, signature, config.affiliateSigner);
}
if (i.limit == 0) {
revert MintingPaused();
}
if (!verify(auth, i.tokenAddress, msgSender)) {
revert WalletUnauthorizedToMint();
}
if (block.timestamp < i.start) {
revert MintNotYetStarted();
}
if (i.end > i.start && block.timestamp > i.end) {
revert MintEnded();
}
uint256 totalQuantity = 0;
for (uint256 j = 0; j < args.quantities.length; j++) {
totalQuantity += args.quantities[j];
}
{
uint256 totalAfterMint;
if (i.limit < i.maxSupply) {
totalAfterMint = minted[msgSender][auth.key] + totalQuantity;
if (totalAfterMint > i.limit) {
revert NumberOfMintsExceeded();
}
}
if (i.maxSupply < UINT32_MAX) {
totalAfterMint = args.listSupply + totalQuantity;
if (totalAfterMint > i.maxSupply) {
revert ListMaxSupplyExceeded();
}
}
}
uint256[] memory checked = new uint256[](tokenSupply.length);
for (uint256 j = 0; j < args.tokenIds.length; j++) {
uint256 tokenId = args.tokenIds[j];
if (i.tokenIds.length != 0) {
bool isValid = false;
for (uint256 k = 0; k < i.tokenIds.length; k++) {
if (tokenId == i.tokenIds[k]) {
isValid = true;
break;
}
}
if (!isValid) {
revert InvalidTokenId();
}
}
if (
(tokenSupply[tokenId - 1] + checked[tokenId - 1] + args.quantities[j]) >
config.maxSupply[tokenId - 1]
) {
revert MaxSupplyExceeded();
}
checked[tokenId - 1] += args.quantities[j];
}
if (totalQuantity > config.maxBatchSize) {
revert MaxBatchSizeExceeded();
}
if (i.tokenAddress != address(0)) {
IERC20 erc20Token = IERC20(i.tokenAddress);
if (erc20Token.allowance(msgSender, address(this)) < cost) {
revert NotApprovedToTransfer();
}
if (erc20Token.balanceOf(msgSender) < cost) {
revert Erc20BalanceTooLow();
}
if (msg.value != 0) {
revert ExcessiveEthSent();
}
} else {
if (msg.value < cost) {
revert InsufficientEthSent();
}
}
}
function updateBalances(
AdvancedInvite storage i,
Config storage config,
mapping(address => uint128) storage _ownerBalance,
mapping(address => mapping(address => uint128)) storage _affiliateBalance,
address affiliate,
uint256 quantity,
uint128 value
) public {
address tokenAddress = i.tokenAddress;
uint128 affiliateWad;
if (affiliate != address(0)) {
affiliateWad = (value * config.affiliateFee) / 10000;
_affiliateBalance[affiliate][tokenAddress] += affiliateWad;
emit Referral(affiliate, tokenAddress, affiliateWad, quantity);
}
uint128 balance = _ownerBalance[tokenAddress];
uint128 ownerWad = value - affiliateWad;
_ownerBalance[tokenAddress] = balance + ownerWad;
if (tokenAddress != address(0)) {
IERC20 erc20Token = IERC20(tokenAddress);
erc20Token.safeTransferFrom(_msgSender(), address(this), value);
}
}
function withdrawTokensAffiliate(
mapping(address => mapping(address => uint128)) storage _affiliateBalance,
address[] calldata tokens
) public {
address msgSender = _msgSender();
for (uint256 i; i < tokens.length; i++) {
address tokenAddress = tokens[i];
uint128 wad = _affiliateBalance[msgSender][tokenAddress];
_affiliateBalance[msgSender][tokenAddress] = 0;
if (wad == 0) {
revert BalanceEmpty();
}
if (tokenAddress == address(0)) {
bool success = false;
(success, ) = msgSender.call{ value: wad }("");
if (!success) {
revert TransferFailed();
}
} else {
IERC20 erc20Token = IERC20(tokenAddress);
erc20Token.safeTransfer(msgSender, wad);
}
emit Withdrawal(msgSender, tokenAddress, wad);
}
}
function withdrawTokens(
PayoutConfig storage payoutConfig,
mapping(address => uint128) storage _ownerBalance,
address owner,
address[] calldata tokens
) public {
address msgSender = _msgSender();
for (uint256 i; i < tokens.length; i++) {
address tokenAddress = tokens[i];
uint128 wad;
if (
msgSender == owner ||
msgSender == PLATFORM ||
msgSender == payoutConfig.partner ||
msgSender == payoutConfig.superAffiliate ||
msgSender == payoutConfig.ownerAltPayout
) {
wad = _ownerBalance[tokenAddress];
_ownerBalance[tokenAddress] = 0;
} else {
revert NotShareholder();
}
if (wad == 0) {
revert BalanceEmpty();
}
address ownerPayout = owner;
if (payoutConfig.ownerAltPayout != address(0)) {
ownerPayout = payoutConfig.ownerAltPayout;
}
uint256 ownerShare = (uint256(wad) * payoutConfig.ownerBps) / 10000;
uint256 remainingShare = wad - ownerShare;
if (tokenAddress == address(0)) {
(bool success, ) = payable(ownerPayout).call{ value: ownerShare }("");
if (!success) revert TransferFailed();
} else {
IERC20(tokenAddress).safeTransfer(ownerPayout, ownerShare);
}
address[] memory recipients = new address[](3);
recipients[0] = PLATFORM;
recipients[1] = payoutConfig.partner;
recipients[2] = payoutConfig.superAffiliate;
uint16[] memory splits = new uint16[](3);
uint16 remainingBps = 10000 - payoutConfig.ownerBps;
splits[1] = uint16((uint256(payoutConfig.partnerBps) * 10000) / remainingBps);
splits[2] = uint16((uint256(payoutConfig.superAffiliateBps) * 10000) / remainingBps);
splits[0] = 10000 - splits[1] - splits[2];
if (tokenAddress == address(0)) {
ArchetypePayouts(PAYOUTS).updateBalances{ value: remainingShare }(
remainingShare,
tokenAddress,
recipients,
splits
);
} else {
ArchetypePayouts(PAYOUTS).updateBalances(
remainingShare,
tokenAddress,
recipients,
splits
);
}
emit Withdrawal(msgSender, tokenAddress, wad);
}
}
function validateAffiliate(
address affiliate,
bytes calldata signature,
address affiliateSigner
) public view {
bytes32 signedMessagehash = ECDSA.toEthSignedMessageHash(
keccak256(abi.encodePacked(affiliate))
);
address signer = ECDSA.recover(signedMessagehash, signature);
if (signer != affiliateSigner) {
revert InvalidSignature();
}
}
function verify(
Auth calldata auth,
address tokenAddress,
address account
) public pure returns (bool) {
// keys 0-255 and tokenAddress are public
if (uint256(auth.key) <= 0xff || auth.key == keccak256(abi.encodePacked(tokenAddress))) {
return true;
}
return MerkleProofLib.verify(auth.proof, auth.key, keccak256(abi.encodePacked(account)));
}
function _msgSender() internal view returns (address) {
return msg.sender == BATCH ? tx.origin : msg.sender;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Gas optimized ECDSA wrapper.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ECDSA.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ECDSA.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol)
///
/// @dev Note:
/// - The recovery functions use the ecrecover precompile (0x1).
/// - As of Solady version 0.0.68, the `recover` variants will revert upon recovery failure.
/// This is for more safety by default.
/// Use the `tryRecover` variants if you need to get the zero address back
/// upon recovery failure instead.
/// - As of Solady version 0.0.134, all `bytes signature` variants accept both
/// regular 65-byte `(r, s, v)` and EIP-2098 `(r, vs)` short form signatures.
/// See: https://eips.ethereum.org/EIPS/eip-2098
/// This is for calldata efficiency on smart accounts prevalent on L2s.
///
/// WARNING! Do NOT directly use signatures as unique identifiers:
/// - The recovery operations do NOT check if a signature is non-malleable.
/// - Use a nonce in the digest to prevent replay attacks on the same contract.
/// - Use EIP-712 for the digest to prevent replay attacks across different chains and contracts.
/// EIP-712 also enables readable signing of typed data for better user safety.
/// - If you need a unique hash from a signature, please use the `canonicalHash` functions.
library ECDSA {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The order of the secp256k1 elliptic curve.
uint256 internal constant N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141;
/// @dev `N/2 + 1`. Used for checking the malleability of the signature.
uint256 private constant _HALF_N_PLUS_1 =
0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a1;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The signature is invalid.
error InvalidSignature();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* RECOVERY OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
function recover(bytes32 hash, bytes memory signature) internal view returns (address result) {
/// @solidity memory-safe-assembly
assembly {
result := 1
let m := mload(0x40) // Cache the free memory pointer.
for {} 1 {} {
mstore(0x00, hash)
mstore(0x40, mload(add(signature, 0x20))) // `r`.
if eq(mload(signature), 64) {
let vs := mload(add(signature, 0x40))
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x60, shr(1, shl(1, vs))) // `s`.
break
}
if eq(mload(signature), 65) {
mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`.
mstore(0x60, mload(add(signature, 0x40))) // `s`.
break
}
result := 0
break
}
result :=
mload(
staticcall(
gas(), // Amount of gas left for the transaction.
result, // Address of `ecrecover`.
0x00, // Start of input.
0x80, // Size of input.
0x01, // Start of output.
0x20 // Size of output.
)
)
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
if iszero(returndatasize()) {
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
revert(0x1c, 0x04)
}
mstore(0x60, 0) // Restore the zero slot.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
function recoverCalldata(bytes32 hash, bytes calldata signature)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
result := 1
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, hash)
for {} 1 {} {
if eq(signature.length, 64) {
let vs := calldataload(add(signature.offset, 0x20))
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x40, calldataload(signature.offset)) // `r`.
mstore(0x60, shr(1, shl(1, vs))) // `s`.
break
}
if eq(signature.length, 65) {
mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`.
calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`.
break
}
result := 0
break
}
result :=
mload(
staticcall(
gas(), // Amount of gas left for the transaction.
result, // Address of `ecrecover`.
0x00, // Start of input.
0x80, // Size of input.
0x01, // Start of output.
0x20 // Size of output.
)
)
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
if iszero(returndatasize()) {
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
revert(0x1c, 0x04)
}
mstore(0x60, 0) // Restore the zero slot.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Recovers the signer's address from a message digest `hash`,
/// and the EIP-2098 short form signature defined by `r` and `vs`.
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal view returns (address result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, hash)
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x40, r)
mstore(0x60, shr(1, shl(1, vs))) // `s`.
result :=
mload(
staticcall(
gas(), // Amount of gas left for the transaction.
1, // Address of `ecrecover`.
0x00, // Start of input.
0x80, // Size of input.
0x01, // Start of output.
0x20 // Size of output.
)
)
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
if iszero(returndatasize()) {
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
revert(0x1c, 0x04)
}
mstore(0x60, 0) // Restore the zero slot.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Recovers the signer's address from a message digest `hash`,
/// and the signature defined by `v`, `r`, `s`.
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, hash)
mstore(0x20, and(v, 0xff))
mstore(0x40, r)
mstore(0x60, s)
result :=
mload(
staticcall(
gas(), // Amount of gas left for the transaction.
1, // Address of `ecrecover`.
0x00, // Start of input.
0x80, // Size of input.
0x01, // Start of output.
0x20 // Size of output.
)
)
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
if iszero(returndatasize()) {
mstore(0x00, 0x8baa579f) // `InvalidSignature()`.
revert(0x1c, 0x04)
}
mstore(0x60, 0) // Restore the zero slot.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* TRY-RECOVER OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// WARNING!
// These functions will NOT revert upon recovery failure.
// Instead, they will return the zero address upon recovery failure.
// It is critical that the returned address is NEVER compared against
// a zero address (e.g. an uninitialized address variable).
/// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
function tryRecover(bytes32 hash, bytes memory signature)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
result := 1
let m := mload(0x40) // Cache the free memory pointer.
for {} 1 {} {
mstore(0x00, hash)
mstore(0x40, mload(add(signature, 0x20))) // `r`.
if eq(mload(signature), 64) {
let vs := mload(add(signature, 0x40))
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x60, shr(1, shl(1, vs))) // `s`.
break
}
if eq(mload(signature), 65) {
mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`.
mstore(0x60, mload(add(signature, 0x40))) // `s`.
break
}
result := 0
break
}
pop(
staticcall(
gas(), // Amount of gas left for the transaction.
result, // Address of `ecrecover`.
0x00, // Start of input.
0x80, // Size of input.
0x40, // Start of output.
0x20 // Size of output.
)
)
mstore(0x60, 0) // Restore the zero slot.
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
result := mload(xor(0x60, returndatasize()))
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Recovers the signer's address from a message digest `hash`, and the `signature`.
function tryRecoverCalldata(bytes32 hash, bytes calldata signature)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
result := 1
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, hash)
for {} 1 {} {
if eq(signature.length, 64) {
let vs := calldataload(add(signature.offset, 0x20))
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x40, calldataload(signature.offset)) // `r`.
mstore(0x60, shr(1, shl(1, vs))) // `s`.
break
}
if eq(signature.length, 65) {
mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`.
calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`.
break
}
result := 0
break
}
pop(
staticcall(
gas(), // Amount of gas left for the transaction.
result, // Address of `ecrecover`.
0x00, // Start of input.
0x80, // Size of input.
0x40, // Start of output.
0x20 // Size of output.
)
)
mstore(0x60, 0) // Restore the zero slot.
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
result := mload(xor(0x60, returndatasize()))
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Recovers the signer's address from a message digest `hash`,
/// and the EIP-2098 short form signature defined by `r` and `vs`.
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, hash)
mstore(0x20, add(shr(255, vs), 27)) // `v`.
mstore(0x40, r)
mstore(0x60, shr(1, shl(1, vs))) // `s`.
pop(
staticcall(
gas(), // Amount of gas left for the transaction.
1, // Address of `ecrecover`.
0x00, // Start of input.
0x80, // Size of input.
0x40, // Start of output.
0x20 // Size of output.
)
)
mstore(0x60, 0) // Restore the zero slot.
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
result := mload(xor(0x60, returndatasize()))
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Recovers the signer's address from a message digest `hash`,
/// and the signature defined by `v`, `r`, `s`.
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s)
internal
view
returns (address result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x00, hash)
mstore(0x20, and(v, 0xff))
mstore(0x40, r)
mstore(0x60, s)
pop(
staticcall(
gas(), // Amount of gas left for the transaction.
1, // Address of `ecrecover`.
0x00, // Start of input.
0x80, // Size of input.
0x40, // Start of output.
0x20 // Size of output.
)
)
mstore(0x60, 0) // Restore the zero slot.
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
result := mload(xor(0x60, returndatasize()))
mstore(0x40, m) // Restore the free memory pointer.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* HASHING OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns an Ethereum Signed Message, created from a `hash`.
/// This produces a hash corresponding to the one signed with the
/// [`eth_sign`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign)
/// JSON-RPC method as part of EIP-191.
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x20, hash) // Store into scratch space for keccak256.
mstore(0x00, "\x00\x00\x00\x00\x19Ethereum Signed Message:\n32") // 28 bytes.
result := keccak256(0x04, 0x3c) // `32 * 2 - (32 - 28) = 60 = 0x3c`.
}
}
/// @dev Returns an Ethereum Signed Message, created from `s`.
/// This produces a hash corresponding to the one signed with the
/// [`eth_sign`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign)
/// JSON-RPC method as part of EIP-191.
/// Note: Supports lengths of `s` up to 999999 bytes.
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let sLength := mload(s)
let o := 0x20
mstore(o, "\x19Ethereum Signed Message:\n") // 26 bytes, zero-right-padded.
mstore(0x00, 0x00)
// Convert the `s.length` to ASCII decimal representation: `base10(s.length)`.
for { let temp := sLength } 1 {} {
o := sub(o, 1)
mstore8(o, add(48, mod(temp, 10)))
temp := div(temp, 10)
if iszero(temp) { break }
}
let n := sub(0x3a, o) // Header length: `26 + 32 - o`.
// Throw an out-of-offset error (consumes all gas) if the header exceeds 32 bytes.
returndatacopy(returndatasize(), returndatasize(), gt(n, 0x20))
mstore(s, or(mload(0x00), mload(n))) // Temporarily store the header.
result := keccak256(add(s, sub(0x20, n)), add(n, sLength))
mstore(s, sLength) // Restore the length.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CANONICAL HASH FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// The following functions returns the hash of the signature in it's canonicalized format,
// which is the 65-byte `abi.encodePacked(r, s, uint8(v))`, where `v` is either 27 or 28.
// If `s` is greater than `N / 2` then it will be converted to `N - s`
// and the `v` value will be flipped.
// If the signature has an invalid length, or if `v` is invalid,
// a uniquely corrupt hash will be returned.
// These functions are useful for "poor-mans-VRF".
/// @dev Returns the canonical hash of `signature`.
function canonicalHash(bytes memory signature) internal pure returns (bytes32 result) {
// @solidity memory-safe-assembly
assembly {
let l := mload(signature)
for {} 1 {} {
mstore(0x00, mload(add(signature, 0x20))) // `r`.
let s := mload(add(signature, 0x40))
let v := mload(add(signature, 0x41))
if eq(l, 64) {
v := add(shr(255, s), 27)
s := shr(1, shl(1, s))
}
if iszero(lt(s, _HALF_N_PLUS_1)) {
v := xor(v, 7)
s := sub(N, s)
}
mstore(0x21, v)
mstore(0x20, s)
result := keccak256(0x00, 0x41)
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
break
}
// If the length is neither 64 nor 65, return a uniquely corrupted hash.
if iszero(lt(sub(l, 64), 2)) {
// `bytes4(keccak256("InvalidSignatureLength"))`.
result := xor(keccak256(add(signature, 0x20), l), 0xd62f1ab2)
}
}
}
/// @dev Returns the canonical hash of `signature`.
function canonicalHashCalldata(bytes calldata signature)
internal
pure
returns (bytes32 result)
{
// @solidity memory-safe-assembly
assembly {
let l := signature.length
for {} 1 {} {
mstore(0x00, calldataload(signature.offset)) // `r`.
let s := calldataload(add(signature.offset, 0x20))
let v := calldataload(add(signature.offset, 0x21))
if eq(l, 64) {
v := add(shr(255, s), 27)
s := shr(1, shl(1, s))
}
if iszero(lt(s, _HALF_N_PLUS_1)) {
v := xor(v, 7)
s := sub(N, s)
}
mstore(0x21, v)
mstore(0x20, s)
result := keccak256(0x00, 0x41)
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
break
}
// If the length is neither 64 nor 65, return a uniquely corrupted hash.
if iszero(lt(sub(l, 64), 2)) {
calldatacopy(mload(0x40), signature.offset, l)
// `bytes4(keccak256("InvalidSignatureLength"))`.
result := xor(keccak256(mload(0x40), l), 0xd62f1ab2)
}
}
}
/// @dev Returns the canonical hash of `signature`.
function canonicalHash(bytes32 r, bytes32 vs) internal pure returns (bytes32 result) {
// @solidity memory-safe-assembly
assembly {
mstore(0x00, r) // `r`.
let v := add(shr(255, vs), 27)
let s := shr(1, shl(1, vs))
mstore(0x21, v)
mstore(0x20, s)
result := keccak256(0x00, 0x41)
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
}
}
/// @dev Returns the canonical hash of `signature`.
function canonicalHash(uint8 v, bytes32 r, bytes32 s) internal pure returns (bytes32 result) {
// @solidity memory-safe-assembly
assembly {
mstore(0x00, r) // `r`.
if iszero(lt(s, _HALF_N_PLUS_1)) {
v := xor(v, 7)
s := sub(N, s)
}
mstore(0x21, v)
mstore(0x20, s)
result := keccak256(0x00, 0x41)
mstore(0x21, 0) // Restore the overwritten part of the free memory pointer.
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EMPTY CALLDATA HELPERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns an empty calldata bytes.
function emptySignature() internal pure returns (bytes calldata signature) {
/// @solidity memory-safe-assembly
assembly {
signature.length := 0
}
}
}// 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();
/// @dev The input string must be a 7-bit ASCII.
error StringNot7BitASCII();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The constant returned when the `search` is not found in the string.
uint256 internal constant NOT_FOUND = type(uint256).max;
/// @dev Lookup for '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.
uint128 internal constant ALPHANUMERIC_7_BIT_ASCII = 0x7fffffe07fffffe03ff000000000000;
/// @dev Lookup for 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.
uint128 internal constant LETTERS_7_BIT_ASCII = 0x7fffffe07fffffe0000000000000000;
/// @dev Lookup for 'abcdefghijklmnopqrstuvwxyz'.
uint128 internal constant LOWERCASE_7_BIT_ASCII = 0x7fffffe000000000000000000000000;
/// @dev Lookup for 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
uint128 internal constant UPPERCASE_7_BIT_ASCII = 0x7fffffe0000000000000000;
/// @dev Lookup for '0123456789'.
uint128 internal constant DIGITS_7_BIT_ASCII = 0x3ff000000000000;
/// @dev Lookup for '0123456789abcdefABCDEF'.
uint128 internal constant HEXDIGITS_7_BIT_ASCII = 0x7e0000007e03ff000000000000;
/// @dev Lookup for '01234567'.
uint128 internal constant OCTDIGITS_7_BIT_ASCII = 0xff000000000000;
/// @dev Lookup for '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'.
uint128 internal constant PRINTABLE_7_BIT_ASCII = 0x7fffffffffffffffffffffff00003e00;
/// @dev Lookup for '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'.
uint128 internal constant PUNCTUATION_7_BIT_ASCII = 0x78000001f8000001fc00fffe00000000;
/// @dev Lookup for ' \t\n\r\x0b\x0c'.
uint128 internal constant WHITESPACE_7_BIT_ASCII = 0x100003e00;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* DECIMAL OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the base 10 decimal representation of `value`.
function toString(uint256 value) internal pure returns (string memory result) {
/// @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.
result := add(mload(0x40), 0x80)
mstore(0x40, add(result, 0x20)) // Allocate memory.
mstore(result, 0) // Zeroize the slot after the string.
let end := result // Cache the end of the memory to calculate the length later.
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 {} {
result := add(result, w) // `sub(result, 1)`.
// Store the character to the pointer.
// The ASCII index of the '0' character is 48.
mstore8(result, add(48, mod(temp, 10)))
temp := div(temp, 10) // Keep dividing `temp` until zero.
if iszero(temp) { break }
}
let n := sub(end, result)
result := sub(result, 0x20) // Move the pointer 32 bytes back to make room for the length.
mstore(result, n) // Store the length.
}
}
/// @dev Returns the base 10 decimal representation of `value`.
function toString(int256 value) internal pure returns (string memory result) {
if (value >= 0) return toString(uint256(value));
unchecked {
result = 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 n := mload(result) // Load the string length.
mstore(result, 0x2d) // Store the '-' character.
result := sub(result, 1) // Move back the string pointer by a byte.
mstore(result, add(n, 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 result)
{
result = toHexStringNoPrefix(value, length);
/// @solidity memory-safe-assembly
assembly {
let n := add(mload(result), 2) // Compute the length.
mstore(result, 0x3078) // Store the "0x" prefix.
result := sub(result, 2) // Move the pointer.
mstore(result, n) // Store the length.
}
}
/// @dev Returns the hexadecimal representation of `value`,
/// left-padded to an input length of `length` bytes.
/// The output is not prefixed with "0x" and is 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 result)
{
/// @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.
result := add(mload(0x40), and(add(shl(1, length), 0x42), not(0x1f)))
mstore(0x40, add(result, 0x20)) // Allocate memory.
mstore(result, 0) // Zeroize the slot after the string.
let end := result // Cache the end to calculate the length later.
// Store "0123456789abcdef" in scratch space.
mstore(0x0f, 0x30313233343536373839616263646566)
let start := sub(result, 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 {} {
result := add(result, w) // `sub(result, 2)`.
mstore8(add(result, 1), mload(and(temp, 15)))
mstore8(result, mload(and(shr(4, temp), 15)))
temp := shr(8, temp)
if iszero(xor(result, start)) { break }
}
if temp {
mstore(0x00, 0x2194895a) // `HexLengthInsufficient()`.
revert(0x1c, 0x04)
}
let n := sub(end, result)
result := sub(result, 0x20)
mstore(result, n) // Store the length.
}
}
/// @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 result) {
result = toHexStringNoPrefix(value);
/// @solidity memory-safe-assembly
assembly {
let n := add(mload(result), 2) // Compute the length.
mstore(result, 0x3078) // Store the "0x" prefix.
result := sub(result, 2) // Move the pointer.
mstore(result, n) // Store 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 result) {
result = toHexStringNoPrefix(value);
/// @solidity memory-safe-assembly
assembly {
let o := eq(byte(0, mload(add(result, 0x20))), 0x30) // Whether leading zero is present.
let n := add(mload(result), 2) // Compute the length.
mstore(add(result, o), 0x3078) // Store the "0x" prefix, accounting for leading zero.
result := sub(add(result, o), 2) // Move the pointer, accounting for leading zero.
mstore(result, sub(n, o)) // Store 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 result)
{
result = toHexStringNoPrefix(value);
/// @solidity memory-safe-assembly
assembly {
let o := eq(byte(0, mload(add(result, 0x20))), 0x30) // Whether leading zero is present.
let n := mload(result) // Get the length.
result := add(result, o) // Move the pointer, accounting for leading zero.
mstore(result, sub(n, o)) // Store 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 result) {
/// @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.
result := add(mload(0x40), 0x80)
mstore(0x40, add(result, 0x20)) // Allocate memory.
mstore(result, 0) // Zeroize the slot after the string.
let end := result // Cache the end to calculate the length later.
mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup.
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 {} {
result := add(result, w) // `sub(result, 2)`.
mstore8(add(result, 1), mload(and(temp, 15)))
mstore8(result, mload(and(shr(4, temp), 15)))
temp := shr(8, temp)
if iszero(temp) { break }
}
let n := sub(end, result)
result := sub(result, 0x20)
mstore(result, n) // Store the length.
}
}
/// @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 result) {
result = toHexString(value);
/// @solidity memory-safe-assembly
assembly {
let mask := shl(6, div(not(0), 255)) // `0b010000000100000000 ...`
let o := add(result, 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 result) {
result = toHexStringNoPrefix(value);
/// @solidity memory-safe-assembly
assembly {
let n := add(mload(result), 2) // Compute the length.
mstore(result, 0x3078) // Store the "0x" prefix.
result := sub(result, 2) // Move the pointer.
mstore(result, n) // Store 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 result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40)
// Allocate 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(result, 0x80))
mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup.
result := add(result, 2)
mstore(result, 40) // Store the length.
let o := add(result, 0x20)
mstore(add(o, 40), 0) // Zeroize the slot after the string.
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 result) {
result = toHexStringNoPrefix(raw);
/// @solidity memory-safe-assembly
assembly {
let n := add(mload(result), 2) // Compute the length.
mstore(result, 0x3078) // Store the "0x" prefix.
result := sub(result, 2) // Move the pointer.
mstore(result, n) // Store 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 result) {
/// @solidity memory-safe-assembly
assembly {
let n := mload(raw)
result := add(mload(0x40), 2) // Skip 2 bytes for the optional prefix.
mstore(result, add(n, n)) // Store the length of the output.
mstore(0x0f, 0x30313233343536373839616263646566) // Store the "0123456789abcdef" lookup.
let o := add(result, 0x20)
let end := add(raw, n)
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 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 {
result := 1
let mask := shl(7, div(not(0), 255))
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)
}
}
}
/// @dev Returns if this string is a 7-bit ASCII string,
/// AND all characters are in the `allowed` lookup.
/// Note: If `s` is empty, returns true regardless of `allowed`.
function is7BitASCII(string memory s, uint128 allowed) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
result := 1
if mload(s) {
let allowed_ := shr(128, shl(128, allowed))
let o := add(s, 0x20)
for { let end := add(o, mload(s)) } 1 {} {
result := and(result, shr(byte(0, mload(o)), allowed_))
o := add(o, 1)
if iszero(and(result, lt(o, end))) { break }
}
}
}
}
/// @dev Converts the bytes in the 7-bit ASCII string `s` to
/// an allowed lookup for use in `is7BitASCII(s, allowed)`.
/// To save runtime gas, you can cache the result in an immutable variable.
function to7BitASCIIAllowedLookup(string memory s) internal pure returns (uint128 result) {
/// @solidity memory-safe-assembly
assembly {
if mload(s) {
let o := add(s, 0x20)
for { let end := add(o, mload(s)) } 1 {} {
result := or(result, shl(byte(0, mload(o)), 1))
o := add(o, 1)
if iszero(lt(o, end)) { break }
}
if shr(128, result) {
mstore(0x00, 0xc9807e0d) // `StringNot7BitASCII()`.
revert(0x1c, 0x04)
}
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* 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 `needle` replaced with `replacement`.
function replace(string memory subject, string memory needle, string memory replacement)
internal
pure
returns (string memory result)
{
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40)
let needleLen := mload(needle)
let replacementLen := mload(replacement)
let d := sub(result, subject) // Memory difference.
let i := add(subject, 0x20) // Subject bytes pointer.
let end := add(i, mload(subject))
if iszero(gt(needleLen, mload(subject))) {
let subjectSearchEnd := add(sub(end, needleLen), 1)
let h := 0 // The hash of `needle`.
if iszero(lt(needleLen, 0x20)) { h := keccak256(add(needle, 0x20), needleLen) }
let s := mload(add(needle, 0x20))
for { let m := shl(3, sub(0x20, and(needleLen, 0x1f))) } 1 {} {
let t := mload(i)
// Whether the first `needleLen % 32` bytes of `subject` and `needle` matches.
if iszero(shr(m, xor(t, s))) {
if h {
if iszero(eq(keccak256(i, needleLen), h)) {
mstore(add(i, d), t)
i := add(i, 1)
if iszero(lt(i, subjectSearchEnd)) { break }
continue
}
}
// Copy the `replacement` one word at a time.
for { let j := 0 } 1 {} {
mstore(add(add(i, d), j), mload(add(add(replacement, 0x20), j)))
j := add(j, 0x20)
if iszero(lt(j, replacementLen)) { break }
}
d := sub(add(d, replacementLen), needleLen)
if needleLen {
i := add(i, needleLen)
if iszero(lt(i, subjectSearchEnd)) { break }
continue
}
}
mstore(add(i, d), t)
i := add(i, 1)
if iszero(lt(i, subjectSearchEnd)) { break }
}
}
let n := add(sub(d, add(result, 0x20)), end)
// Copy the rest of the string one word at a time.
for {} lt(i, end) { i := add(i, 0x20) } { mstore(add(i, d), mload(i)) }
let o := add(i, d)
mstore(o, 0) // Zeroize the slot after the string.
mstore(0x40, add(o, 0x20)) // Allocate memory.
mstore(result, n) // Store the length.
}
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from left to right, starting from `from`.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function indexOf(string memory subject, string memory needle, uint256 from)
internal
pure
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
result := not(0) // Initialize to `NOT_FOUND`.
for { let subjectLen := mload(subject) } 1 {} {
if iszero(mload(needle)) {
result := from
if iszero(gt(from, subjectLen)) { break }
result := subjectLen
break
}
let needleLen := mload(needle)
let subjectStart := add(subject, 0x20)
subject := add(subjectStart, from)
let end := add(sub(add(subjectStart, subjectLen), needleLen), 1)
let m := shl(3, sub(0x20, and(needleLen, 0x1f)))
let s := mload(add(needle, 0x20))
if iszero(and(lt(subject, end), lt(from, subjectLen))) { break }
if iszero(lt(needleLen, 0x20)) {
for { let h := keccak256(add(needle, 0x20), needleLen) } 1 {} {
if iszero(shr(m, xor(mload(subject), s))) {
if eq(keccak256(subject, needleLen), 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 `needle` in `subject`,
/// needleing from left to right.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function indexOf(string memory subject, string memory needle)
internal
pure
returns (uint256 result)
{
result = indexOf(subject, needle, 0);
}
/// @dev Returns the byte index of the first location of `needle` in `subject`,
/// needleing from right to left, starting from `from`.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function lastIndexOf(string memory subject, string memory needle, uint256 from)
internal
pure
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
for {} 1 {} {
result := not(0) // Initialize to `NOT_FOUND`.
let needleLen := mload(needle)
if gt(needleLen, mload(subject)) { break }
let w := result
let fromMax := sub(mload(subject), needleLen)
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(needle, 0x20), needleLen) } 1 {} {
if eq(keccak256(subject, needleLen), 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 `needle` in `subject`,
/// needleing from right to left.
/// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `needle` is not found.
function lastIndexOf(string memory subject, string memory needle)
internal
pure
returns (uint256 result)
{
result = lastIndexOf(subject, needle, type(uint256).max);
}
/// @dev Returns true if `needle` is found in `subject`, false otherwise.
function contains(string memory subject, string memory needle) internal pure returns (bool) {
return indexOf(subject, needle) != NOT_FOUND;
}
/// @dev Returns whether `subject` starts with `needle`.
function startsWith(string memory subject, string memory needle)
internal
pure
returns (bool result)
{
/// @solidity memory-safe-assembly
assembly {
let needleLen := mload(needle)
// Just using keccak256 directly is actually cheaper.
// forgefmt: disable-next-item
result := and(
iszero(gt(needleLen, mload(subject))),
eq(
keccak256(add(subject, 0x20), needleLen),
keccak256(add(needle, 0x20), needleLen)
)
)
}
}
/// @dev Returns whether `subject` ends with `needle`.
function endsWith(string memory subject, string memory needle)
internal
pure
returns (bool result)
{
/// @solidity memory-safe-assembly
assembly {
let needleLen := mload(needle)
// Whether `needle` is not longer than `subject`.
let inRange := iszero(gt(needleLen, mload(subject)))
// Just using keccak256 directly is actually cheaper.
// forgefmt: disable-next-item
result := and(
eq(
keccak256(
// `subject + 0x20 + max(subjectLen - needleLen, 0)`.
add(add(subject, 0x20), mul(inRange, sub(mload(subject), needleLen))),
needleLen
),
keccak256(add(needle, 0x20), needleLen)
),
inRange
)
}
}
/// @dev Returns `subject` repeated `times`.
function repeat(string memory subject, uint256 times)
internal
pure
returns (string memory result)
{
/// @solidity memory-safe-assembly
assembly {
let subjectLen := mload(subject)
if iszero(or(iszero(times), iszero(subjectLen))) {
result := mload(0x40)
subject := add(subject, 0x20)
let o := add(result, 0x20)
for {} 1 {} {
// Copy the `subject` one word at a time.
for { let j := 0 } 1 {} {
mstore(add(o, j), mload(add(subject, j)))
j := add(j, 0x20)
if iszero(lt(j, subjectLen)) { break }
}
o := add(o, subjectLen)
times := sub(times, 1)
if iszero(times) { break }
}
mstore(o, 0) // Zeroize the slot after the string.
mstore(0x40, add(o, 0x20)) // Allocate memory.
mstore(result, sub(o, add(result, 0x20))) // Store the length.
}
}
}
/// @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 subjectLen := mload(subject)
if iszero(gt(subjectLen, end)) { end := subjectLen }
if iszero(gt(subjectLen, start)) { start := subjectLen }
if lt(start, end) {
result := mload(0x40)
let n := sub(end, start)
let i := add(subject, start)
let w := not(0x1f)
// Copy the `subject` one word at a time, backwards.
for { let j := and(add(n, 0x1f), w) } 1 {} {
mstore(add(result, j), mload(add(i, j)))
j := add(j, w) // `sub(j, 0x20)`.
if iszero(j) { break }
}
let o := add(add(result, 0x20), n)
mstore(o, 0) // Zeroize the slot after the string.
mstore(0x40, add(o, 0x20)) // Allocate memory.
mstore(result, n) // Store the length.
}
}
}
/// @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, type(uint256).max);
}
/// @dev Returns all the indices of `needle` in `subject`.
/// The indices are byte offsets.
function indicesOf(string memory subject, string memory needle)
internal
pure
returns (uint256[] memory result)
{
/// @solidity memory-safe-assembly
assembly {
let searchLen := mload(needle)
if iszero(gt(searchLen, mload(subject))) {
result := mload(0x40)
let i := add(subject, 0x20)
let o := add(result, 0x20)
let subjectSearchEnd := add(sub(add(i, mload(subject)), searchLen), 1)
let h := 0 // The hash of `needle`.
if iszero(lt(searchLen, 0x20)) { h := keccak256(add(needle, 0x20), searchLen) }
let s := mload(add(needle, 0x20))
for { let m := shl(3, sub(0x20, and(searchLen, 0x1f))) } 1 {} {
let t := mload(i)
// Whether the first `searchLen % 32` bytes of `subject` and `needle` matches.
if iszero(shr(m, xor(t, s))) {
if h {
if iszero(eq(keccak256(i, searchLen), h)) {
i := add(i, 1)
if iszero(lt(i, subjectSearchEnd)) { break }
continue
}
}
mstore(o, sub(i, add(subject, 0x20))) // Append to `result`.
o := add(o, 0x20)
i := add(i, searchLen) // Advance `i` by `searchLen`.
if searchLen {
if iszero(lt(i, subjectSearchEnd)) { break }
continue
}
}
i := add(i, 1)
if iszero(lt(i, subjectSearchEnd)) { break }
}
mstore(result, shr(5, sub(o, add(result, 0x20)))) // Store the length of `result`.
// Allocate memory for result.
// We allocate one more word, so this array can be recycled for {split}.
mstore(0x40, add(o, 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))
for { let prevIndex := 0 } 1 {} {
let index := mload(indexPtr)
mstore(indexPtr, 0x60)
if iszero(eq(index, prevIndex)) {
let element := mload(0x40)
let l := sub(index, prevIndex)
mstore(element, l) // Store the length of the element.
// Copy the `subject` one word at a time, backwards.
for { let o := and(add(l, 0x1f), w) } 1 {} {
mstore(add(element, o), mload(add(add(subject, prevIndex), o)))
o := add(o, w) // `sub(o, 0x20)`.
if iszero(o) { break }
}
mstore(add(add(element, 0x20), l), 0) // Zeroize the slot after the string.
// Allocate memory for the length and the bytes, rounded up to a multiple of 32.
mstore(0x40, add(element, and(add(l, 0x3f), w)))
mstore(indexPtr, element) // Store the `element` into the array.
}
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 {
result := mload(0x40)
let w := not(0x1f)
let aLen := mload(a)
// Copy `a` one word at a time, backwards.
for { let o := and(add(aLen, 0x20), w) } 1 {} {
mstore(add(result, o), mload(add(a, o)))
o := add(o, w) // `sub(o, 0x20)`.
if iszero(o) { break }
}
let bLen := mload(b)
let output := add(result, aLen)
// Copy `b` one word at a time, backwards.
for { let o := and(add(bLen, 0x20), w) } 1 {} {
mstore(add(output, o), mload(add(b, o)))
o := add(o, w) // `sub(o, 0x20)`.
if iszero(o) { break }
}
let totalLen := add(aLen, bLen)
let last := add(add(result, 0x20), totalLen)
mstore(last, 0) // Zeroize the slot after the string.
mstore(result, totalLen) // Store the length.
mstore(0x40, add(last, 0x20)) // Allocate memory.
}
}
/// @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 n := mload(subject)
if n {
result := mload(0x40)
let o := add(result, 0x20)
let d := sub(subject, result)
let flags := shl(add(70, shl(5, toUpper)), 0x3ffffff)
for { let end := add(o, n) } 1 {} {
let b := byte(0, mload(add(d, o)))
mstore8(o, xor(and(shr(b, flags), 0x20), b))
o := add(o, 1)
if eq(o, end) { break }
}
mstore(result, n) // Store the length.
mstore(o, 0) // Zeroize the slot after the string.
mstore(0x40, add(o, 0x20)) // Allocate 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) // Store the length.
let o := add(result, 0x20)
mstore(o, s) // Store the bytes of the string.
mstore(add(o, n), 0) // Zeroize the slot after the string.
mstore(0x40, add(result, 0x40)) // Allocate memory.
}
}
/// @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 {
result := mload(0x40)
let end := add(s, mload(s))
let o := add(result, 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 ""&'<>" 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(o, c)
o := add(o, 1)
continue
}
let t := shr(248, mload(c))
mstore(o, mload(and(t, 0x1f)))
o := add(o, shr(5, t))
}
mstore(o, 0) // Zeroize the slot after the string.
mstore(result, sub(o, add(result, 0x20))) // Store the length.
mstore(0x40, add(o, 0x20)) // Allocate 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 {
result := mload(0x40)
let o := add(result, 0x20)
if addDoubleQuotes {
mstore8(o, 34)
o := add(1, o)
}
// 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 { let end := add(s, mload(s)) } 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(o, c)
o := add(o, 1)
continue
}
mstore8(o, 0x5c) // "\\".
mstore8(add(o, 1), c)
o := add(o, 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(o, mload(0x19)) // "\\u00XX".
o := add(o, 6)
continue
}
mstore8(o, 0x5c) // "\\".
mstore8(add(o, 1), mload(add(c, 8)))
o := add(o, 2)
}
if addDoubleQuotes {
mstore8(o, 34)
o := add(1, o)
}
mstore(o, 0) // Zeroize the slot after the string.
mstore(result, sub(o, add(result, 0x20))) // Store the length.
mstore(0x40, add(o, 0x20)) // Allocate 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 Encodes `s` so that it can be safely used in a URI,
/// just like `encodeURIComponent` in JavaScript.
/// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
/// See: https://datatracker.ietf.org/doc/html/rfc2396
/// See: https://datatracker.ietf.org/doc/html/rfc3986
function encodeURIComponent(string memory s) internal pure returns (string memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40)
// Store "0123456789ABCDEF" in scratch space.
// Uppercased to be consistent with JavaScript's implementation.
mstore(0x0f, 0x30313233343536373839414243444546)
let o := add(result, 0x20)
for { let end := add(s, mload(s)) } iszero(eq(s, end)) {} {
s := add(s, 1)
let c := and(mload(s), 0xff)
// If not in `[0-9A-Z-a-z-_.!~*'()]`.
if iszero(and(1, shr(c, 0x47fffffe87fffffe03ff678200000000))) {
mstore8(o, 0x25) // '%'.
mstore8(add(o, 1), mload(and(shr(4, c), 15)))
mstore8(add(o, 2), mload(and(c, 15)))
o := add(o, 3)
continue
}
mstore8(o, c)
o := add(o, 1)
}
mstore(result, sub(o, add(result, 0x20))) // Store the length.
mstore(o, 0) // Zeroize the slot after the string.
mstore(0x40, add(o, 0x20)) // Allocate memory.
}
}
/// @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 {
result := mload(0x40) // Grab the free memory pointer.
mstore(0x40, add(result, 0x40)) // Allocate 2 words (1 for the length, 1 for the bytes).
mstore(result, 0) // Zeroize the length slot.
mstore(add(result, 0x1f), packed) // Store the length and bytes.
mstore(add(add(result, 0x20), mload(result)), 0) // Right pad with zeroes.
}
}
/// @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 aLen := mload(a)
// We don't need to zero right pad the strings,
// since this is our own custom non-standard packing scheme.
result :=
mul(
or( // Load the length and the bytes of `a` and `b`.
shl(shl(3, sub(0x1f, aLen)), mload(add(a, aLen))), mload(sub(add(b, 0x1e), aLen))),
// `totalLen != 0 && totalLen < 31`. Abuses underflow.
// Assumes that the lengths are valid and within the block gas limit.
lt(sub(add(aLen, mload(b)), 1), 0x1e)
)
}
}
/// @dev Unpacks strings packed using {packTwo}.
/// Returns the empty strings if `packed` is `bytes32(0)`.
/// If `packed` is not an output of {packTwo}, the output behavior is undefined.
function unpackTwo(bytes32 packed)
internal
pure
returns (string memory resultA, string memory resultB)
{
/// @solidity memory-safe-assembly
assembly {
resultA := mload(0x40) // Grab the free memory pointer.
resultB := add(resultA, 0x40)
// Allocate 2 words for each string (1 for the length, 1 for the byte). Total 4 words.
mstore(0x40, add(resultB, 0x40))
// Zeroize the length slots.
mstore(resultA, 0)
mstore(resultB, 0)
// Store the lengths and bytes.
mstore(add(resultA, 0x1f), packed)
mstore(add(resultB, 0x1f), mload(add(add(resultA, 0x20), mload(resultA))))
// Right pad with zeroes.
mstore(add(add(resultA, 0x20), mload(resultA)), 0)
mstore(add(add(resultB, 0x20), mload(resultB)), 0)
}
}
/// @dev Directly returns `a` without copying.
function directReturn(string memory a) internal pure {
assembly {
// Assumes that the string does not start from the scratch space.
let retStart := sub(a, 0x20)
let retUnpaddedSize := add(mload(a), 0x40)
// Right pad with zeroes. Just in case the string is produced
// by a method that doesn't zero right pad.
mstore(add(retStart, retUnpaddedSize), 0)
mstore(retStart, 0x20) // Store the return offset.
// End the transaction, returning the string.
return(retStart, and(not(0x1f), add(0x1f, retUnpaddedSize)))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Gas optimized verification of proof of inclusion for a leaf in a Merkle tree.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/MerkleProofLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/MerkleProofLib.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/MerkleProof.sol)
library MerkleProofLib {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* MERKLE PROOF VERIFICATION OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf)
internal
pure
returns (bool isValid)
{
/// @solidity memory-safe-assembly
assembly {
if mload(proof) {
// Initialize `offset` to the offset of `proof` elements in memory.
let offset := add(proof, 0x20)
// Left shift by 5 is equivalent to multiplying by 0x20.
let end := add(offset, shl(5, mload(proof)))
// Iterate over proof elements to compute root hash.
for {} 1 {} {
// Slot of `leaf` in scratch space.
// If the condition is true: 0x20, otherwise: 0x00.
let scratch := shl(5, gt(leaf, mload(offset)))
// Store elements to hash contiguously in scratch space.
// Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
mstore(scratch, leaf)
mstore(xor(scratch, 0x20), mload(offset))
// Reuse `leaf` to store the hash to reduce stack operations.
leaf := keccak256(0x00, 0x40)
offset := add(offset, 0x20)
if iszero(lt(offset, end)) { break }
}
}
isValid := eq(leaf, root)
}
}
/// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf)
internal
pure
returns (bool isValid)
{
/// @solidity memory-safe-assembly
assembly {
if proof.length {
// Left shift by 5 is equivalent to multiplying by 0x20.
let end := add(proof.offset, shl(5, proof.length))
// Initialize `offset` to the offset of `proof` in the calldata.
let offset := proof.offset
// Iterate over proof elements to compute root hash.
for {} 1 {} {
// Slot of `leaf` in scratch space.
// If the condition is true: 0x20, otherwise: 0x00.
let scratch := shl(5, gt(leaf, calldataload(offset)))
// Store elements to hash contiguously in scratch space.
// Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
mstore(scratch, leaf)
mstore(xor(scratch, 0x20), calldataload(offset))
// Reuse `leaf` to store the hash to reduce stack operations.
leaf := keccak256(0x00, 0x40)
offset := add(offset, 0x20)
if iszero(lt(offset, end)) { break }
}
}
isValid := eq(leaf, root)
}
}
/// @dev Returns whether all `leaves` exist in the Merkle tree with `root`,
/// given `proof` and `flags`.
///
/// Note:
/// - Breaking the invariant `flags.length == (leaves.length - 1) + proof.length`
/// will always return false.
/// - The sum of the lengths of `proof` and `leaves` must never overflow.
/// - Any non-zero word in the `flags` array is treated as true.
/// - The memory offset of `proof` must be non-zero
/// (i.e. `proof` is not pointing to the scratch space).
function verifyMultiProof(
bytes32[] memory proof,
bytes32 root,
bytes32[] memory leaves,
bool[] memory flags
) internal pure returns (bool isValid) {
// Rebuilds the root by consuming and producing values on a queue.
// The queue starts with the `leaves` array, and goes into a `hashes` array.
// After the process, the last element on the queue is verified
// to be equal to the `root`.
//
// The `flags` array denotes whether the sibling
// should be popped from the queue (`flag == true`), or
// should be popped from the `proof` (`flag == false`).
/// @solidity memory-safe-assembly
assembly {
// Cache the lengths of the arrays.
let leavesLength := mload(leaves)
let proofLength := mload(proof)
let flagsLength := mload(flags)
// Advance the pointers of the arrays to point to the data.
leaves := add(0x20, leaves)
proof := add(0x20, proof)
flags := add(0x20, flags)
// If the number of flags is correct.
for {} eq(add(leavesLength, proofLength), add(flagsLength, 1)) {} {
// For the case where `proof.length + leaves.length == 1`.
if iszero(flagsLength) {
// `isValid = (proof.length == 1 ? proof[0] : leaves[0]) == root`.
isValid := eq(mload(xor(leaves, mul(xor(proof, leaves), proofLength))), root)
break
}
// The required final proof offset if `flagsLength` is not zero, otherwise zero.
let proofEnd := add(proof, shl(5, proofLength))
// We can use the free memory space for the queue.
// We don't need to allocate, since the queue is temporary.
let hashesFront := mload(0x40)
// Copy the leaves into the hashes.
// Sometimes, a little memory expansion costs less than branching.
// Should cost less, even with a high free memory offset of 0x7d00.
leavesLength := shl(5, leavesLength)
for { let i := 0 } iszero(eq(i, leavesLength)) { i := add(i, 0x20) } {
mstore(add(hashesFront, i), mload(add(leaves, i)))
}
// Compute the back of the hashes.
let hashesBack := add(hashesFront, leavesLength)
// This is the end of the memory for the queue.
// We recycle `flagsLength` to save on stack variables (sometimes save gas).
flagsLength := add(hashesBack, shl(5, flagsLength))
for {} 1 {} {
// Pop from `hashes`.
let a := mload(hashesFront)
// Pop from `hashes`.
let b := mload(add(hashesFront, 0x20))
hashesFront := add(hashesFront, 0x40)
// If the flag is false, load the next proof,
// else, pops from the queue.
if iszero(mload(flags)) {
// Loads the next proof.
b := mload(proof)
proof := add(proof, 0x20)
// Unpop from `hashes`.
hashesFront := sub(hashesFront, 0x20)
}
// Advance to the next flag.
flags := add(flags, 0x20)
// Slot of `a` in scratch space.
// If the condition is true: 0x20, otherwise: 0x00.
let scratch := shl(5, gt(a, b))
// Hash the scratch space and push the result onto the queue.
mstore(scratch, a)
mstore(xor(scratch, 0x20), b)
mstore(hashesBack, keccak256(0x00, 0x40))
hashesBack := add(hashesBack, 0x20)
if iszero(lt(hashesBack, flagsLength)) { break }
}
isValid :=
and(
// Checks if the last value in the queue is same as the root.
eq(mload(sub(hashesBack, 0x20)), root),
// And whether all the proofs are used, if required.
eq(proofEnd, proof)
)
break
}
}
}
/// @dev Returns whether all `leaves` exist in the Merkle tree with `root`,
/// given `proof` and `flags`.
///
/// Note:
/// - Breaking the invariant `flags.length == (leaves.length - 1) + proof.length`
/// will always return false.
/// - Any non-zero word in the `flags` array is treated as true.
/// - The calldata offset of `proof` must be non-zero
/// (i.e. `proof` is from a regular Solidity function with a 4-byte selector).
function verifyMultiProofCalldata(
bytes32[] calldata proof,
bytes32 root,
bytes32[] calldata leaves,
bool[] calldata flags
) internal pure returns (bool isValid) {
// Rebuilds the root by consuming and producing values on a queue.
// The queue starts with the `leaves` array, and goes into a `hashes` array.
// After the process, the last element on the queue is verified
// to be equal to the `root`.
//
// The `flags` array denotes whether the sibling
// should be popped from the queue (`flag == true`), or
// should be popped from the `proof` (`flag == false`).
/// @solidity memory-safe-assembly
assembly {
// If the number of flags is correct.
for {} eq(add(leaves.length, proof.length), add(flags.length, 1)) {} {
// For the case where `proof.length + leaves.length == 1`.
if iszero(flags.length) {
// `isValid = (proof.length == 1 ? proof[0] : leaves[0]) == root`.
// forgefmt: disable-next-item
isValid := eq(
calldataload(
xor(leaves.offset, mul(xor(proof.offset, leaves.offset), proof.length))
),
root
)
break
}
// The required final proof offset if `flagsLength` is not zero, otherwise zero.
let proofEnd := add(proof.offset, shl(5, proof.length))
// We can use the free memory space for the queue.
// We don't need to allocate, since the queue is temporary.
let hashesFront := mload(0x40)
// Copy the leaves into the hashes.
// Sometimes, a little memory expansion costs less than branching.
// Should cost less, even with a high free memory offset of 0x7d00.
calldatacopy(hashesFront, leaves.offset, shl(5, leaves.length))
// Compute the back of the hashes.
let hashesBack := add(hashesFront, shl(5, leaves.length))
// This is the end of the memory for the queue.
// We recycle `flagsLength` to save on stack variables (sometimes save gas).
flags.length := add(hashesBack, shl(5, flags.length))
// We don't need to make a copy of `proof.offset` or `flags.offset`,
// as they are pass-by-value (this trick may not always save gas).
for {} 1 {} {
// Pop from `hashes`.
let a := mload(hashesFront)
// Pop from `hashes`.
let b := mload(add(hashesFront, 0x20))
hashesFront := add(hashesFront, 0x40)
// If the flag is false, load the next proof,
// else, pops from the queue.
if iszero(calldataload(flags.offset)) {
// Loads the next proof.
b := calldataload(proof.offset)
proof.offset := add(proof.offset, 0x20)
// Unpop from `hashes`.
hashesFront := sub(hashesFront, 0x20)
}
// Advance to the next flag offset.
flags.offset := add(flags.offset, 0x20)
// Slot of `a` in scratch space.
// If the condition is true: 0x20, otherwise: 0x00.
let scratch := shl(5, gt(a, b))
// Hash the scratch space and push the result onto the queue.
mstore(scratch, a)
mstore(xor(scratch, 0x20), b)
mstore(hashesBack, keccak256(0x00, 0x40))
hashesBack := add(hashesBack, 0x20)
if iszero(lt(hashesBack, flags.length)) { break }
}
isValid :=
and(
// Checks if the last value in the queue is same as the root.
eq(mload(sub(hashesBack, 0x20)), root),
// And whether all the proofs are used, if required.
eq(proofEnd, proof.offset)
)
break
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EMPTY CALLDATA HELPERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns an empty calldata bytes32 array.
function emptyProof() internal pure returns (bytes32[] calldata proof) {
/// @solidity memory-safe-assembly
assembly {
proof.length := 0
}
}
/// @dev Returns an empty calldata bytes32 array.
function emptyLeaves() internal pure returns (bytes32[] calldata leaves) {
/// @solidity memory-safe-assembly
assembly {
leaves.length := 0
}
}
/// @dev Returns an empty calldata bool array.
function emptyFlags() internal pure returns (bool[] calldata flags) {
/// @solidity memory-safe-assembly
assembly {
flags.length := 0
}
}
}{
"optimizer": {
"enabled": true,
"runs": 1
},
"metadata": {
"useLiteralContent": true
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {
"contracts/ERC1155/ArchetypeErc1155.sol": {
"ArchetypeLogicErc1155": "0xaeb8ec71de076d8ad24a85daccb161ca640415f0"
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"InvalidConfig","type":"error"},{"inputs":[],"name":"InvalidSplitShares","type":"error"},{"inputs":[],"name":"LockedForever","type":"error"},{"inputs":[],"name":"MaxSupplyExceeded","type":"error"},{"inputs":[],"name":"MintToZeroAddress","type":"error"},{"inputs":[],"name":"NotApprovedToTransfer","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"inputs":[],"name":"NotSupported","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"inputs":[],"name":"URIQueryForNonexistentToken","type":"error"},{"inputs":[],"name":"WrongPassword","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"key","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"cid","type":"bytes32"}],"name":"Invited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"affiliate","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint128","name":"wad","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"numMints","type":"uint256"}],"name":"Referral","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"src","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint128","name":"wad","type":"uint128"}],"name":"Withdrawal","type":"event"},{"inputs":[{"internalType":"address","name":"affiliate","type":"address"}],"name":"affiliateBalance","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"affiliate","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"affiliateBalanceToken","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bytes32","name":"key","type":"bytes32"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"internalType":"struct Auth","name":"auth","type":"tuple"},{"internalType":"address[]","name":"toList","type":"address[]"},{"internalType":"uint256[]","name":"quantityList","type":"uint256[]"},{"internalType":"uint256[]","name":"tokenIdList","type":"uint256[]"},{"internalType":"address","name":"affiliate","type":"address"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"batchMintTo","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"bool","name":"affiliateUsed","type":"bool"}],"name":"computePrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"config","outputs":[{"internalType":"string","name":"baseUri","type":"string"},{"internalType":"address","name":"affiliateSigner","type":"address"},{"internalType":"uint16","name":"maxBatchSize","type":"uint16"},{"internalType":"uint16","name":"affiliateFee","type":"uint16"},{"internalType":"uint16","name":"affiliateDiscount","type":"uint16"},{"internalType":"uint16","name":"defaultRoyalty","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"components":[{"internalType":"string","name":"baseUri","type":"string"},{"internalType":"address","name":"affiliateSigner","type":"address"},{"internalType":"uint32[]","name":"maxSupply","type":"uint32[]"},{"internalType":"uint16","name":"maxBatchSize","type":"uint16"},{"internalType":"uint16","name":"affiliateFee","type":"uint16"},{"internalType":"uint16","name":"affiliateDiscount","type":"uint16"},{"internalType":"uint16","name":"defaultRoyalty","type":"uint16"}],"internalType":"struct Config","name":"config_","type":"tuple"},{"components":[{"internalType":"uint16","name":"ownerBps","type":"uint16"},{"internalType":"uint16","name":"platformBps","type":"uint16"},{"internalType":"uint16","name":"partnerBps","type":"uint16"},{"internalType":"uint16","name":"superAffiliateBps","type":"uint16"},{"internalType":"address","name":"partner","type":"address"},{"internalType":"address","name":"superAffiliate","type":"address"},{"internalType":"address","name":"ownerAltPayout","type":"address"}],"internalType":"struct PayoutConfig","name":"payoutConfig_","type":"tuple"},{"internalType":"address","name":"_receiver","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"invites","outputs":[{"internalType":"uint128","name":"price","type":"uint128"},{"internalType":"uint128","name":"reservePrice","type":"uint128"},{"internalType":"uint128","name":"delta","type":"uint128"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"},{"internalType":"uint32","name":"limit","type":"uint32"},{"internalType":"uint32","name":"maxSupply","type":"uint32"},{"internalType":"uint32","name":"interval","type":"uint32"},{"internalType":"uint32","name":"unitSize","type":"uint32"},{"internalType":"address","name":"tokenAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"listSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"password","type":"string"}],"name":"lockAffiliateFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"password","type":"string"}],"name":"lockMaxSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"password","type":"string"}],"name":"lockOwnerAltPayout","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"password","type":"string"}],"name":"lockURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"maxSupply","outputs":[{"internalType":"uint32[]","name":"","type":"uint32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bytes32","name":"key","type":"bytes32"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"internalType":"struct Auth","name":"auth","type":"tuple"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"affiliate","type":"address"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"mintTo","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes32","name":"key","type":"bytes32"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"internalType":"struct Auth","name":"auth","type":"tuple"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"affiliate","type":"address"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"mintToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"minter","type":"address"},{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"minted","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"options","outputs":[{"internalType":"bool","name":"uriLocked","type":"bool"},{"internalType":"bool","name":"maxSupplyLocked","type":"bool"},{"internalType":"bool","name":"affiliateFeeLocked","type":"bool"},{"internalType":"bool","name":"ownerAltPayoutLocked","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ownerBalance","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"ownerBalanceToken","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"packedBonusDiscounts","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"payoutConfig","outputs":[{"internalType":"uint16","name":"ownerBps","type":"uint16"},{"internalType":"uint16","name":"platformBps","type":"uint16"},{"internalType":"uint16","name":"partnerBps","type":"uint16"},{"internalType":"uint16","name":"superAffiliateBps","type":"uint16"},{"internalType":"address","name":"partner","type":"address"},{"internalType":"address","name":"superAffiliate","type":"address"},{"internalType":"address","name":"ownerAltPayout","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"platform","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"},{"internalType":"bytes32","name":"_cid","type":"bytes32"},{"components":[{"internalType":"uint128","name":"price","type":"uint128"},{"internalType":"uint128","name":"reservePrice","type":"uint128"},{"internalType":"uint128","name":"delta","type":"uint128"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"},{"internalType":"uint32","name":"limit","type":"uint32"},{"internalType":"uint32","name":"maxSupply","type":"uint32"},{"internalType":"uint32","name":"interval","type":"uint32"},{"internalType":"uint32","name":"unitSize","type":"uint32"},{"internalType":"uint32[]","name":"tokenIds","type":"uint32[]"},{"internalType":"address","name":"tokenAddress","type":"address"}],"internalType":"struct AdvancedInvite","name":"_AdvancedInvite","type":"tuple"}],"name":"setAdvancedInvite","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"affiliateDiscount","type":"uint16"}],"name":"setAffiliateDiscount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"affiliateFee","type":"uint16"}],"name":"setAffiliateFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"baseUri","type":"string"}],"name":"setBaseURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint16","name":"feeNumerator","type":"uint16"}],"name":"setDefaultRoyalty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_key","type":"bytes32"},{"internalType":"bytes32","name":"_cid","type":"bytes32"},{"components":[{"internalType":"uint128","name":"price","type":"uint128"},{"internalType":"uint32","name":"start","type":"uint32"},{"internalType":"uint32","name":"end","type":"uint32"},{"internalType":"uint32","name":"limit","type":"uint32"},{"internalType":"uint32","name":"maxSupply","type":"uint32"},{"internalType":"uint32","name":"unitSize","type":"uint32"},{"internalType":"uint32[]","name":"tokenIds","type":"uint32[]"},{"internalType":"address","name":"tokenAddress","type":"address"}],"internalType":"struct Invite","name":"_invite","type":"tuple"}],"name":"setInvite","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"maxBatchSize","type":"uint16"}],"name":"setMaxBatchSize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32[]","name":"newMaxSupply","type":"uint32[]"},{"internalType":"string","name":"password","type":"string"}],"name":"setMaxSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"ownerAltPayout","type":"address"}],"name":"setOwnerAltPayout","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawAffiliate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"withdrawTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"withdrawTokensAffiliate","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
608060405234801561001057600080fd5b50614f07806100206000396000f3fe6080604052600436106102435760003560e01c8062fdd58e1461024857806301ffc9a71461027b57806306fdde03146102ab5780630c6f910b146102cd5780630e89341c146102ef5780631069143a1461030f57806315ec67201461037057806318160ddd146103855780631fff79b01461039a57806321d5bf24146103ad5780632693ebf21461041557806327a59437146104355780632a55205a146104745780632eb2c2d6146104a257806332f7c6d4146104c25780633ccfd60b146104e25780634331f639146104f75780634bde38c8146105175780634e1273f4146105525780635000d3d11461057f57806355f804b3146105925780635ecb16cd146105b2578063715018a6146105d257806379502c55146105e757806379b004db1461060e5780637c5d0a081461062e5780637ded18481461064e5780638b4795d6146106615780638da5cb5b1461068157806395d89b4114610696578063978a4509146106ab5780639a7a973c146106f6578063a22cb46514610723578063a3edb86a14610743578063a5aa4aa414610786578063aefc542814610892578063b2938bd4146108b2578063b581085b146108d2578063b68836fa146108f2578063ba7bc0221461091f578063bedcf0031461093f578063caf3e53214610985578063ce216e2f146109a5578063d4048441146109c5578063d5abeb0114610a70578063de6cd0db14610a92578063e985e9c514610ab2578063ead0055314610afb578063f242432a14610b1b578063f2fde38b14610b3b578063f588eb5014610b5b575b600080fd5b34801561025457600080fd5b506102686102633660046134ae565b610b7b565b6040519081526020015b60405180910390f35b34801561028757600080fd5b5061029b6102963660046134f0565b610c16565b6040519015158152602001610272565b3480156102b757600080fd5b506102c0610c30565b6040516102729190613564565b3480156102d957600080fd5b506102ed6102e8366004613587565b610cbf565b005b3480156102fb57600080fd5b506102c061030a3660046135a4565b610d3a565b34801561031b57600080fd5b50610109546103469060ff808216916101008104821691620100008204811691630100000090041684565b60408051941515855292151560208501529015159183019190915215156060820152608001610272565b34801561037c57600080fd5b506102ed610d9d565b34801561039157600080fd5b50610268610e00565b6102ed6103a8366004613610565b610e54565b3480156103b957600080fd5b506103fd6103c83660046136a1565b6001600160a01b039182166000908152610100602090815260408083209390941682529190915220546001600160801b031690565b6040516001600160801b039091168152602001610272565b34801561042157600080fd5b506102686104303660046135a4565b610e72565b34801561044157600080fd5b506103fd6104503660046136da565b6001600160a01b0316600090815260ff60205260409020546001600160801b031690565b34801561048057600080fd5b5061049461048f3660046136f7565b610eca565b604051610272929190613719565b3480156104ae57600080fd5b506102ed6104bd3660046138a4565b610f78565b3480156104ce57600080fd5b506102ed6104dd366004613951565b610fd6565b3480156104ee57600080fd5b506102ed610ffe565b34801561050357600080fd5b506102ed61051236600461398d565b61105e565b34801561052357600080fd5b507386b82972282dd22348374bc63fd21620f7ed847b5b6040516001600160a01b039091168152602001610272565b34801561055e57600080fd5b5061057261056d366004613a2a565b611096565b6040516102729190613ac8565b6102ed61058d366004613b1f565b6111bf565b34801561059e57600080fd5b506102ed6105ad366004613951565b611444565b3480156105be57600080fd5b506102ed6105cd366004613c1d565b61147e565b3480156105de57600080fd5b506102ed6114f1565b3480156105f357600080fd5b506105fc611505565b60405161027296959493929190613c51565b34801561061a57600080fd5b506102ed610629366004613587565b6115cf565b34801561063a57600080fd5b506102ed610649366004613951565b6115f0565b6102ed61065c366004613c9f565b611614565b34801561066d57600080fd5b506102ed61067c366004613587565b611872565b34801561068d57600080fd5b5061053a6118ef565b3480156106a257600080fd5b506102c06118fe565b3480156106b757600080fd5b506103fd6106c63660046136da565b6001600160a01b03166000908152610100602090815260408083208380529091529020546001600160801b031690565b34801561070257600080fd5b506102686107113660046135a4565b600090815260fe602052604090205490565b34801561072f57600080fd5b506102ed61073e366004613d53565b61190c565b34801561074f57600080fd5b5061026861075e3660046134ae565b6001600160a01b0391909116600090815260fd60209081526040808320938352929052205490565b34801561079257600080fd5b506108226107a13660046135a4565b60fb6020526000908152604090208054600182015460028301546004909301546001600160801b0380841694600160801b948590048216949184169391820463ffffffff90811693600160a01b8404821693600160c01b8104831693600160e01b90910483169280821692600160201b90920416906001600160a01b03168a565b604080516001600160801b039b8c168152998b1660208b0152979099169688019690965263ffffffff9485166060880152928416608087015290831660a0860152821660c0850152811660e0840152166101008201526001600160a01b0390911661012082015261014001610272565b34801561089e57600080fd5b506102ed6108ad366004613e24565b61191e565b3480156108be57600080fd5b506102ed6108cd366004613f56565b611b75565b3480156108de57600080fd5b506102ed6108ed366004613fc1565b611cfd565b3480156108fe57600080fd5b5061026861090d3660046135a4565b60fc6020526000908152604090205481565b34801561092b57600080fd5b506102ed61093a366004614071565b612028565b34801561094b57600080fd5b506000805260ff6020527f03d616f3758432b4d7452e2e9011612152589bfc903ce751686613c478b2af5f546001600160801b03166103fd565b34801561099157600080fd5b506102686109a03660046140c8565b612185565b3480156109b157600080fd5b506102ed6109c0366004613951565b612238565b3480156109d157600080fd5b50610106546101075461010854610a219261ffff80821693620100008304821693600160201b8404831693600160301b8104909316926001600160a01b03600160401b9091048116928116911687565b6040805161ffff98891681529688166020880152948716948601949094529190941660608401526001600160a01b039384166080840152831660a08301529190911660c082015260e001610272565b348015610a7c57600080fd5b50610a8561225e565b60405161027291906140f6565b348015610a9e57600080fd5b506102ed610aad366004613951565b6122e6565b348015610abe57600080fd5b5061029b610acd3660046136a1565b6001600160a01b03918216600090815260666020908152604080832093909416825291909152205460ff1690565b348015610b0757600080fd5b506102ed610b163660046136da565b612308565b348015610b2757600080fd5b506102ed610b36366004614140565b61235f565b348015610b4757600080fd5b506102ed610b563660046136da565b6123b6565b348015610b6757600080fd5b506102ed610b76366004613c1d565b61242c565b60006001600160a01b038316610beb5760405162461bcd60e51b815260206004820152602a60248201527f455243313135353a2061646472657373207a65726f206973206e6f742061207660448201526930b634b21037bbb732b960b11b60648201526084015b60405180910390fd5b5060008181526065602090815260408083206001600160a01b03861684529091529020545b92915050565b6000610c2182612467565b80610c105750610c10826124b7565b61010a8054610c3e906141a8565b80601f0160208091040260200160405190810160405280929190818152602001828054610c6a906141a8565b8015610cb75780601f10610c8c57610100808354040283529160200191610cb7565b820191906000526020600020905b815481529060010190602001808311610c9a57829003601f168201915b505050505081565b610cc76124dc565b6101095462010000900460ff1615610cf25760405163249fab5d60e01b815260040160405180910390fd5b61138861ffff82161115610d19576040516306b7c75960e31b815260040160405180910390fd5b610105805461ffff909216620100000263ffff000019909216919091179055565b60606101026000018054610d4d906141a8565b9050600003610d6b5760405180602001604052806000815250610c10565b610102610d778361251c565b604051602001610d889291906141dc565b60405160208183030381529060405292915050565b60408051600180825281830190925260009160208083019080368337019050509050600081600081518110610dd457610dd4614263565b60200260200101906001600160a01b031690816001600160a01b031681525050610dfd8161242c565b50565b600080805b61010154811015610e4e576101018181548110610e2457610e24614263565b906000526020600020015482610e3a919061428f565b915080610e46816142a2565b915050610e05565b50919050565b610e6a8686610e61612560565b87878787611614565b505050505050565b6000610e7d82612587565b610e9a57604051630a14c4b560e41b815260040160405180910390fd5b610101610ea86001846142bb565b81548110610eb857610eb8614263565b90600052602060002001549050919050565b600082815260ca602090815260408083208151808301909252546001600160a01b038116808352600160a01b9091046001600160601b0316928201929092528291610f3f57506040805180820190915260c9546001600160a01b0381168252600160a01b90046001600160601b031660208201525b602081015160009061271090610f5e906001600160601b0316876142ce565b610f6891906142e5565b91519350909150505b9250929050565b610f80612560565b6001600160a01b0316856001600160a01b03161480610fa65750610fa685610acd612560565b610fc25760405162461bcd60e51b8152600401610be290614307565b610fcf858585858561259d565b5050505050565b610fde6124dc565b610fe781612780565b50610109805463ff00000019166301000000179055565b6040805160018082528183019092526000916020808301908036833701905050905060008160008151811061103557611035614263565b60200260200101906001600160a01b031690816001600160a01b031681525050610dfd8161147e565b6110666124dc565b610105805461ffff60301b1916600160301b61ffff8416908102919091179091556110929083906127ea565b5050565b606081518351146110fb5760405162461bcd60e51b815260206004820152602960248201527f455243313135353a206163636f756e747320616e6420696473206c656e677468604482015268040dad2e6dac2e8c6d60bb1b6064820152608401610be2565b600083516001600160401b0381111561111657611116613732565b60405190808252806020026020018201604052801561113f578160200160208202803683370190505b50905060005b84518110156111b75761118a85828151811061116357611163614263565b602002602001015185838151811061117d5761117d614263565b6020026020010151610b7b565b82828151811061119c5761119c614263565b60209081029190910101526111b0816142a2565b9050611145565b509392505050565b85881415806111ce5750858414155b156111ec576040516306b7c75960e31b815260040160405180910390fd5b6000805b878110156112305788888281811061120a5761120a614263565b905060200201358261121c919061428f565b915080611228816142a2565b9150506111f0565b50611239613342565b6040518060c0016040528061124c6118ef565b6001600160a01b03168152602001866001600160a01b031681526020018a8a808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152505050908252506040805160208a810282810182019093528a82529283019290918b918b918291850190849080828437600092018290525093855250505060208083018690528f3580835260fe825260408084205494810194909452825260fb9052206002810154919250906001600160201b90910463ffffffff16111561133357604051630280e1e560e61b815260040160405180910390fd5b611341818e848989896128e3565b60005b8b8110156114345760606113b08e8e8481811061136357611363614263565b905060200201602081019061137891906136da565b8b8b8581811061138a5761138a614263565b905060200201358e8e868181106113a3576113a3614263565b9050602002013584612bb0565b8b8b838181106113c2576113c2614263565b9050602002013561010160018c8c868181106113e0576113e0614263565b905060200201356113f191906142bb565b8154811061140157611401614263565b90600052602060002001600082825461141a919061428f565b9091555082915061142c9050816142a2565b915050611344565b5050505050505050505050505050565b61144c612cb6565b6101095460ff16156114715760405163249fab5d60e01b815260040160405180910390fd5b61010261109282826143b8565b73aeb8ec71de076d8ad24a85daccb161ca640415f0638e1ab86661010660ff6114a56118ef565b856040518563ffffffff1660e01b81526004016114c594939291906144aa565b60006040518083038186803b1580156114dd57600080fd5b505af4158015610fcf573d6000803e3d6000fd5b6114f9612cb6565b6115036000612d25565b565b61010280548190611515906141a8565b80601f0160208091040260200160405190810160405280929190818152602001828054611541906141a8565b801561158e5780601f106115635761010080835404028352916020019161158e565b820191906000526020600020905b81548152906001019060200180831161157157829003601f168201915b505050600184015460039094015492936001600160a01b03169261ffff808216935062010000820481169250600160201b8204811691600160301b90041686565b6115d76124dc565b610105805461ffff191661ffff92909216919091179055565b6115f86124dc565b61160181612780565b50610109805461ff001916610100179055565b6001600160a01b03851661163a57604051622e076360e81b815260040160405180910390fd5b8635600090815260fb6020526040902060028101546001600160201b90910463ffffffff16111561168457600281015461168190600160201b900463ffffffff16886142ce565b96505b61168c613342565b6040805160018082528183019092526000916020808301908036833701905050905086816000815181106116c2576116c2614263565b6020908102919091010152604080516001808252818301909252600091816020016020820280368337019050509050898160008151811061170557611705614263565b6020026020010181815250506040518060c001604052806117246118ef565b6001600160a01b03168152602001886001600160a01b031681526020018281526020018381526020018b815260200160fe60008e6000013581526020019081526020016000205481525092505050611780828a838888886128e3565b60005b8160600151518110156118665760606117d889846060015184815181106117ac576117ac614263565b6020026020010151856040015185815181106117ca576117ca614263565b602002602001015184612bb0565b826040015182815181106117ee576117ee614263565b602002602001015161010160018560600151858151811061181157611811614263565b602002602001015161182391906142bb565b8154811061183357611833614263565b90600052602060002001600082825461184c919061428f565b9091555082915061185e9050816142a2565b915050611783565b50505050505050505050565b61187a6124dc565b6101095462010000900460ff16156118a55760405163249fab5d60e01b815260040160405180910390fd5b61138861ffff821611156118cc576040516306b7c75960e31b815260040160405180910390fd5b610105805461ffff909216600160201b0261ffff60201b19909216919091179055565b6097546001600160a01b031690565b61010b8054610c3e906141a8565b611092611917612560565b8383612d77565b6119266124dc565b6101408101516001600160a01b0316156119eb5761014081015160405163095ea7b360e01b81526000916001600160a01b03169063095ea7b3906119869073aafdfa4a935d8511bf285af11a0544ce7e4a11999060001990600401613719565b6020604051808303816000875af11580156119a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119c991906144d7565b9050806119e9576040516302df483560e21b815260040160405180910390fd5b505b42816060015163ffffffff161015611a0a5763ffffffff421660608201525b600083815260fb60209081526040918290208351848301516001600160801b03918216600160801b9183168202178355938501516001830180546060880151608089015160a08a015160c08b0151959096166001600160a01b03199093169290921763ffffffff91821690980297909717600160a01b600160e01b031916600160a01b9188169190910263ffffffff60c01b191617600160c01b93871693909302929092176001600160e01b0316600160e01b9186169190910217905560e08401516002820180546101008701519286166001600160401b031990911617600160201b9290951691909102939093179092556101208301518051849392611b1892600385019291019061338a565b506101409190910151600490910180546001600160a01b0319166001600160a01b03909216919091179055604051829084907fe9a0c17645ed78ccc9996259f00297ffc75e6b9d22cd605ccc9992cc8ca3f4c190600090a3505050565b611b7d612cb6565b604051602001611b8c906144f4565b6040516020818303038152906040528051906020012081604051602001611bb39190614507565b6040516020818303038152906040528051906020012014611be757604051635ee88f9760e01b815260040160405180910390fd5b61010954610100900460ff1615611c115760405163249fab5d60e01b815260040160405180910390fd5b60005b61010154811015611c8f576101018181548110611c3357611c33614263565b9060005260206000200154838281518110611c5057611c50614263565b602002602001015163ffffffff161015611c7d57604051638a164f6360e01b815260040160405180910390fd5b80611c87816142a2565b915050611c14565b50610101545b8251811015611ce357610101805460018101825560009182527f109ea3cebb188b9c1b9fc5bb3920be60dfdc8699098dff92f3d80daaca747689015580611cdb816142a2565b915050611c95565b508151611cf89061010490602085019061338a565b505050565b600054610100900460ff1615808015611d1d5750600054600160ff909116105b80611d3e5750611d2c30612e57565b158015611d3e575060005460ff166001145b611da15760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610be2565b6000805460ff191660011790558015611dc4576000805461ff0019166101001790555b61010a611dd187826143b8565b5061010b611ddf86826143b8565b50611df860405180602001604052806000815250612e66565b611388611e0b60a0860160808701613587565b61ffff161180611e2f5750611388611e2960c0860160a08701613587565b61ffff16115b80611e5257506000611e4760408601602087016136da565b6001600160a01b0316145b80611e6e5750611e686080850160608601613587565b61ffff16155b15611e8c576040516306b7c75960e31b815260040160405180910390fd5b83610102611e9a8282614805565b50611eaa90506040850185614609565b90506001600160401b03811115611ec357611ec3613732565b604051908082528060200260200182016040528015611eec578160200160208202803683370190505b508051611f029161010191602090910190613439565b50611f0b612e96565b6000611f1d6080850160608601613587565b611f2d6060860160408701613587565b611f3d6040870160208801613587565b611f4a6020880188613587565b611f5491906148ed565b611f5e91906148ed565b611f6891906148ed565b61ffff16905060fa611f806040860160208701613587565b61ffff161080611f9257508061271014155b15611fb057604051632429608560e11b815260040160405180910390fd5b83610106611fbe828261490f565b505061010554611fda908490600160301b900461ffff1661105e565b508015610e6a576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a1505050505050565b6120306124dc565b611cf8838360405180610160016040528085600001602081019061205491906149de565b6001600160801b03168152602090810190612071908701876149de565b6001600160801b0316815260200160006001600160801b031681526020018560200160208101906120a291906149f9565b63ffffffff1681526020016120bd60608701604088016149f9565b63ffffffff1681526020016120d860808701606088016149f9565b63ffffffff1681526020016120f360a08701608088016149f9565b63ffffffff1681526000602082015260400161211560c0870160a088016149f9565b63ffffffff16815260200161212d60c0870187614609565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001612175610100870160e088016136da565b6001600160a01b0316905261191e565b600083815260fb6020908152604080832060fe90925280832054610105549151631c130e3f60e21b8152909173aeb8ec71de076d8ad24a85daccb161ca640415f09163704c38fc916121ed918691600160201b900461ffff16908a9087908b90600401614a16565b602060405180830381865af415801561220a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061222e9190614a3f565b9695505050505050565b6122406124dc565b61224981612780565b50610109805462ff0000191662010000179055565b60606101026002018054806020026020016040519081016040528092919081815260200182805480156122dc57602002820191906000526020600020906000905b82829054906101000a900463ffffffff1663ffffffff168152602001906004019060208260030104928301926001038202915080841161229f5790505b5050505050905090565b6122ee6124dc565b6122f781612780565b50610109805460ff19166001179055565b6123106124dc565b610109546301000000900460ff161561233c5760405163249fab5d60e01b815260040160405180910390fd5b61010880546001600160a01b0319166001600160a01b0392909216919091179055565b612367612560565b6001600160a01b0316856001600160a01b0316148061238d575061238d85610acd612560565b6123a95760405162461bcd60e51b8152600401610be290614307565b610fcf8585858585612ec5565b6123be612cb6565b6001600160a01b0381166124235760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610be2565b610dfd81612d25565b60405163140fbc8560e01b815273aeb8ec71de076d8ad24a85daccb161ca640415f09063140fbc85906114c590610100908590600401614a58565b60006001600160e01b03198216636cdb3d1360e11b148061249857506001600160e01b031982166303a24d0760e21b145b80610c1057506301ffc9a760e01b6001600160e01b0319831614610c10565b60006001600160e01b0319821663152a902d60e11b1480610c105750610c1082612467565b6124e46118ef565b6001600160a01b03166124f5612560565b6001600160a01b031614611503576040516330cd747160e01b815260040160405180910390fd5b60606080604051019050602081016040526000815280600019835b928101926030600a8206018453600a900480612537575050819003601f19909101908152919050565b60003373ea49e7be310716da66725c84a5127d2f6a202eaf1461258257503390565b503290565b60008082118015610c1057505061010154101590565b81518351146125ff5760405162461bcd60e51b815260206004820152602860248201527f455243313135353a2069647320616e6420616d6f756e7473206c656e677468206044820152670dad2e6dac2e8c6d60c31b6064820152608401610be2565b6001600160a01b0384166126255760405162461bcd60e51b8152600401610be290614a71565b600061262f612560565b905060005b845181101561271a57600085828151811061265157612651614263565b60200260200101519050600085838151811061266f5761266f614263565b60209081029190910181015160008481526065835260408082206001600160a01b038e1683529093529190912054909150818110156126c05760405162461bcd60e51b8152600401610be290614ab6565b60008381526065602090815260408083206001600160a01b038e8116855292528083208585039055908b168252812080548492906126ff90849061428f565b9250508190555050505080612713906142a2565b9050612634565b50846001600160a01b0316866001600160a01b0316826001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb878760405161276a929190614b00565b60405180910390a4610e6a818787878787612fec565b60405160200161278f906144f4565b60405160208183030381529060405280519060200120816040516020016127b69190614507565b6040516020818303038152906040528051906020012014610dfd57604051635ee88f9760e01b815260040160405180910390fd5b6127106001600160601b03821611156128585760405162461bcd60e51b815260206004820152602a60248201527f455243323938313a20726f79616c7479206665652077696c6c206578636565646044820152692073616c65507269636560b01b6064820152608401610be2565b6001600160a01b0382166128aa5760405162461bcd60e51b815260206004820152601960248201527822a921991c9c189d1034b73b30b634b2103932b1b2b4bb32b960391b6044820152606401610be2565b604080518082019091526001600160a01b039092168083526001600160601b039091166020909201829052600160a01b9091021760c955565b61010554608085015160a08601516020870151604051631c130e3f60e21b815260009473aeb8ec71de076d8ad24a85daccb161ca640415f09463704c38fc9461294b948e94600160201b90940461ffff16936001600160a01b03909116151590600401614a16565b602060405180830381865af4158015612968573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061298c9190614a3f565b604051631e1b3fbf60e11b815290915073aeb8ec71de076d8ad24a85daccb161ca640415f090633c367f7e906129db908a90610102908b9060fd90610101908b908b908f908c90600401614bc6565b60006040518083038186803b1580156129f357600080fd5b505af4158015612a07573d6000803e3d6000fd5b505050600188015463ffffffff600160e01b82048116600160c01b9092041610159050612a8957846080015160fd6000612a3f612560565b6001600160a01b03166001600160a01b031681526020019081526020016000206000886000013581526020019081526020016000206000828254612a83919061428f565b90915550505b600187015463ffffffff600160e01b90910481161015612ace5760808501518635600090815260fe602052604081208054909190612ac890849061428f565b90915550505b608085015160405163032cef8f60e41b815260048101899052610102602482015260ff604482015261010060648201526001600160a01b038616608482015260a48101919091526001600160801b03821660c482015273aeb8ec71de076d8ad24a85daccb161ca640415f0906332cef8f09060e40160006040518083038186803b158015612b5b57600080fd5b505af4158015612b6f573d6000803e3d6000fd5b50505050806001600160801b0316341115612ba757612ba7612b8f612560565b612ba26001600160801b038416346142bb565b61314e565b50505050505050565b6001600160a01b038416612c105760405162461bcd60e51b815260206004820152602160248201527f455243313135353a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b6064820152608401610be2565b6000612c1a612560565b90506000612c27856131c2565b90506000612c34856131c2565b905060008681526065602090815260408083206001600160a01b038b16845290915281208054879290612c6890849061428f565b909155505060408051878152602081018790526001600160a01b03808a169260009291871691600080516020614eb2833981519152910160405180910390a4612ba78360008989898961320d565b612cbe612560565b6001600160a01b0316612ccf6118ef565b6001600160a01b0316146115035760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610be2565b609780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b816001600160a01b0316836001600160a01b031603612dea5760405162461bcd60e51b815260206004820152602960248201527f455243313135353a2073657474696e6720617070726f76616c20737461747573604482015268103337b91039b2b63360b91b6064820152608401610be2565b6001600160a01b03838116600081815260666020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6001600160a01b03163b151590565b600054610100900460ff16612e8d5760405162461bcd60e51b8152600401610be290614cb9565b610dfd816132cf565b600054610100900460ff16612ebd5760405162461bcd60e51b8152600401610be290614cb9565b6115036132ff565b6001600160a01b038416612eeb5760405162461bcd60e51b8152600401610be290614a71565b6000612ef5612560565b90506000612f02856131c2565b90506000612f0f856131c2565b905060008681526065602090815260408083206001600160a01b038c16845290915290205485811015612f545760405162461bcd60e51b8152600401610be290614ab6565b60008781526065602090815260408083206001600160a01b038d8116855292528083208985039055908a16825281208054889290612f9390849061428f565b909155505060408051888152602081018890526001600160a01b03808b16928c82169291881691600080516020614eb2833981519152910160405180910390a4612fe1848a8a8a8a8a61320d565b505050505050505050565b612ffe846001600160a01b0316612e57565b15610e6a5760405163bc197c8160e01b81526001600160a01b0385169063bc197c81906130379089908990889088908890600401614d04565b6020604051808303816000875af1925050508015613072575060408051601f3d908101601f1916820190925261306f91810190614d62565b60015b61311e5761307e614d7f565b806308c379a0036130b75750613092614d9b565b8061309d57506130b9565b8060405162461bcd60e51b8152600401610be29190613564565b505b60405162461bcd60e51b815260206004820152603460248201527f455243313135353a207472616e7366657220746f206e6f6e2d455243313135356044820152732932b1b2b4bb32b91034b6b83632b6b2b73a32b960611b6064820152608401610be2565b6001600160e01b0319811663bc197c8160e01b14612ba75760405162461bcd60e51b8152600401610be290614e24565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461319b576040519150601f19603f3d011682016040523d82523d6000602084013e6131a0565b606091505b5050905080611cf8576040516312171d8360e31b815260040160405180910390fd5b604080516001808252818301909252606091600091906020808301908036833701905050905082816000815181106131fc576131fc614263565b602090810291909101015292915050565b61321f846001600160a01b0316612e57565b15610e6a5760405163f23a6e6160e01b81526001600160a01b0385169063f23a6e61906132589089908990889088908890600401614e6c565b6020604051808303816000875af1925050508015613293575060408051601f3d908101601f1916820190925261329091810190614d62565b60015b61329f5761307e614d7f565b6001600160e01b0319811663f23a6e6160e01b14612ba75760405162461bcd60e51b8152600401610be290614e24565b600054610100900460ff166132f65760405162461bcd60e51b8152600401610be290614cb9565b610dfd81613336565b600054610100900460ff166133265760405162461bcd60e51b8152600401610be290614cb9565b611503613331612560565b612d25565b606761109282826143b8565b6040518060c0016040528060006001600160a01b0316815260200160006001600160a01b03168152602001606081526020016060815260200160008152602001600081525090565b828054828255906000526020600020906007016008900481019282156134295791602002820160005b838211156133f757835183826101000a81548163ffffffff021916908363ffffffff16021790555092602001926004016020816003010492830192600103026133b3565b80156134275782816101000a81549063ffffffff02191690556004016020816003010492830192600103026133f7565b505b50613435929150613474565b5090565b828054828255906000526020600020908101928215613429579160200282015b82811115613429578251825591602001919060010190613459565b5b808211156134355760008155600101613475565b6001600160a01b0381168114610dfd57600080fd5b80356134a981613489565b919050565b600080604083850312156134c157600080fd5b82356134cc81613489565b946020939093013593505050565b6001600160e01b031981168114610dfd57600080fd5b60006020828403121561350257600080fd5b813561350d816134da565b9392505050565b60005b8381101561352f578181015183820152602001613517565b50506000910152565b60008151808452613550816020860160208601613514565b601f01601f19169290920160200192915050565b60208152600061350d6020830184613538565b61ffff81168114610dfd57600080fd5b60006020828403121561359957600080fd5b813561350d81613577565b6000602082840312156135b657600080fd5b5035919050565b600060408284031215610e4e57600080fd5b60008083601f8401126135e157600080fd5b5081356001600160401b038111156135f857600080fd5b602083019150836020828501011115610f7157600080fd5b60008060008060008060a0878903121561362957600080fd5b86356001600160401b038082111561364057600080fd5b61364c8a838b016135bd565b975060208901359650604089013595506060890135915061366c82613489565b9093506080880135908082111561368257600080fd5b5061368f89828a016135cf565b979a9699509497509295939492505050565b600080604083850312156136b457600080fd5b82356136bf81613489565b915060208301356136cf81613489565b809150509250929050565b6000602082840312156136ec57600080fd5b813561350d81613489565b6000806040838503121561370a57600080fd5b50508035926020909101359150565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052604160045260246000fd5b601f8201601f191681016001600160401b038111828210171561376d5761376d613732565b6040525050565b60405161016081016001600160401b038111828210171561379757613797613732565b60405290565b60006001600160401b038211156137b6576137b6613732565b5060051b60200190565b600082601f8301126137d157600080fd5b813560206137de8261379d565b6040516137eb8282613748565b83815260059390931b850182019282810191508684111561380b57600080fd5b8286015b84811015613826578035835291830191830161380f565b509695505050505050565b600082601f83011261384257600080fd5b81356001600160401b0381111561385b5761385b613732565b604051613872601f8301601f191660200182613748565b81815284602083860101111561388757600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a086880312156138bc57600080fd5b85356138c781613489565b945060208601356138d781613489565b935060408601356001600160401b03808211156138f357600080fd5b6138ff89838a016137c0565b9450606088013591508082111561391557600080fd5b61392189838a016137c0565b9350608088013591508082111561393757600080fd5b5061394488828901613831565b9150509295509295909350565b60006020828403121561396357600080fd5b81356001600160401b0381111561397957600080fd5b61398584828501613831565b949350505050565b600080604083850312156139a057600080fd5b82356139ab81613489565b915060208301356136cf81613577565b600082601f8301126139cc57600080fd5b813560206139d98261379d565b6040516139e68282613748565b83815260059390931b8501820192828101915086841115613a0657600080fd5b8286015b84811015613826578035613a1d81613489565b8352918301918301613a0a565b60008060408385031215613a3d57600080fd5b82356001600160401b0380821115613a5457600080fd5b613a60868387016139bb565b93506020850135915080821115613a7657600080fd5b50613a83858286016137c0565b9150509250929050565b600081518084526020808501945080840160005b83811015613abd57815187529582019590820190600101613aa1565b509495945050505050565b60208152600061350d6020830184613a8d565b60008083601f840112613aed57600080fd5b5081356001600160401b03811115613b0457600080fd5b6020830191508360208260051b8501011115610f7157600080fd5b60008060008060008060008060008060c08b8d031215613b3e57600080fd5b8a356001600160401b0380821115613b5557600080fd5b613b618e838f016135bd565b9b5060208d0135915080821115613b7757600080fd5b613b838e838f01613adb565b909b50995060408d0135915080821115613b9c57600080fd5b613ba88e838f01613adb565b909950975060608d0135915080821115613bc157600080fd5b613bcd8e838f01613adb565b9097509550859150613be160808e0161349e565b945060a08d0135915080821115613bf757600080fd5b50613c048d828e016135cf565b915080935050809150509295989b9194979a5092959850565b600060208284031215613c2f57600080fd5b81356001600160401b03811115613c4557600080fd5b613985848285016139bb565b60c081526000613c6460c0830189613538565b6001600160a01b039790971660208301525061ffff94851660408201529284166060840152908316608083015290911660a090910152919050565b600080600080600080600060c0888a031215613cba57600080fd5b87356001600160401b0380821115613cd157600080fd5b613cdd8b838c016135bd565b985060208a0135975060408a01359150613cf682613489565b90955060608901359450608089013590613d0f82613489565b90935060a08901359080821115613d2557600080fd5b50613d328a828b016135cf565b989b979a50959850939692959293505050565b8015158114610dfd57600080fd5b60008060408385031215613d6657600080fd5b8235613d7181613489565b915060208301356136cf81613d45565b80356001600160801b03811681146134a957600080fd5b63ffffffff81168114610dfd57600080fd5b80356134a981613d98565b600082601f830112613dc657600080fd5b81356020613dd38261379d565b604051613de08282613748565b83815260059390931b8501820192828101915086841115613e0057600080fd5b8286015b84811015613826578035613e1781613d98565b8352918301918301613e04565b600080600060608486031215613e3957600080fd5b833592506020840135915060408401356001600160401b0380821115613e5e57600080fd5b908501906101608288031215613e7357600080fd5b613e7b613774565b613e8483613d81565b8152613e9260208401613d81565b6020820152613ea360408401613d81565b6040820152613eb460608401613daa565b6060820152613ec560808401613daa565b6080820152613ed660a08401613daa565b60a0820152613ee760c08401613daa565b60c0820152613ef860e08401613daa565b60e0820152610100613f0b818501613daa565b908201526101208381013583811115613f2357600080fd5b613f2f8a828701613db5565b8284015250506101409150613f4582840161349e565b828201528093505050509250925092565b60008060408385031215613f6957600080fd5b82356001600160401b0380821115613f8057600080fd5b613f8c86838701613db5565b93506020850135915080821115613fa257600080fd5b50613a8385828601613831565b600060e08284031215610e4e57600080fd5b60008060008060006101608688031215613fda57600080fd5b85356001600160401b0380821115613ff157600080fd5b613ffd89838a01613831565b9650602088013591508082111561401357600080fd5b61401f89838a01613831565b9550604088013591508082111561403557600080fd5b5061404288828901613faf565b9350506140528760608801613faf565b915061014086013561406381613489565b809150509295509295909350565b60008060006060848603121561408657600080fd5b833592506020840135915060408401356001600160401b038111156140aa57600080fd5b840161010081870312156140bd57600080fd5b809150509250925092565b6000806000606084860312156140dd57600080fd5b833592506020840135915060408401356140bd81613d45565b6020808252825182820181905260009190848201906040850190845b8181101561413457835163ffffffff1683529284019291840191600101614112565b50909695505050505050565b600080600080600060a0868803121561415857600080fd5b853561416381613489565b9450602086013561417381613489565b9350604086013592506060860135915060808601356001600160401b0381111561419c57600080fd5b61394488828901613831565b600181811c908216806141bc57607f821691505b602082108103610e4e57634e487b7160e01b600052602260045260246000fd5b60008084546141ea816141a8565b60018281168015614202576001811461421757614246565b60ff1984168752821515830287019450614246565b8860005260208060002060005b8581101561423d5781548a820152908401908201614224565b50505082870194505b50505050835161425a818360208801613514565b01949350505050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610c1057610c10614279565b6000600182016142b4576142b4614279565b5060010190565b81810381811115610c1057610c10614279565b8082028115828204841417610c1057610c10614279565b60008261430257634e487b7160e01b600052601260045260246000fd5b500490565b6020808252602e908201527f455243313135353a2063616c6c6572206973206e6f7420746f6b656e206f776e60408201526d195c881bdc88185c1c1c9bdd995960921b606082015260800190565b5b818110156110925760008155600101614356565b601f821115611cf857806000526020600020601f840160051c810160208510156143915750805b610fcf601f850160051c830182614355565b600019600383901b1c191660019190911b1790565b81516001600160401b038111156143d1576143d1613732565b6143e5816143df84546141a8565b8461436a565b602080601f83116001811461441457600084156144025750858301515b61440c85826143a3565b865550610e6a565b600085815260208120601f198616915b8281101561444357888601518255948401946001909101908401614424565b50858210156144615787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b600081518084526020808501945080840160005b83811015613abd5781516001600160a01b031687529582019590820190600101614485565b84815283602082015260018060a01b038316604082015260806060820152600061222e6080830184614471565b6000602082840312156144e957600080fd5b815161350d81613d45565b663337b932bb32b960c91b815260070190565b60008251614519818460208701613514565b9190910192915050565b6001600160401b0383111561453a5761453a613732565b61454e8361454883546141a8565b8361436a565b6000601f84116001811461457c576000851561456a5750838201355b61457486826143a3565b845550610fcf565b600083815260209020601f19861690835b828110156145ad578685013582556020948501946001909201910161458d565b50868210156145ca5760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b60008135610c1081613489565b80546001600160a01b0319166001600160a01b0392909216919091179055565b6000808335601e1984360301811261462057600080fd5b8301803591506001600160401b0382111561463a57600080fd5b6020019150600581901b3603821315610f7157600080fd5b600160401b82111561466657614666613732565b805482825580831015611cf8578160005260206000206007840160031c8101601c8560021b1680156146a9576000198083018054828460200360031b1c16815550505b50610fcf6007840160031c830182614355565b60008135610c1081613d98565b6001600160401b038311156146e0576146e0613732565b6146ea8382614652565b60008181526020902082908460031c60005b81811015614755576000805b60088110156147485761473761471d876146bc565b63ffffffff600584901b81811b19861692909116901b1790565b602096909601959150600101614708565b50838201556001016146fc565b506007198616808703818814614794576000805b8281101561478e5761477d61471d886146bc565b602097909701969150600101614769565b50848401555b5050505050505050565b60008135610c1081613577565b805463ffff00008360101b1663ffff0000198216178255505050565b805461ffff60201b191660209290921b61ffff60201b16919091179055565b805461ffff60301b191660309290921b61ffff60301b16919091179055565b8135601e1983360301811261481957600080fd5b820180356001600160401b0381111561483157600080fd5b60208201915080360382131561484657600080fd5b614851818385614523565b505061486b614862602084016145dc565b600183016145e9565b6148786040830183614609565b6148868183600286016146c9565b5050600381016148ae61489b6060850161479e565b825461ffff191661ffff91909116178255565b6148c36148bd6080850161479e565b826147ab565b6148d86148d260a0850161479e565b826147c7565b611cf86148e760c0850161479e565b826147e6565b61ffff81811683821601908082111561490857614908614279565b5092915050565b813561491a81613577565b815461ffff191661ffff821617825550602082013561493881613577565b61494281836147ab565b50604082013561495181613577565b61495b81836147c7565b50606082013561496a81613577565b61497481836147e6565b50608082013561498381613489565b8154600160401b600160e01b03191660409190911b600160401b600160e01b031617815560a08201356149b581613489565b6149c281600184016145e9565b5060c08201356149d181613489565b611cf881600284016145e9565b6000602082840312156149f057600080fd5b61350d82613d81565b600060208284031215614a0b57600080fd5b813561350d81613d98565b94855261ffff939093166020850152604084019190915260608301521515608082015260a00190565b600060208284031215614a5157600080fd5b5051919050565b8281526040602082015260006139856040830184614471565b60208082526025908201527f455243313135353a207472616e7366657220746f20746865207a65726f206164604082015264647265737360d81b606082015260800190565b6020808252602a908201527f455243313135353a20696e73756666696369656e742062616c616e636520666f60408201526939103a3930b739b332b960b11b606082015260800190565b604081526000614b136040830185613a8d565b8281036020840152614b258185613a8d565b95945050505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b600060018060a01b0380835116845280602084015116602085015250604082015160c06040850152614b8c60c0850182613a8d565b905060608301518482036060860152614ba58282613a8d565b9150506080830151608085015260a083015160a08501528091505092915050565b60006101008b83528a6020840152806040840152893581840152506020890135601e198a3603018112614bf857600080fd5b89016020810190356001600160401b03811115614c1457600080fd5b8060051b803603831315614c2757600080fd5b604061012086015261014085018290526101606001600160fb1b03831115614c4e57600080fd5b81848288013781860193508b60608701528a6080870152808685030160a0870152614c7c8185018a8c614b2e565b935050505082810360c0840152614c938186614b57565b915050614cab60e08301846001600160801b03169052565b9a9950505050505050505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6001600160a01b0386811682528516602082015260a060408201819052600090614d3090830186613a8d565b8281036060840152614d428186613a8d565b90508281036080840152614d568185613538565b98975050505050505050565b600060208284031215614d7457600080fd5b815161350d816134da565b600060033d1115614d985760046000803e5060005160e01c5b90565b600060443d1015614da95790565b6040516003193d81016004833e81513d6001600160401b038083116024840183101715614dd857505050505090565b8285019150815181811115614df05750505050505090565b843d8701016020828501011115614e0a5750505050505090565b614e1960208286010187613748565b509095945050505050565b60208082526028908201527f455243313135353a204552433131353552656365697665722072656a656374656040820152676420746f6b656e7360c01b606082015260800190565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090614ea690830184613538565b97965050505050505056fec3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62a2646970667358221220513d73faf61591316cff61468d34703c43914cb0ff24101e26d89d280981272164736f6c63430008140033
Deployed Bytecode
0x6080604052600436106102435760003560e01c8062fdd58e1461024857806301ffc9a71461027b57806306fdde03146102ab5780630c6f910b146102cd5780630e89341c146102ef5780631069143a1461030f57806315ec67201461037057806318160ddd146103855780631fff79b01461039a57806321d5bf24146103ad5780632693ebf21461041557806327a59437146104355780632a55205a146104745780632eb2c2d6146104a257806332f7c6d4146104c25780633ccfd60b146104e25780634331f639146104f75780634bde38c8146105175780634e1273f4146105525780635000d3d11461057f57806355f804b3146105925780635ecb16cd146105b2578063715018a6146105d257806379502c55146105e757806379b004db1461060e5780637c5d0a081461062e5780637ded18481461064e5780638b4795d6146106615780638da5cb5b1461068157806395d89b4114610696578063978a4509146106ab5780639a7a973c146106f6578063a22cb46514610723578063a3edb86a14610743578063a5aa4aa414610786578063aefc542814610892578063b2938bd4146108b2578063b581085b146108d2578063b68836fa146108f2578063ba7bc0221461091f578063bedcf0031461093f578063caf3e53214610985578063ce216e2f146109a5578063d4048441146109c5578063d5abeb0114610a70578063de6cd0db14610a92578063e985e9c514610ab2578063ead0055314610afb578063f242432a14610b1b578063f2fde38b14610b3b578063f588eb5014610b5b575b600080fd5b34801561025457600080fd5b506102686102633660046134ae565b610b7b565b6040519081526020015b60405180910390f35b34801561028757600080fd5b5061029b6102963660046134f0565b610c16565b6040519015158152602001610272565b3480156102b757600080fd5b506102c0610c30565b6040516102729190613564565b3480156102d957600080fd5b506102ed6102e8366004613587565b610cbf565b005b3480156102fb57600080fd5b506102c061030a3660046135a4565b610d3a565b34801561031b57600080fd5b50610109546103469060ff808216916101008104821691620100008204811691630100000090041684565b60408051941515855292151560208501529015159183019190915215156060820152608001610272565b34801561037c57600080fd5b506102ed610d9d565b34801561039157600080fd5b50610268610e00565b6102ed6103a8366004613610565b610e54565b3480156103b957600080fd5b506103fd6103c83660046136a1565b6001600160a01b039182166000908152610100602090815260408083209390941682529190915220546001600160801b031690565b6040516001600160801b039091168152602001610272565b34801561042157600080fd5b506102686104303660046135a4565b610e72565b34801561044157600080fd5b506103fd6104503660046136da565b6001600160a01b0316600090815260ff60205260409020546001600160801b031690565b34801561048057600080fd5b5061049461048f3660046136f7565b610eca565b604051610272929190613719565b3480156104ae57600080fd5b506102ed6104bd3660046138a4565b610f78565b3480156104ce57600080fd5b506102ed6104dd366004613951565b610fd6565b3480156104ee57600080fd5b506102ed610ffe565b34801561050357600080fd5b506102ed61051236600461398d565b61105e565b34801561052357600080fd5b507386b82972282dd22348374bc63fd21620f7ed847b5b6040516001600160a01b039091168152602001610272565b34801561055e57600080fd5b5061057261056d366004613a2a565b611096565b6040516102729190613ac8565b6102ed61058d366004613b1f565b6111bf565b34801561059e57600080fd5b506102ed6105ad366004613951565b611444565b3480156105be57600080fd5b506102ed6105cd366004613c1d565b61147e565b3480156105de57600080fd5b506102ed6114f1565b3480156105f357600080fd5b506105fc611505565b60405161027296959493929190613c51565b34801561061a57600080fd5b506102ed610629366004613587565b6115cf565b34801561063a57600080fd5b506102ed610649366004613951565b6115f0565b6102ed61065c366004613c9f565b611614565b34801561066d57600080fd5b506102ed61067c366004613587565b611872565b34801561068d57600080fd5b5061053a6118ef565b3480156106a257600080fd5b506102c06118fe565b3480156106b757600080fd5b506103fd6106c63660046136da565b6001600160a01b03166000908152610100602090815260408083208380529091529020546001600160801b031690565b34801561070257600080fd5b506102686107113660046135a4565b600090815260fe602052604090205490565b34801561072f57600080fd5b506102ed61073e366004613d53565b61190c565b34801561074f57600080fd5b5061026861075e3660046134ae565b6001600160a01b0391909116600090815260fd60209081526040808320938352929052205490565b34801561079257600080fd5b506108226107a13660046135a4565b60fb6020526000908152604090208054600182015460028301546004909301546001600160801b0380841694600160801b948590048216949184169391820463ffffffff90811693600160a01b8404821693600160c01b8104831693600160e01b90910483169280821692600160201b90920416906001600160a01b03168a565b604080516001600160801b039b8c168152998b1660208b0152979099169688019690965263ffffffff9485166060880152928416608087015290831660a0860152821660c0850152811660e0840152166101008201526001600160a01b0390911661012082015261014001610272565b34801561089e57600080fd5b506102ed6108ad366004613e24565b61191e565b3480156108be57600080fd5b506102ed6108cd366004613f56565b611b75565b3480156108de57600080fd5b506102ed6108ed366004613fc1565b611cfd565b3480156108fe57600080fd5b5061026861090d3660046135a4565b60fc6020526000908152604090205481565b34801561092b57600080fd5b506102ed61093a366004614071565b612028565b34801561094b57600080fd5b506000805260ff6020527f03d616f3758432b4d7452e2e9011612152589bfc903ce751686613c478b2af5f546001600160801b03166103fd565b34801561099157600080fd5b506102686109a03660046140c8565b612185565b3480156109b157600080fd5b506102ed6109c0366004613951565b612238565b3480156109d157600080fd5b50610106546101075461010854610a219261ffff80821693620100008304821693600160201b8404831693600160301b8104909316926001600160a01b03600160401b9091048116928116911687565b6040805161ffff98891681529688166020880152948716948601949094529190941660608401526001600160a01b039384166080840152831660a08301529190911660c082015260e001610272565b348015610a7c57600080fd5b50610a8561225e565b60405161027291906140f6565b348015610a9e57600080fd5b506102ed610aad366004613951565b6122e6565b348015610abe57600080fd5b5061029b610acd3660046136a1565b6001600160a01b03918216600090815260666020908152604080832093909416825291909152205460ff1690565b348015610b0757600080fd5b506102ed610b163660046136da565b612308565b348015610b2757600080fd5b506102ed610b36366004614140565b61235f565b348015610b4757600080fd5b506102ed610b563660046136da565b6123b6565b348015610b6757600080fd5b506102ed610b76366004613c1d565b61242c565b60006001600160a01b038316610beb5760405162461bcd60e51b815260206004820152602a60248201527f455243313135353a2061646472657373207a65726f206973206e6f742061207660448201526930b634b21037bbb732b960b11b60648201526084015b60405180910390fd5b5060008181526065602090815260408083206001600160a01b03861684529091529020545b92915050565b6000610c2182612467565b80610c105750610c10826124b7565b61010a8054610c3e906141a8565b80601f0160208091040260200160405190810160405280929190818152602001828054610c6a906141a8565b8015610cb75780601f10610c8c57610100808354040283529160200191610cb7565b820191906000526020600020905b815481529060010190602001808311610c9a57829003601f168201915b505050505081565b610cc76124dc565b6101095462010000900460ff1615610cf25760405163249fab5d60e01b815260040160405180910390fd5b61138861ffff82161115610d19576040516306b7c75960e31b815260040160405180910390fd5b610105805461ffff909216620100000263ffff000019909216919091179055565b60606101026000018054610d4d906141a8565b9050600003610d6b5760405180602001604052806000815250610c10565b610102610d778361251c565b604051602001610d889291906141dc565b60405160208183030381529060405292915050565b60408051600180825281830190925260009160208083019080368337019050509050600081600081518110610dd457610dd4614263565b60200260200101906001600160a01b031690816001600160a01b031681525050610dfd8161242c565b50565b600080805b61010154811015610e4e576101018181548110610e2457610e24614263565b906000526020600020015482610e3a919061428f565b915080610e46816142a2565b915050610e05565b50919050565b610e6a8686610e61612560565b87878787611614565b505050505050565b6000610e7d82612587565b610e9a57604051630a14c4b560e41b815260040160405180910390fd5b610101610ea86001846142bb565b81548110610eb857610eb8614263565b90600052602060002001549050919050565b600082815260ca602090815260408083208151808301909252546001600160a01b038116808352600160a01b9091046001600160601b0316928201929092528291610f3f57506040805180820190915260c9546001600160a01b0381168252600160a01b90046001600160601b031660208201525b602081015160009061271090610f5e906001600160601b0316876142ce565b610f6891906142e5565b91519350909150505b9250929050565b610f80612560565b6001600160a01b0316856001600160a01b03161480610fa65750610fa685610acd612560565b610fc25760405162461bcd60e51b8152600401610be290614307565b610fcf858585858561259d565b5050505050565b610fde6124dc565b610fe781612780565b50610109805463ff00000019166301000000179055565b6040805160018082528183019092526000916020808301908036833701905050905060008160008151811061103557611035614263565b60200260200101906001600160a01b031690816001600160a01b031681525050610dfd8161147e565b6110666124dc565b610105805461ffff60301b1916600160301b61ffff8416908102919091179091556110929083906127ea565b5050565b606081518351146110fb5760405162461bcd60e51b815260206004820152602960248201527f455243313135353a206163636f756e747320616e6420696473206c656e677468604482015268040dad2e6dac2e8c6d60bb1b6064820152608401610be2565b600083516001600160401b0381111561111657611116613732565b60405190808252806020026020018201604052801561113f578160200160208202803683370190505b50905060005b84518110156111b75761118a85828151811061116357611163614263565b602002602001015185838151811061117d5761117d614263565b6020026020010151610b7b565b82828151811061119c5761119c614263565b60209081029190910101526111b0816142a2565b9050611145565b509392505050565b85881415806111ce5750858414155b156111ec576040516306b7c75960e31b815260040160405180910390fd5b6000805b878110156112305788888281811061120a5761120a614263565b905060200201358261121c919061428f565b915080611228816142a2565b9150506111f0565b50611239613342565b6040518060c0016040528061124c6118ef565b6001600160a01b03168152602001866001600160a01b031681526020018a8a808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152505050908252506040805160208a810282810182019093528a82529283019290918b918b918291850190849080828437600092018290525093855250505060208083018690528f3580835260fe825260408084205494810194909452825260fb9052206002810154919250906001600160201b90910463ffffffff16111561133357604051630280e1e560e61b815260040160405180910390fd5b611341818e848989896128e3565b60005b8b8110156114345760606113b08e8e8481811061136357611363614263565b905060200201602081019061137891906136da565b8b8b8581811061138a5761138a614263565b905060200201358e8e868181106113a3576113a3614263565b9050602002013584612bb0565b8b8b838181106113c2576113c2614263565b9050602002013561010160018c8c868181106113e0576113e0614263565b905060200201356113f191906142bb565b8154811061140157611401614263565b90600052602060002001600082825461141a919061428f565b9091555082915061142c9050816142a2565b915050611344565b5050505050505050505050505050565b61144c612cb6565b6101095460ff16156114715760405163249fab5d60e01b815260040160405180910390fd5b61010261109282826143b8565b73aeb8ec71de076d8ad24a85daccb161ca640415f0638e1ab86661010660ff6114a56118ef565b856040518563ffffffff1660e01b81526004016114c594939291906144aa565b60006040518083038186803b1580156114dd57600080fd5b505af4158015610fcf573d6000803e3d6000fd5b6114f9612cb6565b6115036000612d25565b565b61010280548190611515906141a8565b80601f0160208091040260200160405190810160405280929190818152602001828054611541906141a8565b801561158e5780601f106115635761010080835404028352916020019161158e565b820191906000526020600020905b81548152906001019060200180831161157157829003601f168201915b505050600184015460039094015492936001600160a01b03169261ffff808216935062010000820481169250600160201b8204811691600160301b90041686565b6115d76124dc565b610105805461ffff191661ffff92909216919091179055565b6115f86124dc565b61160181612780565b50610109805461ff001916610100179055565b6001600160a01b03851661163a57604051622e076360e81b815260040160405180910390fd5b8635600090815260fb6020526040902060028101546001600160201b90910463ffffffff16111561168457600281015461168190600160201b900463ffffffff16886142ce565b96505b61168c613342565b6040805160018082528183019092526000916020808301908036833701905050905086816000815181106116c2576116c2614263565b6020908102919091010152604080516001808252818301909252600091816020016020820280368337019050509050898160008151811061170557611705614263565b6020026020010181815250506040518060c001604052806117246118ef565b6001600160a01b03168152602001886001600160a01b031681526020018281526020018381526020018b815260200160fe60008e6000013581526020019081526020016000205481525092505050611780828a838888886128e3565b60005b8160600151518110156118665760606117d889846060015184815181106117ac576117ac614263565b6020026020010151856040015185815181106117ca576117ca614263565b602002602001015184612bb0565b826040015182815181106117ee576117ee614263565b602002602001015161010160018560600151858151811061181157611811614263565b602002602001015161182391906142bb565b8154811061183357611833614263565b90600052602060002001600082825461184c919061428f565b9091555082915061185e9050816142a2565b915050611783565b50505050505050505050565b61187a6124dc565b6101095462010000900460ff16156118a55760405163249fab5d60e01b815260040160405180910390fd5b61138861ffff821611156118cc576040516306b7c75960e31b815260040160405180910390fd5b610105805461ffff909216600160201b0261ffff60201b19909216919091179055565b6097546001600160a01b031690565b61010b8054610c3e906141a8565b611092611917612560565b8383612d77565b6119266124dc565b6101408101516001600160a01b0316156119eb5761014081015160405163095ea7b360e01b81526000916001600160a01b03169063095ea7b3906119869073aafdfa4a935d8511bf285af11a0544ce7e4a11999060001990600401613719565b6020604051808303816000875af11580156119a5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119c991906144d7565b9050806119e9576040516302df483560e21b815260040160405180910390fd5b505b42816060015163ffffffff161015611a0a5763ffffffff421660608201525b600083815260fb60209081526040918290208351848301516001600160801b03918216600160801b9183168202178355938501516001830180546060880151608089015160a08a015160c08b0151959096166001600160a01b03199093169290921763ffffffff91821690980297909717600160a01b600160e01b031916600160a01b9188169190910263ffffffff60c01b191617600160c01b93871693909302929092176001600160e01b0316600160e01b9186169190910217905560e08401516002820180546101008701519286166001600160401b031990911617600160201b9290951691909102939093179092556101208301518051849392611b1892600385019291019061338a565b506101409190910151600490910180546001600160a01b0319166001600160a01b03909216919091179055604051829084907fe9a0c17645ed78ccc9996259f00297ffc75e6b9d22cd605ccc9992cc8ca3f4c190600090a3505050565b611b7d612cb6565b604051602001611b8c906144f4565b6040516020818303038152906040528051906020012081604051602001611bb39190614507565b6040516020818303038152906040528051906020012014611be757604051635ee88f9760e01b815260040160405180910390fd5b61010954610100900460ff1615611c115760405163249fab5d60e01b815260040160405180910390fd5b60005b61010154811015611c8f576101018181548110611c3357611c33614263565b9060005260206000200154838281518110611c5057611c50614263565b602002602001015163ffffffff161015611c7d57604051638a164f6360e01b815260040160405180910390fd5b80611c87816142a2565b915050611c14565b50610101545b8251811015611ce357610101805460018101825560009182527f109ea3cebb188b9c1b9fc5bb3920be60dfdc8699098dff92f3d80daaca747689015580611cdb816142a2565b915050611c95565b508151611cf89061010490602085019061338a565b505050565b600054610100900460ff1615808015611d1d5750600054600160ff909116105b80611d3e5750611d2c30612e57565b158015611d3e575060005460ff166001145b611da15760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610be2565b6000805460ff191660011790558015611dc4576000805461ff0019166101001790555b61010a611dd187826143b8565b5061010b611ddf86826143b8565b50611df860405180602001604052806000815250612e66565b611388611e0b60a0860160808701613587565b61ffff161180611e2f5750611388611e2960c0860160a08701613587565b61ffff16115b80611e5257506000611e4760408601602087016136da565b6001600160a01b0316145b80611e6e5750611e686080850160608601613587565b61ffff16155b15611e8c576040516306b7c75960e31b815260040160405180910390fd5b83610102611e9a8282614805565b50611eaa90506040850185614609565b90506001600160401b03811115611ec357611ec3613732565b604051908082528060200260200182016040528015611eec578160200160208202803683370190505b508051611f029161010191602090910190613439565b50611f0b612e96565b6000611f1d6080850160608601613587565b611f2d6060860160408701613587565b611f3d6040870160208801613587565b611f4a6020880188613587565b611f5491906148ed565b611f5e91906148ed565b611f6891906148ed565b61ffff16905060fa611f806040860160208701613587565b61ffff161080611f9257508061271014155b15611fb057604051632429608560e11b815260040160405180910390fd5b83610106611fbe828261490f565b505061010554611fda908490600160301b900461ffff1661105e565b508015610e6a576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a1505050505050565b6120306124dc565b611cf8838360405180610160016040528085600001602081019061205491906149de565b6001600160801b03168152602090810190612071908701876149de565b6001600160801b0316815260200160006001600160801b031681526020018560200160208101906120a291906149f9565b63ffffffff1681526020016120bd60608701604088016149f9565b63ffffffff1681526020016120d860808701606088016149f9565b63ffffffff1681526020016120f360a08701608088016149f9565b63ffffffff1681526000602082015260400161211560c0870160a088016149f9565b63ffffffff16815260200161212d60c0870187614609565b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250505090825250602001612175610100870160e088016136da565b6001600160a01b0316905261191e565b600083815260fb6020908152604080832060fe90925280832054610105549151631c130e3f60e21b8152909173aeb8ec71de076d8ad24a85daccb161ca640415f09163704c38fc916121ed918691600160201b900461ffff16908a9087908b90600401614a16565b602060405180830381865af415801561220a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061222e9190614a3f565b9695505050505050565b6122406124dc565b61224981612780565b50610109805462ff0000191662010000179055565b60606101026002018054806020026020016040519081016040528092919081815260200182805480156122dc57602002820191906000526020600020906000905b82829054906101000a900463ffffffff1663ffffffff168152602001906004019060208260030104928301926001038202915080841161229f5790505b5050505050905090565b6122ee6124dc565b6122f781612780565b50610109805460ff19166001179055565b6123106124dc565b610109546301000000900460ff161561233c5760405163249fab5d60e01b815260040160405180910390fd5b61010880546001600160a01b0319166001600160a01b0392909216919091179055565b612367612560565b6001600160a01b0316856001600160a01b0316148061238d575061238d85610acd612560565b6123a95760405162461bcd60e51b8152600401610be290614307565b610fcf8585858585612ec5565b6123be612cb6565b6001600160a01b0381166124235760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610be2565b610dfd81612d25565b60405163140fbc8560e01b815273aeb8ec71de076d8ad24a85daccb161ca640415f09063140fbc85906114c590610100908590600401614a58565b60006001600160e01b03198216636cdb3d1360e11b148061249857506001600160e01b031982166303a24d0760e21b145b80610c1057506301ffc9a760e01b6001600160e01b0319831614610c10565b60006001600160e01b0319821663152a902d60e11b1480610c105750610c1082612467565b6124e46118ef565b6001600160a01b03166124f5612560565b6001600160a01b031614611503576040516330cd747160e01b815260040160405180910390fd5b60606080604051019050602081016040526000815280600019835b928101926030600a8206018453600a900480612537575050819003601f19909101908152919050565b60003373ea49e7be310716da66725c84a5127d2f6a202eaf1461258257503390565b503290565b60008082118015610c1057505061010154101590565b81518351146125ff5760405162461bcd60e51b815260206004820152602860248201527f455243313135353a2069647320616e6420616d6f756e7473206c656e677468206044820152670dad2e6dac2e8c6d60c31b6064820152608401610be2565b6001600160a01b0384166126255760405162461bcd60e51b8152600401610be290614a71565b600061262f612560565b905060005b845181101561271a57600085828151811061265157612651614263565b60200260200101519050600085838151811061266f5761266f614263565b60209081029190910181015160008481526065835260408082206001600160a01b038e1683529093529190912054909150818110156126c05760405162461bcd60e51b8152600401610be290614ab6565b60008381526065602090815260408083206001600160a01b038e8116855292528083208585039055908b168252812080548492906126ff90849061428f565b9250508190555050505080612713906142a2565b9050612634565b50846001600160a01b0316866001600160a01b0316826001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb878760405161276a929190614b00565b60405180910390a4610e6a818787878787612fec565b60405160200161278f906144f4565b60405160208183030381529060405280519060200120816040516020016127b69190614507565b6040516020818303038152906040528051906020012014610dfd57604051635ee88f9760e01b815260040160405180910390fd5b6127106001600160601b03821611156128585760405162461bcd60e51b815260206004820152602a60248201527f455243323938313a20726f79616c7479206665652077696c6c206578636565646044820152692073616c65507269636560b01b6064820152608401610be2565b6001600160a01b0382166128aa5760405162461bcd60e51b815260206004820152601960248201527822a921991c9c189d1034b73b30b634b2103932b1b2b4bb32b960391b6044820152606401610be2565b604080518082019091526001600160a01b039092168083526001600160601b039091166020909201829052600160a01b9091021760c955565b61010554608085015160a08601516020870151604051631c130e3f60e21b815260009473aeb8ec71de076d8ad24a85daccb161ca640415f09463704c38fc9461294b948e94600160201b90940461ffff16936001600160a01b03909116151590600401614a16565b602060405180830381865af4158015612968573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061298c9190614a3f565b604051631e1b3fbf60e11b815290915073aeb8ec71de076d8ad24a85daccb161ca640415f090633c367f7e906129db908a90610102908b9060fd90610101908b908b908f908c90600401614bc6565b60006040518083038186803b1580156129f357600080fd5b505af4158015612a07573d6000803e3d6000fd5b505050600188015463ffffffff600160e01b82048116600160c01b9092041610159050612a8957846080015160fd6000612a3f612560565b6001600160a01b03166001600160a01b031681526020019081526020016000206000886000013581526020019081526020016000206000828254612a83919061428f565b90915550505b600187015463ffffffff600160e01b90910481161015612ace5760808501518635600090815260fe602052604081208054909190612ac890849061428f565b90915550505b608085015160405163032cef8f60e41b815260048101899052610102602482015260ff604482015261010060648201526001600160a01b038616608482015260a48101919091526001600160801b03821660c482015273aeb8ec71de076d8ad24a85daccb161ca640415f0906332cef8f09060e40160006040518083038186803b158015612b5b57600080fd5b505af4158015612b6f573d6000803e3d6000fd5b50505050806001600160801b0316341115612ba757612ba7612b8f612560565b612ba26001600160801b038416346142bb565b61314e565b50505050505050565b6001600160a01b038416612c105760405162461bcd60e51b815260206004820152602160248201527f455243313135353a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b6064820152608401610be2565b6000612c1a612560565b90506000612c27856131c2565b90506000612c34856131c2565b905060008681526065602090815260408083206001600160a01b038b16845290915281208054879290612c6890849061428f565b909155505060408051878152602081018790526001600160a01b03808a169260009291871691600080516020614eb2833981519152910160405180910390a4612ba78360008989898961320d565b612cbe612560565b6001600160a01b0316612ccf6118ef565b6001600160a01b0316146115035760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610be2565b609780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b816001600160a01b0316836001600160a01b031603612dea5760405162461bcd60e51b815260206004820152602960248201527f455243313135353a2073657474696e6720617070726f76616c20737461747573604482015268103337b91039b2b63360b91b6064820152608401610be2565b6001600160a01b03838116600081815260666020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6001600160a01b03163b151590565b600054610100900460ff16612e8d5760405162461bcd60e51b8152600401610be290614cb9565b610dfd816132cf565b600054610100900460ff16612ebd5760405162461bcd60e51b8152600401610be290614cb9565b6115036132ff565b6001600160a01b038416612eeb5760405162461bcd60e51b8152600401610be290614a71565b6000612ef5612560565b90506000612f02856131c2565b90506000612f0f856131c2565b905060008681526065602090815260408083206001600160a01b038c16845290915290205485811015612f545760405162461bcd60e51b8152600401610be290614ab6565b60008781526065602090815260408083206001600160a01b038d8116855292528083208985039055908a16825281208054889290612f9390849061428f565b909155505060408051888152602081018890526001600160a01b03808b16928c82169291881691600080516020614eb2833981519152910160405180910390a4612fe1848a8a8a8a8a61320d565b505050505050505050565b612ffe846001600160a01b0316612e57565b15610e6a5760405163bc197c8160e01b81526001600160a01b0385169063bc197c81906130379089908990889088908890600401614d04565b6020604051808303816000875af1925050508015613072575060408051601f3d908101601f1916820190925261306f91810190614d62565b60015b61311e5761307e614d7f565b806308c379a0036130b75750613092614d9b565b8061309d57506130b9565b8060405162461bcd60e51b8152600401610be29190613564565b505b60405162461bcd60e51b815260206004820152603460248201527f455243313135353a207472616e7366657220746f206e6f6e2d455243313135356044820152732932b1b2b4bb32b91034b6b83632b6b2b73a32b960611b6064820152608401610be2565b6001600160e01b0319811663bc197c8160e01b14612ba75760405162461bcd60e51b8152600401610be290614e24565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461319b576040519150601f19603f3d011682016040523d82523d6000602084013e6131a0565b606091505b5050905080611cf8576040516312171d8360e31b815260040160405180910390fd5b604080516001808252818301909252606091600091906020808301908036833701905050905082816000815181106131fc576131fc614263565b602090810291909101015292915050565b61321f846001600160a01b0316612e57565b15610e6a5760405163f23a6e6160e01b81526001600160a01b0385169063f23a6e61906132589089908990889088908890600401614e6c565b6020604051808303816000875af1925050508015613293575060408051601f3d908101601f1916820190925261329091810190614d62565b60015b61329f5761307e614d7f565b6001600160e01b0319811663f23a6e6160e01b14612ba75760405162461bcd60e51b8152600401610be290614e24565b600054610100900460ff166132f65760405162461bcd60e51b8152600401610be290614cb9565b610dfd81613336565b600054610100900460ff166133265760405162461bcd60e51b8152600401610be290614cb9565b611503613331612560565b612d25565b606761109282826143b8565b6040518060c0016040528060006001600160a01b0316815260200160006001600160a01b03168152602001606081526020016060815260200160008152602001600081525090565b828054828255906000526020600020906007016008900481019282156134295791602002820160005b838211156133f757835183826101000a81548163ffffffff021916908363ffffffff16021790555092602001926004016020816003010492830192600103026133b3565b80156134275782816101000a81549063ffffffff02191690556004016020816003010492830192600103026133f7565b505b50613435929150613474565b5090565b828054828255906000526020600020908101928215613429579160200282015b82811115613429578251825591602001919060010190613459565b5b808211156134355760008155600101613475565b6001600160a01b0381168114610dfd57600080fd5b80356134a981613489565b919050565b600080604083850312156134c157600080fd5b82356134cc81613489565b946020939093013593505050565b6001600160e01b031981168114610dfd57600080fd5b60006020828403121561350257600080fd5b813561350d816134da565b9392505050565b60005b8381101561352f578181015183820152602001613517565b50506000910152565b60008151808452613550816020860160208601613514565b601f01601f19169290920160200192915050565b60208152600061350d6020830184613538565b61ffff81168114610dfd57600080fd5b60006020828403121561359957600080fd5b813561350d81613577565b6000602082840312156135b657600080fd5b5035919050565b600060408284031215610e4e57600080fd5b60008083601f8401126135e157600080fd5b5081356001600160401b038111156135f857600080fd5b602083019150836020828501011115610f7157600080fd5b60008060008060008060a0878903121561362957600080fd5b86356001600160401b038082111561364057600080fd5b61364c8a838b016135bd565b975060208901359650604089013595506060890135915061366c82613489565b9093506080880135908082111561368257600080fd5b5061368f89828a016135cf565b979a9699509497509295939492505050565b600080604083850312156136b457600080fd5b82356136bf81613489565b915060208301356136cf81613489565b809150509250929050565b6000602082840312156136ec57600080fd5b813561350d81613489565b6000806040838503121561370a57600080fd5b50508035926020909101359150565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052604160045260246000fd5b601f8201601f191681016001600160401b038111828210171561376d5761376d613732565b6040525050565b60405161016081016001600160401b038111828210171561379757613797613732565b60405290565b60006001600160401b038211156137b6576137b6613732565b5060051b60200190565b600082601f8301126137d157600080fd5b813560206137de8261379d565b6040516137eb8282613748565b83815260059390931b850182019282810191508684111561380b57600080fd5b8286015b84811015613826578035835291830191830161380f565b509695505050505050565b600082601f83011261384257600080fd5b81356001600160401b0381111561385b5761385b613732565b604051613872601f8301601f191660200182613748565b81815284602083860101111561388757600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080600060a086880312156138bc57600080fd5b85356138c781613489565b945060208601356138d781613489565b935060408601356001600160401b03808211156138f357600080fd5b6138ff89838a016137c0565b9450606088013591508082111561391557600080fd5b61392189838a016137c0565b9350608088013591508082111561393757600080fd5b5061394488828901613831565b9150509295509295909350565b60006020828403121561396357600080fd5b81356001600160401b0381111561397957600080fd5b61398584828501613831565b949350505050565b600080604083850312156139a057600080fd5b82356139ab81613489565b915060208301356136cf81613577565b600082601f8301126139cc57600080fd5b813560206139d98261379d565b6040516139e68282613748565b83815260059390931b8501820192828101915086841115613a0657600080fd5b8286015b84811015613826578035613a1d81613489565b8352918301918301613a0a565b60008060408385031215613a3d57600080fd5b82356001600160401b0380821115613a5457600080fd5b613a60868387016139bb565b93506020850135915080821115613a7657600080fd5b50613a83858286016137c0565b9150509250929050565b600081518084526020808501945080840160005b83811015613abd57815187529582019590820190600101613aa1565b509495945050505050565b60208152600061350d6020830184613a8d565b60008083601f840112613aed57600080fd5b5081356001600160401b03811115613b0457600080fd5b6020830191508360208260051b8501011115610f7157600080fd5b60008060008060008060008060008060c08b8d031215613b3e57600080fd5b8a356001600160401b0380821115613b5557600080fd5b613b618e838f016135bd565b9b5060208d0135915080821115613b7757600080fd5b613b838e838f01613adb565b909b50995060408d0135915080821115613b9c57600080fd5b613ba88e838f01613adb565b909950975060608d0135915080821115613bc157600080fd5b613bcd8e838f01613adb565b9097509550859150613be160808e0161349e565b945060a08d0135915080821115613bf757600080fd5b50613c048d828e016135cf565b915080935050809150509295989b9194979a5092959850565b600060208284031215613c2f57600080fd5b81356001600160401b03811115613c4557600080fd5b613985848285016139bb565b60c081526000613c6460c0830189613538565b6001600160a01b039790971660208301525061ffff94851660408201529284166060840152908316608083015290911660a090910152919050565b600080600080600080600060c0888a031215613cba57600080fd5b87356001600160401b0380821115613cd157600080fd5b613cdd8b838c016135bd565b985060208a0135975060408a01359150613cf682613489565b90955060608901359450608089013590613d0f82613489565b90935060a08901359080821115613d2557600080fd5b50613d328a828b016135cf565b989b979a50959850939692959293505050565b8015158114610dfd57600080fd5b60008060408385031215613d6657600080fd5b8235613d7181613489565b915060208301356136cf81613d45565b80356001600160801b03811681146134a957600080fd5b63ffffffff81168114610dfd57600080fd5b80356134a981613d98565b600082601f830112613dc657600080fd5b81356020613dd38261379d565b604051613de08282613748565b83815260059390931b8501820192828101915086841115613e0057600080fd5b8286015b84811015613826578035613e1781613d98565b8352918301918301613e04565b600080600060608486031215613e3957600080fd5b833592506020840135915060408401356001600160401b0380821115613e5e57600080fd5b908501906101608288031215613e7357600080fd5b613e7b613774565b613e8483613d81565b8152613e9260208401613d81565b6020820152613ea360408401613d81565b6040820152613eb460608401613daa565b6060820152613ec560808401613daa565b6080820152613ed660a08401613daa565b60a0820152613ee760c08401613daa565b60c0820152613ef860e08401613daa565b60e0820152610100613f0b818501613daa565b908201526101208381013583811115613f2357600080fd5b613f2f8a828701613db5565b8284015250506101409150613f4582840161349e565b828201528093505050509250925092565b60008060408385031215613f6957600080fd5b82356001600160401b0380821115613f8057600080fd5b613f8c86838701613db5565b93506020850135915080821115613fa257600080fd5b50613a8385828601613831565b600060e08284031215610e4e57600080fd5b60008060008060006101608688031215613fda57600080fd5b85356001600160401b0380821115613ff157600080fd5b613ffd89838a01613831565b9650602088013591508082111561401357600080fd5b61401f89838a01613831565b9550604088013591508082111561403557600080fd5b5061404288828901613faf565b9350506140528760608801613faf565b915061014086013561406381613489565b809150509295509295909350565b60008060006060848603121561408657600080fd5b833592506020840135915060408401356001600160401b038111156140aa57600080fd5b840161010081870312156140bd57600080fd5b809150509250925092565b6000806000606084860312156140dd57600080fd5b833592506020840135915060408401356140bd81613d45565b6020808252825182820181905260009190848201906040850190845b8181101561413457835163ffffffff1683529284019291840191600101614112565b50909695505050505050565b600080600080600060a0868803121561415857600080fd5b853561416381613489565b9450602086013561417381613489565b9350604086013592506060860135915060808601356001600160401b0381111561419c57600080fd5b61394488828901613831565b600181811c908216806141bc57607f821691505b602082108103610e4e57634e487b7160e01b600052602260045260246000fd5b60008084546141ea816141a8565b60018281168015614202576001811461421757614246565b60ff1984168752821515830287019450614246565b8860005260208060002060005b8581101561423d5781548a820152908401908201614224565b50505082870194505b50505050835161425a818360208801613514565b01949350505050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610c1057610c10614279565b6000600182016142b4576142b4614279565b5060010190565b81810381811115610c1057610c10614279565b8082028115828204841417610c1057610c10614279565b60008261430257634e487b7160e01b600052601260045260246000fd5b500490565b6020808252602e908201527f455243313135353a2063616c6c6572206973206e6f7420746f6b656e206f776e60408201526d195c881bdc88185c1c1c9bdd995960921b606082015260800190565b5b818110156110925760008155600101614356565b601f821115611cf857806000526020600020601f840160051c810160208510156143915750805b610fcf601f850160051c830182614355565b600019600383901b1c191660019190911b1790565b81516001600160401b038111156143d1576143d1613732565b6143e5816143df84546141a8565b8461436a565b602080601f83116001811461441457600084156144025750858301515b61440c85826143a3565b865550610e6a565b600085815260208120601f198616915b8281101561444357888601518255948401946001909101908401614424565b50858210156144615787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b600081518084526020808501945080840160005b83811015613abd5781516001600160a01b031687529582019590820190600101614485565b84815283602082015260018060a01b038316604082015260806060820152600061222e6080830184614471565b6000602082840312156144e957600080fd5b815161350d81613d45565b663337b932bb32b960c91b815260070190565b60008251614519818460208701613514565b9190910192915050565b6001600160401b0383111561453a5761453a613732565b61454e8361454883546141a8565b8361436a565b6000601f84116001811461457c576000851561456a5750838201355b61457486826143a3565b845550610fcf565b600083815260209020601f19861690835b828110156145ad578685013582556020948501946001909201910161458d565b50868210156145ca5760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b60008135610c1081613489565b80546001600160a01b0319166001600160a01b0392909216919091179055565b6000808335601e1984360301811261462057600080fd5b8301803591506001600160401b0382111561463a57600080fd5b6020019150600581901b3603821315610f7157600080fd5b600160401b82111561466657614666613732565b805482825580831015611cf8578160005260206000206007840160031c8101601c8560021b1680156146a9576000198083018054828460200360031b1c16815550505b50610fcf6007840160031c830182614355565b60008135610c1081613d98565b6001600160401b038311156146e0576146e0613732565b6146ea8382614652565b60008181526020902082908460031c60005b81811015614755576000805b60088110156147485761473761471d876146bc565b63ffffffff600584901b81811b19861692909116901b1790565b602096909601959150600101614708565b50838201556001016146fc565b506007198616808703818814614794576000805b8281101561478e5761477d61471d886146bc565b602097909701969150600101614769565b50848401555b5050505050505050565b60008135610c1081613577565b805463ffff00008360101b1663ffff0000198216178255505050565b805461ffff60201b191660209290921b61ffff60201b16919091179055565b805461ffff60301b191660309290921b61ffff60301b16919091179055565b8135601e1983360301811261481957600080fd5b820180356001600160401b0381111561483157600080fd5b60208201915080360382131561484657600080fd5b614851818385614523565b505061486b614862602084016145dc565b600183016145e9565b6148786040830183614609565b6148868183600286016146c9565b5050600381016148ae61489b6060850161479e565b825461ffff191661ffff91909116178255565b6148c36148bd6080850161479e565b826147ab565b6148d86148d260a0850161479e565b826147c7565b611cf86148e760c0850161479e565b826147e6565b61ffff81811683821601908082111561490857614908614279565b5092915050565b813561491a81613577565b815461ffff191661ffff821617825550602082013561493881613577565b61494281836147ab565b50604082013561495181613577565b61495b81836147c7565b50606082013561496a81613577565b61497481836147e6565b50608082013561498381613489565b8154600160401b600160e01b03191660409190911b600160401b600160e01b031617815560a08201356149b581613489565b6149c281600184016145e9565b5060c08201356149d181613489565b611cf881600284016145e9565b6000602082840312156149f057600080fd5b61350d82613d81565b600060208284031215614a0b57600080fd5b813561350d81613d98565b94855261ffff939093166020850152604084019190915260608301521515608082015260a00190565b600060208284031215614a5157600080fd5b5051919050565b8281526040602082015260006139856040830184614471565b60208082526025908201527f455243313135353a207472616e7366657220746f20746865207a65726f206164604082015264647265737360d81b606082015260800190565b6020808252602a908201527f455243313135353a20696e73756666696369656e742062616c616e636520666f60408201526939103a3930b739b332b960b11b606082015260800190565b604081526000614b136040830185613a8d565b8281036020840152614b258185613a8d565b95945050505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b600060018060a01b0380835116845280602084015116602085015250604082015160c06040850152614b8c60c0850182613a8d565b905060608301518482036060860152614ba58282613a8d565b9150506080830151608085015260a083015160a08501528091505092915050565b60006101008b83528a6020840152806040840152893581840152506020890135601e198a3603018112614bf857600080fd5b89016020810190356001600160401b03811115614c1457600080fd5b8060051b803603831315614c2757600080fd5b604061012086015261014085018290526101606001600160fb1b03831115614c4e57600080fd5b81848288013781860193508b60608701528a6080870152808685030160a0870152614c7c8185018a8c614b2e565b935050505082810360c0840152614c938186614b57565b915050614cab60e08301846001600160801b03169052565b9a9950505050505050505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6001600160a01b0386811682528516602082015260a060408201819052600090614d3090830186613a8d565b8281036060840152614d428186613a8d565b90508281036080840152614d568185613538565b98975050505050505050565b600060208284031215614d7457600080fd5b815161350d816134da565b600060033d1115614d985760046000803e5060005160e01c5b90565b600060443d1015614da95790565b6040516003193d81016004833e81513d6001600160401b038083116024840183101715614dd857505050505090565b8285019150815181811115614df05750505050505090565b843d8701016020828501011115614e0a5750505050505090565b614e1960208286010187613748565b509095945050505050565b60208082526028908201527f455243313135353a204552433131353552656365697665722072656a656374656040820152676420746f6b656e7360c01b606082015260800190565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090614ea690830184613538565b97965050505050505056fec3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62a2646970667358221220513d73faf61591316cff61468d34703c43914cb0ff24101e26d89d280981272164736f6c63430008140033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in MON
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.