Overview
ETH Balance
More Info
ContractCreator
Multichain Info
Latest 1 from a total of 1 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
Amount
|
||||
|---|---|---|---|---|---|---|---|---|---|
| Deploy Migration... | 26934676 | 183 days ago | IN | 0 ETH | 0.00000486 |
Latest 5 internal transactions
| Parent Transaction Hash | Block | From | To | Amount | ||
|---|---|---|---|---|---|---|
| 26934676 | 183 days ago | Contract Creation | 0 ETH | |||
| 26934676 | 183 days ago | Contract Creation | 0 ETH | |||
| 26934676 | 183 days ago | Contract Creation | 0 ETH | |||
| 26934676 | 183 days ago | Contract Creation | 0 ETH | |||
| 26934676 | 183 days ago | Contract Creation | 0 ETH |
Contract Source Code Verified (Exact Match)
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./ZenToken.sol";
import "./EONBackupVault.sol";
import "./ZendBackupVault.sol";
import "./LinearTokenVesting.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/// @title ZenMigrationFactory
/// @notice This is a factory contract responsible for deploying all the contracts used for ZEN migration.
contract ZenMigrationFactory is Ownable {
ZenToken public token;
EONBackupVault public eonVault;
ZendBackupVault public zendVault;
LinearTokenVesting public horizenFoundationVestingContract;
LinearTokenVesting public horizenDaoVestingContract;
uint256 internal constant VESTING_TIME_BETWEEN_INTERVALS = 30 * 24 * 60 * 60; //Length in seconds of each vesting interval (30 days)
uint256 internal constant VESTING_INTERVALS = 48; //Total number of vesting intervals
error ContractsAlreadyDeployed();
event ZenMigrationContractsCreated(address token, address eonVault, address zendVault, address horizenFoundationVestingContract, address horizenDaoVestingContract);
/// @notice Smart contract constructor
/// @param _admin The only entity authorized to deploy migration contracts and the future owner of the contracts themselves
constructor(address _admin) Ownable(_admin) {}
/// @notice Deploys the migration contracts and the ERC20 token contract.
/// @param tokenName Name of the token
/// @param tokenSymbol Token ticker
/// @param base_claim_message One of the parts of the message to sign for zen claim
/// @param horizenFoundationAdmin The account that has the rights to change the vesting parameters for the Foundation
/// @param horizenFoundationBeneficiary Address who will receive the remaining portion of Zen reserved to the Foundation
/// @param horizenDaoAdmin The account that has the rights to change the vesting parameters for the DAO
/// @param horizenDaoBeneficiary Address who will receive the remaining portion of Zen reserved to the DAO
function deployMigrationContracts(
string memory tokenName,
string memory tokenSymbol,
string memory base_claim_message,
address horizenFoundationAdmin,
address horizenFoundationBeneficiary,
address horizenDaoAdmin,
address horizenDaoBeneficiary
) public onlyOwner {
if (address(token) != address(0)) {
revert ContractsAlreadyDeployed();
}
eonVault = new EONBackupVault(address(this));
zendVault = new ZendBackupVault(address(this), base_claim_message);
horizenFoundationVestingContract = new LinearTokenVesting(horizenFoundationBeneficiary, VESTING_TIME_BETWEEN_INTERVALS, VESTING_INTERVALS);
horizenDaoVestingContract = new LinearTokenVesting(horizenDaoBeneficiary, VESTING_TIME_BETWEEN_INTERVALS, VESTING_INTERVALS);
token = new ZenToken(
tokenName,
tokenSymbol,
address(eonVault),
address(zendVault),
address(horizenFoundationVestingContract),
address(horizenDaoVestingContract)
);
eonVault.setERC20(address(token));
zendVault.setERC20(address(token));
horizenFoundationVestingContract.setERC20(address(token));
horizenDaoVestingContract.setERC20(address(token));
eonVault.transferOwnership(owner());
zendVault.transferOwnership(owner());
horizenFoundationVestingContract.transferOwnership(horizenFoundationAdmin);
horizenDaoVestingContract.transferOwnership(horizenDaoAdmin);
emit ZenMigrationContractsCreated(address(token), address(eonVault), address(zendVault), address(horizenFoundationVestingContract), address(horizenDaoVestingContract));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance < type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Capped.sol)
pragma solidity ^0.8.20;
import {ERC20} from "../ERC20.sol";
/**
* @dev Extension of {ERC20} that adds a cap to the supply of tokens.
*/
abstract contract ERC20Capped is ERC20 {
uint256 private immutable _cap;
/**
* @dev Total supply cap has been exceeded.
*/
error ERC20ExceededCap(uint256 increasedSupply, uint256 cap);
/**
* @dev The supplied cap is not a valid cap.
*/
error ERC20InvalidCap(uint256 cap);
/**
* @dev Sets the value of the `cap`. This value is immutable, it can only be
* set once during construction.
*/
constructor(uint256 cap_) {
if (cap_ == 0) {
revert ERC20InvalidCap(0);
}
_cap = cap_;
}
/**
* @dev Returns the cap on the token's total supply.
*/
function cap() public view virtual returns (uint256) {
return _cap;
}
/**
* @dev See {ERC20-_update}.
*/
function _update(address from, address to, uint256 value) internal virtual override {
super._update(from, to, value);
if (from == address(0)) {
uint256 maxSupply = cap();
uint256 supply = totalSupply();
if (supply > maxSupply) {
revert ERC20ExceededCap(supply, maxSupply);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2²⁵⁶ + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= prod1) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 exp;
unchecked {
exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
value >>= exp;
result += exp;
exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
value >>= exp;
result += exp;
exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
value >>= exp;
result += exp;
exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
value >>= exp;
result += exp;
exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
value >>= exp;
result += exp;
exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
value >>= exp;
result += exp;
exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
value >>= exp;
result += exp;
result += SafeCast.toUint(value > 1);
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 isGt;
unchecked {
isGt = SafeCast.toUint(value > (1 << 128) - 1);
value >>= isGt * 128;
result += isGt * 16;
isGt = SafeCast.toUint(value > (1 << 64) - 1);
value >>= isGt * 64;
result += isGt * 8;
isGt = SafeCast.toUint(value > (1 << 32) - 1);
value >>= isGt * 32;
result += isGt * 4;
isGt = SafeCast.toUint(value > (1 << 16) - 1);
value >>= isGt * 16;
result += isGt * 2;
result += SafeCast.toUint(value > (1 << 8) - 1);
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
}
}
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
// Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
// taking advantage of the most significant (or "sign" bit) in two's complement representation.
// This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
// the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
int256 mask = n >> 255;
// A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
return uint256((n + mask) ^ mask);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SafeCast} from "./math/SafeCast.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
using SafeCast for *;
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev The string being parsed contains characters that are not in scope of the given base.
*/
error StringsInvalidChar();
/**
* @dev The string being parsed is not a properly formatted address.
*/
error StringsInvalidAddressFormat();
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly ("memory-safe") {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly ("memory-safe") {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
* representation, according to EIP-55.
*/
function toChecksumHexString(address addr) internal pure returns (string memory) {
bytes memory buffer = bytes(toHexString(addr));
// hash the hex part of buffer (skip length + 2 bytes, length 40)
uint256 hashValue;
assembly ("memory-safe") {
hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
}
for (uint256 i = 41; i > 1; --i) {
// possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
// case shift by xoring with 0x20
buffer[i] ^= 0x20;
}
hashValue >>= 4;
}
return string(buffer);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
/**
* @dev Parse a decimal string and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input) internal pure returns (uint256) {
return parseUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseUint} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
uint256 result = 0;
for (uint256 i = begin; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 9) return (false, 0);
result *= 10;
result += chr;
}
return (true, result);
}
/**
* @dev Parse a decimal string and returns the value as a `int256`.
*
* Requirements:
* - The string must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input) internal pure returns (int256) {
return parseInt(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {
(bool success, int256 value) = tryParseInt(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if
* the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {
return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);
}
uint256 private constant ABS_MIN_INT256 = 2 ** 255;
/**
* @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character or if the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, int256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseIntUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseInt} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseIntUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, int256 value) {
bytes memory buffer = bytes(input);
// Check presence of a negative sign.
bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
bool positiveSign = sign == bytes1("+");
bool negativeSign = sign == bytes1("-");
uint256 offset = (positiveSign || negativeSign).toUint();
(bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);
if (absSuccess && absValue < ABS_MIN_INT256) {
return (true, negativeSign ? -int256(absValue) : int256(absValue));
} else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {
return (true, type(int256).min);
} else return (false, 0);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input) internal pure returns (uint256) {
return parseHexUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseHexUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an
* invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseHexUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseHexUint} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseHexUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
// skip 0x prefix if present
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 offset = hasPrefix.toUint() * 2;
uint256 result = 0;
for (uint256 i = begin + offset; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 15) return (false, 0);
result *= 16;
unchecked {
// Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).
// This guaratees that adding a value < 16 will not cause an overflow, hence the unchecked.
result += chr;
}
}
return (true, result);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as an `address`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input) internal pure returns (address) {
return parseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {
(bool success, address value) = tryParseAddress(input, begin, end);
if (!success) revert StringsInvalidAddressFormat();
return value;
}
/**
* @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly
* formatted address. See {parseAddress} requirements.
*/
function tryParseAddress(string memory input) internal pure returns (bool success, address value) {
return tryParseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly
* formatted address. See {parseAddress} requirements.
*/
function tryParseAddress(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, address value) {
if (end > bytes(input).length || begin > end) return (false, address(0));
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 expectedLength = 40 + hasPrefix.toUint() * 2;
// check that input is the correct length
if (end - begin == expectedLength) {
// length guarantees that this does not overflow, and value is at most type(uint160).max
(bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);
return (s, address(uint160(v)));
} else {
return (false, address(0));
}
}
function _tryParseChr(bytes1 chr) private pure returns (uint8) {
uint8 value = uint8(chr);
// Try to parse `chr`:
// - Case 1: [0-9]
// - Case 2: [a-f]
// - Case 3: [A-F]
// - otherwise not supported
unchecked {
if (value > 47 && value < 58) value -= 48;
else if (value > 96 && value < 103) value -= 87;
else if (value > 64 && value < 71) value -= 55;
else return type(uint8).max;
}
return value;
}
/**
* @dev Reads a bytes32 from a bytes array without bounds checking.
*
* NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the
* assembly block as such would prevent some optimizations.
*/
function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
// This is not memory safe in the general case, but all calls to this private function are within bounds.
assembly ("memory-safe") {
value := mload(add(buffer, add(0x20, offset)))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./interfaces/IZenToken.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/// @title EONBackupVault
/// @notice This contract is used to store balances from old EON chain, and, once all are loaded, distribute corresponding ZEN in the new chain.
/// In the constructor will receive an admin address (owner), the only entity authorized to perform operations. Before loading all the accounts,
// the cumulative hash calculated with all the accounts dump data must be set.
///
contract EONBackupVault is Ownable {
struct AddressValue {
address addr;
uint256 value;
}
// Map of the balances
mapping(address => uint256) public balances;
// Array to track inserted addresses
address[] private addressList;
// Cumulative Hash calculated
bytes32 public _cumulativeHash;
// Final expected Cumulative Hash, used for checkpoint, to unlock distribution
bytes32 public cumulativeHashCheckpoint;
// Tracks rewarded addresses (index to next address to reward)
uint256 private nextRewardIndex;
IZenToken public zenToken;
error AddressNotValid();
error CumulativeHashNotValid();
error CumulativeHashCheckpointReached();
error CumulativeHashCheckpointNotSet();
error UnauthorizedOperation();
error ERC20NotSet();
error NothingToDistribute();
/// @notice Smart contract constructor
/// @param _admin the only entity authorized to perform restore and distribution operations
constructor(address _admin) Ownable(_admin) {
}
/// @notice Set expected cumulative hash after all the data has been loaded
/// @param _cumulativeHashCheckpoint a cumulative recursive hash calculated with all the dump data.
/// Will be used to verify the consistency of the restored data, and as
/// a checkpoint to understand when all the data has been loaded and the distribution
/// can start
function setCumulativeHashCheckpoint(bytes32 _cumulativeHashCheckpoint) public onlyOwner {
if(_cumulativeHashCheckpoint == bytes32(0)) revert CumulativeHashNotValid();
if (cumulativeHashCheckpoint != bytes32(0)) revert UnauthorizedOperation(); //already set
cumulativeHashCheckpoint = _cumulativeHashCheckpoint;
}
/// @notice Insert a new batch of tuples (address, value) and updates the cumulative hash.
/// To guarantee the same algorithm is applied, the expected cumulativeHash after the batch processing must be provided explicitly
function batchInsert(bytes32 expectedCumulativeHash, AddressValue[] memory addressValues) public onlyOwner {
if (cumulativeHashCheckpoint == bytes32(0)) revert CumulativeHashCheckpointNotSet();
if(_cumulativeHash == cumulativeHashCheckpoint) revert CumulativeHashCheckpointReached();
uint256 i;
bytes32 auxHash = _cumulativeHash;
while (i != addressValues.length) {
balances[addressValues[i].addr] = addressValues[i].value;
addressList.push(addressValues[i].addr);
auxHash = keccak256(abi.encode(auxHash, addressValues[i].addr, addressValues[i].value));
unchecked { ++i; }
}
_cumulativeHash = auxHash;
if (expectedCumulativeHash != _cumulativeHash) revert CumulativeHashNotValid();
}
/// @notice Set official ZEN ERC-20 smart contract that will be used for minting
function setERC20(address addr) public onlyOwner {
if (address(zenToken) != address(0)) revert UnauthorizedOperation(); //ERC-20 address already set
if(addr == address(0)) revert AddressNotValid();
zenToken = IZenToken(addr);
}
/// @notice Distribute ZEN for the next (max) "maxCount" addresses, until we have reached the end of the list
/// Can be executed only when we have reached the planned cumulativeHashCheckpoint (meaning all data has been loaded)
function distribute(uint256 maxCount) public onlyOwner {
if (cumulativeHashCheckpoint == bytes32(0)) revert CumulativeHashCheckpointNotSet();
if (address(zenToken) == address(0)) revert ERC20NotSet();
if (_cumulativeHash != cumulativeHashCheckpoint) revert CumulativeHashNotValid(); //Loaded data not matching - distribution locked
if (nextRewardIndex == addressList.length) revert NothingToDistribute();
uint256 count = 0;
uint256 _nextRewardIndex = nextRewardIndex;
while (_nextRewardIndex != addressList.length && count != maxCount) {
address addr = addressList[_nextRewardIndex];
uint256 amount = balances[addr];
if (amount > 0) {
balances[addr] = 0;
zenToken.mint(addr, amount);
}
unchecked {
++_nextRewardIndex;
++count;
}
}
nextRewardIndex = _nextRewardIndex;
if (nextRewardIndex == addressList.length){
zenToken.notifyMintingDone();
}
}
/// @notice Return true if admin is able to distribute more
function moreToDistribute() public view returns (bool) {
return (address(zenToken) != address(0)) &&
(_cumulativeHash != bytes32(0)) &&
_cumulativeHash == cumulativeHashCheckpoint &&
nextRewardIndex < addressList.length;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IVesting {
function beneficiary() external view returns(address);
function startVesting() external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IZenToken is IERC20 {
function mint(address to, uint256 amount) external;
function notifyMintingDone() external;
function symbol() external view returns(string memory);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IVesting.sol";
/// @title LinearTokenVesting
/// @notice This contract implements the vesting strategy for the remaining ZEN supply.
contract LinearTokenVesting is Ownable, IVesting {
uint8 private _allowedOwnershipTransfers = 2;
ERC20 public token;
address public beneficiary;
uint256 public amountForEachClaim;
uint256 public startTimestamp;
uint256 public timeBetweenClaims;
uint256 public intervalsToClaim;
uint256 public intervalsAlreadyClaimed;
event Claimed(address indexed claimer, address indexed beneficiary, uint256 claimAmount, uint256 timestamp);
event ChangedBeneficiary(address indexed newBeneficiary, address indexed oldBeneficiary);
event ChangedVestingParams(
uint256 newTimeBetweenClaims,
uint256 newIntervalsToClaim,
uint256 oldTimeBetweenClaims,
uint256 oldIntervalsToClaim);
error AddressParameterCantBeZero();
error TokenAndBeneficiaryCantBeTheSame();
error AmountCantBeZero();
error InvalidTimes();
error InvalidNumOfIntervals();
error NothingToClaim();
error ClaimCompleted();
error UnauthorizedOperation();
error ERC20NotSet();
error VestingNotStartedYet();
error VestingAlreadyStarted();
error UnauthorizedAccount(address account);
error ImmutableOwner();
/// @notice Smart contract constructor
/// @param _beneficiary the account that will receive the vested zen
/// @param _timeBetweenClaims The minimum time in seconds that must be waited between claims
/// @param _intervalsToClaim The number of vesting periods
constructor(address _beneficiary, uint256 _timeBetweenClaims, uint256 _intervalsToClaim) Ownable(msg.sender) {
_setBeneficiary(_beneficiary);
_setVestingParams(_timeBetweenClaims, _intervalsToClaim);
}
/// @notice Set official ZEN ERC-20 smart contract that will be used for initial transfer and start vesting
/// @param addr Address of the ERC20
function setERC20(address addr) public onlyOwner {
if (address(token) != address(0)) revert UnauthorizedOperation(); //ERC-20 address already set
if(addr == address(0)) revert AddressParameterCantBeZero();
if(addr == beneficiary) revert TokenAndBeneficiaryCantBeTheSame();
token = ERC20(addr);
}
/// @notice This function is called by the ERC20 when minting has ended, to notify that the vesting period can start.
function startVesting() public {
if (msg.sender != address(token)) revert UnauthorizedOperation();
if (amountForEachClaim != 0 || startTimestamp != 0) revert VestingAlreadyStarted(); //already called
uint256 totalToVest = token.balanceOf(address(this));
if (totalToVest == 0) revert AmountCantBeZero();
amountForEachClaim = totalToVest / intervalsToClaim;
startTimestamp = block.timestamp;
}
/// @notice This function is called for transfer to beneficiary the amount that was accrued from the last claim. If it is called before at least one interval has passed, the claim fails.
/// If more than one period have passed, the sum of amounts of the passed periods is transferred.
function claim() public {
if (address(token) == address(0)) revert ERC20NotSet();
if (startTimestamp == 0) revert VestingNotStartedYet();
if (intervalsAlreadyClaimed == intervalsToClaim) revert ClaimCompleted();
uint256 periodsPassed = (block.timestamp - (startTimestamp + timeBetweenClaims * intervalsAlreadyClaimed)) / timeBetweenClaims;
if (periodsPassed == 0) revert NothingToClaim();
uint256 intervalsToClaimNow = _min(intervalsToClaim - intervalsAlreadyClaimed, periodsPassed);
intervalsAlreadyClaimed += intervalsToClaimNow;
uint256 amountToClaimNow;
if (intervalsAlreadyClaimed < intervalsToClaim) {
amountToClaimNow = intervalsToClaimNow * amountForEachClaim;
}
else {
amountToClaimNow = token.balanceOf(address(this));
}
emit Claimed(msg.sender, beneficiary, amountToClaimNow, block.timestamp);
token.transfer(beneficiary, amountToClaimNow);
}
/// @notice Changes the beneficiary of the vesting
/// @param newBeneficiary Address of the new beneficiary
function changeBeneficiary(address newBeneficiary) public onlyOwner {
if (intervalsAlreadyClaimed == intervalsToClaim) revert UnauthorizedOperation();
if (newBeneficiary == address(token)) revert TokenAndBeneficiaryCantBeTheSame();
address oldBeneficiary = beneficiary;
_setBeneficiary(newBeneficiary);
emit ChangedBeneficiary(newBeneficiary, oldBeneficiary);
}
/// @notice Changes the number of vesting intervals and their duration. After this method has been called, the supply not claimed yet (i.e the balance of this contract) will be able to be claimed
/// in a time equal to newTimeBetweenClaims * newNumberOfIntervalsToClaim. Note that the remaining supply includes the amounts already accrued but not claimed yet.
/// @param newTimeBetweenClaims New duration in seconds of a vesting interval
/// @param newNumberOfIntervalsToClaim Number of intervals that need to pass for vesting the remaining supply
function changeVestingParams(uint256 newTimeBetweenClaims, uint256 newNumberOfIntervalsToClaim) public onlyOwner {
if (intervalsAlreadyClaimed == intervalsToClaim) revert UnauthorizedOperation();
uint256 oldTimeBetweenClaims = timeBetweenClaims;
uint256 oldNumberOfIntervalsToClaim = intervalsToClaim;
_setVestingParams(newTimeBetweenClaims, newNumberOfIntervalsToClaim);
// if startVesting was already called, startTimestamp, amountForEachClaim and intervalsAlreadyClaimed need to be reset
if (startTimestamp != 0){
uint256 totalToVest = token.balanceOf(address(this));
amountForEachClaim = totalToVest / intervalsToClaim;
startTimestamp = block.timestamp;
intervalsAlreadyClaimed = 0;
}
emit ChangedVestingParams(newTimeBetweenClaims, newNumberOfIntervalsToClaim, oldTimeBetweenClaims, oldNumberOfIntervalsToClaim);
}
function _min(uint256 a, uint256 b) internal pure returns(uint256) {
return a < b? a : b;
}
function _setBeneficiary(address newBeneficiary) internal {
if(newBeneficiary == address(0)) revert AddressParameterCantBeZero();
beneficiary = newBeneficiary;
}
function _setVestingParams(uint256 newTimeBetweenClaims, uint256 newNumberOfIntervalsToClaim) internal {
if(newNumberOfIntervalsToClaim == 0) revert InvalidNumOfIntervals();
if(newTimeBetweenClaims == 0) revert InvalidTimes();
timeBetweenClaims = newTimeBetweenClaims;
intervalsToClaim = newNumberOfIntervalsToClaim;
}
function _transferOwnership(address newOwner) internal override {
if (_allowedOwnershipTransfers == 0) revert ImmutableOwner();
unchecked {--_allowedOwnershipTransfers;}
super._transferOwnership(newOwner);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title VerificationLibrary
/// @notice Solidity Verification functions for signatures generated with Horizen ZEND mainchain.
library VerificationLibrary {
error InvalidSignature(); //signature not correctly generated
error SignatureNotMatching(); //signature was correctly generated but public key not matching
error SignatureMustBe65Bytes();
bytes private constant MESSAGE_MAGIC_BYTES = bytes("Zcash Signed Message:\n");
struct Signature {
bytes32 r;
bytes32 s;
uint8 v;
}
/// @notice Parse a ZEND signature from its byte representation.
/// First byte represents the v field, then 32 bytes for r field and 32 bytes for s field
function parseZendSignature(bytes memory hexSignature) internal pure returns (Signature memory){
if(hexSignature.length != 65) revert SignatureMustBe65Bytes();
bytes32 r;
bytes32 s;
uint8 v = uint8(hexSignature[0]);
assembly {
r := mload(add(hexSignature, 33)) // bytes 1-32
s := mload(add(hexSignature, 65)) // bytes 33-65 bytes
}
// Rejects the “high-s” twin ( s′ = n − s ) that signs the very same message, to avoid S-malleability issues
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0)
revert InvalidSignature();
return Signature({r: r, s: s, v: v});
}
function verifyZendSignatureBool(bytes32 messageHash, Signature memory signature, bytes32 pubKeyX, bytes32 pubKeyY) internal pure returns(bool) {
uint8 v_ethereumFormat;
if (signature.v == 31 || signature.v==32){
//zend signature from compressed pubkey has +4 in the first byte, but ethereum does not expect this
v_ethereumFormat = signature.v - 4;
}else{
v_ethereumFormat = signature.v;
}
address msgSigner = ecrecover(messageHash, v_ethereumFormat, signature.r, signature.s);
if(msgSigner == address(0)) revert InvalidSignature();
//generate an ethereum address from the pubkey
bytes32 hash = keccak256(abi.encodePacked(pubKeyX, pubKeyY));
address ethAddress = address(uint160(uint256(hash)));
return msgSigner == ethAddress;
}
function verifyZendSignature(bytes32 messageHash, Signature memory signature, bytes32 pubKeyX, bytes32 pubKeyY) internal pure {
if(!verifyZendSignatureBool(messageHash, signature, pubKeyX, pubKeyY)) revert SignatureNotMatching();
}
/// @notice Create a message hash compatible with ZEND format from an arbitrary message string.
function createMessageHash(string memory message) internal pure returns(bytes32) {
bytes memory messageToSignBytes = bytes(message);
bytes memory mmb2 = abi.encodePacked(uint8(MESSAGE_MAGIC_BYTES.length), MESSAGE_MAGIC_BYTES);
bytes memory mts2 = abi.encodePacked(uint8(messageToSignBytes.length), messageToSignBytes);
// array concatenation
bytes memory combinedMessage = abi.encodePacked(mmb2, mts2);
// Double SHA-256 hashing
return sha256(abi.encodePacked(sha256(combinedMessage)));
}
function pubKeyUncompressedToZenAddress(bytes32 pubKeyX, bytes32 pubKeyY) internal pure returns (bytes20) {
return ripemd160(abi.encodePacked(sha256(abi.encodePacked(hex"04", pubKeyX, pubKeyY))));
}
function pubKeyCompressedToZenAddress(bytes32 xPubKeyBE, uint8 sign) internal pure returns (bytes20) {
return ripemd160(abi.encodePacked(sha256(abi.encodePacked(sign, xPubKeyBE))));
}
function signByte(bytes32 yPubKeyBE) internal pure returns (uint8) {
uint256 yPub = uint256(yPubKeyBE);
if (yPub % 2 == 0) {
return 0x02;
} else {
return 0x03;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {VerificationLibrary} from './VerificationLibrary.sol';
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./VerificationLibrary.sol";
import "./interfaces/IZenToken.sol";
/// @title ZendBackupVault
/// @notice This contract is used to store balances from old ZEND Mainchain, and, once all are loaded, it allows manual claiming in the new chain.
/// In the constructor will receive an admin address (owner), the only entity authorized to perform load operations. Before loading all the accounts,
// the cumulative hash calculated with all the accounts dump data must be set.
contract ZendBackupVault is Ownable {
uint256 constant HORIZEN_UNCOMPRESSED_PUBLIC_KEY_LENGTH = 65;
uint256 constant HORIZEN_COMPRESSED_PUBLIC_KEY_LENGTH = 33;
struct AddressValue {
bytes20 addr;
uint256 value;
}
struct PubKey {
bytes32 x;
bytes32 y;
}
// Map of the claimable balances.
// The key is the zendAddress in bs58 decoded format
mapping(bytes20 => uint256) public balances;
// Cumulative Hash calculated
bytes32 public _cumulativeHash;
// Final expected Cumulative Hash, used for checkpoint, to unlock claim
bytes32 public cumulativeHashCheckpoint;
IZenToken public zenToken;
string private MESSAGE_CONSTANT;
/// First part of the message to sign, needed for zen claim operation. It is composed by the token symbol + MESSAGE_CONSTANT
string public message_prefix;
error AddressNotValid();
error CumulativeHashNotValid();
error CumulativeHashCheckpointReached();
error CumulativeHashCheckpointNotSet();
error UnauthorizedOperation();
error ERC20NotSet();
error NothingToClaim(bytes20 zenAddress);
error InsufficientSignatures(uint256 number, uint256 required);
error InvalidSignatureArrayLength();
error InvalidPublicKeysArraysLength();
error TooManySignatures();
error InvalidScriptLength();
error InvalidPublicKeySize(uint256 size);
error UnexpectedZeroPublicKey(PubKey);
error InvalidPublicKey(uint256 index, uint256 xOrY, bytes32 expected, bytes32 received);
error InvalidDirectMultisigScript(uint256 requiredSignaturesInScript, uint256 totalSignaturesInScript);
event Claimed(address indexed claimer, address indexed destAddress, bytes20 zenAddress, uint256 amount);
/// @notice verify if we are in the state in which users can already claim
modifier canClaim(address destAddress) {
if (_cumulativeHash != cumulativeHashCheckpoint) revert CumulativeHashNotValid(); //Loaded data not matching - distribution locked
if (address(zenToken) == address(0)) revert ERC20NotSet();
if (address(destAddress) == address(0)) revert AddressNotValid();
if (cumulativeHashCheckpoint == bytes32(0)) revert CumulativeHashCheckpointNotSet();
_;
}
/// @notice Smart contract constructor
/// @param _admin the only entity authorized to perform restore operations
/// @param base_message one of the parts of the message to sign for zen claim
constructor(address _admin, string memory base_message) Ownable(_admin) {
MESSAGE_CONSTANT = base_message;
}
/// @notice Set expected cumulative hash after all the data has been loaded
/// @param _cumulativeHashCheckpoint a cumulative recursive hash calculated with all the dump data.
/// Will be used to verify the consistency of the restored data, and as
/// a checkpoint to understand when all the data has been loaded and the claim
/// can start
function setCumulativeHashCheckpoint(bytes32 _cumulativeHashCheckpoint) public onlyOwner{
if(_cumulativeHashCheckpoint == bytes32(0)) revert CumulativeHashNotValid();
if (cumulativeHashCheckpoint != bytes32(0)) revert UnauthorizedOperation(); //already set
cumulativeHashCheckpoint = _cumulativeHashCheckpoint;
}
/// @notice Insert a new batch of account tuples (bytes20, value) and updates the cumulative hash. The total balance of all accounts is minted and assigned to Zend Vault contract.
/// The zend addresses are in bs58 decoded format, without prefix and checksum.
/// To guarantee the same algorithm is applied, the expected cumulativeHash after the batch processing must be provided explicitly
/// @param expectedCumulativeHash the cumulative recursive hash calculated with all the data already inserted plus the current batch.
/// @param addressValues new accounts batch to insert
function batchInsert(bytes32 expectedCumulativeHash, AddressValue[] calldata addressValues) public onlyOwner {
if (cumulativeHashCheckpoint == bytes32(0)) revert CumulativeHashCheckpointNotSet();
if (address(zenToken) == address(0)) revert ERC20NotSet();
if (_cumulativeHash == cumulativeHashCheckpoint) revert CumulativeHashCheckpointReached();
uint256 i;
bytes32 auxHash = _cumulativeHash;
uint256 cumulativeBalance;
while (i != addressValues.length) {
balances[addressValues[i].addr] = addressValues[i].value;
auxHash = keccak256(abi.encode(auxHash, addressValues[i].addr, addressValues[i].value));
unchecked {cumulativeBalance = cumulativeBalance + addressValues[i].value; }
unchecked { ++i; }
}
_cumulativeHash = auxHash;
if (expectedCumulativeHash != _cumulativeHash) revert CumulativeHashNotValid();
zenToken.mint(address(this), cumulativeBalance);
if (cumulativeHashCheckpoint == _cumulativeHash){
zenToken.notifyMintingDone();
}
}
/// @notice Set official ZEN ERC-20 smart contract that will be used for minting
function setERC20(address addr) public onlyOwner {
if (address(zenToken) != address(0)) revert UnauthorizedOperation(); //ERC-20 address already set
if(addr == address(0)) revert AddressNotValid();
zenToken = IZenToken(addr);
message_prefix = string(abi.encodePacked(zenToken.symbol(), MESSAGE_CONSTANT));
}
/// @notice Internal claim function, to reuse the code between P2PKH and P2PSH
function _claim(address destAddress, bytes20 zenAddress) internal {
uint256 amount = balances[zenAddress];
balances[zenAddress] = 0;
zenToken.transfer(destAddress, amount);
emit Claimed(msg.sender, destAddress, zenAddress, amount);
}
/// @notice Claim a P2PKH balance.
/// @param destAddress is the receiver of the funds
/// @param hexSignature is the signature of the claiming message. Must be generated in a compressed format to claim a zend address
/// generated with the public key in compressed format, or uncompressed otherwise.
/// (Claiming message is predefined and composed by the concatenation of the message_prefix (token symbol + MESSAGE_CONSTANT) and the destination address in EIP-55 format (https://github.com/ethereum/ercs/blob/master/ERCS/erc-55.md) string)
/// @param pubKey are the first 32 bytes and second 32 bytes of the signing key (we use always the uncompressed format here)
/// Note: we pass the pubkey explicitly because the extraction from the signature would be GAS expensive.
function claimP2PKH(address destAddress, bytes memory hexSignature, PubKey calldata pubKey) public canClaim(destAddress) {
VerificationLibrary.Signature memory signature = VerificationLibrary.parseZendSignature(hexSignature);
bytes20 zenAddress;
if (signature.v == 31 || signature.v == 32){
//signature was compressed, also the zen address will be from the compressed format
zenAddress = VerificationLibrary.pubKeyCompressedToZenAddress(pubKey.x, VerificationLibrary.signByte(pubKey.y));
} else {
zenAddress = VerificationLibrary.pubKeyUncompressedToZenAddress(pubKey.x, pubKey.y);
}
//check amount to claim
uint256 amount = balances[zenAddress];
if (amount == 0) revert NothingToClaim(zenAddress);
//address in signed message should respect EIP-55 format (https://github.com/ethereum/ercs/blob/master/ERCS/erc-55.md)
string memory asString = Strings.toChecksumHexString(destAddress);
string memory strMessageToSign = string(abi.encodePacked(message_prefix, asString));
bytes32 messageHash = VerificationLibrary.createMessageHash(strMessageToSign);
VerificationLibrary.verifyZendSignature(messageHash, signature, pubKey.x, pubKey.y);
_claim(destAddress, zenAddress);
}
/// @notice Direct claim of special UTXOs generated deterministically from a BaseAddress.
/// This is a special usecase for users that can't sign a message, and requires they create this special UTXO in the old mainchain before the migration.
/// Check documentation for details.
/// @param baseDestAddress is the receiver of the funds. The zend address will be calculated from this one.
function claimDirect(address baseDestAddress) public canClaim(baseDestAddress) {
bytes memory addressToBytes = abi.encodePacked(baseDestAddress);
bytes20 zenAddress = _extractZenAddressFromScriptOrDestAddress(addressToBytes);
//check amount to claim
uint256 amount = balances[zenAddress];
if (amount == 0) revert NothingToClaim(zenAddress);
_claim(baseDestAddress, zenAddress);
}
/// @notice Claim a P2SH balance.
/// destAddress is the receiver of the funds
/// hexSignatures is the array of the signatures of the claiming message. If a signature is not present, signature MUST be 0
/// IMPORTANT: the array should have as length the number of public keys in the script. The signature in the "i" position should be the signature for the "i"
/// pub key in the order it appears in the script. If the signature is not present for that key, it should be empty.
/// This is to avoid duplicated signatures without expensive checks.
///
/// script is the script to claim, from which pubKeys will be extracted
/// pubKeysX and pubKeysY are the first 32 bytes and second 32 bytes of the signing keys for each one in the script (we use always the uncompressed format here)
/// If a public key is not needed (because signature is zero) its value can be zero; even if not needed, if it is present, it should be the same used for the script
/// (Claiming message is predefined and composed by the string in the message_prefix variable concatenated with the zenAddress and destAddress in lowercase string hex format)
/// (zenAddress is the string representation with 0x prefix )
function claimP2SH(address destAddress, bytes[] calldata hexSignatures, bytes memory script, PubKey[] calldata pubKeys) public canClaim(destAddress) {
if(hexSignatures.length != pubKeys.length) revert InvalidSignatureArrayLength(); //check method doc
if(hexSignatures.length > 16) revert TooManySignatures(); //ZEND multisig scripts support up to 16 signatures
bytes20 zenAddress = _extractZenAddressFromScriptOrDestAddress(script);
//check amount to claim
if (balances[zenAddress] == 0) revert NothingToClaim(zenAddress);
uint256 minSignatures = uint256(uint8(script[0])) - 80;
_verifyPubKeysFromScript(script, pubKeys);
//address in signed message should respect EIP-55 format (https://github.com/ethereum/ercs/blob/master/ERCS/erc-55.md)
string memory destAddressAsString = Strings.toChecksumHexString(destAddress);
string memory zenAddressAsString = Strings.toHexString(address(zenAddress));
string memory strMessageToSign = string(abi.encodePacked(message_prefix, zenAddressAsString, destAddressAsString));
bytes32 messageHash = VerificationLibrary.createMessageHash(strMessageToSign);
//check signatures
uint256 validSignatures;
uint256 i;
while(i != hexSignatures.length && validSignatures < minSignatures) {
if(hexSignatures[i].length != 0) { // skip otherwise
if(pubKeys[i].x == bytes32(0) || pubKeys[i].y == bytes32(0)) revert UnexpectedZeroPublicKey(pubKeys[i]);
else {
VerificationLibrary.Signature memory signature = VerificationLibrary.parseZendSignature(hexSignatures[i]);
//check doc: we suppose the signature in i position belonging to the pub key in i position in the script
if(VerificationLibrary.verifyZendSignatureBool(messageHash, signature, pubKeys[i].x, pubKeys[i].y)) {
unchecked { ++validSignatures; }
}
}
}
unchecked { ++i; }
}
if(validSignatures < minSignatures) revert InsufficientSignatures(validSignatures, minSignatures); //insufficient signatures
_claim(destAddress, zenAddress);
}
/// @notice Direct claim of special UTXOs to a multisignature partially generated deterministically from a BaseAddress.
/// This is a special usecase for users that can't sign a message, and requires they create this special UTXO in the old mainchain before the migration.
/// Check documentation for details.
/// @param script is the redeem script for the multisig wallet.
/// @param baseDestAddress is the receiver of the funds. The zend address will be calculated from this one.
function claimDirectMultisig(bytes memory script, address baseDestAddress) public canClaim(baseDestAddress) {
//check amount to claim
bytes20 zenAddress = _extractZenAddressFromScriptOrDestAddress(script);
uint256 amount = balances[zenAddress];
if (amount == 0) revert NothingToClaim(zenAddress);
//generate derivative pub key from base address
bytes memory baseAddressToBytes = abi.encodePacked(baseDestAddress);
bytes32 pubKeyXFromBaseAddress = sha256(baseAddressToBytes);
//check is multisig 1 of 2
uint256 minSignatures = uint256(uint8(script[0])) - 80;
uint256 total = uint256(uint8(script[script.length - 2])) - 80;
if(minSignatures != 1 || total != 2) revert InvalidDirectMultisigScript(minSignatures, total);
//extract second key "x" from script
uint256 firstPubKeySize = uint256(uint8(script[1]));
uint256 start = firstPubKeySize + 4; //skip first OP (+1), skip size of first key (+1), first key (firstPubKeySize), size of second key (+1) and prefix of second key (+1)
bytes32 key = _extractBytes32FromBytes(script, start);
if(pubKeyXFromBaseAddress != key) revert InvalidPublicKey(1, 0, key, pubKeyXFromBaseAddress);
_claim(baseDestAddress, zenAddress);
}
/// @notice verify public keys from multisignature script
function _verifyPubKeysFromScript(bytes memory script, PubKey[] calldata pubKeys) internal pure {
if(script.length < 2) revert InvalidScriptLength();
uint256 total = uint256(uint8(script[script.length - 2])) - 80;
if(pubKeys.length != total) revert InvalidPublicKeysArraysLength();
uint256 pos = 1;
uint256 i;
while(i < total) {
uint256 nextPubKeySize = uint256(uint8(script[pos]));
unchecked { ++pos; }
if(nextPubKeySize != HORIZEN_COMPRESSED_PUBLIC_KEY_LENGTH && nextPubKeySize != HORIZEN_UNCOMPRESSED_PUBLIC_KEY_LENGTH) revert InvalidPublicKeySize(nextPubKeySize);
if(pubKeys[i].x != 0 && pubKeys[i].y != 0) { //we check pub keys only if both x and y are != 0
//extract key
//first 32 bytes
uint256 firstPartStart = pos+1;
bytes32 firstPart = _extractBytes32FromBytes(script, firstPartStart);
if(pubKeys[i].x != firstPart) revert InvalidPublicKey(i, 0, firstPart, pubKeys[i].x);
//second part
if(nextPubKeySize == HORIZEN_UNCOMPRESSED_PUBLIC_KEY_LENGTH) { //uncompressed case
uint256 secondPartStart = pos + 33;
bytes32 secondPart = _extractBytes32FromBytes(script, secondPartStart);
if(pubKeys[i].y != secondPart) revert InvalidPublicKey(i, 1, secondPart, pubKeys[i].y);
}
else { //in compressed case, we just check sign
uint8 sign;
assembly {
let offset := add(add(script, 0x20), pos) // data start + pos
sign := byte(0, mload(offset)) // take the LS byte
}
uint8 ySign = VerificationLibrary.signByte(pubKeys[i].y);
if(sign != ySign) revert InvalidPublicKey(i, 1, bytes32(uint256(sign)), bytes32(uint256(ySign)));
}
}
pos += nextPubKeySize;
unchecked { ++i; }
}
}
/// @notice extract zen address from multisignature script or address (direct claim)
function _extractZenAddressFromScriptOrDestAddress(bytes memory script) internal pure returns(bytes20) {
bytes32 scriptHash = sha256(script);
scriptHash = ripemd160(abi.encode(scriptHash));
return bytes20(scriptHash);
}
/// @notice extract a bytes32 object from a bytes object starting from the given position
function _extractBytes32FromBytes(bytes memory script, uint256 start) internal pure returns(bytes32) {
bytes32 ret;
assembly {
let sourcePtr := add(script, 0x20)
let offset := add(sourcePtr, start)
ret := mload(offset)
}
return ret;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "./interfaces/IVesting.sol";
/// @title ZEN official ERC-20 smart contract
/// @notice Minting role is granted in the constructor to the Vault Contracts, responsible for
/// restoring EON and Zend balances.
contract ZenToken is ERC20Capped {
// Simple mapping to track authorized minters
mapping(address => bool) public minters;
uint256 internal constant TOTAL_ZEN_SUPPLY = 21_000_000;
uint256 internal constant TOKEN_SIZE = 10 ** 18;
address public immutable horizenFoundationVested;
address public immutable horizenDaoVested;
uint8 private numOfMinters;
uint256 public constant DAO_SUPPLY_PERCENTAGE = 60;
uint256 public constant INITIAL_SUPPLY_PERCENTAGE = 25;
error AddressParameterCantBeZero(string paramName);
error CallerNotMinter(address caller);
modifier canMint() {
// Checks that the calling account has the minter role
if (!minters[msg.sender]) {
revert CallerNotMinter(msg.sender);
}
_;
}
/// @notice Smart contract constructor
/// @param tokenName Name of the token
/// @param tokenSymbol Ticker of the token
/// @param _eonBackupContract Address of EON Vault contract
/// @param _zendBackupContract Address of ZEND Vault contract
/// @param _horizenFoundationVested Address who will receive the remaining portion of Zen reserved to the Foundation (with locking period)
/// @param _horizenDaoVested Address who will receive the remaining portion of Zen reserved to the DAO (with locking period)
constructor(
string memory tokenName,
string memory tokenSymbol,
address _eonBackupContract,
address _zendBackupContract,
address _horizenFoundationVested,
address _horizenDaoVested
) ERC20(tokenName, tokenSymbol) ERC20Capped(TOTAL_ZEN_SUPPLY * TOKEN_SIZE) {
if (_eonBackupContract == address(0))
revert AddressParameterCantBeZero("_eonBackupContract");
if (_zendBackupContract == address(0))
revert AddressParameterCantBeZero("_zendBackupContract");
if (_horizenFoundationVested == address(0))
revert AddressParameterCantBeZero("_horizenFoundationVested");
if (_horizenDaoVested == address(0))
revert AddressParameterCantBeZero("_horizenDaoVested");
// Grant the minter role to a specified account
minters[_eonBackupContract] = true;
minters[_zendBackupContract] = true;
numOfMinters = 2;
horizenFoundationVested = _horizenFoundationVested;
horizenDaoVested = _horizenDaoVested;
}
function mint(address to, uint256 amount) public canMint {
_mint(to, amount);
}
function notifyMintingDone() public canMint {
minters[msg.sender] = false;
unchecked {
--numOfMinters;
}
if (numOfMinters == 0) {
uint256 remainingSupply = cap() - totalSupply();
//Horizen DAO is eligible of 60% of the remaining supply. The rest is for the Foundation.
uint256 daoSupply = (remainingSupply * DAO_SUPPLY_PERCENTAGE) / 100;
uint256 foundationSupply = remainingSupply - daoSupply;
uint256 daoInitialSupply = (daoSupply * INITIAL_SUPPLY_PERCENTAGE) / 100;
uint256 foundationInitialSupply = (foundationSupply * INITIAL_SUPPLY_PERCENTAGE) / 100;
_mint(
IVesting(horizenFoundationVested).beneficiary(),
foundationInitialSupply
);
_mint(
horizenFoundationVested,
foundationSupply - foundationInitialSupply
);
_mint(
IVesting(horizenDaoVested).beneficiary(),
daoInitialSupply
);
_mint(horizenDaoVested, daoSupply - daoInitialSupply);
IVesting(horizenFoundationVested).startVesting();
IVesting(horizenDaoVested).startVesting();
}
}
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"evmVersion": "shanghai",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract ABI
API[{"inputs":[{"internalType":"address","name":"_admin","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ContractsAlreadyDeployed","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"eonVault","type":"address"},{"indexed":false,"internalType":"address","name":"zendVault","type":"address"},{"indexed":false,"internalType":"address","name":"horizenFoundationVestingContract","type":"address"},{"indexed":false,"internalType":"address","name":"horizenDaoVestingContract","type":"address"}],"name":"ZenMigrationContractsCreated","type":"event"},{"inputs":[{"internalType":"string","name":"tokenName","type":"string"},{"internalType":"string","name":"tokenSymbol","type":"string"},{"internalType":"string","name":"base_claim_message","type":"string"},{"internalType":"address","name":"horizenFoundationAdmin","type":"address"},{"internalType":"address","name":"horizenFoundationBeneficiary","type":"address"},{"internalType":"address","name":"horizenDaoAdmin","type":"address"},{"internalType":"address","name":"horizenDaoBeneficiary","type":"address"}],"name":"deployMigrationContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"eonVault","outputs":[{"internalType":"contract EONBackupVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"horizenDaoVestingContract","outputs":[{"internalType":"contract LinearTokenVesting","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"horizenFoundationVestingContract","outputs":[{"internalType":"contract LinearTokenVesting","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"contract ZenToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"zendVault","outputs":[{"internalType":"contract ZendBackupVault","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
6080604052348015600e575f5ffd5b50604051615b74380380615b74833981016040819052602b9160b4565b806001600160a01b038116605857604051631e4fbdf760e01b81525f600482015260240160405180910390fd5b605f816065565b505060df565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f6020828403121560c3575f5ffd5b81516001600160a01b038116811460d8575f5ffd5b9392505050565b615a88806100ec5f395ff3fe608060405234801561000f575f5ffd5b5060043610610090575f3560e01c8063ca21070511610063578063ca210705146100f0578063e45c86c714610103578063e7a57f3b14610116578063f2fde38b14610129578063fc0c546a1461013c575f5ffd5b80632f082dfe14610094578063715018a6146100c35780638da5cb5b146100cd578063b6d3ee19146100dd575b5f5ffd5b6003546100a7906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b6100cb61014f565b005b5f546001600160a01b03166100a7565b6002546100a7906001600160a01b031681565b6100cb6100fe3660046108bc565b610162565b6005546100a7906001600160a01b031681565b6004546100a7906001600160a01b031681565b6100cb61013736600461098b565b610711565b6001546100a7906001600160a01b031681565b610157610753565b6101605f61077f565b565b61016a610753565b6001546001600160a01b0316156101945760405163ad5b93e360e01b815260040160405180910390fd5b306040516101a1906107ce565b6001600160a01b039091168152602001604051809103905ff0801580156101ca573d5f5f3e3d5ffd5b5060025f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555030856040516101fe906107db565b6102099291906109ee565b604051809103905ff080158015610222573d5f5f3e3d5ffd5b5060035f6101000a8154816001600160a01b0302191690836001600160a01b031602179055508262278d00603060405161025b906107e8565b6001600160a01b03909316835260208301919091526040820152606001604051809103905ff080158015610291573d5f5f3e3d5ffd5b5060045f6101000a8154816001600160a01b0302191690836001600160a01b031602179055508062278d0060306040516102ca906107e8565b6001600160a01b03909316835260208301919091526040820152606001604051809103905ff080158015610300573d5f5f3e3d5ffd5b50600580546001600160a01b0319166001600160a01b039283169081179091556002546003546004546040518c958c95948116949381169392169190610345906107f5565b61035496959493929190610a19565b604051809103905ff08015801561036d573d5f5f3e3d5ffd5b50600180546001600160a01b0319166001600160a01b0392831690811790915560025460405163614d37ed60e11b815260048101929092529091169063c29a6fda906024015f604051808303815f87803b1580156103c9575f5ffd5b505af11580156103db573d5f5f3e3d5ffd5b505060035460015460405163614d37ed60e11b81526001600160a01b0391821660048201529116925063c29a6fda91506024015f604051808303815f87803b158015610425575f5ffd5b505af1158015610437573d5f5f3e3d5ffd5b50506004805460015460405163614d37ed60e11b81526001600160a01b039182169381019390935216925063c29a6fda91506024015f604051808303815f87803b158015610483575f5ffd5b505af1158015610495573d5f5f3e3d5ffd5b505060055460015460405163614d37ed60e11b81526001600160a01b0391821660048201529116925063c29a6fda91506024015f604051808303815f87803b1580156104df575f5ffd5b505af11580156104f1573d5f5f3e3d5ffd5b50506002546001600160a01b0316915063f2fde38b90506105195f546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201526024015f604051808303815f87803b158015610557575f5ffd5b505af1158015610569573d5f5f3e3d5ffd5b50506003546001600160a01b0316915063f2fde38b90506105915f546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201526024015f604051808303815f87803b1580156105cf575f5ffd5b505af11580156105e1573d5f5f3e3d5ffd5b50506004805460405163f2fde38b60e01b81526001600160a01b03898116938201939093529116925063f2fde38b91506024015f604051808303815f87803b15801561062b575f5ffd5b505af115801561063d573d5f5f3e3d5ffd5b505060055460405163f2fde38b60e01b81526001600160a01b038681166004830152909116925063f2fde38b91506024015f604051808303815f87803b158015610685575f5ffd5b505af1158015610697573d5f5f3e3d5ffd5b5050600154600254600354600454600554604080516001600160a01b039687168152948616602086015292851684840152908416606084015292909216608082015290517f58cf092af1db61442ba2a7a12c04e594db226c99370dff3eea5023f5dcb21fc693509081900360a0019150a150505050505050565b610719610753565b6001600160a01b03811661074757604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b6107508161077f565b50565b5f546001600160a01b031633146101605760405163118cdaa760e01b815233600482015260240161073e565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b610a1580610a7283390190565b6126bd8061148783390190565b610cbb80613b4483390190565b611254806147ff83390190565b634e487b7160e01b5f52604160045260245ffd5b5f82601f830112610825575f5ffd5b813567ffffffffffffffff81111561083f5761083f610802565b604051601f8201601f19908116603f0116810167ffffffffffffffff8111828210171561086e5761086e610802565b604052818152838201602001851015610885575f5ffd5b816020850160208301375f918101602001919091529392505050565b80356001600160a01b03811681146108b7575f5ffd5b919050565b5f5f5f5f5f5f5f60e0888a0312156108d2575f5ffd5b873567ffffffffffffffff8111156108e8575f5ffd5b6108f48a828b01610816565b975050602088013567ffffffffffffffff811115610910575f5ffd5b61091c8a828b01610816565b965050604088013567ffffffffffffffff811115610938575f5ffd5b6109448a828b01610816565b955050610953606089016108a1565b9350610961608089016108a1565b925061096f60a089016108a1565b915061097d60c089016108a1565b905092959891949750929550565b5f6020828403121561099b575f5ffd5b6109a4826108a1565b9392505050565b5f81518084525f5b818110156109cf576020818501810151868301820152016109b3565b505f602082860101526020601f19601f83011685010191505092915050565b6001600160a01b03831681526040602082018190525f90610a11908301846109ab565b949350505050565b60c081525f610a2b60c08301896109ab565b8281036020840152610a3d81896109ab565b6001600160a01b03978816604085015295871660608401525050918416608083015290921660a0909201919091529291505056fe6080604052348015600e575f5ffd5b50604051610a15380380610a15833981016040819052602b9160b4565b806001600160a01b038116605857604051631e4fbdf760e01b81525f600482015260240160405180910390fd5b605f816065565b505060df565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f6020828403121560c3575f5ffd5b81516001600160a01b038116811460d8575f5ffd5b9392505050565b610929806100ec5f395ff3fe608060405234801561000f575f5ffd5b50600436106100b1575f3560e01c806391c05b0b1161006e57806391c05b0b14610144578063a617ba6014610157578063c29a6fda1461016a578063d6db84e91461017d578063d89ae26c14610186578063f2fde38b1461019e575f5ffd5b806301af9843146100b55780631a843afb146100ca57806327e235e3146100dd5780634285fcbd1461010f578063715018a6146101185780638da5cb5b14610120575b5f5ffd5b6100c86100c336600461073b565b6101b1565b005b6100c86100d83660046107db565b6101fd565b6100fc6100eb3660046108bf565b60016020525f908152604090205481565b6040519081526020015b60405180910390f35b6100fc60045481565b6100c86103c0565b5f546001600160a01b03165b6040516001600160a01b039091168152602001610106565b6100c861015236600461073b565b6103d3565b60065461012c906001600160a01b031681565b6100c86101783660046108bf565b6105c3565b6100fc60035481565b61018e61063e565b6040519015158152602001610106565b6100c86101ac3660046108bf565b61067e565b6101b96106c0565b806101d757604051636f6ed5ab60e01b815260040160405180910390fd5b600454156101f857604051635ee8231160e01b815260040160405180910390fd5b600455565b6102056106c0565b6004546102255760405163350212c960e11b815260040160405180910390fd5b60045460035403610249576040516302f715b160e51b815260040160405180910390fd5b6003545f905b8251821461039557828281518110610269576102696108df565b60200260200101516020015160015f85858151811061028a5761028a6108df565b60200260200101515f01516001600160a01b03166001600160a01b031681526020019081526020015f208190555060028383815181106102cc576102cc6108df565b6020908102919091018101515182546001810184555f938452919092200180546001600160a01b0319166001600160a01b039092169190911790558251819084908490811061031d5761031d6108df565b60200260200101515f015184848151811061033a5761033a6108df565b602002602001015160200151604051602001610372939291909283526001600160a01b03919091166020830152604082015260600190565b60405160208183030381529060405280519060200120905081600101915061024f565b60038190558381146103ba57604051636f6ed5ab60e01b815260040160405180910390fd5b50505050565b6103c86106c0565b6103d15f6106ec565b565b6103db6106c0565b6004546103fb5760405163350212c960e11b815260040160405180910390fd5b6006546001600160a01b031661042457604051637bbede1f60e11b815260040160405180910390fd5b6004546003541461044857604051636f6ed5ab60e01b815260040160405180910390fd5b6002546005540361046b5760405162598fc960e21b815260040160405180910390fd5b6005545f905b60025481148015906104835750828214155b1561054d575f6002828154811061049c5761049c6108df565b5f9182526020808320909101546001600160a01b03168083526001909152604090912054909150801561053f576001600160a01b038281165f818152600160205260408082209190915560065490516340c10f1960e01b8152600481019290925260248201849052909116906340c10f19906044015f604051808303815f87803b158015610528575f5ffd5b505af115801561053a573d5f5f3e3d5ffd5b505050505b505060019182019101610471565b600581905560025481036105be5760065f9054906101000a90046001600160a01b03166001600160a01b0316637986eb0b6040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156105a7575f5ffd5b505af11580156105b9573d5f5f3e3d5ffd5b505050505b505050565b6105cb6106c0565b6006546001600160a01b0316156105f557604051635ee8231160e01b815260040160405180910390fd5b6001600160a01b03811661061c5760405163d23f952160e01b815260040160405180910390fd5b600680546001600160a01b0319166001600160a01b0392909216919091179055565b6006545f906001600160a01b03161580159061065b575060035415155b801561066a5750600454600354145b80156106795750600254600554105b905090565b6106866106c0565b6001600160a01b0381166106b457604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b6106bd816106ec565b50565b5f546001600160a01b031633146103d15760405163118cdaa760e01b81523360048201526024016106ab565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f6020828403121561074b575f5ffd5b5035919050565b634e487b7160e01b5f52604160045260245ffd5b6040805190810167ffffffffffffffff8111828210171561078957610789610752565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156107b8576107b8610752565b604052919050565b80356001600160a01b03811681146107d6575f5ffd5b919050565b5f5f604083850312156107ec575f5ffd5b82359150602083013567ffffffffffffffff811115610809575f5ffd5b8301601f81018513610819575f5ffd5b803567ffffffffffffffff81111561083357610833610752565b61084260208260051b0161078f565b8082825260208201915060208360061b850101925087831115610863575f5ffd5b6020840193505b828410156108b15760408489031215610881575f5ffd5b610889610766565b610892856107c0565b815260208581013581830152908352604090940193919091019061086a565b809450505050509250929050565b5f602082840312156108cf575f5ffd5b6108d8826107c0565b9392505050565b634e487b7160e01b5f52603260045260245ffdfea26469706673582212202189f268735afa99da28236675acf93f9a8d04c4d1822b6e3d348bc02be0709264736f6c634300081b0033608060405234801561000f575f5ffd5b506040516126bd3803806126bd83398101604081905261002e916100dd565b816001600160a01b03811661005c57604051631e4fbdf760e01b81525f600482015260240160405180910390fd5b6100658161007a565b5060056100728282610245565b5050506102ff565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b634e487b7160e01b5f52604160045260245ffd5b5f5f604083850312156100ee575f5ffd5b82516001600160a01b0381168114610104575f5ffd5b60208401519092506001600160401b0381111561011f575f5ffd5b8301601f8101851361012f575f5ffd5b80516001600160401b03811115610148576101486100c9565b604051601f8201601f19908116603f011681016001600160401b0381118282101715610176576101766100c9565b60405281815282820160200187101561018d575f5ffd5b5f5b828110156101ab5760208185018101518383018201520161018f565b505f602083830101528093505050509250929050565b600181811c908216806101d557607f821691505b6020821081036101f357634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111561024057805f5260205f20601f840160051c8101602085101561021e5750805b601f840160051c820191505b8181101561023d575f815560010161022a565b50505b505050565b81516001600160401b0381111561025e5761025e6100c9565b6102728161026c84546101c1565b846101f9565b6020601f8211600181146102a4575f831561028d5750848201515b5f19600385901b1c1916600184901b17845561023d565b5f84815260208120601f198516915b828110156102d357878501518255602094850194600190920191016102b3565b50848210156102f057868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b6123b18061030c5f395ff3fe608060405234801561000f575f5ffd5b50600436106100f0575f3560e01c80638da5cb5b11610093578063c29a6fda11610063578063c29a6fda146101d8578063d6db84e9146101eb578063f2113dc9146101f4578063f2fde38b14610213575f5ffd5b80638da5cb5b1461017b578063a617ba601461019f578063aca8f752146101b2578063b2b505b4146101c5575f5ffd5b80635123106b116100ce5780635123106b14610138578063550d13551461014b578063715018a61461016057806381aef57d14610168575f5ffd5b806301af9843146100f4578063178617b9146101095780634285fcbd1461011c575b5f5ffd5b610107610102366004611bb9565b610226565b005b610107610117366004611c17565b610272565b61012560035481565b6040519081526020015b60405180910390f35b610107610146366004611d35565b6104fb565b610153610872565b60405161012f9190611e2f565b6101076108fe565b610107610176366004611e61565b610911565b5f546001600160a01b03165b6040516001600160a01b03909116815260200161012f565b600454610187906001600160a01b031681565b6101076101c0366004611ec5565b610aa4565b6101076101d3366004611ee5565b610bc6565b6101076101e6366004611ec5565b610e4f565b61012560025481565b610125610202366004611f2f565b60016020525f908152604090205481565b610107610221366004611ec5565b610f56565b61022e610f93565b8061024c57604051636f6ed5ab60e01b815260040160405180910390fd5b6003541561026d57604051635ee8231160e01b815260040160405180910390fd5b600355565b61027a610f93565b60035461029a5760405163350212c960e11b815260040160405180910390fd5b6004546001600160a01b03166102c357604051637bbede1f60e11b815260040160405180910390fd5b600354600254036102e7576040516302f715b160e51b815260040160405180910390fd5b6002545f90815b82841461040b5784848481811061030757610307611f56565b9050604002016020013560015f87878781811061032657610326611f56565b61033c9260206040909202019081019150611f2f565b6001600160601b031916815260208101919091526040015f20558185858581811061036957610369611f56565b61037f9260206040909202019081019150611f2f565b86868681811061039157610391611f56565b905060400201602001356040516020016103c8939291909283526001600160601b0319919091166020830152604082015260600190565b6040516020818303038152906040528051906020012091508484848181106103f2576103f2611f56565b90506040020160200135810190508260010192506102ee565b600282905585821461043057604051636f6ed5ab60e01b815260040160405180910390fd5b600480546040516340c10f1960e01b81523092810192909252602482018390526001600160a01b0316906340c10f19906044015f604051808303815f87803b15801561047a575f5ffd5b505af115801561048c573d5f5f3e3d5ffd5b50505050600254600354036104f3576004805460408051637986eb0b60e01b815290516001600160a01b0390921692637986eb0b92828201925f929082900301818387803b1580156104dc575f5ffd5b505af11580156104ee573d5f5f3e3d5ffd5b505050505b505050505050565b856003546002541461052057604051636f6ed5ab60e01b815260040160405180910390fd5b6004546001600160a01b031661054957604051637bbede1f60e11b815260040160405180910390fd5b6001600160a01b0381166105705760405163d23f952160e01b815260040160405180910390fd5b6003546105905760405163350212c960e11b815260040160405180910390fd5b8482146105b057604051636758971b60e11b815260040160405180910390fd5b60108511156105d2576040516387e497e560e01b815260040160405180910390fd5b5f6105dc85610fbf565b6001600160601b031981165f9081526001602052604081205491925003610627576040516303d2b3ef60e21b81526001600160601b0319821660048201526024015b60405180910390fd5b5f6050865f8151811061063c5761063c611f56565b016020015161064e919060f81c611f7e565b905061065b868686611076565b5f6106658a61135a565b90505f6106748460601c611408565b90505f6006828460405160200161068d93929190612031565b60405160208183030381529060405290505f6106a882611424565b90505f5f5b808d148015906106bc57508682105b1561082c578d8d828181106106d3576106d3611f56565b90506020028101906106e59190612069565b159050610824575f8b8b838181106106ff576106ff611f56565b9050604002015f0135148061072e57505f8b8b8381811061072257610722611f56565b90506040020160200135145b15610772578a8a8281811061074557610745611f56565b604080516304d5bf6160e41b8152910292909201803560048401526020013560248301525060440161061e565b5f6107d38f8f8481811061078857610788611f56565b905060200281019061079a9190612069565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920191909152506115b992505050565b905061081684828e8e868181106107ec576107ec611f56565b9050604002015f01358f8f8781811061080757610807611f56565b90506040020160200135611690565b15610822578260010192505b505b6001016106ad565b86821015610857576040516378f4355360e11b8152600481018390526024810188905260440161061e565b6108618f896117a9565b505050505050505050505050505050565b6006805461087f90611f91565b80601f01602080910402602001604051908101604052809291908181526020018280546108ab90611f91565b80156108f65780601f106108cd576101008083540402835291602001916108f6565b820191905f5260205f20905b8154815290600101906020018083116108d957829003601f168201915b505050505081565b610906610f93565b61090f5f611892565b565b826003546002541461093657604051636f6ed5ab60e01b815260040160405180910390fd5b6004546001600160a01b031661095f57604051637bbede1f60e11b815260040160405180910390fd5b6001600160a01b0381166109865760405163d23f952160e01b815260040160405180910390fd5b6003546109a65760405163350212c960e11b815260040160405180910390fd5b5f6109b0846115b9565b90505f816040015160ff16601f14806109d05750816040015160ff166020145b156109f3576109ec84356109e760208701356118e1565b61190c565b9050610a05565b610a02843560208601356119e6565b90505b6001600160601b031981165f9081526001602052604081205490819003610a4b576040516303d2b3ef60e21b81526001600160601b03198316600482015260240161061e565b5f610a558861135a565b90505f600682604051602001610a6c9291906120ab565b60405160208183030381529060405290505f610a8782611424565b9050610a9a81878a3560208c0135611a11565b6104ee8a866117a9565b8060035460025414610ac957604051636f6ed5ab60e01b815260040160405180910390fd5b6004546001600160a01b0316610af257604051637bbede1f60e11b815260040160405180910390fd5b6001600160a01b038116610b195760405163d23f952160e01b815260040160405180910390fd5b600354610b395760405163350212c960e11b815260040160405180910390fd5b60408051606084901b6001600160601b03191660208201528151601481830301815260349091019091525f610b6d82610fbf565b6001600160601b031981165f90815260016020526040812054919250819003610bb5576040516303d2b3ef60e21b81526001600160601b03198316600482015260240161061e565b610bbf85836117a9565b5050505050565b8060035460025414610beb57604051636f6ed5ab60e01b815260040160405180910390fd5b6004546001600160a01b0316610c1457604051637bbede1f60e11b815260040160405180910390fd5b6001600160a01b038116610c3b5760405163d23f952160e01b815260040160405180910390fd5b600354610c5b5760405163350212c960e11b815260040160405180910390fd5b5f610c6584610fbf565b6001600160601b031981165f90815260016020526040812054919250819003610cad576040516303d2b3ef60e21b81526001600160601b03198316600482015260240161061e565b6040516001600160601b0319606086901b1660208201525f9060340160405160208183030381529060405290505f600282604051610ceb91906120cf565b602060405180830381855afa158015610d06573d5f5f3e3d5ffd5b5050506040513d601f19601f82011682018060405250810190610d2991906120ea565b90505f6050885f81518110610d4057610d40611f56565b0160200151610d52919060f81c611f7e565b90505f60508960028b51610d669190611f7e565b81518110610d7657610d76611f56565b0160200151610d88919060f81c611f7e565b9050816001141580610d9b575080600214155b15610dc357604051633c70407360e11b8152600481018390526024810182905260440161061e565b5f89600181518110610dd757610dd7611f56565b016020015160f81c90505f610ded826004612101565b90505f610dfe8c8360209101015190565b9050808614610e375760405163049c2f1960e01b8152600160048201525f6024820152604481018290526064810187905260840161061e565b610e418b8a6117a9565b505050505050505050505050565b610e57610f93565b6004546001600160a01b031615610e8157604051635ee8231160e01b815260040160405180910390fd5b6001600160a01b038116610ea85760405163d23f952160e01b815260040160405180910390fd5b600480546001600160a01b0319166001600160a01b0383169081178255604080516395d89b4160e01b8152905191926395d89b4192828201925f92908290030181865afa158015610efb573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610f229190810190612114565b6005604051602001610f35929190612185565b60405160208183030381529060405260069081610f5291906121eb565b5050565b610f5e610f93565b6001600160a01b038116610f8757604051631e4fbdf760e01b81525f600482015260240161061e565b610f9081611892565b50565b5f546001600160a01b0316331461090f5760405163118cdaa760e01b815233600482015260240161061e565b5f5f600283604051610fd191906120cf565b602060405180830381855afa158015610fec573d5f5f3e3d5ffd5b5050506040513d601f19601f8201168201806040525081019061100f91906120ea565b905060038160405160200161102691815260200190565b60408051601f1981840301815290829052611040916120cf565b602060405180830381855afa15801561105b573d5f5f3e3d5ffd5b50506040515160601b6001600160601b031916949350505050565b60028351101561109957604051631302f01760e21b815260040160405180910390fd5b5f605084600286516110ab9190611f7e565b815181106110bb576110bb611f56565b01602001516110cd919060f81c611f7e565b90508181146110ef57604051637ea25c0360e01b815260040160405180910390fd5b60015f5b828110156104f3575f86838151811061110e5761110e611f56565b016020015160019093019260f81c905060218114801590611130575060418114155b15611151576040516351c5a9a560e11b81526004810182905260240161061e565b85858381811061116357611163611f56565b60400291909101351580159150611197575085858381811061118757611187611f56565b905060400201602001355f5f1b14155b15611345575f6111a8846001612101565b90505f6111b9898360209101015190565b9050808888868181106111ce576111ce611f56565b9050604002015f01351461122957835f828a8a888181106111f1576111f1611f56565b6040805163049c2f1960e01b81526004810197909752602487019590955260448601939093525091020135606482015260840161061e565b604183036112cc575f61123d866021612101565b90505f61124e8b8360209101015190565b9050808a8a8881811061126357611263611f56565b90506040020160200135146112c557856001828c8c8a81811061128857611288611f56565b9050604002016020013560405163049c2f1960e01b815260040161061e949392919093845260208401929092526040830152606082015260800190565b5050611342565b888501602001515f90811a906112fc8a8a888181106112ed576112ed611f56565b905060400201602001356118e1565b90508060ff168260ff161461133f5760405163049c2f1960e01b8152600481018790526001602482015260ff83811660448301528216606482015260840161061e565b50505b50505b61134f8184612101565b9250506001016110f3565b60605f61136683611408565b6028602282012090915060601c60295b60018111156113ff57600782600f161180156113ab575060608382815181106113a1576113a1611f56565b016020015160f81c115b156113e857602060f81b8382815181106113c7576113c7611f56565b0160200180516001600160f81b0319908116909218909116905f82901a9053505b60049190911c906113f8816122a5565b9050611376565b50909392505050565b606061141e6001600160a01b0383166014611a40565b92915050565b5f5f8290505f604051806040016040528060168152602001752d31b0b9b41029b4b3b732b21026b2b9b9b0b3b29d0560511b81525051604051806040016040528060168152602001752d31b0b9b41029b4b3b732b21026b2b9b9b0b3b29d0560511b81525060405160200161149a9291906122ba565b60405160208183030381529060405290505f8251836040516020016114c09291906122ba565b60405160208183030381529060405290505f82826040516020016114e59291906122e8565b60405160208183030381529060405290506002808260405161150791906120cf565b602060405180830381855afa158015611522573d5f5f3e3d5ffd5b5050506040513d601f19601f8201168201806040525081019061154591906120ea565b60405160200161155791815260200190565b60408051601f1981840301815290829052611571916120cf565b602060405180830381855afa15801561158c573d5f5f3e3d5ffd5b5050506040513d601f19601f820116820180604052508101906115af91906120ea565b9695505050505050565b6115dd60405180606001604052805f81526020015f81526020015f60ff1681525090565b81516041146115ff57604051636e6a2efd60e11b815260040160405180910390fd5b5f5f5f845f8151811061161457611614611f56565b016020015160218601516041870151909450925060f81c90507f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a082111561166e57604051638baa579f60e01b815260040160405180910390fd5b60408051606081018252938452602084019290925260ff169082015292915050565b5f5f846040015160ff16601f14806116af5750846040015160ff166020145b156116cc57600485604001516116c5919061230d565b90506116d3565b5060408401515b8451602080870151604080515f8082529381018083528b905260ff861691810191909152606081019390935260808301529060019060a0016020604051602081039080840390855afa15801561172b573d5f5f3e3d5ffd5b5050604051601f1901519150506001600160a01b03811661175f57604051638baa579f60e01b815260040160405180910390fd5b60408051602081018790529081018590525f9060600160408051808303601f1901815291905280516020909101206001600160a01b03908116921691909114979650505050505050565b6001600160601b031981165f90815260016020526040808220805492905560048054915163a9059cbb60e01b81526001600160a01b03868116928201929092526024810184905291169063a9059cbb906044016020604051808303815f875af1158015611818573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061183c9190612326565b50604080516001600160601b031984168152602081018390526001600160a01b0385169133917fb7a3182152821ec30be365140cc780a582127d526b3fa9dbbfa1717bf120d1f7910160405180910390a3505050565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f816118ee600282612345565b5f036118fd5750600292915050565b50600392915050565b50919050565b6040516001600160f81b031960f883901b166020820152602181018390525f906003906002906041015b60408051601f1981840301815290829052611950916120cf565b602060405180830381855afa15801561196b573d5f5f3e3d5ffd5b5050506040513d601f19601f8201168201806040525081019061198e91906120ea565b6040516020016119a091815260200190565b60408051601f19818403018152908290526119ba916120cf565b602060405180830381855afa1580156119d5573d5f5f3e3d5ffd5b50506040515160601b949350505050565b604051600160fa1b602082015260218101839052604181018290525f90600390600290606101611936565b611a1d84848484611690565b611a3a5760405163fb5eb01360e01b815260040160405180910390fd5b50505050565b6060825f611a4f846002612364565b611a5a906002612101565b6001600160401b03811115611a7157611a71611c79565b6040519080825280601f01601f191660200182016040528015611a9b576020820181803683370190505b509050600360fc1b815f81518110611ab557611ab5611f56565b60200101906001600160f81b03191690815f1a905350600f60fb1b81600181518110611ae357611ae3611f56565b60200101906001600160f81b03191690815f1a9053505f611b05856002612364565b611b10906001612101565b90505b6001811115611b87576f181899199a1a9b1b9c1cb0b131b232b360811b83600f1660108110611b4457611b44611f56565b1a60f81b828281518110611b5a57611b5a611f56565b60200101906001600160f81b03191690815f1a90535060049290921c91611b80816122a5565b9050611b13565b508115611bb15760405163e22e27eb60e01b8152600481018690526024810185905260440161061e565b949350505050565b5f60208284031215611bc9575f5ffd5b5035919050565b5f5f83601f840112611be0575f5ffd5b5081356001600160401b03811115611bf6575f5ffd5b6020830191508360208260061b8501011115611c10575f5ffd5b9250929050565b5f5f5f60408486031215611c29575f5ffd5b8335925060208401356001600160401b03811115611c45575f5ffd5b611c5186828701611bd0565b9497909650939450505050565b80356001600160a01b0381168114611c74575f5ffd5b919050565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f191681016001600160401b0381118282101715611cb557611cb5611c79565b604052919050565b5f6001600160401b03821115611cd557611cd5611c79565b50601f01601f191660200190565b5f82601f830112611cf2575f5ffd5b8135611d05611d0082611cbd565b611c8d565b818152846020838601011115611d19575f5ffd5b816020850160208301375f918101602001919091529392505050565b5f5f5f5f5f5f60808789031215611d4a575f5ffd5b611d5387611c5e565b955060208701356001600160401b03811115611d6d575f5ffd5b8701601f81018913611d7d575f5ffd5b80356001600160401b03811115611d92575f5ffd5b8960208260051b8401011115611da6575f5ffd5b6020919091019550935060408701356001600160401b03811115611dc8575f5ffd5b611dd489828a01611ce3565b93505060608701356001600160401b03811115611def575f5ffd5b611dfb89828a01611bd0565b979a9699509497509295939492505050565b5f5b83811015611e27578181015183820152602001611e0f565b50505f910152565b602081525f8251806020840152611e4d816040850160208701611e0d565b601f01601f19169190910160400192915050565b5f5f5f8385036080811215611e74575f5ffd5b611e7d85611c5e565b935060208501356001600160401b03811115611e97575f5ffd5b611ea387828801611ce3565b9350506040603f1982011215611eb7575f5ffd5b506040840190509250925092565b5f60208284031215611ed5575f5ffd5b611ede82611c5e565b9392505050565b5f5f60408385031215611ef6575f5ffd5b82356001600160401b03811115611f0b575f5ffd5b611f1785828601611ce3565b925050611f2660208401611c5e565b90509250929050565b5f60208284031215611f3f575f5ffd5b81356001600160601b031981168114611ede575f5ffd5b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b8181038181111561141e5761141e611f6a565b600181811c90821680611fa557607f821691505b60208210810361190657634e487b7160e01b5f52602260045260245ffd5b5f8154611fcf81611f91565b600182168015611fe65760018114611ffb57612028565b60ff1983168652811515820286019350612028565b845f5260205f205f5b8381101561202057815488820152600190910190602001612004565b505081860193505b50505092915050565b5f61203c8286611fc3565b845161204c818360208901611e0d565b845191019061205f818360208801611e0d565b0195945050505050565b5f5f8335601e1984360301811261207e575f5ffd5b8301803591506001600160401b03821115612097575f5ffd5b602001915036819003821315611c10575f5ffd5b5f6120b68285611fc3565b83516120c6818360208801611e0d565b01949350505050565b5f82516120e0818460208701611e0d565b9190910192915050565b5f602082840312156120fa575f5ffd5b5051919050565b8082018082111561141e5761141e611f6a565b5f60208284031215612124575f5ffd5b81516001600160401b03811115612139575f5ffd5b8201601f81018413612149575f5ffd5b8051612157611d0082611cbd565b81815285602083850101111561216b575f5ffd5b61217c826020830160208601611e0d565b95945050505050565b5f8351612196818460208801611e0d565b61217c81840185611fc3565b601f8211156121e657805f5260205f20601f840160051c810160208510156121c75750805b601f840160051c820191505b81811015610bbf575f81556001016121d3565b505050565b81516001600160401b0381111561220457612204611c79565b612218816122128454611f91565b846121a2565b6020601f82116001811461224a575f83156122335750848201515b5f19600385901b1c1916600184901b178455610bbf565b5f84815260208120601f198516915b828110156122795787850151825560209485019460019092019101612259565b508482101561229657868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b5f816122b3576122b3611f6a565b505f190190565b60ff60f81b8360f81b1681525f82516122da816001850160208701611e0d565b919091016001019392505050565b5f83516122f9818460208801611e0d565b8351908301906120c6818360208801611e0d565b60ff828116828216039081111561141e5761141e611f6a565b5f60208284031215612336575f5ffd5b81518015158114611ede575f5ffd5b5f8261235f57634e487b7160e01b5f52601260045260245ffd5b500690565b808202811582820484141761141e5761141e611f6a56fea2646970667358221220cfeae0fdebe1bd8ad16e8001d0364f949dbe2b0879dc68c85071fc5866fabf0864736f6c634300081b003360806040525f805460ff60a01b1916600160a11b179055348015610021575f5ffd5b50604051610cbb380380610cbb833981016040819052610040916101c8565b338061006557604051631e4fbdf760e01b81525f600482015260240160405180910390fd5b61006e8161008a565b50610078836100e5565b610082828261012e565b505050610207565b5f8054600160a01b900460ff1690036100b657604051638863b38f60e01b815260040160405180910390fd5b5f80545f1960ff600160a01b808404821692909201160260ff60a01b199091161790556100e281610179565b50565b6001600160a01b03811661010c5760405163c387fe1560e01b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b805f0361014e57604051638ea90cbf60e01b815260040160405180910390fd5b815f0361016e57604051637e44c36f60e11b815260040160405180910390fd5b600591909155600655565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f5f5f606084860312156101da575f5ffd5b83516001600160a01b03811681146101f0575f5ffd5b602085015160409095015190969495509392505050565b610aa7806102145f395ff3fe608060405234801561000f575f5ffd5b50600436106100f0575f3560e01c8063ae92e61c11610093578063e6fd48bc11610063578063e6fd48bc146101b0578063f2fde38b146101b9578063f9140f7f146101cc578063fc0c546a146101d5575f5ffd5b8063ae92e61c14610179578063c29a6fda14610182578063dc07065714610195578063deb36e32146101a8575f5ffd5b80634e71d92d116100ce5780634e71d92d14610144578063692d36a71461014e578063715018a6146101615780638da5cb5b14610169575f5ffd5b806338af3eed146100f45780633be283e9146101245780633f69cb001461013b575b5f5ffd5b600254610107906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b61012d60065481565b60405190815260200161011b565b61012d60075481565b61014c6101e8565b005b61014c61015c36600461097e565b610435565b61014c61054e565b5f546001600160a01b0316610107565b61012d60035481565b61014c61019036600461099e565b610561565b61014c6101a336600461099e565b61060b565b61014c6106bf565b61012d60045481565b61014c6101c736600461099e565b6107bc565b61012d60055481565b600154610107906001600160a01b031681565b6001546001600160a01b031661021157604051637bbede1f60e11b815260040160405180910390fd5b6004545f036102335760405163641c0b2160e11b815260040160405180910390fd5b600654600754036102575760405163275d416d60e21b815260040160405180910390fd5b5f60055460075460055461026b91906109df565b60045461027891906109f6565b6102829042610a09565b61028c9190610a1c565b9050805f036102ae576040516312d37ee560e31b815260040160405180910390fd5b5f6102c86007546006546102c29190610a09565b836107fe565b90508060075f8282546102db91906109f6565b925050819055505f6006546007541015610303576003546102fc90836109df565b9050610370565b6001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610349573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061036d9190610a3b565b90505b600254604080518381524260208201526001600160a01b039092169133917f2f6639d24651730c7bf57c95ddbf96d66d11477e4ec626876f92c22e5f365e68910160405180910390a360015460025460405163a9059cbb60e01b81526001600160a01b0391821660048201526024810184905291169063a9059cbb906044016020604051808303815f875af115801561040b573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061042f9190610a52565b50505050565b61043d610817565b6006546007540361046157604051635ee8231160e01b815260040160405180910390fd5b6005546006546104718484610843565b60045415610500576001546040516370a0823160e01b81523060048201525f916001600160a01b0316906370a0823190602401602060405180830381865afa1580156104bf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104e39190610a3b565b9050600654816104f39190610a1c565b60035550426004555f6007555b6040805185815260208101859052908101839052606081018290527f9cef914ceeeeda20f16e41daa8acec1596a28a6ade3a2052ef13ed94beee928e9060800160405180910390a150505050565b610556610817565b61055f5f61088e565b565b610569610817565b6001546001600160a01b03161561059357604051635ee8231160e01b815260040160405180910390fd5b6001600160a01b0381166105ba5760405163c387fe1560e01b815260040160405180910390fd5b6002546001600160a01b03908116908216036105e9576040516399d8ae3360e01b815260040160405180910390fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b610613610817565b6006546007540361063757604051635ee8231160e01b815260040160405180910390fd5b6001546001600160a01b0390811690821603610666576040516399d8ae3360e01b815260040160405180910390fd5b6002546001600160a01b031661067b826108e6565b806001600160a01b0316826001600160a01b03167f948b7fd6001c5a82456f922e394fd549fed19d11220898d726ffb430fb951e9460405160405180910390a35050565b6001546001600160a01b031633146106ea57604051635ee8231160e01b815260040160405180910390fd5b6003541515806106fb575060045415155b15610719576040516372de7acd60e01b815260040160405180910390fd5b6001546040516370a0823160e01b81523060048201525f916001600160a01b0316906370a0823190602401602060405180830381865afa15801561075f573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107839190610a3b565b9050805f036107a5576040516346f1397d60e01b815260040160405180910390fd5b6006546107b29082610a1c565b6003555042600455565b6107c4610817565b6001600160a01b0381166107f257604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b6107fb8161088e565b50565b5f81831061080c578161080e565b825b90505b92915050565b5f546001600160a01b0316331461055f5760405163118cdaa760e01b81523360048201526024016107e9565b805f0361086357604051638ea90cbf60e01b815260040160405180910390fd5b815f0361088357604051637e44c36f60e11b815260040160405180910390fd5b600591909155600655565b5f8054600160a01b900460ff1690036108ba57604051638863b38f60e01b815260040160405180910390fd5b5f80545f1960ff600160a01b808404821692909201160260ff60a01b199091161790556107fb8161092f565b6001600160a01b03811661090d5760405163c387fe1560e01b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f5f6040838503121561098f575f5ffd5b50508035926020909101359150565b5f602082840312156109ae575f5ffd5b81356001600160a01b03811681146109c4575f5ffd5b9392505050565b634e487b7160e01b5f52601160045260245ffd5b8082028115828204841417610811576108116109cb565b80820180821115610811576108116109cb565b81810381811115610811576108116109cb565b5f82610a3657634e487b7160e01b5f52601260045260245ffd5b500490565b5f60208284031215610a4b575f5ffd5b5051919050565b5f60208284031215610a62575f5ffd5b815180151581146109c4575f5ffdfea2646970667358221220fccf81d5a305b940bce8c44664ab7f722df15f3a5d052b6052931731beafd33964736f6c634300081b003360e060405234801561000f575f5ffd5b5060405161125438038061125483398101604081905261002e916102f5565b610044670de0b6b3a76400006301406f40610399565b868660036100528382610446565b50600461005f8282610446565b505050805f036100895760405163392e1e2760e01b81525f60048201526024015b60405180910390fd5b6080526001600160a01b0384166100d857604051630e02d8f560e31b815260206004820152601260248201527117d95bdb909858dadd5c10dbdb9d1c9858dd60721b6044820152606401610080565b6001600160a01b03831661012f57604051630e02d8f560e31b815260206004820152601360248201527f5f7a656e644261636b7570436f6e7472616374000000000000000000000000006044820152606401610080565b6001600160a01b03821661018657604051630e02d8f560e31b815260206004820152601860248201527f5f686f72697a656e466f756e646174696f6e56657374656400000000000000006044820152606401610080565b6001600160a01b0381166101d157604051630e02d8f560e31b815260206004820152601160248201527017da1bdc9a5e995b91185bd5995cdd1959607a1b6044820152606401610080565b6001600160a01b039384165f90815260056020526040808220805460ff1990811660019081179092559587168352912080548516909117905560068054909316600217909255821660a0521660c052506105009050565b634e487b7160e01b5f52604160045260245ffd5b5f82601f83011261024b575f5ffd5b81516001600160401b0381111561026457610264610228565b604051601f8201601f19908116603f011681016001600160401b038111828210171561029257610292610228565b6040528181528382016020018510156102a9575f5ffd5b5f5b828110156102c7576020818601810151838301820152016102ab565b505f918101602001919091529392505050565b80516001600160a01b03811681146102f0575f5ffd5b919050565b5f5f5f5f5f5f60c0878903121561030a575f5ffd5b86516001600160401b0381111561031f575f5ffd5b61032b89828a0161023c565b602089015190975090506001600160401b03811115610348575f5ffd5b61035489828a0161023c565b955050610363604088016102da565b9350610371606088016102da565b925061037f608088016102da565b915061038d60a088016102da565b90509295509295509295565b80820281158282048414176103bc57634e487b7160e01b5f52601160045260245ffd5b92915050565b600181811c908216806103d657607f821691505b6020821081036103f457634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111561044157805f5260205f20601f840160051c8101602085101561041f5750805b601f840160051c820191505b8181101561043e575f815560010161042b565b50505b505050565b81516001600160401b0381111561045f5761045f610228565b6104738161046d84546103c2565b846103fa565b6020601f8211600181146104a5575f831561048e5750848201515b5f19600385901b1c1916600184901b17845561043e565b5f84815260208120601f198516915b828110156104d457878501518255602094850194600190920191016104b4565b50848210156104f157868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b60805160a05160c051610cf26105625f395f818161023e0152818161059d0152818161062601526106bf01525f81816101ff015281816104e10152818161056a015261065101525f81816101810152818161045b015261095e0152610cf25ff3fe608060405234801561000f575f5ffd5b5060043610610106575f3560e01c806375252b261161009e5780638a2545161161006e5780638a2545161461023957806395d89b4114610260578063a9059cbb14610268578063dd62ed3e1461027b578063f46eccc4146102b3575f5ffd5b806375252b26146101e25780637986eb0b146101ea5780637c745afb146101f2578063867e3036146101fa575f5ffd5b8063313ce567116100d9578063313ce56714610170578063355274ea1461017f57806340c10f19146101a557806370a08231146101ba575f5ffd5b806306fdde031461010a578063095ea7b31461012857806318160ddd1461014b57806323b872dd1461015d575b5f5ffd5b6101126102d5565b60405161011f9190610ad6565b60405180910390f35b61013b610136366004610b38565b610365565b604051901515815260200161011f565b6002545b60405190815260200161011f565b61013b61016b366004610b62565b61037e565b6040516012815260200161011f565b7f000000000000000000000000000000000000000000000000000000000000000061014f565b6101b86101b3366004610b38565b6103a1565b005b61014f6101c8366004610ba0565b6001600160a01b03165f9081526020819052604090205490565b61014f603c81565b6101b86103e5565b61014f601981565b6102217f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161011f565b6102217f000000000000000000000000000000000000000000000000000000000000000081565b610112610733565b61013b610276366004610b38565b610742565b61014f610289366004610bc2565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b61013b6102c1366004610ba0565b60056020525f908152604090205460ff1681565b6060600380546102e490610bf9565b80601f016020809104026020016040519081016040528092919081815260200182805461031090610bf9565b801561035b5780601f106103325761010080835404028352916020019161035b565b820191905f5260205f20905b81548152906001019060200180831161033e57829003601f168201915b5050505050905090565b5f3361037281858561074f565b60019150505b92915050565b5f3361038b858285610761565b6103968585856107dd565b506001949350505050565b335f9081526005602052604090205460ff166103d757604051632fdab94f60e11b81523360048201526024015b60405180910390fd5b6103e1828261083a565b5050565b335f9081526005602052604090205460ff1661041657604051632fdab94f60e11b81523360048201526024016103ce565b335f908152600560205260408120805460ff19908116909155600680545f1960ff82811691909101169216821790559003610731575f61045560025490565b61047f907f0000000000000000000000000000000000000000000000000000000000000000610c45565b90505f606461048f603c84610c58565b6104999190610c6f565b90505f6104a68284610c45565b90505f60646104b6601985610c58565b6104c09190610c6f565b90505f60646104d0601985610c58565b6104da9190610c6f565b90506105657f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166338af3eed6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561053b573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061055f9190610c8e565b8261083a565b6105987f00000000000000000000000000000000000000000000000000000000000000006105938386610c45565b61083a565b6106217f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166338af3eed6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105f7573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061061b9190610c8e565b8361083a565b61064f7f00000000000000000000000000000000000000000000000000000000000000006105938487610c45565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663deb36e326040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156106a7575f5ffd5b505af11580156106b9573d5f5f3e3d5ffd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663deb36e326040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610715575f5ffd5b505af1158015610727573d5f5f3e3d5ffd5b5050505050505050505b565b6060600480546102e490610bf9565b5f336103728185856107dd565b61075c838383600161086e565b505050565b6001600160a01b038381165f908152600160209081526040808320938616835292905220545f198110156107d757818110156107c957604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064016103ce565b6107d784848484035f61086e565b50505050565b6001600160a01b03831661080657604051634b637e8f60e11b81525f60048201526024016103ce565b6001600160a01b03821661082f5760405163ec442f0560e01b81525f60048201526024016103ce565b61075c838383610940565b6001600160a01b0382166108635760405163ec442f0560e01b81525f60048201526024016103ce565b6103e15f8383610940565b6001600160a01b0384166108975760405163e602df0560e01b81525f60048201526024016103ce565b6001600160a01b0383166108c057604051634a1406b160e11b81525f60048201526024016103ce565b6001600160a01b038085165f90815260016020908152604080832093871683529290522082905580156107d757826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161093291815260200190565b60405180910390a350505050565b61094b8383836109b0565b6001600160a01b03831661075c576002547f000000000000000000000000000000000000000000000000000000000000000090818111156109a95760405163279e7e1560e21b815260048101829052602481018390526044016103ce565b5050505050565b6001600160a01b0383166109da578060025f8282546109cf9190610ca9565b90915550610a4a9050565b6001600160a01b0383165f9081526020819052604090205481811015610a2c5760405163391434e360e21b81526001600160a01b038516600482015260248101829052604481018390526064016103ce565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b038216610a6657600280548290039055610a84565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051610ac991815260200190565b60405180910390a3505050565b602081525f82518060208401525f5b81811015610b025760208186018101516040868401015201610ae5565b505f604082850101526040601f19601f83011684010191505092915050565b6001600160a01b0381168114610b35575f5ffd5b50565b5f5f60408385031215610b49575f5ffd5b8235610b5481610b21565b946020939093013593505050565b5f5f5f60608486031215610b74575f5ffd5b8335610b7f81610b21565b92506020840135610b8f81610b21565b929592945050506040919091013590565b5f60208284031215610bb0575f5ffd5b8135610bbb81610b21565b9392505050565b5f5f60408385031215610bd3575f5ffd5b8235610bde81610b21565b91506020830135610bee81610b21565b809150509250929050565b600181811c90821680610c0d57607f821691505b602082108103610c2b57634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52601160045260245ffd5b8181038181111561037857610378610c31565b808202811582820484141761037857610378610c31565b5f82610c8957634e487b7160e01b5f52601260045260245ffd5b500490565b5f60208284031215610c9e575f5ffd5b8151610bbb81610b21565b8082018082111561037857610378610c3156fea2646970667358221220db3b20861bef87be0d07273f9aaf0cab87e2a74a95141c3d82455a325752ab8964736f6c634300081b0033a264697066735822122022f022eee3d136553ecdcb1ce8062d5b9c17ac4740d305c5bbf1c12f674dfa5a64736f6c634300081b00330000000000000000000000004053aeaa16c5c81511e2b38eb3cd3594ad98c755
Deployed Bytecode
0x608060405234801561000f575f5ffd5b5060043610610090575f3560e01c8063ca21070511610063578063ca210705146100f0578063e45c86c714610103578063e7a57f3b14610116578063f2fde38b14610129578063fc0c546a1461013c575f5ffd5b80632f082dfe14610094578063715018a6146100c35780638da5cb5b146100cd578063b6d3ee19146100dd575b5f5ffd5b6003546100a7906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b6100cb61014f565b005b5f546001600160a01b03166100a7565b6002546100a7906001600160a01b031681565b6100cb6100fe3660046108bc565b610162565b6005546100a7906001600160a01b031681565b6004546100a7906001600160a01b031681565b6100cb61013736600461098b565b610711565b6001546100a7906001600160a01b031681565b610157610753565b6101605f61077f565b565b61016a610753565b6001546001600160a01b0316156101945760405163ad5b93e360e01b815260040160405180910390fd5b306040516101a1906107ce565b6001600160a01b039091168152602001604051809103905ff0801580156101ca573d5f5f3e3d5ffd5b5060025f6101000a8154816001600160a01b0302191690836001600160a01b0316021790555030856040516101fe906107db565b6102099291906109ee565b604051809103905ff080158015610222573d5f5f3e3d5ffd5b5060035f6101000a8154816001600160a01b0302191690836001600160a01b031602179055508262278d00603060405161025b906107e8565b6001600160a01b03909316835260208301919091526040820152606001604051809103905ff080158015610291573d5f5f3e3d5ffd5b5060045f6101000a8154816001600160a01b0302191690836001600160a01b031602179055508062278d0060306040516102ca906107e8565b6001600160a01b03909316835260208301919091526040820152606001604051809103905ff080158015610300573d5f5f3e3d5ffd5b50600580546001600160a01b0319166001600160a01b039283169081179091556002546003546004546040518c958c95948116949381169392169190610345906107f5565b61035496959493929190610a19565b604051809103905ff08015801561036d573d5f5f3e3d5ffd5b50600180546001600160a01b0319166001600160a01b0392831690811790915560025460405163614d37ed60e11b815260048101929092529091169063c29a6fda906024015f604051808303815f87803b1580156103c9575f5ffd5b505af11580156103db573d5f5f3e3d5ffd5b505060035460015460405163614d37ed60e11b81526001600160a01b0391821660048201529116925063c29a6fda91506024015f604051808303815f87803b158015610425575f5ffd5b505af1158015610437573d5f5f3e3d5ffd5b50506004805460015460405163614d37ed60e11b81526001600160a01b039182169381019390935216925063c29a6fda91506024015f604051808303815f87803b158015610483575f5ffd5b505af1158015610495573d5f5f3e3d5ffd5b505060055460015460405163614d37ed60e11b81526001600160a01b0391821660048201529116925063c29a6fda91506024015f604051808303815f87803b1580156104df575f5ffd5b505af11580156104f1573d5f5f3e3d5ffd5b50506002546001600160a01b0316915063f2fde38b90506105195f546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201526024015f604051808303815f87803b158015610557575f5ffd5b505af1158015610569573d5f5f3e3d5ffd5b50506003546001600160a01b0316915063f2fde38b90506105915f546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201526024015f604051808303815f87803b1580156105cf575f5ffd5b505af11580156105e1573d5f5f3e3d5ffd5b50506004805460405163f2fde38b60e01b81526001600160a01b03898116938201939093529116925063f2fde38b91506024015f604051808303815f87803b15801561062b575f5ffd5b505af115801561063d573d5f5f3e3d5ffd5b505060055460405163f2fde38b60e01b81526001600160a01b038681166004830152909116925063f2fde38b91506024015f604051808303815f87803b158015610685575f5ffd5b505af1158015610697573d5f5f3e3d5ffd5b5050600154600254600354600454600554604080516001600160a01b039687168152948616602086015292851684840152908416606084015292909216608082015290517f58cf092af1db61442ba2a7a12c04e594db226c99370dff3eea5023f5dcb21fc693509081900360a0019150a150505050505050565b610719610753565b6001600160a01b03811661074757604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b6107508161077f565b50565b5f546001600160a01b031633146101605760405163118cdaa760e01b815233600482015260240161073e565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b610a1580610a7283390190565b6126bd8061148783390190565b610cbb80613b4483390190565b611254806147ff83390190565b634e487b7160e01b5f52604160045260245ffd5b5f82601f830112610825575f5ffd5b813567ffffffffffffffff81111561083f5761083f610802565b604051601f8201601f19908116603f0116810167ffffffffffffffff8111828210171561086e5761086e610802565b604052818152838201602001851015610885575f5ffd5b816020850160208301375f918101602001919091529392505050565b80356001600160a01b03811681146108b7575f5ffd5b919050565b5f5f5f5f5f5f5f60e0888a0312156108d2575f5ffd5b873567ffffffffffffffff8111156108e8575f5ffd5b6108f48a828b01610816565b975050602088013567ffffffffffffffff811115610910575f5ffd5b61091c8a828b01610816565b965050604088013567ffffffffffffffff811115610938575f5ffd5b6109448a828b01610816565b955050610953606089016108a1565b9350610961608089016108a1565b925061096f60a089016108a1565b915061097d60c089016108a1565b905092959891949750929550565b5f6020828403121561099b575f5ffd5b6109a4826108a1565b9392505050565b5f81518084525f5b818110156109cf576020818501810151868301820152016109b3565b505f602082860101526020601f19601f83011685010191505092915050565b6001600160a01b03831681526040602082018190525f90610a11908301846109ab565b949350505050565b60c081525f610a2b60c08301896109ab565b8281036020840152610a3d81896109ab565b6001600160a01b03978816604085015295871660608401525050918416608083015290921660a0909201919091529291505056fe6080604052348015600e575f5ffd5b50604051610a15380380610a15833981016040819052602b9160b4565b806001600160a01b038116605857604051631e4fbdf760e01b81525f600482015260240160405180910390fd5b605f816065565b505060df565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f6020828403121560c3575f5ffd5b81516001600160a01b038116811460d8575f5ffd5b9392505050565b610929806100ec5f395ff3fe608060405234801561000f575f5ffd5b50600436106100b1575f3560e01c806391c05b0b1161006e57806391c05b0b14610144578063a617ba6014610157578063c29a6fda1461016a578063d6db84e91461017d578063d89ae26c14610186578063f2fde38b1461019e575f5ffd5b806301af9843146100b55780631a843afb146100ca57806327e235e3146100dd5780634285fcbd1461010f578063715018a6146101185780638da5cb5b14610120575b5f5ffd5b6100c86100c336600461073b565b6101b1565b005b6100c86100d83660046107db565b6101fd565b6100fc6100eb3660046108bf565b60016020525f908152604090205481565b6040519081526020015b60405180910390f35b6100fc60045481565b6100c86103c0565b5f546001600160a01b03165b6040516001600160a01b039091168152602001610106565b6100c861015236600461073b565b6103d3565b60065461012c906001600160a01b031681565b6100c86101783660046108bf565b6105c3565b6100fc60035481565b61018e61063e565b6040519015158152602001610106565b6100c86101ac3660046108bf565b61067e565b6101b96106c0565b806101d757604051636f6ed5ab60e01b815260040160405180910390fd5b600454156101f857604051635ee8231160e01b815260040160405180910390fd5b600455565b6102056106c0565b6004546102255760405163350212c960e11b815260040160405180910390fd5b60045460035403610249576040516302f715b160e51b815260040160405180910390fd5b6003545f905b8251821461039557828281518110610269576102696108df565b60200260200101516020015160015f85858151811061028a5761028a6108df565b60200260200101515f01516001600160a01b03166001600160a01b031681526020019081526020015f208190555060028383815181106102cc576102cc6108df565b6020908102919091018101515182546001810184555f938452919092200180546001600160a01b0319166001600160a01b039092169190911790558251819084908490811061031d5761031d6108df565b60200260200101515f015184848151811061033a5761033a6108df565b602002602001015160200151604051602001610372939291909283526001600160a01b03919091166020830152604082015260600190565b60405160208183030381529060405280519060200120905081600101915061024f565b60038190558381146103ba57604051636f6ed5ab60e01b815260040160405180910390fd5b50505050565b6103c86106c0565b6103d15f6106ec565b565b6103db6106c0565b6004546103fb5760405163350212c960e11b815260040160405180910390fd5b6006546001600160a01b031661042457604051637bbede1f60e11b815260040160405180910390fd5b6004546003541461044857604051636f6ed5ab60e01b815260040160405180910390fd5b6002546005540361046b5760405162598fc960e21b815260040160405180910390fd5b6005545f905b60025481148015906104835750828214155b1561054d575f6002828154811061049c5761049c6108df565b5f9182526020808320909101546001600160a01b03168083526001909152604090912054909150801561053f576001600160a01b038281165f818152600160205260408082209190915560065490516340c10f1960e01b8152600481019290925260248201849052909116906340c10f19906044015f604051808303815f87803b158015610528575f5ffd5b505af115801561053a573d5f5f3e3d5ffd5b505050505b505060019182019101610471565b600581905560025481036105be5760065f9054906101000a90046001600160a01b03166001600160a01b0316637986eb0b6040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156105a7575f5ffd5b505af11580156105b9573d5f5f3e3d5ffd5b505050505b505050565b6105cb6106c0565b6006546001600160a01b0316156105f557604051635ee8231160e01b815260040160405180910390fd5b6001600160a01b03811661061c5760405163d23f952160e01b815260040160405180910390fd5b600680546001600160a01b0319166001600160a01b0392909216919091179055565b6006545f906001600160a01b03161580159061065b575060035415155b801561066a5750600454600354145b80156106795750600254600554105b905090565b6106866106c0565b6001600160a01b0381166106b457604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b6106bd816106ec565b50565b5f546001600160a01b031633146103d15760405163118cdaa760e01b81523360048201526024016106ab565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f6020828403121561074b575f5ffd5b5035919050565b634e487b7160e01b5f52604160045260245ffd5b6040805190810167ffffffffffffffff8111828210171561078957610789610752565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156107b8576107b8610752565b604052919050565b80356001600160a01b03811681146107d6575f5ffd5b919050565b5f5f604083850312156107ec575f5ffd5b82359150602083013567ffffffffffffffff811115610809575f5ffd5b8301601f81018513610819575f5ffd5b803567ffffffffffffffff81111561083357610833610752565b61084260208260051b0161078f565b8082825260208201915060208360061b850101925087831115610863575f5ffd5b6020840193505b828410156108b15760408489031215610881575f5ffd5b610889610766565b610892856107c0565b815260208581013581830152908352604090940193919091019061086a565b809450505050509250929050565b5f602082840312156108cf575f5ffd5b6108d8826107c0565b9392505050565b634e487b7160e01b5f52603260045260245ffdfea26469706673582212202189f268735afa99da28236675acf93f9a8d04c4d1822b6e3d348bc02be0709264736f6c634300081b0033608060405234801561000f575f5ffd5b506040516126bd3803806126bd83398101604081905261002e916100dd565b816001600160a01b03811661005c57604051631e4fbdf760e01b81525f600482015260240160405180910390fd5b6100658161007a565b5060056100728282610245565b5050506102ff565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b634e487b7160e01b5f52604160045260245ffd5b5f5f604083850312156100ee575f5ffd5b82516001600160a01b0381168114610104575f5ffd5b60208401519092506001600160401b0381111561011f575f5ffd5b8301601f8101851361012f575f5ffd5b80516001600160401b03811115610148576101486100c9565b604051601f8201601f19908116603f011681016001600160401b0381118282101715610176576101766100c9565b60405281815282820160200187101561018d575f5ffd5b5f5b828110156101ab5760208185018101518383018201520161018f565b505f602083830101528093505050509250929050565b600181811c908216806101d557607f821691505b6020821081036101f357634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111561024057805f5260205f20601f840160051c8101602085101561021e5750805b601f840160051c820191505b8181101561023d575f815560010161022a565b50505b505050565b81516001600160401b0381111561025e5761025e6100c9565b6102728161026c84546101c1565b846101f9565b6020601f8211600181146102a4575f831561028d5750848201515b5f19600385901b1c1916600184901b17845561023d565b5f84815260208120601f198516915b828110156102d357878501518255602094850194600190920191016102b3565b50848210156102f057868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b6123b18061030c5f395ff3fe608060405234801561000f575f5ffd5b50600436106100f0575f3560e01c80638da5cb5b11610093578063c29a6fda11610063578063c29a6fda146101d8578063d6db84e9146101eb578063f2113dc9146101f4578063f2fde38b14610213575f5ffd5b80638da5cb5b1461017b578063a617ba601461019f578063aca8f752146101b2578063b2b505b4146101c5575f5ffd5b80635123106b116100ce5780635123106b14610138578063550d13551461014b578063715018a61461016057806381aef57d14610168575f5ffd5b806301af9843146100f4578063178617b9146101095780634285fcbd1461011c575b5f5ffd5b610107610102366004611bb9565b610226565b005b610107610117366004611c17565b610272565b61012560035481565b6040519081526020015b60405180910390f35b610107610146366004611d35565b6104fb565b610153610872565b60405161012f9190611e2f565b6101076108fe565b610107610176366004611e61565b610911565b5f546001600160a01b03165b6040516001600160a01b03909116815260200161012f565b600454610187906001600160a01b031681565b6101076101c0366004611ec5565b610aa4565b6101076101d3366004611ee5565b610bc6565b6101076101e6366004611ec5565b610e4f565b61012560025481565b610125610202366004611f2f565b60016020525f908152604090205481565b610107610221366004611ec5565b610f56565b61022e610f93565b8061024c57604051636f6ed5ab60e01b815260040160405180910390fd5b6003541561026d57604051635ee8231160e01b815260040160405180910390fd5b600355565b61027a610f93565b60035461029a5760405163350212c960e11b815260040160405180910390fd5b6004546001600160a01b03166102c357604051637bbede1f60e11b815260040160405180910390fd5b600354600254036102e7576040516302f715b160e51b815260040160405180910390fd5b6002545f90815b82841461040b5784848481811061030757610307611f56565b9050604002016020013560015f87878781811061032657610326611f56565b61033c9260206040909202019081019150611f2f565b6001600160601b031916815260208101919091526040015f20558185858581811061036957610369611f56565b61037f9260206040909202019081019150611f2f565b86868681811061039157610391611f56565b905060400201602001356040516020016103c8939291909283526001600160601b0319919091166020830152604082015260600190565b6040516020818303038152906040528051906020012091508484848181106103f2576103f2611f56565b90506040020160200135810190508260010192506102ee565b600282905585821461043057604051636f6ed5ab60e01b815260040160405180910390fd5b600480546040516340c10f1960e01b81523092810192909252602482018390526001600160a01b0316906340c10f19906044015f604051808303815f87803b15801561047a575f5ffd5b505af115801561048c573d5f5f3e3d5ffd5b50505050600254600354036104f3576004805460408051637986eb0b60e01b815290516001600160a01b0390921692637986eb0b92828201925f929082900301818387803b1580156104dc575f5ffd5b505af11580156104ee573d5f5f3e3d5ffd5b505050505b505050505050565b856003546002541461052057604051636f6ed5ab60e01b815260040160405180910390fd5b6004546001600160a01b031661054957604051637bbede1f60e11b815260040160405180910390fd5b6001600160a01b0381166105705760405163d23f952160e01b815260040160405180910390fd5b6003546105905760405163350212c960e11b815260040160405180910390fd5b8482146105b057604051636758971b60e11b815260040160405180910390fd5b60108511156105d2576040516387e497e560e01b815260040160405180910390fd5b5f6105dc85610fbf565b6001600160601b031981165f9081526001602052604081205491925003610627576040516303d2b3ef60e21b81526001600160601b0319821660048201526024015b60405180910390fd5b5f6050865f8151811061063c5761063c611f56565b016020015161064e919060f81c611f7e565b905061065b868686611076565b5f6106658a61135a565b90505f6106748460601c611408565b90505f6006828460405160200161068d93929190612031565b60405160208183030381529060405290505f6106a882611424565b90505f5f5b808d148015906106bc57508682105b1561082c578d8d828181106106d3576106d3611f56565b90506020028101906106e59190612069565b159050610824575f8b8b838181106106ff576106ff611f56565b9050604002015f0135148061072e57505f8b8b8381811061072257610722611f56565b90506040020160200135145b15610772578a8a8281811061074557610745611f56565b604080516304d5bf6160e41b8152910292909201803560048401526020013560248301525060440161061e565b5f6107d38f8f8481811061078857610788611f56565b905060200281019061079a9190612069565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920191909152506115b992505050565b905061081684828e8e868181106107ec576107ec611f56565b9050604002015f01358f8f8781811061080757610807611f56565b90506040020160200135611690565b15610822578260010192505b505b6001016106ad565b86821015610857576040516378f4355360e11b8152600481018390526024810188905260440161061e565b6108618f896117a9565b505050505050505050505050505050565b6006805461087f90611f91565b80601f01602080910402602001604051908101604052809291908181526020018280546108ab90611f91565b80156108f65780601f106108cd576101008083540402835291602001916108f6565b820191905f5260205f20905b8154815290600101906020018083116108d957829003601f168201915b505050505081565b610906610f93565b61090f5f611892565b565b826003546002541461093657604051636f6ed5ab60e01b815260040160405180910390fd5b6004546001600160a01b031661095f57604051637bbede1f60e11b815260040160405180910390fd5b6001600160a01b0381166109865760405163d23f952160e01b815260040160405180910390fd5b6003546109a65760405163350212c960e11b815260040160405180910390fd5b5f6109b0846115b9565b90505f816040015160ff16601f14806109d05750816040015160ff166020145b156109f3576109ec84356109e760208701356118e1565b61190c565b9050610a05565b610a02843560208601356119e6565b90505b6001600160601b031981165f9081526001602052604081205490819003610a4b576040516303d2b3ef60e21b81526001600160601b03198316600482015260240161061e565b5f610a558861135a565b90505f600682604051602001610a6c9291906120ab565b60405160208183030381529060405290505f610a8782611424565b9050610a9a81878a3560208c0135611a11565b6104ee8a866117a9565b8060035460025414610ac957604051636f6ed5ab60e01b815260040160405180910390fd5b6004546001600160a01b0316610af257604051637bbede1f60e11b815260040160405180910390fd5b6001600160a01b038116610b195760405163d23f952160e01b815260040160405180910390fd5b600354610b395760405163350212c960e11b815260040160405180910390fd5b60408051606084901b6001600160601b03191660208201528151601481830301815260349091019091525f610b6d82610fbf565b6001600160601b031981165f90815260016020526040812054919250819003610bb5576040516303d2b3ef60e21b81526001600160601b03198316600482015260240161061e565b610bbf85836117a9565b5050505050565b8060035460025414610beb57604051636f6ed5ab60e01b815260040160405180910390fd5b6004546001600160a01b0316610c1457604051637bbede1f60e11b815260040160405180910390fd5b6001600160a01b038116610c3b5760405163d23f952160e01b815260040160405180910390fd5b600354610c5b5760405163350212c960e11b815260040160405180910390fd5b5f610c6584610fbf565b6001600160601b031981165f90815260016020526040812054919250819003610cad576040516303d2b3ef60e21b81526001600160601b03198316600482015260240161061e565b6040516001600160601b0319606086901b1660208201525f9060340160405160208183030381529060405290505f600282604051610ceb91906120cf565b602060405180830381855afa158015610d06573d5f5f3e3d5ffd5b5050506040513d601f19601f82011682018060405250810190610d2991906120ea565b90505f6050885f81518110610d4057610d40611f56565b0160200151610d52919060f81c611f7e565b90505f60508960028b51610d669190611f7e565b81518110610d7657610d76611f56565b0160200151610d88919060f81c611f7e565b9050816001141580610d9b575080600214155b15610dc357604051633c70407360e11b8152600481018390526024810182905260440161061e565b5f89600181518110610dd757610dd7611f56565b016020015160f81c90505f610ded826004612101565b90505f610dfe8c8360209101015190565b9050808614610e375760405163049c2f1960e01b8152600160048201525f6024820152604481018290526064810187905260840161061e565b610e418b8a6117a9565b505050505050505050505050565b610e57610f93565b6004546001600160a01b031615610e8157604051635ee8231160e01b815260040160405180910390fd5b6001600160a01b038116610ea85760405163d23f952160e01b815260040160405180910390fd5b600480546001600160a01b0319166001600160a01b0383169081178255604080516395d89b4160e01b8152905191926395d89b4192828201925f92908290030181865afa158015610efb573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610f229190810190612114565b6005604051602001610f35929190612185565b60405160208183030381529060405260069081610f5291906121eb565b5050565b610f5e610f93565b6001600160a01b038116610f8757604051631e4fbdf760e01b81525f600482015260240161061e565b610f9081611892565b50565b5f546001600160a01b0316331461090f5760405163118cdaa760e01b815233600482015260240161061e565b5f5f600283604051610fd191906120cf565b602060405180830381855afa158015610fec573d5f5f3e3d5ffd5b5050506040513d601f19601f8201168201806040525081019061100f91906120ea565b905060038160405160200161102691815260200190565b60408051601f1981840301815290829052611040916120cf565b602060405180830381855afa15801561105b573d5f5f3e3d5ffd5b50506040515160601b6001600160601b031916949350505050565b60028351101561109957604051631302f01760e21b815260040160405180910390fd5b5f605084600286516110ab9190611f7e565b815181106110bb576110bb611f56565b01602001516110cd919060f81c611f7e565b90508181146110ef57604051637ea25c0360e01b815260040160405180910390fd5b60015f5b828110156104f3575f86838151811061110e5761110e611f56565b016020015160019093019260f81c905060218114801590611130575060418114155b15611151576040516351c5a9a560e11b81526004810182905260240161061e565b85858381811061116357611163611f56565b60400291909101351580159150611197575085858381811061118757611187611f56565b905060400201602001355f5f1b14155b15611345575f6111a8846001612101565b90505f6111b9898360209101015190565b9050808888868181106111ce576111ce611f56565b9050604002015f01351461122957835f828a8a888181106111f1576111f1611f56565b6040805163049c2f1960e01b81526004810197909752602487019590955260448601939093525091020135606482015260840161061e565b604183036112cc575f61123d866021612101565b90505f61124e8b8360209101015190565b9050808a8a8881811061126357611263611f56565b90506040020160200135146112c557856001828c8c8a81811061128857611288611f56565b9050604002016020013560405163049c2f1960e01b815260040161061e949392919093845260208401929092526040830152606082015260800190565b5050611342565b888501602001515f90811a906112fc8a8a888181106112ed576112ed611f56565b905060400201602001356118e1565b90508060ff168260ff161461133f5760405163049c2f1960e01b8152600481018790526001602482015260ff83811660448301528216606482015260840161061e565b50505b50505b61134f8184612101565b9250506001016110f3565b60605f61136683611408565b6028602282012090915060601c60295b60018111156113ff57600782600f161180156113ab575060608382815181106113a1576113a1611f56565b016020015160f81c115b156113e857602060f81b8382815181106113c7576113c7611f56565b0160200180516001600160f81b0319908116909218909116905f82901a9053505b60049190911c906113f8816122a5565b9050611376565b50909392505050565b606061141e6001600160a01b0383166014611a40565b92915050565b5f5f8290505f604051806040016040528060168152602001752d31b0b9b41029b4b3b732b21026b2b9b9b0b3b29d0560511b81525051604051806040016040528060168152602001752d31b0b9b41029b4b3b732b21026b2b9b9b0b3b29d0560511b81525060405160200161149a9291906122ba565b60405160208183030381529060405290505f8251836040516020016114c09291906122ba565b60405160208183030381529060405290505f82826040516020016114e59291906122e8565b60405160208183030381529060405290506002808260405161150791906120cf565b602060405180830381855afa158015611522573d5f5f3e3d5ffd5b5050506040513d601f19601f8201168201806040525081019061154591906120ea565b60405160200161155791815260200190565b60408051601f1981840301815290829052611571916120cf565b602060405180830381855afa15801561158c573d5f5f3e3d5ffd5b5050506040513d601f19601f820116820180604052508101906115af91906120ea565b9695505050505050565b6115dd60405180606001604052805f81526020015f81526020015f60ff1681525090565b81516041146115ff57604051636e6a2efd60e11b815260040160405180910390fd5b5f5f5f845f8151811061161457611614611f56565b016020015160218601516041870151909450925060f81c90507f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a082111561166e57604051638baa579f60e01b815260040160405180910390fd5b60408051606081018252938452602084019290925260ff169082015292915050565b5f5f846040015160ff16601f14806116af5750846040015160ff166020145b156116cc57600485604001516116c5919061230d565b90506116d3565b5060408401515b8451602080870151604080515f8082529381018083528b905260ff861691810191909152606081019390935260808301529060019060a0016020604051602081039080840390855afa15801561172b573d5f5f3e3d5ffd5b5050604051601f1901519150506001600160a01b03811661175f57604051638baa579f60e01b815260040160405180910390fd5b60408051602081018790529081018590525f9060600160408051808303601f1901815291905280516020909101206001600160a01b03908116921691909114979650505050505050565b6001600160601b031981165f90815260016020526040808220805492905560048054915163a9059cbb60e01b81526001600160a01b03868116928201929092526024810184905291169063a9059cbb906044016020604051808303815f875af1158015611818573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061183c9190612326565b50604080516001600160601b031984168152602081018390526001600160a01b0385169133917fb7a3182152821ec30be365140cc780a582127d526b3fa9dbbfa1717bf120d1f7910160405180910390a3505050565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f816118ee600282612345565b5f036118fd5750600292915050565b50600392915050565b50919050565b6040516001600160f81b031960f883901b166020820152602181018390525f906003906002906041015b60408051601f1981840301815290829052611950916120cf565b602060405180830381855afa15801561196b573d5f5f3e3d5ffd5b5050506040513d601f19601f8201168201806040525081019061198e91906120ea565b6040516020016119a091815260200190565b60408051601f19818403018152908290526119ba916120cf565b602060405180830381855afa1580156119d5573d5f5f3e3d5ffd5b50506040515160601b949350505050565b604051600160fa1b602082015260218101839052604181018290525f90600390600290606101611936565b611a1d84848484611690565b611a3a5760405163fb5eb01360e01b815260040160405180910390fd5b50505050565b6060825f611a4f846002612364565b611a5a906002612101565b6001600160401b03811115611a7157611a71611c79565b6040519080825280601f01601f191660200182016040528015611a9b576020820181803683370190505b509050600360fc1b815f81518110611ab557611ab5611f56565b60200101906001600160f81b03191690815f1a905350600f60fb1b81600181518110611ae357611ae3611f56565b60200101906001600160f81b03191690815f1a9053505f611b05856002612364565b611b10906001612101565b90505b6001811115611b87576f181899199a1a9b1b9c1cb0b131b232b360811b83600f1660108110611b4457611b44611f56565b1a60f81b828281518110611b5a57611b5a611f56565b60200101906001600160f81b03191690815f1a90535060049290921c91611b80816122a5565b9050611b13565b508115611bb15760405163e22e27eb60e01b8152600481018690526024810185905260440161061e565b949350505050565b5f60208284031215611bc9575f5ffd5b5035919050565b5f5f83601f840112611be0575f5ffd5b5081356001600160401b03811115611bf6575f5ffd5b6020830191508360208260061b8501011115611c10575f5ffd5b9250929050565b5f5f5f60408486031215611c29575f5ffd5b8335925060208401356001600160401b03811115611c45575f5ffd5b611c5186828701611bd0565b9497909650939450505050565b80356001600160a01b0381168114611c74575f5ffd5b919050565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f191681016001600160401b0381118282101715611cb557611cb5611c79565b604052919050565b5f6001600160401b03821115611cd557611cd5611c79565b50601f01601f191660200190565b5f82601f830112611cf2575f5ffd5b8135611d05611d0082611cbd565b611c8d565b818152846020838601011115611d19575f5ffd5b816020850160208301375f918101602001919091529392505050565b5f5f5f5f5f5f60808789031215611d4a575f5ffd5b611d5387611c5e565b955060208701356001600160401b03811115611d6d575f5ffd5b8701601f81018913611d7d575f5ffd5b80356001600160401b03811115611d92575f5ffd5b8960208260051b8401011115611da6575f5ffd5b6020919091019550935060408701356001600160401b03811115611dc8575f5ffd5b611dd489828a01611ce3565b93505060608701356001600160401b03811115611def575f5ffd5b611dfb89828a01611bd0565b979a9699509497509295939492505050565b5f5b83811015611e27578181015183820152602001611e0f565b50505f910152565b602081525f8251806020840152611e4d816040850160208701611e0d565b601f01601f19169190910160400192915050565b5f5f5f8385036080811215611e74575f5ffd5b611e7d85611c5e565b935060208501356001600160401b03811115611e97575f5ffd5b611ea387828801611ce3565b9350506040603f1982011215611eb7575f5ffd5b506040840190509250925092565b5f60208284031215611ed5575f5ffd5b611ede82611c5e565b9392505050565b5f5f60408385031215611ef6575f5ffd5b82356001600160401b03811115611f0b575f5ffd5b611f1785828601611ce3565b925050611f2660208401611c5e565b90509250929050565b5f60208284031215611f3f575f5ffd5b81356001600160601b031981168114611ede575f5ffd5b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b8181038181111561141e5761141e611f6a565b600181811c90821680611fa557607f821691505b60208210810361190657634e487b7160e01b5f52602260045260245ffd5b5f8154611fcf81611f91565b600182168015611fe65760018114611ffb57612028565b60ff1983168652811515820286019350612028565b845f5260205f205f5b8381101561202057815488820152600190910190602001612004565b505081860193505b50505092915050565b5f61203c8286611fc3565b845161204c818360208901611e0d565b845191019061205f818360208801611e0d565b0195945050505050565b5f5f8335601e1984360301811261207e575f5ffd5b8301803591506001600160401b03821115612097575f5ffd5b602001915036819003821315611c10575f5ffd5b5f6120b68285611fc3565b83516120c6818360208801611e0d565b01949350505050565b5f82516120e0818460208701611e0d565b9190910192915050565b5f602082840312156120fa575f5ffd5b5051919050565b8082018082111561141e5761141e611f6a565b5f60208284031215612124575f5ffd5b81516001600160401b03811115612139575f5ffd5b8201601f81018413612149575f5ffd5b8051612157611d0082611cbd565b81815285602083850101111561216b575f5ffd5b61217c826020830160208601611e0d565b95945050505050565b5f8351612196818460208801611e0d565b61217c81840185611fc3565b601f8211156121e657805f5260205f20601f840160051c810160208510156121c75750805b601f840160051c820191505b81811015610bbf575f81556001016121d3565b505050565b81516001600160401b0381111561220457612204611c79565b612218816122128454611f91565b846121a2565b6020601f82116001811461224a575f83156122335750848201515b5f19600385901b1c1916600184901b178455610bbf565b5f84815260208120601f198516915b828110156122795787850151825560209485019460019092019101612259565b508482101561229657868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b5f816122b3576122b3611f6a565b505f190190565b60ff60f81b8360f81b1681525f82516122da816001850160208701611e0d565b919091016001019392505050565b5f83516122f9818460208801611e0d565b8351908301906120c6818360208801611e0d565b60ff828116828216039081111561141e5761141e611f6a565b5f60208284031215612336575f5ffd5b81518015158114611ede575f5ffd5b5f8261235f57634e487b7160e01b5f52601260045260245ffd5b500690565b808202811582820484141761141e5761141e611f6a56fea2646970667358221220cfeae0fdebe1bd8ad16e8001d0364f949dbe2b0879dc68c85071fc5866fabf0864736f6c634300081b003360806040525f805460ff60a01b1916600160a11b179055348015610021575f5ffd5b50604051610cbb380380610cbb833981016040819052610040916101c8565b338061006557604051631e4fbdf760e01b81525f600482015260240160405180910390fd5b61006e8161008a565b50610078836100e5565b610082828261012e565b505050610207565b5f8054600160a01b900460ff1690036100b657604051638863b38f60e01b815260040160405180910390fd5b5f80545f1960ff600160a01b808404821692909201160260ff60a01b199091161790556100e281610179565b50565b6001600160a01b03811661010c5760405163c387fe1560e01b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b805f0361014e57604051638ea90cbf60e01b815260040160405180910390fd5b815f0361016e57604051637e44c36f60e11b815260040160405180910390fd5b600591909155600655565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f5f5f606084860312156101da575f5ffd5b83516001600160a01b03811681146101f0575f5ffd5b602085015160409095015190969495509392505050565b610aa7806102145f395ff3fe608060405234801561000f575f5ffd5b50600436106100f0575f3560e01c8063ae92e61c11610093578063e6fd48bc11610063578063e6fd48bc146101b0578063f2fde38b146101b9578063f9140f7f146101cc578063fc0c546a146101d5575f5ffd5b8063ae92e61c14610179578063c29a6fda14610182578063dc07065714610195578063deb36e32146101a8575f5ffd5b80634e71d92d116100ce5780634e71d92d14610144578063692d36a71461014e578063715018a6146101615780638da5cb5b14610169575f5ffd5b806338af3eed146100f45780633be283e9146101245780633f69cb001461013b575b5f5ffd5b600254610107906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b61012d60065481565b60405190815260200161011b565b61012d60075481565b61014c6101e8565b005b61014c61015c36600461097e565b610435565b61014c61054e565b5f546001600160a01b0316610107565b61012d60035481565b61014c61019036600461099e565b610561565b61014c6101a336600461099e565b61060b565b61014c6106bf565b61012d60045481565b61014c6101c736600461099e565b6107bc565b61012d60055481565b600154610107906001600160a01b031681565b6001546001600160a01b031661021157604051637bbede1f60e11b815260040160405180910390fd5b6004545f036102335760405163641c0b2160e11b815260040160405180910390fd5b600654600754036102575760405163275d416d60e21b815260040160405180910390fd5b5f60055460075460055461026b91906109df565b60045461027891906109f6565b6102829042610a09565b61028c9190610a1c565b9050805f036102ae576040516312d37ee560e31b815260040160405180910390fd5b5f6102c86007546006546102c29190610a09565b836107fe565b90508060075f8282546102db91906109f6565b925050819055505f6006546007541015610303576003546102fc90836109df565b9050610370565b6001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610349573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061036d9190610a3b565b90505b600254604080518381524260208201526001600160a01b039092169133917f2f6639d24651730c7bf57c95ddbf96d66d11477e4ec626876f92c22e5f365e68910160405180910390a360015460025460405163a9059cbb60e01b81526001600160a01b0391821660048201526024810184905291169063a9059cbb906044016020604051808303815f875af115801561040b573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061042f9190610a52565b50505050565b61043d610817565b6006546007540361046157604051635ee8231160e01b815260040160405180910390fd5b6005546006546104718484610843565b60045415610500576001546040516370a0823160e01b81523060048201525f916001600160a01b0316906370a0823190602401602060405180830381865afa1580156104bf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104e39190610a3b565b9050600654816104f39190610a1c565b60035550426004555f6007555b6040805185815260208101859052908101839052606081018290527f9cef914ceeeeda20f16e41daa8acec1596a28a6ade3a2052ef13ed94beee928e9060800160405180910390a150505050565b610556610817565b61055f5f61088e565b565b610569610817565b6001546001600160a01b03161561059357604051635ee8231160e01b815260040160405180910390fd5b6001600160a01b0381166105ba5760405163c387fe1560e01b815260040160405180910390fd5b6002546001600160a01b03908116908216036105e9576040516399d8ae3360e01b815260040160405180910390fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b610613610817565b6006546007540361063757604051635ee8231160e01b815260040160405180910390fd5b6001546001600160a01b0390811690821603610666576040516399d8ae3360e01b815260040160405180910390fd5b6002546001600160a01b031661067b826108e6565b806001600160a01b0316826001600160a01b03167f948b7fd6001c5a82456f922e394fd549fed19d11220898d726ffb430fb951e9460405160405180910390a35050565b6001546001600160a01b031633146106ea57604051635ee8231160e01b815260040160405180910390fd5b6003541515806106fb575060045415155b15610719576040516372de7acd60e01b815260040160405180910390fd5b6001546040516370a0823160e01b81523060048201525f916001600160a01b0316906370a0823190602401602060405180830381865afa15801561075f573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107839190610a3b565b9050805f036107a5576040516346f1397d60e01b815260040160405180910390fd5b6006546107b29082610a1c565b6003555042600455565b6107c4610817565b6001600160a01b0381166107f257604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b6107fb8161088e565b50565b5f81831061080c578161080e565b825b90505b92915050565b5f546001600160a01b0316331461055f5760405163118cdaa760e01b81523360048201526024016107e9565b805f0361086357604051638ea90cbf60e01b815260040160405180910390fd5b815f0361088357604051637e44c36f60e11b815260040160405180910390fd5b600591909155600655565b5f8054600160a01b900460ff1690036108ba57604051638863b38f60e01b815260040160405180910390fd5b5f80545f1960ff600160a01b808404821692909201160260ff60a01b199091161790556107fb8161092f565b6001600160a01b03811661090d5760405163c387fe1560e01b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f5f6040838503121561098f575f5ffd5b50508035926020909101359150565b5f602082840312156109ae575f5ffd5b81356001600160a01b03811681146109c4575f5ffd5b9392505050565b634e487b7160e01b5f52601160045260245ffd5b8082028115828204841417610811576108116109cb565b80820180821115610811576108116109cb565b81810381811115610811576108116109cb565b5f82610a3657634e487b7160e01b5f52601260045260245ffd5b500490565b5f60208284031215610a4b575f5ffd5b5051919050565b5f60208284031215610a62575f5ffd5b815180151581146109c4575f5ffdfea2646970667358221220fccf81d5a305b940bce8c44664ab7f722df15f3a5d052b6052931731beafd33964736f6c634300081b003360e060405234801561000f575f5ffd5b5060405161125438038061125483398101604081905261002e916102f5565b610044670de0b6b3a76400006301406f40610399565b868660036100528382610446565b50600461005f8282610446565b505050805f036100895760405163392e1e2760e01b81525f60048201526024015b60405180910390fd5b6080526001600160a01b0384166100d857604051630e02d8f560e31b815260206004820152601260248201527117d95bdb909858dadd5c10dbdb9d1c9858dd60721b6044820152606401610080565b6001600160a01b03831661012f57604051630e02d8f560e31b815260206004820152601360248201527f5f7a656e644261636b7570436f6e7472616374000000000000000000000000006044820152606401610080565b6001600160a01b03821661018657604051630e02d8f560e31b815260206004820152601860248201527f5f686f72697a656e466f756e646174696f6e56657374656400000000000000006044820152606401610080565b6001600160a01b0381166101d157604051630e02d8f560e31b815260206004820152601160248201527017da1bdc9a5e995b91185bd5995cdd1959607a1b6044820152606401610080565b6001600160a01b039384165f90815260056020526040808220805460ff1990811660019081179092559587168352912080548516909117905560068054909316600217909255821660a0521660c052506105009050565b634e487b7160e01b5f52604160045260245ffd5b5f82601f83011261024b575f5ffd5b81516001600160401b0381111561026457610264610228565b604051601f8201601f19908116603f011681016001600160401b038111828210171561029257610292610228565b6040528181528382016020018510156102a9575f5ffd5b5f5b828110156102c7576020818601810151838301820152016102ab565b505f918101602001919091529392505050565b80516001600160a01b03811681146102f0575f5ffd5b919050565b5f5f5f5f5f5f60c0878903121561030a575f5ffd5b86516001600160401b0381111561031f575f5ffd5b61032b89828a0161023c565b602089015190975090506001600160401b03811115610348575f5ffd5b61035489828a0161023c565b955050610363604088016102da565b9350610371606088016102da565b925061037f608088016102da565b915061038d60a088016102da565b90509295509295509295565b80820281158282048414176103bc57634e487b7160e01b5f52601160045260245ffd5b92915050565b600181811c908216806103d657607f821691505b6020821081036103f457634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111561044157805f5260205f20601f840160051c8101602085101561041f5750805b601f840160051c820191505b8181101561043e575f815560010161042b565b50505b505050565b81516001600160401b0381111561045f5761045f610228565b6104738161046d84546103c2565b846103fa565b6020601f8211600181146104a5575f831561048e5750848201515b5f19600385901b1c1916600184901b17845561043e565b5f84815260208120601f198516915b828110156104d457878501518255602094850194600190920191016104b4565b50848210156104f157868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b60805160a05160c051610cf26105625f395f818161023e0152818161059d0152818161062601526106bf01525f81816101ff015281816104e10152818161056a015261065101525f81816101810152818161045b015261095e0152610cf25ff3fe608060405234801561000f575f5ffd5b5060043610610106575f3560e01c806375252b261161009e5780638a2545161161006e5780638a2545161461023957806395d89b4114610260578063a9059cbb14610268578063dd62ed3e1461027b578063f46eccc4146102b3575f5ffd5b806375252b26146101e25780637986eb0b146101ea5780637c745afb146101f2578063867e3036146101fa575f5ffd5b8063313ce567116100d9578063313ce56714610170578063355274ea1461017f57806340c10f19146101a557806370a08231146101ba575f5ffd5b806306fdde031461010a578063095ea7b31461012857806318160ddd1461014b57806323b872dd1461015d575b5f5ffd5b6101126102d5565b60405161011f9190610ad6565b60405180910390f35b61013b610136366004610b38565b610365565b604051901515815260200161011f565b6002545b60405190815260200161011f565b61013b61016b366004610b62565b61037e565b6040516012815260200161011f565b7f000000000000000000000000000000000000000000000000000000000000000061014f565b6101b86101b3366004610b38565b6103a1565b005b61014f6101c8366004610ba0565b6001600160a01b03165f9081526020819052604090205490565b61014f603c81565b6101b86103e5565b61014f601981565b6102217f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161011f565b6102217f000000000000000000000000000000000000000000000000000000000000000081565b610112610733565b61013b610276366004610b38565b610742565b61014f610289366004610bc2565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b61013b6102c1366004610ba0565b60056020525f908152604090205460ff1681565b6060600380546102e490610bf9565b80601f016020809104026020016040519081016040528092919081815260200182805461031090610bf9565b801561035b5780601f106103325761010080835404028352916020019161035b565b820191905f5260205f20905b81548152906001019060200180831161033e57829003601f168201915b5050505050905090565b5f3361037281858561074f565b60019150505b92915050565b5f3361038b858285610761565b6103968585856107dd565b506001949350505050565b335f9081526005602052604090205460ff166103d757604051632fdab94f60e11b81523360048201526024015b60405180910390fd5b6103e1828261083a565b5050565b335f9081526005602052604090205460ff1661041657604051632fdab94f60e11b81523360048201526024016103ce565b335f908152600560205260408120805460ff19908116909155600680545f1960ff82811691909101169216821790559003610731575f61045560025490565b61047f907f0000000000000000000000000000000000000000000000000000000000000000610c45565b90505f606461048f603c84610c58565b6104999190610c6f565b90505f6104a68284610c45565b90505f60646104b6601985610c58565b6104c09190610c6f565b90505f60646104d0601985610c58565b6104da9190610c6f565b90506105657f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166338af3eed6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561053b573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061055f9190610c8e565b8261083a565b6105987f00000000000000000000000000000000000000000000000000000000000000006105938386610c45565b61083a565b6106217f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166338af3eed6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105f7573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061061b9190610c8e565b8361083a565b61064f7f00000000000000000000000000000000000000000000000000000000000000006105938487610c45565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663deb36e326040518163ffffffff1660e01b81526004015f604051808303815f87803b1580156106a7575f5ffd5b505af11580156106b9573d5f5f3e3d5ffd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663deb36e326040518163ffffffff1660e01b81526004015f604051808303815f87803b158015610715575f5ffd5b505af1158015610727573d5f5f3e3d5ffd5b5050505050505050505b565b6060600480546102e490610bf9565b5f336103728185856107dd565b61075c838383600161086e565b505050565b6001600160a01b038381165f908152600160209081526040808320938616835292905220545f198110156107d757818110156107c957604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064016103ce565b6107d784848484035f61086e565b50505050565b6001600160a01b03831661080657604051634b637e8f60e11b81525f60048201526024016103ce565b6001600160a01b03821661082f5760405163ec442f0560e01b81525f60048201526024016103ce565b61075c838383610940565b6001600160a01b0382166108635760405163ec442f0560e01b81525f60048201526024016103ce565b6103e15f8383610940565b6001600160a01b0384166108975760405163e602df0560e01b81525f60048201526024016103ce565b6001600160a01b0383166108c057604051634a1406b160e11b81525f60048201526024016103ce565b6001600160a01b038085165f90815260016020908152604080832093871683529290522082905580156107d757826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161093291815260200190565b60405180910390a350505050565b61094b8383836109b0565b6001600160a01b03831661075c576002547f000000000000000000000000000000000000000000000000000000000000000090818111156109a95760405163279e7e1560e21b815260048101829052602481018390526044016103ce565b5050505050565b6001600160a01b0383166109da578060025f8282546109cf9190610ca9565b90915550610a4a9050565b6001600160a01b0383165f9081526020819052604090205481811015610a2c5760405163391434e360e21b81526001600160a01b038516600482015260248101829052604481018390526064016103ce565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b038216610a6657600280548290039055610a84565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051610ac991815260200190565b60405180910390a3505050565b602081525f82518060208401525f5b81811015610b025760208186018101516040868401015201610ae5565b505f604082850101526040601f19601f83011684010191505092915050565b6001600160a01b0381168114610b35575f5ffd5b50565b5f5f60408385031215610b49575f5ffd5b8235610b5481610b21565b946020939093013593505050565b5f5f5f60608486031215610b74575f5ffd5b8335610b7f81610b21565b92506020840135610b8f81610b21565b929592945050506040919091013590565b5f60208284031215610bb0575f5ffd5b8135610bbb81610b21565b9392505050565b5f5f60408385031215610bd3575f5ffd5b8235610bde81610b21565b91506020830135610bee81610b21565b809150509250929050565b600181811c90821680610c0d57607f821691505b602082108103610c2b57634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52601160045260245ffd5b8181038181111561037857610378610c31565b808202811582820484141761037857610378610c31565b5f82610c8957634e487b7160e01b5f52601260045260245ffd5b500490565b5f60208284031215610c9e575f5ffd5b8151610bbb81610b21565b8082018082111561037857610378610c3156fea2646970667358221220db3b20861bef87be0d07273f9aaf0cab87e2a74a95141c3d82455a325752ab8964736f6c634300081b0033a264697066735822122022f022eee3d136553ecdcb1ce8062d5b9c17ac4740d305c5bbf1c12f674dfa5a64736f6c634300081b0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000004053aeaa16c5c81511e2b38eb3cd3594ad98c755
-----Decoded View---------------
Arg [0] : _admin (address): 0x4053AEAa16c5c81511E2B38eb3cd3594AD98c755
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000004053aeaa16c5c81511e2b38eb3cd3594ad98c755
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.