Source Code
Overview
MON Balance
MON Value
$0.00Latest 25 from a total of 290 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Fulfill Limit Or... | 42717029 | 38 days ago | IN | 0 MON | 0.52643485 | ||||
| Fulfill Limit Or... | 42716729 | 38 days ago | IN | 0 MON | 0.4663546 | ||||
| Fulfill Limit Or... | 42715681 | 38 days ago | IN | 0 MON | 0.47671189 | ||||
| Fulfill Limit Or... | 42714029 | 38 days ago | IN | 0 MON | 0.27375943 | ||||
| Fulfill Limit Or... | 42710381 | 38 days ago | IN | 0 MON | 0.20717144 | ||||
| Fulfill Limit Or... | 42710249 | 38 days ago | IN | 0 MON | 0.39671072 | ||||
| Fulfill Limit Or... | 42710241 | 38 days ago | IN | 0 MON | 0.37678225 | ||||
| Fulfill Limit Or... | 42398337 | 40 days ago | IN | 0 MON | 0.50356563 | ||||
| Fulfill Limit Or... | 39225781 | 54 days ago | IN | 0 MON | 0.51665361 | ||||
| Fulfill Limit Or... | 39225667 | 54 days ago | IN | 0 MON | 0.44955515 | ||||
| Fulfill Limit Or... | 39225661 | 54 days ago | IN | 0 MON | 0.28794421 | ||||
| Fulfill Limit Or... | 39225639 | 54 days ago | IN | 0 MON | 0.37138735 | ||||
| Fulfill Limit Or... | 39223374 | 54 days ago | IN | 0 MON | 0.2846274 | ||||
| Fulfill Limit Or... | 39222618 | 54 days ago | IN | 0 MON | 0.31419752 | ||||
| Fulfill Limit Or... | 39222419 | 54 days ago | IN | 0 MON | 0.37355732 | ||||
| Fulfill Limit Or... | 39221731 | 54 days ago | IN | 0 MON | 0.3334601 | ||||
| Fulfill Limit Or... | 39221151 | 54 days ago | IN | 0 MON | 0.27336626 | ||||
| Fulfill Limit Or... | 39219987 | 54 days ago | IN | 0 MON | 0.41030399 | ||||
| Fulfill Limit Or... | 39219878 | 54 days ago | IN | 0 MON | 0.29842961 | ||||
| Fulfill Limit Or... | 39219852 | 54 days ago | IN | 0 MON | 0.20962512 | ||||
| Fulfill Limit Or... | 39219827 | 54 days ago | IN | 0 MON | 0.32861829 | ||||
| Fulfill Limit Or... | 39219609 | 54 days ago | IN | 0 MON | 0.40113417 | ||||
| Fulfill Limit Or... | 39219473 | 54 days ago | IN | 0 MON | 0.29695162 | ||||
| Fulfill Limit Or... | 39219472 | 54 days ago | IN | 0 MON | 0.27194202 | ||||
| Fulfill Limit Or... | 39187079 | 55 days ago | IN | 0 MON | 0.20693107 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x4D7BB9A4...f00215A87 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
SingleChainGuardLimit
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 999999 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import "./base/SingleChainGuard.sol";
import "./interfaces/ISingleChainGuardLimit.sol";
import "./libraries/SingleChainLimitOrderLib.sol";
/// @notice Smart contract for handling single chain Limit orders
contract SingleChainGuardLimit is SingleChainGuard, EIP712, ISingleChainGuardLimit {
using SingleChainLimitOrderLib for SingleChainLimitOrder;
using SingleChainLimitOrderLib for SingleChainLimitSolverPermission;
using SafeERC20 for IERC20;
mapping (bytes32 orderHash => bool) public orderManuallyInitialized;
event OrderFulfilled(bytes32 indexed orderHash, uint256 mainAmountOut);
event OrderManuallyCancelled(bytes32 orderHash);
error OrderWasAlreadyManuallyInitialized();
error OrderWasNotManuallyInitialized();
/// @param initialOwner Initial smart contract owner
/// @param _auctioneer Initial auctioneer address. Auctioneer is authority role, that signs important data.
/// @param _permit2 Permit2 contract address.
/// @param _externalCallHandler ExternalCallHandler contract
constructor(
address initialOwner,
address _auctioneer,
ISignatureTransfer _permit2,
IExternalCallHandler _externalCallHandler
)
EIP712("SingleChainGuardLimit", "1")
SingleChainGuard(_auctioneer, _permit2, _externalCallHandler)
Ownable(initialOwner)
{}
/// @inheritdoc ISingleChainGuardLimit
function createOrderManually(SingleChainLimitOrder calldata order) external {
if (msg.sender != order.user) revert NotAUser();
if (order.amountIn == 0 || order.requestedOutput.receiver == address(0)) revert InvalidOrder();
if (order.deadline < block.timestamp) revert OverdueDeadline();
if (order.tokenIn == address(0)) revert ZeroAddress();
bytes32 orderHash = order.hash();
if (orderManuallyInitialized[orderHash]) revert OrderWasAlreadyManuallyInitialized();
uint256 balanceBefore = IERC20(order.tokenIn).balanceOf(address(this));
IERC20(order.tokenIn).safeTransferFrom(msg.sender, address(this), order.amountIn);
uint256 received = IERC20(order.tokenIn).balanceOf(address(this)) - balanceBefore;
if (received < order.amountIn) revert FeeOnTransferTokensNotSupported();
orderManuallyInitialized[orderHash] = true;
emit OrderManuallyInitialized(orderHash);
}
/// @inheritdoc ISingleChainGuardLimit
function fulfillLimitOrder(
uint256 promisedAmountOut,
SingleChainLimitOrder calldata order,
bytes calldata userSignature,
SingleChainLimitSolverPermission calldata permission,
bytes calldata auctioneerSignature,
ISingleChainIntentFulfiller fulfillerContract,
bytes calldata callBackData,
bool orderWasInitializedManually
) external {
bytes32 orderHash = order.hash();
_validateOrderFulfillment(
orderHash,
promisedAmountOut,
order,
permission,
auctioneerSignature
);
if (orderWasInitializedManually) {
if (!orderManuallyInitialized[orderHash]) {
revert OrderWasNotManuallyInitialized();
}
orderManuallyInitialized[orderHash] = false;
IERC20(order.tokenIn).safeTransfer(address(fulfillerContract), order.amountIn);
} else {
_transferTokensInWithPermit(orderHash, order, userSignature, fulfillerContract);
}
uint256 mainAmountOut = _fulfillLimitOrder(
promisedAmountOut,
order,
permission,
fulfillerContract,
callBackData
);
emit OrderFulfilled(orderHash, mainAmountOut);
}
/// @inheritdoc ISingleChainGuardLimit
function cancelManuallyCreatedOrder(SingleChainLimitOrder calldata order) external {
if (msg.sender != order.user) revert NotAUser();
bytes32 orderHash = order.hash();
if (!orderManuallyInitialized[orderHash]) revert OrderWasNotManuallyInitialized();
IERC20(order.tokenIn).safeTransfer(order.user, order.amountIn);
orderManuallyInitialized[orderHash] = false;
emit OrderManuallyCancelled(orderHash);
}
/// @notice Validates inputs for the order fulfillment
/// @param orderHash Order hash
/// @param promisedAmountOut Amount of tokens OUT that `msg.sender` promises to deliver to `tokenOutDestinationAddress`
/// Allows fulfilling order for non-solver accounts
/// if `promisedAmountOut >= permission.amountOutMin * (10_000 + EXCLUSIVITY_OVERRIDE) / 10_000`'
/// @param order Order data, signed by the user
/// @param permission Permission data, signed by auctioneer
/// @param auctioneerSignature Auctioneer signature
function _validateOrderFulfillment(
bytes32 orderHash,
uint256 promisedAmountOut,
SingleChainLimitOrder calldata order,
SingleChainLimitSolverPermission calldata permission,
bytes calldata auctioneerSignature
) internal view {
if (
order.amountIn == 0 || order.requestedOutput.receiver == address(0)
) revert InvalidOrder();
if (order.deadline < block.timestamp || permission.permissionDeadline < block.timestamp) {
revert OverdueDeadline();
}
if (permission.solver != msg.sender) {
// Allow fulfilling order to non-solver account it it can deliver at least EXCLUSIVITY_OVERRIDE more tokens OUT
if (promisedAmountOut < permission.amountOutMin * (10_000 + EXCLUSIVITY_OVERRIDE) / 10_000) {
revert NotASolver();
}
}
if (promisedAmountOut < permission.amountOutMin) revert InvalidPromisedAmountOut();
if (orderHash != permission.orderHash) revert InvalidPermission();
// Checking Auctioneer's signature
{
(address recovered, ECDSA.RecoverError err, ) = ECDSA.tryRecover(
_hashTypedDataV4(permission.hash()),
auctioneerSignature
);
if (err != ECDSA.RecoverError.NoError || recovered == address(0) || recovered != auctioneer) {
revert InvalidAuctioneerSignature();
}
}
}
/// @notice Transfer Tokens IN with Permit2 to destination address. Avoiding Stack too deep error
/// @param orderHash Order hash
/// @param order Order data, signed by the user
/// @param userSignature Permit2 user signature
/// @param fulfillerContract Filler contract, passed by the Solver that will receive tokens IN and fulfill the order
function _transferTokensInWithPermit(
bytes32 orderHash,
SingleChainLimitOrder calldata order,
bytes calldata userSignature,
ISingleChainIntentFulfiller fulfillerContract
) private {
address transferDestination = address(fulfillerContract);
uint256 balanceBefore = IERC20(order.tokenIn).balanceOf(transferDestination);
permit2.permitWitnessTransferFrom(
order.toPermit(),
order.transferDetails(transferDestination),
order.user,
orderHash,
SingleChainLimitOrderLib.PERMIT2_ORDER_TYPE,
userSignature
);
uint256 received = IERC20(order.tokenIn).balanceOf(transferDestination) - balanceBefore;
if (received < order.amountIn) revert FeeOnTransferTokensNotSupported();
}
/// @notice Fulfills limit order
/// @param promisedAmountOut Amount of tokens OUT that `msg.sender` promises to deliver to `tokenOutDestinationAddress`
/// Allows fulfilling order for non-solver accounts
/// if `promisedAmountOut >= permission.amountOutMin * (10_000 + EXCLUSIVITY_OVERRIDE) / 10_000`'
/// @param order Order data, signed by the user
/// @param permission Permission data, signed by auctioneer
/// @param fulfillerContract Filler contract, passed by the Solver that will receive tokens IN and fulfill the order
/// @param callBackData Encoded data that will be used by Filler contract
/// @return mainAmountOut Main Amount OUT
function _fulfillLimitOrder(
uint256 promisedAmountOut,
SingleChainLimitOrder calldata order,
SingleChainLimitSolverPermission calldata permission,
ISingleChainIntentFulfiller fulfillerContract,
bytes calldata callBackData
) internal returns(uint256 mainAmountOut) {
RequestedTransferLib.TransferData memory mainTransfer = RequestedTransferLib.TransferData({
token: order.requestedOutput.token,
receiver: order.requestedOutput.receiver,
amount: promisedAmountOut
});
mainAmountOut = _fulfillSingleChainIntent(FulfillmentDetails({
tokenIn: order.tokenIn,
amountIn: order.amountIn,
mainTransfer: mainTransfer,
protocolFeeTransfer: permission.protocolFeeTransfer,
extraTransfers: order.extraTransfers,
fulfiller: fulfillerContract,
callBackData: callBackData,
encodedExternalCallData: order.encodedExternalCallData
}));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (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.
*
* Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
*/
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.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";// 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: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/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 recovered, RecoverError err, bytes32 errArg) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
assembly ("memory-safe") {
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 recovered, RecoverError err, bytes32 errArg) {
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 recovered, RecoverError err, bytes32 errArg) {
// 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.1.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
// OpenZeppelin Contracts (last updated v5.1.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) {
assembly ("memory-safe") {
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) {
assembly ("memory-safe") {
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.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2²⁵⁶ + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= prod1) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 exp;
unchecked {
exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
value >>= exp;
result += exp;
exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
value >>= exp;
result += exp;
exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
value >>= exp;
result += exp;
exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
value >>= exp;
result += exp;
exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
value >>= exp;
result += exp;
exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
value >>= exp;
result += exp;
exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
value >>= exp;
result += exp;
result += SafeCast.toUint(value > 1);
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 isGt;
unchecked {
isGt = SafeCast.toUint(value > (1 << 128) - 1);
value >>= isGt * 128;
result += isGt * 16;
isGt = SafeCast.toUint(value > (1 << 64) - 1);
value >>= isGt * 64;
result += isGt * 8;
isGt = SafeCast.toUint(value > (1 << 32) - 1);
value >>= isGt * 32;
result += isGt * 4;
isGt = SafeCast.toUint(value > (1 << 16) - 1);
value >>= isGt * 16;
result += isGt * 2;
result += SafeCast.toUint(value > (1 << 8) - 1);
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
}
}
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
// Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
// taking advantage of the most significant (or "sign" bit) in two's complement representation.
// This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
// the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
int256 mask = n >> 255;
// A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
return uint256((n + mask) ^ mask);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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);
assembly ("memory-safe") {
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.1.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 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* 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;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 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) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
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) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
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) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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;
assembly ("memory-safe") {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly ("memory-safe") {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
* representation, according to EIP-55.
*/
function toChecksumHexString(address addr) internal pure returns (string memory) {
bytes memory buffer = bytes(toHexString(addr));
// hash the hex part of buffer (skip length + 2 bytes, length 40)
uint256 hashValue;
assembly ("memory-safe") {
hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
}
for (uint256 i = 41; i > 1; --i) {
// possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
// case shift by xoring with 0x20
buffer[i] ^= 0x20;
}
hashValue >>= 4;
}
return string(buffer);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/access/Ownable2Step.sol";
import "../interfaces/ISingleChainIntentFulfiller.sol";
import "../libraries/RequestedTransferLib.sol";
import "../Permit2/interfaces/ISignatureTransfer.sol";
import "../interfaces/IExternalCallHandler.sol";
/// @title Abstract smart contract that checks order fulfillment for any intent type
abstract contract SingleChainGuard is Ownable2Step {
using RequestedTransferLib for RequestedTransferLib.TransferData[];
using SafeERC20 for IERC20;
ISignatureTransfer public immutable permit2;
IExternalCallHandler public immutable externalCallHandler;
struct FulfillmentDetails {
/// Token IN that Fulfiller contract will receive before the call
address tokenIn;
/// Amount of tokens IN that Fulfiller contract will receive before the call
uint256 amountIn;
/// Token OUT, token OUT destination and min amount OUT
RequestedTransferLib.TransferData mainTransfer;
/// Protocol fee token, amount and receiver
RequestedTransferLib.TransferData protocolFeeTransfer;
/// Extra transfers requested for order fulfillment
RequestedTransferLib.TransferData[] extraTransfers;
/// Fulfiller contract address, passed by the Solver
ISingleChainIntentFulfiller fulfiller;
/// Encoded execution data to decode on Fulfiller contract (Will used for swaps execution, etc.)
bytes callBackData;
/// abi.encoded external call data. bytes(0) if external call is not required
/// Encoded data:
// - address fallbackAddress,
// - address callTarget,
// - bytes memory callData,
// - CallMode callMode
bytes encodedExternalCallData;
}
/// % in basis points, that non-exclusive solver needs to improve output amount to be able to fulfill the order
uint256 internal constant EXCLUSIVITY_OVERRIDE = 1000; // 10%
address public auctioneer;
event AuctioneerSet(address);
event OrderManuallyInitialized(bytes32 orderHash);
error FeeOnTransferTokensNotSupported();
error InvalidAuctioneerSignature();
error InvalidOrder();
error InvalidPermission();
error InvalidPromisedAmountOut();
error NotAUser();
error NotASolver();
error OverdueDeadline();
error ZeroAddress();
/// @param _auctioneer Initial auctioneer address. Auctioneer is authority role, that signs important data.
/// @param _permit2 Permit2 contract address.
/// @param _externalCallHandler ExternalCallHandler contract
constructor(
address _auctioneer,
ISignatureTransfer _permit2,
IExternalCallHandler _externalCallHandler
) {
if (
_auctioneer == address(0)
|| address(_permit2) == address(0)
|| address(_externalCallHandler) == address(0)
) revert ZeroAddress();
auctioneer = _auctioneer;
permit2 = _permit2;
externalCallHandler = _externalCallHandler;
}
/// @notice Fulfills any single chain intent by calling `ISingleChainIntentFulfiller.fulfillSingleChainIntent`
/// callback and checking that all requested actions were executed.
/// @param details Fulfillment details, contained in struct to avoid 'stack too deep' error
/// * tokenIn Token IN that Fulfiller contract will receive before the call
/// * amountIn Amount of tokens IN that Fulfiller contract will receive before the call
/// * mainTransfer Token OUT, token OUT destination and min amount OUT
/// * protocolFeeTransfer Protocol fee token, amount and receiver
/// * extraTransfers Extra transfers requested for order fulfillment
/// * fulfiller Fulfiller contract address, passed by the Solver
/// * callBackData Encoded execution data to decode on Fulfiller contract (Will used for swaps execution, etc.)
/// @return mainAmountOut Main Amount OUT
function _fulfillSingleChainIntent(
FulfillmentDetails memory details
) internal returns(uint256 mainAmountOut) {
bool externalCallRequested = details.encodedExternalCallData.length != 0;
// Since there may be an edge case when same receiver may receive same tokens multiple times
// we want to accumulate that data before execution
RequestedTransferLib.TransferData[] memory requestedTransfers = new RequestedTransferLib.TransferData[](
// main transfer + protocol fee + extra transfers
2 + details.extraTransfers.length
);
uint256 uniqueTransfersNum = 0;
// Collecting `requestedTransfers`
{
// Token OUT
uniqueTransfersNum = requestedTransfers.accumulateOrAppend(
uniqueTransfersNum,
RequestedTransferLib.TransferData({
token: details.mainTransfer.token,
receiver: externalCallRequested
? address(externalCallHandler)
: details.mainTransfer.receiver,
amount: details.mainTransfer.amount
})
);
// Protocol fee
uniqueTransfersNum = requestedTransfers.accumulateOrAppend(
uniqueTransfersNum,
details.protocolFeeTransfer
);
// Extra transfers
for (uint256 i = 0; i < details.extraTransfers.length; i++) {
uniqueTransfersNum = requestedTransfers.accumulateOrAppend(
uniqueTransfersNum,
details.extraTransfers[i]
);
}
// decrease array length
assembly {
mstore(requestedTransfers, uniqueTransfersNum)
}
}
uint256[] memory preBalances = requestedTransfers.getBalances();
// Token IN should be already transferred to Filler contract
details.fulfiller.fulfillSingleChainIntent(
details.tokenIn,
details.amountIn,
requestedTransfers,
details.callBackData
);
mainAmountOut = requestedTransfers.verifyFulfillment(preBalances);
if (externalCallRequested) {
_handleExternalCall(details.mainTransfer, details.encodedExternalCallData);
}
}
/// @notice Decodes external call data and calls ExternalCallHandler
/// @param mainTransfer Main transfer data
/// @param encodedExternalCallData abi.encoded external call data
/// @dev By the time of this call ExternalCallHandler contract should have the tokens
function _handleExternalCall(
RequestedTransferLib.TransferData memory mainTransfer,
bytes memory encodedExternalCallData
) internal {
(
address fallbackAddress,
address callTarget,
bytes memory callData,
IExternalCallExecutioner.CallMode callMode
) = abi.decode(
encodedExternalCallData,
(address, address, bytes, IExternalCallExecutioner.CallMode)
);
externalCallHandler.executeCall(
mainTransfer.token,
mainTransfer.receiver,
payable(fallbackAddress),
callTarget,
callData,
callMode
);
}
/// @notice Set new auctioneer address
/// @param newAuctioneer New auctioneer address. Auctioneer is authority role, that signs important data.
/// @dev Can be called only by the owner
function setAuctioneer(address newAuctioneer) external onlyOwner {
if (newAuctioneer == address(0)) revert ZeroAddress();
auctioneer = newAuctioneer;
emit AuctioneerSet(newAuctioneer);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "../libraries/CrossChainExternalCall.sol";
interface IExternalCallExecutioner {
enum CallMode {
/// Approve tokens to call target and call it
/// If tokens are not taken - send to fallback address
/// If token is native (address(0)) use msg.value to send tokens
ApproveAndCall,
/// Transfer tokens to call target and call it
/// If token is native (address(0)) use `call` to send tokens
TransferAndCall
}
/// @notice Executes requested call with approving or transferring all remaining tokens
/// @param token ERC20 token address or address(0) for Native currency
/// @param destinationAddress Main token destination address.
/// For `CallMode.ApproveAndCall` tokens are approved to this address
/// For `CallMode.TransferAndCall` tokens are transferred to this address
/// @param balance Current token balance of this contract
/// @param callTarget Smart contract address that must be called
/// @param callData Calldata that should be passed to the call
/// @param callMode Call mode:
/// - ApproveAndCall
/// Approve tokens to call target and call it
/// If tokens are not taken - send to fallback address
/// If token is native (address(0)) msg.value will be used to send tokens
/// - TransferAndCall
/// Transfer tokens to call target and call it
/// If token is native (address(0)) `call` will be used to send tokens
/// @dev Should not be called externally. Main purpose of this function is using it in try-catch approach
function executeCall_Internal(
address token,
address destinationAddress,
uint256 balance,
address callTarget,
bytes calldata callData,
CallMode callMode
) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./IExternalCallExecutioner.sol";
interface IExternalCallHandler {
event FailedExternalCall(address callTarget);
error ExternalCallFailed(bytes errorData);
/// @notice Tries to Execute requested call with approving or transferring all available tokens
/// @param token ERC20 token address or address(0) for Native currency
/// @param destinationAddress Main token destination address.
/// For `CallMode.ApproveAndCall` tokens are approved to this address
/// For `CallMode.TransferAndCall` tokens are transferred to this address
/// @param fallbackAddress Receiver of tokens in case of external call failure or if callTarget did not take all
/// available tokens during `CallMode.ApproveAndCall`.
/// address(0) if call will require success
/// @param callTarget Smart contract address that must be called
/// @param callData Calldata that should be passed to the call
/// @param callMode Call mode:
/// - ApproveAndCall
/// Approve tokens to call target and call it
/// If tokens are not taken - send to fallback address
/// If token is native (address(0)) msg.value will be used to send tokens
/// - TransferAndCall
/// Transfer tokens to call target and call it
/// If token is native (address(0)) `call` will be used to send tokens
function executeCall(
address token,
address destinationAddress,
address payable fallbackAddress,
address callTarget,
bytes calldata callData,
IExternalCallExecutioner.CallMode callMode
) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "../base/SingleChainGuard.sol";
// User signs SingleChainLimitOrder as a part of Permit2 struct
// Data is signed and provided by front end
struct SingleChainLimitOrder {
/// The address of the user which created the order
/// User address must be same as a signer of Permit2 approval
address user;
/// Token that will be spent
/// Token IN address must be same as token address in Permit2 approval
address tokenIn;
/// Amount of tokens to spend
uint256 amountIn;
/// Requested main Transfer OUT data:
/// - Requested token OUT address
/// - Address that should receive tokens OUT
/// - Minimum amount of tokens OUT
RequestedTransferLib.TransferData requestedOutput;
/// Array of requested extra transfers that should be executed as well
RequestedTransferLib.TransferData[] extraTransfers;
/// abi.encoded external call data. bytes(0) if external call is not required
/// Encoded data:
/// - address payable fallbackAddress,
/// - address callTarget,
/// - bytes memory callData,
/// - CallMode callMode
bytes encodedExternalCallData;
/// Deadline, until when this order must be fulfilled. Must be in the future
uint32 deadline;
/// Number that can be only used once, for Permit2
uint256 nonce;
}
// Permission to signed by the Auctioneer and provided to the Solver
// after choosing this Solver
// Should be signed according to signTypedData_v4 standard by the Auctioneer
// Values are set by Auctioneer
struct SingleChainLimitSolverPermission {
/// The address of the solver that's allowed to fulfill this order
/// May be ignored if `msg.sender` promised amount of tokens OUT higher than `amountOutMin`
/// by `EXCLUSIVITY_OVERRIDE` %
address solver;
/// Hash of the order that is allowed to be processed
bytes32 orderHash;
/// Minimum amount of tokens OUT that Solver must deliver.
/// Must be >= `SingleChainLimitOrder.amountOutMin`
uint256 amountOutMin;
/// Protocol fee data:
/// - Address of the token that should be collected as protocol fee. Set in permission for more flexibility
/// - Receiver address of protocol fees.
/// Signed by Auctioneer to allow having different receiver.
/// Not stored in smart contract to decrease gas cost.
/// - Amount of protocol fee tokens that solver needs to pay for taking the order
RequestedTransferLib.TransferData protocolFeeTransfer;
/// Deadline, until this permission is valid
uint32 permissionDeadline;
}
interface ISingleChainGuardLimit {
/// @notice Lock tokens IN and initialize the order. Should be used for smart contracts that want to
/// create order and don't support IERC1271
/// @param order Order data
function createOrderManually(SingleChainLimitOrder calldata order) external;
/// @notice Fulfill limit order
/// @param promisedAmountOut Amount of tokens OUT that `msg.sender` promises to deliver to `tokenOutDestinationAddress`
/// Allows fulfilling order for non-solver accounts
/// if `promisedAmountOut >= permission.amountOutMin * (10_000 + EXCLUSIVITY_OVERRIDE) / 10_000`'
/// @param order Order data, signed by the user
/// @param userSignature Permit2 user signature
/// @param permission Permission data, signed by auctioneer
/// @param auctioneerSignature Auctioneer signature
/// @param fulfillerContract Filler contract, passed by the Solver that will receive tokens IN and fulfill the order
/// @param callBackData Encoded data that will be used by Filler contract
/// @param orderWasInitializedManually `true` if order was initialized with `createOrderManually` function
function fulfillLimitOrder(
uint256 promisedAmountOut,
SingleChainLimitOrder calldata order,
bytes calldata userSignature,
SingleChainLimitSolverPermission calldata permission,
bytes calldata auctioneerSignature,
ISingleChainIntentFulfiller fulfillerContract,
bytes calldata callBackData,
bool orderWasInitializedManually
) external;
/// @notice Cancels manually created (by calling `createOrderManually` function) order
/// and unlocks tokens IN
/// @param order Order data
function cancelManuallyCreatedOrder(SingleChainLimitOrder calldata order) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "../libraries/RequestedTransferLib.sol";
interface ISingleChainIntentFulfiller {
receive() external payable;
/// @notice Fulfills intent by receiving tokens IN, providing tokens OUT,
/// sending extra transfers, paying fees, etc.
/// @param tokenIn Token IN that contract receives before the call
/// @param amountIn Amount of tokens IN that contract receives before the call
/// @param requestedTransfers Array of requested transfers (token, receiver, minAmount)
/// @param data Encoded execution data to decode on smart contract (Will used for swaps execution, etc.)
function fulfillSingleChainIntent(
address tokenIn,
uint256 amountIn,
RequestedTransferLib.TransferData[] calldata requestedTransfers,
bytes calldata data
) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./RequestedTransferLib.sol";
import "../interfaces/IExternalCallExecutioner.sol";
/// @title Cross chain order fulfillment struct handling
/// Required data to fulfill order on destination chain with external call
library CrossChainExternalCall {
struct RequestedFulfillmentWithExternalCall {
/// Order ID
string orderId;
/// Fulfillment deadline, in seconds
uint256 deadline;
/// Main token address. address(0) for native token
address token;
/// Main token destination address.
/// For `CallMode.ApproveAndCall` tokens are approved to this address
/// For `CallMode.TransferAndCall` tokens are transferred to this address
address tokenDestination;
/// Main token amount
/// For `CallMode.ApproveAndCall` this is minimum approval amount
/// For `CallMode.TransferAndCall` this is minimum transfer amount
uint256 requestedAmount;
/// Contract address that must be called
address callTarget;
/// Call data of requested call to `callTarget`
bytes callData;
/// Requested call mode
IExternalCallExecutioner.CallMode callMode;
/// In case of failed call, tokens will be sent to `fallbackAddress`
/// All remaining main tokens and tokens from extra transfers will also be sent to `fallbackAddress`
address fallbackAddress;
/// Array of requested extra transfers
RequestedTransferLib.TransferData[] extraTransfers;
}
bytes internal constant REQUESTED_FULFILLMENT_TYPE = abi.encodePacked(
abi.encodePacked(
"RequestedFulfillmentWithExternalCall(",
"string orderId,",
"uint256 deadline,",
"address token,",
"address tokenDestination,",
"uint256 requestedAmount,",
"address callTarget,",
"bytes callData,",
"uint8 callMode,",
"address fallbackAddress,",
"TransferData[] extraTransfers)"
),
RequestedTransferLib.TRANSFER_TYPE
);
bytes32 internal constant REQUESTED_FULFILLMENT_TYPE_HASH = keccak256(REQUESTED_FULFILLMENT_TYPE);
/// @notice Hash requested fulfillment data
/// @param requestedFulfillment Requested fulfillment data
/// @return EIP-712 hash
function hash(
RequestedFulfillmentWithExternalCall calldata requestedFulfillment
) internal pure returns (bytes32) {
bytes32[] memory extraTransferHashes = new bytes32[](requestedFulfillment.extraTransfers.length);
for (uint256 i = 0; i < extraTransferHashes.length; i++) {
extraTransferHashes[i] = RequestedTransferLib.hash(
requestedFulfillment.extraTransfers[i]
);
}
return keccak256(
abi.encode(
REQUESTED_FULFILLMENT_TYPE_HASH,
keccak256(bytes(requestedFulfillment.orderId)),
requestedFulfillment.deadline,
requestedFulfillment.token,
requestedFulfillment.tokenDestination,
requestedFulfillment.requestedAmount,
requestedFulfillment.callTarget,
keccak256(requestedFulfillment.callData),
requestedFulfillment.callMode,
requestedFulfillment.fallbackAddress,
keccak256(abi.encodePacked(extraTransferHashes))
)
);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./TokenUtils.sol";
library RequestedTransferLib {
string internal constant TRANSFER_TYPE = "TransferData(address token,address receiver,uint256 amount)";
bytes32 internal constant TRANSFER_TYPE_HASH = keccak256(abi.encodePacked(TRANSFER_TYPE));
struct TransferData {
address token;
address receiver;
uint256 amount;
}
error RequestedTransferNotFulfilled(
address token,
address account,
uint256 minAmount,
uint256 received
);
error RequestedTransfersLengthMismatch();
/// @notice Adds or accumulates a requested transfer to the array.
/// @dev If token+receiver pair exists, adds to minAmount. Otherwise, appends new element.
/// @param requestedTransfers Requested transfers array to mutate
/// @param currentLength Current
/// @param transferToAccumulate Transfer that should be accumulated
/// @return newLength New number of non-empty array elements
function accumulateOrAppend(
TransferData[] memory requestedTransfers,
uint256 currentLength,
TransferData memory transferToAccumulate
) internal pure returns (uint256 newLength) {
if (transferToAccumulate.amount == 0) return currentLength;
if (currentLength > requestedTransfers.length) revert RequestedTransfersLengthMismatch();
for (uint256 i = 0; i < currentLength; i++) {
if (
requestedTransfers[i].token == transferToAccumulate.token
&& requestedTransfers[i].receiver == transferToAccumulate.receiver
) {
requestedTransfers[i].amount += transferToAccumulate.amount;
return currentLength;
}
}
requestedTransfers[currentLength] = transferToAccumulate;
return currentLength + 1;
}
/// @notice Collects balances for requested token+account pair
/// @param requestedTransfers Array of requested transfers
/// @return Array of corresponding balances
function getBalances(TransferData[] memory requestedTransfers) internal view returns (uint256[] memory) {
uint256[] memory balances = new uint256[](requestedTransfers.length);
for (uint256 i = 0; i < requestedTransfers.length; i++) {
balances[i] = TokenUtils.getBalance(
requestedTransfers[i].token,
requestedTransfers[i].receiver
);
}
return balances;
}
/// @notice Checks that requested transfers were fulfilled
/// @param requestedTransfers Array of requested transfers
/// @param preBalances Array of balances before fulfillment
/// @return firstAmount First `received` amount. Should be the main amount OUT
function verifyFulfillment(
TransferData[] memory requestedTransfers,
uint256[] memory preBalances
) internal view returns(uint256 firstAmount) {
if (preBalances.length != requestedTransfers.length) revert RequestedTransfersLengthMismatch();
firstAmount = 0;
for (uint256 i = 0; i < requestedTransfers.length; i++) {
uint256 postBalance = TokenUtils.getBalance(
requestedTransfers[i].token,
requestedTransfers[i].receiver
);
uint256 received = postBalance - preBalances[i];
if (i == 0) {
firstAmount = received;
}
if (received < requestedTransfers[i].amount) {
revert RequestedTransferNotFulfilled(
requestedTransfers[i].token,
requestedTransfers[i].receiver,
requestedTransfers[i].amount,
received
);
}
}
}
/// @notice Hash Transfer struct
/// @param transferData Transfer data to hash
/// @return EIP-712 hash
function hash(TransferData memory transferData) internal pure returns (bytes32) {
return keccak256(
abi.encode(
TRANSFER_TYPE_HASH,
transferData.token,
transferData.receiver,
transferData.amount
)
);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "../Permit2/interfaces/ISignatureTransfer.sol";
import "../interfaces/ISingleChainGuardLimit.sol";
import "../libraries/RequestedTransferLib.sol";
library SingleChainLimitOrderLib {
using RequestedTransferLib for RequestedTransferLib.TransferData;
bytes internal constant WITNESS_TYPE = abi.encodePacked(
"SingleChainLimitOrder(",
"address user,",
"address tokenIn,",
"uint256 amountIn,",
"TransferData requestedOutput,",
"TransferData[] extraTransfers,",
"bytes encodedExternalCallData,",
"uint32 deadline,",
"uint256 nonce)"
);
bytes32 internal constant WITNESS_TYPE_HASH = keccak256(abi.encodePacked(
WITNESS_TYPE, RequestedTransferLib.TRANSFER_TYPE
));
string internal constant TOKEN_PERMISSIONS_TYPE = "TokenPermissions(address token,uint256 amount)";
string internal constant PERMIT2_ORDER_TYPE = string(abi.encodePacked(
"SingleChainLimitOrder witness)",
WITNESS_TYPE,
TOKEN_PERMISSIONS_TYPE,
RequestedTransferLib.TRANSFER_TYPE
));
/// @notice Hash the order
/// @param order Order data
/// @return EIP-712 hash
function hash(SingleChainLimitOrder memory order) internal pure returns (bytes32) {
bytes32[] memory extraTransfersHashes = new bytes32[](order.extraTransfers.length);
for (uint256 i = 0; i < order.extraTransfers.length; i++) {
extraTransfersHashes[i] = order.extraTransfers[i].hash();
}
return keccak256(
abi.encode(
WITNESS_TYPE_HASH,
order.user,
order.tokenIn,
order.amountIn,
order.requestedOutput.hash(),
keccak256(abi.encodePacked(extraTransfersHashes)),
keccak256(order.encodedExternalCallData),
order.deadline,
order.nonce
)
);
}
/// @notice Prepares Permit2 PermitTransferFrom struct from the order
/// @param order Order data
/// @return PermitTransferFrom struct
function toPermit(SingleChainLimitOrder memory order)
internal
pure
returns (ISignatureTransfer.PermitTransferFrom memory)
{
return ISignatureTransfer.PermitTransferFrom({
permitted: ISignatureTransfer.TokenPermissions({token: order.tokenIn, amount: order.amountIn}),
nonce: order.nonce,
deadline: order.deadline
});
}
/// @notice Prepares Permit2 SignatureTransferDetails struct from the order
/// @param order Order data
/// @param to Tokens receiver
/// @return SignatureTransferDetails struct
function transferDetails(SingleChainLimitOrder memory order, address to)
internal
pure
returns (ISignatureTransfer.SignatureTransferDetails memory)
{
return ISignatureTransfer.SignatureTransferDetails({
to: to,
requestedAmount: order.amountIn
});
}
// ------------------------- SOLVER PERMISSION ------------------------- //
bytes internal constant SOLVER_PERMISSION_TYPE = abi.encodePacked(
"SingleChainLimitSolverPermission(",
"address solver,",
"bytes32 orderHash,",
"uint256 amountOutMin,",
"TransferData protocolFeeTransfer,",
"uint32 permissionDeadline)",
RequestedTransferLib.TRANSFER_TYPE
);
bytes32 internal constant SOLVER_PERMISSION_TYPE_HASH = keccak256(SOLVER_PERMISSION_TYPE);
/// @notice Hash the Solver permission to fulfill the order
/// @param permission Solver permission
/// @return EIP-712 hash
function hash(SingleChainLimitSolverPermission calldata permission) internal pure returns (bytes32) {
return keccak256(
abi.encode(
SOLVER_PERMISSION_TYPE_HASH,
permission.solver,
permission.orderHash,
permission.amountOutMin,
permission.protocolFeeTransfer.hash(),
permission.permissionDeadline
)
);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
/// @title Utils to work with ERC20 and Native tokens
library TokenUtils {
using SafeERC20 for IERC20;
/// @notice Sends tokens to `to` address
/// @param to Tokens receiver
/// @param token ERC20 token address or address(0) for Native currency
/// @param amount Amount of tokens to send
function sendTokens(
address payable to,
address token,
uint256 amount
) internal {
if (token == address(0)) {
(bool success,) = to.call{value: amount}("");
require(success, "Native transfer failed");
} else {
IERC20(token).safeTransfer(to, amount);
}
}
/// @notice Returns balance of this smart contract
/// @param token Token address. address(0) for native token
function getContractBalance(address token) internal view returns (uint256) {
return getBalance(token, address(this));
}
/// @notice Returns balance of specific address
/// @param token Token address. address(0) for native token
/// @param account Account address to check balance for
function getBalance(address token, address account) internal view returns (uint256) {
return token == address(0)
? account.balance
: IERC20(token).balanceOf(account);
}
/**
* @notice Approves ERC20 token to `spender` in case of insufficient allowance
* @param token ERC20 token that needs to be approved
* @param spender Spender address
* @param amountToSpend Amount of tokens to spend
*/
function safeApproveIfRequired(
IERC20 token,
address spender,
uint256 amountToSpend
) internal {
uint256 allowance = token.allowance(address(this), spender);
if (allowance < amountToSpend) {
// Approves to 0 in case token processes `approve` like `increaseAllowance`
if (allowance != 0) {
token.forceApprove(spender, 0);
}
token.forceApprove(spender, type(uint256).max);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IEIP712 {
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IEIP712} from "./IEIP712.sol";
/// @title SignatureTransfer
/// @notice Handles ERC20 token transfers through signature based actions
/// @dev Requires user's token approval on the Permit2 contract
interface ISignatureTransfer is IEIP712 {
/// @notice Thrown when the requested amount for a transfer is larger than the permissioned amount
/// @param maxAmount The maximum amount a spender can request to transfer
error InvalidAmount(uint256 maxAmount);
/// @notice Thrown when the number of tokens permissioned to a spender does not match the number of tokens being transferred
/// @dev If the spender does not need to transfer the number of tokens permitted, the spender can request amount 0 to be transferred
error LengthMismatch();
/// @notice Emits an event when the owner successfully invalidates an unordered nonce.
event UnorderedNonceInvalidation(address indexed owner, uint256 word, uint256 mask);
/// @notice The token and amount details for a transfer signed in the permit transfer signature
struct TokenPermissions {
// ERC20 token address
address token;
// the maximum amount that can be spent
uint256 amount;
}
/// @notice The signed permit message for a single token transfer
struct PermitTransferFrom {
TokenPermissions permitted;
// a unique value for every token owner's signature to prevent signature replays
uint256 nonce;
// deadline on the permit signature
uint256 deadline;
}
/// @notice Specifies the recipient address and amount for batched transfers.
/// @dev Recipients and amounts correspond to the index of the signed token permissions array.
/// @dev Reverts if the requested amount is greater than the permitted signed amount.
struct SignatureTransferDetails {
// recipient address
address to;
// spender requested amount
uint256 requestedAmount;
}
/// @notice Used to reconstruct the signed permit message for multiple token transfers
/// @dev Do not need to pass in spender address as it is required that it is msg.sender
/// @dev Note that a user still signs over a spender address
struct PermitBatchTransferFrom {
// the tokens and corresponding amounts permitted for a transfer
TokenPermissions[] permitted;
// a unique value for every token owner's signature to prevent signature replays
uint256 nonce;
// deadline on the permit signature
uint256 deadline;
}
/// @notice A map from token owner address and a caller specified word index to a bitmap. Used to set bits in the bitmap to prevent against signature replay protection
/// @dev Uses unordered nonces so that permit messages do not need to be spent in a certain order
/// @dev The mapping is indexed first by the token owner, then by an index specified in the nonce
/// @dev It returns a uint256 bitmap
/// @dev The index, or wordPosition is capped at type(uint248).max
function nonceBitmap(address, uint256) external view returns (uint256);
/// @notice Transfers a token using a signed permit message
/// @dev Reverts if the requested amount is greater than the permitted signed amount
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails The spender's requested transfer details for the permitted token
/// @param signature The signature to verify
function permitTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes calldata signature
) external;
/// @notice Transfers a token using a signed permit message
/// @notice Includes extra data provided by the caller to verify signature over
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
/// @dev Reverts if the requested amount is greater than the permitted signed amount
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails The spender's requested transfer details for the permitted token
/// @param witness Extra data to include when checking the user signature
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
/// @param signature The signature to verify
function permitWitnessTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;
/// @notice Transfers multiple tokens using a signed permit message
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
/// @param signature The signature to verify
function permitTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes calldata signature
) external;
/// @notice Transfers multiple tokens using a signed permit message
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
/// @notice Includes extra data provided by the caller to verify signature over
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
/// @param witness Extra data to include when checking the user signature
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
/// @param signature The signature to verify
function permitWitnessTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;
/// @notice Invalidates the bits specified in mask for the bitmap at the word position
/// @dev The wordPos is maxed at type(uint248).max
/// @param wordPos A number to index the nonceBitmap at
/// @param mask A bitmap masked against msg.sender's current bitmap at the word position
function invalidateUnorderedNonces(uint256 wordPos, uint256 mask) external;
}{
"optimizer": {
"enabled": true,
"runs": 999999
},
"metadata": {
"bytecodeHash": "ipfs"
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"initialOwner","type":"address"},{"internalType":"address","name":"_auctioneer","type":"address"},{"internalType":"contract ISignatureTransfer","name":"_permit2","type":"address"},{"internalType":"contract IExternalCallHandler","name":"_externalCallHandler","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"FeeOnTransferTokensNotSupported","type":"error"},{"inputs":[],"name":"InvalidAuctioneerSignature","type":"error"},{"inputs":[],"name":"InvalidOrder","type":"error"},{"inputs":[],"name":"InvalidPermission","type":"error"},{"inputs":[],"name":"InvalidPromisedAmountOut","type":"error"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[],"name":"NotASolver","type":"error"},{"inputs":[],"name":"NotAUser","type":"error"},{"inputs":[],"name":"OrderWasAlreadyManuallyInitialized","type":"error"},{"inputs":[],"name":"OrderWasNotManuallyInitialized","type":"error"},{"inputs":[],"name":"OverdueDeadline","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":"address","name":"token","type":"address"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"minAmount","type":"uint256"},{"internalType":"uint256","name":"received","type":"uint256"}],"name":"RequestedTransferNotFulfilled","type":"error"},{"inputs":[],"name":"RequestedTransfersLengthMismatch","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"","type":"address"}],"name":"AuctioneerSet","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"mainAmountOut","type":"uint256"}],"name":"OrderFulfilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"orderHash","type":"bytes32"}],"name":"OrderManuallyCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"orderHash","type":"bytes32"}],"name":"OrderManuallyInitialized","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"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"auctioneer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct RequestedTransferLib.TransferData","name":"requestedOutput","type":"tuple"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct RequestedTransferLib.TransferData[]","name":"extraTransfers","type":"tuple[]"},{"internalType":"bytes","name":"encodedExternalCallData","type":"bytes"},{"internalType":"uint32","name":"deadline","type":"uint32"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct SingleChainLimitOrder","name":"order","type":"tuple"}],"name":"cancelManuallyCreatedOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct RequestedTransferLib.TransferData","name":"requestedOutput","type":"tuple"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct RequestedTransferLib.TransferData[]","name":"extraTransfers","type":"tuple[]"},{"internalType":"bytes","name":"encodedExternalCallData","type":"bytes"},{"internalType":"uint32","name":"deadline","type":"uint32"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct SingleChainLimitOrder","name":"order","type":"tuple"}],"name":"createOrderManually","outputs":[],"stateMutability":"nonpayable","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":[],"name":"externalCallHandler","outputs":[{"internalType":"contract IExternalCallHandler","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"promisedAmountOut","type":"uint256"},{"components":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct RequestedTransferLib.TransferData","name":"requestedOutput","type":"tuple"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct RequestedTransferLib.TransferData[]","name":"extraTransfers","type":"tuple[]"},{"internalType":"bytes","name":"encodedExternalCallData","type":"bytes"},{"internalType":"uint32","name":"deadline","type":"uint32"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct SingleChainLimitOrder","name":"order","type":"tuple"},{"internalType":"bytes","name":"userSignature","type":"bytes"},{"components":[{"internalType":"address","name":"solver","type":"address"},{"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct RequestedTransferLib.TransferData","name":"protocolFeeTransfer","type":"tuple"},{"internalType":"uint32","name":"permissionDeadline","type":"uint32"}],"internalType":"struct SingleChainLimitSolverPermission","name":"permission","type":"tuple"},{"internalType":"bytes","name":"auctioneerSignature","type":"bytes"},{"internalType":"contract ISingleChainIntentFulfiller","name":"fulfillerContract","type":"address"},{"internalType":"bytes","name":"callBackData","type":"bytes"},{"internalType":"bool","name":"orderWasInitializedManually","type":"bool"}],"name":"fulfillLimitOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"orderHash","type":"bytes32"}],"name":"orderManuallyInitialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"permit2","outputs":[{"internalType":"contract ISignatureTransfer","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAuctioneer","type":"address"}],"name":"setAuctioneer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
0x6101a060405234801561001157600080fd5b50604051613dd6380380613dd6833981016040819052610030916102dc565b604080518082018252601581527f53696e676c65436861696e47756172644c696d69740000000000000000000000602080830191909152825180840190935260018352603160f81b9083015290848484886001600160a01b0381166100b057604051631e4fbdf760e01b8152600060048201526024015b60405180910390fd5b6100b9816101ea565b506001600160a01b03831615806100d757506001600160a01b038216155b806100e957506001600160a01b038116155b156101075760405163d92e233d60e01b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b039485161790559082166080521660a052610138826003610206565b61016052610147816004610206565b61018052815160208084019190912061012052815190820120610140524660e0526101d66101205161014051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201529081019290925260608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b60c052505030610100525061050a92505050565b600180546001600160a01b031916905561020381610239565b50565b60006020835110156102225761021b83610289565b9050610233565b8161022d84826103da565b5060ff90505b92915050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080829050601f815111156102b4578260405163305a27a960e01b81526004016100a79190610498565b80516102bf826104e6565b179392505050565b6001600160a01b038116811461020357600080fd5b600080600080608085870312156102f257600080fd5b84516102fd816102c7565b602086015190945061030e816102c7565b604086015190935061031f816102c7565b6060860151909250610330816102c7565b939692955090935050565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061036557607f821691505b60208210810361038557634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156103d557806000526020600020601f840160051c810160208510156103b25750805b601f840160051c820191505b818110156103d257600081556001016103be565b50505b505050565b81516001600160401b038111156103f3576103f361033b565b610407816104018454610351565b8461038b565b6020601f82116001811461043b57600083156104235750848201515b600019600385901b1c1916600184901b1784556103d2565b600084815260208120601f198516915b8281101561046b578785015182556020948501946001909201910161044b565b50848210156104895786840151600019600387901b60f8161c191681555b50505050600190811b01905550565b602081526000825180602084015260005b818110156104c657602081860181015160408684010152016104a9565b506000604082850101526040601f19601f83011684010191505092915050565b805160208083015191908110156103855760001960209190910360031b1b16919050565b60805160a05160c05160e051610100516101205161014051610160516101805161384761058f60003960006119d8015260006119a6015260006121c70152600061219f015260006120fa015260006121240152600061214e01526000818161021b01528181611e280152612765015260008181610108015261135e01526138476000f3fe608060405234801561001057600080fd5b50600436106100e95760003560e01c80638da5cb5b1161008c578063df3be9b911610066578063df3be9b914610216578063e30c39781461023d578063f2fde38b1461025b578063f32132361461026e57600080fd5b80638da5cb5b146101b2578063b7d8c5a6146101d0578063dc27c13e1461020357600080fd5b80635ec2c7bf116100c85780635ec2c7bf14610167578063715018a61461018757806379ba50971461018f57806384b0196e1461019757600080fd5b8062ede7e4146100ee57806312261ee714610103578063526a004814610154575b600080fd5b6101016100fc36600461295d565b610281565b005b61012a7f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6101016101623660046129fe565b61034f565b60025461012a9073ffffffffffffffffffffffffffffffffffffffff1681565b610101610492565b6101016104a6565b61019f610522565b60405161014b9796959493929190612b81565b60005473ffffffffffffffffffffffffffffffffffffffff1661012a565b6101f36101de366004612c42565b60056020526000908152604090205460ff1681565b604051901515815260200161014b565b610101610211366004612c5b565b610584565b61012a7f000000000000000000000000000000000000000000000000000000000000000081565b60015473ffffffffffffffffffffffffffffffffffffffff1661012a565b61010161026936600461295d565b6109ab565b61010161027c366004612c5b565b610a5b565b610289610bbb565b73ffffffffffffffffffffffffffffffffffffffff81166102d6576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081179091556040519081527f4ee0985a129917c72eab0afe7ec6060bf6c6e0796bedc42de903d9dbbadfc51d9060200160405180910390a150565b600061036261035d8c612ee9565b610c0e565b9050610372818d8d8b8b8b610f44565b811561042a5760008181526005602052604090205460ff166103c0576040517f462b743200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006005600083815260200190815260200160002060006101000a81548160ff021916908315150217905550610425858c604001358d6020016020810190610408919061295d565b73ffffffffffffffffffffffffffffffffffffffff16919061121a565b610437565b610437818c8c8c896112a0565b60006104478d8d8b898989611789565b9050817f5c36d11ac0f0183c71c1510b7905a133ced19e12a469813de8c0be5a97644b6e8260405161047b91815260200190565b60405180910390a250505050505050505050505050565b61049a610bbb565b6104a4600061196e565b565b600154339073ffffffffffffffffffffffffffffffffffffffff168114610516576040517f118cdaa700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff821660048201526024015b60405180910390fd5b61051f8161196e565b50565b60006060806000806000606061053661199f565b61053e6119d1565b604080516000808252602082019092527f0f000000000000000000000000000000000000000000000000000000000000009b939a50919850469750309650945092509050565b610591602082018261295d565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146105f5576040517f25602e6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040810135158061062b5750600061061360a083016080840161295d565b73ffffffffffffffffffffffffffffffffffffffff16145b15610662576040517faf61069300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b4261067561012083016101008401612fb7565b63ffffffff1610156106b3576040517fa99f132a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006106c5604083016020840161295d565b73ffffffffffffffffffffffffffffffffffffffff1603610712576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600061072061035d83612ee9565b60008181526005602052604090205490915060ff161561076c576040517f54b0ccbd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600061077e604084016020850161295d565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff91909116906370a0823190602401602060405180830381865afa1580156107ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061080e9190612fd2565b9050610847333060408601803590610829906020890161295d565b73ffffffffffffffffffffffffffffffffffffffff169291906119fe565b60008161085a604086016020870161295d565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff91909116906370a0823190602401602060405180830381865afa1580156108c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108ea9190612fd2565b6108f4919061301a565b90508360400135811015610934576040517fe1628f7200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000838152600560205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055517fdcef777a456015e43fb48986c15368416c3103dcf3ec68d9ae8c3111006ff69c9061099d9085815260200190565b60405180910390a150505050565b6109b3610bbb565b6001805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff00000000000000000000000000000000000000009091168117909155610a1660005473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b610a68602082018261295d565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610acc576040517f25602e6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000610ada61035d83612ee9565b60008181526005602052604090205490915060ff16610b25576040517f462b743200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610b49610b35602084018461295d565b60408401803590610408906020870161295d565b6000818152600560205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055517f83ac8dd1b61f3fb0ce7944414f284fc0c798d63f009df7b90dbaf29845280c0790610baf9083815260200190565b60405180910390a15050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146104a4576040517f118cdaa700000000000000000000000000000000000000000000000000000000815233600482015260240161050d565b60008082608001515167ffffffffffffffff811115610c2f57610c2f612c98565b604051908082528060200260200182016040528015610c58578160200160208202803683370190505b50905060005b836080015151811015610cb657610c9184608001518281518110610c8457610c8461302d565b6020026020010151611a4a565b828281518110610ca357610ca361302d565b6020908102919091010152600101610c5e565b50604080517f53696e676c65436861696e4c696d69744f72646572280000000000000000000060208201527f6164647265737320757365722c0000000000000000000000000000000000000060368201527f6164647265737320746f6b656e496e2c0000000000000000000000000000000060438201527f75696e7432353620616d6f756e74496e2c00000000000000000000000000000060538201527f5472616e7366657244617461207265717565737465644f75747075742c00000060648201527f5472616e73666572446174615b5d2065787472615472616e73666572732c000060818201527f627974657320656e636f64656445787465726e616c43616c6c446174612c0000609f8201527f75696e74333220646561646c696e652c0000000000000000000000000000000060bd8201527f75696e74323536206e6f6e63652900000000000000000000000000000000000060cd820152815160bb81830301815261013b8201909252603b60db8201818152916137d79060fb0139604051602001610e4692919061305c565b60405160208183030381529060405280519060200120836000015184602001518560400151610e788760600151611a4a565b85604051602001610e89919061308b565b604051602081830303815290604052805190602001208860a00151805190602001208960c001518a60e00151604051602001610f269998979695949392919098895273ffffffffffffffffffffffffffffffffffffffff97881660208a01529590961660408801526060870193909352608086019190915260a085015260c084015263ffffffff9190911660e08301526101008201526101200190565b60405160208183030381529060405280519060200120915050919050565b60408401351580610f7a57506000610f6260a086016080870161295d565b73ffffffffffffffffffffffffffffffffffffffff16145b15610fb1576040517faf61069300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b42610fc461012086016101008701612fb7565b63ffffffff161080610fea575042610fe260e0850160c08601612fb7565b63ffffffff16105b15611021576040517fa99f132a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3361102f602085018561295d565b73ffffffffffffffffffffffffffffffffffffffff16146110aa576127106110596103e8826130c1565b6110679060408601356130d4565b61107191906130eb565b8510156110aa576040517f95b2fb6900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82604001358510156110e8576040517f9463b69700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82602001358614611125576040517f868a64de00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008061117861113c61113787611b0a565b611bfc565b85858080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611c4a92505050565b509092509050600081600381111561119257611192613126565b1415806111b3575073ffffffffffffffffffffffffffffffffffffffff8216155b806111d9575060025473ffffffffffffffffffffffffffffffffffffffff838116911614155b15611210576040517f070f548200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050505050505050565b60405173ffffffffffffffffffffffffffffffffffffffff83811660248301526044820183905261129b91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611c97565b505050565b8060006112b3604087016020880161295d565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff848116600483015291909116906370a0823190602401602060405180830381865afa158015611321573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113459190612fd2565b905073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001663137c29fe61140e61138f89612ee9565b6040805160a0810182526000606082018181526080830182905282526020820181905291810191909152506040805160a08101825260208084015173ffffffffffffffffffffffffffffffffffffffff1660608301908152848401516080840152825260e08401519082015260c09092015163ffffffff169082015290565b61145a8561141b8b612ee9565b60408051808201825260008082526020918201528151808301835273ffffffffffffffffffffffffffffffffffffffff90941684529101519082015290565b61146760208b018b61295d565b6040517f53696e676c65436861696e4c696d69744f72646572280000000000000000000060208201527f6164647265737320757365722c0000000000000000000000000000000000000060368201527f6164647265737320746f6b656e496e2c0000000000000000000000000000000060438201527f75696e7432353620616d6f756e74496e2c00000000000000000000000000000060538201527f5472616e7366657244617461207265717565737465644f75747075742c00000060648201527f5472616e73666572446174615b5d2065787472615472616e73666572732c000060818201527f627974657320656e636f64656445787465726e616c43616c6c446174612c0000609f8201527f75696e74333220646561646c696e652c0000000000000000000000000000000060bd8201527f75696e74323536206e6f6e63652900000000000000000000000000000000000060cd8201528c9060db01604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815260608301909152602e8083529091906137a960208301396040518060600160405280603b81526020016137d7603b913960405160200161163293929190613155565b6040516020818303038152906040528b8b6040518863ffffffff1660e01b815260040161166597969594939291906131c4565b600060405180830381600087803b15801561167f57600080fd5b505af1158015611693573d6000803e3d6000fd5b505050506000818760200160208101906116ad919061295d565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff868116600483015291909116906370a0823190602401602060405180830381865afa15801561171b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061173f9190612fd2565b611749919061301a565b90508660400135811015611210576040517fe1628f7200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008060405180606001604052808860600160000160208101906117ad919061295d565b73ffffffffffffffffffffffffffffffffffffffff1681526020016117d860a08a0160808b0161295d565b73ffffffffffffffffffffffffffffffffffffffff16815260200189815250905061196260405180610100016040528089602001602081019061181b919061295d565b73ffffffffffffffffffffffffffffffffffffffff168152602001896040013581526020018381526020018860600180360381019061185a91906132c1565b815260200161186c60c08b018b6132dd565b808060200260200160405190810160405280939291908181526020016000905b828210156118b8576118a9606083028601368190038101906132c1565b8152602001906001019061188c565b505050505081526020018773ffffffffffffffffffffffffffffffffffffffff16815260200186868080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509082525060200161192760e08b018b613344565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050915250611d3b565b98975050505050505050565b600180547fffffffffffffffffffffffff000000000000000000000000000000000000000016905561051f81611fc0565b60606119cc7f00000000000000000000000000000000000000000000000000000000000000006003612035565b905090565b60606119cc7f00000000000000000000000000000000000000000000000000000000000000006004612035565b60405173ffffffffffffffffffffffffffffffffffffffff8481166024830152838116604483015260648201839052611a449186918216906323b872dd90608401611254565b50505050565b60006040518060600160405280603b81526020016137d7603b9139604051602001611a7591906133a9565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181528282528051602091820120855186830151878501519386019290925273ffffffffffffffffffffffffffffffffffffffff90811693850193909352919091166060830152608082015260a0015b604051602081830303815290604052805190602001209050919050565b60006040518060600160405280603b81526020016137d7603b9139604051602001611b3591906133c5565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152919052805160209182012090611b789084018461295d565b60208401356040850135611b9c611b97368890038801606089016132c1565b611a4a565b611bac60e0880160c08901612fb7565b60408051602081019790975273ffffffffffffffffffffffffffffffffffffffff909516948601949094526060850192909252608084015260a083015263ffffffff1660c082015260e001611aed565b6000611c44611c096120e0565b836040517f19010000000000000000000000000000000000000000000000000000000000008152600281019290925260228201526042902090565b92915050565b60008060008351604103611c845760208401516040850151606086015160001a611c7688828585612218565b955095509550505050611c90565b50508151600091506002905b9250925092565b600080602060008451602086016000885af180611cba576040513d6000823e3d81fd5b50506000513d91508115611cd2578060011415611cec565b73ffffffffffffffffffffffffffffffffffffffff84163b155b15611a44576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8516600482015260240161050d565b60e0810151516080820151516000911515908290611d5a9060026130c1565b67ffffffffffffffff811115611d7257611d72612c98565b604051908082528060200260200182016040528015611ddb57816020015b60408051606081018252600080825260208083018290529282015282527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff909201910181611d905790505b5090506000611e7681604051806060016040528088604001516000015173ffffffffffffffffffffffffffffffffffffffff16815260200186611e2657886040015160200151611e48565b7f00000000000000000000000000000000000000000000000000000000000000005b73ffffffffffffffffffffffffffffffffffffffff1681526040808a01510151602090910152849190612312565b9050611e91818660600151846123129092919063ffffffff16565b905060005b856080015151811015611edf57611ed58287608001518381518110611ebd57611ebd61302d565b6020026020010151856123129092919063ffffffff16565b9150600101611e96565b508082526000611eee83612492565b60a08701518751602089015160c08a01516040517f3071d61d00000000000000000000000000000000000000000000000000000000815294955073ffffffffffffffffffffffffffffffffffffffff90931693633071d61d93611f58939291899190600401613514565b600060405180830381600087803b158015611f7257600080fd5b505af1158015611f86573d6000803e3d6000fd5b50505050611f9d818461255890919063ffffffff16565b94508315611fb757611fb786604001518760e001516126fc565b50505050919050565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b606060ff831461204f57612048836127db565b9050611c44565b81805461205b906135cf565b80601f0160208091040260200160405190810160405280929190818152602001828054612087906135cf565b80156120d45780601f106120a9576101008083540402835291602001916120d4565b820191906000526020600020905b8154815290600101906020018083116120b757829003601f168201915b50505050509050611c44565b60003073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614801561214657507f000000000000000000000000000000000000000000000000000000000000000046145b1561217057507f000000000000000000000000000000000000000000000000000000000000000090565b6119cc604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411156122535750600091506003905082612308565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa1580156122a7573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff81166122fe57506000925060019150829050612308565b9250600091508190505b9450945094915050565b6000816040015160000361232757508161248b565b8351831115612362576040517f2116eb0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b8381101561245e57826000015173ffffffffffffffffffffffffffffffffffffffff1685828151811061239a5761239a61302d565b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff161480156124155750826020015173ffffffffffffffffffffffffffffffffffffffff168582815181106123f1576123f161302d565b60200260200101516020015173ffffffffffffffffffffffffffffffffffffffff16145b156124565782604001518582815181106124315761243161302d565b602002602001015160400181815161244991906130c1565b90525083915061248b9050565b600101612365565b50818484815181106124725761247261302d565b60209081029190910101526124888360016130c1565b90505b9392505050565b60606000825167ffffffffffffffff8111156124b0576124b0612c98565b6040519080825280602002602001820160405280156124d9578160200160208202803683370190505b50905060005b83518110156125515761252c8482815181106124fd576124fd61302d565b60200260200101516000015185838151811061251b5761251b61302d565b60200260200101516020015161281a565b82828151811061253e5761253e61302d565b60209081029190910101526001016124df565b5092915050565b60008251825114612595576040517f2116eb0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506000805b83518110156125515760006125d88583815181106125ba576125ba61302d565b60200260200101516000015186848151811061251b5761251b61302d565b905060008483815181106125ee576125ee61302d565b602002602001015182612601919061301a565b90508260000361260f578093505b8583815181106126215761262161302d565b6020026020010151604001518110156126f2578583815181106126465761264661302d565b6020026020010151600001518684815181106126645761266461302d565b6020026020010151602001518785815181106126825761268261302d565b602090810291909101015160409081015190517f1f00e79900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff938416600482015292909116602483015260448201526064810182905260840161050d565b505060010161259a565b60008060008084806020019051810190612716919061362b565b895160208b01516040517f9aca0642000000000000000000000000000000000000000000000000000000008152959950939750919550935073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001692639aca0642926127a1929189908990899089906004016136db565b600060405180830381600087803b1580156127bb57600080fd5b505af11580156127cf573d6000803e3d6000fd5b50505050505050505050565b606060006127e8836128ea565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b600073ffffffffffffffffffffffffffffffffffffffff8316156128cd576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83811660048301528416906370a0823190602401602060405180830381865afa1580156128a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128c89190612fd2565b61248b565b5073ffffffffffffffffffffffffffffffffffffffff1631919050565b600060ff8216601f811115611c44576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8116811461051f57600080fd5b80356129588161292b565b919050565b60006020828403121561296f57600080fd5b813561248b8161292b565b6000610140828403121561298d57600080fd5b50919050565b60008083601f8401126129a557600080fd5b50813567ffffffffffffffff8111156129bd57600080fd5b6020830191508360208285010111156129d557600080fd5b9250929050565b600060e0828403121561298d57600080fd5b8035801515811461295857600080fd5b60008060008060008060008060008060006101c08c8e031215612a2057600080fd5b8b359a5060208c013567ffffffffffffffff811115612a3e57600080fd5b612a4a8e828f0161297a565b9a505060408c013567ffffffffffffffff811115612a6757600080fd5b612a738e828f01612993565b909a509850612a8790508d60608e016129dc565b96506101408c013567ffffffffffffffff811115612aa457600080fd5b612ab08e828f01612993565b9097509550612ac490506101608d0161294d565b93506101808c013567ffffffffffffffff811115612ae157600080fd5b612aed8e828f01612993565b9094509250612b0190506101a08d016129ee565b90509295989b509295989b9093969950565b60005b83811015612b2e578181015183820152602001612b16565b50506000910152565b60008151808452612b4f816020860160208601612b13565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b7fff000000000000000000000000000000000000000000000000000000000000008816815260e060208201526000612bbc60e0830189612b37565b8281036040840152612bce8189612b37565b6060840188905273ffffffffffffffffffffffffffffffffffffffff8716608085015260a0840186905283810360c08501528451808252602080870193509091019060005b81811015612c31578351835260209384019390920191600101612c13565b50909b9a5050505050505050505050565b600060208284031215612c5457600080fd5b5035919050565b600060208284031215612c6d57600080fd5b813567ffffffffffffffff811115612c8457600080fd5b612c908482850161297a565b949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051610100810167ffffffffffffffff81118282101715612ceb57612ceb612c98565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715612d3857612d38612c98565b604052919050565b600060608284031215612d5257600080fd5b6040516060810167ffffffffffffffff81118282101715612d7557612d75612c98565b6040529050808235612d868161292b565b81526020830135612d968161292b565b6020820152604092830135920191909152919050565b600082601f830112612dbd57600080fd5b813567ffffffffffffffff811115612dd757612dd7612c98565b612de660208260051b01612cf1565b80828252602082019150602060608402860101925085831115612e0857600080fd5b602085015b83811015612e2f57612e1f8782612d40565b8352602090920191606001612e0d565b5095945050505050565b600067ffffffffffffffff821115612e5357612e53612c98565b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b600082601f830112612e9057600080fd5b8135612ea3612e9e82612e39565b612cf1565b818152846020838601011115612eb857600080fd5b816020850160208301376000918101602001919091529392505050565b803563ffffffff8116811461295857600080fd5b60006101408236031215612efc57600080fd5b612f04612cc7565b612f0d8361294d565b8152612f1b6020840161294d565b602082015260408381013590820152612f373660608501612d40565b606082015260c083013567ffffffffffffffff811115612f5657600080fd5b612f6236828601612dac565b60808301525060e083013567ffffffffffffffff811115612f8257600080fd5b612f8e36828601612e7f565b60a083015250612fa16101008401612ed5565b60c0820152610120929092013560e08301525090565b600060208284031215612fc957600080fd5b61248b82612ed5565b600060208284031215612fe457600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b81810381811115611c4457611c44612feb565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000835161306e818460208801612b13565b835190830190613082818360208801612b13565b01949350505050565b8151600090829060208501835b828110156130b6578151845260209384019390910190600101613098565b509195945050505050565b80820180821115611c4457611c44612feb565b8082028115828204841417611c4457611c44612feb565b600082613121577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b7f53696e676c65436861696e4c696d69744f72646572207769746e65737329000081526000845161318d81601e850160208901612b13565b8451908301906131a481601e840160208901612b13565b84519101601e01906131ba818360208801612b13565b0195945050505050565b6131ef818951805173ffffffffffffffffffffffffffffffffffffffff168252602090810151910152565b60208801516040820152604088015160608201526132306080820188805173ffffffffffffffffffffffffffffffffffffffff168252602090810151910152565b73ffffffffffffffffffffffffffffffffffffffff861660c08201528460e0820152610140610100820152600061326b610140830186612b37565b8281036101208401528381528385602083013760006020858301015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f86011682010191505098975050505050505050565b6000606082840312156132d357600080fd5b61248b8383612d40565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261331257600080fd5b83018035915067ffffffffffffffff82111561332d57600080fd5b60200191506060810236038213156129d557600080fd5b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261337957600080fd5b83018035915067ffffffffffffffff82111561339457600080fd5b6020019150368190038213156129d557600080fd5b600082516133bb818460208701612b13565b9190910192915050565b7f53696e676c65436861696e4c696d6974536f6c7665725065726d697373696f6e81527f280000000000000000000000000000000000000000000000000000000000000060208201527f6164647265737320736f6c7665722c000000000000000000000000000000000060218201527f62797465733332206f72646572486173682c000000000000000000000000000060308201527f75696e7432353620616d6f756e744f75744d696e2c000000000000000000000060428201527f5472616e73666572446174612070726f746f636f6c4665655472616e7366657260578201527f2c0000000000000000000000000000000000000000000000000000000000000060778201527f75696e743332207065726d697373696f6e446561646c696e6529000000000000607882015260008251613507816092850160208701612b13565b9190910160920192915050565b60006080820173ffffffffffffffffffffffffffffffffffffffff871683528560208401526080604084015280855180835260a08501915060208701925060005b818110156135bb57835173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501526040810151604085015250606083019250602084019350600181019050613555565b505083810360608501526119628186612b37565b600181811c908216806135e357607f821691505b60208210810361298d577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b80516002811061295857600080fd5b6000806000806080858703121561364157600080fd5b845161364c8161292b565b602086015190945061365d8161292b565b604086015190935067ffffffffffffffff81111561367a57600080fd5b8501601f8101871361368b57600080fd5b8051613699612e9e82612e39565b8181528860208385010111156136ae57600080fd5b6136bf826020830160208601612b13565b93506136d09150506060860161361c565b905092959194509250565b73ffffffffffffffffffffffffffffffffffffffff8716815273ffffffffffffffffffffffffffffffffffffffff8616602082015273ffffffffffffffffffffffffffffffffffffffff8516604082015273ffffffffffffffffffffffffffffffffffffffff8416606082015260c06080820152600061375e60c0830185612b37565b905060028310613797577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8260a083015297965050505050505056fe546f6b656e5065726d697373696f6e73286164647265737320746f6b656e2c75696e7432353620616d6f756e74295472616e7366657244617461286164647265737320746f6b656e2c616464726573732072656365697665722c75696e7432353620616d6f756e7429a2646970667358221220a44fe2143fe2534b60068f92c2a534c9a32b55d8f3c9ffb1ae6b5a5b6044f55a64736f6c634300081c0033000000000000000000000000d8655d1154a74748ac48f673264efba5c369f4bd000000000000000000000000c89ce8ce46946432afc55b867af58cb211adcd9a000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba300000000000000000000000062d4b37ed6427e623ae915cd7bbf0e7784c73b53
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100e95760003560e01c80638da5cb5b1161008c578063df3be9b911610066578063df3be9b914610216578063e30c39781461023d578063f2fde38b1461025b578063f32132361461026e57600080fd5b80638da5cb5b146101b2578063b7d8c5a6146101d0578063dc27c13e1461020357600080fd5b80635ec2c7bf116100c85780635ec2c7bf14610167578063715018a61461018757806379ba50971461018f57806384b0196e1461019757600080fd5b8062ede7e4146100ee57806312261ee714610103578063526a004814610154575b600080fd5b6101016100fc36600461295d565b610281565b005b61012a7f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba381565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6101016101623660046129fe565b61034f565b60025461012a9073ffffffffffffffffffffffffffffffffffffffff1681565b610101610492565b6101016104a6565b61019f610522565b60405161014b9796959493929190612b81565b60005473ffffffffffffffffffffffffffffffffffffffff1661012a565b6101f36101de366004612c42565b60056020526000908152604090205460ff1681565b604051901515815260200161014b565b610101610211366004612c5b565b610584565b61012a7f00000000000000000000000062d4b37ed6427e623ae915cd7bbf0e7784c73b5381565b60015473ffffffffffffffffffffffffffffffffffffffff1661012a565b61010161026936600461295d565b6109ab565b61010161027c366004612c5b565b610a5b565b610289610bbb565b73ffffffffffffffffffffffffffffffffffffffff81166102d6576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081179091556040519081527f4ee0985a129917c72eab0afe7ec6060bf6c6e0796bedc42de903d9dbbadfc51d9060200160405180910390a150565b600061036261035d8c612ee9565b610c0e565b9050610372818d8d8b8b8b610f44565b811561042a5760008181526005602052604090205460ff166103c0576040517f462b743200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006005600083815260200190815260200160002060006101000a81548160ff021916908315150217905550610425858c604001358d6020016020810190610408919061295d565b73ffffffffffffffffffffffffffffffffffffffff16919061121a565b610437565b610437818c8c8c896112a0565b60006104478d8d8b898989611789565b9050817f5c36d11ac0f0183c71c1510b7905a133ced19e12a469813de8c0be5a97644b6e8260405161047b91815260200190565b60405180910390a250505050505050505050505050565b61049a610bbb565b6104a4600061196e565b565b600154339073ffffffffffffffffffffffffffffffffffffffff168114610516576040517f118cdaa700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff821660048201526024015b60405180910390fd5b61051f8161196e565b50565b60006060806000806000606061053661199f565b61053e6119d1565b604080516000808252602082019092527f0f000000000000000000000000000000000000000000000000000000000000009b939a50919850469750309650945092509050565b610591602082018261295d565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146105f5576040517f25602e6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040810135158061062b5750600061061360a083016080840161295d565b73ffffffffffffffffffffffffffffffffffffffff16145b15610662576040517faf61069300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b4261067561012083016101008401612fb7565b63ffffffff1610156106b3576040517fa99f132a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006106c5604083016020840161295d565b73ffffffffffffffffffffffffffffffffffffffff1603610712576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600061072061035d83612ee9565b60008181526005602052604090205490915060ff161561076c576040517f54b0ccbd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600061077e604084016020850161295d565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff91909116906370a0823190602401602060405180830381865afa1580156107ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061080e9190612fd2565b9050610847333060408601803590610829906020890161295d565b73ffffffffffffffffffffffffffffffffffffffff169291906119fe565b60008161085a604086016020870161295d565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff91909116906370a0823190602401602060405180830381865afa1580156108c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108ea9190612fd2565b6108f4919061301a565b90508360400135811015610934576040517fe1628f7200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000838152600560205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055517fdcef777a456015e43fb48986c15368416c3103dcf3ec68d9ae8c3111006ff69c9061099d9085815260200190565b60405180910390a150505050565b6109b3610bbb565b6001805473ffffffffffffffffffffffffffffffffffffffff83167fffffffffffffffffffffffff00000000000000000000000000000000000000009091168117909155610a1660005473ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e2270060405160405180910390a350565b610a68602082018261295d565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610acc576040517f25602e6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000610ada61035d83612ee9565b60008181526005602052604090205490915060ff16610b25576040517f462b743200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610b49610b35602084018461295d565b60408401803590610408906020870161295d565b6000818152600560205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169055517f83ac8dd1b61f3fb0ce7944414f284fc0c798d63f009df7b90dbaf29845280c0790610baf9083815260200190565b60405180910390a15050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146104a4576040517f118cdaa700000000000000000000000000000000000000000000000000000000815233600482015260240161050d565b60008082608001515167ffffffffffffffff811115610c2f57610c2f612c98565b604051908082528060200260200182016040528015610c58578160200160208202803683370190505b50905060005b836080015151811015610cb657610c9184608001518281518110610c8457610c8461302d565b6020026020010151611a4a565b828281518110610ca357610ca361302d565b6020908102919091010152600101610c5e565b50604080517f53696e676c65436861696e4c696d69744f72646572280000000000000000000060208201527f6164647265737320757365722c0000000000000000000000000000000000000060368201527f6164647265737320746f6b656e496e2c0000000000000000000000000000000060438201527f75696e7432353620616d6f756e74496e2c00000000000000000000000000000060538201527f5472616e7366657244617461207265717565737465644f75747075742c00000060648201527f5472616e73666572446174615b5d2065787472615472616e73666572732c000060818201527f627974657320656e636f64656445787465726e616c43616c6c446174612c0000609f8201527f75696e74333220646561646c696e652c0000000000000000000000000000000060bd8201527f75696e74323536206e6f6e63652900000000000000000000000000000000000060cd820152815160bb81830301815261013b8201909252603b60db8201818152916137d79060fb0139604051602001610e4692919061305c565b60405160208183030381529060405280519060200120836000015184602001518560400151610e788760600151611a4a565b85604051602001610e89919061308b565b604051602081830303815290604052805190602001208860a00151805190602001208960c001518a60e00151604051602001610f269998979695949392919098895273ffffffffffffffffffffffffffffffffffffffff97881660208a01529590961660408801526060870193909352608086019190915260a085015260c084015263ffffffff9190911660e08301526101008201526101200190565b60405160208183030381529060405280519060200120915050919050565b60408401351580610f7a57506000610f6260a086016080870161295d565b73ffffffffffffffffffffffffffffffffffffffff16145b15610fb1576040517faf61069300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b42610fc461012086016101008701612fb7565b63ffffffff161080610fea575042610fe260e0850160c08601612fb7565b63ffffffff16105b15611021576040517fa99f132a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3361102f602085018561295d565b73ffffffffffffffffffffffffffffffffffffffff16146110aa576127106110596103e8826130c1565b6110679060408601356130d4565b61107191906130eb565b8510156110aa576040517f95b2fb6900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82604001358510156110e8576040517f9463b69700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82602001358614611125576040517f868a64de00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008061117861113c61113787611b0a565b611bfc565b85858080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611c4a92505050565b509092509050600081600381111561119257611192613126565b1415806111b3575073ffffffffffffffffffffffffffffffffffffffff8216155b806111d9575060025473ffffffffffffffffffffffffffffffffffffffff838116911614155b15611210576040517f070f548200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050505050505050565b60405173ffffffffffffffffffffffffffffffffffffffff83811660248301526044820183905261129b91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611c97565b505050565b8060006112b3604087016020880161295d565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff848116600483015291909116906370a0823190602401602060405180830381865afa158015611321573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113459190612fd2565b905073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba31663137c29fe61140e61138f89612ee9565b6040805160a0810182526000606082018181526080830182905282526020820181905291810191909152506040805160a08101825260208084015173ffffffffffffffffffffffffffffffffffffffff1660608301908152848401516080840152825260e08401519082015260c09092015163ffffffff169082015290565b61145a8561141b8b612ee9565b60408051808201825260008082526020918201528151808301835273ffffffffffffffffffffffffffffffffffffffff90941684529101519082015290565b61146760208b018b61295d565b6040517f53696e676c65436861696e4c696d69744f72646572280000000000000000000060208201527f6164647265737320757365722c0000000000000000000000000000000000000060368201527f6164647265737320746f6b656e496e2c0000000000000000000000000000000060438201527f75696e7432353620616d6f756e74496e2c00000000000000000000000000000060538201527f5472616e7366657244617461207265717565737465644f75747075742c00000060648201527f5472616e73666572446174615b5d2065787472615472616e73666572732c000060818201527f627974657320656e636f64656445787465726e616c43616c6c446174612c0000609f8201527f75696e74333220646561646c696e652c0000000000000000000000000000000060bd8201527f75696e74323536206e6f6e63652900000000000000000000000000000000000060cd8201528c9060db01604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815260608301909152602e8083529091906137a960208301396040518060600160405280603b81526020016137d7603b913960405160200161163293929190613155565b6040516020818303038152906040528b8b6040518863ffffffff1660e01b815260040161166597969594939291906131c4565b600060405180830381600087803b15801561167f57600080fd5b505af1158015611693573d6000803e3d6000fd5b505050506000818760200160208101906116ad919061295d565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff868116600483015291909116906370a0823190602401602060405180830381865afa15801561171b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061173f9190612fd2565b611749919061301a565b90508660400135811015611210576040517fe1628f7200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008060405180606001604052808860600160000160208101906117ad919061295d565b73ffffffffffffffffffffffffffffffffffffffff1681526020016117d860a08a0160808b0161295d565b73ffffffffffffffffffffffffffffffffffffffff16815260200189815250905061196260405180610100016040528089602001602081019061181b919061295d565b73ffffffffffffffffffffffffffffffffffffffff168152602001896040013581526020018381526020018860600180360381019061185a91906132c1565b815260200161186c60c08b018b6132dd565b808060200260200160405190810160405280939291908181526020016000905b828210156118b8576118a9606083028601368190038101906132c1565b8152602001906001019061188c565b505050505081526020018773ffffffffffffffffffffffffffffffffffffffff16815260200186868080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509082525060200161192760e08b018b613344565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050915250611d3b565b98975050505050505050565b600180547fffffffffffffffffffffffff000000000000000000000000000000000000000016905561051f81611fc0565b60606119cc7f53696e676c65436861696e47756172644c696d697400000000000000000000156003612035565b905090565b60606119cc7f31000000000000000000000000000000000000000000000000000000000000016004612035565b60405173ffffffffffffffffffffffffffffffffffffffff8481166024830152838116604483015260648201839052611a449186918216906323b872dd90608401611254565b50505050565b60006040518060600160405280603b81526020016137d7603b9139604051602001611a7591906133a9565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181528282528051602091820120855186830151878501519386019290925273ffffffffffffffffffffffffffffffffffffffff90811693850193909352919091166060830152608082015260a0015b604051602081830303815290604052805190602001209050919050565b60006040518060600160405280603b81526020016137d7603b9139604051602001611b3591906133c5565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152919052805160209182012090611b789084018461295d565b60208401356040850135611b9c611b97368890038801606089016132c1565b611a4a565b611bac60e0880160c08901612fb7565b60408051602081019790975273ffffffffffffffffffffffffffffffffffffffff909516948601949094526060850192909252608084015260a083015263ffffffff1660c082015260e001611aed565b6000611c44611c096120e0565b836040517f19010000000000000000000000000000000000000000000000000000000000008152600281019290925260228201526042902090565b92915050565b60008060008351604103611c845760208401516040850151606086015160001a611c7688828585612218565b955095509550505050611c90565b50508151600091506002905b9250925092565b600080602060008451602086016000885af180611cba576040513d6000823e3d81fd5b50506000513d91508115611cd2578060011415611cec565b73ffffffffffffffffffffffffffffffffffffffff84163b155b15611a44576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8516600482015260240161050d565b60e0810151516080820151516000911515908290611d5a9060026130c1565b67ffffffffffffffff811115611d7257611d72612c98565b604051908082528060200260200182016040528015611ddb57816020015b60408051606081018252600080825260208083018290529282015282527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff909201910181611d905790505b5090506000611e7681604051806060016040528088604001516000015173ffffffffffffffffffffffffffffffffffffffff16815260200186611e2657886040015160200151611e48565b7f00000000000000000000000062d4b37ed6427e623ae915cd7bbf0e7784c73b535b73ffffffffffffffffffffffffffffffffffffffff1681526040808a01510151602090910152849190612312565b9050611e91818660600151846123129092919063ffffffff16565b905060005b856080015151811015611edf57611ed58287608001518381518110611ebd57611ebd61302d565b6020026020010151856123129092919063ffffffff16565b9150600101611e96565b508082526000611eee83612492565b60a08701518751602089015160c08a01516040517f3071d61d00000000000000000000000000000000000000000000000000000000815294955073ffffffffffffffffffffffffffffffffffffffff90931693633071d61d93611f58939291899190600401613514565b600060405180830381600087803b158015611f7257600080fd5b505af1158015611f86573d6000803e3d6000fd5b50505050611f9d818461255890919063ffffffff16565b94508315611fb757611fb786604001518760e001516126fc565b50505050919050565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b606060ff831461204f57612048836127db565b9050611c44565b81805461205b906135cf565b80601f0160208091040260200160405190810160405280929190818152602001828054612087906135cf565b80156120d45780601f106120a9576101008083540402835291602001916120d4565b820191906000526020600020905b8154815290600101906020018083116120b757829003601f168201915b50505050509050611c44565b60003073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000008cbaa5db68c1dc5485dbc8dd1f86b089614926e71614801561214657507f000000000000000000000000000000000000000000000000000000000000008f46145b1561217057507fc62618dd8e3c484f6dd5c4b6f21e8c7e207fe01b395f86aa48313e0f29a701d090565b6119cc604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527fd00fcd1da9b4458beab6749a64d520ced1aefd5405d62d64279508d0afa16434918101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b600080807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08411156122535750600091506003905082612308565b604080516000808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa1580156122a7573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff81166122fe57506000925060019150829050612308565b9250600091508190505b9450945094915050565b6000816040015160000361232757508161248b565b8351831115612362576040517f2116eb0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b8381101561245e57826000015173ffffffffffffffffffffffffffffffffffffffff1685828151811061239a5761239a61302d565b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff161480156124155750826020015173ffffffffffffffffffffffffffffffffffffffff168582815181106123f1576123f161302d565b60200260200101516020015173ffffffffffffffffffffffffffffffffffffffff16145b156124565782604001518582815181106124315761243161302d565b602002602001015160400181815161244991906130c1565b90525083915061248b9050565b600101612365565b50818484815181106124725761247261302d565b60209081029190910101526124888360016130c1565b90505b9392505050565b60606000825167ffffffffffffffff8111156124b0576124b0612c98565b6040519080825280602002602001820160405280156124d9578160200160208202803683370190505b50905060005b83518110156125515761252c8482815181106124fd576124fd61302d565b60200260200101516000015185838151811061251b5761251b61302d565b60200260200101516020015161281a565b82828151811061253e5761253e61302d565b60209081029190910101526001016124df565b5092915050565b60008251825114612595576040517f2116eb0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506000805b83518110156125515760006125d88583815181106125ba576125ba61302d565b60200260200101516000015186848151811061251b5761251b61302d565b905060008483815181106125ee576125ee61302d565b602002602001015182612601919061301a565b90508260000361260f578093505b8583815181106126215761262161302d565b6020026020010151604001518110156126f2578583815181106126465761264661302d565b6020026020010151600001518684815181106126645761266461302d565b6020026020010151602001518785815181106126825761268261302d565b602090810291909101015160409081015190517f1f00e79900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff938416600482015292909116602483015260448201526064810182905260840161050d565b505060010161259a565b60008060008084806020019051810190612716919061362b565b895160208b01516040517f9aca0642000000000000000000000000000000000000000000000000000000008152959950939750919550935073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000062d4b37ed6427e623ae915cd7bbf0e7784c73b531692639aca0642926127a1929189908990899089906004016136db565b600060405180830381600087803b1580156127bb57600080fd5b505af11580156127cf573d6000803e3d6000fd5b50505050505050505050565b606060006127e8836128ea565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b600073ffffffffffffffffffffffffffffffffffffffff8316156128cd576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83811660048301528416906370a0823190602401602060405180830381865afa1580156128a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128c89190612fd2565b61248b565b5073ffffffffffffffffffffffffffffffffffffffff1631919050565b600060ff8216601f811115611c44576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8116811461051f57600080fd5b80356129588161292b565b919050565b60006020828403121561296f57600080fd5b813561248b8161292b565b6000610140828403121561298d57600080fd5b50919050565b60008083601f8401126129a557600080fd5b50813567ffffffffffffffff8111156129bd57600080fd5b6020830191508360208285010111156129d557600080fd5b9250929050565b600060e0828403121561298d57600080fd5b8035801515811461295857600080fd5b60008060008060008060008060008060006101c08c8e031215612a2057600080fd5b8b359a5060208c013567ffffffffffffffff811115612a3e57600080fd5b612a4a8e828f0161297a565b9a505060408c013567ffffffffffffffff811115612a6757600080fd5b612a738e828f01612993565b909a509850612a8790508d60608e016129dc565b96506101408c013567ffffffffffffffff811115612aa457600080fd5b612ab08e828f01612993565b9097509550612ac490506101608d0161294d565b93506101808c013567ffffffffffffffff811115612ae157600080fd5b612aed8e828f01612993565b9094509250612b0190506101a08d016129ee565b90509295989b509295989b9093969950565b60005b83811015612b2e578181015183820152602001612b16565b50506000910152565b60008151808452612b4f816020860160208601612b13565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b7fff000000000000000000000000000000000000000000000000000000000000008816815260e060208201526000612bbc60e0830189612b37565b8281036040840152612bce8189612b37565b6060840188905273ffffffffffffffffffffffffffffffffffffffff8716608085015260a0840186905283810360c08501528451808252602080870193509091019060005b81811015612c31578351835260209384019390920191600101612c13565b50909b9a5050505050505050505050565b600060208284031215612c5457600080fd5b5035919050565b600060208284031215612c6d57600080fd5b813567ffffffffffffffff811115612c8457600080fd5b612c908482850161297a565b949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051610100810167ffffffffffffffff81118282101715612ceb57612ceb612c98565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715612d3857612d38612c98565b604052919050565b600060608284031215612d5257600080fd5b6040516060810167ffffffffffffffff81118282101715612d7557612d75612c98565b6040529050808235612d868161292b565b81526020830135612d968161292b565b6020820152604092830135920191909152919050565b600082601f830112612dbd57600080fd5b813567ffffffffffffffff811115612dd757612dd7612c98565b612de660208260051b01612cf1565b80828252602082019150602060608402860101925085831115612e0857600080fd5b602085015b83811015612e2f57612e1f8782612d40565b8352602090920191606001612e0d565b5095945050505050565b600067ffffffffffffffff821115612e5357612e53612c98565b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b600082601f830112612e9057600080fd5b8135612ea3612e9e82612e39565b612cf1565b818152846020838601011115612eb857600080fd5b816020850160208301376000918101602001919091529392505050565b803563ffffffff8116811461295857600080fd5b60006101408236031215612efc57600080fd5b612f04612cc7565b612f0d8361294d565b8152612f1b6020840161294d565b602082015260408381013590820152612f373660608501612d40565b606082015260c083013567ffffffffffffffff811115612f5657600080fd5b612f6236828601612dac565b60808301525060e083013567ffffffffffffffff811115612f8257600080fd5b612f8e36828601612e7f565b60a083015250612fa16101008401612ed5565b60c0820152610120929092013560e08301525090565b600060208284031215612fc957600080fd5b61248b82612ed5565b600060208284031215612fe457600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b81810381811115611c4457611c44612feb565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000835161306e818460208801612b13565b835190830190613082818360208801612b13565b01949350505050565b8151600090829060208501835b828110156130b6578151845260209384019390910190600101613098565b509195945050505050565b80820180821115611c4457611c44612feb565b8082028115828204841417611c4457611c44612feb565b600082613121577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b7f53696e676c65436861696e4c696d69744f72646572207769746e65737329000081526000845161318d81601e850160208901612b13565b8451908301906131a481601e840160208901612b13565b84519101601e01906131ba818360208801612b13565b0195945050505050565b6131ef818951805173ffffffffffffffffffffffffffffffffffffffff168252602090810151910152565b60208801516040820152604088015160608201526132306080820188805173ffffffffffffffffffffffffffffffffffffffff168252602090810151910152565b73ffffffffffffffffffffffffffffffffffffffff861660c08201528460e0820152610140610100820152600061326b610140830186612b37565b8281036101208401528381528385602083013760006020858301015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f86011682010191505098975050505050505050565b6000606082840312156132d357600080fd5b61248b8383612d40565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261331257600080fd5b83018035915067ffffffffffffffff82111561332d57600080fd5b60200191506060810236038213156129d557600080fd5b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261337957600080fd5b83018035915067ffffffffffffffff82111561339457600080fd5b6020019150368190038213156129d557600080fd5b600082516133bb818460208701612b13565b9190910192915050565b7f53696e676c65436861696e4c696d6974536f6c7665725065726d697373696f6e81527f280000000000000000000000000000000000000000000000000000000000000060208201527f6164647265737320736f6c7665722c000000000000000000000000000000000060218201527f62797465733332206f72646572486173682c000000000000000000000000000060308201527f75696e7432353620616d6f756e744f75744d696e2c000000000000000000000060428201527f5472616e73666572446174612070726f746f636f6c4665655472616e7366657260578201527f2c0000000000000000000000000000000000000000000000000000000000000060778201527f75696e743332207065726d697373696f6e446561646c696e6529000000000000607882015260008251613507816092850160208701612b13565b9190910160920192915050565b60006080820173ffffffffffffffffffffffffffffffffffffffff871683528560208401526080604084015280855180835260a08501915060208701925060005b818110156135bb57835173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501526040810151604085015250606083019250602084019350600181019050613555565b505083810360608501526119628186612b37565b600181811c908216806135e357607f821691505b60208210810361298d577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b80516002811061295857600080fd5b6000806000806080858703121561364157600080fd5b845161364c8161292b565b602086015190945061365d8161292b565b604086015190935067ffffffffffffffff81111561367a57600080fd5b8501601f8101871361368b57600080fd5b8051613699612e9e82612e39565b8181528860208385010111156136ae57600080fd5b6136bf826020830160208601612b13565b93506136d09150506060860161361c565b905092959194509250565b73ffffffffffffffffffffffffffffffffffffffff8716815273ffffffffffffffffffffffffffffffffffffffff8616602082015273ffffffffffffffffffffffffffffffffffffffff8516604082015273ffffffffffffffffffffffffffffffffffffffff8416606082015260c06080820152600061375e60c0830185612b37565b905060028310613797577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8260a083015297965050505050505056fe546f6b656e5065726d697373696f6e73286164647265737320746f6b656e2c75696e7432353620616d6f756e74295472616e7366657244617461286164647265737320746f6b656e2c616464726573732072656365697665722c75696e7432353620616d6f756e7429a2646970667358221220a44fe2143fe2534b60068f92c2a534c9a32b55d8f3c9ffb1ae6b5a5b6044f55a64736f6c634300081c0033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in MON
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
[ 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.