My Name Tag:
Not Available, login to update
Txn Hash | Method |
Block
|
From
|
To
|
Value | ||||
---|---|---|---|---|---|---|---|---|---|
0x44c3d486b1ffbaf97e7954e563d7159926bc0b7b9d772ae913f39aafcac6f459 | Initialize | 472431 | 350 days 17 hrs ago | Boba Network: Deployer | IN | Boba Network: L2LiquidityPool | 0 Ether | 0.000351389 | |
0x95c8d9fba9965fe4e62d74e86cc34458320fedd7140265be79b9f673f8c78e0b | Initialize | 472429 | 350 days 17 hrs ago | Boba Network: Deployer | IN | Boba Network: L2LiquidityPool | 0 Ether | 0.000314957 | |
0xd41e963d0517ea027dbb3779921f586dc963295585089b7c0c53a71d996581f5 | 0x60806040 | 472428 | 350 days 17 hrs ago | Boba Network: Deployer | IN | Create: L2LiquidityPool | 0 Ether | 0.005887667 |
[ Download CSV Export ]
Latest 25 internal transaction
[ Download CSV Export ]
Contract Name:
L2LiquidityPool
Compiler Version
v0.8.9+commit.e5eed63a
Optimization Enabled:
Yes with 10000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity >0.7.5; import "./interfaces/iL1LiquidityPool.sol"; /* Library Imports */ import "@eth-optimism/contracts/contracts/libraries/bridge/CrossDomainEnabled.sol"; import "@eth-optimism/contracts/contracts/libraries/constants/Lib_PredeployAddresses.sol"; /* External Imports */ import '@openzeppelin/contracts/utils/math/SafeMath.sol'; import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "@eth-optimism/contracts/contracts/L2/predeploys/OVM_GasPriceOracle.sol"; import "@eth-optimism/contracts/contracts/L2/messaging/L2StandardBridge.sol"; /* External Imports */ import "../standards/xL2GovernanceERC20.sol"; import "../L2BillingContract.sol"; /** * @dev An L2 LiquidityPool implementation */ contract L2LiquidityPool is CrossDomainEnabled, ReentrancyGuardUpgradeable, PausableUpgradeable { using SafeERC20 for IERC20; using SafeMath for uint256; /************** * Struct * **************/ // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. uint256 pendingReward; // Pending reward // // We do some fancy math here. Basically, any point in time, the amount of rewards // entitled to a user but is pending to be distributed is: // // Update Reward Per Share: // accUserRewardPerShare = accUserRewardPerShare + (accUserReward - lastAccUserReward) / userDepositAmount // // LP Provider: // Deposit: // Case 1 (new user): // Update Reward Per Share(); // Calculate user.rewardDebt = amount * accUserRewardPerShare; // Case 2 (user who has already deposited add more funds): // Update Reward Per Share(); // Calculate user.pendingReward = amount * accUserRewardPerShare - user.rewardDebt; // Calculate user.rewardDebt = (amount + new_amount) * accUserRewardPerShare; // // Withdraw // Update Reward Per Share(); // Calculate user.pendingReward = amount * accUserRewardPerShare - user.rewardDebt; // Calculate user.rewardDebt = (amount - withdraw_amount) * accUserRewardPerShare; } // Info of each pool. struct PoolInfo { address l1TokenAddress; // Address of token contract. address l2TokenAddress; // Address of toekn contract. // balance uint256 userDepositAmount; // user deposit amount; // user rewards uint256 lastAccUserReward; // Last accumulated user reward uint256 accUserReward; // Accumulated user reward. uint256 accUserRewardPerShare; // Accumulated user rewards per share, times 1e12. See below. // owner rewards uint256 accOwnerReward; // Accumulated owner reward. // start time uint256 startTime; } // Token batch structure struct ClientPayToken { address payable to; address l2TokenAddress; uint256 amount; } /************* * Variables * *************/ // mapping L1 and L2 token address to poolInfo mapping(address => PoolInfo) public poolInfo; // Info of each user that stakes tokens. mapping(address => mapping(address => UserInfo)) public userInfo; address public owner; address public L1LiquidityPoolAddress; uint256 public userRewardMinFeeRate; uint256 public ownerRewardFeeRate; // Default gas value which can be overridden if more complex logic runs on L1. uint32 public DEFAULT_FINALIZE_WITHDRAWAL_L1_GAS; uint256 private constant SAFE_GAS_STIPEND = 2300; address public DAO; uint256 public extraGasRelay; uint256 public userRewardMaxFeeRate; address public xBOBAAddress; address public BOBAAddress; // mapping user address to the status of xBOBA mapping(address => bool) public xBOBAStatus; // billing contract address address public billingContractAddress; /******************** * Event * ********************/ event AddLiquidity( address sender, uint256 amount, address tokenAddress ); event OwnerRecoverFee( address sender, address receiver, uint256 amount, address tokenAddress ); event ClientDepositL2( address sender, uint256 receivedAmount, address tokenAddress ); event ClientPayL2( address sender, uint256 amount, uint256 userRewardFee, uint256 ownerRewardFee, uint256 totalFee, address tokenAddress ); event ClientPayL2Settlement( address sender, uint256 amount, uint256 userRewardFee, uint256 ownerRewardFee, uint256 totalFee, address tokenAddress ); event WithdrawLiquidity( address sender, address receiver, uint256 amount, address tokenAddress ); event WithdrawReward( address sender, address receiver, uint256 amount, address tokenAddress ); event RebalanceLP( uint256 amount, address tokenAddress ); event OwnershipTransferred( address newOwner ); event DaoRoleTransferred( address newDao ); /******************************** * Constructor & Initialization * ********************************/ constructor () CrossDomainEnabled(address(0)) {} /********************** * Function Modifiers * **********************/ modifier onlyOwner() { require(msg.sender == owner || owner == address(0), 'Caller is not the owner'); _; } modifier onlyDAO() { require(msg.sender == DAO, 'Caller is not the DAO'); _; } modifier onlyNotInitialized() { require(address(L1LiquidityPoolAddress) == address(0), "Contract has been initialized"); _; } modifier onlyInitialized() { require(address(L1LiquidityPoolAddress) != address(0), "Contract has not yet been initialized"); _; } modifier onlyWithBillingContract() { require(billingContractAddress != address(0), "Billing contract address is not set"); _; } /******************** * Public Functions * ********************/ /** * @dev transfer ownership * * @param _newOwner new owner of this contract */ function transferOwnership( address _newOwner ) public onlyOwner() { require(_newOwner != address(0), 'New owner cannot be the zero address'); owner = _newOwner; emit OwnershipTransferred(_newOwner); } /** * @dev transfer priviledges to DAO * * @param _newDAO new fee setter */ function transferDAORole( address _newDAO ) public onlyDAO() { require(_newDAO != address(0), 'New DAO address cannot be the zero address'); DAO = _newDAO; emit DaoRoleTransferred(_newDAO); } /** * @dev Initialize this contract. * @param _l2CrossDomainMessenger L2 Messenger address being used for sending the cross-chain message. * @param _L1LiquidityPoolAddress Address of the corresponding L1 LP deployed to the main chain */ function initialize( address _l2CrossDomainMessenger, address _L1LiquidityPoolAddress ) public onlyOwner() onlyNotInitialized() initializer() { require(_l2CrossDomainMessenger != address(0) && _L1LiquidityPoolAddress != address(0), "zero address not allowed"); messenger = _l2CrossDomainMessenger; L1LiquidityPoolAddress = _L1LiquidityPoolAddress; owner = msg.sender; DAO = msg.sender; // translates to fee rates 0.1%, 1% and 1.5% respectively configureFee(1, 10, 15); configureGas(100000); __Context_init_unchained(); __Pausable_init_unchained(); __ReentrancyGuard_init_unchained(); } /** * @dev Configure fee of this contract. * @dev Each fee rate is scaled by 10^3 for precision, eg- a fee rate of 50 would mean 5% * @param _userRewardMinFeeRate minimum fee rate that users get * @param _userRewardMaxFeeRate maximum fee rate that users get * @param _ownerRewardFeeRate fee rate that contract owner gets */ function configureFee( uint256 _userRewardMinFeeRate, uint256 _userRewardMaxFeeRate, uint256 _ownerRewardFeeRate ) public onlyDAO() onlyInitialized() { require(_userRewardMinFeeRate <= _userRewardMaxFeeRate && _userRewardMinFeeRate > 0 && _userRewardMaxFeeRate <= 50 && _ownerRewardFeeRate <= 50, 'user and owner fee rates should be lower than 5 percent each'); userRewardMinFeeRate = _userRewardMinFeeRate; userRewardMaxFeeRate = _userRewardMaxFeeRate; ownerRewardFeeRate = _ownerRewardFeeRate; } /** * @dev Configure fee of the L1LP contract * @dev Each fee rate is scaled by 10^3 for precision, eg- a fee rate of 50 would mean 5% * @param _userRewardMinFeeRate minimum fee rate that users get * @param _userRewardMaxFeeRate maximum fee rate that users get * @param _ownerRewardFeeRate fee rate that contract owner gets */ function configureFeeExits( uint256 _userRewardMinFeeRate, uint256 _userRewardMaxFeeRate, uint256 _ownerRewardFeeRate ) external onlyDAO() onlyInitialized() { require(_userRewardMinFeeRate <= _userRewardMaxFeeRate && _userRewardMinFeeRate > 0 && _userRewardMaxFeeRate <= 50 && _ownerRewardFeeRate <= 50, 'user and owner fee rates should be lower than 5 percent each'); bytes memory data = abi.encodeWithSelector( iL1LiquidityPool.configureFee.selector, _userRewardMinFeeRate, _userRewardMaxFeeRate, _ownerRewardFeeRate ); // Send calldata into L1 sendCrossDomainMessage( address(L1LiquidityPoolAddress), getFinalizeDepositL1Gas(), data ); } /** * @dev Configure gas. * * @param _l1GasFee default finalized withdraw L1 Gas */ function configureGas( uint32 _l1GasFee ) public onlyOwner() onlyInitialized() { DEFAULT_FINALIZE_WITHDRAWAL_L1_GAS = _l1GasFee; } /** * @dev Configure billing contract address. * * @param _billingContractAddress billing contract address */ function configureBillingContractAddress( address _billingContractAddress ) public onlyOwner() { require(_billingContractAddress != address(0), "Billing contract address cannot be zero"); billingContractAddress = _billingContractAddress; } /** * @dev Return user reward fee rate. * * @param _l2TokenAddress L2 token address */ function getUserRewardFeeRate( address _l2TokenAddress ) public view onlyInitialized() returns (uint256 userRewardFeeRate) { PoolInfo storage pool = poolInfo[_l2TokenAddress]; uint256 poolLiquidity = pool.userDepositAmount; uint256 poolBalance; if (_l2TokenAddress == Lib_PredeployAddresses.OVM_ETH) { poolBalance = address(this).balance; } else { poolBalance = IERC20(_l2TokenAddress).balanceOf(address(this)); } if (poolBalance == 0) { return userRewardMaxFeeRate; } else { uint256 poolRewardRate = userRewardMinFeeRate * poolLiquidity / poolBalance; if (userRewardMinFeeRate > poolRewardRate) { return userRewardMinFeeRate; } else if (userRewardMaxFeeRate < poolRewardRate) { return userRewardMaxFeeRate; } return poolRewardRate; } } /*** * @dev Register BOBA tokens * * @param _BOBAAddress L2 BOBA address * @param _xBOBAAddress L2 xBOBA address * */ function registerBOBA ( address _BOBAAddress, address _xBOBAAddress ) public onlyOwner() { require(BOBAAddress == address(0) && _BOBAAddress != address(0) && _xBOBAAddress != address(0), "Invalid BOBA address"); BOBAAddress = _BOBAAddress; xBOBAAddress = _xBOBAAddress; } /*** * @dev Add the new token pair to the pool * DO NOT add the same LP token more than once. Rewards will be messed up if you do. * * @param _l1TokenAddress * @param _l2TokenAddress * */ function registerPool ( address _l1TokenAddress, address _l2TokenAddress ) public onlyOwner() { require(_l1TokenAddress != _l2TokenAddress, "l1 and l2 token addresses cannot be same"); require(_l2TokenAddress != address(0), "l2 token address cannot be zero address"); // use with caution, can register only once PoolInfo storage pool = poolInfo[_l2TokenAddress]; // l2 token address equal to zero, then pair is not registered. require(pool.l2TokenAddress == address(0), "Token Address Already Registered"); poolInfo[_l2TokenAddress] = PoolInfo({ l1TokenAddress: _l1TokenAddress, l2TokenAddress: _l2TokenAddress, userDepositAmount: 0, lastAccUserReward: 0, accUserReward: 0, accUserRewardPerShare: 0, accOwnerReward: 0, startTime: block.timestamp }); } /** * @dev Overridable getter for the L1 gas limit of settling the deposit, in the case it may be * dynamic, and the above public constant does not suffice. * */ function getFinalizeDepositL1Gas() public view virtual returns( uint32 ) { return DEFAULT_FINALIZE_WITHDRAWAL_L1_GAS; } /** * Update the user reward per share * @param _tokenAddress Address of the target token. */ function updateUserRewardPerShare( address _tokenAddress ) public { PoolInfo storage pool = poolInfo[_tokenAddress]; if (pool.lastAccUserReward < pool.accUserReward) { uint256 accUserRewardDiff = (pool.accUserReward.sub(pool.lastAccUserReward)); if (pool.userDepositAmount != 0) { pool.accUserRewardPerShare = pool.accUserRewardPerShare.add( accUserRewardDiff.mul(1e12).div(pool.userDepositAmount) ); } pool.lastAccUserReward = pool.accUserReward; } } /** * Give xBOBA to users who has already deposited liquidity * @param _tokenAddress address of the liquidity token. */ function mintXBOBAForPreOwner( address _tokenAddress ) internal { if (!xBOBAStatus[msg.sender] && BOBAAddress == _tokenAddress && BOBAAddress != address(0)) { // mint xBoba UserInfo storage user = userInfo[_tokenAddress][msg.sender]; if (user.amount != 0) { xL2GovernanceERC20(xBOBAAddress).mint(msg.sender, user.amount); } xBOBAStatus[msg.sender] = true; } } /** * Give xBOBA to users who deposit liquidity * @param _amount boba amount that users want to deposit. * @param _tokenAddress address of the liquidity token. */ function mintXBOBA( uint256 _amount, address _tokenAddress ) internal { if (BOBAAddress == _tokenAddress && BOBAAddress != address(0)) { // mint xBoba xL2GovernanceERC20(xBOBAAddress).mint(msg.sender, _amount); } } /** * Burn xBOBA for users who withdraw liquidity * @param _amount boba amount that users want to withdraw. * @param _tokenAddress address of the liquidity token. */ function burnXBOBA( uint256 _amount, address _tokenAddress ) internal { if (BOBAAddress == _tokenAddress && BOBAAddress != address(0)) { // burn xBOBA xL2GovernanceERC20(xBOBAAddress).burn(msg.sender, _amount); } } /** * Liquididity providers add liquidity * @param _amount liquidity amount that users want to deposit. * @param _tokenAddress address of the liquidity token. */ function addLiquidity( uint256 _amount, address _tokenAddress ) external payable nonReentrant whenNotPaused { require(msg.value != 0 || _tokenAddress != Lib_PredeployAddresses.OVM_ETH, "Either Amount Incorrect or Token Address Incorrect"); // combine to make logical XOR to avoid user error require(!(msg.value != 0 && _tokenAddress != Lib_PredeployAddresses.OVM_ETH), "Either Amount Incorrect or Token Address Incorrect"); // check whether user sends ovm_ETH or ERC20 if (msg.value != 0) { // override the _amount and token address _amount = msg.value; _tokenAddress = Lib_PredeployAddresses.OVM_ETH; } PoolInfo storage pool = poolInfo[_tokenAddress]; UserInfo storage user = userInfo[_tokenAddress][msg.sender]; require(pool.l2TokenAddress != address(0), "Token Address Not Registered"); // Send initial xBOBA mintXBOBAForPreOwner(_tokenAddress); // Update accUserRewardPerShare updateUserRewardPerShare(_tokenAddress); // if the user has already deposited token, we move the rewards to // pendingReward and update the reward debet. if (user.amount > 0) { user.pendingReward = user.pendingReward.add( user.amount.mul(pool.accUserRewardPerShare).div(1e12).sub(user.rewardDebt) ); user.rewardDebt = (user.amount.add(_amount)).mul(pool.accUserRewardPerShare).div(1e12); } else { user.rewardDebt = _amount.mul(pool.accUserRewardPerShare).div(1e12); } // update amounts user.amount = user.amount.add(_amount); pool.userDepositAmount = pool.userDepositAmount.add(_amount); emit AddLiquidity( msg.sender, _amount, _tokenAddress ); // transfer funds if users deposit ERC20 if (_tokenAddress != Lib_PredeployAddresses.OVM_ETH) { IERC20(_tokenAddress).safeTransferFrom(msg.sender, address(this), _amount); } // xBOBA mintXBOBA(_amount, _tokenAddress); } /** * Client deposit ERC20 from their account to this contract, which then releases funds on the L1 side * @param _amount amount that client wants to transfer. * @param _tokenAddress L2 token address */ function clientDepositL2( uint256 _amount, address _tokenAddress ) external payable whenNotPaused onlyWithBillingContract { // Collect the exit fee L2BillingContract billingContract = L2BillingContract(billingContractAddress); IERC20(billingContract.feeTokenAddress()).safeTransferFrom(msg.sender, billingContractAddress, billingContract.exitFee()); require(msg.value != 0 || _tokenAddress != Lib_PredeployAddresses.OVM_ETH, "Either Amount Incorrect or Token Address Incorrect"); // combine to make logical XOR to avoid user error require(!(msg.value != 0 && _tokenAddress != Lib_PredeployAddresses.OVM_ETH), "Either Amount Incorrect or Token Address Incorrect"); // check whether user sends ovm_ETH or ERC20 if (msg.value != 0) { // override the _amount and token address _amount = msg.value; _tokenAddress = Lib_PredeployAddresses.OVM_ETH; } PoolInfo storage pool = poolInfo[_tokenAddress]; require(pool.l2TokenAddress != address(0), "Token Address Not Registered"); emit ClientDepositL2( msg.sender, _amount, _tokenAddress ); // transfer funds if users deposit ERC20 if (_tokenAddress != Lib_PredeployAddresses.OVM_ETH) { IERC20(_tokenAddress).safeTransferFrom(msg.sender, address(this), _amount); } // Construct calldata for L1LiquidityPool.clientPayL1(_to, _amount, _tokenAddress) bytes memory data = abi.encodeWithSelector( iL1LiquidityPool.clientPayL1.selector, msg.sender, _amount, pool.l1TokenAddress ); // Send calldata into L1 sendCrossDomainMessage( address(L1LiquidityPoolAddress), getFinalizeDepositL1Gas(), data ); } /** * Users withdraw token from LP * @param _amount amount to withdraw * @param _tokenAddress L2 token address * @param _to receiver to get the funds */ function withdrawLiquidity( uint256 _amount, address _tokenAddress, address payable _to ) external whenNotPaused { PoolInfo storage pool = poolInfo[_tokenAddress]; UserInfo storage user = userInfo[_tokenAddress][msg.sender]; require(pool.l2TokenAddress != address(0), "Token Address Not Registered"); require(user.amount >= _amount, "Requested amount exceeds amount staked"); // Send initial xBOBA mintXBOBAForPreOwner(_tokenAddress); // Update accUserRewardPerShare updateUserRewardPerShare(_tokenAddress); // calculate all the rewards and set it as pending rewards user.pendingReward = user.pendingReward.add( user.amount.mul(pool.accUserRewardPerShare).div(1e12).sub(user.rewardDebt) ); // Update the user data user.amount = user.amount.sub(_amount); // update reward debt user.rewardDebt = user.amount.mul(pool.accUserRewardPerShare).div(1e12); // update total user deposit amount pool.userDepositAmount = pool.userDepositAmount.sub(_amount); emit WithdrawLiquidity( msg.sender, _to, _amount, _tokenAddress ); if (_tokenAddress != Lib_PredeployAddresses.OVM_ETH) { IERC20(_tokenAddress).safeTransfer(_to, _amount); } else { (bool sent,) = _to.call{gas: SAFE_GAS_STIPEND, value: _amount}(""); require(sent, "Failed to send ovm_Eth"); } // burn xBOBA burnXBOBA(_amount, _tokenAddress); } /** * owner recovers fee from ERC20 * @param _amount amount to transfer to the other account. * @param _tokenAddress L2 token address * @param _to receiver to get the fee. */ function ownerRecoverFee( uint256 _amount, address _tokenAddress, address _to ) external onlyOwner() { PoolInfo storage pool = poolInfo[_tokenAddress]; require(pool.l2TokenAddress != address(0), "Token Address Not Registered"); require(pool.accOwnerReward >= _amount, "Requested amount exceeds reward"); pool.accOwnerReward = pool.accOwnerReward.sub(_amount); emit OwnerRecoverFee( msg.sender, _to, _amount, _tokenAddress ); if (_tokenAddress != Lib_PredeployAddresses.OVM_ETH) { IERC20(_tokenAddress).safeTransfer(_to, _amount); } else { (bool sent,) = _to.call{gas: SAFE_GAS_STIPEND, value: _amount}(""); require(sent, "Failed to send ovm_Eth"); } } /** * withdraw reward from ERC20 * @param _amount reward amount that liquidity providers want to withdraw * @param _tokenAddress L2 token address * @param _to receiver to get the reward */ function withdrawReward( uint256 _amount, address _tokenAddress, address _to ) external whenNotPaused { PoolInfo storage pool = poolInfo[_tokenAddress]; UserInfo storage user = userInfo[_tokenAddress][msg.sender]; require(pool.l2TokenAddress != address(0), "Token Address Not Registered"); uint256 pendingReward = user.pendingReward.add( user.amount.mul(pool.accUserRewardPerShare).div(1e12).sub(user.rewardDebt) ); require(pendingReward >= _amount, "Requested amount exceeds pendingReward"); user.pendingReward = pendingReward.sub(_amount); user.rewardDebt = user.amount.mul(pool.accUserRewardPerShare).div(1e12); emit WithdrawReward( msg.sender, _to, _amount, _tokenAddress ); if (_tokenAddress != Lib_PredeployAddresses.OVM_ETH) { IERC20(_tokenAddress).safeTransfer(_to, _amount); } else { (bool sent,) = _to.call{gas: SAFE_GAS_STIPEND, value: _amount}(""); require(sent, "Failed to send ovm_Eth"); } } /* * Rebalance LPs * @param _amount token amount that we want to move from L2 to L1 * @param _tokenAddress L2 token address */ function rebalanceLP( uint256 _amount, address _tokenAddress ) external onlyOwner() whenNotPaused() { require(_amount != 0, "Amount cannot be 0"); PoolInfo storage pool = poolInfo[_tokenAddress]; require(L1LiquidityPoolAddress != address(0), "L1 Liquidity Pool Not Registered"); require(pool.l2TokenAddress != address(0), "Token Address Not Registered"); if (_tokenAddress == Lib_PredeployAddresses.OVM_ETH) { require(_amount <= address(this).balance, "Requested ETH exceeds pool balance"); L2StandardBridge(Lib_PredeployAddresses.L2_STANDARD_BRIDGE).withdrawTo( _tokenAddress, L1LiquidityPoolAddress, _amount, DEFAULT_FINALIZE_WITHDRAWAL_L1_GAS, "" ); } else { require(_amount <= IERC20(_tokenAddress).balanceOf(address(this)), "Requested ERC20 exceeds pool balance"); L2StandardBridge(Lib_PredeployAddresses.L2_STANDARD_BRIDGE).withdrawTo( _tokenAddress, L1LiquidityPoolAddress, _amount, DEFAULT_FINALIZE_WITHDRAWAL_L1_GAS, "" ); } emit RebalanceLP( _amount, _tokenAddress ); } /** * Pause contract */ function pause() external onlyOwner() { _pause(); } /** * UnPause contract */ function unpause() external onlyOwner() { _unpause(); } /************************* * Cross-chain Functions * *************************/ /** * Move funds from L1 to L2, and pay out from the right liquidity pool * @param _to receiver to get the funds * @param _amount amount to to be transferred. * @param _tokenAddress L2 token address */ function clientPayL2( address payable _to, uint256 _amount, address _tokenAddress ) external onlyInitialized() onlyFromCrossDomainAccount(address(L1LiquidityPoolAddress)) whenNotPaused { _initiateClientPayL2(_to, _amount, _tokenAddress); } /** * Move funds in batch from L1 to L2, and pay out from the right liquidity pool * @param _tokens tokens in batch */ function clientPayL2Batch( ClientPayToken [] calldata _tokens ) external onlyInitialized() onlyFromCrossDomainAccount(address(L1LiquidityPoolAddress)) whenNotPaused { for (uint256 i = 0; i < _tokens.length; i++) { ClientPayToken memory token = _tokens[i]; _initiateClientPayL2(token.to, token.amount, token.l2TokenAddress); } } /** * Move funds from L1 to L2, and pay out from the right liquidity pool * @param _to receiver to get the funds * @param _amount amount to to be transferred. * @param _tokenAddress L2 token address */ function _initiateClientPayL2( address payable _to, uint256 _amount, address _tokenAddress ) internal { // replyNeeded helps store the status if a message needs to be sent back to the other layer // in case there is not enough funds to give away bool replyNeeded = false; PoolInfo storage pool = poolInfo[_tokenAddress]; // if this fails, relay can be attempted again after registering require(pool.l2TokenAddress != address(0), "Token Address Not Registered"); uint256 userRewardFeeRate = getUserRewardFeeRate(_tokenAddress); uint256 userRewardFee = (_amount.mul(userRewardFeeRate)).div(1000); uint256 ownerRewardFee = (_amount.mul(ownerRewardFeeRate)).div(1000); uint256 totalFee = userRewardFee.add(ownerRewardFee); uint256 receivedAmount = _amount.sub(totalFee); if (_tokenAddress != Lib_PredeployAddresses.OVM_ETH) { if (receivedAmount > IERC20(_tokenAddress).balanceOf(address(this))) { replyNeeded = true; } else { pool.accUserReward = pool.accUserReward.add(userRewardFee); pool.accOwnerReward = pool.accOwnerReward.add(ownerRewardFee); IERC20(_tokenAddress).safeTransfer(_to, receivedAmount); } } else { if (receivedAmount > address(this).balance) { replyNeeded = true; } else { pool.accUserReward = pool.accUserReward.add(userRewardFee); pool.accOwnerReward = pool.accOwnerReward.add(ownerRewardFee); //this is ovm_ETH (bool sent,) = _to.call{gas: SAFE_GAS_STIPEND, value: receivedAmount}(""); require(sent, "Failed to send ovm_Eth"); } } if (replyNeeded) { // send cross domain message bytes memory data = abi.encodeWithSelector( iL1LiquidityPool.clientPayL1Settlement.selector, _to, _amount, pool.l1TokenAddress ); sendCrossDomainMessage( address(L1LiquidityPoolAddress), getFinalizeDepositL1Gas(), data ); } else { emit ClientPayL2( _to, receivedAmount, userRewardFee, ownerRewardFee, totalFee, _tokenAddress ); } } /** * Settlement pay when there's not enough funds on other side * @param _to receiver to get the funds * @param _amount amount to to be transferred. * @param _tokenAddress L2 token address */ function clientPayL2Settlement( address payable _to, uint256 _amount, address _tokenAddress ) external onlyInitialized() onlyFromCrossDomainAccount(address(L1LiquidityPoolAddress)) whenNotPaused { PoolInfo storage pool = poolInfo[_tokenAddress]; uint256 userRewardFeeRate = getUserRewardFeeRate(_tokenAddress); uint256 userRewardFee = (_amount.mul(userRewardFeeRate)).div(1000); uint256 ownerRewardFee = (_amount.mul(ownerRewardFeeRate)).div(1000); uint256 totalFee = userRewardFee.add(ownerRewardFee); uint256 receivedAmount = _amount.sub(totalFee); pool.accUserReward = pool.accUserReward.add(userRewardFee); pool.accOwnerReward = pool.accOwnerReward.add(ownerRewardFee); emit ClientPayL2Settlement( _to, receivedAmount, userRewardFee, ownerRewardFee, totalFee, _tokenAddress ); if (_tokenAddress != Lib_PredeployAddresses.OVM_ETH) { IERC20(_tokenAddress).safeTransfer(_to, receivedAmount); } else { //this is ovm_ETH (bool sent,) = _to.call{gas: SAFE_GAS_STIPEND, value: receivedAmount}(""); require(sent, "Failed to send ovm_Eth"); } } }
// SPDX-License-Identifier: MIT pragma solidity >0.7.5; pragma experimental ABIEncoderV2; /** * @title iL1LiquidityPool */ interface iL1LiquidityPool { /******************** * Events * ********************/ event AddLiquidity( address sender, uint256 amount, address tokenAddress ); event OwnerRecoverFee( address sender, address receiver, uint256 amount, address tokenAddress ); event ClientDepositL1( address sender, uint256 receivedAmount, address tokenAddress ); event ClientPayL1( address sender, uint256 amount, uint256 userRewardFee, uint256 ownerRewardFee, uint256 totalFee, address tokenAddress ); event ClientPayL1Settlement( address sender, uint256 amount, uint256 userRewardFee, uint256 ownerRewardFee, uint256 totalFee, address tokenAddress ); event WithdrawLiquidity( address sender, address receiver, uint256 amount, address tokenAddress ); event WithdrawReward( address sender, address receiver, uint256 amount, address tokenAddress ); /************************* * Cross-chain Functions * *************************/ function clientPayL1( address payable _to, uint256 _amount, address _tokenAddress ) external; function clientPayL1Settlement( address payable _to, uint256 _amount, address _tokenAddress ) external; function configureFee( uint256 _userRewardMinFeeRate, uint256 _userRewardMaxFeeRate, uint256 _ownerRewardFeeRate ) external; }
// SPDX-License-Identifier: MIT pragma solidity >0.5.0 <0.9.0; /* Interface Imports */ import { ICrossDomainMessenger } from "./ICrossDomainMessenger.sol"; /** * @title CrossDomainEnabled * @dev Helper contract for contracts performing cross-domain communications * * Compiler used: defined by inheriting contract * Runtime target: defined by inheriting contract */ contract CrossDomainEnabled { /************* * Variables * *************/ // Messenger contract used to send and recieve messages from the other domain. address public messenger; /*************** * Constructor * ***************/ /** * @param _messenger Address of the CrossDomainMessenger on the current layer. */ constructor(address _messenger) { messenger = _messenger; } /********************** * Function Modifiers * **********************/ /** * Enforces that the modified function is only callable by a specific cross-domain account. * @param _sourceDomainAccount The only account on the originating domain which is * authenticated to call this function. */ modifier onlyFromCrossDomainAccount(address _sourceDomainAccount) { require( msg.sender == address(getCrossDomainMessenger()), "OVM_XCHAIN: messenger contract unauthenticated" ); require( getCrossDomainMessenger().xDomainMessageSender() == _sourceDomainAccount, "OVM_XCHAIN: wrong sender of cross-domain message" ); _; } /********************** * Internal Functions * **********************/ /** * Gets the messenger, usually from storage. This function is exposed in case a child contract * needs to override. * @return The address of the cross-domain messenger contract which should be used. */ function getCrossDomainMessenger() internal virtual returns (ICrossDomainMessenger) { return ICrossDomainMessenger(messenger); } /**q * Sends a message to an account on another domain * @param _crossDomainTarget The intended recipient on the destination domain * @param _message The data to send to the target (usually calldata to a function with * `onlyFromCrossDomainAccount()`) * @param _gasLimit The gasLimit for the receipt of the message on the target domain. */ function sendCrossDomainMessage( address _crossDomainTarget, uint32 _gasLimit, bytes memory _message ) internal { getCrossDomainMessenger().sendMessage(_crossDomainTarget, _message, _gasLimit); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; /** * @title Lib_PredeployAddresses */ library Lib_PredeployAddresses { // solhint-disable max-line-length address internal constant L2_TO_L1_MESSAGE_PASSER = 0x4200000000000000000000000000000000000000; address internal constant L1_MESSAGE_SENDER = 0x4200000000000000000000000000000000000001; address internal constant DEPLOYER_WHITELIST = 0x4200000000000000000000000000000000000002; address payable internal constant OVM_ETH = payable(0x4200000000000000000000000000000000000006); // solhint-disable-next-line max-line-length address internal constant L2_CROSS_DOMAIN_MESSENGER = 0x4200000000000000000000000000000000000007; address internal constant LIB_ADDRESS_MANAGER = 0x4200000000000000000000000000000000000008; address internal constant PROXY_EOA = 0x4200000000000000000000000000000000000009; address internal constant L2_STANDARD_BRIDGE = 0x4200000000000000000000000000000000000010; address internal constant SEQUENCER_FEE_WALLET = 0x4200000000000000000000000000000000000011; address internal constant L2_STANDARD_TOKEN_FACTORY = 0x4200000000000000000000000000000000000012; address internal constant L1_BLOCK_NUMBER = 0x4200000000000000000000000000000000000013; address internal constant OVM_GAS_PRICE_ORACLE = 0x420000000000000000000000000000000000000F; address internal constant PROXY__BOBA_TURING_PREPAY = 0x4200000000000000000000000000000000000020; address internal constant BOBA_TURING_PREPAY = 0x4200000000000000000000000000000000000021; address internal constant BOBA_TURING_HELPER = 0x4200000000000000000000000000000000000022; address internal constant L2_BOBA = 0x4200000000000000000000000000000000000023; address internal constant PROXY__BOBA_GAS_PRICE_ORACLE = 0x4200000000000000000000000000000000000024; address internal constant BOBA_GAS_PRICE_ORACLE = 0x4200000000000000000000000000000000000025; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { 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 division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 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 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @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). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../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 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; uint256 private _status; function __ReentrancyGuard_init() internal initializer { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal initializer { _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 make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } uint256[49] private __gap; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../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 { /** * @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); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal initializer { __Context_init_unchained(); __Pausable_init_unchained(); } function __Pausable_init_unchained() internal initializer { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } uint256[49] private __gap; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; /* External Imports */ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; /** * @title OVM_GasPriceOracle * @dev This contract exposes the current l2 gas price, a measure of how congested the network * currently is. This measure is used by the Sequencer to determine what fee to charge for * transactions. When the system is more congested, the l2 gas price will increase and fees * will also increase as a result. * * All public variables are set while generating the initial L2 state. The * constructor doesn't run in practice as the L2 state generation script uses * the deployed bytecode instead of running the initcode. */ contract OVM_GasPriceOracle is Ownable { /************* * Variables * *************/ // Current L2 gas price uint256 public gasPrice; // Current L1 base fee uint256 public l1BaseFee; // Amortized cost of batch submission per transaction uint256 public overhead; // Value to scale the fee up by uint256 public scalar; // Number of decimals of the scalar uint256 public decimals; /*************** * Constructor * ***************/ /** * @param _owner Address that will initially own this contract. */ constructor(address _owner) Ownable() { transferOwnership(_owner); } /********** * Events * **********/ event GasPriceUpdated(uint256); event L1BaseFeeUpdated(uint256); event OverheadUpdated(uint256); event ScalarUpdated(uint256); event DecimalsUpdated(uint256); /******************** * Public Functions * ********************/ /** * Allows the owner to modify the l2 gas price. * @param _gasPrice New l2 gas price. */ function setGasPrice(uint256 _gasPrice) public onlyOwner { gasPrice = _gasPrice; emit GasPriceUpdated(_gasPrice); } /** * Allows the owner to modify the l1 base fee. * @param _baseFee New l1 base fee */ function setL1BaseFee(uint256 _baseFee) public onlyOwner { l1BaseFee = _baseFee; emit L1BaseFeeUpdated(_baseFee); } /** * Allows the owner to modify the overhead. * @param _overhead New overhead */ function setOverhead(uint256 _overhead) public onlyOwner { overhead = _overhead; emit OverheadUpdated(_overhead); } /** * Allows the owner to modify the scalar. * @param _scalar New scalar */ function setScalar(uint256 _scalar) public onlyOwner { scalar = _scalar; emit ScalarUpdated(_scalar); } /** * Allows the owner to modify the decimals. * @param _decimals New decimals */ function setDecimals(uint256 _decimals) public onlyOwner { decimals = _decimals; emit DecimalsUpdated(_decimals); } /** * Computes the L1 portion of the fee * based on the size of the RLP encoded tx * and the current l1BaseFee * @param _data Unsigned RLP encoded tx, 6 elements * @return L1 fee that should be paid for the tx */ function getL1Fee(bytes memory _data) public view returns (uint256) { uint256 l1GasUsed = getL1GasUsed(_data); uint256 l1Fee = l1GasUsed * l1BaseFee; uint256 divisor = 10**decimals; uint256 unscaled = l1Fee * scalar; uint256 scaled = unscaled / divisor; return scaled; } /** * Computes the extra L2 gas to cover the * L1 security fee * @param _data Unsigned RLP encoded tx, 6 elements * @return L2 extra gas that should be included in the L2 gas */ function getExtraL2Gas(bytes memory _data) public view returns (uint256) { return getL1Fee(_data) / gasPrice; } /** * Computes the amount of L1 gas used for a transaction * The overhead represents the per batch gas overhead of * posting both transaction and state roots to L1 given larger * batch sizes. * 4 gas for 0 byte * https://github.com/ethereum/go-ethereum/blob/ * 9ada4a2e2c415e6b0b51c50e901336872e028872/params/protocol_params.go#L33 * 16 gas for non zero byte * https://github.com/ethereum/go-ethereum/blob/ * 9ada4a2e2c415e6b0b51c50e901336872e028872/params/protocol_params.go#L87 * This will need to be updated if calldata gas prices change * Account for the transaction being unsigned * Padding is added to account for lack of signature on transaction * 1 byte for RLP V prefix * 1 byte for V * 1 byte for RLP R prefix * 32 bytes for R * 1 byte for RLP S prefix * 32 bytes for S * Total: 68 bytes of padding * @param _data Unsigned RLP encoded tx, 6 elements * @return Amount of L1 gas used for a transaction */ function getL1GasUsed(bytes memory _data) public view returns (uint256) { uint256 total = 0; for (uint256 i = 0; i < _data.length; i++) { if (_data[i] == 0) { total += 4; } else { total += 16; } } uint256 unsigned = total + overhead; return unsigned + (68 * 16); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; /* Interface Imports */ import { IL1StandardBridge } from "../../L1/messaging/IL1StandardBridge.sol"; import { IL1ERC20Bridge } from "../../L1/messaging/IL1ERC20Bridge.sol"; import { IL2ERC20Bridge } from "./IL2ERC20Bridge.sol"; /* Library Imports */ import { ERC165Checker } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import { CrossDomainEnabled } from "../../libraries/bridge/CrossDomainEnabled.sol"; import { Lib_PredeployAddresses } from "../../libraries/constants/Lib_PredeployAddresses.sol"; /* Contract Imports */ import { IL2StandardERC20 } from "../../standards/IL2StandardERC20.sol"; /** * @title L2StandardBridge * @dev The L2 Standard bridge is a contract which works together with the L1 Standard bridge to * enable ETH and ERC20 transitions between L1 and L2. * This contract acts as a minter for new tokens when it hears about deposits into the L1 Standard * bridge. * This contract also acts as a burner of the tokens intended for withdrawal, informing the L1 * bridge to release L1 funds. */ contract L2StandardBridge is IL2ERC20Bridge, CrossDomainEnabled { /******************************** * External Contract References * ********************************/ address public l1TokenBridge; /*************** * Constructor * ***************/ /** * @param _l2CrossDomainMessenger Cross-domain messenger used by this contract. * @param _l1TokenBridge Address of the L1 bridge deployed to the main chain. */ constructor(address _l2CrossDomainMessenger, address _l1TokenBridge) CrossDomainEnabled(_l2CrossDomainMessenger) { l1TokenBridge = _l1TokenBridge; } /*************** * Withdrawing * ***************/ /** * @inheritdoc IL2ERC20Bridge */ function withdraw( address _l2Token, uint256 _amount, uint32 _l1Gas, bytes calldata _data ) external virtual { _initiateWithdrawal(_l2Token, msg.sender, msg.sender, _amount, _l1Gas, _data); } /** * @inheritdoc IL2ERC20Bridge */ function withdrawTo( address _l2Token, address _to, uint256 _amount, uint32 _l1Gas, bytes calldata _data ) external virtual { _initiateWithdrawal(_l2Token, msg.sender, _to, _amount, _l1Gas, _data); } /** * @dev Performs the logic for deposits by storing the token and informing the L2 token Gateway * of the deposit. * @param _l2Token Address of L2 token where withdrawal was initiated. * @param _from Account to pull the deposit from on L2. * @param _to Account to give the withdrawal to on L1. * @param _amount Amount of the token to withdraw. * param _l1Gas Unused, but included for potential forward compatibility considerations. * @param _data Optional data to forward to L1. This data is provided * solely as a convenience for external contracts. Aside from enforcing a maximum * length, these contracts provide no guarantees about its content. */ function _initiateWithdrawal( address _l2Token, address _from, address _to, uint256 _amount, uint32 _l1Gas, bytes calldata _data ) internal { // When a withdrawal is initiated, we burn the withdrawer's funds to prevent subsequent L2 // usage IL2StandardERC20(_l2Token).burn(msg.sender, _amount); // Construct calldata for l1TokenBridge.finalizeERC20Withdrawal(_to, _amount) address l1Token = IL2StandardERC20(_l2Token).l1Token(); bytes memory message; if (_l2Token == Lib_PredeployAddresses.OVM_ETH) { message = abi.encodeWithSelector( IL1StandardBridge.finalizeETHWithdrawal.selector, _from, _to, _amount, _data ); } else { message = abi.encodeWithSelector( IL1ERC20Bridge.finalizeERC20Withdrawal.selector, l1Token, _l2Token, _from, _to, _amount, _data ); } // Send message up to L1 bridge sendCrossDomainMessage(l1TokenBridge, _l1Gas, message); emit WithdrawalInitiated(l1Token, _l2Token, msg.sender, _to, _amount, _data); } /************************************ * Cross-chain Function: Depositing * ************************************/ /** * @inheritdoc IL2ERC20Bridge */ function finalizeDeposit( address _l1Token, address _l2Token, address _from, address _to, uint256 _amount, bytes calldata _data ) external virtual onlyFromCrossDomainAccount(l1TokenBridge) { // Check the target token is compliant and // verify the deposited token on L1 matches the L2 deposited token representation here if ( ERC165Checker.supportsInterface(_l2Token, 0x1d1d8b63) && _l1Token == IL2StandardERC20(_l2Token).l1Token() ) { // When a deposit is finalized, we credit the account on L2 with the same amount of // tokens. IL2StandardERC20(_l2Token).mint(_to, _amount); emit DepositFinalized(_l1Token, _l2Token, _from, _to, _amount, _data); } else { // Either the L2 token which is being deposited-into disagrees about the correct address // of its L1 token, or does not support the correct interface. // This should only happen if there is a malicious L2 token, or if a user somehow // specified the wrong L2 token address to deposit into. // In either case, we stop the process here and construct a withdrawal // message so that users can get their funds out in some cases. // There is no way to prevent malicious token contracts altogether, but this does limit // user error and mitigate some forms of malicious contract behavior. bytes memory message = abi.encodeWithSelector( IL1ERC20Bridge.finalizeERC20Withdrawal.selector, _l1Token, _l2Token, _to, // switched the _to and _from here to bounce back the deposit to the sender _from, _amount, _data ); // Send message up to L1 bridge sendCrossDomainMessage(l1TokenBridge, 0, message); emit DepositFailed(_l1Token, _l2Token, _from, _to, _amount, _data); } } }
// SPDX-License-Identifier: MIT pragma solidity >0.7.5; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { ERC20Permit } from "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol"; import { ERC20Votes } from "@openzeppelin/contracts/token/ERC20/extensions/regenesis/ERC20VotesRegenesis.sol"; import { ERC20VotesComp } from "@openzeppelin/contracts/token/ERC20/extensions/regenesis/ERC20VotesCompRegenesis.sol"; import { Address } from "@openzeppelin/contracts/utils/Address.sol"; /* External Imports */ import "@openzeppelin/contracts/security/Pausable.sol"; contract xL2GovernanceERC20 is ERC20, ERC20Permit, ERC20Votes, ERC20VotesComp, Pausable { uint224 public constant maxSupply = 500000000e18; // 500 million BOBA uint8 private immutable _decimals; address public owner; address public DAO; mapping(address => bool) public controllers; /** * @param _name ERC20 name. * @param _symbol ERC20 symbol. */ constructor( string memory _name, string memory _symbol, uint8 decimals_ ) ERC20(_name, _symbol) ERC20Permit(_name) { _decimals = decimals_; owner = msg.sender; DAO = msg.sender; _pause(); } modifier onlyOwner { require(msg.sender == owner || owner == address(0), 'Caller is not the owner'); _; } modifier onlyDAO { require(msg.sender == DAO, 'Caller is not the owner'); _; } modifier onlyController { require(controllers[msg.sender], "Only controller can mint and burn"); _; } modifier onlyContract (address _address) { require(Address.isContract(_address), "Account not contract"); _; } /** * transfer ownership * * @param _newOwner new owner of this contract */ function transferOwnership( address _newOwner ) public onlyOwner() { owner = _newOwner; } /** * transfer DAO * * @param _newDAO new owner of this contract */ function transferDAO( address _newDAO ) public onlyDAO() { DAO = _newDAO; } /** * add controller * * @param _controller new controller of this contract */ function addController( address _controller ) public onlyOwner() onlyContract(_controller) { require(!controllers[_controller]); controllers[_controller] = true; } /** * delete controller * * @param _controller controller of this contract */ function deleteController( address _controller ) public onlyOwner() onlyContract(_controller) { require(controllers[_controller]); controllers[_controller] = false; } /** * Pause contract */ function pause() external onlyDAO() { _pause(); } /** * UnPause contract */ function unpause() external onlyDAO() { _unpause(); } function decimals() public view virtual override returns (uint8) { return _decimals; } function supportsInterface(bytes4 _interfaceId) public pure returns (bool) { bytes4 firstSupportedInterface = bytes4(keccak256("supportsInterface(bytes4)")); // ERC165 return _interfaceId == firstSupportedInterface; } function mint(address _to, uint256 _amount) public virtual onlyController { _mint(_to, _amount); } function burn(address _from, uint256 _amount) public virtual onlyController { _burn(_from, _amount); } // Overrides required by Solidity function _mint(address _to, uint256 _amount) internal override (ERC20, ERC20Votes) { super._mint(_to, _amount); } function _burn(address _account, uint256 _amount) internal override (ERC20, ERC20Votes) { super._burn(_account, _amount); } function transfer(address recipient, uint256 amount) public virtual whenNotPaused override (ERC20) returns (bool) { return super.transfer(recipient, amount); } function transferFrom( address sender, address recipient, uint256 amount ) public virtual whenNotPaused override (ERC20) returns (bool) { return super.transferFrom(sender, recipient, amount); } function approve(address spender, uint256 amount) public virtual whenNotPaused override (ERC20) returns (bool) { return super.approve(spender, amount); } function increaseAllowance(address spender, uint256 addedValue) public virtual whenNotPaused override (ERC20) returns (bool) { return super.increaseAllowance(spender, addedValue); } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual whenNotPaused override (ERC20) returns (bool) { return super.decreaseAllowance(spender, subtractedValue); } function _afterTokenTransfer( address from, address to, uint256 amount ) internal override (ERC20, ERC20Votes) { super._afterTokenTransfer(from, to, amount); } function _maxSupply() internal pure override (ERC20Votes, ERC20VotesComp) returns (uint224) { return maxSupply; } }
// SPDX-License-Identifier: MIT pragma solidity >0.7.5; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; contract L2BillingContract { using SafeERC20 for IERC20; /************* * Variables * *************/ address public owner; address public feeTokenAddress; address public l2FeeWallet; uint256 public exitFee; /************* * Events * *************/ event TransferOwnership(address, address); event UpdateExitFee(uint256); event CollectFee(address, uint256); event Withdraw(address, uint256); /************* * Modifiers * *************/ modifier onlyNotInitialized() { require(feeTokenAddress == address(0), "Contract has been initialized"); _; } modifier onlyInitialized() { require(feeTokenAddress != address(0), "Contract has not been initialized"); _; } modifier onlyOwner() { require(owner == msg.sender, "Caller is not the owner"); _; } /************* * Functions * *************/ function initialize(address _feeTokenAddress, address _l2FeeWallet, uint256 _exitFee) public onlyNotInitialized { require(_feeTokenAddress != address(0), "Fee token address cannot be zero"); require(_l2FeeWallet != address(0), "L2 fee wallet cannot be zero"); require(_exitFee > 0, "exit fee cannot be zero"); feeTokenAddress = _feeTokenAddress; l2FeeWallet = _l2FeeWallet; exitFee = _exitFee; owner = msg.sender; } function transferOwnership(address _newOwner) public onlyOwner { require(_newOwner != address(0), "Ownable: new owner is the zero address"); address oldOwner = owner; owner = _newOwner; emit TransferOwnership(oldOwner, _newOwner); } function updateExitFee(uint256 _exitFee) public onlyOwner() { require(_exitFee > 0, "exit fee cannot be zero"); exitFee = _exitFee; emit UpdateExitFee(_exitFee); } function collectFee() external onlyInitialized { IERC20(feeTokenAddress).safeTransferFrom(msg.sender, address(this), exitFee); emit CollectFee(msg.sender, exitFee); } function withdraw() external onlyInitialized { uint256 balance = IERC20(feeTokenAddress).balanceOf(address(this)); require(balance >= 150e18, "Balance is too low"); IERC20(feeTokenAddress).safeTransfer(l2FeeWallet, balance); emit Withdraw(l2FeeWallet, balance); } }
// SPDX-License-Identifier: MIT pragma solidity >0.5.0 <0.9.0; /** * @title ICrossDomainMessenger */ interface ICrossDomainMessenger { /********** * Events * **********/ event SentMessage( address indexed target, address sender, bytes message, uint256 messageNonce, uint256 gasLimit ); event RelayedMessage(bytes32 indexed msgHash); event FailedRelayedMessage(bytes32 indexed msgHash); /************* * Variables * *************/ function xDomainMessageSender() external view returns (address); /******************** * Public Functions * ********************/ /** * Sends a cross domain message to the target messenger. * @param _target Target contract address. * @param _message Message to send to the target. * @param _gasLimit Gas limit for the provided message. */ function sendMessage( address _target, bytes calldata _message, uint32 _gasLimit ) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) 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 `amount` 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 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @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); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @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, it is bubbled up by this * function (like regular Solidity function calls). * * 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. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @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`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // 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 { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 a proxied contract can't have 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. * * 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. */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Modifier to protect an initializer function from being invoked twice. */ modifier initializer() { require(_initializing || !_initialized, "Initializable: contract is already initialized"); bool isTopLevelCall = !_initializing; if (isTopLevelCall) { _initializing = true; _initialized = true; } _; if (isTopLevelCall) { _initializing = false; } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../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 initializer { __Context_init_unchained(); } function __Context_init_unchained() internal initializer { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } uint256[50] private __gap; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT pragma solidity >0.5.0 <0.9.0; import "./IL1ERC20Bridge.sol"; /** * @title IL1StandardBridge */ interface IL1StandardBridge is IL1ERC20Bridge { /********** * Events * **********/ event ETHDepositInitiated( address indexed _from, address indexed _to, uint256 _amount, bytes _data ); event ETHWithdrawalFinalized( address indexed _from, address indexed _to, uint256 _amount, bytes _data ); /******************** * Public Functions * ********************/ /** * @dev Deposit an amount of the ETH to the caller's balance on L2. * @param _l2Gas Gas limit required to complete the deposit on L2. * @param _data Optional data to forward to L2. This data is provided * solely as a convenience for external contracts. Aside from enforcing a maximum * length, these contracts provide no guarantees about its content. */ function depositETH(uint32 _l2Gas, bytes calldata _data) external payable; /** * @dev Deposit an amount of ETH to a recipient's balance on L2. * @param _to L2 address to credit the withdrawal to. * @param _l2Gas Gas limit required to complete the deposit on L2. * @param _data Optional data to forward to L2. This data is provided * solely as a convenience for external contracts. Aside from enforcing a maximum * length, these contracts provide no guarantees about its content. */ function depositETHTo( address _to, uint32 _l2Gas, bytes calldata _data ) external payable; /************************* * Cross-chain Functions * *************************/ /** * @dev Complete a withdrawal from L2 to L1, and credit funds to the recipient's balance of the * L1 ETH token. Since only the xDomainMessenger can call this function, it will never be called * before the withdrawal is finalized. * @param _from L2 address initiating the transfer. * @param _to L1 address to credit the withdrawal to. * @param _amount Amount of the ERC20 to deposit. * @param _data Optional data to forward to L2. This data is provided * solely as a convenience for external contracts. Aside from enforcing a maximum * length, these contracts provide no guarantees about its content. */ function finalizeETHWithdrawal( address _from, address _to, uint256 _amount, bytes calldata _data ) external; }
// SPDX-License-Identifier: MIT pragma solidity >0.5.0 <0.9.0; /** * @title IL1ERC20Bridge */ interface IL1ERC20Bridge { /********** * Events * **********/ event ERC20DepositInitiated( address indexed _l1Token, address indexed _l2Token, address indexed _from, address _to, uint256 _amount, bytes _data ); event ERC20WithdrawalFinalized( address indexed _l1Token, address indexed _l2Token, address indexed _from, address _to, uint256 _amount, bytes _data ); /******************** * Public Functions * ********************/ /** * @dev get the address of the corresponding L2 bridge contract. * @return Address of the corresponding L2 bridge contract. */ function l2TokenBridge() external returns (address); /** * @dev deposit an amount of the ERC20 to the caller's balance on L2. * @param _l1Token Address of the L1 ERC20 we are depositing * @param _l2Token Address of the L1 respective L2 ERC20 * @param _amount Amount of the ERC20 to deposit * @param _l2Gas Gas limit required to complete the deposit on L2. * @param _data Optional data to forward to L2. This data is provided * solely as a convenience for external contracts. Aside from enforcing a maximum * length, these contracts provide no guarantees about its content. */ function depositERC20( address _l1Token, address _l2Token, uint256 _amount, uint32 _l2Gas, bytes calldata _data ) external; /** * @dev deposit an amount of ERC20 to a recipient's balance on L2. * @param _l1Token Address of the L1 ERC20 we are depositing * @param _l2Token Address of the L1 respective L2 ERC20 * @param _to L2 address to credit the withdrawal to. * @param _amount Amount of the ERC20 to deposit. * @param _l2Gas Gas limit required to complete the deposit on L2. * @param _data Optional data to forward to L2. This data is provided * solely as a convenience for external contracts. Aside from enforcing a maximum * length, these contracts provide no guarantees about its content. */ function depositERC20To( address _l1Token, address _l2Token, address _to, uint256 _amount, uint32 _l2Gas, bytes calldata _data ) external; /************************* * Cross-chain Functions * *************************/ /** * @dev Complete a withdrawal from L2 to L1, and credit funds to the recipient's balance of the * L1 ERC20 token. * This call will fail if the initialized withdrawal from L2 has not been finalized. * * @param _l1Token Address of L1 token to finalizeWithdrawal for. * @param _l2Token Address of L2 token where withdrawal was initiated. * @param _from L2 address initiating the transfer. * @param _to L1 address to credit the withdrawal to. * @param _amount Amount of the ERC20 to deposit. * @param _data Data provided by the sender on L2. This data is provided * solely as a convenience for external contracts. Aside from enforcing a maximum * length, these contracts provide no guarantees about its content. */ function finalizeERC20Withdrawal( address _l1Token, address _l2Token, address _from, address _to, uint256 _amount, bytes calldata _data ) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; /** * @title IL2ERC20Bridge */ interface IL2ERC20Bridge { /********** * Events * **********/ event WithdrawalInitiated( address indexed _l1Token, address indexed _l2Token, address indexed _from, address _to, uint256 _amount, bytes _data ); event DepositFinalized( address indexed _l1Token, address indexed _l2Token, address indexed _from, address _to, uint256 _amount, bytes _data ); event DepositFailed( address indexed _l1Token, address indexed _l2Token, address indexed _from, address _to, uint256 _amount, bytes _data ); /******************** * Public Functions * ********************/ /** * @dev get the address of the corresponding L1 bridge contract. * @return Address of the corresponding L1 bridge contract. */ function l1TokenBridge() external returns (address); /** * @dev initiate a withdraw of some tokens to the caller's account on L1 * @param _l2Token Address of L2 token where withdrawal was initiated. * @param _amount Amount of the token to withdraw. * param _l1Gas Unused, but included for potential forward compatibility considerations. * @param _data Optional data to forward to L1. This data is provided * solely as a convenience for external contracts. Aside from enforcing a maximum * length, these contracts provide no guarantees about its content. */ function withdraw( address _l2Token, uint256 _amount, uint32 _l1Gas, bytes calldata _data ) external; /** * @dev initiate a withdraw of some token to a recipient's account on L1. * @param _l2Token Address of L2 token where withdrawal is initiated. * @param _to L1 adress to credit the withdrawal to. * @param _amount Amount of the token to withdraw. * param _l1Gas Unused, but included for potential forward compatibility considerations. * @param _data Optional data to forward to L1. This data is provided * solely as a convenience for external contracts. Aside from enforcing a maximum * length, these contracts provide no guarantees about its content. */ function withdrawTo( address _l2Token, address _to, uint256 _amount, uint32 _l1Gas, bytes calldata _data ) external; /************************* * Cross-chain Functions * *************************/ /** * @dev Complete a deposit from L1 to L2, and credits funds to the recipient's balance of this * L2 token. This call will fail if it did not originate from a corresponding deposit in * L1StandardTokenBridge. * @param _l1Token Address for the l1 token this is called with * @param _l2Token Address for the l2 token this is called with * @param _from Account to pull the deposit from on L2. * @param _to Address to receive the withdrawal at * @param _amount Amount of the token to withdraw * @param _data Data provider by the sender on L1. This data is provided * solely as a convenience for external contracts. Aside from enforcing a maximum * length, these contracts provide no guarantees about its content. */ function finalizeDeposit( address _l1Token, address _l2Token, address _from, address _to, uint256 _amount, bytes calldata _data ) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Library used to query support of an interface declared via {IERC165}. * * Note that these functions return the actual result of the query: they do not * `revert` if an interface is not supported. It is up to the caller to decide * what to do in these cases. */ library ERC165Checker { // As per the EIP-165 spec, no interface should ever match 0xffffffff bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff; /** * @dev Returns true if `account` supports the {IERC165} interface, */ function supportsERC165(address account) internal view returns (bool) { // Any contract that implements ERC165 must explicitly indicate support of // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid return _supportsERC165Interface(account, type(IERC165).interfaceId) && !_supportsERC165Interface(account, _INTERFACE_ID_INVALID); } /** * @dev Returns true if `account` supports the interface defined by * `interfaceId`. Support for {IERC165} itself is queried automatically. * * See {IERC165-supportsInterface}. */ function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) { // query support of both ERC165 as per the spec and support of _interfaceId return supportsERC165(account) && _supportsERC165Interface(account, interfaceId); } /** * @dev Returns a boolean array where each value corresponds to the * interfaces passed in and whether they're supported or not. This allows * you to batch check interfaces for a contract where your expectation * is that some interfaces may not be supported. * * See {IERC165-supportsInterface}. * * _Available since v3.4._ */ function getSupportedInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool[] memory) { // an array of booleans corresponding to interfaceIds and whether they're supported or not bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length); // query support of ERC165 itself if (supportsERC165(account)) { // query support of each interface in interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { interfaceIdsSupported[i] = _supportsERC165Interface(account, interfaceIds[i]); } } return interfaceIdsSupported; } /** * @dev Returns true if `account` supports all the interfaces defined in * `interfaceIds`. Support for {IERC165} itself is queried automatically. * * Batch-querying can lead to gas savings by skipping repeated checks for * {IERC165} support. * * See {IERC165-supportsInterface}. */ function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) { // query support of ERC165 itself if (!supportsERC165(account)) { return false; } // query support of each interface in _interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { if (!_supportsERC165Interface(account, interfaceIds[i])) { return false; } } // all interfaces supported return true; } /** * @notice Query if a contract implements an interface, does not check ERC165 support * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Assumes that account contains a contract that supports ERC165, otherwise * the behavior of this method is undefined. This precondition can be checked * with {supportsERC165}. * Interface identification is specified in ERC-165. */ function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) { bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId); (bool success, bytes memory result) = account.staticcall{gas: 30000}(encodedParams); if (result.length < 32) return false; return success && abi.decode(result, (bool)); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; interface IL2StandardERC20 is IERC20, IERC165 { function l1Token() external returns (address); function mint(address _to, uint256 _amount) external; function burn(address _from, uint256 _amount) external; event Mint(address indexed _account, uint256 _amount); event Burn(address indexed _account, uint256 _amount); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * 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[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); unchecked { _approve(sender, _msgSender(), currentAllowance - amount); } return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(_msgSender(), spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `sender` to `recipient`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[sender] = senderBalance - amount; } _balances[recipient] += amount; emit Transfer(sender, recipient, amount); _afterTokenTransfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./draft-IERC20Permit.sol"; import "../ERC20.sol"; import "../../../utils/cryptography/draft-EIP712.sol"; import "../../../utils/cryptography/ECDSA.sol"; import "../../../utils/Counters.sol"; /** * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. * * _Available since v3.4._ */ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { using Counters for Counters.Counter; mapping(address => Counters.Counter) private _nonces; // solhint-disable-next-line var-name-mixedcase bytes32 private immutable _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); /** * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. * * It's a good idea to use the same `name` that is defined as the ERC20 token name. */ constructor(string memory name) EIP712(name, "1") {} /** * @dev See {IERC20Permit-permit}. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual override { require(block.timestamp <= deadline, "ERC20Permit: expired deadline"); bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline)); bytes32 hash = _hashTypedDataV4(structHash); address signer = ECDSA.recover(hash, v, r, s); require(signer == owner, "ERC20Permit: invalid signature"); _approve(owner, spender, value); } /** * @dev See {IERC20Permit-nonces}. */ function nonces(address owner) public view virtual override returns (uint256) { return _nonces[owner].current(); } /** * @dev See {IERC20Permit-DOMAIN_SEPARATOR}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view override returns (bytes32) { return _domainSeparatorV4(); } /** * @dev "Consume a nonce": return the current value and increment. * * _Available since v4.1._ */ function _useNonce(address owner) internal virtual returns (uint256 current) { Counters.Counter storage nonce = _nonces[owner]; current = nonce.current(); nonce.increment(); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../draft-ERC20Permit.sol"; import "../../../../utils/math/Math.sol"; import "../../../../utils/math/SafeCast.sol"; import "../../../../utils/cryptography/ECDSA.sol"; /** * @dev Extension of ERC20 to support Compound-like voting and delegation. This version is more generic than Compound's, * and supports token supply up to 2^224^ - 1, while COMP is limited to 2^96^ - 1. * * NOTE: If exact COMP compatibility is required, use the {ERC20VotesComp} variant of this module. * * This extension keeps a history (checkpoints) of each account's vote power. Vote power can be delegated either * by calling the {delegate} function directly, or by providing a signature to be used with {delegateBySig}. Voting * power can be queried through the public accessors {getVotes} and {getPastVotes}. * * By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it * requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked. * Enabling self-delegation can easily be done by overriding the {delegates} function. Keep in mind however that this * will significantly increase the base gas cost of transfers. * * _Available since v4.2._ */ abstract contract ERC20Votes is ERC20Permit { struct Checkpoint { uint32 fromBlock; uint224 votes; } bytes32 private constant _DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); mapping(address => address) private _delegates; mapping(address => Checkpoint[]) private _checkpoints; Checkpoint[] private _totalSupplyCheckpoints; // for regenesis, this is cumulative, all blocks since contract // OFFSET = current OFFSET + blocks in old chain uint256 public constant OFFSET = 0; /** * @dev Emitted when an account changes their delegate. */ event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); /** * @dev Emitted when a token transfer or delegate change results in changes to an account's voting power. */ event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance); /** * @dev Get the `pos`-th checkpoint for `account`. */ function checkpoints(address account, uint32 pos) public view virtual returns (Checkpoint memory) { return _checkpoints[account][pos]; } /** * @dev Get number of checkpoints for `account`. */ function numCheckpoints(address account) public view virtual returns (uint32) { return SafeCast.toUint32(_checkpoints[account].length); } /** * @dev Get the address `account` is currently delegating to. */ function delegates(address account) public view virtual returns (address) { return _delegates[account]; } /** * @dev Gets the current votes balance for `account` */ function getVotes(address account) public view returns (uint256) { uint256 pos = _checkpoints[account].length; return pos == 0 ? 0 : _checkpoints[account][pos - 1].votes; } /** * @dev Retrieve the number of votes for `account` at the end of `blockNumber`. * * Requirements: * * - `blockNumber` must have been already mined */ function getPastVotes(address account, uint256 blockNumber) public view returns (uint256) { require(blockNumber < block.number, "ERC20Votes: block not yet mined"); return _checkpointsLookup(_checkpoints[account], blockNumber); } /** * @dev Retrieve the `totalSupply` at the end of `blockNumber`. Note, this value is the sum of all balances. * It is but NOT the sum of all the delegated votes! * * Requirements: * * - `blockNumber` must have been already mined */ function getPastTotalSupply(uint256 blockNumber) public view returns (uint256) { require(blockNumber < block.number, "ERC20Votes: block not yet mined"); return _checkpointsLookup(_totalSupplyCheckpoints, blockNumber); } /** * @dev Lookup a value in a list of (sorted) checkpoints. */ function _checkpointsLookup(Checkpoint[] storage ckpts, uint256 blockNumber) private view returns (uint256) { // We run a binary search to look for the earliest checkpoint taken after `blockNumber`. // // During the loop, the index of the wanted checkpoint remains in the range [low-1, high). // With each iteration, either `low` or `high` is moved towards the middle of the range to maintain the invariant. // - If the middle checkpoint is after `blockNumber`, we look in [low, mid) // - If the middle checkpoint is before or equal to `blockNumber`, we look in [mid+1, high) // Once we reach a single value (when low == high), we've found the right checkpoint at the index high-1, if not // out of bounds (in which case we're looking too far in the past and the result is 0). // Note that if the latest checkpoint available is exactly for `blockNumber`, we end up with an index that is // past the end of the array, so we technically don't find a checkpoint after `blockNumber`, but it works out // the same. blockNumber += OFFSET; uint256 high = ckpts.length; uint256 low = 0; while (low < high) { uint256 mid = Math.average(low, high); if (ckpts[mid].fromBlock > blockNumber) { high = mid; } else { low = mid + 1; } } return high == 0 ? 0 : ckpts[high - 1].votes; } /** * @dev Delegate votes from the sender to `delegatee`. */ function delegate(address delegatee) public virtual { return _delegate(_msgSender(), delegatee); } /** * @dev Delegates votes from signer to `delegatee` */ function delegateBySig( address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s ) public virtual { require(block.timestamp <= expiry, "ERC20Votes: signature expired"); address signer = ECDSA.recover( _hashTypedDataV4(keccak256(abi.encode(_DELEGATION_TYPEHASH, delegatee, nonce, expiry))), v, r, s ); require(nonce == _useNonce(signer), "ERC20Votes: invalid nonce"); return _delegate(signer, delegatee); } /** * @dev Maximum token supply. Defaults to `type(uint224).max` (2^224^ - 1). */ function _maxSupply() internal view virtual returns (uint224) { return type(uint224).max; } /** * @dev Snapshots the totalSupply after it has been increased. */ function _mint(address account, uint256 amount) internal virtual override { super._mint(account, amount); require(totalSupply() <= _maxSupply(), "ERC20Votes: total supply risks overflowing votes"); _writeCheckpoint(_totalSupplyCheckpoints, _add, amount); } /** * @dev Snapshots the totalSupply after it has been decreased. */ function _burn(address account, uint256 amount) internal virtual override { super._burn(account, amount); _writeCheckpoint(_totalSupplyCheckpoints, _subtract, amount); } /** * @dev Move voting power when tokens are transferred. * * Emits a {DelegateVotesChanged} event. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual override { super._afterTokenTransfer(from, to, amount); _moveVotingPower(delegates(from), delegates(to), amount); } /** * @dev Change delegation for `delegator` to `delegatee`. * * Emits events {DelegateChanged} and {DelegateVotesChanged}. */ function _delegate(address delegator, address delegatee) internal virtual { address currentDelegate = delegates(delegator); uint256 delegatorBalance = balanceOf(delegator); _delegates[delegator] = delegatee; emit DelegateChanged(delegator, currentDelegate, delegatee); _moveVotingPower(currentDelegate, delegatee, delegatorBalance); } function _moveVotingPower( address src, address dst, uint256 amount ) private { if (src != dst && amount > 0) { if (src != address(0)) { (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[src], _subtract, amount); emit DelegateVotesChanged(src, oldWeight, newWeight); } if (dst != address(0)) { (uint256 oldWeight, uint256 newWeight) = _writeCheckpoint(_checkpoints[dst], _add, amount); emit DelegateVotesChanged(dst, oldWeight, newWeight); } } } function _writeCheckpoint( Checkpoint[] storage ckpts, function(uint256, uint256) view returns (uint256) op, uint256 delta ) private returns (uint256 oldWeight, uint256 newWeight) { uint256 pos = ckpts.length; oldWeight = pos == 0 ? 0 : ckpts[pos - 1].votes; newWeight = op(oldWeight, delta); if (pos > 0 && ckpts[pos - 1].fromBlock == block.number + OFFSET) { ckpts[pos - 1].votes = SafeCast.toUint224(newWeight); } else { ckpts.push(Checkpoint({fromBlock: SafeCast.toUint32(block.number + OFFSET), votes: SafeCast.toUint224(newWeight)})); } } function _add(uint256 a, uint256 b) private pure returns (uint256) { return a + b; } function _subtract(uint256 a, uint256 b) private pure returns (uint256) { return a - b; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ERC20VotesRegenesis.sol"; /** * @dev Extension of ERC20 to support Compound's voting and delegation. This version exactly matches Compound's * interface, with the drawback of only supporting supply up to (2^96^ - 1). * * NOTE: You should use this contract if you need exact compatibility with COMP (for example in order to use your token * with Governor Alpha or Bravo) and if you are sure the supply cap of 2^96^ is enough for you. Otherwise, use the * {ERC20Votes} variant of this module. * * This extension keeps a history (checkpoints) of each account's vote power. Vote power can be delegated either * by calling the {delegate} function directly, or by providing a signature to be used with {delegateBySig}. Voting * power can be queried through the public accessors {getCurrentVotes} and {getPriorVotes}. * * By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it * requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked. * Enabling self-delegation can easily be done by overriding the {delegates} function. Keep in mind however that this * will significantly increase the base gas cost of transfers. * * _Available since v4.2._ */ abstract contract ERC20VotesComp is ERC20Votes { /** * @dev Comp version of the {getVotes} accessor, with `uint96` return type. */ function getCurrentVotes(address account) external view returns (uint96) { return SafeCast.toUint96(getVotes(account)); } /** * @dev Comp version of the {getPastVotes} accessor, with `uint96` return type. */ function getPriorVotes(address account, uint256 blockNumber) external view returns (uint96) { return SafeCast.toUint96(getPastVotes(account, blockNumber)); } /** * @dev Maximum token supply. Reduced to `type(uint96).max` (2^96^ - 1) to fit COMP interface. */ function _maxSupply() internal view virtual override returns (uint224) { return type(uint96).max; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { /** * @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); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./ECDSA.sol"; /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. * * The encoding specified in the EIP is very generic, and such a generic 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 their contracts 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]. * * _Available since v3.4._ */ abstract contract EIP712 { /* solhint-disable var-name-mixedcase */ // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to // invalidate the cached domain separator if the chain id changes. bytes32 private immutable _CACHED_DOMAIN_SEPARATOR; uint256 private immutable _CACHED_CHAIN_ID; bytes32 private immutable _HASHED_NAME; bytes32 private immutable _HASHED_VERSION; bytes32 private immutable _TYPE_HASH; /* solhint-enable var-name-mixedcase */ /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ constructor(string memory name, string memory version) { bytes32 hashedName = keccak256(bytes(name)); bytes32 hashedVersion = keccak256(bytes(version)); bytes32 typeHash = keccak256( "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)" ); _HASHED_NAME = hashedName; _HASHED_VERSION = hashedVersion; _CACHED_CHAIN_ID = block.chainid; _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion); _TYPE_HASH = typeHash; } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view returns (bytes32) { if (block.chainid == _CACHED_CHAIN_ID) { return _CACHED_DOMAIN_SEPARATOR; } else { return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION); } } function _buildDomainSeparator( bytes32 typeHash, bytes32 nameHash, bytes32 versionHash ) private view returns (bytes32) { return keccak256(abi.encode(typeHash, nameHash, versionHash, 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 ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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, InvalidSignatureV } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } else if (error == RecoverError.InvalidSignatureV) { revert("ECDSA: invalid signature 'v' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode 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 {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] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { // Check the signature length // - case 65: r,s,v signature (standard) // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._ 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 { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else if (signature.length == 64) { bytes32 r; bytes32 vs; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. assembly { r := mload(add(signature, 0x20)) vs := mload(add(signature, 0x40)) } return tryRecover(hash, r, vs); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode 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 {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); 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[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s; uint8 v; assembly { s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) v := add(shr(255, vs), 27) } return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // 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); } if (v != 27 && v != 28) { return (address(0), RecoverError.InvalidSignatureV); } // 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); } return (signer, RecoverError.NoError); } /** * @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) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids. * * Include with `using Counters for Counters.Counter;` */ library Counters { struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { unchecked { counter._value += 1; } } function decrement(Counter storage counter) internal { uint256 value = counter._value; require(value > 0, "Counter: decrement overflow"); unchecked { counter._value = value - 1; } } function reset(Counter storage counter) internal { counter._value = 0; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a / b + (a % b == 0 ? 0 : 1); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX 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. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @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) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(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) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(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) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(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) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(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) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(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) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); 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) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); 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) { require(value >= 0, "SafeCast: value must be positive"); return uint256(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 * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128) { require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits"); return int128(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 * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64) { require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits"); return int64(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 * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32) { require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits"); return int32(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 * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16) { require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits"); return int16(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. * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8) { require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits"); return int8(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 require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
{ "optimizer": { "enabled": true, "runs": 10000 }, "metadata": { "bytecodeHash": "none", "useLiteralContent": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"}],"name":"AddLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"receivedAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"}],"name":"ClientDepositL2","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"userRewardFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ownerRewardFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalFee","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"}],"name":"ClientPayL2","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"userRewardFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ownerRewardFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalFee","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"}],"name":"ClientPayL2Settlement","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newDao","type":"address"}],"name":"DaoRoleTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"}],"name":"OwnerRecoverFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"}],"name":"RebalanceLP","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"}],"name":"WithdrawLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"}],"name":"WithdrawReward","type":"event"},{"inputs":[],"name":"BOBAAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DAO","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_FINALIZE_WITHDRAWAL_L1_GAS","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"L1LiquidityPoolAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_tokenAddress","type":"address"}],"name":"addLiquidity","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"billingContractAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_tokenAddress","type":"address"}],"name":"clientDepositL2","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_tokenAddress","type":"address"}],"name":"clientPayL2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address payable","name":"to","type":"address"},{"internalType":"address","name":"l2TokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct L2LiquidityPool.ClientPayToken[]","name":"_tokens","type":"tuple[]"}],"name":"clientPayL2Batch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_tokenAddress","type":"address"}],"name":"clientPayL2Settlement","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_billingContractAddress","type":"address"}],"name":"configureBillingContractAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_userRewardMinFeeRate","type":"uint256"},{"internalType":"uint256","name":"_userRewardMaxFeeRate","type":"uint256"},{"internalType":"uint256","name":"_ownerRewardFeeRate","type":"uint256"}],"name":"configureFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_userRewardMinFeeRate","type":"uint256"},{"internalType":"uint256","name":"_userRewardMaxFeeRate","type":"uint256"},{"internalType":"uint256","name":"_ownerRewardFeeRate","type":"uint256"}],"name":"configureFeeExits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_l1GasFee","type":"uint32"}],"name":"configureGas","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"extraGasRelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFinalizeDepositL1Gas","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_l2TokenAddress","type":"address"}],"name":"getUserRewardFeeRate","outputs":[{"internalType":"uint256","name":"userRewardFeeRate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_l2CrossDomainMessenger","type":"address"},{"internalType":"address","name":"_L1LiquidityPoolAddress","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"messenger","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address","name":"_to","type":"address"}],"name":"ownerRecoverFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"ownerRewardFeeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"poolInfo","outputs":[{"internalType":"address","name":"l1TokenAddress","type":"address"},{"internalType":"address","name":"l2TokenAddress","type":"address"},{"internalType":"uint256","name":"userDepositAmount","type":"uint256"},{"internalType":"uint256","name":"lastAccUserReward","type":"uint256"},{"internalType":"uint256","name":"accUserReward","type":"uint256"},{"internalType":"uint256","name":"accUserRewardPerShare","type":"uint256"},{"internalType":"uint256","name":"accOwnerReward","type":"uint256"},{"internalType":"uint256","name":"startTime","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_tokenAddress","type":"address"}],"name":"rebalanceLP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_BOBAAddress","type":"address"},{"internalType":"address","name":"_xBOBAAddress","type":"address"}],"name":"registerBOBA","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_l1TokenAddress","type":"address"},{"internalType":"address","name":"_l2TokenAddress","type":"address"}],"name":"registerPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newDAO","type":"address"}],"name":"transferDAORole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"}],"name":"updateUserRewardPerShare","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"userInfo","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"rewardDebt","type":"uint256"},{"internalType":"uint256","name":"pendingReward","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"userRewardMaxFeeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"userRewardMinFeeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address payable","name":"_to","type":"address"}],"name":"withdrawLiquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address","name":"_to","type":"address"}],"name":"withdrawReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"xBOBAAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"xBOBAStatus","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b50600080546001600160a01b0319169055615052806100306000396000f3fe6080604052600436106102a05760003560e01c80636854e22b1161016e57806398fabd3a116100cb578063c58827ea1161007f578063ecb12db011610064578063ecb12db0146107fa578063f2fde38b1461081a578063f48712681461083a57600080fd5b8063c58827ea146107c7578063c95f9d0e146107e757600080fd5b80639a7b5f11116100b05780639a7b5f11146106d6578063b4eeb98814610787578063bd2d1cab146107a757600080fd5b806398fabd3a14610693578063997d73df146106bb57600080fd5b8063744a5aa21161012257806381e6bdac1161010757806381e6bdac1461063e5780638456cb591461065e5780638da5cb5b1461067357600080fd5b8063744a5aa21461061257806377b594a21461062857600080fd5b80636af9f1c2116101535780636af9f1c2146105bc57806370ac3180146105dc5780637286e5e5146105f257600080fd5b80636854e22b1461056a57806368be42ca1461059c57600080fd5b80633cb747bf1161021c578063485cc955116101d0578063531645cb116101b5578063531645cb146105125780635c975abb14610532578063650a767b1461054a57600080fd5b8063485cc955146104d257806349561dc4146104f257600080fd5b80633f4ba83a116102015780633f4ba83a1461047d5780633f89e9521461049257806341132e4c146104b257600080fd5b80633cb747bf1461043d5780633d93941b1461045d57600080fd5b80631786e46d116102735780631f0bfb8c116102585780631f0bfb8c146103b957806334636648146103f9578063358fc07e1461041957600080fd5b80631786e46d146103865780631d00a771146103a657600080fd5b8063067b2dcb146102a55780630f208beb146102c757806312f54c1a1461032e57806316a8dda71461034e575b600080fd5b3480156102b157600080fd5b506102c56102c0366004614b85565b61085a565b005b3480156102d357600080fd5b5061030e6102e2366004614b85565b609860209081526000928352604080842090915290825290208054600182015460029092015490919083565b604080519384526020840192909252908201526060015b60405180910390f35b34801561033a57600080fd5b506102c5610349366004614bbe565b610994565b34801561035a57600080fd5b50609a5461036e906001600160a01b031681565b6040516001600160a01b039091168152602001610325565b34801561039257600080fd5b5060a15461036e906001600160a01b031681565b6102c56103b4366004614bdb565b610a2a565b3480156103c557600080fd5b506103e96103d4366004614bbe565b60a26020526000908152604090205460ff1681565b6040519015158152602001610325565b34801561040557600080fd5b506102c5610414366004614c00565b610f0c565b34801561042557600080fd5b5061042f609c5481565b604051908152602001610325565b34801561044957600080fd5b5060005461036e906001600160a01b031681565b34801561046957600080fd5b506102c5610478366004614bbe565b61102f565b34801561048957600080fd5b506102c5611153565b34801561049e57600080fd5b506102c56104ad366004614bdb565b6111cb565b3480156104be57600080fd5b506102c56104cd366004614c26565b6116f3565b3480156104de57600080fd5b506102c56104ed366004614b85565b611908565b3480156104fe57600080fd5b506102c561050d366004614c52565b611c49565b34801561051e57600080fd5b5060a05461036e906001600160a01b031681565b34801561053e57600080fd5b5060655460ff166103e9565b34801561055657600080fd5b506102c5610565366004614c94565b611f45565b34801561057657600080fd5b50609d546105879063ffffffff1681565b60405163ffffffff9091168152602001610325565b3480156105a857600080fd5b506102c56105b7366004614c52565b6123af565b3480156105c857600080fd5b5060a35461036e906001600160a01b031681565b3480156105e857600080fd5b5061042f609e5481565b3480156105fe57600080fd5b506102c561060d366004614b85565b6126ce565b34801561061e57600080fd5b5061042f609f5481565b34801561063457600080fd5b5061042f609b5481565b34801561064a57600080fd5b506102c5610659366004614c52565b612979565b34801561066a57600080fd5b506102c5612bf0565b34801561067f57600080fd5b5060995461036e906001600160a01b031681565b34801561069f57600080fd5b50609d5461036e9064010000000090046001600160a01b031681565b3480156106c757600080fd5b50609d5463ffffffff16610587565b3480156106e257600080fd5b506107416106f1366004614bbe565b609760205260009081526040902080546001820154600283015460038401546004850154600586015460068701546007909701546001600160a01b03968716979590961695939492939192909188565b604080516001600160a01b03998a168152989097166020890152958701949094526060860192909252608085015260a084015260c083015260e082015261010001610325565b34801561079357600080fd5b506102c56107a2366004614ccb565b612c66565b3480156107b357600080fd5b506102c56107c2366004614c94565b612f44565b3480156107d357600080fd5b506102c56107e2366004614c26565b6131cc565b6102c56107f5366004614bdb565b613356565b34801561080657600080fd5b5061042f610815366004614bbe565b61373a565b34801561082657600080fd5b506102c5610835366004614bbe565b6138fe565b34801561084657600080fd5b506102c5610855366004614bbe565b613a54565b6099546001600160a01b031633148061087c57506099546001600160a01b0316155b6108cd5760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420746865206f776e657200000000000000000060448201526064015b60405180910390fd5b60a1546001600160a01b03161580156108ee57506001600160a01b03821615155b801561090257506001600160a01b03811615155b61094e5760405162461bcd60e51b815260206004820152601460248201527f496e76616c696420424f4241206164647265737300000000000000000000000060448201526064016108c4565b60a180546001600160a01b039384167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161790915560a08054929093169116179055565b6001600160a01b0381166000908152609760205260409020600481015460038201541015610a265760006109d982600301548360040154613ba290919063ffffffff16565b90508160020154600014610a1a576002820154610a1490610a0990610a038464e8d4a51000613bb5565b90613bc1565b600584015490613bcd565b60058301555b50600481015460038201555b5050565b60655460ff1615610a7d5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016108c4565b60a3546001600160a01b0316610afb5760405162461bcd60e51b815260206004820152602360248201527f42696c6c696e6720636f6e74726163742061646472657373206973206e6f742060448201527f736574000000000000000000000000000000000000000000000000000000000060648201526084016108c4565b60a354604080517f6284ae4100000000000000000000000000000000000000000000000000000000815290516001600160a01b0390921691610c1d91339184918291636284ae4191600480820192602092909190829003018186803b158015610b6357600080fd5b505afa158015610b77573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b9b9190614d40565b846001600160a01b031663b8df0dea6040518163ffffffff1660e01b815260040160206040518083038186803b158015610bd457600080fd5b505afa158015610be8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c0c9190614d59565b6001600160a01b0316929190613bd9565b34151580610c4857506001600160a01b03821673420000000000000000000000000000000000000614155b610cba5760405162461bcd60e51b815260206004820152603260248201527f45697468657220416d6f756e7420496e636f7272656374206f7220546f6b656e60448201527f204164647265737320496e636f7272656374000000000000000000000000000060648201526084016108c4565b3415801590610ce657506001600160a01b03821673420000000000000000000000000000000000000614155b15610d595760405162461bcd60e51b815260206004820152603260248201527f45697468657220416d6f756e7420496e636f7272656374206f7220546f6b656e60448201527f204164647265737320496e636f7272656374000000000000000000000000000060648201526084016108c4565b3415610d7a5734925073420000000000000000000000000000000000000691505b6001600160a01b0380831660009081526097602052604090206001810154909116610de75760405162461bcd60e51b815260206004820152601c60248201527f546f6b656e2041646472657373204e6f7420526567697374657265640000000060448201526064016108c4565b60408051338152602081018690526001600160a01b0385168183015290517fe57500de6b6dcf76b201fef514aca6501809e3b700c9fbd5e803567c66edf54c9181900360600190a16001600160a01b03831673420000000000000000000000000000000000000614610e6857610e686001600160a01b038416333087613bd9565b805460408051336024820152604481018790526001600160a01b039283166064808301919091528251808303909101815260849091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fcf26fb1b00000000000000000000000000000000000000000000000000000000179052609a54609d549192610f059291169063ffffffff165b83613ca8565b5050505050565b6099546001600160a01b0316331480610f2e57506099546001600160a01b0316155b610f7a5760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420746865206f776e657200000000000000000060448201526064016108c4565b609a546001600160a01b0316610ff85760405162461bcd60e51b815260206004820152602560248201527f436f6e747261637420686173206e6f7420796574206265656e20696e6974696160448201527f6c697a656400000000000000000000000000000000000000000000000000000060648201526084016108c4565b609d80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff92909216919091179055565b6099546001600160a01b031633148061105157506099546001600160a01b0316155b61109d5760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420746865206f776e657200000000000000000060448201526064016108c4565b6001600160a01b0381166111195760405162461bcd60e51b815260206004820152602760248201527f42696c6c696e6720636f6e747261637420616464726573732063616e6e6f742060448201527f6265207a65726f0000000000000000000000000000000000000000000000000060648201526084016108c4565b60a380547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0392909216919091179055565b6099546001600160a01b031633148061117557506099546001600160a01b0316155b6111c15760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420746865206f776e657200000000000000000060448201526064016108c4565b6111c9613d23565b565b6099546001600160a01b03163314806111ed57506099546001600160a01b0316155b6112395760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420746865206f776e657200000000000000000060448201526064016108c4565b60655460ff161561128c5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016108c4565b816112d95760405162461bcd60e51b815260206004820152601260248201527f416d6f756e742063616e6e6f742062652030000000000000000000000000000060448201526064016108c4565b6001600160a01b038082166000908152609760205260409020609a549091166113445760405162461bcd60e51b815260206004820181905260248201527f4c31204c697175696469747920506f6f6c204e6f74205265676973746572656460448201526064016108c4565b60018101546001600160a01b031661139e5760405162461bcd60e51b815260206004820152601c60248201527f546f6b656e2041646472657373204e6f7420526567697374657265640000000060448201526064016108c4565b6001600160a01b03821673420000000000000000000000000000000000000614156114f357478311156114395760405162461bcd60e51b815260206004820152602260248201527f52657175657374656420455448206578636565647320706f6f6c2062616c616e60448201527f636500000000000000000000000000000000000000000000000000000000000060648201526084016108c4565b609a54609d546040517fa3a795480000000000000000000000000000000000000000000000000000000081526001600160a01b03808616600483015290921660248301526044820185905263ffffffff16606482015260a06084820152600060a48201527342000000000000000000000000000000000000109063a3a795489060c401600060405180830381600087803b1580156114d657600080fd5b505af11580156114ea573d6000803e3d6000fd5b505050506116ad565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038316906370a082319060240160206040518083038186803b15801561154b57600080fd5b505afa15801561155f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115839190614d40565b8311156115f75760405162461bcd60e51b8152602060048201526024808201527f526571756573746564204552433230206578636565647320706f6f6c2062616c60448201527f616e63650000000000000000000000000000000000000000000000000000000060648201526084016108c4565b609a54609d546040517fa3a795480000000000000000000000000000000000000000000000000000000081526001600160a01b03808616600483015290921660248301526044820185905263ffffffff16606482015260a06084820152600060a48201527342000000000000000000000000000000000000109063a3a795489060c401600060405180830381600087803b15801561169457600080fd5b505af11580156116a8573d6000803e3d6000fd5b505050505b604080518481526001600160a01b03841660208201527f40637a7e139eeb28b936b8decebe78604164b2ade81ce7f4c70deb132e7614c2910160405180910390a1505050565b609d5464010000000090046001600160a01b031633146117555760405162461bcd60e51b815260206004820152601560248201527f43616c6c6572206973206e6f74207468652044414f000000000000000000000060448201526064016108c4565b609a546001600160a01b03166117d35760405162461bcd60e51b815260206004820152602560248201527f436f6e747261637420686173206e6f7420796574206265656e20696e6974696160448201527f6c697a656400000000000000000000000000000000000000000000000000000060648201526084016108c4565b8183111580156117e35750600083115b80156117f0575060328211155b80156117fd575060328111155b61186f5760405162461bcd60e51b815260206004820152603c60248201527f7573657220616e64206f776e6572206665652072617465732073686f756c642060448201527f6265206c6f776572207468616e20352070657263656e7420656163680000000060648201526084016108c4565b60408051602481018590526044810184905260648082018490528251808303909101815260849091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fc58827ea00000000000000000000000000000000000000000000000000000000179052609a54609d54611902916001600160a01b03169063ffffffff16610eff565b50505050565b6099546001600160a01b031633148061192a57506099546001600160a01b0316155b6119765760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420746865206f776e657200000000000000000060448201526064016108c4565b609a546001600160a01b0316156119cf5760405162461bcd60e51b815260206004820152601d60248201527f436f6e747261637420686173206265656e20696e697469616c697a656400000060448201526064016108c4565b6000547501000000000000000000000000000000000000000000900460ff1680611a14575060005474010000000000000000000000000000000000000000900460ff16155b611a865760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084016108c4565b6000547501000000000000000000000000000000000000000000900460ff16158015611aed57600080547fffffffffffffffffffff0000ffffffffffffffffffffffffffffffffffffffff1675010100000000000000000000000000000000000000001790555b6001600160a01b03831615801590611b0d57506001600160a01b03821615155b611b595760405162461bcd60e51b815260206004820152601860248201527f7a65726f2061646472657373206e6f7420616c6c6f776564000000000000000060448201526064016108c4565b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000009081166001600160a01b0386811691909117909255609a80548216928516929092179091556099805433921682179055609d80547fffffffffffffffff0000000000000000000000000000000000000000ffffffff16640100000000909202919091179055611bf16001600a600f6131cc565b611bfd620186a0610f0c565b611c05613ddd565b611c0d613f2d565b611c156140a4565b8015611c4457600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff1690555b505050565b60655460ff1615611c9c5760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016108c4565b6001600160a01b0380831660009081526097602090815260408083206098835281842033855290925290912060018201549192909116611d1e5760405162461bcd60e51b815260206004820152601c60248201527f546f6b656e2041646472657373204e6f7420526567697374657265640000000060448201526064016108c4565b6000611d60611d558360010154611d4f64e8d4a51000610a0388600501548860000154613bb590919063ffffffff16565b90613ba2565b600284015490613bcd565b905085811015611dd85760405162461bcd60e51b815260206004820152602660248201527f52657175657374656420616d6f756e7420657863656564732070656e64696e6760448201527f526577617264000000000000000000000000000000000000000000000000000060648201526084016108c4565b611de28187613ba2565b600283015560058301548254611e029164e8d4a5100091610a0391613bb5565b6001830155604080513381526001600160a01b0386811660208301528183018990528716606082015290517f3cb7cb475a33eda02ee6e719b6c2fc0c899157cfc6f098daf545354dbbce41ec9181900360800190a16001600160a01b03851673420000000000000000000000000000000000000614611e9457611e8f6001600160a01b03861685886141f7565b611f3d565b6000846001600160a01b03166108fc88604051600060405180830381858888f193505050503d8060008114611ee5576040519150601f19603f3d011682016040523d82523d6000602084013e611eea565b606091505b5050905080611f3b5760405162461bcd60e51b815260206004820152601660248201527f4661696c656420746f2073656e64206f766d5f4574680000000000000000000060448201526064016108c4565b505b505050505050565b609a546001600160a01b0316611fc35760405162461bcd60e51b815260206004820152602560248201527f436f6e747261637420686173206e6f7420796574206265656e20696e6974696160448201527f6c697a656400000000000000000000000000000000000000000000000000000060648201526084016108c4565b609a546001600160a01b0316611fe16000546001600160a01b031690565b6001600160a01b0316336001600160a01b0316146120675760405162461bcd60e51b815260206004820152602e60248201527f4f564d5f58434841494e3a206d657373656e67657220636f6e7472616374207560448201527f6e61757468656e7469636174656400000000000000000000000000000000000060648201526084016108c4565b806001600160a01b03166120836000546001600160a01b031690565b6001600160a01b0316636e296e456040518163ffffffff1660e01b815260040160206040518083038186803b1580156120bb57600080fd5b505afa1580156120cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120f39190614d59565b6001600160a01b03161461216f5760405162461bcd60e51b815260206004820152603060248201527f4f564d5f58434841494e3a2077726f6e672073656e646572206f662063726f7360448201527f732d646f6d61696e206d6573736167650000000000000000000000000000000060648201526084016108c4565b60655460ff16156121c25760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016108c4565b6001600160a01b0382166000908152609760205260408120906121e48461373a565b905060006121f86103e8610a038885613bb5565b905060006122176103e8610a03609c548a613bb590919063ffffffff16565b905060006122258383613bcd565b905060006122338983613ba2565b60048701549091506122459085613bcd565b600487015560068601546122599084613bcd565b6006870155604080516001600160a01b038c811682526020820184905281830187905260608201869052608082018590528a1660a082015290517ff1068421680e00dfc2c4f3fc20c7f565bf1ec365420e7544365bae13d5cbc8c89181900360c00190a16001600160a01b038816734200000000000000000000000000000000000006146122fa576122f56001600160a01b0389168b836141f7565b6123a3565b60008a6001600160a01b03166108fc83604051600060405180830381858888f193505050503d806000811461234b576040519150601f19603f3d011682016040523d82523d6000602084013e612350565b606091505b50509050806123a15760405162461bcd60e51b815260206004820152601660248201527f4661696c656420746f2073656e64206f766d5f4574680000000000000000000060448201526064016108c4565b505b50505050505050505050565b60655460ff16156124025760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016108c4565b6001600160a01b03808316600090815260976020908152604080832060988352818420338552909252909120600182015491929091166124845760405162461bcd60e51b815260206004820152601c60248201527f546f6b656e2041646472657373204e6f7420526567697374657265640000000060448201526064016108c4565b80548511156124fb5760405162461bcd60e51b815260206004820152602660248201527f52657175657374656420616d6f756e74206578636565647320616d6f756e742060448201527f7374616b6564000000000000000000000000000000000000000000000000000060648201526084016108c4565b61250484614240565b61250d84610994565b61254761253c8260010154611d4f64e8d4a51000610a0387600501548760000154613bb590919063ffffffff16565b600283015490613bcd565b600282015580546125589086613ba2565b80825560058301546125759164e8d4a5100091610a039190613bb5565b600182015560028201546125899086613ba2565b6002830155604080513381526001600160a01b0385811660208301528183018890528616606082015290517ffa2e8fcf14fd6ea11b6ebe7caf7de210198b8fe1eaf0e06d19f8d87c73860c469181900360800190a16001600160a01b0384167342000000000000000000000000000000000000061461261b576126166001600160a01b03851684876141f7565b6126c4565b6000836001600160a01b03166108fc87604051600060405180830381858888f193505050503d806000811461266c576040519150601f19603f3d011682016040523d82523d6000602084013e612671565b606091505b50509050806126c25760405162461bcd60e51b815260206004820152601660248201527f4661696c656420746f2073656e64206f766d5f4574680000000000000000000060448201526064016108c4565b505b610f05858561436f565b6099546001600160a01b03163314806126f057506099546001600160a01b0316155b61273c5760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420746865206f776e657200000000000000000060448201526064016108c4565b806001600160a01b0316826001600160a01b031614156127c45760405162461bcd60e51b815260206004820152602860248201527f6c3120616e64206c3220746f6b656e206164647265737365732063616e6e6f7460448201527f2062652073616d6500000000000000000000000000000000000000000000000060648201526084016108c4565b6001600160a01b0381166128405760405162461bcd60e51b815260206004820152602760248201527f6c3220746f6b656e20616464726573732063616e6e6f74206265207a65726f2060448201527f616464726573730000000000000000000000000000000000000000000000000060648201526084016108c4565b6001600160a01b0380821660009081526097602052604090206001810154909116156128ae5760405162461bcd60e51b815260206004820181905260248201527f546f6b656e204164647265737320416c7265616479205265676973746572656460448201526064016108c4565b5060408051610100810182526001600160a01b03938416815291831660208084018281526000858501818152606087018281526080880183815260a0890184815260c08a018581524260e08c0190815298865260979097529790932097518854908a167fffffffffffffffffffffffff0000000000000000000000000000000000000000918216178955935160018901805491909a16941693909317909755955160028601555160038501559351600484015590516005830155915160068201559051600790910155565b6099546001600160a01b031633148061299b57506099546001600160a01b0316155b6129e75760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420746865206f776e657200000000000000000060448201526064016108c4565b6001600160a01b0380831660009081526097602052604090206001810154909116612a545760405162461bcd60e51b815260206004820152601c60248201527f546f6b656e2041646472657373204e6f7420526567697374657265640000000060448201526064016108c4565b8381600601541015612aa85760405162461bcd60e51b815260206004820152601f60248201527f52657175657374656420616d6f756e742065786365656473207265776172640060448201526064016108c4565b6006810154612ab79085613ba2565b6006820155604080513381526001600160a01b0384811660208301528183018790528516606082015290517f3cb71b9a1fb601579f96812b9f86ab5e914fc3e54c98d5f84d95581b2b9884f39181900360800190a16001600160a01b03831673420000000000000000000000000000000000000614612b4957612b446001600160a01b03841683866141f7565b611902565b6000826001600160a01b03166108fc86604051600060405180830381858888f193505050503d8060008114612b9a576040519150601f19603f3d011682016040523d82523d6000602084013e612b9f565b606091505b5050905080610f055760405162461bcd60e51b815260206004820152601660248201527f4661696c656420746f2073656e64206f766d5f4574680000000000000000000060448201526064016108c4565b6099546001600160a01b0316331480612c1257506099546001600160a01b0316155b612c5e5760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420746865206f776e657200000000000000000060448201526064016108c4565b6111c9614415565b609a546001600160a01b0316612ce45760405162461bcd60e51b815260206004820152602560248201527f436f6e747261637420686173206e6f7420796574206265656e20696e6974696160448201527f6c697a656400000000000000000000000000000000000000000000000000000060648201526084016108c4565b609a546001600160a01b0316612d026000546001600160a01b031690565b6001600160a01b0316336001600160a01b031614612d885760405162461bcd60e51b815260206004820152602e60248201527f4f564d5f58434841494e3a206d657373656e67657220636f6e7472616374207560448201527f6e61757468656e7469636174656400000000000000000000000000000000000060648201526084016108c4565b806001600160a01b0316612da46000546001600160a01b031690565b6001600160a01b0316636e296e456040518163ffffffff1660e01b815260040160206040518083038186803b158015612ddc57600080fd5b505afa158015612df0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e149190614d59565b6001600160a01b031614612e905760405162461bcd60e51b815260206004820152603060248201527f4f564d5f58434841494e3a2077726f6e672073656e646572206f662063726f7360448201527f732d646f6d61696e206d6573736167650000000000000000000000000000000060648201526084016108c4565b60655460ff1615612ee35760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016108c4565b60005b82811015611902576000848483818110612f0257612f02614d76565b905060600201803603810190612f189190614da5565b9050612f318160000151826040015183602001516144bb565b5080612f3c81614e66565b915050612ee6565b609a546001600160a01b0316612fc25760405162461bcd60e51b815260206004820152602560248201527f436f6e747261637420686173206e6f7420796574206265656e20696e6974696160448201527f6c697a656400000000000000000000000000000000000000000000000000000060648201526084016108c4565b609a546001600160a01b0316612fe06000546001600160a01b031690565b6001600160a01b0316336001600160a01b0316146130665760405162461bcd60e51b815260206004820152602e60248201527f4f564d5f58434841494e3a206d657373656e67657220636f6e7472616374207560448201527f6e61757468656e7469636174656400000000000000000000000000000000000060648201526084016108c4565b806001600160a01b03166130826000546001600160a01b031690565b6001600160a01b0316636e296e456040518163ffffffff1660e01b815260040160206040518083038186803b1580156130ba57600080fd5b505afa1580156130ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130f29190614d59565b6001600160a01b03161461316e5760405162461bcd60e51b815260206004820152603060248201527f4f564d5f58434841494e3a2077726f6e672073656e646572206f662063726f7360448201527f732d646f6d61696e206d6573736167650000000000000000000000000000000060648201526084016108c4565b60655460ff16156131c15760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016108c4565b6119028484846144bb565b609d5464010000000090046001600160a01b0316331461322e5760405162461bcd60e51b815260206004820152601560248201527f43616c6c6572206973206e6f74207468652044414f000000000000000000000060448201526064016108c4565b609a546001600160a01b03166132ac5760405162461bcd60e51b815260206004820152602560248201527f436f6e747261637420686173206e6f7420796574206265656e20696e6974696160448201527f6c697a656400000000000000000000000000000000000000000000000000000060648201526084016108c4565b8183111580156132bc5750600083115b80156132c9575060328211155b80156132d6575060328111155b6133485760405162461bcd60e51b815260206004820152603c60248201527f7573657220616e64206f776e6572206665652072617465732073686f756c642060448201527f6265206c6f776572207468616e20352070657263656e7420656163680000000060648201526084016108c4565b609b92909255609f55609c55565b600260015414156133a95760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016108c4565b600260015560655460ff16156134015760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016108c4565b3415158061342c57506001600160a01b03811673420000000000000000000000000000000000000614155b61349e5760405162461bcd60e51b815260206004820152603260248201527f45697468657220416d6f756e7420496e636f7272656374206f7220546f6b656e60448201527f204164647265737320496e636f7272656374000000000000000000000000000060648201526084016108c4565b34158015906134ca57506001600160a01b03811673420000000000000000000000000000000000000614155b1561353d5760405162461bcd60e51b815260206004820152603260248201527f45697468657220416d6f756e7420496e636f7272656374206f7220546f6b656e60448201527f204164647265737320496e636f7272656374000000000000000000000000000060648201526084016108c4565b341561355d57503490507342000000000000000000000000000000000000065b6001600160a01b03808216600090815260976020908152604080832060988352818420338552909252909120600182015491929091166135df5760405162461bcd60e51b815260206004820152601c60248201527f546f6b656e2041646472657373204e6f7420526567697374657265640000000060448201526064016108c4565b6135e883614240565b6135f183610994565b80541561365d5761362761253c8260010154611d4f64e8d4a51000610a0387600501548760000154613bb590919063ffffffff16565b6002820155600582015481546136539164e8d4a5100091610a03919061364d9089613bcd565b90613bb5565b6001820155613683565b61367d64e8d4a51000610a03846005015487613bb590919063ffffffff16565b60018201555b805461368f9085613bcd565b815560028201546136a09085613bcd565b600283015560408051338152602081018690526001600160a01b0385168183015290517f5852d1d46e583f7e92c2a572221de0e681d82ef71f489847e056b9445c0147369181900360600190a16001600160a01b03831673420000000000000000000000000000000000000614613726576137266001600160a01b038416333087613bd9565b6137308484614880565b5050600180555050565b609a546000906001600160a01b03166137bb5760405162461bcd60e51b815260206004820152602560248201527f436f6e747261637420686173206e6f7420796574206265656e20696e6974696160448201527f6c697a656400000000000000000000000000000000000000000000000000000060648201526084016108c4565b6001600160a01b03821660008181526097602052604081206002810154909290919073420000000000000000000000000000000000000614156137ff575047613892565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038616906370a082319060240160206040518083038186803b15801561385757600080fd5b505afa15801561386b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061388f9190614d40565b90505b806138a3575050609f549392505050565b60008183609b546138b49190614e9f565b6138be9190614edc565b905080609b5411156138d7575050609b54949350505050565b80609f5410156138ee575050609f54949350505050565b93506138f992505050565b919050565b6099546001600160a01b031633148061392057506099546001600160a01b0316155b61396c5760405162461bcd60e51b815260206004820152601760248201527f43616c6c6572206973206e6f7420746865206f776e657200000000000000000060448201526064016108c4565b6001600160a01b0381166139e75760405162461bcd60e51b8152602060048201526024808201527f4e6577206f776e65722063616e6e6f7420626520746865207a65726f2061646460448201527f726573730000000000000000000000000000000000000000000000000000000060648201526084016108c4565b609980547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0383169081179091556040519081527f04dba622d284ed0014ee4b9a6a68386be1a4c08a4913ae272de89199cc686163906020015b60405180910390a150565b609d5464010000000090046001600160a01b03163314613ab65760405162461bcd60e51b815260206004820152601560248201527f43616c6c6572206973206e6f74207468652044414f000000000000000000000060448201526064016108c4565b6001600160a01b038116613b325760405162461bcd60e51b815260206004820152602a60248201527f4e65772044414f20616464726573732063616e6e6f7420626520746865207a6560448201527f726f20616464726573730000000000000000000000000000000000000000000060648201526084016108c4565b609d80547fffffffffffffffff0000000000000000000000000000000000000000ffffffff166401000000006001600160a01b038416908102919091179091556040519081527fcbd426f7d93b6fa3ff268c099102ab716488e9831c27880216aea6c689da297d90602001613a49565b6000613bae8284614f17565b9392505050565b6000613bae8284614e9f565b6000613bae8284614edc565b6000613bae8284614f2e565b6040516001600160a01b03808516602483015283166044820152606481018290526119029085907f23b872dd00000000000000000000000000000000000000000000000000000000906084015b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091526148fc565b6000546040517f3dbb202b0000000000000000000000000000000000000000000000000000000081526001600160a01b0390911690633dbb202b90613cf590869085908790600401614fbc565b600060405180830381600087803b158015613d0f57600080fd5b505af1158015611f3b573d6000803e3d6000fd5b60655460ff16613d755760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f742070617573656400000000000000000000000060448201526064016108c4565b606580547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6000547501000000000000000000000000000000000000000000900460ff1680613e22575060005474010000000000000000000000000000000000000000900460ff16155b613e945760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084016108c4565b6000547501000000000000000000000000000000000000000000900460ff16158015613efb57600080547fffffffffffffffffffff0000ffffffffffffffffffffffffffffffffffffffff1675010100000000000000000000000000000000000000001790555b8015613f2a57600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff1690555b50565b6000547501000000000000000000000000000000000000000000900460ff1680613f72575060005474010000000000000000000000000000000000000000900460ff16155b613fe45760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084016108c4565b6000547501000000000000000000000000000000000000000000900460ff1615801561404b57600080547fffffffffffffffffffff0000ffffffffffffffffffffffffffffffffffffffff1675010100000000000000000000000000000000000000001790555b606580547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690558015613f2a57600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff16905550565b6000547501000000000000000000000000000000000000000000900460ff16806140e9575060005474010000000000000000000000000000000000000000900460ff16155b61415b5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084016108c4565b6000547501000000000000000000000000000000000000000000900460ff161580156141c257600080547fffffffffffffffffffff0000ffffffffffffffffffffffffffffffffffffffff1675010100000000000000000000000000000000000000001790555b600180558015613f2a57600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff16905550565b6040516001600160a01b038316602482015260448101829052611c449084907fa9059cbb0000000000000000000000000000000000000000000000000000000090606401613c26565b33600090815260a2602052604090205460ff1615801561426d575060a1546001600160a01b038281169116145b8015614283575060a1546001600160a01b031615155b15613f2a576001600160a01b038116600090815260986020908152604080832033845290915290208054156143335760a05481546040517f40c10f1900000000000000000000000000000000000000000000000000000000815233600482015260248101919091526001600160a01b03909116906340c10f1990604401600060405180830381600087803b15801561431a57600080fd5b505af115801561432e573d6000803e3d6000fd5b505050505b5033600090815260a26020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905550565b60a1546001600160a01b038281169116148015614396575060a1546001600160a01b031615155b15610a265760a0546040517f9dc29fac000000000000000000000000000000000000000000000000000000008152336004820152602481018490526001600160a01b0390911690639dc29fac906044015b600060405180830381600087803b15801561440157600080fd5b505af1158015611f3d573d6000803e3d6000fd5b60655460ff16156144685760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a207061757365640000000000000000000000000000000060448201526064016108c4565b606580547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613dc03390565b6001600160a01b0380821660009081526097602052604081206001810154919290911661452a5760405162461bcd60e51b815260206004820152601c60248201527f546f6b656e2041646472657373204e6f7420526567697374657265640000000060448201526064016108c4565b60006145358461373a565b905060006145496103e8610a038885613bb5565b905060006145686103e8610a03609c548a613bb590919063ffffffff16565b905060006145768383613bcd565b905060006145848983613ba2565b90506001600160a01b0388167342000000000000000000000000000000000000061461468b576040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038916906370a082319060240160206040518083038186803b15801561460257600080fd5b505afa158015614616573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061463a9190614d40565b81111561464a576001965061476c565b60048601546146599085613bcd565b6004870155600686015461466d9084613bcd565b60068701556146866001600160a01b0389168b836141f7565b61476c565b4781111561469c576001965061476c565b60048601546146ab9085613bcd565b600487015560068601546146bf9084613bcd565b60068701556040516000906001600160a01b038c16906108fc90849084818181858888f193505050503d8060008114614714576040519150601f19603f3d011682016040523d82523d6000602084013e614719565b606091505b505090508061476a5760405162461bcd60e51b815260206004820152601660248201527f4661696c656420746f2073656e64206f766d5f4574680000000000000000000060448201526064016108c4565b505b8615614815578554604080516001600160a01b038d81166024830152604482018d90529283166064808301919091528251808303909101815260849091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f53174cc100000000000000000000000000000000000000000000000000000000179052609a54609d54919261480f9291169063ffffffff16610eff565b506123a3565b604080516001600160a01b038c811682526020820184905281830187905260608201869052608082018590528a1660a082015290517fedb4d3b4b55168608412f15db11c00859915842963c31b1f08d910a38e1d6aa49181900360c00190a150505050505050505050565b60a1546001600160a01b0382811691161480156148a7575060a1546001600160a01b031615155b15610a265760a0546040517f40c10f19000000000000000000000000000000000000000000000000000000008152336004820152602481018490526001600160a01b03909116906340c10f19906044016143e7565b6000614951826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166149e19092919063ffffffff16565b805190915015611c44578080602001905181019061496f9190614ff4565b611c445760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f7420737563636565640000000000000000000000000000000000000000000060648201526084016108c4565b60606149f084846000856149f8565b949350505050565b606082471015614a705760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c000000000000000000000000000000000000000000000000000060648201526084016108c4565b843b614abe5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016108c4565b600080866001600160a01b03168587604051614ada9190615016565b60006040518083038185875af1925050503d8060008114614b17576040519150601f19603f3d011682016040523d82523d6000602084013e614b1c565b606091505b5091509150614b2c828286614b37565b979650505050505050565b60608315614b46575081613bae565b825115614b565782518084602001fd5b8160405162461bcd60e51b81526004016108c49190615032565b6001600160a01b0381168114613f2a57600080fd5b60008060408385031215614b9857600080fd5b8235614ba381614b70565b91506020830135614bb381614b70565b809150509250929050565b600060208284031215614bd057600080fd5b8135613bae81614b70565b60008060408385031215614bee57600080fd5b823591506020830135614bb381614b70565b600060208284031215614c1257600080fd5b813563ffffffff81168114613bae57600080fd5b600080600060608486031215614c3b57600080fd5b505081359360208301359350604090920135919050565b600080600060608486031215614c6757600080fd5b833592506020840135614c7981614b70565b91506040840135614c8981614b70565b809150509250925092565b600080600060608486031215614ca957600080fd5b8335614cb481614b70565b9250602084013591506040840135614c8981614b70565b60008060208385031215614cde57600080fd5b823567ffffffffffffffff80821115614cf657600080fd5b818501915085601f830112614d0a57600080fd5b813581811115614d1957600080fd5b866020606083028501011115614d2e57600080fd5b60209290920196919550909350505050565b600060208284031215614d5257600080fd5b5051919050565b600060208284031215614d6b57600080fd5b8151613bae81614b70565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600060608284031215614db757600080fd5b6040516060810181811067ffffffffffffffff82111715614e01577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040528235614e0f81614b70565b81526020830135614e1f81614b70565b60208201526040928301359281019290925250919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415614e9857614e98614e37565b5060010190565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615614ed757614ed7614e37565b500290565b600082614f12577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b600082821015614f2957614f29614e37565b500390565b60008219821115614f4157614f41614e37565b500190565b60005b83811015614f61578181015183820152602001614f49565b838111156119025750506000910152565b60008151808452614f8a816020860160208601614f46565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6001600160a01b0384168152606060208201526000614fde6060830185614f72565b905063ffffffff83166040830152949350505050565b60006020828403121561500657600080fd5b81518015158114613bae57600080fd5b60008251615028818460208701614f46565b9190910192915050565b602081526000613bae6020830184614f7256fea164736f6c6343000809000a
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.