Source Code
Overview
ETH Balance
0 ETH
More Info
ContractCreator
Multichain Info
N/A
Latest 25 from a total of 1,013 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
Amount
|
||||
|---|---|---|---|---|---|---|---|---|---|
| Redeem Delegatio... | 9777287 | 27 hrs ago | IN | 0 ETH | 0.00000022 | ||||
| Redeem Delegatio... | 9776977 | 28 hrs ago | IN | 0 ETH | 0.00000009 | ||||
| Redeem Delegatio... | 9776953 | 28 hrs ago | IN | 0 ETH | 0.00000014 | ||||
| Redeem Delegatio... | 9776843 | 28 hrs ago | IN | 0 ETH | 0.00000009 | ||||
| Redeem Delegatio... | 9776841 | 28 hrs ago | IN | 0 ETH | 0.00000015 | ||||
| Redeem Delegatio... | 9776791 | 29 hrs ago | IN | 0 ETH | 0.00000009 | ||||
| Redeem Delegatio... | 9776788 | 29 hrs ago | IN | 0 ETH | 0.00000014 | ||||
| Redeem Delegatio... | 9776753 | 29 hrs ago | IN | 0 ETH | 0.00000008 | ||||
| Redeem Delegatio... | 9776601 | 29 hrs ago | IN | 0 ETH | 0.00000006 | ||||
| Redeem Delegatio... | 9776465 | 30 hrs ago | IN | 0 ETH | 0.00000006 | ||||
| Redeem Delegatio... | 9776322 | 30 hrs ago | IN | 0 ETH | 0.00000006 | ||||
| Redeem Delegatio... | 9776291 | 30 hrs ago | IN | 0 ETH | 0.00000006 | ||||
| Redeem Delegatio... | 9776085 | 31 hrs ago | IN | 0 ETH | 0.00000007 | ||||
| Redeem Delegatio... | 9776037 | 31 hrs ago | IN | 0 ETH | 0.00000005 | ||||
| Redeem Delegatio... | 9776028 | 31 hrs ago | IN | 0 ETH | 0.00000005 | ||||
| Redeem Delegatio... | 9776006 | 31 hrs ago | IN | 0 ETH | 0.00000012 | ||||
| Redeem Delegatio... | 9775962 | 31 hrs ago | IN | 0 ETH | 0.00000007 | ||||
| Redeem Delegatio... | 9775937 | 32 hrs ago | IN | 0 ETH | 0.00000007 | ||||
| Redeem Delegatio... | 9775821 | 32 hrs ago | IN | 0 ETH | 0.00000006 | ||||
| Redeem Delegatio... | 9775815 | 32 hrs ago | IN | 0 ETH | 0.00000006 | ||||
| Redeem Delegatio... | 9775759 | 32 hrs ago | IN | 0 ETH | 0.00000008 | ||||
| Redeem Delegatio... | 9775744 | 32 hrs ago | IN | 0 ETH | 0 | ||||
| Redeem Delegatio... | 9775727 | 32 hrs ago | IN | 0 ETH | 0 | ||||
| Redeem Delegatio... | 9775717 | 32 hrs ago | IN | 0 ETH | 0 | ||||
| Redeem Delegatio... | 9775705 | 32 hrs ago | IN | 0 ETH | 0.00000006 |
Latest 1 internal transaction
Advanced mode:
| Parent Transaction Hash | Method | Block |
From
|
To
|
Amount
|
||
|---|---|---|---|---|---|---|---|
| 0x61016060 | 7996571 | 253 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
DelegationManager
Compiler Version
v0.8.23+commit.f704f362
Optimization Enabled:
Yes with 200 runs
Other Settings:
london EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT AND Apache-2.0
pragma solidity 0.8.23;
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { Ownable2Step, Ownable } from "@openzeppelin/contracts/access/Ownable2Step.sol";
import { IERC1271 } from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import { Pausable } from "@openzeppelin/contracts/utils/Pausable.sol";
import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import { ICaveatEnforcer } from "./interfaces/ICaveatEnforcer.sol";
import { IDelegationManager } from "./interfaces/IDelegationManager.sol";
import { IDeleGatorCore } from "./interfaces/IDeleGatorCore.sol";
import { Delegation, Caveat, ModeCode } from "./utils/Types.sol";
import { EncoderLib } from "./libraries/EncoderLib.sol";
import { ERC1271Lib } from "./libraries/ERC1271Lib.sol";
/**
* @title DelegationManager
* @notice This contract is used to manage delegations.
* Delegations can be validated and executed through this contract.
*/
contract DelegationManager is IDelegationManager, Ownable2Step, Pausable, EIP712 {
using MessageHashUtils for bytes32;
////////////////////////////// State //////////////////////////////
/// @dev The name of the contract
string public constant NAME = "DelegationManager";
/// @dev The full version of the contract
string public constant VERSION = "1.3.0";
/// @dev The version used in the domainSeparator for EIP712
string public constant DOMAIN_VERSION = "1";
/// @dev Special authority value. Indicates that the delegator is the authority
bytes32 public constant ROOT_AUTHORITY = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
/// @dev Special delegate value. Allows any delegate to redeem the delegation
address public constant ANY_DELEGATE = address(0xa11);
/// @dev A mapping of delegation hashes that have been disabled by the delegator
mapping(bytes32 delegationHash => bool isDisabled) public disabledDelegations;
////////////////////////////// Modifier //////////////////////////////
/**
* @notice Require the caller to be the delegator
* This is to prevent others from accessing protected methods.
* @dev Check that the caller is delegator.
*/
modifier onlyDeleGator(address delegator) {
if (delegator != msg.sender) revert InvalidDelegator();
_;
}
////////////////////////////// Constructor //////////////////////////////
/**
* @notice Initializes Ownable and the DelegationManager's state
* @param _owner The initial owner of the contract
*/
constructor(address _owner) Ownable(_owner) EIP712(NAME, DOMAIN_VERSION) {
bytes32 DOMAIN_HASH = _domainSeparatorV4();
emit SetDomain(DOMAIN_HASH, NAME, DOMAIN_VERSION, block.chainid, address(this));
}
////////////////////////////// External Methods //////////////////////////////
/**
* @notice Allows the owner of the DelegationManager to pause delegation redemption functionality
*/
function pause() external onlyOwner {
_pause();
}
/**
* @notice Allows the owner of the DelegationManager to unpause the delegation redemption functionality
*/
function unpause() external onlyOwner {
_unpause();
}
/**
* @notice This method is used to disable a delegation. Disabled delegations will fail upon redemption.
* @dev This method MUST be called by the delegator
* @param _delegation The delegation to be disabled
*/
function disableDelegation(Delegation calldata _delegation) external onlyDeleGator(_delegation.delegator) {
bytes32 delegationHash_ = getDelegationHash(_delegation);
if (disabledDelegations[delegationHash_]) revert AlreadyDisabled();
disabledDelegations[delegationHash_] = true;
emit DisabledDelegation(delegationHash_, _delegation.delegator, _delegation.delegate, _delegation);
}
/**
* @notice This method is used to enable a delegation
* @dev This method MUST be called by the delegator
* @dev This method is only needed when a delegation has previously been disabled
* @param _delegation The delegation to be disabled
*/
function enableDelegation(Delegation calldata _delegation) external onlyDeleGator(_delegation.delegator) {
bytes32 delegationHash_ = getDelegationHash(_delegation);
if (!disabledDelegations[delegationHash_]) revert AlreadyEnabled();
disabledDelegations[delegationHash_] = false;
emit EnabledDelegation(delegationHash_, _delegation.delegator, _delegation.delegate, _delegation);
}
/**
* @notice Validates permission contexts and executes batch actions if the caller is authorized.
* @dev For each execution in the batch:
* - Calls `beforeAllHook` before any actions begin.
* - For each delegation, calls `beforeHook` before its execution.
* - Executes the call data.
* - For each delegation, calls `afterHook` after execution.
* - Calls `afterAllHook` after all actions are completed.
* If any hook fails, the entire transaction reverts.
*
* @dev The lengths of `_permissionContexts`, `_modes`, and `_executionCallDatas` must be equal.
* @param _permissionContexts An array where each element is an array of `Delegation` structs used for
* authority validation ordered from leaf to root. An empty entry denotes self-authorization.
* @param _modes An array specifying modes to execute the corresponding `_executionCallDatas`.
* @param _executionCallDatas An array of encoded actions to be executed.
*/
function redeemDelegations(
bytes[] calldata _permissionContexts,
ModeCode[] calldata _modes,
bytes[] calldata _executionCallDatas
)
external
whenNotPaused
{
uint256 batchSize_ = _permissionContexts.length;
if (batchSize_ != _executionCallDatas.length || batchSize_ != _modes.length) revert BatchDataLengthMismatch();
Delegation[][] memory batchDelegations_ = new Delegation[][](batchSize_);
bytes32[][] memory batchDelegationHashes_ = new bytes32[][](batchSize_);
// Validate and process delegations for each execution
for (uint256 batchIndex_; batchIndex_ < batchSize_; ++batchIndex_) {
Delegation[] memory delegations_ = abi.decode(_permissionContexts[batchIndex_], (Delegation[]));
if (delegations_.length == 0) {
// Special case: If the permissionContext is empty, treat it as a self authorized execution
batchDelegations_[batchIndex_] = new Delegation[](0);
batchDelegationHashes_[batchIndex_] = new bytes32[](0);
} else {
batchDelegations_[batchIndex_] = delegations_;
// Load delegation hashes and validate signatures (leaf to root)
bytes32[] memory delegationHashes_ = new bytes32[](delegations_.length);
batchDelegationHashes_[batchIndex_] = delegationHashes_;
// Validate caller
if (delegations_[0].delegate != msg.sender && delegations_[0].delegate != ANY_DELEGATE) {
revert InvalidDelegate();
}
for (uint256 delegationsIndex_; delegationsIndex_ < delegations_.length; ++delegationsIndex_) {
Delegation memory delegation_ = delegations_[delegationsIndex_];
delegationHashes_[delegationsIndex_] = EncoderLib._getDelegationHash(delegation_);
if (delegation_.delegator.code.length == 0) {
// Validate delegation if it's an EOA
address result_ = ECDSA.recover(
MessageHashUtils.toTypedDataHash(getDomainHash(), delegationHashes_[delegationsIndex_]),
delegation_.signature
);
if (result_ != delegation_.delegator) revert InvalidEOASignature();
} else {
// Validate delegation if it's a contract
bytes32 typedDataHash_ =
MessageHashUtils.toTypedDataHash(getDomainHash(), delegationHashes_[delegationsIndex_]);
bytes32 result_ = IERC1271(delegation_.delegator).isValidSignature(typedDataHash_, delegation_.signature);
if (result_ != ERC1271Lib.EIP1271_MAGIC_VALUE) {
revert InvalidERC1271Signature();
}
}
}
// Validate authority and delegate (leaf to root)
for (uint256 delegationsIndex_; delegationsIndex_ < delegations_.length; ++delegationsIndex_) {
// Validate if delegation is disabled
if (disabledDelegations[delegationHashes_[delegationsIndex_]]) {
revert CannotUseADisabledDelegation();
}
// Validate authority
if (delegationsIndex_ != delegations_.length - 1) {
if (delegations_[delegationsIndex_].authority != delegationHashes_[delegationsIndex_ + 1]) {
revert InvalidAuthority();
}
// Validate delegate
address nextDelegate_ = delegations_[delegationsIndex_ + 1].delegate;
if (nextDelegate_ != ANY_DELEGATE && delegations_[delegationsIndex_].delegator != nextDelegate_) {
revert InvalidDelegate();
}
} else if (delegations_[delegationsIndex_].authority != ROOT_AUTHORITY) {
revert InvalidAuthority();
}
}
}
}
// beforeAllHook (leaf to root)
for (uint256 batchIndex_; batchIndex_ < batchSize_; ++batchIndex_) {
if (batchDelegations_[batchIndex_].length > 0) {
// Execute beforeAllHooks
for (uint256 delegationsIndex_; delegationsIndex_ < batchDelegations_[batchIndex_].length; ++delegationsIndex_) {
Caveat[] memory caveats_ = batchDelegations_[batchIndex_][delegationsIndex_].caveats;
for (uint256 caveatsIndex_; caveatsIndex_ < caveats_.length; ++caveatsIndex_) {
ICaveatEnforcer enforcer_ = ICaveatEnforcer(caveats_[caveatsIndex_].enforcer);
enforcer_.beforeAllHook(
caveats_[caveatsIndex_].terms,
caveats_[caveatsIndex_].args,
_modes[batchIndex_],
_executionCallDatas[batchIndex_],
batchDelegationHashes_[batchIndex_][delegationsIndex_],
batchDelegations_[batchIndex_][delegationsIndex_].delegator,
msg.sender
);
}
}
}
}
for (uint256 batchIndex_; batchIndex_ < batchSize_; ++batchIndex_) {
if (batchDelegations_[batchIndex_].length == 0) {
// Special case: If there are no delegations, defer the call to the caller.
IDeleGatorCore(msg.sender).executeFromExecutor(_modes[batchIndex_], _executionCallDatas[batchIndex_]);
} else {
// Execute beforeHooks
for (uint256 delegationsIndex_; delegationsIndex_ < batchDelegations_[batchIndex_].length; ++delegationsIndex_) {
Caveat[] memory caveats_ = batchDelegations_[batchIndex_][delegationsIndex_].caveats;
for (uint256 caveatsIndex_; caveatsIndex_ < caveats_.length; ++caveatsIndex_) {
ICaveatEnforcer enforcer_ = ICaveatEnforcer(caveats_[caveatsIndex_].enforcer);
enforcer_.beforeHook(
caveats_[caveatsIndex_].terms,
caveats_[caveatsIndex_].args,
_modes[batchIndex_],
_executionCallDatas[batchIndex_],
batchDelegationHashes_[batchIndex_][delegationsIndex_],
batchDelegations_[batchIndex_][delegationsIndex_].delegator,
msg.sender
);
}
}
// Perform execution
IDeleGatorCore(batchDelegations_[batchIndex_][batchDelegations_[batchIndex_].length - 1].delegator)
.executeFromExecutor(_modes[batchIndex_], _executionCallDatas[batchIndex_]);
// Execute afterHooks
for (uint256 delegationsIndex_ = batchDelegations_[batchIndex_].length; delegationsIndex_ > 0; --delegationsIndex_)
{
Caveat[] memory caveats_ = batchDelegations_[batchIndex_][delegationsIndex_ - 1].caveats;
for (uint256 caveatsIndex_ = caveats_.length; caveatsIndex_ > 0; --caveatsIndex_) {
ICaveatEnforcer enforcer_ = ICaveatEnforcer(caveats_[caveatsIndex_ - 1].enforcer);
enforcer_.afterHook(
caveats_[caveatsIndex_ - 1].terms,
caveats_[caveatsIndex_ - 1].args,
_modes[batchIndex_],
_executionCallDatas[batchIndex_],
batchDelegationHashes_[batchIndex_][delegationsIndex_ - 1],
batchDelegations_[batchIndex_][delegationsIndex_ - 1].delegator,
msg.sender
);
}
}
}
}
// afterAllHook (root to leaf)
for (uint256 batchIndex_; batchIndex_ < batchSize_; ++batchIndex_) {
if (batchDelegations_[batchIndex_].length > 0) {
// Execute afterAllHooks
for (uint256 delegationsIndex_ = batchDelegations_[batchIndex_].length; delegationsIndex_ > 0; --delegationsIndex_)
{
Caveat[] memory caveats_ = batchDelegations_[batchIndex_][delegationsIndex_ - 1].caveats;
for (uint256 caveatsIndex_ = caveats_.length; caveatsIndex_ > 0; --caveatsIndex_) {
ICaveatEnforcer enforcer_ = ICaveatEnforcer(caveats_[caveatsIndex_ - 1].enforcer);
enforcer_.afterAllHook(
caveats_[caveatsIndex_ - 1].terms,
caveats_[caveatsIndex_ - 1].args,
_modes[batchIndex_],
_executionCallDatas[batchIndex_],
batchDelegationHashes_[batchIndex_][delegationsIndex_ - 1],
batchDelegations_[batchIndex_][delegationsIndex_ - 1].delegator,
msg.sender
);
}
}
}
}
for (uint256 batchIndex_; batchIndex_ < batchSize_; ++batchIndex_) {
if (batchDelegations_[batchIndex_].length > 0) {
for (uint256 delegationsIndex_; delegationsIndex_ < batchDelegations_[batchIndex_].length; ++delegationsIndex_) {
emit RedeemedDelegation(
batchDelegations_[batchIndex_][batchDelegations_[batchIndex_].length - 1].delegator,
msg.sender,
batchDelegations_[batchIndex_][delegationsIndex_]
);
}
}
}
}
/**
* @notice This method returns the domain hash used for signing typed data
* @return bytes32 The domain hash
*/
function getDomainHash() public view returns (bytes32) {
return _domainSeparatorV4();
}
/**
* @notice Creates a hash of a Delegation
* @dev Used in EIP712 signatures and as a key for enabling and disabling delegations
* @param _input A Delegation struct
*/
function getDelegationHash(Delegation calldata _input) public pure returns (bytes32) {
return EncoderLib._getDelegationHash(_input);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)
pragma solidity ^0.8.20;
import {Strings} from "../Strings.sol";
/**
* @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
*
* The library provides methods for generating a hash of a message that conforms to the
* https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
* specifications.
*/
library MessageHashUtils {
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing a bytes32 `messageHash` with
* `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
* keccak256, although any bytes32 value can be safely used because the final digest will
* be re-hashed.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
}
}
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing an arbitrary `message` with
* `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
return
keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
}
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x00` (data with intended validator).
*
* The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
* `validator` address. Then hashing the result.
*
* See {ECDSA-recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(hex"19_00", validator, data));
}
/**
* @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).
*
* The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
* `\x19\x01` and hashing the result. It corresponds to the hash signed by the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
*
* See {ECDSA-recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, hex"19_01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
digest := keccak256(ptr, 0x42)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures]
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError, bytes32) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This extension of the {Ownable} contract includes a two-step mechanism to transfer
* ownership, where the new owner must call {acceptOwnership} in order to replace the
* old one. This can help prevent common mistakes, such as transfers of ownership to
* incorrect accounts, or to contracts that are unable to interact with the
* permission system.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1271.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-1271 standard signature validation method for
* contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
*/
interface IERC1271 {
/**
* @dev Should return whether the signature provided is valid for the provided data
* @param hash Hash of the data to be signed
* @param signature Signature byte array associated with _data
*/
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
bool private _paused;
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.20;
import {MessageHashUtils} from "./MessageHashUtils.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {IERC5267} from "../../interfaces/IERC5267.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.
*
* The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
* encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract
* does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to
* produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
* separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
* separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
*
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
abstract contract EIP712 is IERC5267 {
using ShortStrings for *;
bytes32 private constant TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _cachedDomainSeparator;
uint256 private immutable _cachedChainId;
address private immutable _cachedThis;
bytes32 private immutable _hashedName;
bytes32 private immutable _hashedVersion;
ShortString private immutable _name;
ShortString private immutable _version;
string private _nameFallback;
string private _versionFallback;
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
_name = name.toShortStringWithFallback(_nameFallback);
_version = version.toShortStringWithFallback(_versionFallback);
_hashedName = keccak256(bytes(name));
_hashedVersion = keccak256(bytes(version));
_cachedChainId = block.chainid;
_cachedDomainSeparator = _buildDomainSeparator();
_cachedThis = address(this);
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
return _cachedDomainSeparator;
} else {
return _buildDomainSeparator();
}
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
}
/**
* @dev See {IERC-5267}.
*/
function eip712Domain()
public
view
virtual
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)
{
return (
hex"0f", // 01111
_EIP712Name(),
_EIP712Version(),
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}
/**
* @dev The name parameter for the EIP712 domain.
*
* NOTE: By default this function reads _name which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Name() internal view returns (string memory) {
return _name.toStringWithFallback(_nameFallback);
}
/**
* @dev The version parameter for the EIP712 domain.
*
* NOTE: By default this function reads _version which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Version() internal view returns (string memory) {
return _version.toStringWithFallback(_versionFallback);
}
}// SPDX-License-Identifier: MIT AND Apache-2.0
pragma solidity 0.8.23;
import { ModeCode } from "../utils/Types.sol";
/**
* @title CaveatEnforcer
* @notice This is an abstract contract that exposes pre and post Execution hooks during delegation redemption.
* @dev Hooks can be used to enforce conditions before and after an Execution is performed.
* @dev Reverting during the hooks will revert the entire delegation redemption.
* @dev Child contracts can implement the beforeAllHook, beforeHook, afterAllHook, afterHook methods.
* @dev NOTE: There is no guarantee that the Execution is performed. If you are relying on the execution then
* be sure to use the `afterHook` or `afterAllHook` methods to validate any required conditions.
*/
interface ICaveatEnforcer {
/**
* @notice Enforces conditions before any actions in a batch redemption process begin.
* @dev This function MUST revert if the conditions are not met.
* @param _terms The terms to enforce set by the delegator.
* @param _args An optional input parameter set by the redeemer at time of invocation.
* @param _mode The mode of execution for the executionCalldata.
* @param _executionCalldata The data representing the execution.
* @param _delegationHash The hash of the delegation.
* @param _delegator The address of the delegator.
* @param _redeemer The address that is redeeming the delegation.
*/
function beforeAllHook(
bytes calldata _terms,
bytes calldata _args,
ModeCode _mode,
bytes calldata _executionCalldata,
bytes32 _delegationHash,
address _delegator,
address _redeemer
)
external;
/**
* @notice Enforces conditions before the execution tied to a specific delegation in the redemption process.
* @dev This function MUST revert if the conditions are not met.
* @param _terms The terms to enforce set by the delegator.
* @param _args An optional input parameter set by the redeemer at time of invocation.
* @param _mode The mode of execution for the executionCalldata.
* @param _executionCalldata The data representing the execution.
* @param _delegationHash The hash of the delegation.
* @param _delegator The address of the delegator.
* @param _redeemer The address that is redeeming the delegation.
*/
function beforeHook(
bytes calldata _terms,
bytes calldata _args,
ModeCode _mode,
bytes calldata _executionCalldata,
bytes32 _delegationHash,
address _delegator,
address _redeemer
)
external;
/**
* @notice Enforces conditions after the execution tied to a specific delegation in the redemption process.
* @dev This function MUST revert if the conditions are not met.
* @param _terms The terms to enforce set by the delegator.
* @param _args An optional input parameter set by the redeemer at time of invocation.
* @param _mode The mode of execution for the executionCalldata.
* @param _executionCalldata The data representing the execution.
* @param _delegationHash The hash of the delegation.
* @param _delegator The address of the delegator.
* @param _redeemer The address that is redeeming the delegation.
*/
function afterHook(
bytes calldata _terms,
bytes calldata _args,
ModeCode _mode,
bytes calldata _executionCalldata,
bytes32 _delegationHash,
address _delegator,
address _redeemer
)
external;
/**
* @notice Enforces conditions after all actions in a batch redemption process have been executed.
* @dev This function MUST revert if the conditions are not met.
* @param _terms The terms to enforce set by the delegator.
* @param _args An optional input parameter set by the redeemer at time of invocation.
* @param _mode The mode of execution for the executionCalldata.
* @param _executionCalldata The data representing the execution.
* @param _delegationHash The hash of the delegation.
* @param _delegator The address of the delegator.
* @param _redeemer The address that is redeeming the delegation.
*/
function afterAllHook(
bytes calldata _terms,
bytes calldata _args,
ModeCode _mode,
bytes calldata _executionCalldata,
bytes32 _delegationHash,
address _delegator,
address _redeemer
)
external;
}// SPDX-License-Identifier: MIT AND Apache-2.0
pragma solidity 0.8.23;
import { Delegation, Execution, ModeCode } from "../utils/Types.sol";
/**
* @title IDelegationManager
* @notice Interface that exposes methods of a custom DelegationManager implementation.
*/
interface IDelegationManager {
////////////////////////////// Events //////////////////////////////
/// @dev Emitted when a delegation is redeemed
event RedeemedDelegation(address indexed rootDelegator, address indexed redeemer, Delegation delegation);
/// @dev Emitted when a delegation is enabled after being disabled
event EnabledDelegation(
bytes32 indexed delegationHash, address indexed delegator, address indexed delegate, Delegation delegation
);
/// @dev Emitted when a delegation is disabled
event DisabledDelegation(
bytes32 indexed delegationHash, address indexed delegator, address indexed delegate, Delegation delegation
);
/// @dev Emitted when the domain hash is set
event SetDomain(
bytes32 indexed domainHash, string name, string domainVersion, uint256 chainId, address indexed contractAddress
);
////////////////////////////// Errors //////////////////////////////
/// @dev Error thrown when a user attempts to use a disabled delegation
error CannotUseADisabledDelegation();
/// @dev Error thrown when the authority in a chain of delegations doesn't match the expected authority
error InvalidAuthority();
/// @dev Error thrown when the redeemer doesn't match the approved delegate
error InvalidDelegate();
/// @dev Error thrown when the delegator of a delegation doesn't match the caller
error InvalidDelegator();
/// @dev Error thrown when the EOA signature provided is invalid
error InvalidEOASignature();
/// @dev Error thrown when the ERC1271 signature provided is invalid
error InvalidERC1271Signature();
/// @dev Error thrown when the signature is empty
error EmptySignature();
/// @dev Error thrown when the delegation provided is already disabled
error AlreadyDisabled();
/// @dev Error thrown when the delegation provided is already enabled
error AlreadyEnabled();
/// @dev Error thrown when the batch size doesn't match the execution array size
error BatchDataLengthMismatch();
////////////////////////////// MM Implementation Methods //////////////////////////////
function pause() external;
function unpause() external;
function enableDelegation(Delegation calldata _delegation) external;
function disableDelegation(Delegation calldata _delegation) external;
function disabledDelegations(bytes32 _delegationHash) external view returns (bool);
function getDelegationHash(Delegation calldata _delegation) external pure returns (bytes32);
function redeemDelegations(
bytes[] calldata _permissionContexts,
ModeCode[] calldata _modes,
bytes[] calldata _executionCallDatas
)
external;
function getDomainHash() external view returns (bytes32);
}// SPDX-License-Identifier: MIT AND Apache-2.0
pragma solidity 0.8.23;
import { IERC1271 } from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import { ModeCode } from "../utils/Types.sol";
/**
* @title IDeleGatorCore
* @notice Interface for a DeleGator that exposes the minimal functionality required.
*/
interface IDeleGatorCore is IERC1271 {
/**
* @dev Executes a transaction on behalf of the account.
* This function is intended to be called by Executor Modules
* @dev Ensure adequate authorization control: i.e. onlyExecutorModule
* @dev If a mode is requested that is not supported by the Account, it MUST revert
* @dev Related: @erc7579/MSAAdvanced.sol
* @param _mode The encoded execution mode of the transaction. See @erc7579/ModeLib.sol for details.
* @param _executionCalldata The encoded execution call data
*/
function executeFromExecutor(
ModeCode _mode,
bytes calldata _executionCalldata
)
external
payable
returns (bytes[] memory returnData);
}// SPDX-License-Identifier: MIT AND Apache-2.0
pragma solidity 0.8.23;
import { PackedUserOperation } from "@account-abstraction/interfaces/PackedUserOperation.sol";
import { Execution } from "@erc7579/interfaces/IERC7579Account.sol";
import { ModeCode, CallType, ExecType, ModeSelector, ModePayload } from "@erc7579/lib/ModeLib.sol";
/**
* @title EIP712Domain
* @notice Struct representing the EIP712 domain for signature validation.
*/
struct EIP712Domain {
string name;
string version;
uint256 chainId;
address verifyingContract;
}
/**
* @title Delegation
* @notice Struct representing a delegation to give a delegate authority to act on behalf of a delegator.
* @dev `signature` is ignored during delegation hashing so it can be manipulated post signing.
*/
struct Delegation {
address delegate;
address delegator;
bytes32 authority;
Caveat[] caveats;
uint256 salt;
bytes signature;
}
/**
* @title Caveat
* @notice Struct representing a caveat to enforce on a delegation.
* @dev `args` is ignored during caveat hashing so it can be manipulated post signing.
*/
struct Caveat {
address enforcer;
bytes terms;
bytes args;
}
/**
* @title P256 Public Key
* @notice Struct containing the X and Y coordinates of a P256 public key.
*/
struct P256PublicKey {
uint256 x;
uint256 y;
}
struct DecodedWebAuthnSignature {
uint256 r;
uint256 s;
bytes authenticatorData;
bool requireUserVerification;
string clientDataJSONPrefix;
string clientDataJSONSuffix;
uint256 responseTypeLocation;
}// SPDX-License-Identifier: MIT AND Apache-2.0
pragma solidity 0.8.23;
import { Delegation, Caveat } from "../utils/Types.sol";
import { DELEGATION_TYPEHASH, CAVEAT_TYPEHASH } from "../utils/Constants.sol";
/**
* @dev Provides implementations for common utility methods for Delegation.
* @title Delegation Utility Library
*/
library EncoderLib {
/**
* @notice Encodes and hashes a Delegation struct.
* @dev The hash is used to verify the integrity of the Delegation.
* @param _input The Delegation parameters to be hashed.
* @return The keccak256 hash of the encoded Delegation packet.
*/
function _getDelegationHash(Delegation memory _input) internal pure returns (bytes32) {
bytes memory encoded_ = abi.encode(
DELEGATION_TYPEHASH,
_input.delegate,
_input.delegator,
_input.authority,
_getCaveatArrayPacketHash(_input.caveats),
_input.salt
);
return keccak256(encoded_);
}
/**
* @notice Calculates the hash of an array of Caveats.
* @dev The hash is used to verify the integrity of the Caveats.
* @param _input The array of Caveats.
* @return The keccak256 hash of the encoded Caveat array packet.
*/
function _getCaveatArrayPacketHash(Caveat[] memory _input) internal pure returns (bytes32) {
bytes32[] memory caveatPacketHashes_ = new bytes32[](_input.length);
for (uint256 i = 0; i < _input.length; ++i) {
caveatPacketHashes_[i] = _getCaveatPacketHash(_input[i]);
}
return keccak256(abi.encodePacked(caveatPacketHashes_));
}
/**
* @notice Calculates the hash of a single Caveat.
* @dev The hash is used to verify the integrity of the Caveat.
* @param _input The Caveat data.
* @return The keccak256 hash of the encoded Caveat packet.
*/
function _getCaveatPacketHash(Caveat memory _input) internal pure returns (bytes32) {
bytes memory encoded_ = abi.encode(CAVEAT_TYPEHASH, _input.enforcer, keccak256(_input.terms));
return keccak256(encoded_);
}
}// SPDX-License-Identifier: MIT AND Apache-2.0
pragma solidity 0.8.23;
/**
* @title ERC1271 Library
*/
library ERC1271Lib {
/// @dev Magic value to be returned upon successful validation.
bytes4 internal constant EIP1271_MAGIC_VALUE = 0x1626ba7e;
/// @dev Magic value to be returned upon failed validation.
bytes4 internal constant SIG_VALIDATION_FAILED = 0xffffffff;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
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 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;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
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 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));
}
}// 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.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.0.0) (utils/ShortStrings.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
// | length | 0x BB |
type ShortString is bytes32;
/**
* @dev This library provides functions to convert short memory strings
* into a `ShortString` type that can be used as an immutable variable.
*
* Strings of arbitrary length can be optimized using this library if
* they are short enough (up to 31 bytes) by packing them with their
* length (1 byte) in a single EVM word (32 bytes). Additionally, a
* fallback mechanism can be used for every other case.
*
* Usage example:
*
* ```solidity
* contract Named {
* using ShortStrings for *;
*
* ShortString private immutable _name;
* string private _nameFallback;
*
* constructor(string memory contractName) {
* _name = contractName.toShortStringWithFallback(_nameFallback);
* }
*
* function name() external view returns (string memory) {
* return _name.toStringWithFallback(_nameFallback);
* }
* }
* ```
*/
library ShortStrings {
// Used as an identifier for strings longer than 31 bytes.
bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
error StringTooLong(string str);
error InvalidShortString();
/**
* @dev Encode a string of at most 31 chars into a `ShortString`.
*
* This will trigger a `StringTooLong` error is the input string is too long.
*/
function toShortString(string memory str) internal pure returns (ShortString) {
bytes memory bstr = bytes(str);
if (bstr.length > 31) {
revert StringTooLong(str);
}
return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
}
/**
* @dev Decode a `ShortString` back to a "normal" string.
*/
function toString(ShortString sstr) internal pure returns (string memory) {
uint256 len = byteLength(sstr);
// using `new string(len)` would work locally but is not memory safe.
string memory str = new string(32);
/// @solidity memory-safe-assembly
assembly {
mstore(str, len)
mstore(add(str, 0x20), sstr)
}
return str;
}
/**
* @dev Return the length of a `ShortString`.
*/
function byteLength(ShortString sstr) internal pure returns (uint256) {
uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
if (result > 31) {
revert InvalidShortString();
}
return result;
}
/**
* @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
*/
function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
if (bytes(value).length < 32) {
return toShortString(value);
} else {
StorageSlot.getStringSlot(store).value = value;
return ShortString.wrap(FALLBACK_SENTINEL);
}
}
/**
* @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*/
function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return toString(value);
} else {
return store;
}
}
/**
* @dev Return the length of a string that was encoded to `ShortString` or written to storage using
* {setWithFallback}.
*
* WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
* actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
*/
function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return byteLength(value);
} else {
return bytes(store).length;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)
pragma solidity ^0.8.20;
interface IERC5267 {
/**
* @dev MAY be emitted to signal that the domain could have changed.
*/
event EIP712DomainChanged();
/**
* @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
* signature.
*/
function eip712Domain()
external
view
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.5;
/**
* User Operation struct
* @param sender - The sender account of this request.
* @param nonce - Unique value the sender uses to verify it is not a replay.
* @param initCode - If set, the account contract will be created by this constructor/
* @param callData - The method call to execute on this account.
* @param accountGasLimits - Packed gas limits for validateUserOp and gas limit passed to the callData method call.
* @param preVerificationGas - Gas not calculated by the handleOps method, but added to the gas paid.
* Covers batch overhead.
* @param gasFees - packed gas fields maxPriorityFeePerGas and maxFeePerGas - Same as EIP-1559 gas parameters.
* @param paymasterAndData - If set, this field holds the paymaster address, verification gas limit, postOp gas limit and paymaster-specific extra data
* The paymaster will pay for the transaction instead of the sender.
* @param signature - Sender-verified signature over the entire request, the EntryPoint address and the chain ID.
*/
struct PackedUserOperation {
address sender;
uint256 nonce;
bytes initCode;
bytes callData;
bytes32 accountGasLimits;
uint256 preVerificationGas;
bytes32 gasFees;
bytes paymasterAndData;
bytes signature;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
import { CallType, ExecType, ModeCode } from "../lib/ModeLib.sol";
struct Execution {
address target;
uint256 value;
bytes callData;
}
interface IERC7579Account {
event ModuleInstalled(uint256 moduleTypeId, address module);
event ModuleUninstalled(uint256 moduleTypeId, address module);
/**
* @dev Executes a transaction on behalf of the account.
* This function is intended to be called by ERC-4337 EntryPoint.sol
* @dev Ensure adequate authorization control: i.e. onlyEntryPointOrSelf
*
* @dev MSA MUST implement this function signature.
* If a mode is requested that is not supported by the Account, it MUST revert
* @param mode The encoded execution mode of the transaction. See ModeLib.sol for details
* @param executionCalldata The encoded execution call data
*/
function execute(ModeCode mode, bytes calldata executionCalldata) external payable;
/**
* @dev Executes a transaction on behalf of the account.
* This function is intended to be called by Executor Modules
* @dev Ensure adequate authorization control: i.e. onlyExecutorModule
*
* @dev MSA MUST implement this function signature.
* If a mode is requested that is not supported by the Account, it MUST revert
* @param mode The encoded execution mode of the transaction. See ModeLib.sol for details
* @param executionCalldata The encoded execution call data
*/
function executeFromExecutor(
ModeCode mode,
bytes calldata executionCalldata
)
external
payable
returns (bytes[] memory returnData);
/**
* @dev ERC-1271 isValidSignature
* This function is intended to be used to validate a smart account signature
* and may forward the call to a validator module
*
* @param hash The hash of the data that is signed
* @param data The data that is signed
*/
function isValidSignature(bytes32 hash, bytes calldata data) external view returns (bytes4);
/**
* @dev installs a Module of a certain type on the smart account
* @dev Implement Authorization control of your chosing
* @param moduleTypeId the module type ID according the ERC-7579 spec
* @param module the module address
* @param initData arbitrary data that may be required on the module during `onInstall`
* initialization.
*/
function installModule(
uint256 moduleTypeId,
address module,
bytes calldata initData
)
external
payable;
/**
* @dev uninstalls a Module of a certain type on the smart account
* @dev Implement Authorization control of your chosing
* @param moduleTypeId the module type ID according the ERC-7579 spec
* @param module the module address
* @param deInitData arbitrary data that may be required on the module during `onUninstall`
* de-initialization.
*/
function uninstallModule(
uint256 moduleTypeId,
address module,
bytes calldata deInitData
)
external
payable;
/**
* Function to check if the account supports a certain CallType or ExecType (see ModeLib.sol)
* @param encodedMode the encoded mode
*/
function supportsExecutionMode(ModeCode encodedMode) external view returns (bool);
/**
* Function to check if the account supports installation of a certain module type Id
* @param moduleTypeId the module type ID according the ERC-7579 spec
*/
function supportsModule(uint256 moduleTypeId) external view returns (bool);
/**
* Function to check if the account has a certain module installed
* @param moduleTypeId the module type ID according the ERC-7579 spec
* Note: keep in mind that some contracts can be multiple module types at the same time. It
* thus may be necessary to query multiple module types
* @param module the module address
* @param additionalContext additional context data that the smart account may interpret to
* identifiy conditions under which the module is installed.
* usually this is not necessary, but for some special hooks that
* are stored in mappings, this param might be needed
*/
function isModuleInstalled(
uint256 moduleTypeId,
address module,
bytes calldata additionalContext
)
external
view
returns (bool);
/**
* @dev Returns the account id of the smart account
* @return accountImplementationId the account id of the smart account
* the accountId should be structured like so:
* "vendorname.accountname.semver"
*/
function accountId() external view returns (string memory accountImplementationId);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
/**
* @title ModeLib
* To allow smart accounts to be very simple, but allow for more complex execution, A custom mode
* encoding is used.
* Function Signature of execute function:
* function execute(ModeCode mode, bytes calldata executionCalldata) external payable;
* This allows for a single bytes32 to be used to encode the execution mode, calltype, execType and
* context.
* NOTE: Simple Account implementations only have to scope for the most significant byte. Account that
* implement
* more complex execution modes may use the entire bytes32.
*
* |--------------------------------------------------------------------|
* | CALLTYPE | EXECTYPE | UNUSED | ModeSelector | ModePayload |
* |--------------------------------------------------------------------|
* | 1 byte | 1 byte | 4 bytes | 4 bytes | 22 bytes |
* |--------------------------------------------------------------------|
*
* CALLTYPE: 1 byte
* CallType is used to determine how the executeCalldata paramter of the execute function has to be
* decoded.
* It can be either single, batch or delegatecall. In the future different calls could be added.
* CALLTYPE can be used by a validation module to determine how to decode <userOp.callData[36:]>.
*
* EXECTYPE: 1 byte
* ExecType is used to determine how the account should handle the execution.
* It can indicate if the execution should revert on failure or continue execution.
* In the future more execution modes may be added.
* Default Behavior (EXECTYPE = 0x00) is to revert on a single failed execution. If one execution in
* a batch fails, the entire batch is reverted
*
* UNUSED: 4 bytes
* Unused bytes are reserved for future use.
*
* ModeSelector: bytes4
* The "optional" mode selector can be used by account vendors, to implement custom behavior in
* their accounts.
* the way a ModeSelector is to be calculated is bytes4(keccak256("vendorname.featurename"))
* this is to prevent collisions between different vendors, while allowing innovation and the
* development of new features without coordination between ERC-7579 implementing accounts
*
* ModePayload: 22 bytes
* Mode payload is used to pass additional data to the smart account execution, this may be
* interpreted depending on the ModeSelector
*
* ExecutionCallData: n bytes
* single, delegatecall or batch exec abi.encoded as bytes
*/
import { Execution } from "../interfaces/IERC7579Account.sol";
// Custom type for improved developer experience
type ModeCode is bytes32;
type CallType is bytes1;
type ExecType is bytes1;
type ModeSelector is bytes4;
type ModePayload is bytes22;
// Default CallType
CallType constant CALLTYPE_SINGLE = CallType.wrap(0x00);
// Batched CallType
CallType constant CALLTYPE_BATCH = CallType.wrap(0x01);
// @dev Implementing delegatecall is OPTIONAL!
// implement delegatecall with extreme care.
CallType constant CALLTYPE_STATIC = CallType.wrap(0xFE);
CallType constant CALLTYPE_DELEGATECALL = CallType.wrap(0xFF);
// @dev default behavior is to revert on failure
// To allow very simple accounts to use mode encoding, the default behavior is to revert on failure
// Since this is value 0x00, no additional encoding is required for simple accounts
ExecType constant EXECTYPE_DEFAULT = ExecType.wrap(0x00);
// @dev account may elect to change execution behavior. For example "try exec" / "allow fail"
ExecType constant EXECTYPE_TRY = ExecType.wrap(0x01);
ModeSelector constant MODE_DEFAULT = ModeSelector.wrap(bytes4(0x00000000));
// Example declaration of a custom mode selector
ModeSelector constant MODE_OFFSET = ModeSelector.wrap(bytes4(keccak256("default.mode.offset")));
/**
* @dev ModeLib is a helper library to encode/decode ModeCodes
*/
library ModeLib {
function decode(ModeCode mode)
internal
pure
returns (
CallType _calltype,
ExecType _execType,
ModeSelector _modeSelector,
ModePayload _modePayload
)
{
assembly {
_calltype := mode
_execType := shl(8, mode)
_modeSelector := shl(48, mode)
_modePayload := shl(80, mode)
}
}
function encode(
CallType callType,
ExecType execType,
ModeSelector mode,
ModePayload payload
)
internal
pure
returns (ModeCode)
{
return ModeCode.wrap(
bytes32(
abi.encodePacked(callType, execType, bytes4(0), ModeSelector.unwrap(mode), payload)
)
);
}
function encodeSimpleBatch() internal pure returns (ModeCode mode) {
mode = encode(CALLTYPE_BATCH, EXECTYPE_DEFAULT, MODE_DEFAULT, ModePayload.wrap(0x00));
}
function encodeSimpleSingle() internal pure returns (ModeCode mode) {
mode = encode(CALLTYPE_SINGLE, EXECTYPE_DEFAULT, MODE_DEFAULT, ModePayload.wrap(0x00));
}
function getCallType(ModeCode mode) internal pure returns (CallType calltype) {
assembly {
calltype := mode
}
}
}
using { eqModeSelector as == } for ModeSelector global;
using { eqCallType as == } for CallType global;
using { eqExecType as == } for ExecType global;
function eqCallType(CallType a, CallType b) pure returns (bool) {
return CallType.unwrap(a) == CallType.unwrap(b);
}
function eqExecType(ExecType a, ExecType b) pure returns (bool) {
return ExecType.unwrap(a) == ExecType.unwrap(b);
}
function eqModeSelector(ModeSelector a, ModeSelector b) pure returns (bool) {
return ModeSelector.unwrap(a) == ModeSelector.unwrap(b);
}// SPDX-License-Identifier: MIT AND Apache-2.0
pragma solidity 0.8.23;
import {
CALLTYPE_SINGLE, CALLTYPE_BATCH, EXECTYPE_DEFAULT, EXECTYPE_TRY, MODE_DEFAULT, MODE_OFFSET
} from "@erc7579/lib/ModeLib.sol";
bytes32 constant EIP712_DOMAIN_TYPEHASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
// NOTE: signature is omitted from the Delegation typehash
bytes32 constant DELEGATION_TYPEHASH = keccak256(
"Delegation(address delegate,address delegator,bytes32 authority,Caveat[] caveats,uint256 salt)Caveat(address enforcer,bytes terms)"
);
bytes32 constant CAVEAT_TYPEHASH = keccak256("Caveat(address enforcer,bytes terms)");// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.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 Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return 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 a == 0 ? 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
// 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(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, expect 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 Ferma's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`.
*/
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 x < 0 ? (n - uint256(-x)) : uint256(x); // Wrap the result if it's negative.
}
}
/**
* @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 has 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);
/// @solidity memory-safe-assembly
assembly {
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);
/// @solidity memory-safe-assembly
assembly {
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 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.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return 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 `bytes(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
int256 mask = n >> 255;
// A `bytes(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.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: MIT
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].
*/
// 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 {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.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) {
/// @solidity memory-safe-assembly
assembly {
u := iszero(iszero(b))
}
}
}{
"remappings": [
"@account-abstraction/=lib/account-abstraction/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-upgradable-contracts/contracts/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"@solidity-stringutils/=lib/solidity-stringutils/src/",
"@bytes-utils/=lib/solidity-bytes-utils/contracts/",
"@FCL/=lib/FCL/solidity/src/",
"@erc7579/=lib/erc7579-implementation/src/",
"@SCL/=lib/SCL/src/",
"@solidity/=lib/SCL/src/",
"FCL/=lib/FCL/solidity/src/",
"FreshCryptoLib/=lib/FreshCryptoLib/solidity/src/",
"SCL/=lib/SCL/",
"account-abstraction/=lib/account-abstraction/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"erc7579-implementation/=lib/erc7579-implementation/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"sentinellist/=lib/erc7579-implementation/node_modules/@rhinestone/sentinellist/src/",
"solady/=lib/erc7579-implementation/node_modules/solady/src/",
"solidity-bytes-utils/=lib/solidity-bytes-utils/contracts/",
"solidity-stringutils/=lib/solidity-stringutils/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "london",
"viaIR": false,
"libraries": {}
}Contract ABI
API[{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyDisabled","type":"error"},{"inputs":[],"name":"AlreadyEnabled","type":"error"},{"inputs":[],"name":"BatchDataLengthMismatch","type":"error"},{"inputs":[],"name":"CannotUseADisabledDelegation","type":"error"},{"inputs":[],"name":"ECDSAInvalidSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"ECDSAInvalidSignatureLength","type":"error"},{"inputs":[{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"ECDSAInvalidSignatureS","type":"error"},{"inputs":[],"name":"EmptySignature","type":"error"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[],"name":"InvalidAuthority","type":"error"},{"inputs":[],"name":"InvalidDelegate","type":"error"},{"inputs":[],"name":"InvalidDelegator","type":"error"},{"inputs":[],"name":"InvalidEOASignature","type":"error"},{"inputs":[],"name":"InvalidERC1271Signature","type":"error"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"delegationHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"delegate","type":"address"},{"components":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"delegator","type":"address"},{"internalType":"bytes32","name":"authority","type":"bytes32"},{"components":[{"internalType":"address","name":"enforcer","type":"address"},{"internalType":"bytes","name":"terms","type":"bytes"},{"internalType":"bytes","name":"args","type":"bytes"}],"internalType":"struct Caveat[]","name":"caveats","type":"tuple[]"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"indexed":false,"internalType":"struct Delegation","name":"delegation","type":"tuple"}],"name":"DisabledDelegation","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"delegationHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"delegate","type":"address"},{"components":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"delegator","type":"address"},{"internalType":"bytes32","name":"authority","type":"bytes32"},{"components":[{"internalType":"address","name":"enforcer","type":"address"},{"internalType":"bytes","name":"terms","type":"bytes"},{"internalType":"bytes","name":"args","type":"bytes"}],"internalType":"struct Caveat[]","name":"caveats","type":"tuple[]"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"indexed":false,"internalType":"struct Delegation","name":"delegation","type":"tuple"}],"name":"EnabledDelegation","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"rootDelegator","type":"address"},{"indexed":true,"internalType":"address","name":"redeemer","type":"address"},{"components":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"delegator","type":"address"},{"internalType":"bytes32","name":"authority","type":"bytes32"},{"components":[{"internalType":"address","name":"enforcer","type":"address"},{"internalType":"bytes","name":"terms","type":"bytes"},{"internalType":"bytes","name":"args","type":"bytes"}],"internalType":"struct Caveat[]","name":"caveats","type":"tuple[]"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"indexed":false,"internalType":"struct Delegation","name":"delegation","type":"tuple"}],"name":"RedeemedDelegation","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"domainHash","type":"bytes32"},{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"string","name":"domainVersion","type":"string"},{"indexed":false,"internalType":"uint256","name":"chainId","type":"uint256"},{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"}],"name":"SetDomain","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"ANY_DELEGATE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NAME","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ROOT_AUTHORITY","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"delegator","type":"address"},{"internalType":"bytes32","name":"authority","type":"bytes32"},{"components":[{"internalType":"address","name":"enforcer","type":"address"},{"internalType":"bytes","name":"terms","type":"bytes"},{"internalType":"bytes","name":"args","type":"bytes"}],"internalType":"struct Caveat[]","name":"caveats","type":"tuple[]"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Delegation","name":"_delegation","type":"tuple"}],"name":"disableDelegation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"delegationHash","type":"bytes32"}],"name":"disabledDelegations","outputs":[{"internalType":"bool","name":"isDisabled","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"delegator","type":"address"},{"internalType":"bytes32","name":"authority","type":"bytes32"},{"components":[{"internalType":"address","name":"enforcer","type":"address"},{"internalType":"bytes","name":"terms","type":"bytes"},{"internalType":"bytes","name":"args","type":"bytes"}],"internalType":"struct Caveat[]","name":"caveats","type":"tuple[]"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Delegation","name":"_delegation","type":"tuple"}],"name":"enableDelegation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"address","name":"delegator","type":"address"},{"internalType":"bytes32","name":"authority","type":"bytes32"},{"components":[{"internalType":"address","name":"enforcer","type":"address"},{"internalType":"bytes","name":"terms","type":"bytes"},{"internalType":"bytes","name":"args","type":"bytes"}],"internalType":"struct Caveat[]","name":"caveats","type":"tuple[]"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Delegation","name":"_input","type":"tuple"}],"name":"getDelegationHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getDomainHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"_permissionContexts","type":"bytes[]"},{"internalType":"ModeCode[]","name":"_modes","type":"bytes32[]"},{"internalType":"bytes[]","name":"_executionCallDatas","type":"bytes[]"}],"name":"redeemDelegations","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
6101606040523480156200001257600080fd5b506040516200334f3803806200334f833981016040819052620000359162000384565b60408051808201825260118152702232b632b3b0ba34b7b726b0b730b3b2b960791b602080830191909152825180840190935260018352603160f81b9083015290826001600160a01b038116620000a757604051631e4fbdf760e01b8152600060048201526024015b60405180910390fd5b620000b28162000204565b506001805460ff60a01b19169055620000cd82600262000222565b61012052620000de81600362000222565b61014052815160208084019190912060e052815190820120610100524660a0526200015b60e05161010051604080516000805160206200332f83398151915260208201529081019290925260608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b60805250503060c0526000620001706200025b565b9050306001600160a01b0316817f04a46d9007577c7ff1e513b900545162ec25d25991ae3dc60cf26ec01a84806d604051806040016040528060118152602001702232b632b3b0ba34b7b726b0b730b3b2b960791b815250604051806040016040528060018152602001603160f81b81525046604051620001f493929190620003fe565b60405180910390a35050620005e5565b600180546001600160a01b03191690556200021f81620002f1565b50565b600060208351101562000242576200023a8362000341565b905062000255565b816200024f8482620004df565b5060ff90505b92915050565b600060c0516001600160a01b0316306001600160a01b031614801562000282575060a05146145b156200028f575060805190565b620002ec60e05161010051604080516000805160206200332f83398151915260208201529081019290925260608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b905090565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080829050601f815111156200036f578260405163305a27a960e01b81526004016200009e9190620005ab565b80516200037c82620005c0565b179392505050565b6000602082840312156200039757600080fd5b81516001600160a01b0381168114620003af57600080fd5b9392505050565b6000815180845260005b81811015620003de57602081850181015186830182015201620003c0565b506000602082860101526020601f19601f83011685010191505092915050565b606081526000620004136060830186620003b6565b8281036020840152620004278186620003b6565b915050826040830152949350505050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200046357607f821691505b6020821081036200048457634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620004da576000816000526020600020601f850160051c81016020861015620004b55750805b601f850160051c820191505b81811015620004d657828155600101620004c1565b5050505b505050565b81516001600160401b03811115620004fb57620004fb62000438565b62000513816200050c84546200044e565b846200048a565b602080601f8311600181146200054b5760008415620005325750858301515b600019600386901b1c1916600185901b178555620004d6565b600085815260208120601f198616915b828110156200057c578886015182559484019460019091019084016200055b565b50858210156200059b5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b602081526000620003af6020830184620003b6565b80516020808301519190811015620004845760001960209190910360031b1b16919050565b60805160a05160c05160e051610100516101205161014051612cef620006406000396000611bda01526000611bad01526000611b1201526000611aea01526000611a4501526000611a6f01526000611a990152612cef6000f3fe608060405234801561001057600080fd5b506004361061012c5760003560e01c806383ebb771116100ad578063acb8cc4911610071578063acb8cc491461027f578063cef6d2091461029f578063e30c3978146102b2578063f2fde38b146102c3578063ffa1ad74146102d657600080fd5b806383ebb771146102065780638456cb591461020e57806384b0196e146102165780638da5cb5b14610231578063a3f4df7e1461024257600080fd5b806358909ebc116100f457806358909ebc146101b05780635c975abb146101d157806366134607146101e3578063715018a6146101f657806379ba5097146101fe57600080fd5b80631b13cac2146101315780632d40d0521461014d5780633ed01015146101805780633f4ba83a14610195578063499340471461019d575b600080fd5b61013a60001981565b6040519081526020015b60405180910390f35b61017061015b3660046120e6565b60046020526000908152604090205460ff1681565b6040519015158152602001610144565b61019361018e3660046120ff565b6102fa565b005b6101936103f4565b6101936101ab3660046120ff565b610406565b6101b9610a1181565b6040516001600160a01b039091168152602001610144565b600154600160a01b900460ff16610170565b61013a6101f13660046120ff565b6104f6565b61019361050f565b610193610521565b61013a61056a565b610193610579565b61021e610589565b6040516101449796959493929190612190565b6000546001600160a01b03166101b9565b610272604051806040016040528060118152602001702232b632b3b0ba34b7b726b0b730b3b2b960791b81525081565b6040516101449190612229565b610272604051806040016040528060018152602001603160f81b81525081565b6101936102ad366004612287565b6105cf565b6001546001600160a01b03166101b9565b6101936102d136600461233c565b611891565b610272604051806040016040528060058152602001640312e332e360dc1b81525081565b61030a604082016020830161233c565b6001600160a01b03811633146103335760405163b9f0f17160e01b815260040160405180910390fd5b600061033e836104f6565b60008181526004602052604090205490915060ff1661037057604051637952fbad60e11b815260040160405180910390fd5b6000818152600460209081526040909120805460ff191690556103959084018461233c565b6001600160a01b03166103ae604085016020860161233c565b6001600160a01b0316827f3feadce88fc1b49db633a56fd5307ed6ee18734df83bcc4011daa720c9cd95f1866040516103e79190612484565b60405180910390a4505050565b6103fc611902565b61040461192f565b565b610416604082016020830161233c565b6001600160a01b038116331461043f5760405163b9f0f17160e01b815260040160405180910390fd5b600061044a836104f6565b60008181526004602052604090205490915060ff161561047c57604051625ecddb60e01b815260040160405180910390fd5b6000818152600460209081526040909120805460ff191660011790556104a49084018461233c565b6001600160a01b03166104bd604085016020860161233c565b6001600160a01b0316827fea589ba9473ee1fe77d352c7ed919747715a5d22931b972de9b02a907c66d5dd866040516103e79190612484565b600061050961050483612823565b611984565b92915050565b610517611902565b6104046000611a1f565b60015433906001600160a01b0316811461055e5760405163118cdaa760e01b81526001600160a01b03821660048201526024015b60405180910390fd5b61056781611a1f565b50565b6000610574611a38565b905090565b610581611902565b610404611b63565b60006060806000806000606061059d611ba6565b6105a5611bd3565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6105d7611c00565b8481811415806105e75750808414155b1561060557604051631bcaf69f60e01b815260040160405180910390fd5b6000816001600160401b0381111561061f5761061f612555565b60405190808252806020026020018201604052801561065257816020015b606081526020019060019003908161063d5790505b5090506000826001600160401b0381111561066f5761066f612555565b6040519080825280602002602001820160405280156106a257816020015b606081526020019060019003908161068d5790505b50905060005b83811015610c815760008a8a838181106106c4576106c461282f565b90506020028101906106d69190612845565b8101906106e3919061288b565b905080516000036107d1576040805160008082526020820190925290610765565b6107526040518060c0016040528060006001600160a01b0316815260200160006001600160a01b03168152602001600080191681526020016060815260200160008152602001606081525090565b8152602001906001900390816107045790505b508483815181106107785761077861282f565b602090810291909101015260006040519080825280602002602001820160405280156107ae578160200160208202803683370190505b508383815181106107c1576107c161282f565b6020026020010181905250610c78565b808483815181106107e4576107e461282f565b6020026020010181905250600081516001600160401b0381111561080a5761080a612555565b604051908082528060200260200182016040528015610833578160200160208202803683370190505b509050808484815181106108495761084961282f565b6020026020010181905250336001600160a01b0316826000815181106108715761087161282f565b6020026020010151600001516001600160a01b0316141580156108c65750610a116001600160a01b0316826000815181106108ae576108ae61282f565b6020026020010151600001516001600160a01b031614155b156108e457604051632d618d8160e21b815260040160405180910390fd5b60005b8251811015610ab55760008382815181106109045761090461282f565b6020026020010151905061091781611984565b8383815181106109295761092961282f565b60200260200101818152505080602001516001600160a01b03163b6000036109dc57600061099e61099461095b61056a565b86868151811061096d5761096d61282f565b602002602001015160405161190160f01b8152600281019290925260228201526042902090565b8360a00151611c2b565b905081602001516001600160a01b0316816001600160a01b0316146109d657604051630f6d9e4760e21b815260040160405180910390fd5b50610aac565b60006109fb6109e961056a565b85858151811061096d5761096d61282f565b9050600082602001516001600160a01b0316631626ba7e838560a001516040518363ffffffff1660e01b8152600401610a3592919061293b565b602060405180830381865afa158015610a52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a76919061295c565b6001600160e01b0319169050630b135d3f60e11b8114610aa95760405163155ff42760e01b815260040160405180910390fd5b50505b506001016108e7565b5060005b8251811015610c755760046000838381518110610ad857610ad861282f565b60209081029190910181015182528101919091526040016000205460ff1615610b14576040516302dd502960e11b815260040160405180910390fd5b60018351610b22919061299c565b8114610c2b5781610b348260016129af565b81518110610b4457610b4461282f565b6020026020010151838281518110610b5e57610b5e61282f565b60200260200101516040015114610b8857604051636f6a1b8760e11b815260040160405180910390fd5b600083610b968360016129af565b81518110610ba657610ba661282f565b6020026020010151600001519050610a116001600160a01b0316816001600160a01b031614158015610c075750806001600160a01b0316848381518110610bef57610bef61282f565b6020026020010151602001516001600160a01b031614155b15610c2557604051632d618d8160e21b815260040160405180910390fd5b50610c6d565b60001960001b838281518110610c4357610c4361282f565b60200260200101516040015114610c6d57604051636f6a1b8760e11b815260040160405180910390fd5b600101610ab9565b50505b506001016106a8565b5060005b83811015610ea6576000838281518110610ca157610ca161282f565b6020026020010151511115610e9e5760005b838281518110610cc557610cc561282f565b602002602001015151811015610e9c576000848381518110610ce957610ce961282f565b60200260200101518281518110610d0257610d0261282f565b602002602001015160600151905060005b8151811015610e92576000828281518110610d3057610d3061282f565b6020026020010151600001519050806001600160a01b031663414c3e33848481518110610d5f57610d5f61282f565b602002602001015160200151858581518110610d7d57610d7d61282f565b6020026020010151604001518f8f8a818110610d9b57610d9b61282f565b905060200201358e8e8b818110610db457610db461282f565b9050602002810190610dc69190612845565b8c8c81518110610dd857610dd861282f565b60200260200101518b81518110610df157610df161282f565b60200260200101518e8d81518110610e0b57610e0b61282f565b60200260200101518c81518110610e2457610e2461282f565b602002602001015160200151336040518963ffffffff1660e01b8152600401610e549897969594939291906129c2565b600060405180830381600087803b158015610e6e57600080fd5b505af1158015610e82573d6000803e3d6000fd5b5050505050806001019050610d13565b5050600101610cb3565b505b600101610c85565b5060005b838110156114ca57828181518110610ec457610ec461282f565b602002602001015151600003610f82573363d691c964898984818110610eec57610eec61282f565b90506020020135888885818110610f0557610f0561282f565b9050602002810190610f179190612845565b6040518463ffffffff1660e01b8152600401610f3593929190612a2d565b6000604051808303816000875af1158015610f54573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610f7c9190810190612a50565b506114c2565b60005b838281518110610f9757610f9761282f565b60200260200101515181101561116e576000848381518110610fbb57610fbb61282f565b60200260200101518281518110610fd457610fd461282f565b602002602001015160600151905060005b81518110156111645760008282815181106110025761100261282f565b6020026020010151600001519050806001600160a01b031663a145832a8484815181106110315761103161282f565b60200260200101516020015185858151811061104f5761104f61282f565b6020026020010151604001518f8f8a81811061106d5761106d61282f565b905060200201358e8e8b8181106110865761108661282f565b90506020028101906110989190612845565b8c8c815181106110aa576110aa61282f565b60200260200101518b815181106110c3576110c361282f565b60200260200101518e8d815181106110dd576110dd61282f565b60200260200101518c815181106110f6576110f661282f565b602002602001015160200151336040518963ffffffff1660e01b81526004016111269897969594939291906129c2565b600060405180830381600087803b15801561114057600080fd5b505af1158015611154573d6000803e3d6000fd5b5050505050806001019050610fe5565b5050600101610f85565b508281815181106111815761118161282f565b6020026020010151600184838151811061119d5761119d61282f565b6020026020010151516111b0919061299c565b815181106111c0576111c061282f565b6020026020010151602001516001600160a01b031663d691c9648989848181106111ec576111ec61282f565b905060200201358888858181106112055761120561282f565b90506020028101906112179190612845565b6040518463ffffffff1660e01b815260040161123593929190612a2d565b6000604051808303816000875af1158015611254573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261127c9190810190612a50565b5060008382815181106112915761129161282f565b60200260200101515190505b80156114c05760008483815181106112b7576112b761282f565b60200260200101516001836112cc919061299c565b815181106112dc576112dc61282f565b60200260200101516060015190506000815190505b80156114ad5760008261130560018461299c565b815181106113155761131561282f565b6020026020010151600001519050806001600160a01b031663d3eddcc584600185611340919061299c565b815181106113505761135061282f565b6020026020010151602001518560018661136a919061299c565b8151811061137a5761137a61282f565b6020026020010151604001518f8f8a8181106113985761139861282f565b905060200201358e8e8b8181106113b1576113b161282f565b90506020028101906113c39190612845565b8c8c815181106113d5576113d561282f565b602002602001015160018c6113ea919061299c565b815181106113fa576113fa61282f565b60200260200101518e8d815181106114145761141461282f565b602002602001015160018d611429919061299c565b815181106114395761143961282f565b602002602001015160200151336040518963ffffffff1660e01b81526004016114699897969594939291906129c2565b600060405180830381600087803b15801561148357600080fd5b505af1158015611497573d6000803e3d6000fd5b5050505050806114a690612b2f565b90506112f1565b5050806114b990612b2f565b905061129d565b505b600101610eaa565b5060005b838110156117465760008382815181106114ea576114ea61282f565b602002602001015151111561173e57600083828151811061150d5761150d61282f565b60200260200101515190505b801561173c5760008483815181106115335761153361282f565b6020026020010151600183611548919061299c565b815181106115585761155861282f565b60200260200101516060015190506000815190505b80156117295760008261158160018461299c565b815181106115915761159161282f565b6020026020010151600001519050806001600160a01b031663ed463367846001856115bc919061299c565b815181106115cc576115cc61282f565b602002602001015160200151856001866115e6919061299c565b815181106115f6576115f661282f565b6020026020010151604001518f8f8a8181106116145761161461282f565b905060200201358e8e8b81811061162d5761162d61282f565b905060200281019061163f9190612845565b8c8c815181106116515761165161282f565b602002602001015160018c611666919061299c565b815181106116765761167661282f565b60200260200101518e8d815181106116905761169061282f565b602002602001015160018d6116a5919061299c565b815181106116b5576116b561282f565b602002602001015160200151336040518963ffffffff1660e01b81526004016116e59897969594939291906129c2565b600060405180830381600087803b1580156116ff57600080fd5b505af1158015611713573d6000803e3d6000fd5b50505050508061172290612b2f565b905061156d565b50508061173590612b2f565b9050611519565b505b6001016114ce565b5060005b838110156118855760008382815181106117665761176661282f565b602002602001015151111561187d5760005b83828151811061178a5761178a61282f565b60200260200101515181101561187b57336001600160a01b03168483815181106117b6576117b661282f565b602002602001015160018685815181106117d2576117d261282f565b6020026020010151516117e5919061299c565b815181106117f5576117f561282f565b6020026020010151602001516001600160a01b03167f40dadaa36c6c2e3d7317e24757451ffb2d603d875f0ad5e92c5dd156573b187386858151811061183d5761183d61282f565b602002602001015184815181106118565761185661282f565b602002602001015160405161186b9190612b46565b60405180910390a3600101611778565b505b60010161174a565b50505050505050505050565b611899611902565b600180546001600160a01b0383166001600160a01b031990911681179091556118ca6000546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b6000546001600160a01b031633146104045760405163118cdaa760e01b8152336004820152602401610555565b611937611c55565b6001805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6000807f88c1d2ecf185adf710588203a5f263f0ff61be0d33da39792cde19ba9aa4331e8360000151846020015185604001516119c48760600151611c7f565b6080808901516040805160208101989098526001600160a01b03968716908801529490931660608601529184015260a083015260c082015260e0015b60408051601f1981840301815291905280516020909101209392505050565b600180546001600160a01b031916905561056781611d4a565b6000306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148015611a9157507f000000000000000000000000000000000000000000000000000000000000000046145b15611abb57507f000000000000000000000000000000000000000000000000000000000000000090565b610574604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b611b6b611c00565b6001805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586119673390565b60606105747f00000000000000000000000000000000000000000000000000000000000000006002611d9a565b60606105747f00000000000000000000000000000000000000000000000000000000000000006003611d9a565b600154600160a01b900460ff16156104045760405163d93c066560e01b815260040160405180910390fd5b600080600080611c3b8686611e45565b925092509250611c4b8282611e92565b5090949350505050565b600154600160a01b900460ff1661040457604051638dfc202b60e01b815260040160405180910390fd5b60008082516001600160401b03811115611c9b57611c9b612555565b604051908082528060200260200182016040528015611cc4578160200160208202803683370190505b50905060005b8351811015611d1a57611cf5848281518110611ce857611ce861282f565b6020026020010151611f4f565b828281518110611d0757611d0761282f565b6020908102919091010152600101611cca565b5080604051602001611d2c9190612c33565b60405160208183030381529060405280519060200120915050919050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b606060ff8314611db457611dad83611fb0565b9050610509565b818054611dc090612c69565b80601f0160208091040260200160405190810160405280929190818152602001828054611dec90612c69565b8015611e395780601f10611e0e57610100808354040283529160200191611e39565b820191906000526020600020905b815481529060010190602001808311611e1c57829003601f168201915b50505050509050610509565b60008060008351604103611e7f5760208401516040850151606086015160001a611e7188828585611fef565b955095509550505050611e8b565b50508151600091506002905b9250925092565b6000826003811115611ea657611ea6612ca3565b03611eaf575050565b6001826003811115611ec357611ec3612ca3565b03611ee15760405163f645eedf60e01b815260040160405180910390fd5b6002826003811115611ef557611ef5612ca3565b03611f165760405163fce698f760e01b815260048101829052602401610555565b6003826003811115611f2a57611f2a612ca3565b03611f4b576040516335e2f38360e21b815260048101829052602401610555565b5050565b6000807f80ad7e1b04ee6d994a125f4714ca0720908bd80ed16063ec8aee4b88e9253e2d8360000151846020015180519060200120604051602001611a00939291909283526001600160a01b03919091166020830152604082015260600190565b60606000611fbd836120be565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084111561202a57506000915060039050826120b4565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa15801561207e573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166120aa575060009250600191508290506120b4565b9250600091508190505b9450945094915050565b600060ff8216601f81111561050957604051632cd44ac360e21b815260040160405180910390fd5b6000602082840312156120f857600080fd5b5035919050565b60006020828403121561211157600080fd5b81356001600160401b0381111561212757600080fd5b820160c0818503121561213957600080fd5b9392505050565b60005b8381101561215b578181015183820152602001612143565b50506000910152565b6000815180845261217c816020860160208601612140565b601f01601f19169290920160200192915050565b60ff60f81b881681526000602060e060208401526121b160e084018a612164565b83810360408501526121c3818a612164565b606085018990526001600160a01b038816608086015260a0850187905284810360c08601528551808252602080880193509091019060005b81811015612217578351835292840192918401916001016121fb565b50909c9b505050505050505050505050565b6020815260006121396020830184612164565b60008083601f84011261224e57600080fd5b5081356001600160401b0381111561226557600080fd5b6020830191508360208260051b850101111561228057600080fd5b9250929050565b600080600080600080606087890312156122a057600080fd5b86356001600160401b03808211156122b757600080fd5b6122c38a838b0161223c565b909850965060208901359150808211156122dc57600080fd5b6122e88a838b0161223c565b9096509450604089013591508082111561230157600080fd5b5061230e89828a0161223c565b979a9699509497509295939492505050565b80356001600160a01b038116811461233757600080fd5b919050565b60006020828403121561234e57600080fd5b61213982612320565b6000808335601e1984360301811261236e57600080fd5b83016020810192503590506001600160401b0381111561238d57600080fd5b80360382131561228057600080fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60008383855260208086019550808560051b830101846000805b8881101561247657858403601f19018a52823536899003605e19018112612404578283fd5b880160606001600160a01b0361241983612320565b16865261242887830183612357565b828989015261243a838901828461239c565b92505050604061244c81840184612357565b93508783038289015261246083858361239c565b9d89019d975050509386019350506001016123df565b509198975050505050505050565b6020815260006001600160a01b038061249c85612320565b166020840152806124af60208601612320565b16604084015250604083013560608301526060830135601e198436030181126124d757600080fd5b83016020810190356001600160401b038111156124f357600080fd5b8060051b360382131561250557600080fd5b60c0608085015261251a60e0850182846123c5565b915050608084013560a084015261253460a0850185612357565b848303601f190160c086015261254b83828461239c565b9695505050505050565b634e487b7160e01b600052604160045260246000fd5b604051606081016001600160401b038111828210171561258d5761258d612555565b60405290565b60405160c081016001600160401b038111828210171561258d5761258d612555565b604051601f8201601f191681016001600160401b03811182821017156125dd576125dd612555565b604052919050565b60006001600160401b038211156125fe576125fe612555565b5060051b60200190565b60006001600160401b0382111561262157612621612555565b50601f01601f191660200190565b600082601f83011261264057600080fd5b813561265361264e82612608565b6125b5565b81815284602083860101111561266857600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261269657600080fd5b813560206126a661264e836125e5565b82815260059290921b840181019181810190868411156126c557600080fd5b8286015b848110156127745780356001600160401b03808211156126e95760008081fd5b908801906060828b03601f19018113156127035760008081fd5b61270b61256b565b612716888501612320565b81526040808501358481111561272c5760008081fd5b61273a8e8b8389010161262f565b838b0152509184013591838311156127525760008081fd5b6127608d8a8588010161262f565b9082015286525050509183019183016126c9565b509695505050505050565b600060c0828403121561279157600080fd5b612799612593565b90506127a482612320565b81526127b260208301612320565b60208201526040820135604082015260608201356001600160401b03808211156127db57600080fd5b6127e785838601612685565b60608401526080840135608084015260a084013591508082111561280a57600080fd5b506128178482850161262f565b60a08301525092915050565b6000610509368361277f565b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261285c57600080fd5b8301803591506001600160401b0382111561287657600080fd5b60200191503681900382131561228057600080fd5b6000602080838503121561289e57600080fd5b82356001600160401b03808211156128b557600080fd5b818501915085601f8301126128c957600080fd5b81356128d761264e826125e5565b81815260059190911b830184019084810190888311156128f657600080fd5b8585015b8381101561292e578035858111156129125760008081fd5b6129208b89838a010161277f565b8452509186019186016128fa565b5098975050505050505050565b8281526040602082015260006129546040830184612164565b949350505050565b60006020828403121561296e57600080fd5b81516001600160e01b03198116811461213957600080fd5b634e487b7160e01b600052601160045260246000fd5b8181038181111561050957610509612986565b8082018082111561050957610509612986565b60e0815260006129d560e083018b612164565b82810360208401526129e7818b612164565b90508860408401528281036060840152612a0281888a61239c565b608084019690965250506001600160a01b0392831660a0820152911660c09091015295945050505050565b838152604060208201526000612a4760408301848661239c565b95945050505050565b60006020808385031215612a6357600080fd5b82516001600160401b0380821115612a7a57600080fd5b818501915085601f830112612a8e57600080fd5b8151612a9c61264e826125e5565b81815260059190911b83018401908481019088831115612abb57600080fd5b8585015b8381101561292e57805185811115612ad75760008081fd5b8601603f81018b13612ae95760008081fd5b878101516040612afb61264e83612608565b8281528d82848601011115612b105760008081fd5b612b1f838c8301848701612140565b8652505050918601918601612abf565b600081612b3e57612b3e612986565b506000190190565b602080825282516001600160a01b0390811683830152838201518116604080850191909152808501516060808601919091528086015160c06080870152805160e0870181905260009594610100600583901b8901810195919493870193919290890190885b81811015612c055760ff198b8903018352855187815116895289810151858b8b0152612bd9868b0182612164565b918701518a83038b890152919050612bf18183612164565b995050509488019491880191600101612bab565b50505050505050608085015160a085015260a08501519150601f198482030160c0850152612a478183612164565b815160009082906020808601845b83811015612c5d57815185529382019390820190600101612c41565b50929695505050505050565b600181811c90821680612c7d57607f821691505b602082108103612c9d57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052602160045260246000fdfea2646970667358221220c2284ea0163aafd9aee402e7645e9db93d0c27667921732dd0458883520a475264736f6c634300081700338b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f000000000000000000000000b0403b32f54d0bd752113f4009e8b534c6669f44
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061012c5760003560e01c806383ebb771116100ad578063acb8cc4911610071578063acb8cc491461027f578063cef6d2091461029f578063e30c3978146102b2578063f2fde38b146102c3578063ffa1ad74146102d657600080fd5b806383ebb771146102065780638456cb591461020e57806384b0196e146102165780638da5cb5b14610231578063a3f4df7e1461024257600080fd5b806358909ebc116100f457806358909ebc146101b05780635c975abb146101d157806366134607146101e3578063715018a6146101f657806379ba5097146101fe57600080fd5b80631b13cac2146101315780632d40d0521461014d5780633ed01015146101805780633f4ba83a14610195578063499340471461019d575b600080fd5b61013a60001981565b6040519081526020015b60405180910390f35b61017061015b3660046120e6565b60046020526000908152604090205460ff1681565b6040519015158152602001610144565b61019361018e3660046120ff565b6102fa565b005b6101936103f4565b6101936101ab3660046120ff565b610406565b6101b9610a1181565b6040516001600160a01b039091168152602001610144565b600154600160a01b900460ff16610170565b61013a6101f13660046120ff565b6104f6565b61019361050f565b610193610521565b61013a61056a565b610193610579565b61021e610589565b6040516101449796959493929190612190565b6000546001600160a01b03166101b9565b610272604051806040016040528060118152602001702232b632b3b0ba34b7b726b0b730b3b2b960791b81525081565b6040516101449190612229565b610272604051806040016040528060018152602001603160f81b81525081565b6101936102ad366004612287565b6105cf565b6001546001600160a01b03166101b9565b6101936102d136600461233c565b611891565b610272604051806040016040528060058152602001640312e332e360dc1b81525081565b61030a604082016020830161233c565b6001600160a01b03811633146103335760405163b9f0f17160e01b815260040160405180910390fd5b600061033e836104f6565b60008181526004602052604090205490915060ff1661037057604051637952fbad60e11b815260040160405180910390fd5b6000818152600460209081526040909120805460ff191690556103959084018461233c565b6001600160a01b03166103ae604085016020860161233c565b6001600160a01b0316827f3feadce88fc1b49db633a56fd5307ed6ee18734df83bcc4011daa720c9cd95f1866040516103e79190612484565b60405180910390a4505050565b6103fc611902565b61040461192f565b565b610416604082016020830161233c565b6001600160a01b038116331461043f5760405163b9f0f17160e01b815260040160405180910390fd5b600061044a836104f6565b60008181526004602052604090205490915060ff161561047c57604051625ecddb60e01b815260040160405180910390fd5b6000818152600460209081526040909120805460ff191660011790556104a49084018461233c565b6001600160a01b03166104bd604085016020860161233c565b6001600160a01b0316827fea589ba9473ee1fe77d352c7ed919747715a5d22931b972de9b02a907c66d5dd866040516103e79190612484565b600061050961050483612823565b611984565b92915050565b610517611902565b6104046000611a1f565b60015433906001600160a01b0316811461055e5760405163118cdaa760e01b81526001600160a01b03821660048201526024015b60405180910390fd5b61056781611a1f565b50565b6000610574611a38565b905090565b610581611902565b610404611b63565b60006060806000806000606061059d611ba6565b6105a5611bd3565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6105d7611c00565b8481811415806105e75750808414155b1561060557604051631bcaf69f60e01b815260040160405180910390fd5b6000816001600160401b0381111561061f5761061f612555565b60405190808252806020026020018201604052801561065257816020015b606081526020019060019003908161063d5790505b5090506000826001600160401b0381111561066f5761066f612555565b6040519080825280602002602001820160405280156106a257816020015b606081526020019060019003908161068d5790505b50905060005b83811015610c815760008a8a838181106106c4576106c461282f565b90506020028101906106d69190612845565b8101906106e3919061288b565b905080516000036107d1576040805160008082526020820190925290610765565b6107526040518060c0016040528060006001600160a01b0316815260200160006001600160a01b03168152602001600080191681526020016060815260200160008152602001606081525090565b8152602001906001900390816107045790505b508483815181106107785761077861282f565b602090810291909101015260006040519080825280602002602001820160405280156107ae578160200160208202803683370190505b508383815181106107c1576107c161282f565b6020026020010181905250610c78565b808483815181106107e4576107e461282f565b6020026020010181905250600081516001600160401b0381111561080a5761080a612555565b604051908082528060200260200182016040528015610833578160200160208202803683370190505b509050808484815181106108495761084961282f565b6020026020010181905250336001600160a01b0316826000815181106108715761087161282f565b6020026020010151600001516001600160a01b0316141580156108c65750610a116001600160a01b0316826000815181106108ae576108ae61282f565b6020026020010151600001516001600160a01b031614155b156108e457604051632d618d8160e21b815260040160405180910390fd5b60005b8251811015610ab55760008382815181106109045761090461282f565b6020026020010151905061091781611984565b8383815181106109295761092961282f565b60200260200101818152505080602001516001600160a01b03163b6000036109dc57600061099e61099461095b61056a565b86868151811061096d5761096d61282f565b602002602001015160405161190160f01b8152600281019290925260228201526042902090565b8360a00151611c2b565b905081602001516001600160a01b0316816001600160a01b0316146109d657604051630f6d9e4760e21b815260040160405180910390fd5b50610aac565b60006109fb6109e961056a565b85858151811061096d5761096d61282f565b9050600082602001516001600160a01b0316631626ba7e838560a001516040518363ffffffff1660e01b8152600401610a3592919061293b565b602060405180830381865afa158015610a52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a76919061295c565b6001600160e01b0319169050630b135d3f60e11b8114610aa95760405163155ff42760e01b815260040160405180910390fd5b50505b506001016108e7565b5060005b8251811015610c755760046000838381518110610ad857610ad861282f565b60209081029190910181015182528101919091526040016000205460ff1615610b14576040516302dd502960e11b815260040160405180910390fd5b60018351610b22919061299c565b8114610c2b5781610b348260016129af565b81518110610b4457610b4461282f565b6020026020010151838281518110610b5e57610b5e61282f565b60200260200101516040015114610b8857604051636f6a1b8760e11b815260040160405180910390fd5b600083610b968360016129af565b81518110610ba657610ba661282f565b6020026020010151600001519050610a116001600160a01b0316816001600160a01b031614158015610c075750806001600160a01b0316848381518110610bef57610bef61282f565b6020026020010151602001516001600160a01b031614155b15610c2557604051632d618d8160e21b815260040160405180910390fd5b50610c6d565b60001960001b838281518110610c4357610c4361282f565b60200260200101516040015114610c6d57604051636f6a1b8760e11b815260040160405180910390fd5b600101610ab9565b50505b506001016106a8565b5060005b83811015610ea6576000838281518110610ca157610ca161282f565b6020026020010151511115610e9e5760005b838281518110610cc557610cc561282f565b602002602001015151811015610e9c576000848381518110610ce957610ce961282f565b60200260200101518281518110610d0257610d0261282f565b602002602001015160600151905060005b8151811015610e92576000828281518110610d3057610d3061282f565b6020026020010151600001519050806001600160a01b031663414c3e33848481518110610d5f57610d5f61282f565b602002602001015160200151858581518110610d7d57610d7d61282f565b6020026020010151604001518f8f8a818110610d9b57610d9b61282f565b905060200201358e8e8b818110610db457610db461282f565b9050602002810190610dc69190612845565b8c8c81518110610dd857610dd861282f565b60200260200101518b81518110610df157610df161282f565b60200260200101518e8d81518110610e0b57610e0b61282f565b60200260200101518c81518110610e2457610e2461282f565b602002602001015160200151336040518963ffffffff1660e01b8152600401610e549897969594939291906129c2565b600060405180830381600087803b158015610e6e57600080fd5b505af1158015610e82573d6000803e3d6000fd5b5050505050806001019050610d13565b5050600101610cb3565b505b600101610c85565b5060005b838110156114ca57828181518110610ec457610ec461282f565b602002602001015151600003610f82573363d691c964898984818110610eec57610eec61282f565b90506020020135888885818110610f0557610f0561282f565b9050602002810190610f179190612845565b6040518463ffffffff1660e01b8152600401610f3593929190612a2d565b6000604051808303816000875af1158015610f54573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610f7c9190810190612a50565b506114c2565b60005b838281518110610f9757610f9761282f565b60200260200101515181101561116e576000848381518110610fbb57610fbb61282f565b60200260200101518281518110610fd457610fd461282f565b602002602001015160600151905060005b81518110156111645760008282815181106110025761100261282f565b6020026020010151600001519050806001600160a01b031663a145832a8484815181106110315761103161282f565b60200260200101516020015185858151811061104f5761104f61282f565b6020026020010151604001518f8f8a81811061106d5761106d61282f565b905060200201358e8e8b8181106110865761108661282f565b90506020028101906110989190612845565b8c8c815181106110aa576110aa61282f565b60200260200101518b815181106110c3576110c361282f565b60200260200101518e8d815181106110dd576110dd61282f565b60200260200101518c815181106110f6576110f661282f565b602002602001015160200151336040518963ffffffff1660e01b81526004016111269897969594939291906129c2565b600060405180830381600087803b15801561114057600080fd5b505af1158015611154573d6000803e3d6000fd5b5050505050806001019050610fe5565b5050600101610f85565b508281815181106111815761118161282f565b6020026020010151600184838151811061119d5761119d61282f565b6020026020010151516111b0919061299c565b815181106111c0576111c061282f565b6020026020010151602001516001600160a01b031663d691c9648989848181106111ec576111ec61282f565b905060200201358888858181106112055761120561282f565b90506020028101906112179190612845565b6040518463ffffffff1660e01b815260040161123593929190612a2d565b6000604051808303816000875af1158015611254573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261127c9190810190612a50565b5060008382815181106112915761129161282f565b60200260200101515190505b80156114c05760008483815181106112b7576112b761282f565b60200260200101516001836112cc919061299c565b815181106112dc576112dc61282f565b60200260200101516060015190506000815190505b80156114ad5760008261130560018461299c565b815181106113155761131561282f565b6020026020010151600001519050806001600160a01b031663d3eddcc584600185611340919061299c565b815181106113505761135061282f565b6020026020010151602001518560018661136a919061299c565b8151811061137a5761137a61282f565b6020026020010151604001518f8f8a8181106113985761139861282f565b905060200201358e8e8b8181106113b1576113b161282f565b90506020028101906113c39190612845565b8c8c815181106113d5576113d561282f565b602002602001015160018c6113ea919061299c565b815181106113fa576113fa61282f565b60200260200101518e8d815181106114145761141461282f565b602002602001015160018d611429919061299c565b815181106114395761143961282f565b602002602001015160200151336040518963ffffffff1660e01b81526004016114699897969594939291906129c2565b600060405180830381600087803b15801561148357600080fd5b505af1158015611497573d6000803e3d6000fd5b5050505050806114a690612b2f565b90506112f1565b5050806114b990612b2f565b905061129d565b505b600101610eaa565b5060005b838110156117465760008382815181106114ea576114ea61282f565b602002602001015151111561173e57600083828151811061150d5761150d61282f565b60200260200101515190505b801561173c5760008483815181106115335761153361282f565b6020026020010151600183611548919061299c565b815181106115585761155861282f565b60200260200101516060015190506000815190505b80156117295760008261158160018461299c565b815181106115915761159161282f565b6020026020010151600001519050806001600160a01b031663ed463367846001856115bc919061299c565b815181106115cc576115cc61282f565b602002602001015160200151856001866115e6919061299c565b815181106115f6576115f661282f565b6020026020010151604001518f8f8a8181106116145761161461282f565b905060200201358e8e8b81811061162d5761162d61282f565b905060200281019061163f9190612845565b8c8c815181106116515761165161282f565b602002602001015160018c611666919061299c565b815181106116765761167661282f565b60200260200101518e8d815181106116905761169061282f565b602002602001015160018d6116a5919061299c565b815181106116b5576116b561282f565b602002602001015160200151336040518963ffffffff1660e01b81526004016116e59897969594939291906129c2565b600060405180830381600087803b1580156116ff57600080fd5b505af1158015611713573d6000803e3d6000fd5b50505050508061172290612b2f565b905061156d565b50508061173590612b2f565b9050611519565b505b6001016114ce565b5060005b838110156118855760008382815181106117665761176661282f565b602002602001015151111561187d5760005b83828151811061178a5761178a61282f565b60200260200101515181101561187b57336001600160a01b03168483815181106117b6576117b661282f565b602002602001015160018685815181106117d2576117d261282f565b6020026020010151516117e5919061299c565b815181106117f5576117f561282f565b6020026020010151602001516001600160a01b03167f40dadaa36c6c2e3d7317e24757451ffb2d603d875f0ad5e92c5dd156573b187386858151811061183d5761183d61282f565b602002602001015184815181106118565761185661282f565b602002602001015160405161186b9190612b46565b60405180910390a3600101611778565b505b60010161174a565b50505050505050505050565b611899611902565b600180546001600160a01b0383166001600160a01b031990911681179091556118ca6000546001600160a01b031690565b6001600160a01b03167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b6000546001600160a01b031633146104045760405163118cdaa760e01b8152336004820152602401610555565b611937611c55565b6001805460ff60a01b191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6000807f88c1d2ecf185adf710588203a5f263f0ff61be0d33da39792cde19ba9aa4331e8360000151846020015185604001516119c48760600151611c7f565b6080808901516040805160208101989098526001600160a01b03968716908801529490931660608601529184015260a083015260c082015260e0015b60408051601f1981840301815291905280516020909101209392505050565b600180546001600160a01b031916905561056781611d4a565b6000306001600160a01b037f000000000000000000000000db9b1e94b5b69df7e401ddbede43491141047db316148015611a9157507f0000000000000000000000000000000000000000000000000000000000aa36a746145b15611abb57507f994d0679c1c7b99494c58021faa3299c993405a79baaf76c00260de639f64dba90565b610574604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f604240e1ed005b9ba256cb7011059bf4ae645812b834bbcb5b22c93e2d1185cc918101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b611b6b611c00565b6001805460ff60a01b1916600160a01b1790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586119673390565b60606105747f44656c65676174696f6e4d616e616765720000000000000000000000000000116002611d9a565b60606105747f31000000000000000000000000000000000000000000000000000000000000016003611d9a565b600154600160a01b900460ff16156104045760405163d93c066560e01b815260040160405180910390fd5b600080600080611c3b8686611e45565b925092509250611c4b8282611e92565b5090949350505050565b600154600160a01b900460ff1661040457604051638dfc202b60e01b815260040160405180910390fd5b60008082516001600160401b03811115611c9b57611c9b612555565b604051908082528060200260200182016040528015611cc4578160200160208202803683370190505b50905060005b8351811015611d1a57611cf5848281518110611ce857611ce861282f565b6020026020010151611f4f565b828281518110611d0757611d0761282f565b6020908102919091010152600101611cca565b5080604051602001611d2c9190612c33565b60405160208183030381529060405280519060200120915050919050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b606060ff8314611db457611dad83611fb0565b9050610509565b818054611dc090612c69565b80601f0160208091040260200160405190810160405280929190818152602001828054611dec90612c69565b8015611e395780601f10611e0e57610100808354040283529160200191611e39565b820191906000526020600020905b815481529060010190602001808311611e1c57829003601f168201915b50505050509050610509565b60008060008351604103611e7f5760208401516040850151606086015160001a611e7188828585611fef565b955095509550505050611e8b565b50508151600091506002905b9250925092565b6000826003811115611ea657611ea6612ca3565b03611eaf575050565b6001826003811115611ec357611ec3612ca3565b03611ee15760405163f645eedf60e01b815260040160405180910390fd5b6002826003811115611ef557611ef5612ca3565b03611f165760405163fce698f760e01b815260048101829052602401610555565b6003826003811115611f2a57611f2a612ca3565b03611f4b576040516335e2f38360e21b815260048101829052602401610555565b5050565b6000807f80ad7e1b04ee6d994a125f4714ca0720908bd80ed16063ec8aee4b88e9253e2d8360000151846020015180519060200120604051602001611a00939291909283526001600160a01b03919091166020830152604082015260600190565b60606000611fbd836120be565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084111561202a57506000915060039050826120b4565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa15801561207e573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166120aa575060009250600191508290506120b4565b9250600091508190505b9450945094915050565b600060ff8216601f81111561050957604051632cd44ac360e21b815260040160405180910390fd5b6000602082840312156120f857600080fd5b5035919050565b60006020828403121561211157600080fd5b81356001600160401b0381111561212757600080fd5b820160c0818503121561213957600080fd5b9392505050565b60005b8381101561215b578181015183820152602001612143565b50506000910152565b6000815180845261217c816020860160208601612140565b601f01601f19169290920160200192915050565b60ff60f81b881681526000602060e060208401526121b160e084018a612164565b83810360408501526121c3818a612164565b606085018990526001600160a01b038816608086015260a0850187905284810360c08601528551808252602080880193509091019060005b81811015612217578351835292840192918401916001016121fb565b50909c9b505050505050505050505050565b6020815260006121396020830184612164565b60008083601f84011261224e57600080fd5b5081356001600160401b0381111561226557600080fd5b6020830191508360208260051b850101111561228057600080fd5b9250929050565b600080600080600080606087890312156122a057600080fd5b86356001600160401b03808211156122b757600080fd5b6122c38a838b0161223c565b909850965060208901359150808211156122dc57600080fd5b6122e88a838b0161223c565b9096509450604089013591508082111561230157600080fd5b5061230e89828a0161223c565b979a9699509497509295939492505050565b80356001600160a01b038116811461233757600080fd5b919050565b60006020828403121561234e57600080fd5b61213982612320565b6000808335601e1984360301811261236e57600080fd5b83016020810192503590506001600160401b0381111561238d57600080fd5b80360382131561228057600080fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60008383855260208086019550808560051b830101846000805b8881101561247657858403601f19018a52823536899003605e19018112612404578283fd5b880160606001600160a01b0361241983612320565b16865261242887830183612357565b828989015261243a838901828461239c565b92505050604061244c81840184612357565b93508783038289015261246083858361239c565b9d89019d975050509386019350506001016123df565b509198975050505050505050565b6020815260006001600160a01b038061249c85612320565b166020840152806124af60208601612320565b16604084015250604083013560608301526060830135601e198436030181126124d757600080fd5b83016020810190356001600160401b038111156124f357600080fd5b8060051b360382131561250557600080fd5b60c0608085015261251a60e0850182846123c5565b915050608084013560a084015261253460a0850185612357565b848303601f190160c086015261254b83828461239c565b9695505050505050565b634e487b7160e01b600052604160045260246000fd5b604051606081016001600160401b038111828210171561258d5761258d612555565b60405290565b60405160c081016001600160401b038111828210171561258d5761258d612555565b604051601f8201601f191681016001600160401b03811182821017156125dd576125dd612555565b604052919050565b60006001600160401b038211156125fe576125fe612555565b5060051b60200190565b60006001600160401b0382111561262157612621612555565b50601f01601f191660200190565b600082601f83011261264057600080fd5b813561265361264e82612608565b6125b5565b81815284602083860101111561266857600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261269657600080fd5b813560206126a661264e836125e5565b82815260059290921b840181019181810190868411156126c557600080fd5b8286015b848110156127745780356001600160401b03808211156126e95760008081fd5b908801906060828b03601f19018113156127035760008081fd5b61270b61256b565b612716888501612320565b81526040808501358481111561272c5760008081fd5b61273a8e8b8389010161262f565b838b0152509184013591838311156127525760008081fd5b6127608d8a8588010161262f565b9082015286525050509183019183016126c9565b509695505050505050565b600060c0828403121561279157600080fd5b612799612593565b90506127a482612320565b81526127b260208301612320565b60208201526040820135604082015260608201356001600160401b03808211156127db57600080fd5b6127e785838601612685565b60608401526080840135608084015260a084013591508082111561280a57600080fd5b506128178482850161262f565b60a08301525092915050565b6000610509368361277f565b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261285c57600080fd5b8301803591506001600160401b0382111561287657600080fd5b60200191503681900382131561228057600080fd5b6000602080838503121561289e57600080fd5b82356001600160401b03808211156128b557600080fd5b818501915085601f8301126128c957600080fd5b81356128d761264e826125e5565b81815260059190911b830184019084810190888311156128f657600080fd5b8585015b8381101561292e578035858111156129125760008081fd5b6129208b89838a010161277f565b8452509186019186016128fa565b5098975050505050505050565b8281526040602082015260006129546040830184612164565b949350505050565b60006020828403121561296e57600080fd5b81516001600160e01b03198116811461213957600080fd5b634e487b7160e01b600052601160045260246000fd5b8181038181111561050957610509612986565b8082018082111561050957610509612986565b60e0815260006129d560e083018b612164565b82810360208401526129e7818b612164565b90508860408401528281036060840152612a0281888a61239c565b608084019690965250506001600160a01b0392831660a0820152911660c09091015295945050505050565b838152604060208201526000612a4760408301848661239c565b95945050505050565b60006020808385031215612a6357600080fd5b82516001600160401b0380821115612a7a57600080fd5b818501915085601f830112612a8e57600080fd5b8151612a9c61264e826125e5565b81815260059190911b83018401908481019088831115612abb57600080fd5b8585015b8381101561292e57805185811115612ad75760008081fd5b8601603f81018b13612ae95760008081fd5b878101516040612afb61264e83612608565b8281528d82848601011115612b105760008081fd5b612b1f838c8301848701612140565b8652505050918601918601612abf565b600081612b3e57612b3e612986565b506000190190565b602080825282516001600160a01b0390811683830152838201518116604080850191909152808501516060808601919091528086015160c06080870152805160e0870181905260009594610100600583901b8901810195919493870193919290890190885b81811015612c055760ff198b8903018352855187815116895289810151858b8b0152612bd9868b0182612164565b918701518a83038b890152919050612bf18183612164565b995050509488019491880191600101612bab565b50505050505050608085015160a085015260a08501519150601f198482030160c0850152612a478183612164565b815160009082906020808601845b83811015612c5d57815185529382019390820190600101612c41565b50929695505050505050565b600181811c90821680612c7d57607f821691505b602082108103612c9d57634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052602160045260246000fdfea2646970667358221220c2284ea0163aafd9aee402e7645e9db93d0c27667921732dd0458883520a475264736f6c63430008170033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000b0403b32f54d0bd752113f4009e8b534c6669f44
-----Decoded View---------------
Arg [0] : _owner (address): 0xB0403B32f54d0Bd752113f4009e8B534C6669f44
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000b0403b32f54d0bd752113f4009e8b534c6669f44
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
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.