Source Code
Overview
ETH Balance
0 ETH
More Info
ContractCreator
Multichain Info
N/A
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
4447594 | 2 days ago | Contract Creation | 0 ETH |
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x1671BACf...c246bE74d The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
SheepySale
Compiler Version
v0.8.28+commit.7893614a
ZkSolc Version
v1.5.7
Optimization Enabled:
Yes with Mode 3
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import {SheepyBase} from "./SheepyBase.sol"; import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol"; import {MetadataReaderLib} from "solady/utils/MetadataReaderLib.sol"; import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol"; import {ECDSA} from "solady/utils/ECDSA.sol"; contract SheepySale is SheepyBase { using ECDSA for bytes32; /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* STRUCTS */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev For configuring a sale. struct SaleConfig { address erc20ToSell; uint256 price; // Per `10 ** erc20ToSell.decimals()`. uint256 startTime; uint256 endTime; uint256 totalQuota; // The maximum amount that can be bought. uint256 addressQuota; // The maximum amount that can be bought per-address. address signer; // Leave as `address(0)` if no WL required. } /// @dev Holds the information for a sale. struct SaleInfo { address erc20ToSell; uint256 price; uint256 startTime; uint256 endTime; uint256 totalQuota; uint256 addressQuota; uint256 totalBought; address signer; } /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* EVENTS */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev Emitted for a purchase. event Bought(address by, address to, address erc20ToSell, uint256 price, uint256 amount); /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* STORAGE */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev Sale storage. struct Sale { address erc20ToSell; uint256 price; uint256 startTime; uint256 endTime; uint256 totalQuota; uint256 addressQuota; uint256 totalBought; address signer; mapping(address => uint256) bought; } /// @dev The sales structs. mapping(uint256 => Sale) internal _sales; /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* INITIALIZER */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev For initialization. function initialize(address initialOwner, address initialAdmin, string memory notSoSecret) public virtual { _initializeSheepyBase(initialOwner, initialAdmin, notSoSecret); } /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* SALE */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev Public sale function. /// The `customAddressQuota` can be used to allow dynamic on-the-fly per-address quotas. function buy( uint256 saleId, address to, uint256 amount, uint256 customAddressQuota, bytes calldata signature ) public payable { Sale storage s = _sales[saleId]; require(s.erc20ToSell != address(0), "ERC20 not set."); require(s.startTime <= block.timestamp && block.timestamp <= s.endTime, "Not open."); require((s.totalBought += amount) <= s.totalQuota, "Exceeded total quota."); uint256 minAddressQuota = FixedPointMathLib.min(customAddressQuota, s.addressQuota); require((s.bought[msg.sender] += amount) <= minAddressQuota, "Exceeded address quota."); require(msg.value == priceOf(s.erc20ToSell, amount, s.price), "Wrong payment."); if (s.signer != address(0)) { bytes32 hash = keccak256("SheepySale"); hash = keccak256(abi.encode(hash, saleId, msg.sender, customAddressQuota)); hash = hash.toEthSignedMessageHash(); require(hash.recover(signature) == s.signer, "Invalid signature."); } SafeTransferLib.safeTransfer(s.erc20ToSell, to, amount); emit Bought(msg.sender, to, s.erc20ToSell, s.price, amount); } /// @dev Returns the amount of native currency required for payment. function priceOf(address erc20, uint256 amount, uint256 price) public view returns (uint256) { uint256 decimals = MetadataReaderLib.readDecimals(erc20, type(uint256).max); return FixedPointMathLib.fullMulDivUp(amount, price, 10 ** decimals); } /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* PUBLIC VIEW FUNCTIONS */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev Returns info for `saleId`. function saleInfo(uint256 saleId) public view returns (SaleInfo memory info) { Sale storage s = _sales[saleId]; info.erc20ToSell = s.erc20ToSell; info.price = s.price; info.startTime = s.startTime; info.endTime = s.endTime; info.totalQuota = s.totalQuota; info.addressQuota = s.addressQuota; info.signer = s.signer; info.totalBought = s.totalBought; } /// @dev Returns the total amount bought by `by` in `saleId`. function bought(uint256 saleId, address by) public view returns (uint256) { return _sales[saleId].bought[by]; } /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* ADMIN FUNCTIONS */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev Sets the sale config. function setSale(uint256 saleId, SaleConfig calldata c) public onlyOwnerOrRole(ADMIN_ROLE) { Sale storage s = _sales[saleId]; s.erc20ToSell = c.erc20ToSell; s.price = c.price; s.startTime = c.startTime; s.endTime = c.endTime; s.totalQuota = c.totalQuota; s.addressQuota = c.addressQuota; s.signer = c.signer; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import {Ownable} from "solady/auth/Ownable.sol"; import {EnumerableRoles} from "solady/auth/EnumerableRoles.sol"; import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol"; contract SheepyBase is Ownable, EnumerableRoles { /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* CONSTANTS */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev The admin role. uint256 public constant ADMIN_ROLE = 0; /// @dev The role that can withdraw native currency. uint256 public constant WITHDRAWER_ROLE = 1; /// @dev The maximum role that can be set. uint256 public constant MAX_ROLE = 1; /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* INITIALIZER */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev For initialization. function _initializeSheepyBase( address initialOwner, address initialAdmin, string memory notSoSecret ) internal virtual { _initializeOwner(initialOwner); require( keccak256(bytes(notSoSecret)) == 0x9f6dc27901fd3c0399e319e16bba7e24d8bb2b077fe896daffd2108aa65c40cc ); if (initialAdmin != address(0)) _setRole(initialAdmin, ADMIN_ROLE, true); } /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* ADMIN FUNCTIONS */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev Withdraws `amount` of `erc20` to `to`. function withdrawERC20(address erc20, address to, uint256 amount) public onlyOwnerOrRole(WITHDRAWER_ROLE) { SafeTransferLib.safeTransfer(erc20, _coalesce(to), amount); } /// @dev Withdraws all the native currency in the contract to `to`. function withdrawAllNative(address to) public onlyOwnerOrRole(WITHDRAWER_ROLE) { SafeTransferLib.safeTransferAllETH(_coalesce(to)); } /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* INTERNAL HELPERS */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev Coalesces `to` to `msg.sender` if it is `address(0)`. function _coalesce(address to) internal view returns (address) { return to == address(0) ? msg.sender : to; } /*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/ /* OVERRIDES */ /*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/ /// @dev So that `_initializeOwner` cannot be called twice. function _guardInitializeOwner() internal pure virtual override returns (bool) { return true; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol) /// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol) /// /// @dev Note: /// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection. library SafeTransferLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The ETH transfer has failed. error ETHTransferFailed(); /// @dev The ERC20 `transferFrom` has failed. error TransferFromFailed(); /// @dev The ERC20 `transfer` has failed. error TransferFailed(); /// @dev The ERC20 `approve` has failed. error ApproveFailed(); /// @dev The ERC20 `totalSupply` query has failed. error TotalSupplyQueryFailed(); /// @dev The Permit2 operation has failed. error Permit2Failed(); /// @dev The Permit2 amount must be less than `2**160 - 1`. error Permit2AmountOverflow(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes. uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300; /// @dev Suggested gas stipend for contract receiving ETH to perform a few /// storage reads and writes, but low enough to prevent griefing. uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000; /// @dev The unique EIP-712 domain domain separator for the DAI token contract. bytes32 internal constant DAI_DOMAIN_SEPARATOR = 0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7; /// @dev The address for the WETH9 contract on Ethereum mainnet. address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; /// @dev The canonical Permit2 address. /// [Github](https://github.com/Uniswap/permit2) /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3) address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ETH OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants. // // The regular variants: // - Forwards all remaining gas to the target. // - Reverts if the target reverts. // - Reverts if the current contract has insufficient balance. // // The force variants: // - Forwards with an optional gas stipend // (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases). // - If the target reverts, or if the gas stipend is exhausted, // creates a temporary contract to force send the ETH via `SELFDESTRUCT`. // Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758. // - Reverts if the current contract has insufficient balance. // // The try variants: // - Forwards with a mandatory gas stipend. // - Instead of reverting, returns whether the transfer succeeded. /// @dev Sends `amount` (in wei) ETH to `to`. function safeTransferETH(address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } } } /// @dev Sends all the ETH in the current contract to `to`. function safeTransferAllETH(address to) internal { /// @solidity memory-safe-assembly assembly { // Transfer all the ETH and check if it succeeded or not. if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } } } /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`. function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal { /// @solidity memory-safe-assembly assembly { if lt(selfbalance(), amount) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`. function forceSafeTransferAllETH(address to, uint256 gasStipend) internal { /// @solidity memory-safe-assembly assembly { if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`. function forceSafeTransferETH(address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { if lt(selfbalance(), amount) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`. function forceSafeTransferAllETH(address to) internal { /// @solidity memory-safe-assembly assembly { // forgefmt: disable-next-item if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`. function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00) } } /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`. function trySafeTransferAllETH(address to, uint256 gasStipend) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC20 OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// Reverts upon failure. /// /// The `from` account must have at least `amount` approved for /// the current contract to manage. function safeTransferFrom(address token, address from, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, amount) // Store the `amount` argument. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`. let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// /// The `from` account must have at least `amount` approved for the current contract to manage. function trySafeTransferFrom(address token, address from, address to, uint256 amount) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, amount) // Store the `amount` argument. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`. success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { success := lt(or(iszero(extcodesize(token)), returndatasize()), success) } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends all of ERC20 `token` from `from` to `to`. /// Reverts upon failure. /// /// The `from` account must have their entire balance approved for the current contract to manage. function safeTransferAllFrom(address token, address from, address to) internal returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`. // Read the balance, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20) ) ) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`. amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it. // Perform the transfer, reverting upon failure. let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`. /// Reverts upon failure. function safeTransfer(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`. // Perform the transfer, reverting upon failure. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sends all of ERC20 `token` from the current contract to `to`. /// Reverts upon failure. function safeTransferAll(address token, address to) internal returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`. mstore(0x20, address()) // Store the address of the current contract. // Read the balance, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20) ) ) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } mstore(0x14, to) // Store the `to` argument. amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it. mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`. // Perform the transfer, reverting upon failure. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract. /// Reverts upon failure. function safeApprove(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`. revert(0x1c, 0x04) } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract. /// If the initial attempt to approve fails, attempts to reset the approved amount to zero, /// then retries the approval again (some tokens, e.g. USDT, requires this). /// Reverts upon failure. function safeApproveWithRetry(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. // Perform the approval, retrying upon failure. let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x34, 0) // Store 0 for the `amount`. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval. mstore(0x34, amount) // Store back the original `amount`. // Retry the approval, reverting upon failure. success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) if iszero(and(eq(mload(0x00), 1), success)) { // Check the `extcodesize` again just in case the token selfdestructs lol. if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) { mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`. revert(0x1c, 0x04) } } } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Returns the amount of ERC20 `token` owned by `account`. /// Returns zero if the `token` does not exist. function balanceOf(address token, address account) internal view returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { mstore(0x14, account) // Store the `account` argument. mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`. amount := mul( // The arguments of `mul` are evaluated from right to left. mload(0x20), and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20) ) ) } } /// @dev Returns the total supply of the `token`. /// Reverts if the token does not exist or does not implement `totalSupply()`. function totalSupply(address token) internal view returns (uint256 result) { /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x18160ddd) // `totalSupply()`. if iszero( and(gt(returndatasize(), 0x1f), staticcall(gas(), token, 0x1c, 0x04, 0x00, 0x20)) ) { mstore(0x00, 0x54cd9435) // `TotalSupplyQueryFailed()`. revert(0x1c, 0x04) } result := mload(0x00) } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// If the initial attempt fails, try to use Permit2 to transfer the token. /// Reverts upon failure. /// /// The `from` account must have at least `amount` approved for the current contract to manage. function safeTransferFrom2(address token, address from, address to, uint256 amount) internal { if (!trySafeTransferFrom(token, from, to, amount)) { permit2TransferFrom(token, from, to, amount); } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2. /// Reverts upon failure. function permit2TransferFrom(address token, address from, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(add(m, 0x74), shr(96, shl(96, token))) mstore(add(m, 0x54), amount) mstore(add(m, 0x34), to) mstore(add(m, 0x20), shl(96, from)) // `transferFrom(address,address,uint160,address)`. mstore(m, 0x36c78516000000000000000000000000) let p := PERMIT2 let exists := eq(chainid(), 1) if iszero(exists) { exists := iszero(iszero(extcodesize(p))) } if iszero( and( call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00), lt(iszero(extcodesize(token)), exists) // Token has code and Permit2 exists. ) ) { mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`. revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04) } } } /// @dev Permit a user to spend a given amount of /// another user's tokens via native EIP-2612 permit if possible, falling /// back to Permit2 if native permit fails or is not implemented on the token. function permit2( address token, address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { bool success; /// @solidity memory-safe-assembly assembly { for {} shl(96, xor(token, WETH9)) {} { mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`. if iszero( and( // The arguments of `and` are evaluated from right to left. lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word. // Gas stipend to limit gas burn for tokens that don't refund gas when // an non-existing function is called. 5K should be enough for a SLOAD. staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20) ) ) { break } // After here, we can be sure that token is a contract. let m := mload(0x40) mstore(add(m, 0x34), spender) mstore(add(m, 0x20), shl(96, owner)) mstore(add(m, 0x74), deadline) if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) { mstore(0x14, owner) mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`. mstore( add(m, 0x94), lt(iszero(amount), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20)) ) mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`. // `nonces` is already at `add(m, 0x54)`. // `amount != 0` is already stored at `add(m, 0x94)`. mstore(add(m, 0xb4), and(0xff, v)) mstore(add(m, 0xd4), r) mstore(add(m, 0xf4), s) success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00) break } mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`. mstore(add(m, 0x54), amount) mstore(add(m, 0x94), and(0xff, v)) mstore(add(m, 0xb4), r) mstore(add(m, 0xd4), s) success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00) break } } if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s); } /// @dev Simple permit on the Permit2 contract. function simplePermit2( address token, address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(m, 0x927da105) // `allowance(address,address,address)`. { let addressMask := shr(96, not(0)) mstore(add(m, 0x20), and(addressMask, owner)) mstore(add(m, 0x40), and(addressMask, token)) mstore(add(m, 0x60), and(addressMask, spender)) mstore(add(m, 0xc0), and(addressMask, spender)) } let p := mul(PERMIT2, iszero(shr(160, amount))) if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`. staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60) ) ) { mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`. revert(add(0x18, shl(2, iszero(p))), 0x04) } mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant). // `owner` is already `add(m, 0x20)`. // `token` is already at `add(m, 0x40)`. mstore(add(m, 0x60), amount) mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`. // `nonce` is already at `add(m, 0xa0)`. // `spender` is already at `add(m, 0xc0)`. mstore(add(m, 0xe0), deadline) mstore(add(m, 0x100), 0x100) // `signature` offset. mstore(add(m, 0x120), 0x41) // `signature` length. mstore(add(m, 0x140), r) mstore(add(m, 0x160), s) mstore(add(m, 0x180), shl(248, v)) if iszero( // Revert if token does not have code, or if the call fails. mul(extcodesize(token), call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00))) { mstore(0x00, 0x6b836e6b) // `Permit2Failed()`. revert(0x1c, 0x04) } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Library for reading contract metadata robustly. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/MetadataReaderLib.sol) library MetadataReaderLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Default gas stipend for contract reads. High enough for most practical use cases /// (able to SLOAD about 1000 bytes of data), but low enough to prevent griefing. uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000; /// @dev Default string byte length limit. uint256 internal constant STRING_LIMIT_DEFAULT = 1000; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* METADATA READING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // Best-effort string reading operations. // Should NOT revert as long as sufficient gas is provided. // // Performs the following in order: // 1. Returns the empty string for the following cases: // - Reverts. // - No returndata (e.g. function returns nothing, EOA). // - Returns empty string. // 2. Attempts to `abi.decode` the returndata into a string. // 3. With any remaining gas, scans the returndata from start to end for the // null byte '\0', to interpret the returndata as a null-terminated string. /// @dev Equivalent to `readString(abi.encodeWithSignature("name()"))`. function readName(address target) internal view returns (string memory) { return _string(target, _ptr(0x06fdde03), STRING_LIMIT_DEFAULT, GAS_STIPEND_NO_GRIEF); } /// @dev Equivalent to `readString(abi.encodeWithSignature("name()"), limit)`. function readName(address target, uint256 limit) internal view returns (string memory) { return _string(target, _ptr(0x06fdde03), limit, GAS_STIPEND_NO_GRIEF); } /// @dev Equivalent to `readString(abi.encodeWithSignature("name()"), limit, gasStipend)`. function readName(address target, uint256 limit, uint256 gasStipend) internal view returns (string memory) { return _string(target, _ptr(0x06fdde03), limit, gasStipend); } /// @dev Equivalent to `readString(abi.encodeWithSignature("symbol()"))`. function readSymbol(address target) internal view returns (string memory) { return _string(target, _ptr(0x95d89b41), STRING_LIMIT_DEFAULT, GAS_STIPEND_NO_GRIEF); } /// @dev Equivalent to `readString(abi.encodeWithSignature("symbol()"), limit)`. function readSymbol(address target, uint256 limit) internal view returns (string memory) { return _string(target, _ptr(0x95d89b41), limit, GAS_STIPEND_NO_GRIEF); } /// @dev Equivalent to `readString(abi.encodeWithSignature("symbol()"), limit, gasStipend)`. function readSymbol(address target, uint256 limit, uint256 gasStipend) internal view returns (string memory) { return _string(target, _ptr(0x95d89b41), limit, gasStipend); } /// @dev Performs a best-effort string query on `target` with `data` as the calldata. /// The string will be truncated to `STRING_LIMIT_DEFAULT` (1000) bytes. function readString(address target, bytes memory data) internal view returns (string memory) { return _string(target, _ptr(data), STRING_LIMIT_DEFAULT, GAS_STIPEND_NO_GRIEF); } /// @dev Performs a best-effort string query on `target` with `data` as the calldata. /// The string will be truncated to `limit` bytes. function readString(address target, bytes memory data, uint256 limit) internal view returns (string memory) { return _string(target, _ptr(data), limit, GAS_STIPEND_NO_GRIEF); } /// @dev Performs a best-effort string query on `target` with `data` as the calldata. /// The string will be truncated to `limit` bytes. function readString(address target, bytes memory data, uint256 limit, uint256 gasStipend) internal view returns (string memory) { return _string(target, _ptr(data), limit, gasStipend); } // Best-effort unsigned integer reading operations. // Should NOT revert as long as sufficient gas is provided. // // Performs the following in order: // 1. Attempts to `abi.decode` the result into a uint256 // (equivalent across all Solidity uint types, downcast as needed). // 2. Returns zero for the following cases: // - Reverts. // - No returndata (e.g. function returns nothing, EOA). // - Returns zero. // - `abi.decode` failure. /// @dev Equivalent to `uint8(readUint(abi.encodeWithSignature("decimals()")))`. function readDecimals(address target) internal view returns (uint8) { return uint8(_uint(target, _ptr(0x313ce567), GAS_STIPEND_NO_GRIEF)); } /// @dev Equivalent to `uint8(readUint(abi.encodeWithSignature("decimals()"), gasStipend))`. function readDecimals(address target, uint256 gasStipend) internal view returns (uint8) { return uint8(_uint(target, _ptr(0x313ce567), gasStipend)); } /// @dev Performs a best-effort uint query on `target` with `data` as the calldata. function readUint(address target, bytes memory data) internal view returns (uint256) { return _uint(target, _ptr(data), GAS_STIPEND_NO_GRIEF); } /// @dev Performs a best-effort uint query on `target` with `data` as the calldata. function readUint(address target, bytes memory data, uint256 gasStipend) internal view returns (uint256) { return _uint(target, _ptr(data), gasStipend); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PRIVATE HELPERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Attempts to read and return a string at `target`. function _string(address target, bytes32 ptr, uint256 limit, uint256 gasStipend) private view returns (string memory result) { /// @solidity memory-safe-assembly assembly { function min(x_, y_) -> _z { _z := xor(x_, mul(xor(x_, y_), lt(y_, x_))) } for {} staticcall(gasStipend, target, add(ptr, 0x20), mload(ptr), 0x00, 0x20) {} { let m := mload(0x40) // Grab the free memory pointer. let s := add(0x20, m) // Start of the string's bytes in memory. // Attempt to `abi.decode` if the returndatasize is greater or equal to 64. if iszero(lt(returndatasize(), 0x40)) { let o := mload(0x00) // Load the string's offset in the returndata. // If the string's offset is within bounds. if iszero(gt(o, sub(returndatasize(), 0x20))) { returndatacopy(m, o, 0x20) // Copy the string's length. // If the full string's end is within bounds. // Note: If the full string doesn't fit, the `abi.decode` must be aborted // for compliance purposes, regardless if the truncated string can fit. if iszero(gt(mload(m), sub(returndatasize(), add(o, 0x20)))) { let n := min(mload(m), limit) // Truncate if needed. mstore(m, n) // Overwrite the length. returndatacopy(s, add(o, 0x20), n) // Copy the string's bytes. mstore(add(s, n), 0) // Zeroize the slot after the string. mstore(0x40, add(0x20, add(s, n))) // Allocate memory for the string. result := m break } } } // Try interpreting as a null-terminated string. let n := min(returndatasize(), limit) // Truncate if needed. returndatacopy(s, 0, n) // Copy the string's bytes. mstore8(add(s, n), 0) // Place a '\0' at the end. let i := s // Pointer to the next byte to scan. for {} byte(0, mload(i)) { i := add(i, 1) } {} // Scan for '\0'. mstore(m, sub(i, s)) // Store the string's length. mstore(i, 0) // Zeroize the slot after the string. mstore(0x40, add(0x20, i)) // Allocate memory for the string. result := m break } } } /// @dev Attempts to read and return a uint at `target`. function _uint(address target, bytes32 ptr, uint256 gasStipend) private view returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := mul( mload(0x20), and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gasStipend, target, add(ptr, 0x20), mload(ptr), 0x20, 0x20) ) ) } } /// @dev Casts the function selector `s` into a pointer. function _ptr(uint256 s) private pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { // Layout the calldata in the scratch space for temporary usage. mstore(0x04, s) // Store the function selector. mstore(result, 4) // Store the length. } } /// @dev Casts the `data` into a pointer. function _ptr(bytes memory data) private pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { result := data } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Arithmetic library with operations for fixed-point numbers. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol) library FixedPointMathLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The operation failed, as the output exceeds the maximum value of uint256. error ExpOverflow(); /// @dev The operation failed, as the output exceeds the maximum value of uint256. error FactorialOverflow(); /// @dev The operation failed, due to an overflow. error RPowOverflow(); /// @dev The mantissa is too big to fit. error MantissaOverflow(); /// @dev The operation failed, due to an multiplication overflow. error MulWadFailed(); /// @dev The operation failed, due to an multiplication overflow. error SMulWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error DivWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error SDivWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error MulDivFailed(); /// @dev The division failed, as the denominator is zero. error DivFailed(); /// @dev The full precision multiply-divide operation failed, either due /// to the result being larger than 256 bits, or a division by a zero. error FullMulDivFailed(); /// @dev The output is undefined, as the input is less-than-or-equal to zero. error LnWadUndefined(); /// @dev The input outside the acceptable domain. error OutOfDomain(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The scalar of ETH and most ERC20s. uint256 internal constant WAD = 1e18; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* SIMPLIFIED FIXED POINT OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Equivalent to `(x * y) / WAD` rounded down. function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`. if gt(x, div(not(0), y)) { if y { mstore(0x00, 0xbac65e5b) // `MulWadFailed()`. revert(0x1c, 0x04) } } z := div(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down. function sMulWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`. if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) { mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`. revert(0x1c, 0x04) } z := sdiv(z, WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks. function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks. function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded up. function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`. if iszero(eq(div(z, y), x)) { if y { mstore(0x00, 0xbac65e5b) // `MulWadFailed()`. revert(0x1c, 0x04) } } z := add(iszero(iszero(mod(z, WAD))), div(z, WAD)) } } /// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks. function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD)) } } /// @dev Equivalent to `(x * WAD) / y` rounded down. function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`. if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) { mstore(0x00, 0x7c5f487d) // `DivWadFailed()`. revert(0x1c, 0x04) } z := div(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down. function sDivWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, WAD) // Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`. if iszero(mul(y, eq(sdiv(z, WAD), x))) { mstore(0x00, 0x5c43740d) // `SDivWadFailed()`. revert(0x1c, 0x04) } z := sdiv(z, y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks. function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks. function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded up. function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`. if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) { mstore(0x00, 0x7c5f487d) // `DivWadFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y)) } } /// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks. function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y)) } } /// @dev Equivalent to `x` to the power of `y`. /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`. /// Note: This function is an approximation. function powWad(int256 x, int256 y) internal pure returns (int256) { // Using `ln(x)` means `x` must be greater than 0. return expWad((lnWad(x) * y) / int256(WAD)); } /// @dev Returns `exp(x)`, denominated in `WAD`. /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln /// Note: This function is an approximation. Monotonically increasing. function expWad(int256 x) internal pure returns (int256 r) { unchecked { // When the result is less than 0.5 we return zero. // This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`. if (x <= -41446531673892822313) return r; /// @solidity memory-safe-assembly assembly { // When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as // an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`. if iszero(slt(x, 135305999368893231589)) { mstore(0x00, 0xa37bfec9) // `ExpOverflow()`. revert(0x1c, 0x04) } } // `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96` // for more intermediate precision and a binary basis. This base conversion // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78. x = (x << 78) / 5 ** 18; // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers // of two such that exp(x) = exp(x') * 2**k, where k is an integer. // Solving this gives k = round(x / log(2)) and x' = x - k * log(2). int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96; x = x - k * 54916777467707473351141471128; // `k` is in the range `[-61, 195]`. // Evaluate using a (6, 7)-term rational approximation. // `p` is made monic, we'll multiply by a scale factor later. int256 y = x + 1346386616545796478920950773328; y = ((y * x) >> 96) + 57155421227552351082224309758442; int256 p = y + x - 94201549194550492254356042504812; p = ((p * y) >> 96) + 28719021644029726153956944680412240; p = p * x + (4385272521454847904659076985693276 << 96); // We leave `p` in `2**192` basis so we don't need to scale it back up for the division. int256 q = x - 2855989394907223263936484059900; q = ((q * x) >> 96) + 50020603652535783019961831881945; q = ((q * x) >> 96) - 533845033583426703283633433725380; q = ((q * x) >> 96) + 3604857256930695427073651918091429; q = ((q * x) >> 96) - 14423608567350463180887372962807573; q = ((q * x) >> 96) + 26449188498355588339934803723976023; /// @solidity memory-safe-assembly assembly { // Div in assembly because solidity adds a zero check despite the unchecked. // The q polynomial won't have zeros in the domain as all its roots are complex. // No scaling is necessary because p is already `2**96` too large. r := sdiv(p, q) } // r should be in the range `(0.09, 0.25) * 2**96`. // We now need to multiply r by: // - The scale factor `s ≈ 6.031367120`. // - The `2**k` factor from the range reduction. // - The `1e18 / 2**96` factor for base conversion. // We do this all at once, with an intermediate result in `2**213` // basis, so the final right shift is always by a positive amount. r = int256( (uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k) ); } } /// @dev Returns `ln(x)`, denominated in `WAD`. /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln /// Note: This function is an approximation. Monotonically increasing. function lnWad(int256 x) internal pure returns (int256 r) { /// @solidity memory-safe-assembly assembly { // We want to convert `x` from `10**18` fixed point to `2**96` fixed point. // We do this by multiplying by `2**96 / 10**18`. But since // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here // and add `ln(2**96 / 10**18)` at the end. // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`. r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // We place the check here for more optimal stack operations. if iszero(sgt(x, 0)) { mstore(0x00, 0x1615e638) // `LnWadUndefined()`. revert(0x1c, 0x04) } // forgefmt: disable-next-item r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)), 0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff)) // Reduce range of x to (1, 2) * 2**96 // ln(2^k * x) = k * ln(2) + ln(x) x := shr(159, shl(r, x)) // Evaluate using a (8, 8)-term rational approximation. // `p` is made monic, we will multiply by a scale factor later. // forgefmt: disable-next-item let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir. sar(96, mul(add(43456485725739037958740375743393, sar(96, mul(add(24828157081833163892658089445524, sar(96, mul(add(3273285459638523848632254066296, x), x))), x))), x)), 11111509109440967052023855526967) p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857) p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526) p := sub(mul(p, x), shl(96, 795164235651350426258249787498)) // We leave `p` in `2**192` basis so we don't need to scale it back up for the division. // `q` is monic by convention. let q := add(5573035233440673466300451813936, x) q := add(71694874799317883764090561454958, sar(96, mul(x, q))) q := add(283447036172924575727196451306956, sar(96, mul(x, q))) q := add(401686690394027663651624208769553, sar(96, mul(x, q))) q := add(204048457590392012362485061816622, sar(96, mul(x, q))) q := add(31853899698501571402653359427138, sar(96, mul(x, q))) q := add(909429971244387300277376558375, sar(96, mul(x, q))) // `p / q` is in the range `(0, 0.125) * 2**96`. // Finalization, we need to: // - Multiply by the scale factor `s = 5.549…`. // - Add `ln(2**96 / 10**18)`. // - Add `k * ln(2)`. // - Multiply by `10**18 / 2**96 = 5**18 >> 78`. // The q polynomial is known not to have zeros in the domain. // No scaling required because p is already `2**96` too large. p := sdiv(p, q) // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`. p := mul(1677202110996718588342820967067443963516166, p) // Add `ln(2) * k * 5**18 * 2**192`. // forgefmt: disable-next-item p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p) // Add `ln(2**96 / 10**18) * 5**18 * 2**192`. p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p) // Base conversion: mul `2**18 / 2**192`. r := sar(174, p) } } /// @dev Returns `W_0(x)`, denominated in `WAD`. /// See: https://en.wikipedia.org/wiki/Lambert_W_function /// a.k.a. Product log function. This is an approximation of the principal branch. /// Note: This function is an approximation. Monotonically increasing. function lambertW0Wad(int256 x) internal pure returns (int256 w) { // forgefmt: disable-next-item unchecked { if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`. (int256 wad, int256 p) = (int256(WAD), x); uint256 c; // Whether we need to avoid catastrophic cancellation. uint256 i = 4; // Number of iterations. if (w <= 0x1ffffffffffff) { if (-0x4000000000000 <= w) { i = 1; // Inputs near zero only take one step to converge. } else if (w <= -0x3ffffffffffffff) { i = 32; // Inputs near `-1/e` take very long to converge. } } else if (uint256(w >> 63) == uint256(0)) { /// @solidity memory-safe-assembly assembly { // Inline log2 for more performance, since the range is small. let v := shr(49, w) let l := shl(3, lt(0xff, v)) l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)), 0x0706060506020504060203020504030106050205030304010505030400000000)), 49) w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13)) c := gt(l, 60) i := add(2, add(gt(l, 53), c)) } } else { int256 ll = lnWad(w = lnWad(w)); /// @solidity memory-safe-assembly assembly { // `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`. w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll)) i := add(3, iszero(shr(68, x))) c := iszero(shr(143, x)) } if (c == uint256(0)) { do { // If `x` is big, use Newton's so that intermediate values won't overflow. int256 e = expWad(w); /// @solidity memory-safe-assembly assembly { let t := mul(w, div(e, wad)) w := sub(w, sdiv(sub(t, x), div(add(e, t), wad))) } if (p <= w) break; p = w; } while (--i != uint256(0)); /// @solidity memory-safe-assembly assembly { w := sub(w, sgt(w, 2)) } return w; } } do { // Otherwise, use Halley's for faster convergence. int256 e = expWad(w); /// @solidity memory-safe-assembly assembly { let t := add(w, wad) let s := sub(mul(w, e), mul(x, wad)) w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t))))) } if (p <= w) break; p = w; } while (--i != c); /// @solidity memory-safe-assembly assembly { w := sub(w, sgt(w, 2)) } // For certain ranges of `x`, we'll use the quadratic-rate recursive formula of // R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation. if (c == uint256(0)) return w; int256 t = w | 1; /// @solidity memory-safe-assembly assembly { x := sdiv(mul(x, wad), t) } x = (t * (wad + lnWad(x))); /// @solidity memory-safe-assembly assembly { w := sdiv(x, add(wad, t)) } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* GENERAL NUMBER UTILITIES */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns `a * b == x * y`, with full precision. function fullMulEq(uint256 a, uint256 b, uint256 x, uint256 y) internal pure returns (bool result) { /// @solidity memory-safe-assembly assembly { result := and(eq(mul(a, b), mul(x, y)), eq(mulmod(x, y, not(0)), mulmod(a, b, not(0)))) } } /// @dev Calculates `floor(x * y / d)` with full precision. /// Throws if result overflows a uint256 or when `d` is zero. /// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // 512-bit multiply `[p1 p0] = x * y`. // Compute the product mod `2**256` and mod `2**256 - 1` // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that `product = p1 * 2**256 + p0`. // Temporarily use `z` as `p0` to save gas. z := mul(x, y) // Lower 256 bits of `x * y`. for {} 1 {} { // If overflows. if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) { let mm := mulmod(x, y, not(0)) let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`. /*------------------- 512 by 256 division --------------------*/ // Make division exact by subtracting the remainder from `[p1 p0]`. let r := mulmod(x, y, d) // Compute remainder using mulmod. let t := and(d, sub(0, d)) // The least significant bit of `d`. `t >= 1`. // Make sure `z` is less than `2**256`. Also prevents `d == 0`. // Placing the check here seems to give more optimal stack operations. if iszero(gt(d, p1)) { mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } d := div(d, t) // Divide `d` by `t`, which is a power of two. // Invert `d mod 2**256` // Now that `d` is an odd number, it has an inverse // modulo `2**256` such that `d * inv = 1 mod 2**256`. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, `d * inv = 1 mod 2**4`. let inv := xor(2, mul(3, d)) // Now use 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. inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128 z := mul( // Divide [p1 p0] by the factors of two. // Shift in bits from `p1` into `p0`. For this we need // to flip `t` such that it is `2**256 / t`. or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)), mul(sub(2, mul(d, inv)), inv) // inverse mod 2**256 ) break } z := div(z, d) break } } } /// @dev Calculates `floor(x * y / d)` with full precision. /// Behavior is undefined if `d` is zero or the final result cannot fit in 256 bits. /// Performs the full 512 bit calculation regardless. function fullMulDivUnchecked(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) let mm := mulmod(x, y, not(0)) let p1 := sub(mm, add(z, lt(mm, z))) let t := and(d, sub(0, d)) let r := mulmod(x, y, d) d := div(d, t) let inv := xor(2, mul(3, d)) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) inv := mul(inv, sub(2, mul(d, inv))) z := mul( or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)), mul(sub(2, mul(d, inv)), inv) ) } } /// @dev Calculates `floor(x * y / d)` with full precision, rounded up. /// Throws if result overflows a uint256 or when `d` is zero. /// Credit to Uniswap-v3-core under MIT license: /// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { z = fullMulDiv(x, y, d); /// @solidity memory-safe-assembly assembly { if mulmod(x, y, d) { z := add(z, 1) if iszero(z) { mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } } } } /// @dev Calculates `floor(x * y / 2 ** n)` with full precision. /// Throws if result overflows a uint256. /// Credit to Philogy under MIT license: /// https://github.com/SorellaLabs/angstrom/blob/main/contracts/src/libraries/X128MathLib.sol function fullMulDivN(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Temporarily use `z` as `p0` to save gas. z := mul(x, y) // Lower 256 bits of `x * y`. We'll call this `z`. for {} 1 {} { if iszero(or(iszero(x), eq(div(z, x), y))) { let k := and(n, 0xff) // `n`, cleaned. let mm := mulmod(x, y, not(0)) let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`. // | p1 | z | // Before: | p1_0 ¦ p1_1 | z_0 ¦ z_1 | // Final: | 0 ¦ p1_0 | p1_1 ¦ z_0 | // Check that final `z` doesn't overflow by checking that p1_0 = 0. if iszero(shr(k, p1)) { z := add(shl(sub(256, k), p1), shr(k, z)) break } mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } z := shr(and(n, 0xff), z) break } } } /// @dev Returns `floor(x * y / d)`. /// Reverts if `x * y` overflows, or `d` is zero. function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`. if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) { mstore(0x00, 0xad251c27) // `MulDivFailed()`. revert(0x1c, 0x04) } z := div(z, d) } } /// @dev Returns `ceil(x * y / d)`. /// Reverts if `x * y` overflows, or `d` is zero. function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`. if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) { mstore(0x00, 0xad251c27) // `MulDivFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(z, d))), div(z, d)) } } /// @dev Returns `x`, the modular multiplicative inverse of `a`, such that `(a * x) % n == 1`. function invMod(uint256 a, uint256 n) internal pure returns (uint256 x) { /// @solidity memory-safe-assembly assembly { let g := n let r := mod(a, n) for { let y := 1 } 1 {} { let q := div(g, r) let t := g g := r r := sub(t, mul(r, q)) let u := x x := y y := sub(u, mul(y, q)) if iszero(r) { break } } x := mul(eq(g, 1), add(x, mul(slt(x, 0), n))) } } /// @dev Returns `ceil(x / d)`. /// Reverts if `d` is zero. function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { if iszero(d) { mstore(0x00, 0x65244e4e) // `DivFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(x, d))), div(x, d)) } } /// @dev Returns `max(0, x - y)`. function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(gt(x, y), sub(x, y)) } } /// @dev Returns `condition ? x : y`, without branching. function ternary(bool condition, uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), iszero(condition))) } } /// @dev Returns `condition ? x : y`, without branching. function ternary(bool condition, bytes32 x, bytes32 y) internal pure returns (bytes32 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), iszero(condition))) } } /// @dev Returns `condition ? x : y`, without branching. function ternary(bool condition, address x, address y) internal pure returns (address z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), iszero(condition))) } } /// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`. /// Reverts if the computation overflows. function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`. if x { z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x` let half := shr(1, b) // Divide `b` by 2. // Divide `y` by 2 every iteration. for { y := shr(1, y) } y { y := shr(1, y) } { let xx := mul(x, x) // Store x squared. let xxRound := add(xx, half) // Round to the nearest number. // Revert if `xx + half` overflowed, or if `x ** 2` overflows. if or(lt(xxRound, xx), shr(128, x)) { mstore(0x00, 0x49f7642b) // `RPowOverflow()`. revert(0x1c, 0x04) } x := div(xxRound, b) // Set `x` to scaled `xxRound`. // If `y` is odd: if and(y, 1) { let zx := mul(z, x) // Compute `z * x`. let zxRound := add(zx, half) // Round to the nearest number. // If `z * x` overflowed or `zx + half` overflowed: if or(xor(div(zx, x), z), lt(zxRound, zx)) { // Revert if `x` is non-zero. if x { mstore(0x00, 0x49f7642b) // `RPowOverflow()`. revert(0x1c, 0x04) } } z := div(zxRound, b) // Return properly scaled `zxRound`. } } } } } /// @dev Returns the square root of `x`, rounded down. function sqrt(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`. z := 181 // The "correct" value is 1, but this saves a multiplication later. // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically. // Let `y = x / 2**r`. We check `y >= 2**(k + 8)` // but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`. let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffffff, shr(r, x)))) z := shl(shr(1, r), z) // Goal was to get `z*z*y` within a small factor of `x`. More iterations could // get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`. // We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small. // That's not possible if `x < 256` but we can just verify those cases exhaustively. // Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`. // Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`. // Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps. // For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)` // is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`, // with largest error when `s = 1` and when `s = 256` or `1/256`. // Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`. // Then we can estimate `sqrt(y)` using // `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`. // There is no overflow risk here since `y < 2**136` after the first branch above. z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181. // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough. z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) // If `x+1` is a perfect square, the Babylonian method cycles between // `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor. // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division z := sub(z, lt(div(x, z), z)) } } /// @dev Returns the cube root of `x`, rounded down. /// Credit to bout3fiddy and pcaversaccio under AGPLv3 license: /// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy /// Formally verified by xuwinnie: /// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf function cbrt(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // Makeshift lookup table to nudge the approximate log2 result. z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3))) // Newton-Raphson's. z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) // Round down. z := sub(z, lt(div(x, mul(z, z)), z)) } } /// @dev Returns the square root of `x`, denominated in `WAD`, rounded down. function sqrtWad(uint256 x) internal pure returns (uint256 z) { unchecked { if (x <= type(uint256).max / 10 ** 18) return sqrt(x * 10 ** 18); z = (1 + sqrt(x)) * 10 ** 9; z = (fullMulDivUnchecked(x, 10 ** 18, z) + z) >> 1; } /// @solidity memory-safe-assembly assembly { z := sub(z, gt(999999999999999999, sub(mulmod(z, z, x), 1))) // Round down. } } /// @dev Returns the cube root of `x`, denominated in `WAD`, rounded down. /// Formally verified by xuwinnie: /// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf function cbrtWad(uint256 x) internal pure returns (uint256 z) { unchecked { if (x <= type(uint256).max / 10 ** 36) return cbrt(x * 10 ** 36); z = (1 + cbrt(x)) * 10 ** 12; z = (fullMulDivUnchecked(x, 10 ** 36, z * z) + z + z) / 3; } /// @solidity memory-safe-assembly assembly { let p := x for {} 1 {} { if iszero(shr(229, p)) { if iszero(shr(199, p)) { p := mul(p, 100000000000000000) // 10 ** 17. break } p := mul(p, 100000000) // 10 ** 8. break } if iszero(shr(249, p)) { p := mul(p, 100) } break } let t := mulmod(mul(z, z), z, p) z := sub(z, gt(lt(t, shr(1, p)), iszero(t))) // Round down. } } /// @dev Returns the factorial of `x`. function factorial(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := 1 if iszero(lt(x, 58)) { mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`. revert(0x1c, 0x04) } for {} x { x := sub(x, 1) } { z := mul(z, x) } } } /// @dev Returns the log2 of `x`. /// Equivalent to computing the index of the most significant bit (MSB) of `x`. /// Returns 0 if `x` is zero. function log2(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // forgefmt: disable-next-item r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)), 0x0706060506020504060203020504030106050205030304010505030400000000)) } } /// @dev Returns the log2 of `x`, rounded up. /// Returns 0 if `x` is zero. function log2Up(uint256 x) internal pure returns (uint256 r) { r = log2(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(shl(r, 1), x)) } } /// @dev Returns the log10 of `x`. /// Returns 0 if `x` is zero. function log10(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { if iszero(lt(x, 100000000000000000000000000000000000000)) { x := div(x, 100000000000000000000000000000000000000) r := 38 } if iszero(lt(x, 100000000000000000000)) { x := div(x, 100000000000000000000) r := add(r, 20) } if iszero(lt(x, 10000000000)) { x := div(x, 10000000000) r := add(r, 10) } if iszero(lt(x, 100000)) { x := div(x, 100000) r := add(r, 5) } r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999))))) } } /// @dev Returns the log10 of `x`, rounded up. /// Returns 0 if `x` is zero. function log10Up(uint256 x) internal pure returns (uint256 r) { r = log10(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(exp(10, r), x)) } } /// @dev Returns the log256 of `x`. /// Returns 0 if `x` is zero. function log256(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(shr(3, r), lt(0xff, shr(r, x))) } } /// @dev Returns the log256 of `x`, rounded up. /// Returns 0 if `x` is zero. function log256Up(uint256 x) internal pure returns (uint256 r) { r = log256(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(shl(shl(3, r), 1), x)) } } /// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`. /// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent). function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) { /// @solidity memory-safe-assembly assembly { mantissa := x if mantissa { if iszero(mod(mantissa, 1000000000000000000000000000000000)) { mantissa := div(mantissa, 1000000000000000000000000000000000) exponent := 33 } if iszero(mod(mantissa, 10000000000000000000)) { mantissa := div(mantissa, 10000000000000000000) exponent := add(exponent, 19) } if iszero(mod(mantissa, 1000000000000)) { mantissa := div(mantissa, 1000000000000) exponent := add(exponent, 12) } if iszero(mod(mantissa, 1000000)) { mantissa := div(mantissa, 1000000) exponent := add(exponent, 6) } if iszero(mod(mantissa, 10000)) { mantissa := div(mantissa, 10000) exponent := add(exponent, 4) } if iszero(mod(mantissa, 100)) { mantissa := div(mantissa, 100) exponent := add(exponent, 2) } if iszero(mod(mantissa, 10)) { mantissa := div(mantissa, 10) exponent := add(exponent, 1) } } } } /// @dev Convenience function for packing `x` into a smaller number using `sci`. /// The `mantissa` will be in bits [7..255] (the upper 249 bits). /// The `exponent` will be in bits [0..6] (the lower 7 bits). /// Use `SafeCastLib` to safely ensure that the `packed` number is small /// enough to fit in the desired unsigned integer type: /// ``` /// uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether)); /// ``` function packSci(uint256 x) internal pure returns (uint256 packed) { (x, packed) = sci(x); // Reuse for `mantissa` and `exponent`. /// @solidity memory-safe-assembly assembly { if shr(249, x) { mstore(0x00, 0xce30380c) // `MantissaOverflow()`. revert(0x1c, 0x04) } packed := or(shl(7, x), packed) } } /// @dev Convenience function for unpacking a packed number from `packSci`. function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) { unchecked { unpacked = (packed >> 7) * 10 ** (packed & 0x7f); } } /// @dev Returns the average of `x` and `y`. Rounds towards zero. function avg(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = (x & y) + ((x ^ y) >> 1); } } /// @dev Returns the average of `x` and `y`. Rounds towards negative infinity. function avg(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = (x >> 1) + (y >> 1) + (x & y & 1); } } /// @dev Returns the absolute value of `x`. function abs(int256 x) internal pure returns (uint256 z) { unchecked { z = (uint256(x) + uint256(x >> 255)) ^ uint256(x >> 255); } } /// @dev Returns the absolute distance between `x` and `y`. function dist(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(xor(sub(0, gt(x, y)), sub(y, x)), gt(x, y)) } } /// @dev Returns the absolute distance between `x` and `y`. function dist(int256 x, int256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(xor(sub(0, sgt(x, y)), sub(y, x)), sgt(x, y)) } } /// @dev Returns the minimum of `x` and `y`. function min(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), lt(y, x))) } } /// @dev Returns the minimum of `x` and `y`. function min(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), slt(y, x))) } } /// @dev Returns the maximum of `x` and `y`. function max(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), gt(y, x))) } } /// @dev Returns the maximum of `x` and `y`. function max(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), sgt(y, x))) } } /// @dev Returns `x`, bounded to `minValue` and `maxValue`. function clamp(uint256 x, uint256 minValue, uint256 maxValue) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, minValue), gt(minValue, x))) z := xor(z, mul(xor(z, maxValue), lt(maxValue, z))) } } /// @dev Returns `x`, bounded to `minValue` and `maxValue`. function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, minValue), sgt(minValue, x))) z := xor(z, mul(xor(z, maxValue), slt(maxValue, z))) } } /// @dev Returns greatest common divisor of `x` and `y`. function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { for { z := x } y {} { let t := y y := mod(z, y) z := t } } } /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`, /// with `t` clamped between `begin` and `end` (inclusive). /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`). /// If `begins == end`, returns `t <= begin ? a : b`. function lerp(uint256 a, uint256 b, uint256 t, uint256 begin, uint256 end) internal pure returns (uint256) { if (begin > end) (t, begin, end) = (~t, ~begin, ~end); if (t <= begin) return a; if (t >= end) return b; unchecked { if (b >= a) return a + fullMulDiv(b - a, t - begin, end - begin); return a - fullMulDiv(a - b, t - begin, end - begin); } } /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`. /// with `t` clamped between `begin` and `end` (inclusive). /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`). /// If `begins == end`, returns `t <= begin ? a : b`. function lerp(int256 a, int256 b, int256 t, int256 begin, int256 end) internal pure returns (int256) { if (begin > end) (t, begin, end) = (~t, ~begin, ~end); if (t <= begin) return a; if (t >= end) return b; // forgefmt: disable-next-item unchecked { if (b >= a) return int256(uint256(a) + fullMulDiv(uint256(b - a), uint256(t - begin), uint256(end - begin))); return int256(uint256(a) - fullMulDiv(uint256(a - b), uint256(t - begin), uint256(end - begin))); } } /// @dev Returns if `x` is an even number. Some people may need this. function isEven(uint256 x) internal pure returns (bool) { return x & uint256(1) == uint256(0); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* RAW NUMBER OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns `x + y`, without checking for overflow. function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x + y; } } /// @dev Returns `x + y`, without checking for overflow. function rawAdd(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x + y; } } /// @dev Returns `x - y`, without checking for underflow. function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x - y; } } /// @dev Returns `x - y`, without checking for underflow. function rawSub(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x - y; } } /// @dev Returns `x * y`, without checking for overflow. function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x * y; } } /// @dev Returns `x * y`, without checking for overflow. function rawMul(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x * y; } } /// @dev Returns `x / y`, returning 0 if `y` is zero. function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(x, y) } } /// @dev Returns `x / y`, returning 0 if `y` is zero. function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(x, y) } } /// @dev Returns `x % y`, returning 0 if `y` is zero. function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mod(x, y) } } /// @dev Returns `x % y`, returning 0 if `y` is zero. function rawSMod(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := smod(x, y) } } /// @dev Returns `(x + y) % d`, return 0 if `d` if zero. function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := addmod(x, y, d) } } /// @dev Returns `(x * y) % d`, return 0 if `d` if zero. function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mulmod(x, y, d) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Gas optimized ECDSA wrapper. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ECDSA.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ECDSA.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol) /// /// @dev Note: /// - The recovery functions use the ecrecover precompile (0x1). /// - As of Solady version 0.0.68, the `recover` variants will revert upon recovery failure. /// This is for more safety by default. /// Use the `tryRecover` variants if you need to get the zero address back /// upon recovery failure instead. /// - As of Solady version 0.0.134, all `bytes signature` variants accept both /// regular 65-byte `(r, s, v)` and EIP-2098 `(r, vs)` short form signatures. /// See: https://eips.ethereum.org/EIPS/eip-2098 /// This is for calldata efficiency on smart accounts prevalent on L2s. /// /// WARNING! Do NOT directly use signatures as unique identifiers: /// - The recovery operations do NOT check if a signature is non-malleable. /// - Use a nonce in the digest to prevent replay attacks on the same contract. /// - Use EIP-712 for the digest to prevent replay attacks across different chains and contracts. /// EIP-712 also enables readable signing of typed data for better user safety. /// - If you need a unique hash from a signature, please use the `canonicalHash` functions. library ECDSA { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The order of the secp256k1 elliptic curve. uint256 internal constant N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141; /// @dev `N/2 + 1`. Used for checking the malleability of the signature. uint256 private constant _HALF_N_PLUS_1 = 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a1; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The signature is invalid. error InvalidSignature(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* RECOVERY OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function recover(bytes32 hash, bytes memory signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { for { let m := mload(0x40) } 1 { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } { switch mload(signature) case 64 { let vs := mload(add(signature, 0x40)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`. mstore(0x60, mload(add(signature, 0x40))) // `s`. } default { continue } mstore(0x00, hash) mstore(0x40, mload(add(signature, 0x20))) // `r`. result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if returndatasize() { break } } } } /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function recoverCalldata(bytes32 hash, bytes calldata signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { for { let m := mload(0x40) } 1 { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } { switch signature.length case 64 { let vs := calldataload(add(signature.offset, 0x20)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, calldataload(signature.offset)) // `r`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`. calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`. } default { continue } mstore(0x00, hash) result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if returndatasize() { break } } } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the EIP-2098 short form signature defined by `r` and `vs`. function recover(bytes32 hash, bytes32 r, bytes32 vs) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, r) mstore(0x60, shr(1, shl(1, vs))) // `s`. result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if iszero(returndatasize()) { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the signature defined by `v`, `r`, `s`. function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, and(v, 0xff)) mstore(0x40, r) mstore(0x60, s) result := mload(staticcall(gas(), 1, 0x00, 0x80, 0x01, 0x20)) // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. if iszero(returndatasize()) { mstore(0x00, 0x8baa579f) // `InvalidSignature()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot. mstore(0x40, m) // Restore the free memory pointer. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* TRY-RECOVER OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // WARNING! // These functions will NOT revert upon recovery failure. // Instead, they will return the zero address upon recovery failure. // It is critical that the returned address is NEVER compared against // a zero address (e.g. an uninitialized address variable). /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function tryRecover(bytes32 hash, bytes memory signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { for { let m := mload(0x40) } 1 {} { switch mload(signature) case 64 { let vs := mload(add(signature, 0x40)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, mload(add(signature, 0x60)))) // `v`. mstore(0x60, mload(add(signature, 0x40))) // `s`. } default { break } mstore(0x00, hash) mstore(0x40, mload(add(signature, 0x20))) // `r`. pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20)) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. break } } } /// @dev Recovers the signer's address from a message digest `hash`, and the `signature`. function tryRecoverCalldata(bytes32 hash, bytes calldata signature) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { for { let m := mload(0x40) } 1 {} { switch signature.length case 64 { let vs := calldataload(add(signature.offset, 0x20)) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, calldataload(signature.offset)) // `r`. mstore(0x60, shr(1, shl(1, vs))) // `s`. } case 65 { mstore(0x20, byte(0, calldataload(add(signature.offset, 0x40)))) // `v`. calldatacopy(0x40, signature.offset, 0x40) // Copy `r` and `s`. } default { break } mstore(0x00, hash) pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20)) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. break } } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the EIP-2098 short form signature defined by `r` and `vs`. function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, add(shr(255, vs), 27)) // `v`. mstore(0x40, r) mstore(0x60, shr(1, shl(1, vs))) // `s`. pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20)) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Recovers the signer's address from a message digest `hash`, /// and the signature defined by `v`, `r`, `s`. function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal view returns (address result) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x00, hash) mstore(0x20, and(v, 0xff)) mstore(0x40, r) mstore(0x60, s) pop(staticcall(gas(), 1, 0x00, 0x80, 0x40, 0x20)) mstore(0x60, 0) // Restore the zero slot. // `returndatasize()` will be `0x20` upon success, and `0x00` otherwise. result := mload(xor(0x60, returndatasize())) mstore(0x40, m) // Restore the free memory pointer. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HASHING OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns an Ethereum Signed Message, created from a `hash`. /// This produces a hash corresponding to the one signed with the /// [`eth_sign`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign) /// JSON-RPC method as part of EIP-191. function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { mstore(0x20, hash) // Store into scratch space for keccak256. mstore(0x00, "\x00\x00\x00\x00\x19Ethereum Signed Message:\n32") // 28 bytes. result := keccak256(0x04, 0x3c) // `32 * 2 - (32 - 28) = 60 = 0x3c`. } } /// @dev Returns an Ethereum Signed Message, created from `s`. /// This produces a hash corresponding to the one signed with the /// [`eth_sign`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sign) /// JSON-RPC method as part of EIP-191. /// Note: Supports lengths of `s` up to 999999 bytes. function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32 result) { /// @solidity memory-safe-assembly assembly { let sLength := mload(s) let o := 0x20 mstore(o, "\x19Ethereum Signed Message:\n") // 26 bytes, zero-right-padded. mstore(0x00, 0x00) // Convert the `s.length` to ASCII decimal representation: `base10(s.length)`. for { let temp := sLength } 1 {} { o := sub(o, 1) mstore8(o, add(48, mod(temp, 10))) temp := div(temp, 10) if iszero(temp) { break } } let n := sub(0x3a, o) // Header length: `26 + 32 - o`. // Throw an out-of-offset error (consumes all gas) if the header exceeds 32 bytes. returndatacopy(returndatasize(), returndatasize(), gt(n, 0x20)) mstore(s, or(mload(0x00), mload(n))) // Temporarily store the header. result := keccak256(add(s, sub(0x20, n)), add(n, sLength)) mstore(s, sLength) // Restore the length. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CANONICAL HASH FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // The following functions returns the hash of the signature in it's canonicalized format, // which is the 65-byte `abi.encodePacked(r, s, uint8(v))`, where `v` is either 27 or 28. // If `s` is greater than `N / 2` then it will be converted to `N - s` // and the `v` value will be flipped. // If the signature has an invalid length, or if `v` is invalid, // a uniquely corrupt hash will be returned. // These functions are useful for "poor-mans-VRF". /// @dev Returns the canonical hash of `signature`. function canonicalHash(bytes memory signature) internal pure returns (bytes32 result) { // @solidity memory-safe-assembly assembly { let l := mload(signature) for {} 1 {} { mstore(0x00, mload(add(signature, 0x20))) // `r`. let s := mload(add(signature, 0x40)) let v := mload(add(signature, 0x41)) if eq(l, 64) { v := add(shr(255, s), 27) s := shr(1, shl(1, s)) } if iszero(lt(s, _HALF_N_PLUS_1)) { v := xor(v, 7) s := sub(N, s) } mstore(0x21, v) mstore(0x20, s) result := keccak256(0x00, 0x41) mstore(0x21, 0) // Restore the overwritten part of the free memory pointer. break } // If the length is neither 64 nor 65, return a uniquely corrupted hash. if iszero(lt(sub(l, 64), 2)) { // `bytes4(keccak256("InvalidSignatureLength"))`. result := xor(keccak256(add(signature, 0x20), l), 0xd62f1ab2) } } } /// @dev Returns the canonical hash of `signature`. function canonicalHashCalldata(bytes calldata signature) internal pure returns (bytes32 result) { // @solidity memory-safe-assembly assembly { for {} 1 {} { mstore(0x00, calldataload(signature.offset)) // `r`. let s := calldataload(add(signature.offset, 0x20)) let v := calldataload(add(signature.offset, 0x21)) if eq(signature.length, 64) { v := add(shr(255, s), 27) s := shr(1, shl(1, s)) } if iszero(lt(s, _HALF_N_PLUS_1)) { v := xor(v, 7) s := sub(N, s) } mstore(0x21, v) mstore(0x20, s) result := keccak256(0x00, 0x41) mstore(0x21, 0) // Restore the overwritten part of the free memory pointer. break } // If the length is neither 64 nor 65, return a uniquely corrupted hash. if iszero(lt(sub(signature.length, 64), 2)) { calldatacopy(mload(0x40), signature.offset, signature.length) // `bytes4(keccak256("InvalidSignatureLength"))`. result := xor(keccak256(mload(0x40), signature.length), 0xd62f1ab2) } } } /// @dev Returns the canonical hash of `signature`. function canonicalHash(bytes32 r, bytes32 vs) internal pure returns (bytes32 result) { // @solidity memory-safe-assembly assembly { mstore(0x00, r) // `r`. let v := add(shr(255, vs), 27) let s := shr(1, shl(1, vs)) mstore(0x21, v) mstore(0x20, s) result := keccak256(0x00, 0x41) mstore(0x21, 0) // Restore the overwritten part of the free memory pointer. } } /// @dev Returns the canonical hash of `signature`. function canonicalHash(uint8 v, bytes32 r, bytes32 s) internal pure returns (bytes32 result) { // @solidity memory-safe-assembly assembly { mstore(0x00, r) // `r`. if iszero(lt(s, _HALF_N_PLUS_1)) { v := xor(v, 7) s := sub(N, s) } mstore(0x21, v) mstore(0x20, s) result := keccak256(0x00, 0x41) mstore(0x21, 0) // Restore the overwritten part of the free memory pointer. } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EMPTY CALLDATA HELPERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns an empty calldata bytes. function emptySignature() internal pure returns (bytes calldata signature) { /// @solidity memory-safe-assembly assembly { signature.length := 0 } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Simple single owner authorization mixin. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol) /// /// @dev Note: /// This implementation does NOT auto-initialize the owner to `msg.sender`. /// You MUST call the `_initializeOwner` in the constructor / initializer. /// /// While the ownable portion follows /// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility, /// the nomenclature for the 2-step ownership handover may be unique to this codebase. abstract contract Ownable { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The caller is not authorized to call the function. error Unauthorized(); /// @dev The `newOwner` cannot be the zero address. error NewOwnerIsZeroAddress(); /// @dev The `pendingOwner` does not have a valid handover request. error NoHandoverRequest(); /// @dev Cannot double-initialize. error AlreadyInitialized(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The ownership is transferred from `oldOwner` to `newOwner`. /// This event is intentionally kept the same as OpenZeppelin's Ownable to be /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173), /// despite it not being as lightweight as a single argument event. event OwnershipTransferred(address indexed oldOwner, address indexed newOwner); /// @dev An ownership handover to `pendingOwner` has been requested. event OwnershipHandoverRequested(address indexed pendingOwner); /// @dev The ownership handover to `pendingOwner` has been canceled. event OwnershipHandoverCanceled(address indexed pendingOwner); /// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`. uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE = 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0; /// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`. uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE = 0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d; /// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`. uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE = 0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The owner slot is given by: /// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`. /// It is intentionally chosen to be a high value /// to avoid collision with lower slots. /// The choice of manual storage layout is to enable compatibility /// with both regular and upgradeable contracts. bytes32 internal constant _OWNER_SLOT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927; /// The ownership handover slot of `newOwner` is given by: /// ``` /// mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED)) /// let handoverSlot := keccak256(0x00, 0x20) /// ``` /// It stores the expiry timestamp of the two-step ownership handover. uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Override to return true to make `_initializeOwner` prevent double-initialization. function _guardInitializeOwner() internal pure virtual returns (bool guard) {} /// @dev Initializes the owner directly without authorization guard. /// This function must be called upon initialization, /// regardless of whether the contract is upgradeable or not. /// This is to enable generalization to both regular and upgradeable contracts, /// and to save gas in case the initial owner is not the caller. /// For performance reasons, this function will not check if there /// is an existing owner. function _initializeOwner(address newOwner) internal virtual { if (_guardInitializeOwner()) { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT if sload(ownerSlot) { mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`. revert(0x1c, 0x04) } // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Store the new value. sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner)))) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner) } } else { /// @solidity memory-safe-assembly assembly { // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Store the new value. sstore(_OWNER_SLOT, newOwner) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner) } } } /// @dev Sets the owner directly without authorization guard. function _setOwner(address newOwner) internal virtual { if (_guardInitializeOwner()) { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner) // Store the new value. sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner)))) } } else { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner) // Store the new value. sstore(ownerSlot, newOwner) } } } /// @dev Throws if the sender is not the owner. function _checkOwner() internal view virtual { /// @solidity memory-safe-assembly assembly { // If the caller is not the stored owner, revert. if iszero(eq(caller(), sload(_OWNER_SLOT))) { mstore(0x00, 0x82b42900) // `Unauthorized()`. revert(0x1c, 0x04) } } } /// @dev Returns how long a two-step ownership handover is valid for in seconds. /// Override to return a different value if needed. /// Made internal to conserve bytecode. Wrap it in a public function if needed. function _ownershipHandoverValidFor() internal view virtual returns (uint64) { return 48 * 3600; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC UPDATE FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Allows the owner to transfer the ownership to `newOwner`. function transferOwnership(address newOwner) public payable virtual onlyOwner { /// @solidity memory-safe-assembly assembly { if iszero(shl(96, newOwner)) { mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`. revert(0x1c, 0x04) } } _setOwner(newOwner); } /// @dev Allows the owner to renounce their ownership. function renounceOwnership() public payable virtual onlyOwner { _setOwner(address(0)); } /// @dev Request a two-step ownership handover to the caller. /// The request will automatically expire in 48 hours (172800 seconds) by default. function requestOwnershipHandover() public payable virtual { unchecked { uint256 expires = block.timestamp + _ownershipHandoverValidFor(); /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to `expires`. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x20), expires) // Emit the {OwnershipHandoverRequested} event. log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller()) } } } /// @dev Cancels the two-step ownership handover to the caller, if any. function cancelOwnershipHandover() public payable virtual { /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to 0. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x20), 0) // Emit the {OwnershipHandoverCanceled} event. log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller()) } } /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`. /// Reverts if there is no existing ownership handover requested by `pendingOwner`. function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner { /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to 0. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, pendingOwner) let handoverSlot := keccak256(0x0c, 0x20) // If the handover does not exist, or has expired. if gt(timestamp(), sload(handoverSlot)) { mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`. revert(0x1c, 0x04) } // Set the handover slot to 0. sstore(handoverSlot, 0) } _setOwner(pendingOwner); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC READ FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the owner of the contract. function owner() public view virtual returns (address result) { /// @solidity memory-safe-assembly assembly { result := sload(_OWNER_SLOT) } } /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`. function ownershipHandoverExpiresAt(address pendingOwner) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { // Compute the handover slot. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, pendingOwner) // Load the handover slot. result := sload(keccak256(0x0c, 0x20)) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MODIFIERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Marks a function as only callable by the owner. modifier onlyOwner() virtual { _checkOwner(); _; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Enumerable multiroles authorization mixin. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/EnumerableRoles.sol) /// /// @dev Note: /// This implementation is agnostic to the Ownable that the contract inherits from. /// It performs a self-staticcall to the `owner()` function to determine the owner. /// This is useful for situations where the contract inherits from /// OpenZeppelin's Ownable, such as in LayerZero's OApp contracts. /// /// This implementation performs a self-staticcall to `MAX_ROLE()` to determine /// the maximum role that can be set/unset. If the inheriting contract does not /// have `MAX_ROLE()`, then any role can be set/unset. /// /// This implementation allows for any uint256 role, /// it does NOT take in a bitmask of roles. /// This is to accommodate teams that are allergic to bitwise flags. /// /// By default, the `owner()` is the only account that is authorized to set roles. /// This behavior can be changed via overrides. /// /// This implementation is compatible with any Ownable. /// This implementation is NOT compatible with OwnableRoles. abstract contract EnumerableRoles { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The status of `role` for `holder` has been set to `active`. event RoleSet(address indexed holder, uint256 indexed role, bool indexed active); /// @dev `keccak256(bytes("RoleSet(address,uint256,bool)"))`. uint256 private constant _ROLE_SET_EVENT_SIGNATURE = 0xaddc47d7e02c95c00ec667676636d772a589ffbf0663cfd7cd4dd3d4758201b8; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The index is out of bounds of the role holders array. error RoleHoldersIndexOutOfBounds(); /// @dev Cannot set the role of the zero address. error RoleHolderIsZeroAddress(); /// @dev The role has exceeded the maximum role. error InvalidRole(); /// @dev Unauthorized to perform the action. error EnumerableRolesUnauthorized(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The storage layout of the holders enumerable mapping is given by: /// ``` /// mstore(0x18, holder) /// mstore(0x04, _ENUMERABLE_ROLES_SLOT_SEED) /// mstore(0x00, role) /// let rootSlot := keccak256(0x00, 0x24) /// let positionSlot := keccak256(0x00, 0x38) /// let holderSlot := add(rootSlot, sload(positionSlot)) /// let holderInStorage := shr(96, sload(holderSlot)) /// let length := shr(160, shl(160, sload(rootSlot))) /// ``` uint256 private constant _ENUMERABLE_ROLES_SLOT_SEED = 0xee9853bb; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC UPDATE FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Sets the status of `role` of `holder` to `active`. function setRole(address holder, uint256 role, bool active) public payable virtual { _authorizeSetRole(holder, role, active); _setRole(holder, role, active); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC READ FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns if `holder` has active `role`. function hasRole(address holder, uint256 role) public view virtual returns (bool result) { /// @solidity memory-safe-assembly assembly { mstore(0x18, holder) mstore(0x04, _ENUMERABLE_ROLES_SLOT_SEED) mstore(0x00, role) result := iszero(iszero(sload(keccak256(0x00, 0x38)))) } } /// @dev Returns an array of the holders of `role`. function roleHolders(uint256 role) public view virtual returns (address[] memory result) { /// @solidity memory-safe-assembly assembly { result := mload(0x40) mstore(0x04, _ENUMERABLE_ROLES_SLOT_SEED) mstore(0x00, role) let rootSlot := keccak256(0x00, 0x24) let rootPacked := sload(rootSlot) let n := shr(160, shl(160, rootPacked)) let o := add(0x20, result) mstore(o, shr(96, rootPacked)) for { let i := 1 } lt(i, n) { i := add(i, 1) } { mstore(add(o, shl(5, i)), shr(96, sload(add(rootSlot, i)))) } mstore(result, n) mstore(0x40, add(o, shl(5, n))) } } /// @dev Returns the total number of holders of `role`. function roleHolderCount(uint256 role) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { mstore(0x04, _ENUMERABLE_ROLES_SLOT_SEED) mstore(0x00, role) result := shr(160, shl(160, sload(keccak256(0x00, 0x24)))) } } /// @dev Returns the holder of `role` at the index `i`. function roleHolderAt(uint256 role, uint256 i) public view virtual returns (address result) { /// @solidity memory-safe-assembly assembly { mstore(0x04, _ENUMERABLE_ROLES_SLOT_SEED) mstore(0x00, role) let rootSlot := keccak256(0x00, 0x24) let rootPacked := sload(rootSlot) if iszero(lt(i, shr(160, shl(160, rootPacked)))) { mstore(0x00, 0x5694da8e) // `RoleHoldersIndexOutOfBounds()`. revert(0x1c, 0x04) } result := shr(96, rootPacked) if i { result := shr(96, sload(add(rootSlot, i))) } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Set the role for holder directly without authorization guard. function _setRole(address holder, uint256 role, bool active) internal virtual { _validateRole(role); /// @solidity memory-safe-assembly assembly { let holder_ := shl(96, holder) if iszero(holder_) { mstore(0x00, 0x82550143) // `RoleHolderIsZeroAddress()`. revert(0x1c, 0x04) } mstore(0x18, holder) mstore(0x04, _ENUMERABLE_ROLES_SLOT_SEED) mstore(0x00, role) let rootSlot := keccak256(0x00, 0x24) let n := shr(160, shl(160, sload(rootSlot))) let positionSlot := keccak256(0x00, 0x38) let position := sload(positionSlot) for {} 1 {} { if iszero(active) { if iszero(position) { break } let nSub := sub(n, 1) if iszero(eq(sub(position, 1), nSub)) { let lastHolder_ := shl(96, shr(96, sload(add(rootSlot, nSub)))) sstore(add(rootSlot, sub(position, 1)), lastHolder_) sstore(add(rootSlot, nSub), 0) mstore(0x24, lastHolder_) sstore(keccak256(0x00, 0x38), position) } sstore(rootSlot, or(shl(96, shr(96, sload(rootSlot))), nSub)) sstore(positionSlot, 0) break } if iszero(position) { sstore(add(rootSlot, n), holder_) sstore(positionSlot, add(n, 1)) sstore(rootSlot, add(sload(rootSlot), 1)) } break } // forgefmt: disable-next-item log4(0x00, 0x00, _ROLE_SET_EVENT_SIGNATURE, shr(96, holder_), role, iszero(iszero(active))) } } /// @dev Requires the role is not greater than `MAX_ROLE()`. /// If `MAX_ROLE()` is not implemented, this is an no-op. function _validateRole(uint256 role) internal view virtual { /// @solidity memory-safe-assembly assembly { mstore(0x00, 0xd24f19d5) // `MAX_ROLE()`. if and( and(gt(role, mload(0x00)), gt(returndatasize(), 0x1f)), staticcall(gas(), address(), 0x1c, 0x04, 0x00, 0x20) ) { mstore(0x00, 0xd954416a) // `InvalidRole()`. revert(0x1c, 0x04) } } } /// @dev Checks that the caller is authorized to set the role. function _authorizeSetRole(address holder, uint256 role, bool active) internal virtual { if (!_enumerableRolesSenderIsContractOwner()) _revertEnumerableRolesUnauthorized(); // Silence compiler warning on unused variables. (holder, role, active) = (holder, role, active); } /// @dev Returns if `holder` has any roles in `encodedRoles`. /// `encodedRoles` is `abi.encode(SAMPLE_ROLE_0, SAMPLE_ROLE_1, ...)`. function _hasAnyRoles(address holder, bytes memory encodedRoles) internal view virtual returns (bool result) { /// @solidity memory-safe-assembly assembly { mstore(0x18, holder) mstore(0x04, _ENUMERABLE_ROLES_SLOT_SEED) let end := add(encodedRoles, shl(5, shr(5, mload(encodedRoles)))) for {} lt(result, lt(encodedRoles, end)) {} { encodedRoles := add(0x20, encodedRoles) mstore(0x00, mload(encodedRoles)) result := sload(keccak256(0x00, 0x38)) } result := iszero(iszero(result)) } } /// @dev Reverts if `msg.sender` does not have `role`. function _checkRole(uint256 role) internal view virtual { if (!hasRole(msg.sender, role)) _revertEnumerableRolesUnauthorized(); } /// @dev Reverts if `msg.sender` does not have any role in `encodedRoles`. function _checkRoles(bytes memory encodedRoles) internal view virtual { if (!_hasAnyRoles(msg.sender, encodedRoles)) _revertEnumerableRolesUnauthorized(); } /// @dev Reverts if `msg.sender` is not the contract owner and does not have `role`. function _checkOwnerOrRole(uint256 role) internal view virtual { if (!_enumerableRolesSenderIsContractOwner()) _checkRole(role); } /// @dev Reverts if `msg.sender` is not the contract owner and /// does not have any role in `encodedRoles`. function _checkOwnerOrRoles(bytes memory encodedRoles) internal view virtual { if (!_enumerableRolesSenderIsContractOwner()) _checkRoles(encodedRoles); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MODIFIERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Marks a function as only callable by an account with `role`. modifier onlyRole(uint256 role) virtual { _checkRole(role); _; } /// @dev Marks a function as only callable by an account with any role in `encodedRoles`. /// `encodedRoles` is `abi.encode(SAMPLE_ROLE_0, SAMPLE_ROLE_1, ...)`. modifier onlyRoles(bytes memory encodedRoles) virtual { _checkRoles(encodedRoles); _; } /// @dev Marks a function as only callable by the owner or by an account with `role`. modifier onlyOwnerOrRole(uint256 role) virtual { _checkOwnerOrRole(role); _; } /// @dev Marks a function as only callable by the owner or /// by an account with any role in `encodedRoles`. /// Checks for ownership first, then checks for roles. /// `encodedRoles` is `abi.encode(SAMPLE_ROLE_0, SAMPLE_ROLE_1, ...)`. modifier onlyOwnerOrRoles(bytes memory encodedRoles) virtual { _checkOwnerOrRoles(encodedRoles); _; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PRIVATE HELPERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns if the `msg.sender` is equal to `owner()` on this contract. /// If the contract does not have `owner()` implemented, returns false. function _enumerableRolesSenderIsContractOwner() private view returns (bool result) { /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x8da5cb5b) // `owner()`. result := and( and(eq(caller(), mload(0x00)), gt(returndatasize(), 0x1f)), staticcall(gas(), address(), 0x1c, 0x04, 0x00, 0x20) ) } } /// @dev Reverts with `EnumerableRolesUnauthorized()`. function _revertEnumerableRolesUnauthorized() private pure { /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x99152cca) // `EnumerableRolesUnauthorized()`. revert(0x1c, 0x04) } } }
{ "viaIR": false, "codegen": "yul", "remappings": [ "dn404/=lib/dn404/", "forge-std/=lib/forge-std/src/", "solady/=lib/solady/src/" ], "evmVersion": "cancun", "outputSelection": { "*": { "*": [ "abi", "metadata" ], "": [ "ast" ] } }, "optimizer": { "enabled": true, "mode": "3", "fallback_to_optimizing_for_size": false, "disable_system_request_memoization": true }, "metadata": {}, "libraries": {}, "enableEraVMExtensions": false, "forceEVMLA": false }
[{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"EnumerableRolesUnauthorized","type":"error"},{"inputs":[],"name":"InvalidRole","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"RoleHolderIsZeroAddress","type":"error"},{"inputs":[],"name":"RoleHoldersIndexOutOfBounds","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"by","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"address","name":"erc20ToSell","type":"address"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Bought","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"holder","type":"address"},{"indexed":true,"internalType":"uint256","name":"role","type":"uint256"},{"indexed":true,"internalType":"bool","name":"active","type":"bool"}],"name":"RoleSet","type":"event"},{"inputs":[],"name":"ADMIN_ROLE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_ROLE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WITHDRAWER_ROLE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"saleId","type":"uint256"},{"internalType":"address","name":"by","type":"address"}],"name":"bought","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"saleId","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"customAddressQuota","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"buy","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"},{"internalType":"uint256","name":"role","type":"uint256"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"result","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"initialOwner","type":"address"},{"internalType":"address","name":"initialAdmin","type":"address"},{"internalType":"string","name":"notSoSecret","type":"string"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"erc20","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"price","type":"uint256"}],"name":"priceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"role","type":"uint256"},{"internalType":"uint256","name":"i","type":"uint256"}],"name":"roleHolderAt","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"role","type":"uint256"}],"name":"roleHolderCount","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"role","type":"uint256"}],"name":"roleHolders","outputs":[{"internalType":"address[]","name":"result","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"saleId","type":"uint256"}],"name":"saleInfo","outputs":[{"components":[{"internalType":"address","name":"erc20ToSell","type":"address"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"},{"internalType":"uint256","name":"totalQuota","type":"uint256"},{"internalType":"uint256","name":"addressQuota","type":"uint256"},{"internalType":"uint256","name":"totalBought","type":"uint256"},{"internalType":"address","name":"signer","type":"address"}],"internalType":"struct SheepySale.SaleInfo","name":"info","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"},{"internalType":"uint256","name":"role","type":"uint256"},{"internalType":"bool","name":"active","type":"bool"}],"name":"setRole","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"saleId","type":"uint256"},{"components":[{"internalType":"address","name":"erc20ToSell","type":"address"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"},{"internalType":"uint256","name":"totalQuota","type":"uint256"},{"internalType":"uint256","name":"addressQuota","type":"uint256"},{"internalType":"address","name":"signer","type":"address"}],"internalType":"struct SheepySale.SaleConfig","name":"c","type":"tuple"}],"name":"setSale","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"withdrawAllNative","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"erc20","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Deployed Bytecode
0x0003000000000002000b000000000002000200000001035500000060031002700000025c0030019d0000008004000039000000400040043f00000001002001900000001b0000c13d0000025c02300197000000040020008c000006c30000413d000000000301043b000000e0033002700000025e0030009c000000230000a13d0000025f0030009c000000490000213d000002670030009c000000a20000213d0000026b0030009c0000010d0000613d0000026c0030009c0000011c0000613d0000026d0030009c000001060000613d000006c30000013d0000000001000416000000000001004b000006c30000c13d0000002001000039000001000010044300000120000004430000025d010000410000096d0001042e0000026e0030009c000000740000a13d0000026f0030009c000000ba0000213d000002730030009c000002660000613d000002740030009c000002780000613d000002750030009c000006c30000c13d000000640020008c000006c30000413d0000000402100370000000000202043b000b00000002001d0000027c0020009c000006c30000213d0000002402100370000000000202043b000a00000002001d0000004401100370000000000201043b000000000002004b0000000001000039000000010100c039000900000002001d000000000012004b000006c30000c13d0000026801000041000000000010043f00000000010004140000000004000410000000040040008c000004220000c13d00000001020000390000001c010000390000000103000031000004460000013d000002600030009c000000c60000213d000002640030009c000001060000613d000002650030009c0000015f0000613d000002660030009c000006c30000c13d000000440020008c000006c30000413d0000000002000416000000000002004b000006c30000c13d0000002402100370000000000202043b000b00000002001d0000028602000041000000040020043f0000000401100370000000000101043b000000000010043f00000000010004140000025c0010009c0000025c01008041000000c00110021000000287011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000201043b000000000102041a00000288031001970000000b04000029000000000034004b000003a00000813d0000000003040019000000000004004b000000720000613d0000000001320019000000000101041a0000006001100270000003d50000013d000002760030009c000000db0000a13d000002770030009c000001750000613d000002780030009c000001910000613d000002790030009c000006c30000c13d000000640020008c000006c30000413d0000000003000416000000000003004b000006c30000c13d0000000403100370000000000603043b0000027c0060009c000006c30000213d0000002403100370000000000303043b000b00000003001d0000027c0030009c000006c30000213d0000004403100370000000000403043b000002930040009c000006c30000213d0000002303400039000000000023004b000006c30000813d0000000405400039000000000351034f000000000303043b000002b50030009c0000009c0000813d0000001f08300039000002be088001970000003f08800039000002be08800197000002b60080009c000004990000a13d000002a701000041000000000010043f0000004101000039000000040010043f000002a8010000410000096e00010430000002680030009c000001ab0000613d000002690030009c000001b40000613d0000026a0030009c000006c30000c13d000000640020008c000006c30000413d0000000002000416000000000002004b000006c30000c13d0000000401100370000000000201043b0000027c0020009c000006c30000213d0000029101000041000000040010043f0000000401000039000000000010043f000000040020008c000003a40000c13d00000001010000390000000103000031000003c40000013d000002700030009c000002950000613d000002710030009c000002ae0000613d000002720030009c000006c30000c13d0000000001000416000000000001004b000006c30000c13d000000800000043f0000027e010000410000096d0001042e000002610030009c000001ed0000613d000002620030009c0000021c0000613d000002630030009c000006c30000c13d000000240020008c000006c30000413d0000000002000416000000000002004b000006c30000c13d0000000401100370000000000101043b0000027c0010009c000006c30000213d0000027d020000410000000c0020043f000000000010043f0000000c0100003900000020020000390000018c0000013d0000027a0030009c0000022d0000613d0000027b0030009c000006c30000c13d0000027d010000410000000c0010043f0000000001000411000000000010043f0000028301000041000000000010044300000000010004140000025c0010009c0000025c01008041000000c00110021000000284011001c70000800b02000039096c09670000040f0000000100200190000007260000613d000000000101043b000b00000001001d00000000010004140000025c0010009c0000025c01008041000000c00110021000000282011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b0000000b02000029000002bb0220009a000000000021041b00000000010004140000025c0010009c0000025c01008041000000c0011002100000028f011001c70000800d020000390000000203000039000002bc040000410000028f0000013d0000000001000416000000000001004b000006c30000c13d0000000101000039000000800010043f0000027e010000410000096d0001042e000001040020008c000006c30000413d0000000001000416000000000001004b000006c30000c13d0000026801000041000000000010043f00000000010004140000000002000410000000040020008c000002c80000c13d00000001020000390000001c010000390000000103000031000002ea0000013d000000240020008c000006c30000413d0000000002000416000000000002004b000006c30000c13d0000028602000041000000040020043f0000000401100370000000000101043b000000000010043f00000000010004140000025c0010009c0000025c01008041000000c00110021000000287011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000201043b000000000102041a0000006003100270000000a00030043f0000028803100197000000020030008c000001400000413d00000001040000390000000005240019000000000505041a00000060055002700000000506400210000000a00660003900000000005604350000000104400039000000000034004b000001370000413d000000800030043f0000000501100210000002ab02100197000000a001200039000000400010043f00000020030000390000000000310435000000c003200039000000800400043d0000000000430435000000e003200039000000000004004b000001550000613d000000a005000039000000000600001900000000570504340000027c0770019700000000037304360000000106600039000000000046004b0000014f0000413d0000000002230049000000a00220008a0000025c0020009c0000025c0200804100000060022002100000025c0010009c0000025c010080410000004001100210000000000112019f0000096d0001042e000000240020008c000006c30000413d0000000002000416000000000002004b000006c30000c13d0000000401100370000000000101043b000b00000001001d0000027c0010009c000006c30000213d0000026801000041000000000010043f00000000010004140000000002000410000000040020008c00000001050000390000033b0000c13d0000001c0100043d000000000010043f000000010300003100000000020500190000035e0000013d000000440020008c000006c30000413d0000000002000416000000000002004b000006c30000c13d0000002402100370000000000202043b000b00000002001d0000027c0020009c000006c30000213d0000000401100370000000000101043b000000000010043f000000200000043f00000040020000390000000001000019096c094d0000040f0000000b02000029000000000020043f0000000801100039000000200010043f00000000010000190000004002000039096c094d0000040f000000000101041a000000800010043f0000027e010000410000096d0001042e000000640020008c000006c30000413d0000000002000416000000000002004b000006c30000c13d0000000402100370000000000202043b000b00000002001d0000027c0020009c000006c30000213d0000002401100370000000000101043b000a00000001001d0000027c0010009c000006c30000213d0000026801000041000000000010043f00000000010004140000000002000410000000040020008c000003dc0000c13d00000001020000390000001c0100043d000000000010043f0000000103000031000003fe0000013d0000000001000416000000000001004b000006c30000c13d0000027f01000041000000000101041a0000027c01100197000000800010043f0000027e010000410000096d0001042e000000a40020008c000006c30000413d0000000403100370000000000303043b000b00000003001d0000002403100370000000000303043b000a00000003001d0000027c0030009c000006c30000213d0000006403100370000000000303043b000800000003001d0000004403100370000000000303043b000900000003001d0000008403100370000000000303043b000002930030009c000006c30000213d0000002304300039000000000024004b000006c30000813d0000000404300039000000000141034f000000000101043b000700000001001d000002930010009c000006c30000213d0000002403300039000500000003001d000600070030002d000000060020006b000006c30000213d0000000b01000029000000000010043f000000200000043f00000000010004140000025c0010009c0000025c01008041000000c00110021000000294011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000201043b000000000102041a0000027c00100198000005800000c13d000000400100043d0000004402100039000002aa03000041000000000032043500000024021000390000000e030000390000059d0000013d000000240020008c000006c30000413d0000000401100370000000000101043b000b00000001001d0000027c0010009c000006c30000213d0000027f01000041000000000101041a0000000002000411000000000012004b000002c40000c13d0000027d010000410000000c0010043f0000000b01000029000000000010043f00000000010004140000025c0010009c0000025c01008041000000c00110021000000282011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b000900000001001d000000000101041a000a00000001001d0000028301000041000000000010044300000000010004140000025c0010009c0000025c01008041000000c00110021000000284011001c70000800b02000039096c09670000040f0000000100200190000007260000613d000000000101043b0000000a0010006c000004930000a13d0000028501000041000000000010043f00000281010000410000096e00010430000000240020008c000006c30000413d0000000401100370000000000101043b0000027c0010009c000006c30000213d0000027f02000041000000000202041a0000000003000411000000000023004b000002c40000c13d000000000001004b000004960000c13d0000028001000041000000000010043f00000281010000410000096e00010430000000240020008c000006c30000413d0000000002000416000000000002004b000006c30000c13d0000018002000039000000400020043f000000800000043f000000a00000043f000000c00000043f000000e00000043f000001000000043f000001200000043f0000000401100370000001400000043f000001600000043f000000000101043b000000000010043f000000200000043f00000040020000390000000001000019096c094d0000040f000000000201041a0000027c02200197000000800020043f0000000103100039000000000303041a000000a00030043f0000000204100039000000000404041a000000c00040043f00000006051000390000000706100039000000050710003900000004081000390000000301100039000000000101041a000000e00010043f000000000808041a000001000080043f000000000707041a000001200070043f000000000606041a0000027c06600197000001600060043f000000000505041a000001400050043f000001800020043f000001a00030043f000001c00040043f000001e00010043f000002000080043f000002200070043f000002400050043f000002600060043f000002bd010000410000096d0001042e000000240020008c000006c30000413d0000000002000416000000000002004b000006c30000c13d0000028602000041000000040020043f0000000401100370000000000101043b000000000010043f00000024020000390000000001000019096c094d0000040f000000000101041a0000028801100197000000800010043f0000027e010000410000096d0001042e0000027d010000410000000c0010043f0000000001000411000000000010043f00000000010004140000025c0010009c0000025c01008041000000c00110021000000282011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b000000000001041b00000000010004140000025c0010009c0000025c01008041000000c0011002100000028f011001c70000800d020000390000000203000039000002b4040000410000000005000411096c09620000040f0000000100200190000006c30000613d00000000010000190000096d0001042e000000440020008c000006c30000413d0000000002000416000000000002004b000006c30000c13d0000000402100370000000000202043b0000027c0020009c000006c30000213d000000180020043f0000028602000041000000040020043f0000002401100370000000000101043b000000000010043f00000038020000390000000001000019096c094d0000040f000000000101041a000000000001004b0000000001000039000000010100c039000000800010043f0000027e010000410000096d0001042e0000027f01000041000000000501041a0000000001000411000000000051004b000002c40000c13d00000000010004140000025c0010009c0000025c01008041000000c0011002100000028f011001c70000800d020000390000000303000039000002ae040000410000000006000019096c09620000040f0000000100200190000006c30000613d000002af010000410000027f02000041000000000012041b00000000010000190000096d0001042e000002ad01000041000000000010043f00000281010000410000096e000104300000025c0010009c0000025c01008041000000c00110021000000281011001c7096c09670000040f00000060031002700000025c03300197000000200030008c000000200400003900000000040340190000001f0540018f0000002004400190000002db0000613d000000000601034f0000000007000019000000006806043c0000000007870436000000000047004b000002d70000c13d000000000005004b000002e80000613d000000000141034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f0000000000140435000100000003001f000000000100001900000000040004110000000100200190000003290000613d000000200030008c000003290000413d0000000001010433000000000014004b000003290000c13d00000004010000390000000201100367000000000101043b000000000010043f000000200000043f00000000010004140000025c0010009c0000025c01008041000000c00110021000000294011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b00000002020003670000002403200370000000000303043b0000027c0030009c000006c30000213d000000000401041a000002ac04400197000000000334019f000000000031041b0000004403200370000000000303043b0000000104100039000000000034041b0000006403200370000000000303043b0000000204100039000000000034041b0000008403200370000000000303043b0000000304100039000000000034041b000000a403200370000000000303043b0000000404100039000000000034041b0000000503100039000000c404200370000000000404043b000000000043041b000000e402200370000000000202043b0000027c0020009c000006c30000213d0000000701100039000000000301041a000002ac03300197000000000223019f000000000021041b00000000010000190000096d0001042e000000180040043f0000028601000041000000040010043f000000000000043f00000000010004140000025c0010009c0000025c01008041000000c0011002100000028b011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b000000000101041a000000000001004b000002f20000c13d000004570000013d0000025c0010009c0000025c01008041000000c00110021000000281011001c7096c09670000040f00000060031002700000025c03300197000000200030008c000000200400003900000000040340190000001f0540018f00000020044001900000034e0000613d000000000601034f0000000007000019000000006806043c0000000007870436000000000047004b0000034a0000c13d000000000005004b0000035b0000613d000000000141034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f0000000000140435000100000003001f000000000100043d000000010500003900000000040004110000000100200190000003650000613d000000200030008c000003650000413d000000000014004b000003760000613d000000180040043f0000028601000041000000040010043f000000000050043f00000000010004140000025c0010009c0000025c01008041000000c0011002100000028b011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b000000000101041a000000000001004b000004570000613d0000028c0100004100000000001004430000000001000412000000040010044300000000010004140000025c0010009c0000025c01008041000000c0011002100000028d011001c70000800202000039096c09670000040f00000000030004110000000b0000006b0000000b0300c0290000000100200190000007260000613d0000028e0100004100000000001004430000000001000410000000040010044300000000010004140000025c0010009c0000025c01008041000000c0011002100000028d011001c70000800a02000039000b00000003001d096c09670000040f0000000b040000290000000100200190000007260000613d000000000301043b0000000001000414000000040040008c000002930000613d0000025c0010009c0000025c01008041000000c001100210000000000003004b000005730000c13d0000000b02000029000005770000013d0000028901000041000000000010043f00000281010000410000096e000104300000029201000041096c09670000040f00000060031002700000025c03300197000000200030008c000000200400003900000000040340190000001f0540018f00000020064001900000002004600039000003b50000613d0000002007000039000000000801034f000000008908043c0000000007970436000000000047004b000003b10000c13d000000000005004b000003c20000613d000000000161034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f0000000000140435000000010120018f000100000003001f0000001f0030008c00000000020000390000000102002039000000000121016f000000200200043d00000000012100a9000000ff0110018f096c079e0000040f00000002030003670000004402300370000000000202043b0000002403300370000000000303043b000000000401001900000000010300190000000003040019096c08220000040f000000400200043d00000000001204350000025c0020009c0000025c0200804100000040012002100000028a011001c70000096d0001042e0000025c0010009c0000025c01008041000000c00110021000000281011001c7096c09670000040f00000060031002700000025c03300197000000200030008c000000200400003900000000040340190000001f0540018f0000002004400190000003ef0000613d000000000601034f0000000007000019000000006806043c0000000007870436000000000047004b000003eb0000c13d000000000005004b000003fc0000613d000000000141034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f0000000000140435000100000003001f000000000100043d00000000040004110000000100200190000004050000613d000000200030008c000004050000413d000000000014004b000004180000613d000000180040043f0000028601000041000000040010043f0000000101000039000000000010043f00000000010004140000025c0010009c0000025c01008041000000c0011002100000028b011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b000000000101041a000000000001004b0000000004000411000004570000613d0000000a0000006b0000000a0400c02900000044010000390000000201100367000000000301043b0000000b010000290000000002040019096c07b50000040f00000000010000190000096d0001042e0000025c0010009c0000025c01008041000000c00110021000000281011001c70000000002040019096c09670000040f00000060031002700000025c03300197000000200030008c000000200400003900000000040340190000001f0540018f0000002004400190000004360000613d000000000601034f0000000007000019000000006806043c0000000007870436000000000047004b000004320000c13d000000000005004b000004430000613d000000000141034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f0000000000140435000100000003001f000000000100001900000000040004100000000100200190000004570000613d000000200030008c000004570000413d00000000020004110000000001010433000000000012004b000004570000c13d0000026401000041000000000010043f0000000001000414000000040040008c0000045b0000c13d00000001030000390000001c010000390000000002030019000004810000013d000002ba01000041000000000010043f00000281010000410000096e000104300000025c0010009c0000025c01008041000000c00110021000000281011001c70000000002040019096c09670000040f00000060031002700000025c03300197000000200030008c000000200400003900000000040340190000001f0540018f00000020044001900000046f0000613d000000000601034f0000000007000019000000006806043c0000000007870436000000000047004b0000046b0000c13d000000000005004b0000047c0000613d000000000141034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f0000000000140435000100000003001f0000001f0030008c00000000030000390000000103002039000000000100001900000001002001900000048c0000613d00000001003001900000048c0000613d00000000010104330000000a0010006b0000048c0000a13d000002b301000041000000000010043f00000281010000410000096e000104300000000b01000029000000000001004b000005410000c13d000002b201000041000000000010043f00000281010000410000096e000104300000000901000029000000000001041b0000000b01000029096c08090000040f00000000010000190000096d0001042e00000024044000390000008008800039000000400080043f000000800030043f0000000004430019000000000024004b000006c30000213d0000002002500039000000000221034f000002be043001980000001f0530018f000000a001400039000004ac0000613d000000a007000039000000000802034f000000008908043c0000000007970436000000000017004b000004a80000c13d000000000005004b000004b90000613d000000000242034f0000000304500210000000000501043300000000054501cf000000000545022f000000000202043b0000010004400089000000000242022f00000000024201cf000000000252019f0000000000210435000000a00130003900000000000104350000027f01000041000000000201041a000000000002004b000005a80000c13d000000000006004b0000000002000019000002af02006041000000000262019f000000000021041b00000000010004140000025c0010009c0000025c01008041000000c0011002100000028f011001c70000800d020000390000000303000039000002ae040000410000000005000019096c09620000040f0000000100200190000006c30000613d000000800100043d0000025c0010009c0000025c01008041000000600110021000000000020004140000025c0020009c0000025c02008041000000c002200210000000000121019f000002b8011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b000002b90010009c000006c30000c13d0000000b0000006b000002930000613d0000026401000041000000000010043f00000000010004140000000002000410000000040020008c0000050a0000613d0000025c0010009c0000025c01008041000000c00110021000000281011001c7096c09670000040f00000060021002700000025c02200197000000200020008c000000200300003900000000030240190000001f0430018f0000002003300190000004fc0000613d000000000501034f0000000006000019000000005705043c0000000006760436000000000036004b000004f80000c13d000000000004004b000005090000613d000000000131034f0000000304400210000000000503043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000130435000100000002001f0000000b01000029000000180010043f0000028601000041000000040010043f000000000000043f00000000010004140000025c0010009c0000025c01008041000000c00110021000000287011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b000a00000001001d000000000101041a000900000001001d00000000010004140000025c0010009c0000025c01008041000000c0011002100000028b011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b000000000201041a000000000002004b000005350000c13d0000000b020000290000006002200210000000090300002900000288033001970000000a050000290000000004530019000000000024041b0000000102300039000000000021041b000000000105041a0000000101100039000000000015041b00000000010004140000025c0010009c0000025c01008041000000c0011002100000028f011001c70000800d0200003900000004030000390000000107000039000002b1040000410000000b050000290000000006000019000002900000013d000000180010043f0000028601000041000000040010043f0000000a01000029000000000010043f00000000010004140000025c0010009c0000025c01008041000000c00110021000000287011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b000700000001001d000000000101041a000800000001001d00000000010004140000025c0010009c0000025c01008041000000c0011002100000028b011001c70000801002000039096c09670000040f0000000100200190000006c30000613d0000000802000029000602880020019b000000000101043b000500000001001d000000000101041a000800000001001d000000090000006b000005ac0000613d000000080000006b000005cf0000c13d0000000b010000290000006001100210000000070300002900000006040000290000000002340019000000000012041b00000001014000390000000502000029000000000012041b000000000103041a0000000101100039000000000013041b000005cf0000013d0000028f011001c700008009020000390000000b040000290000000005000019096c09620000040f00000060011002700001025c0010019d0000000100200190000002930000c13d0000029001000041000000000010043f00000281010000410000096e00010430000400000002001d0000000201200039000000000101041a000300000001001d0000028301000041000000000010044300000000010004140000025c0010009c0000025c01008041000000c00110021000000284011001c70000800b02000039096c09670000040f0000000100200190000007260000613d000000000101043b000000030010006b000005970000213d00000004020000290000000302200039000000000202041a000000000021004b000005db0000a13d000000400100043d0000004402100039000002a9030000410000000000320435000000240210003900000009030000390000000000320435000002960200004100000000002104350000000402100039000000200300003900000000003204350000025c0010009c0000025c01008041000000400110021000000297011001c70000096e00010430000002b701000041000000000010043f00000281010000410000096e00010430000000080000006b000005cf0000613d0000000802000029000000060020006c000005c60000613d0000000701000029000000010110008a00000008021000290000000601100029000000000301041a000002b003300197000000000032041b000000000001041b000000240030043f00000000010004140000025c0010009c0000025c01008041000000c0011002100000028b011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b0000000802000029000000000021041b0000000601000029000000010110008a0000000703000029000000000203041a000002b002200197000000000112019f000000000013041b0000000501000029000000000001041b00000000010004140000025c0010009c0000025c01008041000000c0011002100000028f011001c70000800d020000390000000403000039000002b1040000410000000b050000290000000a060000290000000907000029000002900000013d00000004010000290000000601100039000000000201041a000000090020002a0000064d0000413d0000000902200029000000000021041b00000004010000290000000401100039000000000101041a000000000012004b000005ee0000a13d000000400100043d0000004402100039000002a6030000410000000000320435000000240210003900000015030000390000059d0000013d00000004020000290000000501200039000000000101041a000300000001001d00000000010004110000027c01100197000000000010043f0000000801200039000000200010043f00000000010004140000025c0010009c0000025c01008041000000c00110021000000294011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b000000000201041a000000090020002a0000064d0000413d0000000902200029000000000021041b0000000303000029000000080030006c0000000803008029000000000032004b000006120000a13d000000400100043d0000004402100039000002a5030000410000000000320435000000240210003900000017030000390000059d0000013d0000000402000029000000000102041a0000000102200039000100000002001d000000000202041a000200000002001d0000029102000041000000040020043f0000000402000039000000000020043f0000027c01100197000300000001001d000000040010008c000006230000c13d00000001010000390000000103000031000006440000013d00000292010000410000000302000029096c09670000040f00000060031002700000025c03300197000000200030008c000000200400003900000000040340190000001f0540018f00000020064001900000002004600039000006350000613d0000002007000039000000000801034f000000008908043c0000000007970436000000000047004b000006310000c13d000000000005004b000006420000613d000000000161034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f0000000000140435000000010120018f000100000003001f0000001f0030008c00000000020000390000000102002039000000000121016f000000200200043d00000000012100a9000000ff0110018f0000004d0010008c000006530000a13d000002a701000041000000000010043f0000001101000039000000040010043f000002a8010000410000096e00010430000000000001004b000006570000c13d0000000103000039000006600000013d0000000a020000390000000103000039000000010010019000000000042200a9000000010200603900000000033200a900000001011002720000000002040019000006590000c13d00000009010000290000000202000029096c08220000040f0000000002000416000000000012004b000006790000c13d00000004010000290000000701100039000000000101041a0002027c0010019c0000067d0000c13d0000000a01000029000000140010043f0000000901000029000000340010043f000002a001000041000000000010043f00000000010004140000000302000029000000040020008c000006c50000c13d000b00010000003d000000100100043d000000000010043f000006e90000013d000000400100043d00000044021000390000029503000041000001e90000013d000000400100043d00000080021000390000000803000029000000000032043500000060021000390000000003000411000000000032043500000040021000390000000b0300002900000000003204350000008002000039000000000221043600000298030000410000000000320435000002990010009c0000009c0000213d000000a003100039000000400030043f0000025c0020009c0000025c02008041000000400220021000000000010104330000025c0010009c0000025c010080410000006001100210000000000121019f00000000020004140000025c0020009c0000025c02008041000000c002200210000000000112019f0000028f011001c70000801002000039096c09670000040f0000000100200190000006c30000613d000000000101043b000000200010043f0000029a01000041000000000010043f00000000010004140000025c0010009c0000025c01008041000000c0011002100000029b011001c70000801002000039096c09670000040f0000000100200190000006c30000613d00000007020000290000001f02200039000002be022001970000003f02200039000002be02200197000000000101043b000000400300043d0000000002230019000000000032004b00000000050000390000000105004039000002930020009c0000009c0000213d00000001005001900000009c0000c13d000000400020043f000000070200002900000000022304360000000606000029000000000060007c000007270000a13d00000000010000190000096e000104300000025c0010009c0000025c01008041000000c001100210000002a1011001c70000000302000029096c09620000040f00000060031002700000025c03300197000000200030008c000000200400003900000000040340190000001f0540018f0000002004400190000006d90000613d000000000601034f0000000007000019000000006806043c0000000007870436000000000047004b000006d50000c13d000000000005004b000006e60000613d000000000141034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f0000000000140435000b000100200193000100000003001f000000000100043d000000010010008c0000070e0000c13d0000000b0000006b0000070e0000613d000000340000043f0000000401000029000000000101041a0000000102000029000000000202041a000000400300043d000000800430003900000009050000290000000000540435000000600430003900000000002404350000027c01100197000000400230003900000000001204350000000a010000290000027c0110019700000020023000390000000000120435000000000100041100000000001304350000025c0030009c0000025c03008041000000400130021000000000020004140000025c0020009c0000025c02008041000000c002200210000000000112019f000002a3011001c70000800d020000390000000103000039000002a404000041000002900000013d00080001000000350000028c0100004100000000001004430000000301000029000000040010044300000000010004140000025c0010009c0000025c01008041000000c0011002100000028d011001c70000800202000039096c09670000040f0000000100200190000007260000613d000000000101043b000000000001004b000000080200002900000001022061bf0000000b0020006c000006ed0000413d000002a201000041000000000010043f00000281010000410000096e00010430000000000001042f0000000706000029000002be056001980000001f0660018f000000050400002900000002074003670000000004520019000007340000613d000000000807034f0000000009020019000000008a08043c0000000009a90436000000000049004b000007300000c13d000000000006004b000007410000613d000000000557034f0000000306600210000000000704043300000000076701cf000000000767022f000000000505043b0000010006600089000000000565022f00000000056501cf000000000575019f000000000054043500000007042000290000000000040435000000400400043d000b00000004001d0000000004030433000000400040008c000007510000613d000000410040008c000007860000c13d00000060043000390000000004040433000000f804400270000000200040043f00000040033000390000000003030433000007570000013d00000040033000390000000003030433000000ff043002700000001b04400039000000200040043f0000029c03300197000000600030043f000000000010043f0000000001020433000000400010043f00000000010004140000025c0010009c0000025c01008041000000c0011002100000029d011001c70000000102000039096c09670000040f000000010900003900000060031002700000025c03300197000000200030008c000000200400003900000000040340190000001f0540018f000000200640019000000001046001bf000007710000613d000000000701034f000000007807043c0000000009890436000000000049004b0000076d0000c13d000000010220018f000000000005004b0000077f0000613d000000000161034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f0000000000140435000100000003001f0000000001020433000000600000043f0000000b02000029000000400020043f000000000003004b0000078a0000c13d0000029f01000041000000000010043f00000281010000410000096e000104300000027c01100197000000020010006c0000066b0000613d0000000b0300002900000044013000390000029e020000410000000000210435000000240130003900000012020000390000000000210435000002960100004100000000001304350000000401300039000000200200003900000000002104350000025c0030009c0000025c03008041000000400130021000000297011001c70000096e000104300000004e0010008c000007af0000813d000000000001004b000007ad0000613d0000000a030000390000000102000039000000010010019000000000043300a9000000010300603900000000022300a900000001011002720000000003040019000007a40000c13d0000000001020019000000000001042d0000000101000039000000000001042d000002a701000041000000000010043f0000001101000039000000040010043f000002a8010000410000096e0001043000020000000000020000000004010019000000140020043f000000340030043f000002a001000041000000000010043f0000000001000414000000040040008c000007c40000c13d0000000102000039000000100100043d000000000010043f000000000002004b000007ec0000c13d000007ee0000013d0000025c0010009c0000025c01008041000000c001100210000002a1011001c7000200000004001d0000000002040019096c09620000040f00000060031002700000025c03300197000000200030008c000000200400003900000000040340190000001f0540018f0000002004400190000007d90000613d000000000601034f0000000007000019000000006806043c0000000007870436000000000047004b000007d50000c13d000000000005004b000007e60000613d000000000141034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f0000000000140435000000010220018f000100000003001f000000000100043d0000000204000029000000000002004b000007ee0000613d000000010010008c000008020000613d000200000002001d00010001000000350000028c010000410000000000100443000000040040044300000000010004140000025c0010009c0000025c01008041000000c0011002100000028d011001c70000800202000039096c09670000040f0000000100200190000008040000613d000000000101043b000000000001004b000000010200002900000001022061bf000000020020006c000008050000813d000000340000043f000000000001042d000000000001042f000002a201000041000000000010043f00000281010000410000096e0001043000010000000000020000027f02000041000000000502041a00000000020004140000027c061001970000025c0020009c0000025c02008041000000c0012002100000028f011001c70000800d020000390000000303000039000002ae04000041000100000006001d096c09620000040f0000000100200190000008200000613d000000010000006b0000000001000019000002af0100604100000001011001af0000027f02000041000000000012041b000000000001042d00000000010000190000096e00010430000100000000000200000000041200a9000000000001004b000000000514c0d90000000005006019000000000025004b0000000005000039000000010500c039000000000001004b0000000006000039000000010600c039000000000556016f0000000100500190000008340000c13d000000000003004b000008340000613d00000000043400d9000008e50000013d000000010600008a000000000061004b00000000050100190000000005006019000000000062004b0000000007020019000000000700601900000000855700a9000002bfa780012a0000008009500270000002c00080009c000008460000213d000000800aa00210000000000a9a019f000002bf0b7000d10000000000ab004b000000010770208a000008470000013d000000010770008a0000008008800210000000000898019f000002bf077001970000000008780019000002bf9780012a000002bf05500197000002c00080009c000008550000213d0000008009900210000000000959019f000002bf0a7000d100000000009a004b000000010770208a000008560000013d000000010770008a0000008008800210000000000558019f000002bf077001970000000005750019000000000545004b000000010550408a000000000003004b000008650000613d00000000703200d900000000803100d9000002bf0030009c000008670000213d00000000068700a900000000603600d9000008bc0000013d0000000006000019000008bc0000013d00000000798700a9000000000037004b000008bc0000813d000002c10030009c000000c0060000390000008006004039000000000863022f00000040060000390000008006004039000002c20080009c000000200660808a0000002008808270000002c30080009c000000100660808a0000001008808270000001000080008c000000080660808a0000000808808270000000100080008c000000000a080019000000040aa082700000000400a0008c000000000b0a0019000000020bb08270000000020c00008a000000000db000890000000200b0008c000000000d0c8019000000100080008c000000040660808a0000000400a0008c000000020660808a00000000066d0019000000ff0860018f00000000078701cf000002c608600167000000ff0880018f000000010a90027000000000088a022f000000000b87019f00000000076301cf000000800870027000000000ed8b00d900000000096901cf000100000009001d000000800c900270000002bf097001970000089b0000013d000000000e8e0019000000010dd0008a000002bf00e0009c000008a20000813d000002c400d0009c000008970000213d000000000f9d00a9000000800ae00210000000000aca019f0000000000af004b000008970000213d000002bf0ad00197000000000a7a00a9000000800bb00210000000000bcb019f000000000bab004900000000dc8b00d9000000010a000029000002bf0aa00197000008af0000013d000000000d8d0019000000010cc0008a000002bf00d0009c000008b60000813d000002c400c0009c000008ab0000213d000000000e9c00a9000000800fd00210000000000faf019f0000000000fe004b000008ab0000213d000002bf08c0019700000000077800a90000008008b002100000000008a8019f0000000007780049000000000667022f000000000035004b000009480000813d00000000073000890000000007370170000000000873c0d9000000000800601900000003098000c9000000020990015f000000000a8900a9000000020aa0008900000000099a00a9000000000a8900a9000000020aa0008900000000099a00a9000000000a8900a9000000020aa0008900000000099a00a9000000000a8900a9000000020aa0008900000000099a00a9000000000a8900a9000000020aa0008900000000099a00a900000000088900a9000000020880008900000000089800a9000000000007004b000008de0000613d000000000964004900000000097900d9000000000a70008900000000077a00d90000000107700039000008e00000013d00000001070000390000000009000019000000000064004b000000010550408a00000000045700a9000000000494019f00000000044800a900000000203200d900000000103100d9000002bf0030009c000008ef0000213d00000000011200a900000000103100d9000000000001004b000009440000c13d0000000001040019000000000001042d00000000251200a9000000000032004b000009440000813d000002c10030009c000000c0010000390000008001004039000000000613022f00000040010000390000008001004039000002c20060009c000000200110808a0000002006608270000002c30060009c000000100110808a0000001006608270000001000060008c000000080110808a0000000806608270000000100060008c00000000070600190000000407708270000000040070008c00000000080700190000000208808270000000020900008a000000000a800089000000020080008c000000000a098019000000100060008c000000040110808a000000040070008c000000020110808a00000000011a0019000000ff0610018f00000000026201cf000002c606100167000000ff0660018f0000000107500270000000000667022f000000000762019f00000000021301cf000000800320027000000000a93700d900000000061501cf0000008008600270000002bf05200197000009220000013d000000000a3a0019000000010990008a000002bf00a0009c000009290000813d000002c40090009c0000091e0000213d000000000b5900a9000000800ca00210000000000c8c019f0000000000cb004b0000091e0000213d000002bf0990019700000000092900a90000008007700210000000000787019f000000000797004900000000983700d9000002bf06600197000009350000013d0000000009390019000000010880008a000002bf0090009c0000093c0000813d000002c40080009c000009310000213d000000000a5800a9000000800b900210000000000b6b019f0000000000ba004b000009310000213d000002bf0380019700000000022300a90000008003700210000000000363019f0000000002230049000000000112022f000000000001004b000008ed0000613d000000010040003a000009480000413d0000000101400039000000000001042d000002c501000041000000000010043f00000281010000410000096e00010430000000000001042f0000025c0010009c0000025c0100804100000040011002100000025c0020009c0000025c020080410000006002200210000000000112019f00000000020004140000025c0020009c0000025c02008041000000c002200210000000000112019f0000028f011001c70000801002000039096c09670000040f0000000100200190000009600000613d000000000101043b000000000001042d00000000010000190000096e0001043000000965002104210000000102000039000000000001042d0000000002000019000000000001042d0000096a002104230000000102000039000000000001042d0000000002000019000000000001042d0000096c000004320000096d0001042e0000096e00010430000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0000000200000000000000000000000000000040000001000000000000000000000000000000000000000000000000000000000000000000000000007883bfff00000000000000000000000000000000000000000000000000000000d24f19d400000000000000000000000000000000000000000000000000000000f04e283d00000000000000000000000000000000000000000000000000000000f04e283e00000000000000000000000000000000000000000000000000000000f2fde38b00000000000000000000000000000000000000000000000000000000fee81cf400000000000000000000000000000000000000000000000000000000d24f19d500000000000000000000000000000000000000000000000000000000d9f66db100000000000000000000000000000000000000000000000000000000e3b3ac43000000000000000000000000000000000000000000000000000000008da5cb5a000000000000000000000000000000000000000000000000000000008da5cb5b00000000000000000000000000000000000000000000000000000000a988aeed00000000000000000000000000000000000000000000000000000000cff8c22f000000000000000000000000000000000000000000000000000000007883c0000000000000000000000000000000000000000000000000000000000084cc10c50000000000000000000000000000000000000000000000000000000085f438c100000000000000000000000000000000000000000000000000000000492ba874000000000000000000000000000000000000000000000000000000005c97f4a1000000000000000000000000000000000000000000000000000000005c97f4a200000000000000000000000000000000000000000000000000000000715018a60000000000000000000000000000000000000000000000000000000075b238fc00000000000000000000000000000000000000000000000000000000492ba8750000000000000000000000000000000000000000000000000000000054d1f13d000000000000000000000000000000000000000000000000000000005978cd29000000000000000000000000000000000000000000000000000000002c9b5e95000000000000000000000000000000000000000000000000000000002c9b5e960000000000000000000000000000000000000000000000000000000044004cc1000000000000000000000000000000000000000000000000000000004571e3a60000000000000000000000000000000000000000000000000000000002eb4b880000000000000000000000000000000000000000000000000000000025692962000000000000000000000000ffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000389a75e10000000000000000000000000000000000000020000000800000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927000000000000000000000000000000000000000000000000000000007448fbae00000000000000000000000000000000000000040000001c000000000000000002000000000000000000000000000000000000200000000c0000000000000000796b89b91644bc98cd93958e4c9038275d622183e25ac5af08cc6b5d955391320200000200000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000006f5e881800000000000000000000000000000000000000000000000000000000ee9853bb02000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000005694da8e000000000000000000000000000000000000002000000000000000000000000002000000000000000000000000000000000000380000000000000000000000001806aa1896bbf26568e884a7374b41e002500962caba6a15023a8d90e8508b8302000002000000000000000000000000000000240000000000000000000000009cc7f708afc65944829bd487b90b72536b1951864fbfc14e125fc972a6507f39020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b12d13eb00000000000000000000000000000000000000000000000000000000313ce56700000000ffffffff000000000000000000000004000000200000000000000000000000000000000000000000000000000000000000000000ffffffffffffffff020000000000000000000000000000000000004000000000000000000000000057726f6e67207061796d656e742e00000000000000000000000000000000000008c379a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064000000000000000000000000188b85a8e846da9f27b5fa2524ac84b84ce8b8da2af5d3f735571112f85aa480000000000000000000000000000000000000000000000000ffffffffffffff5f0000000019457468657265756d205369676e6564204d6573736167653a0a3332020000000000000000000000000000000000003c0000000400000000000000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000080000000000000000000000000496e76616c6964207369676e61747572652e0000000000000000000000000000000000000000000000000000000000000000000000000000000000008baa579f00000000000000000000000000000000a9059cbb00000000000000000000000000000000000000000000000000000000000000440000001000000000000000000000000000000000000000000000000000000000000000000000000090b8ec1802000000000000000000000000000000000000a0000000000000000000000000e7804cc8b53dc839e6771b33c9cadfcc8e85986e3b8dd5058bf3753f92ea36f5457863656564656420616464726573732071756f74612e000000000000000000457863656564656420746f74616c2071756f74612e00000000000000000000004e487b710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000004e6f74206f70656e2e00000000000000000000000000000000000000000000004552433230206e6f74207365742e000000000000000000000000000000000000000000000000000000000000000000000000001fffffffffffffffffffffffe0ffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082b429008be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffff000000000000000000000000addc47d7e02c95c00ec667676636d772a589ffbf0663cfd7cd4dd3d4758201b8000000000000000000000000000000000000000000000000000000008255014300000000000000000000000000000000000000000000000000000000d954416afa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c920000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000ffffffffffffff7f000000000000000000000000000000000000000000000000000000000dc149f00200000000000000000000000000000000000000000000a000000000000000009f6dc27901fd3c0399e319e16bba7e24d8bb2b077fe896daffd2108aa65c40cc0000000000000000000000000000000000000000000000000000000099152ccafffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd5d00dbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d0000000000000000000000000000000000000100000001800000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe000000000000000000000000000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000fffffffffffffffffffffffffffffffe00000000000000000000000000000000000000000000000000000000ae47f702ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000ce002d6d0be00d733e8ed6722e411a5a3405d816b78ef5c40d7f4ef4aae3039
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.