Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- CWDEscrow
- Optimization enabled
- true
- Compiler version
- v0.8.28+commit.7893614a
- Optimization runs
- 200
- EVM Version
- shanghai
- Verified at
- 2025-10-13T06:58:50.960190Z
contracts/CWDEscrow.sol
// SPDX-License-Identifier: MIT pragma solidity 0.8.28; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import {EIP712Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol"; import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; interface ICWDToken is IERC20 { function burn(uint256 amount) external; } /// @title CWDEscrow - Crypto Wars Dollar Staking Escrow with Progressive Burn Mechanics /// @notice Manages staking of CWD tokens for games with burn-to-earn tokenomics /// @dev Implements UUPS upgradeable pattern with cryptographic proof verification contract CWDEscrow is Initializable, AccessControlUpgradeable, PausableUpgradeable, ReentrancyGuardUpgradeable, UUPSUpgradeable, EIP712Upgradeable { using SafeERC20 for IERC20; bytes32 public constant GAME_MASTER_ROLE = keccak256("GAME_MASTER_ROLE"); bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE"); bytes32 public constant TREASURY_ROLE = keccak256("TREASURY_ROLE"); bytes32 public constant REWARD_MANAGER_ROLE = keccak256("REWARD_MANAGER_ROLE"); bytes32 public constant GAME_SIGNER_ROLE = keccak256("GAME_SIGNER_ROLE"); uint256 public constant MAXIMUM_REWARD_MULTIPLIER = 3; uint256 public constant BURN_REWARD_MULTIPLIER = 3; uint256 public constant DAILY_WITHDRAWAL_LIMIT = 10_000 * 1e18; uint256 public constant GAME_COOLDOWN = 1 hours; uint256 public constant BASIS_POINTS = 10_000; uint256 public constant SETTLEMENT_DEADLINE = 30 minutes; // EIP-712 TypeHash for game result verification bytes32 public constant GAME_RESULT_TYPEHASH = keccak256("GameResult(bytes32 stakeId,address player,uint256 finalMoney,bool won,uint256 deadline)"); enum GameDifficulty { BullMarket, BearMarket, Extreme } enum StakeStatus { None, Active, Won, Lost, Cancelled } struct BurnRate { uint256 burnPercentage; uint256 collateralPercentage; } struct OwnershipTier { uint256 minBalance; uint256 multiplierBps; } struct Stake { address player; uint256 stakedAmount; uint256 burnedAmount; uint256 collateralAmount; uint256 snapshotBalance; uint256 finalMoney; uint256 rewardAmount; uint256 createdAt; uint256 settledAt; GameDifficulty difficulty; StakeStatus status; } struct GameResult { bytes32 stakeId; address player; uint256 finalMoney; bool won; uint256 deadline; } ICWDToken public cwdToken; address public treasury; uint256 public rewardPoolBalance; mapping(bytes32 => Stake) private stakes; mapping(address => bytes32[]) private playerStakes; mapping(address => uint256) public dailyWithdrawals; mapping(address => uint256) public lastWithdrawalReset; mapping(address => uint256) public lastGameTimestamp; mapping(GameDifficulty => BurnRate) public burnRates; mapping(bytes32 => bool) public usedNonces; OwnershipTier[] public ownershipTiers; uint256 public totalStaked; uint256 public totalActiveStakes; uint256 public totalBurned; uint256 public totalRewardsDistributed; event StakeCreated( bytes32 indexed stakeId, address indexed player, uint256 stakedAmount, uint256 burnedAmount, uint256 collateralAmount, GameDifficulty difficulty, uint256 snapshotBalance ); event StakeWon( bytes32 indexed stakeId, address indexed player, uint256 collateralReturned, uint256 finalMoney, uint256 burnReward, uint256 ownershipMultiplier, uint256 totalPayout ); event StakeLost( bytes32 indexed stakeId, address indexed player, uint256 collateralForfeited, uint256 burnedAmount ); event StakeCancelled(bytes32 indexed stakeId, address indexed player, uint256 returnedAmount); event RewardPoolFunded(address indexed funder, uint256 amount, uint256 newBalance); event RewardPoolWithdrawn(address indexed recipient, uint256 amount, uint256 newBalance); event DailyWithdrawalLimitReset(address indexed player, uint256 timestamp); event BurnRateUpdated(GameDifficulty indexed difficulty, uint256 burnPercentage, uint256 collateralPercentage); event OwnershipTiersUpdated(uint256 tierCount); event TreasuryUpdated(address indexed oldTreasury, address indexed newTreasury); /// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); } /// @notice Initializes the CWDEscrow contract with burn mechanics and EIP-712 /// @param defaultAdmin The address that will be granted admin roles /// @param cwdTokenAddress The address of the CWD token contract /// @param treasuryAddress The address of the treasury /// @param gameSigner The address authorized to sign game results function initialize(address defaultAdmin, address cwdTokenAddress, address treasuryAddress, address gameSigner) public initializer { if ( defaultAdmin == address(0) || cwdTokenAddress == address(0) || treasuryAddress == address(0) || gameSigner == address(0) ) { revert InvalidAddress(); } __AccessControl_init(); __Pausable_init(); __ReentrancyGuard_init(); __UUPSUpgradeable_init(); __EIP712_init("CryptoWarsEscrow", "1"); cwdToken = ICWDToken(cwdTokenAddress); treasury = treasuryAddress; _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin); _grantRole(GAME_MASTER_ROLE, defaultAdmin); _grantRole(PAUSER_ROLE, defaultAdmin); _grantRole(UPGRADER_ROLE, defaultAdmin); _grantRole(TREASURY_ROLE, defaultAdmin); _grantRole(REWARD_MANAGER_ROLE, defaultAdmin); _grantRole(GAME_SIGNER_ROLE, gameSigner); _initializeBurnRates(); _initializeOwnershipTiers(); } /// @notice Stakes CWD tokens for a game with progressive burn mechanics /// @param amount The amount of CWD to stake /// @param difficulty The game difficulty level /// @return stakeId The unique identifier for the stake function createStake(uint256 amount, GameDifficulty difficulty) external whenNotPaused nonReentrant returns (bytes32 stakeId) { if (amount == 0) { revert InvalidAmount(); } BurnRate memory rate = burnRates[difficulty]; if (rate.burnPercentage == 0) { revert InvalidDifficulty(); } uint256 burnAmount = (amount * rate.burnPercentage) / BASIS_POINTS; uint256 collateralAmount = amount - burnAmount; uint256 snapshotBalance = cwdToken.balanceOf(_msgSender()); stakeId = _generateStakeId(_msgSender(), amount, difficulty); if (stakes[stakeId].status != StakeStatus.None) { revert StakeAlreadyExists(); } stakes[stakeId] = Stake({ player: _msgSender(), stakedAmount: amount, burnedAmount: burnAmount, collateralAmount: collateralAmount, snapshotBalance: snapshotBalance, finalMoney: 0, rewardAmount: 0, createdAt: block.timestamp, settledAt: 0, difficulty: difficulty, status: StakeStatus.Active }); playerStakes[_msgSender()].push(stakeId); totalStaked += collateralAmount; totalActiveStakes++; IERC20(address(cwdToken)).safeTransferFrom(_msgSender(), address(this), amount); cwdToken.burn(burnAmount); totalBurned += burnAmount; emit StakeCreated(stakeId, _msgSender(), amount, burnAmount, collateralAmount, difficulty, snapshotBalance); } /// @notice Settles a winning stake with proof from game server (player-callable) /// @param result The game result struct /// @param signature The signature from GAME_SIGNER_ROLE function settleWinWithProof(GameResult calldata result, bytes calldata signature) external whenNotPaused nonReentrant { Stake storage stake = stakes[result.stakeId]; if (stake.status != StakeStatus.Active) { revert InvalidStakeStatus(); } if (stake.player != msg.sender) { revert UnauthorizedSettlement(); } if (!result.won) { revert InvalidGameResult(); } if (block.timestamp > result.deadline) { revert SignatureExpired(); } bytes32 nonce = keccak256(abi.encodePacked(result.stakeId, result.deadline)); if (usedNonces[nonce]) { revert NonceAlreadyUsed(); } bytes32 structHash = keccak256( abi.encode( GAME_RESULT_TYPEHASH, result.stakeId, result.player, result.finalMoney, result.won, result.deadline ) ); bytes32 digest = _hashTypedDataV4(structHash); address signer = ECDSA.recover(digest, signature); if (!hasRole(GAME_SIGNER_ROLE, signer)) { revert InvalidSignature(); } usedNonces[nonce] = true; _processWinSettlement(stake, result.stakeId, result.finalMoney); } /// @notice Settles a losing stake with proof from game server (player-callable) /// @param result The game result struct /// @param signature The signature from GAME_SIGNER_ROLE function settleLossWithProof(GameResult calldata result, bytes calldata signature) external whenNotPaused nonReentrant { Stake storage stake = stakes[result.stakeId]; if (stake.status != StakeStatus.Active) { revert InvalidStakeStatus(); } if (stake.player != msg.sender) { revert UnauthorizedSettlement(); } if (result.won) { revert InvalidGameResult(); } if (block.timestamp > result.deadline) { revert SignatureExpired(); } bytes32 nonce = keccak256(abi.encodePacked(result.stakeId, result.deadline)); if (usedNonces[nonce]) { revert NonceAlreadyUsed(); } bytes32 structHash = keccak256( abi.encode( GAME_RESULT_TYPEHASH, result.stakeId, result.player, result.finalMoney, result.won, result.deadline ) ); bytes32 digest = _hashTypedDataV4(structHash); address signer = ECDSA.recover(digest, signature); if (!hasRole(GAME_SIGNER_ROLE, signer)) { revert InvalidSignature(); } usedNonces[nonce] = true; _processLossSettlement(stake, result.stakeId); } /// @notice Internal function to process win settlement /// @param stake The stake storage reference /// @param stakeId The stake identifier /// @param finalMoney The final in-game money earned function _processWinSettlement(Stake storage stake, bytes32 stakeId, uint256 finalMoney) private { uint256 burnReward = stake.burnedAmount * BURN_REWARD_MULTIPLIER; uint256 ownershipMultiplier = _getOwnershipMultiplier(stake.snapshotBalance); uint256 multipliedReward = (burnReward * ownershipMultiplier) / BASIS_POINTS; uint256 guaranteedReturn = stake.collateralAmount + finalMoney; if (guaranteedReturn + multipliedReward > rewardPoolBalance) { revert InsufficientRewardPool(); } _checkAndResetDailyLimit(stake.player); uint256 availableLimit = DAILY_WITHDRAWAL_LIMIT > dailyWithdrawals[stake.player] ? DAILY_WITHDRAWAL_LIMIT - dailyWithdrawals[stake.player] : 0; uint256 cappedBonusReward = multipliedReward > availableLimit ? availableLimit : multipliedReward; uint256 totalPayout = guaranteedReturn + cappedBonusReward; stake.finalMoney = finalMoney; stake.rewardAmount = cappedBonusReward; stake.settledAt = block.timestamp; stake.status = StakeStatus.Won; totalStaked -= stake.collateralAmount; totalActiveStakes--; rewardPoolBalance -= (finalMoney + cappedBonusReward); totalRewardsDistributed += cappedBonusReward; dailyWithdrawals[stake.player] += cappedBonusReward; IERC20(address(cwdToken)).safeTransfer(stake.player, totalPayout); emit StakeWon( stakeId, stake.player, stake.collateralAmount, finalMoney, cappedBonusReward, ownershipMultiplier, totalPayout ); } /// @notice Internal function to process loss settlement /// @param stake The stake storage reference /// @param stakeId The stake identifier function _processLossSettlement(Stake storage stake, bytes32 stakeId) private { stake.settledAt = block.timestamp; stake.status = StakeStatus.Lost; totalStaked -= stake.collateralAmount; totalActiveStakes--; rewardPoolBalance += stake.collateralAmount; emit StakeLost(stakeId, stake.player, stake.collateralAmount, stake.burnedAmount); } /// @notice Emergency settlement by GAME_MASTER (admin only) /// @param stakeId The unique identifier for the stake /// @param finalMoney The final in-game money function adminSettleWin(bytes32 stakeId, uint256 finalMoney) external onlyRole(GAME_MASTER_ROLE) whenNotPaused nonReentrant { Stake storage stake = stakes[stakeId]; if (stake.status != StakeStatus.Active) { revert InvalidStakeStatus(); } _processWinSettlement(stake, stakeId, finalMoney); } /// @notice Emergency loss settlement by GAME_MASTER (admin only) /// @param stakeId The unique identifier for the stake function adminSettleLoss(bytes32 stakeId) external onlyRole(GAME_MASTER_ROLE) whenNotPaused nonReentrant { Stake storage stake = stakes[stakeId]; if (stake.status != StakeStatus.Active) { revert InvalidStakeStatus(); } _processLossSettlement(stake, stakeId); } /// @notice Cancels an active stake and returns collateral /// @dev Only callable by GAME_MASTER_ROLE for dispute resolution /// @param stakeId The unique identifier for the stake function cancelStake(bytes32 stakeId) external onlyRole(GAME_MASTER_ROLE) whenNotPaused nonReentrant { Stake storage stake = stakes[stakeId]; if (stake.status != StakeStatus.Active) { revert InvalidStakeStatus(); } uint256 returnedAmount = stake.collateralAmount; stake.status = StakeStatus.Cancelled; stake.settledAt = block.timestamp; totalStaked -= returnedAmount; totalActiveStakes--; IERC20(address(cwdToken)).safeTransfer(stake.player, returnedAmount); emit StakeCancelled(stakeId, stake.player, returnedAmount); } /// @notice Funds the reward pool with CWD tokens /// @param amount The amount of CWD to add to the reward pool function fundRewardPool(uint256 amount) external onlyRole(REWARD_MANAGER_ROLE) nonReentrant { if (amount == 0) { revert InvalidAmount(); } rewardPoolBalance += amount; IERC20(address(cwdToken)).safeTransferFrom(_msgSender(), address(this), amount); emit RewardPoolFunded(_msgSender(), amount, rewardPoolBalance); } /// @notice Withdraws excess funds from the reward pool /// @param amount The amount to withdraw /// @param recipient The address to receive the funds function withdrawFromRewardPool(uint256 amount, address recipient) external onlyRole(REWARD_MANAGER_ROLE) nonReentrant { if (amount == 0) { revert InvalidAmount(); } if (recipient == address(0)) { revert InvalidAddress(); } if (amount > rewardPoolBalance) { revert InsufficientRewardPool(); } rewardPoolBalance -= amount; IERC20(address(cwdToken)).safeTransfer(recipient, amount); emit RewardPoolWithdrawn(recipient, amount, rewardPoolBalance); } /// @notice Updates burn rates for a specific difficulty /// @param difficulty The game difficulty /// @param burnPercentage The percentage to burn (in basis points) /// @param collateralPercentage The percentage to keep as collateral (in basis points) function updateBurnRate(GameDifficulty difficulty, uint256 burnPercentage, uint256 collateralPercentage) external onlyRole(DEFAULT_ADMIN_ROLE) { if (burnPercentage + collateralPercentage != BASIS_POINTS) { revert InvalidBurnRate(); } burnRates[difficulty] = BurnRate({burnPercentage: burnPercentage, collateralPercentage: collateralPercentage}); emit BurnRateUpdated(difficulty, burnPercentage, collateralPercentage); } /// @notice Updates ownership tiers for reward multipliers /// @param tiers Array of ownership tiers function updateOwnershipTiers(OwnershipTier[] calldata tiers) external onlyRole(DEFAULT_ADMIN_ROLE) { if (tiers.length == 0) { revert InvalidTiers(); } delete ownershipTiers; for (uint256 i = 0; i < tiers.length; i++) { if (i > 0 && tiers[i].minBalance <= tiers[i - 1].minBalance) { revert InvalidTiers(); } ownershipTiers.push(tiers[i]); } emit OwnershipTiersUpdated(tiers.length); } /// @notice Updates the treasury address /// @param newTreasury The new treasury address function setTreasury(address newTreasury) external onlyRole(TREASURY_ROLE) { if (newTreasury == address(0)) { revert InvalidAddress(); } address oldTreasury = treasury; treasury = newTreasury; emit TreasuryUpdated(oldTreasury, newTreasury); } /// @notice Pauses all escrow operations function pause() external onlyRole(PAUSER_ROLE) { _pause(); } /// @notice Unpauses all escrow operations function unpause() external onlyRole(PAUSER_ROLE) { _unpause(); } /// @notice Retrieves stake information /// @param stakeId The unique identifier for the stake /// @return stake The stake struct containing all details function getStake(bytes32 stakeId) external view returns (Stake memory stake) { stake = stakes[stakeId]; if (stake.status == StakeStatus.None) { revert StakeNotFound(); } } /// @notice Attempts to retrieve stake information without reverting /// @param stakeId The unique identifier for the stake /// @return exists True if the stake exists /// @return stake The stake struct containing all details function tryGetStake(bytes32 stakeId) external view returns (bool exists, Stake memory stake) { stake = stakes[stakeId]; exists = stake.status != StakeStatus.None; } /// @notice Retrieves all stake IDs for a player /// @param player The player's address /// @return stakeIds Array of stake IDs function getPlayerStakes(address player) external view returns (bytes32[] memory stakeIds) { return playerStakes[player]; } /// @notice Retrieves only active stake IDs for a player /// @param player The player's address /// @return activeStakeIds Array of active stake IDs function getActivePlayerStakes(address player) external view returns (bytes32[] memory activeStakeIds) { bytes32[] memory allStakes = playerStakes[player]; uint256 activeCount = 0; for (uint256 i = 0; i < allStakes.length; i++) { if (stakes[allStakes[i]].status == StakeStatus.Active) { activeCount++; } } activeStakeIds = new bytes32[](activeCount); uint256 currentIndex = 0; for (uint256 i = 0; i < allStakes.length; i++) { if (stakes[allStakes[i]].status == StakeStatus.Active) { activeStakeIds[currentIndex] = allStakes[i]; currentIndex++; } } } /// @notice Retrieves stake IDs for a player filtered by status /// @param player The player's address /// @param status The status to filter by /// @return filteredStakeIds Array of stake IDs matching the status function getPlayerStakesByStatus(address player, StakeStatus status) external view returns (bytes32[] memory filteredStakeIds) { bytes32[] memory allStakes = playerStakes[player]; uint256 matchingCount = 0; for (uint256 i = 0; i < allStakes.length; i++) { if (stakes[allStakes[i]].status == status) { matchingCount++; } } filteredStakeIds = new bytes32[](matchingCount); uint256 currentIndex = 0; for (uint256 i = 0; i < allStakes.length; i++) { if (stakes[allStakes[i]].status == status) { filteredStakeIds[currentIndex] = allStakes[i]; currentIndex++; } } } /// @notice Retrieves detailed stake information for all player stakes /// @dev This function safely handles invalid stake IDs by skipping them /// @param player The player's address /// @return validStakes Array of valid stake structs /// @return validStakeIds Array of corresponding stake IDs function getPlayerStakesDetailed(address player) external view returns (Stake[] memory validStakes, bytes32[] memory validStakeIds) { bytes32[] memory allStakeIds = playerStakes[player]; uint256 validCount = 0; for (uint256 i = 0; i < allStakeIds.length; i++) { if (stakes[allStakeIds[i]].status != StakeStatus.None) { validCount++; } } validStakes = new Stake[](validCount); validStakeIds = new bytes32[](validCount); uint256 currentIndex = 0; for (uint256 i = 0; i < allStakeIds.length; i++) { Stake memory stake = stakes[allStakeIds[i]]; if (stake.status != StakeStatus.None) { validStakes[currentIndex] = stake; validStakeIds[currentIndex] = allStakeIds[i]; currentIndex++; } } } /// @notice Checks if a stake exists and is active /// @param stakeId The unique identifier for the stake /// @return isActive True if the stake is active function isStakeActive(bytes32 stakeId) external view returns (bool isActive) { return stakes[stakeId].status == StakeStatus.Active; } /// @notice Gets the ownership multiplier for a given balance /// @param balance The wallet balance to check /// @return multiplierBps The multiplier in basis points function getOwnershipMultiplier(uint256 balance) external view returns (uint256 multiplierBps) { return _getOwnershipMultiplier(balance); } /// @notice Gets the current daily withdrawal amount for a player /// @param player The player's address /// @return withdrawn The amount withdrawn today /// @return limit The daily limit /// @return remaining The remaining withdrawal capacity function getDailyWithdrawalStatus(address player) external view returns (uint256 withdrawn, uint256 limit, uint256 remaining) { _checkIfNeedReset(player); withdrawn = dailyWithdrawals[player]; limit = DAILY_WITHDRAWAL_LIMIT; remaining = limit > withdrawn ? limit - withdrawn : 0; } /// @notice Gets all ownership tiers /// @return tiers Array of ownership tiers function getOwnershipTiers() external view returns (OwnershipTier[] memory tiers) { return ownershipTiers; } /// @notice Calculates potential rewards for a stake amount and difficulty /// @param amount The stake amount /// @param difficulty The game difficulty /// @param playerBalance The player's current balance for tier calculation /// @param finalMoney The expected final in-game money /// @return burnAmount The amount that will be burned /// @return collateralAmount The amount held as collateral /// @return guaranteedReturn Guaranteed return (collateral + finalMoney) /// @return bonusReward The burn bonus reward before daily limit cap /// @return cappedBonusReward The bonus reward after applying current daily limit function calculatePotentialRewards( uint256 amount, GameDifficulty difficulty, uint256 playerBalance, uint256 finalMoney ) external view returns ( uint256 burnAmount, uint256 collateralAmount, uint256 guaranteedReturn, uint256 bonusReward, uint256 cappedBonusReward ) { BurnRate memory rate = burnRates[difficulty]; burnAmount = (amount * rate.burnPercentage) / BASIS_POINTS; collateralAmount = amount - burnAmount; uint256 burnReward = burnAmount * BURN_REWARD_MULTIPLIER; uint256 ownershipMultiplier = _getOwnershipMultiplier(playerBalance); bonusReward = (burnReward * ownershipMultiplier) / BASIS_POINTS; guaranteedReturn = collateralAmount + finalMoney; uint256 withdrawn = dailyWithdrawals[msg.sender]; uint256 availableLimit = DAILY_WITHDRAWAL_LIMIT > withdrawn ? DAILY_WITHDRAWAL_LIMIT - withdrawn : 0; cappedBonusReward = bonusReward > availableLimit ? availableLimit : bonusReward; } /// @notice Initializes default burn rates function _initializeBurnRates() private { burnRates[GameDifficulty.BullMarket] = BurnRate({burnPercentage: 1000, collateralPercentage: 9000}); burnRates[GameDifficulty.BearMarket] = BurnRate({burnPercentage: 2500, collateralPercentage: 7500}); burnRates[GameDifficulty.Extreme] = BurnRate({burnPercentage: 5000, collateralPercentage: 5000}); } /// @notice Initializes default ownership tiers function _initializeOwnershipTiers() private { ownershipTiers.push(OwnershipTier({minBalance: 0, multiplierBps: 10000})); ownershipTiers.push(OwnershipTier({minBalance: 1001 * 1e18, multiplierBps: 12000})); ownershipTiers.push(OwnershipTier({minBalance: 5001 * 1e18, multiplierBps: 15000})); ownershipTiers.push(OwnershipTier({minBalance: 10001 * 1e18, multiplierBps: 20000})); ownershipTiers.push(OwnershipTier({minBalance: 50001 * 1e18, multiplierBps: 25000})); } /// @notice Gets the ownership multiplier for a balance /// @param balance The balance to check /// @return multiplierBps The multiplier in basis points function _getOwnershipMultiplier(uint256 balance) private view returns (uint256 multiplierBps) { multiplierBps = ownershipTiers[0].multiplierBps; for (uint256 i = ownershipTiers.length; i > 0; i--) { if (balance >= ownershipTiers[i - 1].minBalance) { multiplierBps = ownershipTiers[i - 1].multiplierBps; break; } } } /// @notice Checks if daily withdrawal limit needs to be reset /// @param player The player's address function _checkIfNeedReset(address player) private view { if (block.timestamp >= lastWithdrawalReset[player] + 1 days) { return; } } /// @notice Checks and resets daily withdrawal limit if needed /// @param player The player's address function _checkAndResetDailyLimit(address player) private { if (block.timestamp >= lastWithdrawalReset[player] + 1 days) { dailyWithdrawals[player] = 0; lastWithdrawalReset[player] = block.timestamp; emit DailyWithdrawalLimitReset(player, block.timestamp); } } /// @notice Generates a unique stake ID /// @param player The player's address /// @param amount The staked amount /// @param difficulty The game difficulty /// @return stakeId The generated stake ID function _generateStakeId(address player, uint256 amount, GameDifficulty difficulty) private view returns (bytes32 stakeId) { stakeId = keccak256(abi.encodePacked(player, amount, difficulty, block.timestamp, block.number)); } /// @notice Authorizes contract upgrades /// @param newImplementation The address of the new implementation contract function _authorizeUpgrade(address newImplementation) internal view override onlyRole(UPGRADER_ROLE) { if (newImplementation == address(0)) { revert InvalidAddress(); } } error InvalidAddress(); error InvalidAmount(); error InvalidStakeStatus(); error StakeNotFound(); error StakeAlreadyExists(); error InvalidDifficulty(); error InvalidBurnRate(); error InvalidTiers(); error InsufficientRewardPool(); error DailyWithdrawalLimitExceeded(); error GameCooldownActive(); error InvalidSignature(); error SignatureExpired(); error NonceAlreadyUsed(); error UnauthorizedSettlement(); error InvalidGameResult(); }
lib/openzeppelin-contracts/contracts/interfaces/IERC5267.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol) pragma solidity ^0.8.20; interface IERC5267 { /** * @dev MAY be emitted to signal that the domain could have changed. */ event EIP712DomainChanged(); /** * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712 * signature. */ function eip712Domain() external view returns ( bytes1 fields, string memory name, string memory version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] memory extensions ); }
lib/openzeppelin-contracts-upgradeable/contracts/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol) pragma solidity ^0.8.20; import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol"; import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol"; import {ERC165Upgradeable} from "../utils/introspection/ERC165Upgradeable.sol"; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ```solidity * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ```solidity * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules} * to enforce additional security measures for this role. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControl, ERC165Upgradeable { struct RoleData { mapping(address account => bool) hasRole; bytes32 adminRole; } bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /// @custom:storage-location erc7201:openzeppelin.storage.AccessControl struct AccessControlStorage { mapping(bytes32 role => RoleData) _roles; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800; function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) { assembly { $.slot := AccessControlStorageLocation } } /** * @dev Modifier that checks that an account has a specific role. Reverts * with an {AccessControlUnauthorizedAccount} error including the required role. */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } function __AccessControl_init() internal onlyInitializing { } function __AccessControl_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual returns (bool) { AccessControlStorage storage $ = _getAccessControlStorage(); return $._roles[role].hasRole[account]; } /** * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()` * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier. */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account` * is missing `role`. */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert AccessControlUnauthorizedAccount(account, role); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) { AccessControlStorage storage $ = _getAccessControlStorage(); return $._roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `callerConfirmation`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address callerConfirmation) public virtual { if (callerConfirmation != _msgSender()) { revert AccessControlBadConfirmation(); } _revokeRole(role, callerConfirmation); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { AccessControlStorage storage $ = _getAccessControlStorage(); bytes32 previousAdminRole = getRoleAdmin(role); $._roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual returns (bool) { AccessControlStorage storage $ = _getAccessControlStorage(); if (!hasRole(role, account)) { $._roles[role].hasRole[account] = true; emit RoleGranted(role, account, _msgSender()); return true; } else { return false; } } /** * @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual returns (bool) { AccessControlStorage storage $ = _getAccessControlStorage(); if (hasRole(role, account)) { $._roles[role].hasRole[account] = false; emit RoleRevoked(role, account, _msgSender()); return true; } else { return false; } } }
lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.20; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Storage of the initializable contract. * * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions * when using with upgradeable contracts. * * @custom:storage-location erc7201:openzeppelin.storage.Initializable */ struct InitializableStorage { /** * @dev Indicates that the contract has been initialized. */ uint64 _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool _initializing; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00; /** * @dev The contract is already initialized. */ error InvalidInitialization(); /** * @dev The contract is not initializing. */ error NotInitializing(); /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint64 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in * production. * * Emits an {Initialized} event. */ modifier initializer() { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); // Cache values to avoid duplicated sloads bool isTopLevelCall = !$._initializing; uint64 initialized = $._initialized; // Allowed calls: // - initialSetup: the contract is not in the initializing state and no previous version was // initialized // - construction: the contract is initialized at version 1 (no reininitialization) and the // current contract is just being deployed bool initialSetup = initialized == 0 && isTopLevelCall; bool construction = initialized == 1 && address(this).code.length == 0; if (!initialSetup && !construction) { revert InvalidInitialization(); } $._initialized = 1; if (isTopLevelCall) { $._initializing = true; } _; if (isTopLevelCall) { $._initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint64 version) { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing || $._initialized >= version) { revert InvalidInitialization(); } $._initialized = version; $._initializing = true; _; $._initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { _checkInitializing(); _; } /** * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}. */ function _checkInitializing() internal view virtual { if (!_isInitializing()) { revert NotInitializing(); } } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing) { revert InvalidInitialization(); } if ($._initialized != type(uint64).max) { $._initialized = type(uint64).max; emit Initialized(type(uint64).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint64) { return _getInitializableStorage()._initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _getInitializableStorage()._initializing; } /** * @dev Returns a pointer to the storage namespace. */ // solhint-disable-next-line var-name-mixedcase function _getInitializableStorage() private pure returns (InitializableStorage storage $) { assembly { $.slot := INITIALIZABLE_STORAGE } } }
lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.20; import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol"; import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; import {Initializable} from "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. */ abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable { /// @custom:oz-upgrades-unsafe-allow state-variable-immutable address private immutable __self = address(this); /** * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)` * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called, * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string. * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function * during an upgrade. */ string public constant UPGRADE_INTERFACE_VERSION = "5.0.0"; /** * @dev The call is from an unauthorized context. */ error UUPSUnauthorizedCallContext(); /** * @dev The storage `slot` is unsupported as a UUID. */ error UUPSUnsupportedProxiableUUID(bytes32 slot); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { _checkProxy(); _; } /** * @dev Check that the execution is not being performed through a delegate call. This allows a function to be * callable on the implementing contract but not through proxies. */ modifier notDelegated() { _checkNotDelegated(); _; } function __UUPSUpgradeable_init() internal onlyInitializing { } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /** * @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the * implementation. It is used to validate the implementation's compatibility when performing an upgrade. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier. */ function proxiableUUID() external view virtual notDelegated returns (bytes32) { return ERC1967Utils.IMPLEMENTATION_SLOT; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. * * @custom:oz-upgrades-unsafe-allow-reachable delegatecall */ function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallUUPS(newImplementation, data); } /** * @dev Reverts if the execution is not performed via delegatecall or the execution * context is not of a proxy with an ERC-1967 compliant implementation pointing to self. * See {_onlyProxy}. */ function _checkProxy() internal view virtual { if ( address(this) == __self || // Must be called through delegatecall ERC1967Utils.getImplementation() != __self // Must be called through an active proxy ) { revert UUPSUnauthorizedCallContext(); } } /** * @dev Reverts if the execution is performed via delegatecall. * See {notDelegated}. */ function _checkNotDelegated() internal view virtual { if (address(this) != __self) { // Must not be called through delegatecall revert UUPSUnauthorizedCallContext(); } } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; /** * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call. * * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value * is expected to be the implementation slot in ERC-1967. * * Emits an {IERC1967-Upgraded} event. */ function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private { try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) { if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) { revert UUPSUnsupportedProxiableUUID(slot); } ERC1967Utils.upgradeToAndCall(newImplementation, data); } catch { // The implementation is not UUPS revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation); } } }
lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
lib/openzeppelin-contracts-upgradeable/contracts/utils/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol) pragma solidity ^0.8.20; import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol"; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract PausableUpgradeable is Initializable, ContextUpgradeable { /// @custom:storage-location erc7201:openzeppelin.storage.Pausable struct PausableStorage { bool _paused; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300; function _getPausableStorage() private pure returns (PausableStorage storage $) { assembly { $.slot := PausableStorageLocation } } /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); /** * @dev The operation failed because the contract is paused. */ error EnforcedPause(); /** * @dev The operation failed because the contract is not paused. */ error ExpectedPause(); /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal onlyInitializing { __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { PausableStorage storage $ = _getPausableStorage(); $._paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { PausableStorage storage $ = _getPausableStorage(); return $._paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { if (paused()) { revert EnforcedPause(); } } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { if (!paused()) { revert ExpectedPause(); } } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { PausableStorage storage $ = _getPausableStorage(); $._paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { PausableStorage storage $ = _getPausableStorage(); $._paused = false; emit Unpaused(_msgSender()); } }
lib/openzeppelin-contracts-upgradeable/contracts/utils/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol) pragma solidity ^0.8.20; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at, * consider using {ReentrancyGuardTransient} instead. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuardUpgradeable is Initializable { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant NOT_ENTERED = 1; uint256 private constant ENTERED = 2; /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard struct ReentrancyGuardStorage { uint256 _status; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00; function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) { assembly { $.slot := ReentrancyGuardStorageLocation } } /** * @dev Unauthorized reentrant call. */ error ReentrancyGuardReentrantCall(); function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); $._status = NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); // On the first call to nonReentrant, _status will be NOT_ENTERED if ($._status == ENTERED) { revert ReentrancyGuardReentrantCall(); } // Any calls to nonReentrant after this point will fail $._status = ENTERED; } function _nonReentrantAfter() private { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) $._status = NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage(); return $._status == ENTERED; } }
lib/openzeppelin-contracts-upgradeable/contracts/utils/cryptography/EIP712Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/EIP712.sol) pragma solidity ^0.8.20; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; import {IERC5267} from "@openzeppelin/contracts/interfaces/IERC5267.sol"; import {Initializable} from "../../proxy/utils/Initializable.sol"; /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data. * * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`. * * This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA * ({_hashTypedDataV4}). * * The implementation of the domain separator was designed to be as efficient as possible while still properly updating * the chain id to protect against replay attacks on an eventual fork of the chain. * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. * * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the * separator from the immutable values, which is cheaper than accessing a cached version in cold storage. */ abstract contract EIP712Upgradeable is Initializable, IERC5267 { bytes32 private constant TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); /// @custom:storage-location erc7201:openzeppelin.storage.EIP712 struct EIP712Storage { /// @custom:oz-renamed-from _HASHED_NAME bytes32 _hashedName; /// @custom:oz-renamed-from _HASHED_VERSION bytes32 _hashedVersion; string _name; string _version; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.EIP712")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant EIP712StorageLocation = 0xa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d100; function _getEIP712Storage() private pure returns (EIP712Storage storage $) { assembly { $.slot := EIP712StorageLocation } } /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ function __EIP712_init(string memory name, string memory version) internal onlyInitializing { __EIP712_init_unchained(name, version); } function __EIP712_init_unchained(string memory name, string memory version) internal onlyInitializing { EIP712Storage storage $ = _getEIP712Storage(); $._name = name; $._version = version; // Reset prior values in storage if upgrading $._hashedName = 0; $._hashedVersion = 0; } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view returns (bytes32) { return _buildDomainSeparator(); } function _buildDomainSeparator() private view returns (bytes32) { return keccak256(abi.encode(TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash(), block.chainid, address(this))); } /** * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this * function returns the hash of the fully encoded EIP712 message for this domain. * * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: * * ```solidity * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( * keccak256("Mail(address to,string contents)"), * mailTo, * keccak256(bytes(mailContents)) * ))); * address signer = ECDSA.recover(digest, signature); * ``` */ function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) { return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash); } /** * @dev See {IERC-5267}. */ function eip712Domain() public view virtual returns ( bytes1 fields, string memory name, string memory version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] memory extensions ) { EIP712Storage storage $ = _getEIP712Storage(); // If the hashed name and version in storage are non-zero, the contract hasn't been properly initialized // and the EIP712 domain is not reliable, as it will be missing name and version. require($._hashedName == 0 && $._hashedVersion == 0, "EIP712: Uninitialized"); return ( hex"0f", // 01111 _EIP712Name(), _EIP712Version(), block.chainid, address(this), bytes32(0), new uint256[](0) ); } /** * @dev The name parameter for the EIP712 domain. * * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ function _EIP712Name() internal view virtual returns (string memory) { EIP712Storage storage $ = _getEIP712Storage(); return $._name; } /** * @dev The version parameter for the EIP712 domain. * * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ function _EIP712Version() internal view virtual returns (string memory) { EIP712Storage storage $ = _getEIP712Storage(); return $._version; } /** * @dev The hash of the name parameter for the EIP712 domain. * * NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Name` instead. */ function _EIP712NameHash() internal view returns (bytes32) { EIP712Storage storage $ = _getEIP712Storage(); string memory name = _EIP712Name(); if (bytes(name).length > 0) { return keccak256(bytes(name)); } else { // If the name is empty, the contract may have been upgraded without initializing the new storage. // We return the name hash in storage if non-zero, otherwise we assume the name is empty by design. bytes32 hashedName = $._hashedName; if (hashedName != 0) { return hashedName; } else { return keccak256(""); } } } /** * @dev The hash of the version parameter for the EIP712 domain. * * NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Version` instead. */ function _EIP712VersionHash() internal view returns (bytes32) { EIP712Storage storage $ = _getEIP712Storage(); string memory version = _EIP712Version(); if (bytes(version).length > 0) { return keccak256(bytes(version)); } else { // If the version is empty, the contract may have been upgraded without initializing the new storage. // We return the version hash in storage if non-zero, otherwise we assume the version is empty by design. bytes32 hashedVersion = $._hashedVersion; if (hashedVersion != 0) { return hashedVersion; } else { return keccak256(""); } } } }
lib/openzeppelin-contracts-upgradeable/contracts/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol) pragma solidity ^0.8.20; import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import {Initializable} from "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` */ abstract contract ERC165Upgradeable is Initializable, IERC165 { function __ERC165_init() internal onlyInitializing { } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
lib/openzeppelin-contracts/contracts/access/IAccessControl.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (access/IAccessControl.sol) pragma solidity ^0.8.20; /** * @dev External interface of AccessControl declared to support ERC-165 detection. */ interface IAccessControl { /** * @dev The `account` is missing a role. */ error AccessControlUnauthorizedAccount(address account, bytes32 neededRole); /** * @dev The caller of a function is not the expected one. * * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}. */ error AccessControlBadConfirmation(); /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call. This account bears the admin role (for the granted role). * Expected in cases where the role was granted using the internal {AccessControl-_grantRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `callerConfirmation`. */ function renounceRole(bytes32 role, address callerConfirmation) external; }
lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol) pragma solidity ^0.8.20; import {IERC20} from "./IERC20.sol"; import {IERC165} from "./IERC165.sol"; /** * @title IERC1363 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363]. * * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction. */ interface IERC1363 is IERC20, IERC165 { /* * Note: the ERC-165 identifier for this interface is 0xb0202a11. * 0xb0202a11 === * bytes4(keccak256('transferAndCall(address,uint256)')) ^ * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^ * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^ * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^ * bytes4(keccak256('approveAndCall(address,uint256)')) ^ * bytes4(keccak256('approveAndCall(address,uint256,bytes)')) */ /** * @dev Moves a `value` amount of tokens from the caller's account to `to` * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferAndCall(address to, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from the caller's account to `to` * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @param data Additional data with no specified format, sent in call to `to`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param from The address which you want to send tokens from. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferFromAndCall(address from, address to, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism * and then calls {IERC1363Receiver-onTransferReceived} on `to`. * @param from The address which you want to send tokens from. * @param to The address which you want to transfer to. * @param value The amount of tokens to be transferred. * @param data Additional data with no specified format, sent in call to `to`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`. * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function approveAndCall(address spender, uint256 value) external returns (bool); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`. * @param spender The address which will spend the funds. * @param value The amount of tokens to be spent. * @param data Additional data with no specified format, sent in call to `spender`. * @return A boolean value indicating whether the operation succeeded unless throwing. */ function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool); }
lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol) pragma solidity ^0.8.20; import {IERC165} from "../utils/introspection/IERC165.sol";
lib/openzeppelin-contracts/contracts/interfaces/IERC1967.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1967.sol) pragma solidity ^0.8.20; /** * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC. */ interface IERC1967 { /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Emitted when the beacon is changed. */ event BeaconUpgraded(address indexed beacon); }
lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../token/ERC20/IERC20.sol";
lib/openzeppelin-contracts/contracts/interfaces/draft-IERC1822.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC1822.sol) pragma solidity ^0.8.20; /** * @dev ERC-1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified * proxy whose upgrades are fully controlled by the current implementation. */ interface IERC1822Proxiable { /** * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation * address. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. */ function proxiableUUID() external view returns (bytes32); }
lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (proxy/ERC1967/ERC1967Utils.sol) pragma solidity ^0.8.21; import {IBeacon} from "../beacon/IBeacon.sol"; import {IERC1967} from "../../interfaces/IERC1967.sol"; import {Address} from "../../utils/Address.sol"; import {StorageSlot} from "../../utils/StorageSlot.sol"; /** * @dev This library provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots. */ library ERC1967Utils { /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1. */ // solhint-disable-next-line private-vars-leading-underscore bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev The `implementation` of the proxy is invalid. */ error ERC1967InvalidImplementation(address implementation); /** * @dev The `admin` of the proxy is invalid. */ error ERC1967InvalidAdmin(address admin); /** * @dev The `beacon` of the proxy is invalid. */ error ERC1967InvalidBeacon(address beacon); /** * @dev An upgrade function sees `msg.value > 0` that may be lost. */ error ERC1967NonPayable(); /** * @dev Returns the current implementation address. */ function getImplementation() internal view returns (address) { return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the ERC-1967 implementation slot. */ function _setImplementation(address newImplementation) private { if (newImplementation.code.length == 0) { revert ERC1967InvalidImplementation(newImplementation); } StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Performs implementation upgrade with additional setup call if data is nonempty. * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected * to avoid stuck value in the contract. * * Emits an {IERC1967-Upgraded} event. */ function upgradeToAndCall(address newImplementation, bytes memory data) internal { _setImplementation(newImplementation); emit IERC1967.Upgraded(newImplementation); if (data.length > 0) { Address.functionDelegateCall(newImplementation, data); } else { _checkNonPayable(); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1. */ // solhint-disable-next-line private-vars-leading-underscore bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Returns the current admin. * * TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103` */ function getAdmin() internal view returns (address) { return StorageSlot.getAddressSlot(ADMIN_SLOT).value; } /** * @dev Stores a new address in the ERC-1967 admin slot. */ function _setAdmin(address newAdmin) private { if (newAdmin == address(0)) { revert ERC1967InvalidAdmin(address(0)); } StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {IERC1967-AdminChanged} event. */ function changeAdmin(address newAdmin) internal { emit IERC1967.AdminChanged(getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1. */ // solhint-disable-next-line private-vars-leading-underscore bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Returns the current beacon. */ function getBeacon() internal view returns (address) { return StorageSlot.getAddressSlot(BEACON_SLOT).value; } /** * @dev Stores a new beacon in the ERC-1967 beacon slot. */ function _setBeacon(address newBeacon) private { if (newBeacon.code.length == 0) { revert ERC1967InvalidBeacon(newBeacon); } StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon; address beaconImplementation = IBeacon(newBeacon).implementation(); if (beaconImplementation.code.length == 0) { revert ERC1967InvalidImplementation(beaconImplementation); } } /** * @dev Change the beacon and trigger a setup call if data is nonempty. * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected * to avoid stuck value in the contract. * * Emits an {IERC1967-BeaconUpgraded} event. * * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for * efficiency. */ function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal { _setBeacon(newBeacon); emit IERC1967.BeaconUpgraded(newBeacon); if (data.length > 0) { Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data); } else { _checkNonPayable(); } } /** * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract * if an upgrade doesn't perform an initialization call. */ function _checkNonPayable() private { if (msg.value > 0) { revert ERC1967NonPayable(); } } }
lib/openzeppelin-contracts/contracts/proxy/beacon/IBeacon.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.20; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeacon { /** * @dev Must return an address that can be used as a delegate call target. * * {UpgradeableBeacon} will check that this address is a contract. */ function implementation() external view returns (address); }
lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-20 standard as defined in the ERC. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the value of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the value of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves a `value` amount of tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 value) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the * allowance mechanism. `value` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 value) external returns (bool); }
lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; import {IERC1363} from "../../../interfaces/IERC1363.sol"; import {Address} from "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC-20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { /** * @dev An operation with an ERC-20 token failed. */ error SafeERC20FailedOperation(address token); /** * @dev Indicates a failed `decreaseAllowance` request. */ error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease); /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value))); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value))); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. * * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client" * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); forceApprove(token, spender, oldAllowance + value); } /** * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no * value, non-reverting calls are assumed to be successful. * * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client" * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal { unchecked { uint256 currentAllowance = token.allowance(address(this), spender); if (currentAllowance < requestedDecrease) { revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease); } forceApprove(token, spender, currentAllowance - requestedDecrease); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. * * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being * set here. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value)); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0))); _callOptionalReturn(token, approvalCall); } } /** * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * Reverts if the returned value is other than `true`. */ function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal { if (to.code.length == 0) { safeTransfer(token, to, value); } else if (!token.transferAndCall(to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * Reverts if the returned value is other than `true`. */ function transferFromAndCallRelaxed( IERC1363 token, address from, address to, uint256 value, bytes memory data ) internal { if (to.code.length == 0) { safeTransferFrom(token, from, to, value); } else if (!token.transferFromAndCall(from, to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when * targeting contracts. * * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}. * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall} * once without retrying, and relies on the returned value to be true. * * Reverts if the returned value is other than `true`. */ function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal { if (to.code.length == 0) { forceApprove(token, to, value); } else if (!token.approveAndCall(to, value, data)) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements. */ function _callOptionalReturn(IERC20 token, bytes memory data) private { uint256 returnSize; uint256 returnValue; assembly ("memory-safe") { let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20) // bubble errors if iszero(success) { let ptr := mload(0x40) returndatacopy(ptr, 0, returndatasize()) revert(ptr, returndatasize()) } returnSize := returndatasize() returnValue := mload(0) } if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { bool success; uint256 returnSize; uint256 returnValue; assembly ("memory-safe") { success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20) returnSize := returndatasize() returnValue := mload(0) } return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1); } }
lib/openzeppelin-contracts/contracts/utils/Address.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol) pragma solidity ^0.8.20; import {Errors} from "./Errors.sol"; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev There's no code at `target` (it is not a contract). */ error AddressEmptyCode(address target); /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { if (address(this).balance < amount) { revert Errors.InsufficientBalance(address(this).balance, amount); } (bool success, ) = recipient.call{value: amount}(""); if (!success) { revert Errors.FailedCall(); } } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason or custom error, it is bubbled * up by this function (like regular Solidity function calls). However, if * the call reverted with no returned reason, this function reverts with a * {Errors.FailedCall} error. * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { if (address(this).balance < value) { revert Errors.InsufficientBalance(address(this).balance, value); } (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target * was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case * of an unsuccessful call. */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata ) internal view returns (bytes memory) { if (!success) { _revert(returndata); } else { // only check if target is a contract if the call was successful and the return data is empty // otherwise we already know that it was a contract if (returndata.length == 0 && target.code.length == 0) { revert AddressEmptyCode(target); } return returndata; } } /** * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the * revert reason or with a default {Errors.FailedCall} error. */ function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) { if (!success) { _revert(returndata); } else { return returndata; } } /** * @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}. */ function _revert(bytes memory returndata) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly ("memory-safe") { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert Errors.FailedCall(); } } }
lib/openzeppelin-contracts/contracts/utils/Errors.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol) pragma solidity ^0.8.20; /** * @dev Collection of common custom errors used in multiple contracts * * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library. * It is recommended to avoid relying on the error API for critical functionality. * * _Available since v5.1._ */ library Errors { /** * @dev The ETH balance of the account is not enough to perform the operation. */ error InsufficientBalance(uint256 balance, uint256 needed); /** * @dev A call to an address target failed. The target may have reverted. */ error FailedCall(); /** * @dev The deployment failed. */ error FailedDeployment(); /** * @dev A necessary precompile is missing. */ error MissingPrecompile(address); }
lib/openzeppelin-contracts/contracts/utils/Panic.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol) pragma solidity ^0.8.20; /** * @dev Helper library for emitting standardized panic codes. * * ```solidity * contract Example { * using Panic for uint256; * * // Use any of the declared internal constants * function foo() { Panic.GENERIC.panic(); } * * // Alternatively * function foo() { Panic.panic(Panic.GENERIC); } * } * ``` * * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil]. * * _Available since v5.1._ */ // slither-disable-next-line unused-state library Panic { /// @dev generic / unspecified error uint256 internal constant GENERIC = 0x00; /// @dev used by the assert() builtin uint256 internal constant ASSERT = 0x01; /// @dev arithmetic underflow or overflow uint256 internal constant UNDER_OVERFLOW = 0x11; /// @dev division or modulo by zero uint256 internal constant DIVISION_BY_ZERO = 0x12; /// @dev enum conversion error uint256 internal constant ENUM_CONVERSION_ERROR = 0x21; /// @dev invalid encoding in storage uint256 internal constant STORAGE_ENCODING_ERROR = 0x22; /// @dev empty array pop uint256 internal constant EMPTY_ARRAY_POP = 0x31; /// @dev array out of bounds access uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32; /// @dev resource error (too large allocation or too large array) uint256 internal constant RESOURCE_ERROR = 0x41; /// @dev calling invalid internal function uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51; /// @dev Reverts with a panic code. Recommended to use with /// the internal constants with predefined codes. function panic(uint256 code) internal pure { assembly ("memory-safe") { mstore(0x00, 0x4e487b71) mstore(0x20, code) revert(0x1c, 0x24) } } }
lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol) // This file was procedurally generated from scripts/generate/templates/StorageSlot.js. pragma solidity ^0.8.20; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC-1967 implementation slot: * ```solidity * contract ERC1967 { * // Define the slot. Alternatively, use the SlotDerivation library to derive the slot. * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(newImplementation.code.length > 0); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * TIP: Consider using this library along with {SlotDerivation}. */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } struct Int256Slot { int256 value; } struct StringSlot { string value; } struct BytesSlot { bytes value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns a `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns a `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns a `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns a `Int256Slot` with member `value` located at `slot`. */ function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns a `StringSlot` with member `value` located at `slot`. */ function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns an `StringSlot` representation of the string storage pointer `store`. */ function getStringSlot(string storage store) internal pure returns (StringSlot storage r) { assembly ("memory-safe") { r.slot := store.slot } } /** * @dev Returns a `BytesSlot` with member `value` located at `slot`. */ function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) { assembly ("memory-safe") { r.slot := slot } } /** * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`. */ function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) { assembly ("memory-safe") { r.slot := store.slot } } }
lib/openzeppelin-contracts/contracts/utils/Strings.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/Strings.sol) pragma solidity ^0.8.20; import {Math} from "./math/Math.sol"; import {SignedMath} from "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant HEX_DIGITS = "0123456789abcdef"; uint8 private constant ADDRESS_LENGTH = 20; /** * @dev The `value` string doesn't fit in the specified `length`. */ error StringsInsufficientHexLength(uint256 value, uint256 length); /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; assembly ("memory-safe") { ptr := add(buffer, add(32, length)) } while (true) { ptr--; assembly ("memory-safe") { mstore8(ptr, byte(mod(value, 10), HEX_DIGITS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toStringSigned(int256 value) internal pure returns (string memory) { return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { uint256 localValue = value; bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = HEX_DIGITS[localValue & 0xf]; localValue >>= 4; } if (localValue != 0) { revert StringsInsufficientHexLength(value, length); } return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal * representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH); } /** * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal * representation, according to EIP-55. */ function toChecksumHexString(address addr) internal pure returns (string memory) { bytes memory buffer = bytes(toHexString(addr)); // hash the hex part of buffer (skip length + 2 bytes, length 40) uint256 hashValue; assembly ("memory-safe") { hashValue := shr(96, keccak256(add(buffer, 0x22), 40)) } for (uint256 i = 41; i > 1; --i) { // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f) if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) { // case shift by xoring with 0x20 buffer[i] ^= 0x20; } hashValue >>= 4; } return string(buffer); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b)); } }
lib/openzeppelin-contracts/contracts/utils/cryptography/ECDSA.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.20; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS } /** * @dev The signature derives the `address(0)`. */ error ECDSAInvalidSignature(); /** * @dev The signature has an invalid length. */ error ECDSAInvalidSignatureLength(uint256 length); /** * @dev The signature has an S value that is in the upper half order. */ error ECDSAInvalidSignatureS(bytes32 s); /** * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not * return address(0) without also returning an error description. Errors are documented using an enum (error type) * and a bytes32 providing additional information about the error. * * If no error is returned, then the address can be used for verification purposes. * * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] */ function tryRecover( bytes32 hash, bytes memory signature ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. assembly ("memory-safe") { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length)); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature); _throwError(error, errorArg); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[ERC-2098 short signatures] */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) { unchecked { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); // We do not check for an overflow here since the shift operation results in 0 or 1. uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. */ function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) { (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs); _throwError(error, errorArg); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address recovered, RecoverError err, bytes32 errArg) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS, s); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature, bytes32(0)); } return (signer, RecoverError.NoError, bytes32(0)); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) { (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s); _throwError(error, errorArg); return recovered; } /** * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided. */ function _throwError(RecoverError error, bytes32 errorArg) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert ECDSAInvalidSignature(); } else if (error == RecoverError.InvalidSignatureLength) { revert ECDSAInvalidSignatureLength(uint256(errorArg)); } else if (error == RecoverError.InvalidSignatureS) { revert ECDSAInvalidSignatureS(errorArg); } } }
lib/openzeppelin-contracts/contracts/utils/cryptography/MessageHashUtils.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/MessageHashUtils.sol) pragma solidity ^0.8.20; import {Strings} from "../Strings.sol"; /** * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing. * * The library provides methods for generating a hash of a message that conforms to the * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712] * specifications. */ library MessageHashUtils { /** * @dev Returns the keccak256 digest of an ERC-191 signed data with version * `0x45` (`personal_sign` messages). * * The digest is calculated by prefixing a bytes32 `messageHash` with * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method. * * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with * keccak256, although any bytes32 value can be safely used because the final digest will * be re-hashed. * * See {ECDSA-recover}. */ function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) { assembly ("memory-safe") { mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20) } } /** * @dev Returns the keccak256 digest of an ERC-191 signed data with version * `0x45` (`personal_sign` messages). * * The digest is calculated by prefixing an arbitrary `message` with * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method. * * See {ECDSA-recover}. */ function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) { return keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message)); } /** * @dev Returns the keccak256 digest of an ERC-191 signed data with version * `0x00` (data with intended validator). * * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended * `validator` address. Then hashing the result. * * See {ECDSA-recover}. */ function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) { return keccak256(abi.encodePacked(hex"19_00", validator, data)); } /** * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`). * * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with * `\x19\x01` and hashing the result. It corresponds to the hash signed by the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712. * * See {ECDSA-recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) { assembly ("memory-safe") { let ptr := mload(0x40) mstore(ptr, hex"19_01") mstore(add(ptr, 0x02), domainSeparator) mstore(add(ptr, 0x22), structHash) digest := keccak256(ptr, 0x42) } } }
lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[ERC]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
lib/openzeppelin-contracts/contracts/utils/math/Math.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol) pragma solidity ^0.8.20; import {Panic} from "../Panic.sol"; import {SafeCast} from "./SafeCast.sol"; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Floor, // Toward negative infinity Ceil, // Toward positive infinity Trunc, // Toward zero Expand // Away from zero } /** * @dev Returns the addition of two unsigned integers, with an success flag (no overflow). */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow). */ function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow). */ function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a success flag (no division by zero). */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero). */ function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant. * * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone. * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute * one branch when needed, making this function more expensive. */ function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) { unchecked { // branchless ternary works because: // b ^ (a ^ b) == a // b ^ 0 == b return b ^ ((a ^ b) * SafeCast.toUint(condition)); } } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return ternary(a > b, a, b); } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return ternary(a < b, a, b); } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds towards infinity instead * of rounding towards zero. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { if (b == 0) { // Guarantee the same behavior as in a regular Solidity division. Panic.panic(Panic.DIVISION_BY_ZERO); } // The following calculation ensures accurate ceiling division without overflow. // Since a is non-zero, (a - 1) / b will not overflow. // The largest possible result occurs when (a - 1) / b is type(uint256).max, // but the largest value we can obtain is type(uint256).max - 1, which happens // when a = type(uint256).max and b = 1. unchecked { return SafeCast.toUint(a > 0) * ((a - 1) / b + 1); } } /** * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or * denominator == 0. * * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by * Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2²⁵⁶ + prod0. uint256 prod0 = x * y; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0. if (denominator <= prod1) { Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW)); } /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. // Always >= 1. See https://cs.stackexchange.com/q/138556/92363. uint256 twos = denominator & (0 - denominator); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv ≡ 1 mod 2⁴. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also // works in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2⁸ inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶ inverse *= 2 - denominator * inverse; // inverse mod 2³² inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴ inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸ inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶ // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @dev Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0); } /** * @dev Calculate the modular multiplicative inverse of a number in Z/nZ. * * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0. * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible. * * If the input value is not inversible, 0 is returned. * * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}. */ function invMod(uint256 a, uint256 n) internal pure returns (uint256) { unchecked { if (n == 0) return 0; // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version) // Used to compute integers x and y such that: ax + ny = gcd(a, n). // When the gcd is 1, then the inverse of a modulo n exists and it's x. // ax + ny = 1 // ax = 1 + (-y)n // ax ≡ 1 (mod n) # x is the inverse of a modulo n // If the remainder is 0 the gcd is n right away. uint256 remainder = a % n; uint256 gcd = n; // Therefore the initial coefficients are: // ax + ny = gcd(a, n) = n // 0a + 1n = n int256 x = 0; int256 y = 1; while (remainder != 0) { uint256 quotient = gcd / remainder; (gcd, remainder) = ( // The old remainder is the next gcd to try. remainder, // Compute the next remainder. // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd // where gcd is at most n (capped to type(uint256).max) gcd - remainder * quotient ); (x, y) = ( // Increment the coefficient of a. y, // Decrement the coefficient of n. // Can overflow, but the result is casted to uint256 so that the // next value of y is "wrapped around" to a value between 0 and n - 1. x - y * int256(quotient) ); } if (gcd != 1) return 0; // No inverse exists. return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative. } } /** * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`. * * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that * `a**(p-2)` is the modular multiplicative inverse of a in Fp. * * NOTE: this function does NOT check that `p` is a prime greater than `2`. */ function invModPrime(uint256 a, uint256 p) internal view returns (uint256) { unchecked { return Math.modExp(a, p - 2, p); } } /** * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m) * * Requirements: * - modulus can't be zero * - underlying staticcall to precompile must succeed * * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make * sure the chain you're using it on supports the precompiled contract for modular exponentiation * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, * the underlying function will succeed given the lack of a revert, but the result may be incorrectly * interpreted as 0. */ function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) { (bool success, uint256 result) = tryModExp(b, e, m); if (!success) { Panic.panic(Panic.DIVISION_BY_ZERO); } return result; } /** * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m). * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying * to operate modulo 0 or if the underlying precompile reverted. * * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack * of a revert, but the result may be incorrectly interpreted as 0. */ function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) { if (m == 0) return (false, 0); assembly ("memory-safe") { let ptr := mload(0x40) // | Offset | Content | Content (Hex) | // |-----------|------------|--------------------------------------------------------------------| // | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 | // | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 | // | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 | // | 0x60:0x7f | value of b | 0x<.............................................................b> | // | 0x80:0x9f | value of e | 0x<.............................................................e> | // | 0xa0:0xbf | value of m | 0x<.............................................................m> | mstore(ptr, 0x20) mstore(add(ptr, 0x20), 0x20) mstore(add(ptr, 0x40), 0x20) mstore(add(ptr, 0x60), b) mstore(add(ptr, 0x80), e) mstore(add(ptr, 0xa0), m) // Given the result < m, it's guaranteed to fit in 32 bytes, // so we can use the memory scratch space located at offset 0. success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20) result := mload(0x00) } } /** * @dev Variant of {modExp} that supports inputs of arbitrary length. */ function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) { (bool success, bytes memory result) = tryModExp(b, e, m); if (!success) { Panic.panic(Panic.DIVISION_BY_ZERO); } return result; } /** * @dev Variant of {tryModExp} that supports inputs of arbitrary length. */ function tryModExp( bytes memory b, bytes memory e, bytes memory m ) internal view returns (bool success, bytes memory result) { if (_zeroBytes(m)) return (false, new bytes(0)); uint256 mLen = m.length; // Encode call args in result and move the free memory pointer result = abi.encodePacked(b.length, e.length, mLen, b, e, m); assembly ("memory-safe") { let dataPtr := add(result, 0x20) // Write result on top of args to avoid allocating extra memory. success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen) // Overwrite the length. // result.length > returndatasize() is guaranteed because returndatasize() == m.length mstore(result, mLen) // Set the memory pointer after the returned data. mstore(0x40, add(dataPtr, mLen)) } } /** * @dev Returns whether the provided byte array is zero. */ function _zeroBytes(bytes memory byteArray) private pure returns (bool) { for (uint256 i = 0; i < byteArray.length; ++i) { if (byteArray[i] != 0) { return false; } } return true; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded * towards zero. * * This method is based on Newton's method for computing square roots; the algorithm is restricted to only * using integer operations. */ function sqrt(uint256 a) internal pure returns (uint256) { unchecked { // Take care of easy edge cases when a == 0 or a == 1 if (a <= 1) { return a; } // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between // the current value as `ε_n = | x_n - sqrt(a) |`. // // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is // bigger than any uint256. // // By noticing that // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)` // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar // to the msb function. uint256 aa = a; uint256 xn = 1; if (aa >= (1 << 128)) { aa >>= 128; xn <<= 64; } if (aa >= (1 << 64)) { aa >>= 64; xn <<= 32; } if (aa >= (1 << 32)) { aa >>= 32; xn <<= 16; } if (aa >= (1 << 16)) { aa >>= 16; xn <<= 8; } if (aa >= (1 << 8)) { aa >>= 8; xn <<= 4; } if (aa >= (1 << 4)) { aa >>= 4; xn <<= 2; } if (aa >= (1 << 2)) { xn <<= 1; } // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1). // // We can refine our estimation by noticing that the middle of that interval minimizes the error. // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2). // This is going to be our x_0 (and ε_0) xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2) // From here, Newton's method give us: // x_{n+1} = (x_n + a / x_n) / 2 // // One should note that: // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a // = ((x_n² + a) / (2 * x_n))² - a // = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a // = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²) // = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²) // = (x_n² - a)² / (2 * x_n)² // = ((x_n² - a) / (2 * x_n))² // ≥ 0 // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n // // This gives us the proof of quadratic convergence of the sequence: // ε_{n+1} = | x_{n+1} - sqrt(a) | // = | (x_n + a / x_n) / 2 - sqrt(a) | // = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) | // = | (x_n - sqrt(a))² / (2 * x_n) | // = | ε_n² / (2 * x_n) | // = ε_n² / | (2 * x_n) | // // For the first iteration, we have a special case where x_0 is known: // ε_1 = ε_0² / | (2 * x_0) | // ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2))) // ≤ 2**(2*e-4) / (3 * 2**(e-1)) // ≤ 2**(e-3) / 3 // ≤ 2**(e-3-log2(3)) // ≤ 2**(e-4.5) // // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n: // ε_{n+1} = ε_n² / | (2 * x_n) | // ≤ (2**(e-k))² / (2 * 2**(e-1)) // ≤ 2**(2*e-2*k) / 2**e // ≤ 2**(e-2*k) xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5 xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9 xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18 xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36 xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72 // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either // sqrt(a) or sqrt(a) + 1. return xn - SafeCast.toUint(xn > a / xn); } } /** * @dev Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a); } } /** * @dev Return the log in base 2 of a positive value rounded towards zero. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; uint256 exp; unchecked { exp = 128 * SafeCast.toUint(value > (1 << 128) - 1); value >>= exp; result += exp; exp = 64 * SafeCast.toUint(value > (1 << 64) - 1); value >>= exp; result += exp; exp = 32 * SafeCast.toUint(value > (1 << 32) - 1); value >>= exp; result += exp; exp = 16 * SafeCast.toUint(value > (1 << 16) - 1); value >>= exp; result += exp; exp = 8 * SafeCast.toUint(value > (1 << 8) - 1); value >>= exp; result += exp; exp = 4 * SafeCast.toUint(value > (1 << 4) - 1); value >>= exp; result += exp; exp = 2 * SafeCast.toUint(value > (1 << 2) - 1); value >>= exp; result += exp; result += SafeCast.toUint(value > 1); } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value); } } /** * @dev Return the log in base 10 of a positive value rounded towards zero. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value); } } /** * @dev Return the log in base 256 of a positive value rounded towards zero. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; uint256 isGt; unchecked { isGt = SafeCast.toUint(value > (1 << 128) - 1); value >>= isGt * 128; result += isGt * 16; isGt = SafeCast.toUint(value > (1 << 64) - 1); value >>= isGt * 64; result += isGt * 8; isGt = SafeCast.toUint(value > (1 << 32) - 1); value >>= isGt * 32; result += isGt * 4; isGt = SafeCast.toUint(value > (1 << 16) - 1); value >>= isGt * 16; result += isGt * 2; result += SafeCast.toUint(value > (1 << 8) - 1); } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value); } } /** * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers. */ function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) { return uint8(rounding) % 2 == 1; } }
lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. pragma solidity ^0.8.20; /** * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeCast { /** * @dev Value doesn't fit in an uint of `bits` size. */ error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value); /** * @dev An int value doesn't fit in an uint of `bits` size. */ error SafeCastOverflowedIntToUint(int256 value); /** * @dev Value doesn't fit in an int of `bits` size. */ error SafeCastOverflowedIntDowncast(uint8 bits, int256 value); /** * @dev An uint value doesn't fit in an int of `bits` size. */ error SafeCastOverflowedUintToInt(uint256 value); /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits */ function toUint248(uint256 value) internal pure returns (uint248) { if (value > type(uint248).max) { revert SafeCastOverflowedUintDowncast(248, value); } return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits */ function toUint240(uint256 value) internal pure returns (uint240) { if (value > type(uint240).max) { revert SafeCastOverflowedUintDowncast(240, value); } return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits */ function toUint232(uint256 value) internal pure returns (uint232) { if (value > type(uint232).max) { revert SafeCastOverflowedUintDowncast(232, value); } return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits */ function toUint224(uint256 value) internal pure returns (uint224) { if (value > type(uint224).max) { revert SafeCastOverflowedUintDowncast(224, value); } return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits */ function toUint216(uint256 value) internal pure returns (uint216) { if (value > type(uint216).max) { revert SafeCastOverflowedUintDowncast(216, value); } return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits */ function toUint208(uint256 value) internal pure returns (uint208) { if (value > type(uint208).max) { revert SafeCastOverflowedUintDowncast(208, value); } return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits */ function toUint200(uint256 value) internal pure returns (uint200) { if (value > type(uint200).max) { revert SafeCastOverflowedUintDowncast(200, value); } return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits */ function toUint192(uint256 value) internal pure returns (uint192) { if (value > type(uint192).max) { revert SafeCastOverflowedUintDowncast(192, value); } return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits */ function toUint184(uint256 value) internal pure returns (uint184) { if (value > type(uint184).max) { revert SafeCastOverflowedUintDowncast(184, value); } return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits */ function toUint176(uint256 value) internal pure returns (uint176) { if (value > type(uint176).max) { revert SafeCastOverflowedUintDowncast(176, value); } return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits */ function toUint168(uint256 value) internal pure returns (uint168) { if (value > type(uint168).max) { revert SafeCastOverflowedUintDowncast(168, value); } return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits */ function toUint160(uint256 value) internal pure returns (uint160) { if (value > type(uint160).max) { revert SafeCastOverflowedUintDowncast(160, value); } return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits */ function toUint152(uint256 value) internal pure returns (uint152) { if (value > type(uint152).max) { revert SafeCastOverflowedUintDowncast(152, value); } return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits */ function toUint144(uint256 value) internal pure returns (uint144) { if (value > type(uint144).max) { revert SafeCastOverflowedUintDowncast(144, value); } return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits */ function toUint136(uint256 value) internal pure returns (uint136) { if (value > type(uint136).max) { revert SafeCastOverflowedUintDowncast(136, value); } return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits */ function toUint128(uint256 value) internal pure returns (uint128) { if (value > type(uint128).max) { revert SafeCastOverflowedUintDowncast(128, value); } return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits */ function toUint120(uint256 value) internal pure returns (uint120) { if (value > type(uint120).max) { revert SafeCastOverflowedUintDowncast(120, value); } return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits */ function toUint112(uint256 value) internal pure returns (uint112) { if (value > type(uint112).max) { revert SafeCastOverflowedUintDowncast(112, value); } return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits */ function toUint104(uint256 value) internal pure returns (uint104) { if (value > type(uint104).max) { revert SafeCastOverflowedUintDowncast(104, value); } return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits */ function toUint96(uint256 value) internal pure returns (uint96) { if (value > type(uint96).max) { revert SafeCastOverflowedUintDowncast(96, value); } return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits */ function toUint88(uint256 value) internal pure returns (uint88) { if (value > type(uint88).max) { revert SafeCastOverflowedUintDowncast(88, value); } return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits */ function toUint80(uint256 value) internal pure returns (uint80) { if (value > type(uint80).max) { revert SafeCastOverflowedUintDowncast(80, value); } return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits */ function toUint72(uint256 value) internal pure returns (uint72) { if (value > type(uint72).max) { revert SafeCastOverflowedUintDowncast(72, value); } return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits */ function toUint64(uint256 value) internal pure returns (uint64) { if (value > type(uint64).max) { revert SafeCastOverflowedUintDowncast(64, value); } return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits */ function toUint56(uint256 value) internal pure returns (uint56) { if (value > type(uint56).max) { revert SafeCastOverflowedUintDowncast(56, value); } return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits */ function toUint48(uint256 value) internal pure returns (uint48) { if (value > type(uint48).max) { revert SafeCastOverflowedUintDowncast(48, value); } return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits */ function toUint40(uint256 value) internal pure returns (uint40) { if (value > type(uint40).max) { revert SafeCastOverflowedUintDowncast(40, value); } return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits */ function toUint32(uint256 value) internal pure returns (uint32) { if (value > type(uint32).max) { revert SafeCastOverflowedUintDowncast(32, value); } return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits */ function toUint24(uint256 value) internal pure returns (uint24) { if (value > type(uint24).max) { revert SafeCastOverflowedUintDowncast(24, value); } return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits */ function toUint16(uint256 value) internal pure returns (uint16) { if (value > type(uint16).max) { revert SafeCastOverflowedUintDowncast(16, value); } return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits */ function toUint8(uint256 value) internal pure returns (uint8) { if (value > type(uint8).max) { revert SafeCastOverflowedUintDowncast(8, value); } return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. */ function toUint256(int256 value) internal pure returns (uint256) { if (value < 0) { revert SafeCastOverflowedIntToUint(value); } return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits */ function toInt248(int256 value) internal pure returns (int248 downcasted) { downcasted = int248(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(248, value); } } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits */ function toInt240(int256 value) internal pure returns (int240 downcasted) { downcasted = int240(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(240, value); } } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits */ function toInt232(int256 value) internal pure returns (int232 downcasted) { downcasted = int232(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(232, value); } } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits */ function toInt224(int256 value) internal pure returns (int224 downcasted) { downcasted = int224(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(224, value); } } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits */ function toInt216(int256 value) internal pure returns (int216 downcasted) { downcasted = int216(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(216, value); } } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits */ function toInt208(int256 value) internal pure returns (int208 downcasted) { downcasted = int208(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(208, value); } } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits */ function toInt200(int256 value) internal pure returns (int200 downcasted) { downcasted = int200(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(200, value); } } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits */ function toInt192(int256 value) internal pure returns (int192 downcasted) { downcasted = int192(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(192, value); } } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits */ function toInt184(int256 value) internal pure returns (int184 downcasted) { downcasted = int184(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(184, value); } } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits */ function toInt176(int256 value) internal pure returns (int176 downcasted) { downcasted = int176(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(176, value); } } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits */ function toInt168(int256 value) internal pure returns (int168 downcasted) { downcasted = int168(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(168, value); } } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits */ function toInt160(int256 value) internal pure returns (int160 downcasted) { downcasted = int160(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(160, value); } } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits */ function toInt152(int256 value) internal pure returns (int152 downcasted) { downcasted = int152(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(152, value); } } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits */ function toInt144(int256 value) internal pure returns (int144 downcasted) { downcasted = int144(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(144, value); } } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits */ function toInt136(int256 value) internal pure returns (int136 downcasted) { downcasted = int136(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(136, value); } } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits */ function toInt128(int256 value) internal pure returns (int128 downcasted) { downcasted = int128(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(128, value); } } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits */ function toInt120(int256 value) internal pure returns (int120 downcasted) { downcasted = int120(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(120, value); } } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits */ function toInt112(int256 value) internal pure returns (int112 downcasted) { downcasted = int112(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(112, value); } } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits */ function toInt104(int256 value) internal pure returns (int104 downcasted) { downcasted = int104(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(104, value); } } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits */ function toInt96(int256 value) internal pure returns (int96 downcasted) { downcasted = int96(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(96, value); } } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits */ function toInt88(int256 value) internal pure returns (int88 downcasted) { downcasted = int88(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(88, value); } } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits */ function toInt80(int256 value) internal pure returns (int80 downcasted) { downcasted = int80(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(80, value); } } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits */ function toInt72(int256 value) internal pure returns (int72 downcasted) { downcasted = int72(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(72, value); } } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits */ function toInt64(int256 value) internal pure returns (int64 downcasted) { downcasted = int64(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(64, value); } } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits */ function toInt56(int256 value) internal pure returns (int56 downcasted) { downcasted = int56(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(56, value); } } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits */ function toInt48(int256 value) internal pure returns (int48 downcasted) { downcasted = int48(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(48, value); } } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits */ function toInt40(int256 value) internal pure returns (int40 downcasted) { downcasted = int40(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(40, value); } } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits */ function toInt32(int256 value) internal pure returns (int32 downcasted) { downcasted = int32(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(32, value); } } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits */ function toInt24(int256 value) internal pure returns (int24 downcasted) { downcasted = int24(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(24, value); } } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits */ function toInt16(int256 value) internal pure returns (int16 downcasted) { downcasted = int16(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(16, value); } } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits */ function toInt8(int256 value) internal pure returns (int8 downcasted) { downcasted = int8(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(8, value); } } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive if (value > uint256(type(int256).max)) { revert SafeCastOverflowedUintToInt(value); } return int256(value); } /** * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump. */ function toUint(bool b) internal pure returns (uint256 u) { assembly ("memory-safe") { u := iszero(iszero(b)) } } }
lib/openzeppelin-contracts/contracts/utils/math/SignedMath.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.20; import {SafeCast} from "./SafeCast.sol"; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant. * * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone. * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute * one branch when needed, making this function more expensive. */ function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) { unchecked { // branchless ternary works because: // b ^ (a ^ b) == a // b ^ 0 == b return b ^ ((a ^ b) * int256(SafeCast.toUint(condition))); } } /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return ternary(a > b, a, b); } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return ternary(a < b, a, b); } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson. // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift, // taking advantage of the most significant (or "sign" bit) in two's complement representation. // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result, // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative). int256 mask = n >> 255; // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it. return uint256((n + mask) ^ mask); } } }
Compiler Settings
{"viaIR":false,"remappings":["@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/","@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/","forge-std/=lib/forge-std/src/","ds-test/=lib/forge-std/lib/ds-test/src/","erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/","halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/","openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/","openzeppelin-contracts/=lib/openzeppelin-contracts/"],"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":200,"enabled":true},"metadata":{"useLiteralContent":false,"bytecodeHash":"ipfs","appendCBOR":true},"libraries":{},"evmVersion":"shanghai"}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"error","name":"AccessControlBadConfirmation","inputs":[]},{"type":"error","name":"AccessControlUnauthorizedAccount","inputs":[{"type":"address","name":"account","internalType":"address"},{"type":"bytes32","name":"neededRole","internalType":"bytes32"}]},{"type":"error","name":"AddressEmptyCode","inputs":[{"type":"address","name":"target","internalType":"address"}]},{"type":"error","name":"DailyWithdrawalLimitExceeded","inputs":[]},{"type":"error","name":"ECDSAInvalidSignature","inputs":[]},{"type":"error","name":"ECDSAInvalidSignatureLength","inputs":[{"type":"uint256","name":"length","internalType":"uint256"}]},{"type":"error","name":"ECDSAInvalidSignatureS","inputs":[{"type":"bytes32","name":"s","internalType":"bytes32"}]},{"type":"error","name":"ERC1967InvalidImplementation","inputs":[{"type":"address","name":"implementation","internalType":"address"}]},{"type":"error","name":"ERC1967NonPayable","inputs":[]},{"type":"error","name":"EnforcedPause","inputs":[]},{"type":"error","name":"ExpectedPause","inputs":[]},{"type":"error","name":"FailedCall","inputs":[]},{"type":"error","name":"GameCooldownActive","inputs":[]},{"type":"error","name":"InsufficientRewardPool","inputs":[]},{"type":"error","name":"InvalidAddress","inputs":[]},{"type":"error","name":"InvalidAmount","inputs":[]},{"type":"error","name":"InvalidBurnRate","inputs":[]},{"type":"error","name":"InvalidDifficulty","inputs":[]},{"type":"error","name":"InvalidGameResult","inputs":[]},{"type":"error","name":"InvalidInitialization","inputs":[]},{"type":"error","name":"InvalidSignature","inputs":[]},{"type":"error","name":"InvalidStakeStatus","inputs":[]},{"type":"error","name":"InvalidTiers","inputs":[]},{"type":"error","name":"NonceAlreadyUsed","inputs":[]},{"type":"error","name":"NotInitializing","inputs":[]},{"type":"error","name":"ReentrancyGuardReentrantCall","inputs":[]},{"type":"error","name":"SafeERC20FailedOperation","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"error","name":"SignatureExpired","inputs":[]},{"type":"error","name":"StakeAlreadyExists","inputs":[]},{"type":"error","name":"StakeNotFound","inputs":[]},{"type":"error","name":"UUPSUnauthorizedCallContext","inputs":[]},{"type":"error","name":"UUPSUnsupportedProxiableUUID","inputs":[{"type":"bytes32","name":"slot","internalType":"bytes32"}]},{"type":"error","name":"UnauthorizedSettlement","inputs":[]},{"type":"event","name":"BurnRateUpdated","inputs":[{"type":"uint8","name":"difficulty","internalType":"enum CWDEscrow.GameDifficulty","indexed":true},{"type":"uint256","name":"burnPercentage","internalType":"uint256","indexed":false},{"type":"uint256","name":"collateralPercentage","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"DailyWithdrawalLimitReset","inputs":[{"type":"address","name":"player","internalType":"address","indexed":true},{"type":"uint256","name":"timestamp","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"EIP712DomainChanged","inputs":[],"anonymous":false},{"type":"event","name":"Initialized","inputs":[{"type":"uint64","name":"version","internalType":"uint64","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTiersUpdated","inputs":[{"type":"uint256","name":"tierCount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Paused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"RewardPoolFunded","inputs":[{"type":"address","name":"funder","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"uint256","name":"newBalance","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RewardPoolWithdrawn","inputs":[{"type":"address","name":"recipient","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"uint256","name":"newBalance","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"previousAdminRole","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"newAdminRole","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"StakeCancelled","inputs":[{"type":"bytes32","name":"stakeId","internalType":"bytes32","indexed":true},{"type":"address","name":"player","internalType":"address","indexed":true},{"type":"uint256","name":"returnedAmount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"StakeCreated","inputs":[{"type":"bytes32","name":"stakeId","internalType":"bytes32","indexed":true},{"type":"address","name":"player","internalType":"address","indexed":true},{"type":"uint256","name":"stakedAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"burnedAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"collateralAmount","internalType":"uint256","indexed":false},{"type":"uint8","name":"difficulty","internalType":"enum CWDEscrow.GameDifficulty","indexed":false},{"type":"uint256","name":"snapshotBalance","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"StakeLost","inputs":[{"type":"bytes32","name":"stakeId","internalType":"bytes32","indexed":true},{"type":"address","name":"player","internalType":"address","indexed":true},{"type":"uint256","name":"collateralForfeited","internalType":"uint256","indexed":false},{"type":"uint256","name":"burnedAmount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"StakeWon","inputs":[{"type":"bytes32","name":"stakeId","internalType":"bytes32","indexed":true},{"type":"address","name":"player","internalType":"address","indexed":true},{"type":"uint256","name":"collateralReturned","internalType":"uint256","indexed":false},{"type":"uint256","name":"finalMoney","internalType":"uint256","indexed":false},{"type":"uint256","name":"burnReward","internalType":"uint256","indexed":false},{"type":"uint256","name":"ownershipMultiplier","internalType":"uint256","indexed":false},{"type":"uint256","name":"totalPayout","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"TreasuryUpdated","inputs":[{"type":"address","name":"oldTreasury","internalType":"address","indexed":true},{"type":"address","name":"newTreasury","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Unpaused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"Upgraded","inputs":[{"type":"address","name":"implementation","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"BASIS_POINTS","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"BURN_REWARD_MULTIPLIER","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"DAILY_WITHDRAWAL_LIMIT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"DEFAULT_ADMIN_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"GAME_COOLDOWN","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"GAME_MASTER_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"GAME_RESULT_TYPEHASH","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"GAME_SIGNER_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"MAXIMUM_REWARD_MULTIPLIER","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"PAUSER_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"REWARD_MANAGER_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"SETTLEMENT_DEADLINE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"TREASURY_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"UPGRADER_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"UPGRADE_INTERFACE_VERSION","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminSettleLoss","inputs":[{"type":"bytes32","name":"stakeId","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"adminSettleWin","inputs":[{"type":"bytes32","name":"stakeId","internalType":"bytes32"},{"type":"uint256","name":"finalMoney","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"burnPercentage","internalType":"uint256"},{"type":"uint256","name":"collateralPercentage","internalType":"uint256"}],"name":"burnRates","inputs":[{"type":"uint8","name":"","internalType":"enum CWDEscrow.GameDifficulty"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"burnAmount","internalType":"uint256"},{"type":"uint256","name":"collateralAmount","internalType":"uint256"},{"type":"uint256","name":"guaranteedReturn","internalType":"uint256"},{"type":"uint256","name":"bonusReward","internalType":"uint256"},{"type":"uint256","name":"cappedBonusReward","internalType":"uint256"}],"name":"calculatePotentialRewards","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"uint8","name":"difficulty","internalType":"enum CWDEscrow.GameDifficulty"},{"type":"uint256","name":"playerBalance","internalType":"uint256"},{"type":"uint256","name":"finalMoney","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"cancelStake","inputs":[{"type":"bytes32","name":"stakeId","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes32","name":"stakeId","internalType":"bytes32"}],"name":"createStake","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"uint8","name":"difficulty","internalType":"enum CWDEscrow.GameDifficulty"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract ICWDToken"}],"name":"cwdToken","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"dailyWithdrawals","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes1","name":"fields","internalType":"bytes1"},{"type":"string","name":"name","internalType":"string"},{"type":"string","name":"version","internalType":"string"},{"type":"uint256","name":"chainId","internalType":"uint256"},{"type":"address","name":"verifyingContract","internalType":"address"},{"type":"bytes32","name":"salt","internalType":"bytes32"},{"type":"uint256[]","name":"extensions","internalType":"uint256[]"}],"name":"eip712Domain","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"fundRewardPool","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32[]","name":"activeStakeIds","internalType":"bytes32[]"}],"name":"getActivePlayerStakes","inputs":[{"type":"address","name":"player","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"withdrawn","internalType":"uint256"},{"type":"uint256","name":"limit","internalType":"uint256"},{"type":"uint256","name":"remaining","internalType":"uint256"}],"name":"getDailyWithdrawalStatus","inputs":[{"type":"address","name":"player","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"multiplierBps","internalType":"uint256"}],"name":"getOwnershipMultiplier","inputs":[{"type":"uint256","name":"balance","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"tiers","internalType":"struct CWDEscrow.OwnershipTier[]","components":[{"type":"uint256","name":"minBalance","internalType":"uint256"},{"type":"uint256","name":"multiplierBps","internalType":"uint256"}]}],"name":"getOwnershipTiers","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32[]","name":"stakeIds","internalType":"bytes32[]"}],"name":"getPlayerStakes","inputs":[{"type":"address","name":"player","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32[]","name":"filteredStakeIds","internalType":"bytes32[]"}],"name":"getPlayerStakesByStatus","inputs":[{"type":"address","name":"player","internalType":"address"},{"type":"uint8","name":"status","internalType":"enum CWDEscrow.StakeStatus"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"validStakes","internalType":"struct CWDEscrow.Stake[]","components":[{"type":"address","name":"player","internalType":"address"},{"type":"uint256","name":"stakedAmount","internalType":"uint256"},{"type":"uint256","name":"burnedAmount","internalType":"uint256"},{"type":"uint256","name":"collateralAmount","internalType":"uint256"},{"type":"uint256","name":"snapshotBalance","internalType":"uint256"},{"type":"uint256","name":"finalMoney","internalType":"uint256"},{"type":"uint256","name":"rewardAmount","internalType":"uint256"},{"type":"uint256","name":"createdAt","internalType":"uint256"},{"type":"uint256","name":"settledAt","internalType":"uint256"},{"type":"uint8","name":"difficulty","internalType":"enum CWDEscrow.GameDifficulty"},{"type":"uint8","name":"status","internalType":"enum CWDEscrow.StakeStatus"}]},{"type":"bytes32[]","name":"validStakeIds","internalType":"bytes32[]"}],"name":"getPlayerStakesDetailed","inputs":[{"type":"address","name":"player","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRoleAdmin","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"stake","internalType":"struct CWDEscrow.Stake","components":[{"type":"address","name":"player","internalType":"address"},{"type":"uint256","name":"stakedAmount","internalType":"uint256"},{"type":"uint256","name":"burnedAmount","internalType":"uint256"},{"type":"uint256","name":"collateralAmount","internalType":"uint256"},{"type":"uint256","name":"snapshotBalance","internalType":"uint256"},{"type":"uint256","name":"finalMoney","internalType":"uint256"},{"type":"uint256","name":"rewardAmount","internalType":"uint256"},{"type":"uint256","name":"createdAt","internalType":"uint256"},{"type":"uint256","name":"settledAt","internalType":"uint256"},{"type":"uint8","name":"difficulty","internalType":"enum CWDEscrow.GameDifficulty"},{"type":"uint8","name":"status","internalType":"enum CWDEscrow.StakeStatus"}]}],"name":"getStake","inputs":[{"type":"bytes32","name":"stakeId","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"address","name":"defaultAdmin","internalType":"address"},{"type":"address","name":"cwdTokenAddress","internalType":"address"},{"type":"address","name":"treasuryAddress","internalType":"address"},{"type":"address","name":"gameSigner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"isActive","internalType":"bool"}],"name":"isStakeActive","inputs":[{"type":"bytes32","name":"stakeId","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lastGameTimestamp","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lastWithdrawalReset","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"minBalance","internalType":"uint256"},{"type":"uint256","name":"multiplierBps","internalType":"uint256"}],"name":"ownershipTiers","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"pause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"paused","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"proxiableUUID","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"callerConfirmation","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"rewardPoolBalance","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setTreasury","inputs":[{"type":"address","name":"newTreasury","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"settleLossWithProof","inputs":[{"type":"tuple","name":"result","internalType":"struct CWDEscrow.GameResult","components":[{"type":"bytes32","name":"stakeId","internalType":"bytes32"},{"type":"address","name":"player","internalType":"address"},{"type":"uint256","name":"finalMoney","internalType":"uint256"},{"type":"bool","name":"won","internalType":"bool"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"settleWinWithProof","inputs":[{"type":"tuple","name":"result","internalType":"struct CWDEscrow.GameResult","components":[{"type":"bytes32","name":"stakeId","internalType":"bytes32"},{"type":"address","name":"player","internalType":"address"},{"type":"uint256","name":"finalMoney","internalType":"uint256"},{"type":"bool","name":"won","internalType":"bool"},{"type":"uint256","name":"deadline","internalType":"uint256"}]},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalActiveStakes","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalBurned","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalRewardsDistributed","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalStaked","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"treasury","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"exists","internalType":"bool"},{"type":"tuple","name":"stake","internalType":"struct CWDEscrow.Stake","components":[{"type":"address","name":"player","internalType":"address"},{"type":"uint256","name":"stakedAmount","internalType":"uint256"},{"type":"uint256","name":"burnedAmount","internalType":"uint256"},{"type":"uint256","name":"collateralAmount","internalType":"uint256"},{"type":"uint256","name":"snapshotBalance","internalType":"uint256"},{"type":"uint256","name":"finalMoney","internalType":"uint256"},{"type":"uint256","name":"rewardAmount","internalType":"uint256"},{"type":"uint256","name":"createdAt","internalType":"uint256"},{"type":"uint256","name":"settledAt","internalType":"uint256"},{"type":"uint8","name":"difficulty","internalType":"enum CWDEscrow.GameDifficulty"},{"type":"uint8","name":"status","internalType":"enum CWDEscrow.StakeStatus"}]}],"name":"tryGetStake","inputs":[{"type":"bytes32","name":"stakeId","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unpause","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateBurnRate","inputs":[{"type":"uint8","name":"difficulty","internalType":"enum CWDEscrow.GameDifficulty"},{"type":"uint256","name":"burnPercentage","internalType":"uint256"},{"type":"uint256","name":"collateralPercentage","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateOwnershipTiers","inputs":[{"type":"tuple[]","name":"tiers","internalType":"struct CWDEscrow.OwnershipTier[]","components":[{"type":"uint256","name":"minBalance","internalType":"uint256"},{"type":"uint256","name":"multiplierBps","internalType":"uint256"}]}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"upgradeToAndCall","inputs":[{"type":"address","name":"newImplementation","internalType":"address"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"usedNonces","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdrawFromRewardPool","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"address","name":"recipient","internalType":"address"}]}]
Contract Creation Code
0x60a060405230608052348015610013575f5ffd5b5061001c610021565b6100d3565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff16156100715760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b03908116146100d05780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b608051614c856100f95f395f81816133180152818161334101526134c90152614c855ff3fe6080604052600436106103a8575f3560e01c806394fa2b8c116101e9578063c0b0e3fa11610108578063e9917c071161009d578063f72c0d8b1161006d578063f72c0d8b14610b75578063f8c8765e14610ba8578063feb6172414610bc7578063ff8cb6cb14610bf5575f5ffd5b8063e9917c0714610b01578063ee17254614610b20578063ef5053ad14610b35578063f0f4426014610b56575f5ffd5b8063d89135cd116100d8578063d89135cd14610a8b578063e1f1c4a714610aa0578063e63ab1e914610ab5578063e765c12214610ad5575f5ffd5b8063c0b0e3fa14610a04578063d11a57ec14610a24578063d547741f14610a57578063d687cd6214610a76575f5ffd5b8063a3600fcd1161017e578063b5192e3c1161014e578063b5192e3c1461097c578063b9b56ae41461099b578063bc4393a3146109ba578063beda1187146109e5575f5ffd5b8063a3600fcd146103e0578063ad1def1e14610900578063ad3cb1cc14610920578063adfae2251461095d575f5ffd5b80639cc71f3f116101b95780639cc71f3f146108665780639e12e8c814610891578063a217fddf146108a6578063a3316c28146108b9575f5ffd5b806394fa2b8c146107dc57806395836a69146107fb5780639a2bce8f1461081a5780639a399bec14610847575f5ffd5b80634f1ef286116102d5578063622f6bb31161026a578063817b1cd21161023a578063817b1cd21461076d5780638456cb591461078257806384b0196e1461079657806391d14854146107bd575f5ffd5b8063622f6bb3146106b75780636d750d80146106f157806374246b49146107115780637a5c08ae14610758575f5ffd5b80635c975abb116102a55780635c975abb1461060c5780635cb95a741461062f5780635effec881461066257806361d027b314610698575f5ffd5b80634f1ef286146105a757806352d1902d146105ba57806358b6043f146105ce5780635bf2d322146105ed575f5ffd5b80632a9248131161034b5780633d426be61161031b5780633d426be61461051c5780633f4ba83a1461054957806341d636a21461055d5780634d875ef614610588575f5ffd5b80632a924813146104a05780632f2ff15d146104bf5780633230f838146104de57806336568abe146104fd575f5ffd5b80631d583e0d116103865780631d583e0d1461042e5780631da0bcd81461044f5780631f079e011461046c578063248a9ca314610481575f5ffd5b806301ffc9a7146103ac578063098cf869146103e0578063147e0d9114610402575b5f5ffd5b3480156103b7575f5ffd5b506103cb6103c63660046141e7565b610c14565b60405190151581526020015b60405180910390f35b3480156103eb575f5ffd5b506103f4600381565b6040519081526020016103d7565b34801561040d575f5ffd5b5061042161041c366004614224565b610c4a565b6040516103d79190614277565b348015610439575f5ffd5b5061044d610448366004614289565b610cb3565b005b34801561045a575f5ffd5b506103f469021e19e0c9bab240000081565b348015610477575f5ffd5b506103f4600c5481565b34801561048c575f5ffd5b506103f461049b366004614289565b610d78565b3480156104ab575f5ffd5b5061044d6104ba366004614289565b610d98565b3480156104ca575f5ffd5b5061044d6104d93660046142a0565b610ec9565b3480156104e9575f5ffd5b5061044d6104f83660046142d8565b610eeb565b348015610508575f5ffd5b5061044d6105173660046142a0565b610fc9565b348015610527575f5ffd5b5061053b610536366004614224565b611001565b6040516103d79291906143c8565b348015610554575f5ffd5b5061044d611325565b348015610568575f5ffd5b506103f4610577366004614224565b60056020525f908152604090205481565b348015610593575f5ffd5b506103f46105a2366004614289565b611347565b61044d6105b536600461443f565b611351565b3480156105c5575f5ffd5b506103f461136c565b3480156105d9575f5ffd5b5061044d6105e8366004614500565b611387565b3480156105f8575f5ffd5b50610421610607366004614224565b611625565b348015610617575f5ffd5b505f516020614c105f395f51905f525460ff166103cb565b34801561063a575f5ffd5b506103f47f80e43b71a3dc4270c5b6dcc6b0c385dd9bc98b168b9086bb845a8921c3342e8b81565b34801561066d575f5ffd5b505f54610680906001600160a01b031681565b6040516001600160a01b0390911681526020016103d7565b3480156106a3575f5ffd5b50600154610680906001600160a01b031681565b3480156106c2575f5ffd5b506106d66106d1366004614224565b6117fa565b604080519384526020840192909252908201526060016103d7565b3480156106fc575f5ffd5b506103f45f516020614bb05f395f51905f5281565b34801561071c575f5ffd5b5061073061072b366004614583565b61184c565b604080519586526020860194909452928401919091526060830152608082015260a0016103d7565b348015610763575f5ffd5b506103f460025481565b348015610778575f5ffd5b506103f4600b5481565b34801561078d575f5ffd5b5061044d61196c565b3480156107a1575f5ffd5b506107aa61198b565b6040516103d79796959493929190614608565b3480156107c8575f5ffd5b506103cb6107d73660046142a0565b611a39565b3480156107e7575f5ffd5b506103cb6107f6366004614289565b611a6f565b348015610806575f5ffd5b5061042161081536600461469e565b611aa3565b348015610825575f5ffd5b50610839610834366004614289565b611c99565b6040516103d79291906146d6565b348015610852575f5ffd5b5061044d6108613660046142a0565b611dae565b348015610871575f5ffd5b506103f4610880366004614224565b60066020525f908152604090205481565b34801561089c575f5ffd5b506103f4610e1081565b3480156108b1575f5ffd5b506103f45f81565b3480156108c4575f5ffd5b506108eb6108d33660046146ed565b60086020525f90815260409020805460019091015482565b604080519283526020830191909152016103d7565b34801561090b575f5ffd5b506103f45f516020614b505f395f51905f5281565b34801561092b575f5ffd5b50610950604051806040016040528060058152602001640352e302e360dc1b81525081565b6040516103d79190614706565b348015610968575f5ffd5b506108eb610977366004614289565b611ec7565b348015610987575f5ffd5b5061044d610996366004614500565b611ef3565b3480156109a6575f5ffd5b5061044d6109b5366004614289565b61216f565b3480156109c5575f5ffd5b506103f46109d4366004614224565b60076020525f908152604090205481565b3480156109f0575f5ffd5b5061044d6109ff366004614718565b612202565b348015610a0f575f5ffd5b506103f45f516020614b305f395f51905f5281565b348015610a2f575f5ffd5b506103f47fe1dcbdb91df27212a29bc27177c840cf2f819ecf2187432e1fac86c2dd5dfca981565b348015610a62575f5ffd5b5061044d610a713660046142a0565b61233e565b348015610a81575f5ffd5b506103f461070881565b348015610a96575f5ffd5b506103f4600d5481565b348015610aab575f5ffd5b506103f461271081565b348015610ac0575f5ffd5b506103f45f516020614bd05f395f51905f5281565b348015610ae0575f5ffd5b50610af4610aef366004614289565b61235a565b6040516103d79190614787565b348015610b0c575f5ffd5b506103f4610b1b366004614796565b612488565b348015610b2b575f5ffd5b506103f4600e5481565b348015610b40575f5ffd5b50610b496128ca565b6040516103d791906147b7565b348015610b61575f5ffd5b5061044d610b70366004614224565b612939565b348015610b80575f5ffd5b506103f47f189ab7a9244df0848122154315af71fe140f3db0fe014031783b0946b8c9d2e381565b348015610bb3575f5ffd5b5061044d610bc2366004614805565b6129dc565b348015610bd2575f5ffd5b506103cb610be1366004614289565b60096020525f908152604090205460ff1681565b348015610c00575f5ffd5b5061044d610c0f366004614856565b612f30565b5f6001600160e01b03198216637965db0b60e01b1480610c4457506301ffc9a760e01b6001600160e01b03198316145b92915050565b6001600160a01b0381165f90815260046020908152604091829020805483518184028101840190945280845260609392830182828015610ca757602002820191905f5260205f20905b815481526020019060010190808311610c93575b50505050509050919050565b5f516020614bb05f395f51905f52610cca81612fc4565b610cd2612fce565b815f03610cf25760405163162908e360e11b815260040160405180910390fd5b8160025f828254610d03919061488a565b90915550505f54610d1f906001600160a01b0316333085613005565b60025460408051848152602081019290925233917f49740176a81d28f933051e26004df983307376c5a93665e9e63f2e6b9d671282910160405180910390a2610d7460015f516020614c305f395f51905f5255565b5050565b5f9081525f516020614bf05f395f51905f52602052604090206001015490565b5f516020614b505f395f51905f52610daf81612fc4565b610db761307f565b610dbf612fce565b5f82815260036020526040902060016009820154610100900460ff166004811115610dec57610dec614308565b14610e0a5760405163b3eb737b60e01b815260040160405180910390fd5b600381015460098201805461ff001916610400179055426008830155600b80548291905f90610e3a90849061489d565b9091555050600c8054905f610e4e836148b0565b909155505081545f54610e6e916001600160a01b039182169116836130b1565b81546040518281526001600160a01b039091169085907faab1aafc363800fe14e0ad1e98986ec2cb2aecfc657f05c53ddd2d485bc81aff9060200160405180910390a35050610d7460015f516020614c305f395f51905f5255565b610ed282610d78565b610edb81612fc4565b610ee583836130e2565b50505050565b5f610ef581612fc4565b612710610f02838561488a565b14610f2057604051634a41f87560e01b815260040160405180910390fd5b60405180604001604052808481526020018381525060085f866002811115610f4a57610f4a614308565b6002811115610f5b57610f5b614308565b81526020808201929092526040015f2082518155910151600190910155836002811115610f8a57610f8a614308565b60408051858152602081018590527f5595837bca534fb8707a86302c437184a0c387b68ed44e7f31c9b13be31394a7910160405180910390a250505050565b6001600160a01b0381163314610ff25760405163334bd91960e11b815260040160405180910390fd5b610ffc8282613183565b505050565b6001600160a01b0381165f90815260046020908152604080832080548251818502810185019093528083526060948594909392919083018282801561106357602002820191905f5260205f20905b81548152602001906001019080831161104f575b509394505f935083925050505b82518110156110e1575f60035f85848151811061108f5761108f6148c5565b602002602001015181526020019081526020015f2060090160019054906101000a900460ff1660048111156110c6576110c6614308565b146110d957816110d5816148d9565b9250505b600101611070565b50806001600160401b038111156110fa576110fa61442b565b60405190808252806020026020018201604052801561113357816020015b611120614148565b8152602001906001900390816111185790505b509350806001600160401b0381111561114e5761114e61442b565b604051908082528060200260200182016040528015611177578160200160208202803683370190505b5092505f805b835181101561131c575f60035f86848151811061119c5761119c6148c5565b60209081029190910181015182528181019290925260409081015f2081516101608101835281546001600160a01b03168152600182015493810193909352600280820154928401929092526003810154606084015260048101546080840152600581015460a0840152600681015460c0840152600781015460e084015260088101546101008401526009810154909161012084019160ff169081111561124457611244614308565b600281111561125557611255614308565b81526020016009820160019054906101000a900460ff16600481111561127d5761127d614308565b600481111561128e5761128e614308565b90525090505f81610140015160048111156112ab576112ab614308565b1461131357808784815181106112c3576112c36148c5565b60200260200101819052508482815181106112e0576112e06148c5565b60200260200101518684815181106112fa576112fa6148c5565b60209081029190910101528261130f816148d9565b9350505b5060010161117d565b50505050915091565b5f516020614bd05f395f51905f5261133c81612fc4565b6113446131fc565b50565b5f610c448261325b565b61135961330d565b611362826133b1565b610d748282613402565b5f6113756134be565b505f516020614b905f395f51905f5290565b61138f61307f565b611397612fce565b82355f90815260036020526040902060016009820154610100900460ff1660048111156113c6576113c6614308565b146113e45760405163b3eb737b60e01b815260040160405180910390fd5b80546001600160a01b0316331461140e57604051631a0d995360e31b815260040160405180910390fd5b61141e60808501606086016148f1565b61143b57604051636f756dcf60e01b815260040160405180910390fd5b836080013542111561146057604051630819bdcd60e01b815260040160405180910390fd5b604080518535602080830191909152608087013582840152825180830384018152606090920183528151918101919091205f81815260099092529190205460ff16156114be57604051623f613760e71b815260040160405180910390fd5b5f7f80e43b71a3dc4270c5b6dcc6b0c385dd9bc98b168b9086bb845a8921c3342e8b86356114f26040890160208a01614224565b604089013561150760808b0160608c016148f1565b6040805160208101969096528501939093526001600160a01b03909116606084015260808381019190915290151560a083015287013560c082015260e0016040516020818303038152906040528051906020012090505f61156782613507565b90505f6115a98288888080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061353392505050565b90506115c25f516020614b305f395f51905f5282611a39565b6115df57604051638baa579f60e01b815260040160405180910390fd5b5f8481526009602052604090819020805460ff1916600117905561160a9086908a35908b013561355b565b5050505050610ffc60015f516020614c305f395f51905f5255565b6001600160a01b0381165f90815260046020908152604080832080548251818502810185019093528083526060949383018282801561168157602002820191905f5260205f20905b81548152602001906001019080831161166d575b509394505f935083925050505b825181101561170057600160035f8584815181106116ae576116ae6148c5565b602002602001015181526020019081526020015f2060090160019054906101000a900460ff1660048111156116e5576116e5614308565b036116f857816116f4816148d9565b9250505b60010161168e565b50806001600160401b038111156117195761171961442b565b604051908082528060200260200182016040528015611742578160200160208202803683370190505b5092505f805b83518110156117f157600160035f868481518110611768576117686148c5565b602002602001015181526020019081526020015f2060090160019054906101000a900460ff16600481111561179f5761179f614308565b036117e9578381815181106117b6576117b66148c5565b60200260200101518583815181106117d0576117d06148c5565b6020908102919091010152816117e5816148d9565b9250505b600101611748565b50505050919050565b5f5f5f611806846137b3565b6001600160a01b0384165f90815260056020526040902054925069021e19e0c9bab2400000915082821161183a575f611844565b611844838361489d565b929491935050565b5f5f5f5f5f5f60085f8a600281111561186757611867614308565b600281111561187857611878614308565b81526020019081526020015f206040518060400160405290815f82015481526020016001820154815250509050612710815f01518b6118b79190614910565b6118c19190614927565b95506118cd868b61489d565b94505f6118db600388614910565b90505f6118e78a61325b565b90506127106118f68284614910565b6119009190614927565b945061190c898861488a565b335f9081526005602052604081205491975069021e19e0c9bab24000008210611935575f611949565b6119498269021e19e0c9bab240000061489d565b9050808711611958578661195a565b805b95505050505050945094509450945094565b5f516020614bd05f395f51905f5261198381612fc4565b6113446137e1565b5f60608082808083815f516020614b705f395f51905f5280549091501580156119b657506001810154155b6119ff5760405162461bcd60e51b81526020600482015260156024820152741152540dcc4c8e88155b9a5b9a5d1a585b1a5e9959605a1b60448201526064015b60405180910390fd5b611a07613829565b611a0f6138e9565b604080515f80825260208201909252600f60f81b9c939b5091995046985030975095509350915050565b5f9182525f516020614bf05f395f51905f52602090815260408084206001600160a01b0393909316845291905290205460ff1690565b5f60015f83815260036020526040902060090154610100900460ff166004811115611a9c57611a9c614308565b1492915050565b6001600160a01b0382165f908152600460209081526040808320805482518185028101850190935280835260609493830182828015611aff57602002820191905f5260205f20905b815481526020019060010190808311611aeb575b509394505f935083925050505b8251811015611b8e57846004811115611b2757611b27614308565b60035f858481518110611b3c57611b3c6148c5565b602002602001015181526020019081526020015f2060090160019054906101000a900460ff166004811115611b7357611b73614308565b03611b865781611b82816148d9565b9250505b600101611b0c565b50806001600160401b03811115611ba757611ba761442b565b604051908082528060200260200182016040528015611bd0578160200160208202803683370190505b5092505f805b8351811015611c8f57856004811115611bf157611bf1614308565b60035f868481518110611c0657611c066148c5565b602002602001015181526020019081526020015f2060090160019054906101000a900460ff166004811115611c3d57611c3d614308565b03611c8757838181518110611c5457611c546148c5565b6020026020010151858381518110611c6e57611c6e6148c5565b602090810291909101015281611c83816148d9565b9250505b600101611bd6565b5050505092915050565b5f611ca2614148565b5f8381526003602081815260409283902083516101608101855281546001600160a01b031681526001820154928101929092526002808201549483019490945291820154606082015260048201546080820152600582015460a0820152600682015460c0820152600782015460e082015260088201546101008201526009820154909261012084019160ff1690811115611d3e57611d3e614308565b6002811115611d4f57611d4f614308565b81526020016009820160019054906101000a900460ff166004811115611d7757611d77614308565b6004811115611d8857611d88614308565b90525090505f8161014001516004811115611da557611da5614308565b14159150915091565b5f516020614bb05f395f51905f52611dc581612fc4565b611dcd612fce565b825f03611ded5760405163162908e360e11b815260040160405180910390fd5b6001600160a01b038216611e145760405163e6c4247b60e01b815260040160405180910390fd5b600254831115611e3757604051633270436b60e01b815260040160405180910390fd5b8260025f828254611e48919061489d565b90915550505f54611e63906001600160a01b031683856130b1565b816001600160a01b03167f0639db63a998ac6f7999198717a150e8512c78f7a9b9f747a8a16687f7d6cbcb84600254604051611ea9929190918252602082015260400190565b60405180910390a2610ffc60015f516020614c305f395f51905f5255565b600a8181548110611ed6575f80fd5b5f9182526020909120600290910201805460019091015490915082565b611efb61307f565b611f03612fce565b82355f90815260036020526040902060016009820154610100900460ff166004811115611f3257611f32614308565b14611f505760405163b3eb737b60e01b815260040160405180910390fd5b80546001600160a01b03163314611f7a57604051631a0d995360e31b815260040160405180910390fd5b611f8a60808501606086016148f1565b15611fa857604051636f756dcf60e01b815260040160405180910390fd5b8360800135421115611fcd57604051630819bdcd60e01b815260040160405180910390fd5b604080518535602080830191909152608087013582840152825180830384018152606090920183528151918101919091205f81815260099092529190205460ff161561202b57604051623f613760e71b815260040160405180910390fd5b5f7f80e43b71a3dc4270c5b6dcc6b0c385dd9bc98b168b9086bb845a8921c3342e8b863561205f6040890160208a01614224565b604089013561207460808b0160608c016148f1565b6040805160208101969096528501939093526001600160a01b03909116606084015260808381019190915290151560a083015287013560c082015260e0016040516020818303038152906040528051906020012090505f6120d482613507565b90505f6121168288888080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061353392505050565b905061212f5f516020614b305f395f51905f5282611a39565b61214c57604051638baa579f60e01b815260040160405180910390fd5b5f848152600960205260409020805460ff1916600117905561160a858935613927565b5f516020614b505f395f51905f5261218681612fc4565b61218e61307f565b612196612fce565b5f82815260036020526040902060016009820154610100900460ff1660048111156121c3576121c3614308565b146121e15760405163b3eb737b60e01b815260040160405180910390fd5b6121eb8184613927565b50610d7460015f516020614c305f395f51905f5255565b5f61220c81612fc4565b5f82900361222d5760405163036899eb60e31b815260040160405180910390fd5b612238600a5f6141b0565b5f5b82811015612305575f8111801561228f5750838361225960018461489d565b818110612268576122686148c5565b9050604002015f0135848483818110612283576122836148c5565b9050604002015f013511155b156122ad5760405163036899eb60e31b815260040160405180910390fd5b600a8484838181106122c1576122c16148c5565b83546001810185555f94855260209094206040909102929092019260020290910190506122fb828281358155602090910135600190910155565b505060010161223a565b506040518281527fcdeaf1302c7aea52ed757d0176c489a3185e2db09a913c747098c03675c56e019060200160405180910390a1505050565b61234782610d78565b61235081612fc4565b610ee58383613183565b612362614148565b5f8281526003602081815260409283902083516101608101855281546001600160a01b031681526001820154928101929092526002808201549483019490945291820154606082015260048201546080820152600582015460a0820152600682015460c0820152600782015460e082015260088201546101008201526009820154909261012084019160ff16908111156123fe576123fe614308565b600281111561240f5761240f614308565b81526020016009820160019054906101000a900460ff16600481111561243757612437614308565b600481111561244857612448614308565b90525090505f816101400151600481111561246557612465614308565b0361248357604051638c877d2160e01b815260040160405180910390fd5b919050565b5f61249161307f565b612499612fce565b825f036124b95760405163162908e360e11b815260040160405180910390fd5b5f60085f8460028111156124cf576124cf614308565b60028111156124e0576124e0614308565b81526020019081526020015f206040518060400160405290815f82015481526020016001820154815250509050805f01515f036125305760405163eff9b19d60e01b815260040160405180910390fd5b80515f90612710906125429087614910565b61254c9190614927565b90505f612559828761489d565b5f8054919250906001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa1580156125b1573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125d59190614946565b90506125e23388886139e4565b94505f5f86815260036020526040902060090154610100900460ff16600481111561260f5761260f614308565b1461262d576040516336c9ceb960e01b815260040160405180910390fd5b6040518061016001604052806126403390565b6001600160a01b031681526020018881526020018481526020018381526020018281526020015f81526020015f81526020014281526020015f815260200187600281111561269057612690614308565b8152600160209182018190525f8881526003808452604091829020855181546001600160a01b0319166001600160a01b039091161781559385015184840155908401516002808501919091556060850151918401919091556080840151600484015560a0840151600584015560c0840151600684015560e0840151600784015561010084015160088401556101208401516009840180549193909260ff1990921691849081111561274357612743614308565b021790555061014082015160098201805461ff00191661010083600481111561276e5761276e614308565b021790555090505060045f6127803390565b6001600160a01b031681526020808201929092526040015f9081208054600181018255908252918120909101869055600b80548492906127c190849061488a565b9091555050600c8054905f6127d5836148d9565b91905055506127f76127e43390565b5f546001600160a01b031690308a613005565b5f54604051630852cd8d60e31b8152600481018590526001600160a01b03909116906342966c68906024015f604051808303815f87803b158015612839575f5ffd5b505af115801561284b573d5f5f3e3d5ffd5b5050505082600d5f828254612860919061488a565b909155503390506001600160a01b0316857f272ddf3a7d8e3437f201a915f70018002dde14d6e057010019f45dd89bda3fca8986868b876040516128a895949392919061495d565b60405180910390a350505050610c4460015f516020614c305f395f51905f5255565b6060600a805480602002602001604051908101604052809291908181526020015f905b82821015612930578382905f5260205f2090600202016040518060400160405290815f8201548152602001600182015481525050815260200190600101906128ed565b50505050905090565b7fe1dcbdb91df27212a29bc27177c840cf2f819ecf2187432e1fac86c2dd5dfca961296381612fc4565b6001600160a01b03821661298a5760405163e6c4247b60e01b815260040160405180910390fd5b600180546001600160a01b038481166001600160a01b0319831681179093556040519116919082907f4ab5be82436d353e61ca18726e984e561f5c1cc7c6d38b29d2553c790434705a905f90a3505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03165f81158015612a205750825b90505f826001600160401b03166001148015612a3b5750303b155b905081158015612a49575080155b15612a675760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315612a9157845460ff60401b1916600160401b1785555b6001600160a01b0389161580612aae57506001600160a01b038816155b80612ac057506001600160a01b038716155b80612ad257506001600160a01b038616155b15612af05760405163e6c4247b60e01b815260040160405180910390fd5b612af8613a1d565b612b00613a25565b612b08613a35565b612b10613a1d565b612b5b6040518060400160405280601081526020016f43727970746f57617273457363726f7760801b815250604051806040016040528060018152602001603160f81b815250613a45565b5f80546001600160a01b03808b166001600160a01b031992831617835560018054918b1691909216179055612b90908a6130e2565b50612ba85f516020614b505f395f51905f528a6130e2565b50612bc05f516020614bd05f395f51905f528a6130e2565b50612beb7f189ab7a9244df0848122154315af71fe140f3db0fe014031783b0946b8c9d2e38a6130e2565b50612c167fe1dcbdb91df27212a29bc27177c840cf2f819ecf2187432e1fac86c2dd5dfca98a6130e2565b50612c2e5f516020614bb05f395f51905f528a6130e2565b50612c465f516020614b305f395f51905f52876130e2565b50612d7d6040805180820182526103e8815261232860208083019182525f808052600880835293517f5eff886ea0ce6ca488a3d6e336d6c0f75f46d19b42c06ce5ee98e42c96d256c75591517f5eff886ea0ce6ca488a3d6e336d6c0f75f46d19b42c06ce5ee98e42c96d256c855835180850185526109c48152611d4c8183019081526001845284835290517fad67d757c34507f157cacfa2e3153e9f260a2244f30428821be7be64587ac55f55517fad67d757c34507f157cacfa2e3153e9f260a2244f30428821be7be64587ac56055835180850190945261138880855284820190815260029092529190915290517f6add646517a5b0f6793cd5891b7937d28a5b2981a5d88ebc7cd776088fea904155517f6add646517a5b0f6793cd5891b7937d28a5b2981a5d88ebc7cd776088fea904255565b612edf6040805180820182525f8082526127106020808401918252600a805460018181018355828652955160029182027fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a88181019290925594517fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a99586015587518089018952683643aa6479860400008152612ee08186019081528454808a01865585895291519184028084019290925551908601558751808901895269010f1ad11b91008400008152613a988186019081528454808a01865585895291519184028084019290925551908601558751808901895269021e27c1806e59a400008152614e208186019081528454808a01865585895291519184028084019290925551908601558751808901909852690a968f44a75922a4000088526161a893880193845282549687018355919094529451939092029384019290925551910155565b8315612f2557845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050505050565b5f516020614b505f395f51905f52612f4781612fc4565b612f4f61307f565b612f57612fce565b5f83815260036020526040902060016009820154610100900460ff166004811115612f8457612f84614308565b14612fa25760405163b3eb737b60e01b815260040160405180910390fd5b612fad81858561355b565b50610ffc60015f516020614c305f395f51905f5255565b6113448133613a57565b5f516020614c305f395f51905f52805460011901612fff57604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b6040516001600160a01b038481166024830152838116604483015260648201839052610ee59186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050613a90565b60015f516020614c305f395f51905f5255565b5f516020614c105f395f51905f525460ff16156130af5760405163d93c066560e01b815260040160405180910390fd5b565b6040516001600160a01b03838116602483015260448201839052610ffc91859182169063a9059cbb9060640161303a565b5f5f516020614bf05f395f51905f526130fb8484611a39565b61317a575f848152602082815260408083206001600160a01b03871684529091529020805460ff191660011790556131303390565b6001600160a01b0316836001600160a01b0316857f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a46001915050610c44565b5f915050610c44565b5f5f516020614bf05f395f51905f5261319c8484611a39565b1561317a575f848152602082815260408083206001600160a01b0387168085529252808320805460ff1916905551339287917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a46001915050610c44565b613204613afc565b5f516020614c105f395f51905f52805460ff191681557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a150565b5f600a5f8154811061326f5761326f6148c5565b5f918252602090912060016002909202010154600a549091505b801561330757600a61329c60018361489d565b815481106132ac576132ac6148c5565b905f5260205f2090600202015f015483106132f557600a6132ce60018361489d565b815481106132de576132de6148c5565b905f5260205f209060020201600101549150613307565b806132ff816148b0565b915050613289565b50919050565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148061339357507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166133875f516020614b905f395f51905f52546001600160a01b031690565b6001600160a01b031614155b156130af5760405163703e46dd60e11b815260040160405180910390fd5b7f189ab7a9244df0848122154315af71fe140f3db0fe014031783b0946b8c9d2e36133db81612fc4565b6001600160a01b038216610d745760405163e6c4247b60e01b815260040160405180910390fd5b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561345c575060408051601f3d908101601f1916820190925261345991810190614946565b60015b61348457604051634c9c8ce360e01b81526001600160a01b03831660048201526024016119f6565b5f516020614b905f395f51905f5281146134b457604051632a87526960e21b8152600481018290526024016119f6565b610ffc8383613b2b565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146130af5760405163703e46dd60e11b815260040160405180910390fd5b5f610c44613513613b80565b8360405161190160f01b8152600281019290925260228201526042902090565b5f5f5f5f6135418686613b8e565b9250925092506135518282613bd7565b5090949350505050565b5f6003846002015461356d9190614910565b90505f61357d856004015461325b565b90505f61271061358d8385614910565b6135979190614927565b90505f8487600301546135aa919061488a565b6002549091506135ba838361488a565b11156135d957604051633270436b60e01b815260040160405180910390fd5b86546135ed906001600160a01b0316613c8f565b86546001600160a01b03165f9081526005602052604081205469021e19e0c9bab24000001161361c575f613649565b87546001600160a01b03165f908152600560205260409020546136499069021e19e0c9bab240000061489d565b90505f818411613659578361365b565b815b90505f613668828561488a565b60058b0189905560068b018390554260088c015560098b01805491925060029161ff0019166101008302179055508960030154600b5f8282546136ab919061489d565b9091555050600c8054905f6136bf836148b0565b909155506136cf9050828961488a565b60025f8282546136df919061489d565b9250508190555081600e5f8282546136f7919061488a565b909155505089546001600160a01b03165f908152600560205260408120805484929061372490849061488a565b909155505089545f54613744916001600160a01b039182169116836130b1565b895460038b015460408051918252602082018b9052810184905260608101889052608081018390526001600160a01b03909116908a907f4024f80853b266efb89e3f4a6e9441947877c98bea88e9fcee132a953bc460f89060a00160405180910390a350505050505050505050565b6001600160a01b0381165f908152600660205260409020546137d8906201518061488a565b42106113445750565b6137e961307f565b5f516020614c105f395f51905f52805460ff191660011781557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2583361323d565b7fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d10280546060915f516020614b705f395f51905f52916138679061498f565b80601f01602080910402602001604051908101604052809291908181526020018280546138939061498f565b80156138de5780601f106138b5576101008083540402835291602001916138de565b820191905f5260205f20905b8154815290600101906020018083116138c157829003601f168201915b505050505091505090565b7fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d10380546060915f516020614b705f395f51905f52916138679061498f565b42600883015560098201805461ff0019166103001790556003820154600b80545f9061395490849061489d565b9091555050600c8054905f613968836148b0565b9190505550816003015460025f828254613982919061488a565b90915550508154600383015460028401546040516001600160a01b039093169284927fbcc9159ec6fb734df3744d9a242dddb9ac631f6a31cac0aa8e9004efd5acf435926139d892918252602082015260400190565b60405180910390a35050565b5f83838342436040516020016139fe9594939291906149c1565b6040516020818303038152906040528051906020012090509392505050565b6130af613d17565b613a2d613d17565b6130af613d60565b613a3d613d17565b6130af613d80565b613a4d613d17565b610d748282613d88565b613a618282611a39565b610d745760405163e2517d3f60e01b81526001600160a01b0382166004820152602481018390526044016119f6565b5f5f60205f8451602086015f885af180613aaf576040513d5f823e3d81fd5b50505f513d91508115613ac6578060011415613ad3565b6001600160a01b0384163b155b15610ee557604051635274afe760e01b81526001600160a01b03851660048201526024016119f6565b5f516020614c105f395f51905f525460ff166130af57604051638dfc202b60e01b815260040160405180910390fd5b613b3482613de7565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2805115613b7857610ffc8282613e4a565b610d74613ebc565b5f613b89613edb565b905090565b5f5f5f8351604103613bc5576020840151604085015160608601515f1a613bb788828585613f4e565b955095509550505050613bd0565b505081515f91506002905b9250925092565b5f826003811115613bea57613bea614308565b03613bf3575050565b6001826003811115613c0757613c07614308565b03613c255760405163f645eedf60e01b815260040160405180910390fd5b6002826003811115613c3957613c39614308565b03613c5a5760405163fce698f760e01b8152600481018290526024016119f6565b6003826003811115613c6e57613c6e614308565b03610d74576040516335e2f38360e21b8152600481018290526024016119f6565b6001600160a01b0381165f90815260066020526040902054613cb4906201518061488a565b4210611344576001600160a01b0381165f8181526005602090815260408083208390556006825291829020429081905591519182527f3d00074868e580fc025cf52e0725371bc13c8ec2e5425a94ff7c32a1b133fcc9910160405180910390a250565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff166130af57604051631afcd79f60e31b815260040160405180910390fd5b613d68613d17565b5f516020614c105f395f51905f52805460ff19169055565b61306c613d17565b613d90613d17565b5f516020614b705f395f51905f527fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d102613dc98482614a5a565b5060038101613dd88382614a5a565b505f8082556001909101555050565b806001600160a01b03163b5f03613e1c57604051634c9c8ce360e01b81526001600160a01b03821660048201526024016119f6565b5f516020614b905f395f51905f5280546001600160a01b0319166001600160a01b0392909216919091179055565b60605f5f846001600160a01b031684604051613e669190614b14565b5f60405180830381855af49150503d805f8114613e9e576040519150601f19603f3d011682016040523d82523d5f602084013e613ea3565b606091505b5091509150613eb3858383614016565b95945050505050565b34156130af5760405163b398979f60e01b815260040160405180910390fd5b5f7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f613f05614075565b613f0d6140dd565b60408051602081019490945283019190915260608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841115613f8757505f9150600390508261400c565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015613fd8573d5f5f3e3d5ffd5b5050604051601f1901519150506001600160a01b03811661400357505f92506001915082905061400c565b92505f91508190505b9450945094915050565b60608261402b576140268261411f565b61406e565b815115801561404257506001600160a01b0384163b155b1561406b57604051639996b31560e01b81526001600160a01b03851660048201526024016119f6565b50805b9392505050565b5f5f516020614b705f395f51905f528161408d613829565b8051909150156140a557805160209091012092915050565b815480156140b4579392505050565b7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470935050505090565b5f5f516020614b705f395f51905f52816140f56138e9565b80519091501561410d57805160209091012092915050565b600182015480156140b4579392505050565b80511561412f5780518082602001fd5b60405163d6bda27560e01b815260040160405180910390fd5b6040518061016001604052805f6001600160a01b031681526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f60028111156141a5576141a5614308565b81526020015f905290565b5080545f8255600202905f5260205f209081019061134491905b808211156141e3575f80825560018201556002016141ca565b5090565b5f602082840312156141f7575f5ffd5b81356001600160e01b03198116811461406e575f5ffd5b80356001600160a01b0381168114612483575f5ffd5b5f60208284031215614234575f5ffd5b61406e8261420e565b5f8151808452602084019350602083015f5b8281101561426d57815186526020958601959091019060010161424f565b5093949350505050565b602081525f61406e602083018461423d565b5f60208284031215614299575f5ffd5b5035919050565b5f5f604083850312156142b1575f5ffd5b823591506142c16020840161420e565b90509250929050565b803560038110612483575f5ffd5b5f5f5f606084860312156142ea575f5ffd5b6142f3846142ca565b95602085013595506040909401359392505050565b634e487b7160e01b5f52602160045260245ffd5b6003811061432c5761432c614308565b9052565b6005811061432c5761432c614308565b80516001600160a01b031682526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e08301526101008101516101008301526101208101516143b361012084018261431c565b50610140810151610ffc610140840182614330565b604080825283519082018190525f9060208501906060840190835b8181101561440d576143f6838551614340565b6020939093019261016092909201916001016143e3565b50508381036020850152614421818661423d565b9695505050505050565b634e487b7160e01b5f52604160045260245ffd5b5f5f60408385031215614450575f5ffd5b6144598361420e565b915060208301356001600160401b03811115614473575f5ffd5b8301601f81018513614483575f5ffd5b80356001600160401b0381111561449c5761449c61442b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156144ca576144ca61442b565b6040528181528282016020018710156144e1575f5ffd5b816020840160208301375f602083830101528093505050509250929050565b5f5f5f83850360c0811215614513575f5ffd5b60a0811215614520575f5ffd5b5083925060a08401356001600160401b0381111561453c575f5ffd5b8401601f8101861361454c575f5ffd5b80356001600160401b03811115614561575f5ffd5b866020828401011115614572575f5ffd5b939660209190910195509293505050565b5f5f5f5f60808587031215614596575f5ffd5b843593506145a6602086016142ca565b93969395505050506040820135916060013590565b5f5b838110156145d55781810151838201526020016145bd565b50505f910152565b5f81518084526145f48160208601602086016145bb565b601f01601f19169290920160200192915050565b60ff60f81b8816815260e060208201525f61462660e08301896145dd565b828103604084015261463881896145dd565b606084018890526001600160a01b038716608085015260a0840186905283810360c0850152845180825260208087019350909101905f5b8181101561468d57835183526020938401939092019160010161466f565b50909b9a5050505050505050505050565b5f5f604083850312156146af575f5ffd5b6146b88361420e565b91506020830135600581106146cb575f5ffd5b809150509250929050565b8215158152610180810161406e6020830184614340565b5f602082840312156146fd575f5ffd5b61406e826142ca565b602081525f61406e60208301846145dd565b5f5f60208385031215614729575f5ffd5b82356001600160401b0381111561473e575f5ffd5b8301601f8101851361474e575f5ffd5b80356001600160401b03811115614763575f5ffd5b8560208260061b8401011115614777575f5ffd5b6020919091019590945092505050565b6101608101610c448284614340565b5f5f604083850312156147a7575f5ffd5b823591506142c1602084016142ca565b602080825282518282018190525f918401906040840190835b818110156147fa5783518051845260209081015181850152909301926040909201916001016147d0565b509095945050505050565b5f5f5f5f60808587031215614818575f5ffd5b6148218561420e565b935061482f6020860161420e565b925061483d6040860161420e565b915061484b6060860161420e565b905092959194509250565b5f5f60408385031215614867575f5ffd5b50508035926020909101359150565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610c4457610c44614876565b81810381811115610c4457610c44614876565b5f816148be576148be614876565b505f190190565b634e487b7160e01b5f52603260045260245ffd5b5f600182016148ea576148ea614876565b5060010190565b5f60208284031215614901575f5ffd5b8135801515811461406e575f5ffd5b8082028115828204841417610c4457610c44614876565b5f8261494157634e487b7160e01b5f52601260045260245ffd5b500490565b5f60208284031215614956575f5ffd5b5051919050565b858152602081018590526040810184905260a0810161497f606083018561431c565b8260808301529695505050505050565b600181811c908216806149a357607f821691505b60208210810361330757634e487b7160e01b5f52602260045260245ffd5b6bffffffffffffffffffffffff198660601b1681528460148201525f600385106149ed576149ed614308565b5060f89390931b60348401526035830191909152605582015260750192915050565b601f821115610ffc57805f5260205f20601f840160051c81016020851015614a345750805b601f840160051c820191505b81811015614a53575f8155600101614a40565b5050505050565b81516001600160401b03811115614a7357614a7361442b565b614a8781614a81845461498f565b84614a0f565b6020601f821160018114614ab9575f8315614aa25750848201515b5f19600385901b1c1916600184901b178455614a53565b5f84815260208120601f198516915b82811015614ae85787850151825560209485019460019092019101614ac8565b5084821015614b0557868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b5f8251614b258184602087016145bb565b919091019291505056fef7a14a339431c5b75d52ee00990f12734fece07deb6cc21a89286e2664bf2fcb1d93c87416ca7b54f0fb8323167b72760e8e2ec93d48660953897a150f97a8b4a16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d100360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc0f51adb3f49e4a9bbb17b3783f025995eaf8c24be2c8eefff214bdfda05ef94d65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033009b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a2646970667358221220529837257370ccf570a8a2813a63a005a1f57586ea37a69d89df59cbcb99110364736f6c634300081c0033
Deployed ByteCode
0x6080604052600436106103a8575f3560e01c806394fa2b8c116101e9578063c0b0e3fa11610108578063e9917c071161009d578063f72c0d8b1161006d578063f72c0d8b14610b75578063f8c8765e14610ba8578063feb6172414610bc7578063ff8cb6cb14610bf5575f5ffd5b8063e9917c0714610b01578063ee17254614610b20578063ef5053ad14610b35578063f0f4426014610b56575f5ffd5b8063d89135cd116100d8578063d89135cd14610a8b578063e1f1c4a714610aa0578063e63ab1e914610ab5578063e765c12214610ad5575f5ffd5b8063c0b0e3fa14610a04578063d11a57ec14610a24578063d547741f14610a57578063d687cd6214610a76575f5ffd5b8063a3600fcd1161017e578063b5192e3c1161014e578063b5192e3c1461097c578063b9b56ae41461099b578063bc4393a3146109ba578063beda1187146109e5575f5ffd5b8063a3600fcd146103e0578063ad1def1e14610900578063ad3cb1cc14610920578063adfae2251461095d575f5ffd5b80639cc71f3f116101b95780639cc71f3f146108665780639e12e8c814610891578063a217fddf146108a6578063a3316c28146108b9575f5ffd5b806394fa2b8c146107dc57806395836a69146107fb5780639a2bce8f1461081a5780639a399bec14610847575f5ffd5b80634f1ef286116102d5578063622f6bb31161026a578063817b1cd21161023a578063817b1cd21461076d5780638456cb591461078257806384b0196e1461079657806391d14854146107bd575f5ffd5b8063622f6bb3146106b75780636d750d80146106f157806374246b49146107115780637a5c08ae14610758575f5ffd5b80635c975abb116102a55780635c975abb1461060c5780635cb95a741461062f5780635effec881461066257806361d027b314610698575f5ffd5b80634f1ef286146105a757806352d1902d146105ba57806358b6043f146105ce5780635bf2d322146105ed575f5ffd5b80632a9248131161034b5780633d426be61161031b5780633d426be61461051c5780633f4ba83a1461054957806341d636a21461055d5780634d875ef614610588575f5ffd5b80632a924813146104a05780632f2ff15d146104bf5780633230f838146104de57806336568abe146104fd575f5ffd5b80631d583e0d116103865780631d583e0d1461042e5780631da0bcd81461044f5780631f079e011461046c578063248a9ca314610481575f5ffd5b806301ffc9a7146103ac578063098cf869146103e0578063147e0d9114610402575b5f5ffd5b3480156103b7575f5ffd5b506103cb6103c63660046141e7565b610c14565b60405190151581526020015b60405180910390f35b3480156103eb575f5ffd5b506103f4600381565b6040519081526020016103d7565b34801561040d575f5ffd5b5061042161041c366004614224565b610c4a565b6040516103d79190614277565b348015610439575f5ffd5b5061044d610448366004614289565b610cb3565b005b34801561045a575f5ffd5b506103f469021e19e0c9bab240000081565b348015610477575f5ffd5b506103f4600c5481565b34801561048c575f5ffd5b506103f461049b366004614289565b610d78565b3480156104ab575f5ffd5b5061044d6104ba366004614289565b610d98565b3480156104ca575f5ffd5b5061044d6104d93660046142a0565b610ec9565b3480156104e9575f5ffd5b5061044d6104f83660046142d8565b610eeb565b348015610508575f5ffd5b5061044d6105173660046142a0565b610fc9565b348015610527575f5ffd5b5061053b610536366004614224565b611001565b6040516103d79291906143c8565b348015610554575f5ffd5b5061044d611325565b348015610568575f5ffd5b506103f4610577366004614224565b60056020525f908152604090205481565b348015610593575f5ffd5b506103f46105a2366004614289565b611347565b61044d6105b536600461443f565b611351565b3480156105c5575f5ffd5b506103f461136c565b3480156105d9575f5ffd5b5061044d6105e8366004614500565b611387565b3480156105f8575f5ffd5b50610421610607366004614224565b611625565b348015610617575f5ffd5b505f516020614c105f395f51905f525460ff166103cb565b34801561063a575f5ffd5b506103f47f80e43b71a3dc4270c5b6dcc6b0c385dd9bc98b168b9086bb845a8921c3342e8b81565b34801561066d575f5ffd5b505f54610680906001600160a01b031681565b6040516001600160a01b0390911681526020016103d7565b3480156106a3575f5ffd5b50600154610680906001600160a01b031681565b3480156106c2575f5ffd5b506106d66106d1366004614224565b6117fa565b604080519384526020840192909252908201526060016103d7565b3480156106fc575f5ffd5b506103f45f516020614bb05f395f51905f5281565b34801561071c575f5ffd5b5061073061072b366004614583565b61184c565b604080519586526020860194909452928401919091526060830152608082015260a0016103d7565b348015610763575f5ffd5b506103f460025481565b348015610778575f5ffd5b506103f4600b5481565b34801561078d575f5ffd5b5061044d61196c565b3480156107a1575f5ffd5b506107aa61198b565b6040516103d79796959493929190614608565b3480156107c8575f5ffd5b506103cb6107d73660046142a0565b611a39565b3480156107e7575f5ffd5b506103cb6107f6366004614289565b611a6f565b348015610806575f5ffd5b5061042161081536600461469e565b611aa3565b348015610825575f5ffd5b50610839610834366004614289565b611c99565b6040516103d79291906146d6565b348015610852575f5ffd5b5061044d6108613660046142a0565b611dae565b348015610871575f5ffd5b506103f4610880366004614224565b60066020525f908152604090205481565b34801561089c575f5ffd5b506103f4610e1081565b3480156108b1575f5ffd5b506103f45f81565b3480156108c4575f5ffd5b506108eb6108d33660046146ed565b60086020525f90815260409020805460019091015482565b604080519283526020830191909152016103d7565b34801561090b575f5ffd5b506103f45f516020614b505f395f51905f5281565b34801561092b575f5ffd5b50610950604051806040016040528060058152602001640352e302e360dc1b81525081565b6040516103d79190614706565b348015610968575f5ffd5b506108eb610977366004614289565b611ec7565b348015610987575f5ffd5b5061044d610996366004614500565b611ef3565b3480156109a6575f5ffd5b5061044d6109b5366004614289565b61216f565b3480156109c5575f5ffd5b506103f46109d4366004614224565b60076020525f908152604090205481565b3480156109f0575f5ffd5b5061044d6109ff366004614718565b612202565b348015610a0f575f5ffd5b506103f45f516020614b305f395f51905f5281565b348015610a2f575f5ffd5b506103f47fe1dcbdb91df27212a29bc27177c840cf2f819ecf2187432e1fac86c2dd5dfca981565b348015610a62575f5ffd5b5061044d610a713660046142a0565b61233e565b348015610a81575f5ffd5b506103f461070881565b348015610a96575f5ffd5b506103f4600d5481565b348015610aab575f5ffd5b506103f461271081565b348015610ac0575f5ffd5b506103f45f516020614bd05f395f51905f5281565b348015610ae0575f5ffd5b50610af4610aef366004614289565b61235a565b6040516103d79190614787565b348015610b0c575f5ffd5b506103f4610b1b366004614796565b612488565b348015610b2b575f5ffd5b506103f4600e5481565b348015610b40575f5ffd5b50610b496128ca565b6040516103d791906147b7565b348015610b61575f5ffd5b5061044d610b70366004614224565b612939565b348015610b80575f5ffd5b506103f47f189ab7a9244df0848122154315af71fe140f3db0fe014031783b0946b8c9d2e381565b348015610bb3575f5ffd5b5061044d610bc2366004614805565b6129dc565b348015610bd2575f5ffd5b506103cb610be1366004614289565b60096020525f908152604090205460ff1681565b348015610c00575f5ffd5b5061044d610c0f366004614856565b612f30565b5f6001600160e01b03198216637965db0b60e01b1480610c4457506301ffc9a760e01b6001600160e01b03198316145b92915050565b6001600160a01b0381165f90815260046020908152604091829020805483518184028101840190945280845260609392830182828015610ca757602002820191905f5260205f20905b815481526020019060010190808311610c93575b50505050509050919050565b5f516020614bb05f395f51905f52610cca81612fc4565b610cd2612fce565b815f03610cf25760405163162908e360e11b815260040160405180910390fd5b8160025f828254610d03919061488a565b90915550505f54610d1f906001600160a01b0316333085613005565b60025460408051848152602081019290925233917f49740176a81d28f933051e26004df983307376c5a93665e9e63f2e6b9d671282910160405180910390a2610d7460015f516020614c305f395f51905f5255565b5050565b5f9081525f516020614bf05f395f51905f52602052604090206001015490565b5f516020614b505f395f51905f52610daf81612fc4565b610db761307f565b610dbf612fce565b5f82815260036020526040902060016009820154610100900460ff166004811115610dec57610dec614308565b14610e0a5760405163b3eb737b60e01b815260040160405180910390fd5b600381015460098201805461ff001916610400179055426008830155600b80548291905f90610e3a90849061489d565b9091555050600c8054905f610e4e836148b0565b909155505081545f54610e6e916001600160a01b039182169116836130b1565b81546040518281526001600160a01b039091169085907faab1aafc363800fe14e0ad1e98986ec2cb2aecfc657f05c53ddd2d485bc81aff9060200160405180910390a35050610d7460015f516020614c305f395f51905f5255565b610ed282610d78565b610edb81612fc4565b610ee583836130e2565b50505050565b5f610ef581612fc4565b612710610f02838561488a565b14610f2057604051634a41f87560e01b815260040160405180910390fd5b60405180604001604052808481526020018381525060085f866002811115610f4a57610f4a614308565b6002811115610f5b57610f5b614308565b81526020808201929092526040015f2082518155910151600190910155836002811115610f8a57610f8a614308565b60408051858152602081018590527f5595837bca534fb8707a86302c437184a0c387b68ed44e7f31c9b13be31394a7910160405180910390a250505050565b6001600160a01b0381163314610ff25760405163334bd91960e11b815260040160405180910390fd5b610ffc8282613183565b505050565b6001600160a01b0381165f90815260046020908152604080832080548251818502810185019093528083526060948594909392919083018282801561106357602002820191905f5260205f20905b81548152602001906001019080831161104f575b509394505f935083925050505b82518110156110e1575f60035f85848151811061108f5761108f6148c5565b602002602001015181526020019081526020015f2060090160019054906101000a900460ff1660048111156110c6576110c6614308565b146110d957816110d5816148d9565b9250505b600101611070565b50806001600160401b038111156110fa576110fa61442b565b60405190808252806020026020018201604052801561113357816020015b611120614148565b8152602001906001900390816111185790505b509350806001600160401b0381111561114e5761114e61442b565b604051908082528060200260200182016040528015611177578160200160208202803683370190505b5092505f805b835181101561131c575f60035f86848151811061119c5761119c6148c5565b60209081029190910181015182528181019290925260409081015f2081516101608101835281546001600160a01b03168152600182015493810193909352600280820154928401929092526003810154606084015260048101546080840152600581015460a0840152600681015460c0840152600781015460e084015260088101546101008401526009810154909161012084019160ff169081111561124457611244614308565b600281111561125557611255614308565b81526020016009820160019054906101000a900460ff16600481111561127d5761127d614308565b600481111561128e5761128e614308565b90525090505f81610140015160048111156112ab576112ab614308565b1461131357808784815181106112c3576112c36148c5565b60200260200101819052508482815181106112e0576112e06148c5565b60200260200101518684815181106112fa576112fa6148c5565b60209081029190910101528261130f816148d9565b9350505b5060010161117d565b50505050915091565b5f516020614bd05f395f51905f5261133c81612fc4565b6113446131fc565b50565b5f610c448261325b565b61135961330d565b611362826133b1565b610d748282613402565b5f6113756134be565b505f516020614b905f395f51905f5290565b61138f61307f565b611397612fce565b82355f90815260036020526040902060016009820154610100900460ff1660048111156113c6576113c6614308565b146113e45760405163b3eb737b60e01b815260040160405180910390fd5b80546001600160a01b0316331461140e57604051631a0d995360e31b815260040160405180910390fd5b61141e60808501606086016148f1565b61143b57604051636f756dcf60e01b815260040160405180910390fd5b836080013542111561146057604051630819bdcd60e01b815260040160405180910390fd5b604080518535602080830191909152608087013582840152825180830384018152606090920183528151918101919091205f81815260099092529190205460ff16156114be57604051623f613760e71b815260040160405180910390fd5b5f7f80e43b71a3dc4270c5b6dcc6b0c385dd9bc98b168b9086bb845a8921c3342e8b86356114f26040890160208a01614224565b604089013561150760808b0160608c016148f1565b6040805160208101969096528501939093526001600160a01b03909116606084015260808381019190915290151560a083015287013560c082015260e0016040516020818303038152906040528051906020012090505f61156782613507565b90505f6115a98288888080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061353392505050565b90506115c25f516020614b305f395f51905f5282611a39565b6115df57604051638baa579f60e01b815260040160405180910390fd5b5f8481526009602052604090819020805460ff1916600117905561160a9086908a35908b013561355b565b5050505050610ffc60015f516020614c305f395f51905f5255565b6001600160a01b0381165f90815260046020908152604080832080548251818502810185019093528083526060949383018282801561168157602002820191905f5260205f20905b81548152602001906001019080831161166d575b509394505f935083925050505b825181101561170057600160035f8584815181106116ae576116ae6148c5565b602002602001015181526020019081526020015f2060090160019054906101000a900460ff1660048111156116e5576116e5614308565b036116f857816116f4816148d9565b9250505b60010161168e565b50806001600160401b038111156117195761171961442b565b604051908082528060200260200182016040528015611742578160200160208202803683370190505b5092505f805b83518110156117f157600160035f868481518110611768576117686148c5565b602002602001015181526020019081526020015f2060090160019054906101000a900460ff16600481111561179f5761179f614308565b036117e9578381815181106117b6576117b66148c5565b60200260200101518583815181106117d0576117d06148c5565b6020908102919091010152816117e5816148d9565b9250505b600101611748565b50505050919050565b5f5f5f611806846137b3565b6001600160a01b0384165f90815260056020526040902054925069021e19e0c9bab2400000915082821161183a575f611844565b611844838361489d565b929491935050565b5f5f5f5f5f5f60085f8a600281111561186757611867614308565b600281111561187857611878614308565b81526020019081526020015f206040518060400160405290815f82015481526020016001820154815250509050612710815f01518b6118b79190614910565b6118c19190614927565b95506118cd868b61489d565b94505f6118db600388614910565b90505f6118e78a61325b565b90506127106118f68284614910565b6119009190614927565b945061190c898861488a565b335f9081526005602052604081205491975069021e19e0c9bab24000008210611935575f611949565b6119498269021e19e0c9bab240000061489d565b9050808711611958578661195a565b805b95505050505050945094509450945094565b5f516020614bd05f395f51905f5261198381612fc4565b6113446137e1565b5f60608082808083815f516020614b705f395f51905f5280549091501580156119b657506001810154155b6119ff5760405162461bcd60e51b81526020600482015260156024820152741152540dcc4c8e88155b9a5b9a5d1a585b1a5e9959605a1b60448201526064015b60405180910390fd5b611a07613829565b611a0f6138e9565b604080515f80825260208201909252600f60f81b9c939b5091995046985030975095509350915050565b5f9182525f516020614bf05f395f51905f52602090815260408084206001600160a01b0393909316845291905290205460ff1690565b5f60015f83815260036020526040902060090154610100900460ff166004811115611a9c57611a9c614308565b1492915050565b6001600160a01b0382165f908152600460209081526040808320805482518185028101850190935280835260609493830182828015611aff57602002820191905f5260205f20905b815481526020019060010190808311611aeb575b509394505f935083925050505b8251811015611b8e57846004811115611b2757611b27614308565b60035f858481518110611b3c57611b3c6148c5565b602002602001015181526020019081526020015f2060090160019054906101000a900460ff166004811115611b7357611b73614308565b03611b865781611b82816148d9565b9250505b600101611b0c565b50806001600160401b03811115611ba757611ba761442b565b604051908082528060200260200182016040528015611bd0578160200160208202803683370190505b5092505f805b8351811015611c8f57856004811115611bf157611bf1614308565b60035f868481518110611c0657611c066148c5565b602002602001015181526020019081526020015f2060090160019054906101000a900460ff166004811115611c3d57611c3d614308565b03611c8757838181518110611c5457611c546148c5565b6020026020010151858381518110611c6e57611c6e6148c5565b602090810291909101015281611c83816148d9565b9250505b600101611bd6565b5050505092915050565b5f611ca2614148565b5f8381526003602081815260409283902083516101608101855281546001600160a01b031681526001820154928101929092526002808201549483019490945291820154606082015260048201546080820152600582015460a0820152600682015460c0820152600782015460e082015260088201546101008201526009820154909261012084019160ff1690811115611d3e57611d3e614308565b6002811115611d4f57611d4f614308565b81526020016009820160019054906101000a900460ff166004811115611d7757611d77614308565b6004811115611d8857611d88614308565b90525090505f8161014001516004811115611da557611da5614308565b14159150915091565b5f516020614bb05f395f51905f52611dc581612fc4565b611dcd612fce565b825f03611ded5760405163162908e360e11b815260040160405180910390fd5b6001600160a01b038216611e145760405163e6c4247b60e01b815260040160405180910390fd5b600254831115611e3757604051633270436b60e01b815260040160405180910390fd5b8260025f828254611e48919061489d565b90915550505f54611e63906001600160a01b031683856130b1565b816001600160a01b03167f0639db63a998ac6f7999198717a150e8512c78f7a9b9f747a8a16687f7d6cbcb84600254604051611ea9929190918252602082015260400190565b60405180910390a2610ffc60015f516020614c305f395f51905f5255565b600a8181548110611ed6575f80fd5b5f9182526020909120600290910201805460019091015490915082565b611efb61307f565b611f03612fce565b82355f90815260036020526040902060016009820154610100900460ff166004811115611f3257611f32614308565b14611f505760405163b3eb737b60e01b815260040160405180910390fd5b80546001600160a01b03163314611f7a57604051631a0d995360e31b815260040160405180910390fd5b611f8a60808501606086016148f1565b15611fa857604051636f756dcf60e01b815260040160405180910390fd5b8360800135421115611fcd57604051630819bdcd60e01b815260040160405180910390fd5b604080518535602080830191909152608087013582840152825180830384018152606090920183528151918101919091205f81815260099092529190205460ff161561202b57604051623f613760e71b815260040160405180910390fd5b5f7f80e43b71a3dc4270c5b6dcc6b0c385dd9bc98b168b9086bb845a8921c3342e8b863561205f6040890160208a01614224565b604089013561207460808b0160608c016148f1565b6040805160208101969096528501939093526001600160a01b03909116606084015260808381019190915290151560a083015287013560c082015260e0016040516020818303038152906040528051906020012090505f6120d482613507565b90505f6121168288888080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061353392505050565b905061212f5f516020614b305f395f51905f5282611a39565b61214c57604051638baa579f60e01b815260040160405180910390fd5b5f848152600960205260409020805460ff1916600117905561160a858935613927565b5f516020614b505f395f51905f5261218681612fc4565b61218e61307f565b612196612fce565b5f82815260036020526040902060016009820154610100900460ff1660048111156121c3576121c3614308565b146121e15760405163b3eb737b60e01b815260040160405180910390fd5b6121eb8184613927565b50610d7460015f516020614c305f395f51905f5255565b5f61220c81612fc4565b5f82900361222d5760405163036899eb60e31b815260040160405180910390fd5b612238600a5f6141b0565b5f5b82811015612305575f8111801561228f5750838361225960018461489d565b818110612268576122686148c5565b9050604002015f0135848483818110612283576122836148c5565b9050604002015f013511155b156122ad5760405163036899eb60e31b815260040160405180910390fd5b600a8484838181106122c1576122c16148c5565b83546001810185555f94855260209094206040909102929092019260020290910190506122fb828281358155602090910135600190910155565b505060010161223a565b506040518281527fcdeaf1302c7aea52ed757d0176c489a3185e2db09a913c747098c03675c56e019060200160405180910390a1505050565b61234782610d78565b61235081612fc4565b610ee58383613183565b612362614148565b5f8281526003602081815260409283902083516101608101855281546001600160a01b031681526001820154928101929092526002808201549483019490945291820154606082015260048201546080820152600582015460a0820152600682015460c0820152600782015460e082015260088201546101008201526009820154909261012084019160ff16908111156123fe576123fe614308565b600281111561240f5761240f614308565b81526020016009820160019054906101000a900460ff16600481111561243757612437614308565b600481111561244857612448614308565b90525090505f816101400151600481111561246557612465614308565b0361248357604051638c877d2160e01b815260040160405180910390fd5b919050565b5f61249161307f565b612499612fce565b825f036124b95760405163162908e360e11b815260040160405180910390fd5b5f60085f8460028111156124cf576124cf614308565b60028111156124e0576124e0614308565b81526020019081526020015f206040518060400160405290815f82015481526020016001820154815250509050805f01515f036125305760405163eff9b19d60e01b815260040160405180910390fd5b80515f90612710906125429087614910565b61254c9190614927565b90505f612559828761489d565b5f8054919250906001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa1580156125b1573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125d59190614946565b90506125e23388886139e4565b94505f5f86815260036020526040902060090154610100900460ff16600481111561260f5761260f614308565b1461262d576040516336c9ceb960e01b815260040160405180910390fd5b6040518061016001604052806126403390565b6001600160a01b031681526020018881526020018481526020018381526020018281526020015f81526020015f81526020014281526020015f815260200187600281111561269057612690614308565b8152600160209182018190525f8881526003808452604091829020855181546001600160a01b0319166001600160a01b039091161781559385015184840155908401516002808501919091556060850151918401919091556080840151600484015560a0840151600584015560c0840151600684015560e0840151600784015561010084015160088401556101208401516009840180549193909260ff1990921691849081111561274357612743614308565b021790555061014082015160098201805461ff00191661010083600481111561276e5761276e614308565b021790555090505060045f6127803390565b6001600160a01b031681526020808201929092526040015f9081208054600181018255908252918120909101869055600b80548492906127c190849061488a565b9091555050600c8054905f6127d5836148d9565b91905055506127f76127e43390565b5f546001600160a01b031690308a613005565b5f54604051630852cd8d60e31b8152600481018590526001600160a01b03909116906342966c68906024015f604051808303815f87803b158015612839575f5ffd5b505af115801561284b573d5f5f3e3d5ffd5b5050505082600d5f828254612860919061488a565b909155503390506001600160a01b0316857f272ddf3a7d8e3437f201a915f70018002dde14d6e057010019f45dd89bda3fca8986868b876040516128a895949392919061495d565b60405180910390a350505050610c4460015f516020614c305f395f51905f5255565b6060600a805480602002602001604051908101604052809291908181526020015f905b82821015612930578382905f5260205f2090600202016040518060400160405290815f8201548152602001600182015481525050815260200190600101906128ed565b50505050905090565b7fe1dcbdb91df27212a29bc27177c840cf2f819ecf2187432e1fac86c2dd5dfca961296381612fc4565b6001600160a01b03821661298a5760405163e6c4247b60e01b815260040160405180910390fd5b600180546001600160a01b038481166001600160a01b0319831681179093556040519116919082907f4ab5be82436d353e61ca18726e984e561f5c1cc7c6d38b29d2553c790434705a905f90a3505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff1615906001600160401b03165f81158015612a205750825b90505f826001600160401b03166001148015612a3b5750303b155b905081158015612a49575080155b15612a675760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315612a9157845460ff60401b1916600160401b1785555b6001600160a01b0389161580612aae57506001600160a01b038816155b80612ac057506001600160a01b038716155b80612ad257506001600160a01b038616155b15612af05760405163e6c4247b60e01b815260040160405180910390fd5b612af8613a1d565b612b00613a25565b612b08613a35565b612b10613a1d565b612b5b6040518060400160405280601081526020016f43727970746f57617273457363726f7760801b815250604051806040016040528060018152602001603160f81b815250613a45565b5f80546001600160a01b03808b166001600160a01b031992831617835560018054918b1691909216179055612b90908a6130e2565b50612ba85f516020614b505f395f51905f528a6130e2565b50612bc05f516020614bd05f395f51905f528a6130e2565b50612beb7f189ab7a9244df0848122154315af71fe140f3db0fe014031783b0946b8c9d2e38a6130e2565b50612c167fe1dcbdb91df27212a29bc27177c840cf2f819ecf2187432e1fac86c2dd5dfca98a6130e2565b50612c2e5f516020614bb05f395f51905f528a6130e2565b50612c465f516020614b305f395f51905f52876130e2565b50612d7d6040805180820182526103e8815261232860208083019182525f808052600880835293517f5eff886ea0ce6ca488a3d6e336d6c0f75f46d19b42c06ce5ee98e42c96d256c75591517f5eff886ea0ce6ca488a3d6e336d6c0f75f46d19b42c06ce5ee98e42c96d256c855835180850185526109c48152611d4c8183019081526001845284835290517fad67d757c34507f157cacfa2e3153e9f260a2244f30428821be7be64587ac55f55517fad67d757c34507f157cacfa2e3153e9f260a2244f30428821be7be64587ac56055835180850190945261138880855284820190815260029092529190915290517f6add646517a5b0f6793cd5891b7937d28a5b2981a5d88ebc7cd776088fea904155517f6add646517a5b0f6793cd5891b7937d28a5b2981a5d88ebc7cd776088fea904255565b612edf6040805180820182525f8082526127106020808401918252600a805460018181018355828652955160029182027fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a88181019290925594517fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a99586015587518089018952683643aa6479860400008152612ee08186019081528454808a01865585895291519184028084019290925551908601558751808901895269010f1ad11b91008400008152613a988186019081528454808a01865585895291519184028084019290925551908601558751808901895269021e27c1806e59a400008152614e208186019081528454808a01865585895291519184028084019290925551908601558751808901909852690a968f44a75922a4000088526161a893880193845282549687018355919094529451939092029384019290925551910155565b8315612f2557845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050505050565b5f516020614b505f395f51905f52612f4781612fc4565b612f4f61307f565b612f57612fce565b5f83815260036020526040902060016009820154610100900460ff166004811115612f8457612f84614308565b14612fa25760405163b3eb737b60e01b815260040160405180910390fd5b612fad81858561355b565b50610ffc60015f516020614c305f395f51905f5255565b6113448133613a57565b5f516020614c305f395f51905f52805460011901612fff57604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b6040516001600160a01b038481166024830152838116604483015260648201839052610ee59186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050613a90565b60015f516020614c305f395f51905f5255565b5f516020614c105f395f51905f525460ff16156130af5760405163d93c066560e01b815260040160405180910390fd5b565b6040516001600160a01b03838116602483015260448201839052610ffc91859182169063a9059cbb9060640161303a565b5f5f516020614bf05f395f51905f526130fb8484611a39565b61317a575f848152602082815260408083206001600160a01b03871684529091529020805460ff191660011790556131303390565b6001600160a01b0316836001600160a01b0316857f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a46001915050610c44565b5f915050610c44565b5f5f516020614bf05f395f51905f5261319c8484611a39565b1561317a575f848152602082815260408083206001600160a01b0387168085529252808320805460ff1916905551339287917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a46001915050610c44565b613204613afc565b5f516020614c105f395f51905f52805460ff191681557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a150565b5f600a5f8154811061326f5761326f6148c5565b5f918252602090912060016002909202010154600a549091505b801561330757600a61329c60018361489d565b815481106132ac576132ac6148c5565b905f5260205f2090600202015f015483106132f557600a6132ce60018361489d565b815481106132de576132de6148c5565b905f5260205f209060020201600101549150613307565b806132ff816148b0565b915050613289565b50919050565b306001600160a01b037f00000000000000000000000014c38e01ea9d5fce80a97573e558be9c46ba11c116148061339357507f00000000000000000000000014c38e01ea9d5fce80a97573e558be9c46ba11c16001600160a01b03166133875f516020614b905f395f51905f52546001600160a01b031690565b6001600160a01b031614155b156130af5760405163703e46dd60e11b815260040160405180910390fd5b7f189ab7a9244df0848122154315af71fe140f3db0fe014031783b0946b8c9d2e36133db81612fc4565b6001600160a01b038216610d745760405163e6c4247b60e01b815260040160405180910390fd5b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561345c575060408051601f3d908101601f1916820190925261345991810190614946565b60015b61348457604051634c9c8ce360e01b81526001600160a01b03831660048201526024016119f6565b5f516020614b905f395f51905f5281146134b457604051632a87526960e21b8152600481018290526024016119f6565b610ffc8383613b2b565b306001600160a01b037f00000000000000000000000014c38e01ea9d5fce80a97573e558be9c46ba11c116146130af5760405163703e46dd60e11b815260040160405180910390fd5b5f610c44613513613b80565b8360405161190160f01b8152600281019290925260228201526042902090565b5f5f5f5f6135418686613b8e565b9250925092506135518282613bd7565b5090949350505050565b5f6003846002015461356d9190614910565b90505f61357d856004015461325b565b90505f61271061358d8385614910565b6135979190614927565b90505f8487600301546135aa919061488a565b6002549091506135ba838361488a565b11156135d957604051633270436b60e01b815260040160405180910390fd5b86546135ed906001600160a01b0316613c8f565b86546001600160a01b03165f9081526005602052604081205469021e19e0c9bab24000001161361c575f613649565b87546001600160a01b03165f908152600560205260409020546136499069021e19e0c9bab240000061489d565b90505f818411613659578361365b565b815b90505f613668828561488a565b60058b0189905560068b018390554260088c015560098b01805491925060029161ff0019166101008302179055508960030154600b5f8282546136ab919061489d565b9091555050600c8054905f6136bf836148b0565b909155506136cf9050828961488a565b60025f8282546136df919061489d565b9250508190555081600e5f8282546136f7919061488a565b909155505089546001600160a01b03165f908152600560205260408120805484929061372490849061488a565b909155505089545f54613744916001600160a01b039182169116836130b1565b895460038b015460408051918252602082018b9052810184905260608101889052608081018390526001600160a01b03909116908a907f4024f80853b266efb89e3f4a6e9441947877c98bea88e9fcee132a953bc460f89060a00160405180910390a350505050505050505050565b6001600160a01b0381165f908152600660205260409020546137d8906201518061488a565b42106113445750565b6137e961307f565b5f516020614c105f395f51905f52805460ff191660011781557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2583361323d565b7fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d10280546060915f516020614b705f395f51905f52916138679061498f565b80601f01602080910402602001604051908101604052809291908181526020018280546138939061498f565b80156138de5780601f106138b5576101008083540402835291602001916138de565b820191905f5260205f20905b8154815290600101906020018083116138c157829003601f168201915b505050505091505090565b7fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d10380546060915f516020614b705f395f51905f52916138679061498f565b42600883015560098201805461ff0019166103001790556003820154600b80545f9061395490849061489d565b9091555050600c8054905f613968836148b0565b9190505550816003015460025f828254613982919061488a565b90915550508154600383015460028401546040516001600160a01b039093169284927fbcc9159ec6fb734df3744d9a242dddb9ac631f6a31cac0aa8e9004efd5acf435926139d892918252602082015260400190565b60405180910390a35050565b5f83838342436040516020016139fe9594939291906149c1565b6040516020818303038152906040528051906020012090509392505050565b6130af613d17565b613a2d613d17565b6130af613d60565b613a3d613d17565b6130af613d80565b613a4d613d17565b610d748282613d88565b613a618282611a39565b610d745760405163e2517d3f60e01b81526001600160a01b0382166004820152602481018390526044016119f6565b5f5f60205f8451602086015f885af180613aaf576040513d5f823e3d81fd5b50505f513d91508115613ac6578060011415613ad3565b6001600160a01b0384163b155b15610ee557604051635274afe760e01b81526001600160a01b03851660048201526024016119f6565b5f516020614c105f395f51905f525460ff166130af57604051638dfc202b60e01b815260040160405180910390fd5b613b3482613de7565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2805115613b7857610ffc8282613e4a565b610d74613ebc565b5f613b89613edb565b905090565b5f5f5f8351604103613bc5576020840151604085015160608601515f1a613bb788828585613f4e565b955095509550505050613bd0565b505081515f91506002905b9250925092565b5f826003811115613bea57613bea614308565b03613bf3575050565b6001826003811115613c0757613c07614308565b03613c255760405163f645eedf60e01b815260040160405180910390fd5b6002826003811115613c3957613c39614308565b03613c5a5760405163fce698f760e01b8152600481018290526024016119f6565b6003826003811115613c6e57613c6e614308565b03610d74576040516335e2f38360e21b8152600481018290526024016119f6565b6001600160a01b0381165f90815260066020526040902054613cb4906201518061488a565b4210611344576001600160a01b0381165f8181526005602090815260408083208390556006825291829020429081905591519182527f3d00074868e580fc025cf52e0725371bc13c8ec2e5425a94ff7c32a1b133fcc9910160405180910390a250565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff166130af57604051631afcd79f60e31b815260040160405180910390fd5b613d68613d17565b5f516020614c105f395f51905f52805460ff19169055565b61306c613d17565b613d90613d17565b5f516020614b705f395f51905f527fa16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d102613dc98482614a5a565b5060038101613dd88382614a5a565b505f8082556001909101555050565b806001600160a01b03163b5f03613e1c57604051634c9c8ce360e01b81526001600160a01b03821660048201526024016119f6565b5f516020614b905f395f51905f5280546001600160a01b0319166001600160a01b0392909216919091179055565b60605f5f846001600160a01b031684604051613e669190614b14565b5f60405180830381855af49150503d805f8114613e9e576040519150601f19603f3d011682016040523d82523d5f602084013e613ea3565b606091505b5091509150613eb3858383614016565b95945050505050565b34156130af5760405163b398979f60e01b815260040160405180910390fd5b5f7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f613f05614075565b613f0d6140dd565b60408051602081019490945283019190915260608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841115613f8757505f9150600390508261400c565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa158015613fd8573d5f5f3e3d5ffd5b5050604051601f1901519150506001600160a01b03811661400357505f92506001915082905061400c565b92505f91508190505b9450945094915050565b60608261402b576140268261411f565b61406e565b815115801561404257506001600160a01b0384163b155b1561406b57604051639996b31560e01b81526001600160a01b03851660048201526024016119f6565b50805b9392505050565b5f5f516020614b705f395f51905f528161408d613829565b8051909150156140a557805160209091012092915050565b815480156140b4579392505050565b7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470935050505090565b5f5f516020614b705f395f51905f52816140f56138e9565b80519091501561410d57805160209091012092915050565b600182015480156140b4579392505050565b80511561412f5780518082602001fd5b60405163d6bda27560e01b815260040160405180910390fd5b6040518061016001604052805f6001600160a01b031681526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f60028111156141a5576141a5614308565b81526020015f905290565b5080545f8255600202905f5260205f209081019061134491905b808211156141e3575f80825560018201556002016141ca565b5090565b5f602082840312156141f7575f5ffd5b81356001600160e01b03198116811461406e575f5ffd5b80356001600160a01b0381168114612483575f5ffd5b5f60208284031215614234575f5ffd5b61406e8261420e565b5f8151808452602084019350602083015f5b8281101561426d57815186526020958601959091019060010161424f565b5093949350505050565b602081525f61406e602083018461423d565b5f60208284031215614299575f5ffd5b5035919050565b5f5f604083850312156142b1575f5ffd5b823591506142c16020840161420e565b90509250929050565b803560038110612483575f5ffd5b5f5f5f606084860312156142ea575f5ffd5b6142f3846142ca565b95602085013595506040909401359392505050565b634e487b7160e01b5f52602160045260245ffd5b6003811061432c5761432c614308565b9052565b6005811061432c5761432c614308565b80516001600160a01b031682526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e08301526101008101516101008301526101208101516143b361012084018261431c565b50610140810151610ffc610140840182614330565b604080825283519082018190525f9060208501906060840190835b8181101561440d576143f6838551614340565b6020939093019261016092909201916001016143e3565b50508381036020850152614421818661423d565b9695505050505050565b634e487b7160e01b5f52604160045260245ffd5b5f5f60408385031215614450575f5ffd5b6144598361420e565b915060208301356001600160401b03811115614473575f5ffd5b8301601f81018513614483575f5ffd5b80356001600160401b0381111561449c5761449c61442b565b604051601f8201601f19908116603f011681016001600160401b03811182821017156144ca576144ca61442b565b6040528181528282016020018710156144e1575f5ffd5b816020840160208301375f602083830101528093505050509250929050565b5f5f5f83850360c0811215614513575f5ffd5b60a0811215614520575f5ffd5b5083925060a08401356001600160401b0381111561453c575f5ffd5b8401601f8101861361454c575f5ffd5b80356001600160401b03811115614561575f5ffd5b866020828401011115614572575f5ffd5b939660209190910195509293505050565b5f5f5f5f60808587031215614596575f5ffd5b843593506145a6602086016142ca565b93969395505050506040820135916060013590565b5f5b838110156145d55781810151838201526020016145bd565b50505f910152565b5f81518084526145f48160208601602086016145bb565b601f01601f19169290920160200192915050565b60ff60f81b8816815260e060208201525f61462660e08301896145dd565b828103604084015261463881896145dd565b606084018890526001600160a01b038716608085015260a0840186905283810360c0850152845180825260208087019350909101905f5b8181101561468d57835183526020938401939092019160010161466f565b50909b9a5050505050505050505050565b5f5f604083850312156146af575f5ffd5b6146b88361420e565b91506020830135600581106146cb575f5ffd5b809150509250929050565b8215158152610180810161406e6020830184614340565b5f602082840312156146fd575f5ffd5b61406e826142ca565b602081525f61406e60208301846145dd565b5f5f60208385031215614729575f5ffd5b82356001600160401b0381111561473e575f5ffd5b8301601f8101851361474e575f5ffd5b80356001600160401b03811115614763575f5ffd5b8560208260061b8401011115614777575f5ffd5b6020919091019590945092505050565b6101608101610c448284614340565b5f5f604083850312156147a7575f5ffd5b823591506142c1602084016142ca565b602080825282518282018190525f918401906040840190835b818110156147fa5783518051845260209081015181850152909301926040909201916001016147d0565b509095945050505050565b5f5f5f5f60808587031215614818575f5ffd5b6148218561420e565b935061482f6020860161420e565b925061483d6040860161420e565b915061484b6060860161420e565b905092959194509250565b5f5f60408385031215614867575f5ffd5b50508035926020909101359150565b634e487b7160e01b5f52601160045260245ffd5b80820180821115610c4457610c44614876565b81810381811115610c4457610c44614876565b5f816148be576148be614876565b505f190190565b634e487b7160e01b5f52603260045260245ffd5b5f600182016148ea576148ea614876565b5060010190565b5f60208284031215614901575f5ffd5b8135801515811461406e575f5ffd5b8082028115828204841417610c4457610c44614876565b5f8261494157634e487b7160e01b5f52601260045260245ffd5b500490565b5f60208284031215614956575f5ffd5b5051919050565b858152602081018590526040810184905260a0810161497f606083018561431c565b8260808301529695505050505050565b600181811c908216806149a357607f821691505b60208210810361330757634e487b7160e01b5f52602260045260245ffd5b6bffffffffffffffffffffffff198660601b1681528460148201525f600385106149ed576149ed614308565b5060f89390931b60348401526035830191909152605582015260750192915050565b601f821115610ffc57805f5260205f20601f840160051c81016020851015614a345750805b601f840160051c820191505b81811015614a53575f8155600101614a40565b5050505050565b81516001600160401b03811115614a7357614a7361442b565b614a8781614a81845461498f565b84614a0f565b6020601f821160018114614ab9575f8315614aa25750848201515b5f19600385901b1c1916600184901b178455614a53565b5f84815260208120601f198516915b82811015614ae85787850151825560209485019460019092019101614ac8565b5084821015614b0557868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b5f8251614b258184602087016145bb565b919091019291505056fef7a14a339431c5b75d52ee00990f12734fece07deb6cc21a89286e2664bf2fcb1d93c87416ca7b54f0fb8323167b72760e8e2ec93d48660953897a150f97a8b4a16a46d94261c7517cc8ff89f61c0ce93598e3c849801011dee649a6a557d100360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc0f51adb3f49e4a9bbb17b3783f025995eaf8c24be2c8eefff214bdfda05ef94d65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033009b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a2646970667358221220529837257370ccf570a8a2813a63a005a1f57586ea37a69d89df59cbcb99110364736f6c634300081c0033