Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- FXSwapStrategyVaultBavaBonus
- Optimization enabled
- true
- Compiler version
- v0.8.18+commit.87f61d96
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2023-09-29T09:28:03.444137Z
contracts/FXSwapStrategyVaultBavaBonus.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import {SafeERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import {MathUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol"; import {IMasterChefV2} from "./interfaces/IMasterChefV2.sol"; import {IRouter} from "./interfaces/IRouter.sol"; import {IPair} from "./interfaces/IPair.sol"; import {IRewardDistributor} from "./interfaces/IRewardDistributor.sol"; import {Types} from './lib/Types.sol'; import {BaseVault} from "./vaults/BaseVault.sol"; // BavaCompoundVault is the compoundVault of FX-Swap Farm. It will autocompound user LP. // Note that it's ownable and the owner wields tremendous power. contract FXSwapStrategyVaultBavaBonus is Initializable, UUPSUpgradeable, BaseVault { using SafeERC20Upgradeable for IERC20Upgradeable; // ============ Constants ============ address internal constant WFX = 0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd; // WFX mainnet: 0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd; WFX testnet: 0x3452e23F9c4cC62c70B7ADAd699B264AF3549C19 address internal constant BAVA = 0xc8B4d3e67238e38B20d38908646fF6F4F48De5EC; // BAVA mainnet: 0xc8B4d3e67238e38B20d38908646fF6F4F48De5EC; BAVA testnet: 0xc7e56EEc629D3728fE41baCa2f6BFc502096f94E uint256 internal constant PRECISION = 1e30; // ============ Storage ============ uint256 public bavaBonusReward; // BAVA bonus reward token from restaking farm contract // ============ Events ============ event Claim(address indexed account, uint256 tokenAmount); event EmergencyWithdraw(address indexed owner, uint256 assets, uint256 shares); event EmergencyWithdrawVault(address indexed owner, bool disableDeposits); event DepositsEnabled(bool newValue); event RestakingEnabled(bool newValue); /// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); } /********************************* INITIAL SETUP *********************************/ /** * @dev Init the vault. Support LP from Fx-Swap masterChef. */ function initVault( address _stakingContract, uint256 _stakingFarmID, address _poolRewardToken, IERC20Upgradeable[] memory _bonusRewardTokens, address _router, address _feeTreasury, address _distributor, Types.StrategySettings memory _strategySettings ) external onlyRole(OWNER_ROLE) { require(address(_stakingContract) != address(0), "0 Add"); stakingContract = IMasterChefV2(_stakingContract); stakingFarmID = _stakingFarmID; poolRewardToken = IERC20Upgradeable(_poolRewardToken); bonusRewardTokens = _bonusRewardTokens; router = IRouter(_router); feeTreasury = _feeTreasury; distributor = _distributor; minTokensToReinvest = _strategySettings.minTokensToReinvest; feeOnReward = _strategySettings.feeOnReward; feeOnCompounder = _strategySettings.feeOnCompounder; feeOnWithdrawal = _strategySettings.feeOnWithdrawal; depositsEnabled = true; restakingEnabled = true; } /** * @notice Approve tokens for use in Strategy, Restricted to avoid griefing attacks */ function approveAllowances(uint256 _amount) external onlyRole(OWNER_ROLE) { address depositToken = asset(); if (address(stakingContract) != address(0)) { IERC20Upgradeable(depositToken).approve( address(stakingContract), _amount ); } if (address(router) != address(0)) { IERC20Upgradeable(WFX).approve(address(router), _amount); IERC20Upgradeable(IPair(depositToken).token0()).approve(address(router), _amount); IERC20Upgradeable(IPair(depositToken).token1()).approve(address(router), _amount); IERC20Upgradeable(depositToken).approve(address(router), _amount); poolRewardToken.approve(address(router), _amount); uint256 rewardLength = bonusRewardTokens.length; uint256 i = 0; for (i; i < rewardLength; i++) { bonusRewardTokens[i].approve(address(router), _amount); } } } /****************************************** FARMING CORE FUNCTION ******************************************/ /** * @notice Deposit LP tokens to staking farm. */ function deposit(uint256 _assets, address _receiver) public nonReentrant override returns (uint256) { require(depositsEnabled == true, "Deposit !enabled"); address depositToken = asset(); uint256 estimatedTotalReward = checkReward(); if (estimatedTotalReward > minTokensToReinvest) { _compound(); } _claim(msg.sender, _receiver); uint256 shares = super.deposit(_assets, _receiver); if (restakingEnabled == true) { uint256 stakeAmount = IERC20Upgradeable(depositToken).balanceOf(address(this)); _depositTokens(stakeAmount); } return shares; } // Withdraw LP tokens from BavaMasterFarmer. argument "_shares" is receipt amount. function redeem(uint256 _shares, address _receiver, address _owner) public nonReentrant override returns (uint256) { uint256 depositTokenAmount = previewRedeem(_shares); uint256 assets; address depositToken = asset(); uint256 estimatedTotalReward = checkReward(); if (estimatedTotalReward > minTokensToReinvest) { _compound(); } _claim(msg.sender, msg.sender); if (depositTokenAmount > 0) { _withdrawTokens(depositTokenAmount); assets = super.redeem(_shares, _receiver, _owner); } if (restakingEnabled == true) { uint256 stakeAmount = IERC20Upgradeable(depositToken).balanceOf(address(this)); _depositTokens(stakeAmount); } return assets; } // EMERGENCY ONLY. Withdraw without caring about rewards. // This has the same 25% fee as same block withdrawals and ucer receipt record set to 0 to prevent abuse of thisfunction. function emergencyRedeem() external nonReentrant { Types.UserInfo storage user = userInfo[msg.sender]; uint256 userBRTAmount = balanceOf(msg.sender); require(userBRTAmount > 0, "#>0"); _updateRewards(msg.sender); user.claimableReward = 0; address depositToken = asset(); // Reordered from Sushi function to prevent risk of reentrancy uint256 assets = _convertToAssets(userBRTAmount, MathUpgradeable.Rounding.Down); assets -= (assets * 2500) / BIPS_DIVISOR; _withdrawTokens(assets); _burn(msg.sender, userBRTAmount); IERC20Upgradeable(depositToken).safeTransfer(address(msg.sender), assets); emit EmergencyWithdraw(msg.sender, assets, userBRTAmount); } function compound() external nonReentrant { uint256 estimatedTotalReward = checkReward(); require(estimatedTotalReward >= minTokensToReinvest, "#<MinInvest"); uint256 liquidity = _compound(); if (restakingEnabled == true) { _depositTokens(liquidity); } } // Update reward variables of the given vault to be up-to-date. function claimReward(address receiver) external nonReentrant returns (uint256) { return _claim(msg.sender, receiver); } function updateRewards() external nonReentrant { _updateRewards(address(0)); } /**************************************** Internal FUNCTIONS ****************************************/ // Deposit LP token to 3rd party restaking farm function _depositTokens(uint256 amount) internal { if(amount > 0) { uint256 rewardBalBefore = IERC20Upgradeable(BAVA).balanceOf(address(this)); stakingContract.deposit( stakingFarmID, amount ); _calRewardAfter(rewardBalBefore); } } // Withdraw LP token to 3rd party restaking farm function _withdrawTokens(uint256 amount) internal { if(amount > 0) { uint256 rewardBalBefore = IERC20Upgradeable(BAVA).balanceOf(address(this)); (uint256 depositAmount, ) = stakingContract.userInfo( stakingFarmID, address(this) ); if (depositAmount > 0) { uint256 pendingRewardAmount = stakingContract.pendingReward(stakingFarmID, address(this)); if (pendingRewardAmount == 0) { stakingContract.emergencyWithdraw( stakingFarmID ); } else if (depositAmount >= amount) { stakingContract.withdraw( stakingFarmID, amount ); } else { stakingContract.withdraw( stakingFarmID, depositAmount ); } } _calRewardAfter(rewardBalBefore); } } // Claim LP restaking reward from 3rd party restaking contract function _getReinvestReward() internal { uint256 rewardBalBefore = IERC20Upgradeable(BAVA).balanceOf(address(this)); uint256 pendingRewardAmount = stakingContract.pendingReward(stakingFarmID, address(this)); if (pendingRewardAmount > 0) { stakingContract.withdraw( stakingFarmID, 0 ); } _calRewardAfter(rewardBalBefore); } function _calRewardAfter(uint256 _rewardBalBefore) private { uint256 rewardBalAfter = 0; uint256 diffRewardBal = 0; rewardBalAfter = IERC20Upgradeable(BAVA).balanceOf(address(this)); if (rewardBalAfter >= _rewardBalBefore) { diffRewardBal = rewardBalAfter - _rewardBalBefore; bavaBonusReward += diffRewardBal; } else { diffRewardBal = _rewardBalBefore - rewardBalAfter; bavaBonusReward -= diffRewardBal; } } // Claim bonus BAVA reward from Baklava function _claim(address account, address receiver) private returns (uint256) { _updateRewards(account); Types.UserInfo storage user = userInfo[account]; uint256 tokenAmount = user.claimableReward; user.claimableReward = 0; if (tokenAmount > 0) { IERC20Upgradeable(rewardToken()).safeTransfer(receiver, tokenAmount); emit Claim(account, tokenAmount); } return tokenAmount; } function _updateRewards(address account) private { uint256 blockReward = IRewardDistributor(distributor).distribute(address(this)); uint256 supply = totalSupply(); uint256 _cumulativeRewardPerToken = cumulativeRewardPerToken; if (supply > 0 && blockReward > 0) { _cumulativeRewardPerToken = _cumulativeRewardPerToken + (blockReward * (PRECISION) / (supply)); cumulativeRewardPerToken = _cumulativeRewardPerToken; } // cumulativeRewardPerToken can only increase // so if cumulativeRewardPerToken is zero, it means there are no rewards yet if (_cumulativeRewardPerToken == 0) { return; } if (account != address(0)) { Types.UserInfo storage user = userInfo[account]; uint256 stakedAmount = balanceOf(account); uint256 accountReward = stakedAmount * (_cumulativeRewardPerToken - (user.previousCumulatedRewardPerToken)) / (PRECISION); uint256 _claimableReward = user.claimableReward + (accountReward); user.claimableReward = _claimableReward; user.previousCumulatedRewardPerToken = _cumulativeRewardPerToken; } } /**************************************** VIEW FUNCTIONS ****************************************/ function rewardToken() public view returns (address) { return IRewardDistributor(distributor).rewardToken(); } // View function to see pending Bavas on frontend. function claimable(address account) public view returns (uint256) { Types.UserInfo memory user = userInfo[account]; uint256 stakedAmount = balanceOf(account); if (stakedAmount == 0) { return user.claimableReward; } uint256 supply = totalSupply(); uint256 pendingRewards = IRewardDistributor(distributor).pendingRewards(address(this)) * (PRECISION); uint256 nextCumulativeRewardPerToken = cumulativeRewardPerToken + (pendingRewards / (supply)); return user.claimableReward + ( stakedAmount * (nextCumulativeRewardPerToken - (user.previousCumulatedRewardPerToken)) / (PRECISION)); } // View function to see pending 3rd party reward. Ignore bonus reward view to reduce code error due to 3rd party contract changes function checkReward() public view returns (uint256) { uint256 pendingRewardAmount = stakingContract.pendingReward( stakingFarmID, address(this) ); uint256 rewardBalance = poolRewardToken.balanceOf(address(this)); return (pendingRewardAmount + rewardBalance); } /**************************************** ONLY OWNER FUNCTIONS ****************************************/ // @notice Rescue any token function, just in case if any user not able to withdraw token from the smart contract. function rescueDeployedFunds( address token, uint256 amount, address _to ) external onlyRole(OWNER_ROLE) { require(_to != address(0), "0Addr"); IERC20Upgradeable(token).safeTransfer(_to, amount); } // @notice Emergency withdraw all LP tokens from staking farm contract function emergencyWithdrawVault(bool disableDeposits) external onlyRole(OWNER_ROLE) { stakingContract.emergencyWithdraw(stakingFarmID); if (depositsEnabled == true && disableDeposits == true) { updateDepositsEnabled(false); updateRestakingEnabled(false); } emit EmergencyWithdrawVault(msg.sender, disableDeposits); } // @notice Enable/disable deposits function updateDepositsEnabled(bool newValue) public onlyRole(OWNER_ROLE) { require(depositsEnabled != newValue); depositsEnabled = newValue; emit DepositsEnabled(newValue); } function updateRestakingEnabled(bool newValue) public onlyRole(OWNER_ROLE) { require(restakingEnabled != newValue); restakingEnabled = newValue; emit RestakingEnabled(newValue); } /**************************************** ONLY AUTHORIZED FUNCTIONS ****************************************/ function updateMinReinvestToken(uint256 _minTokensToReinvest) public onlyRole(GOVERNOR_ROLE) { minTokensToReinvest = _minTokensToReinvest; } function updateFeeBips(uint256 _feeOnReward, uint256 _feeOnCompounder) public onlyRole(GOVERNOR_ROLE) { feeOnReward = _feeOnReward; feeOnCompounder = _feeOnCompounder; } function updateFeeTreasury(address _feeTreasury) public onlyRole(GOVERNOR_ROLE) { feeTreasury = _feeTreasury; } function updateDistributor(address _distributor) public onlyRole(GOVERNOR_ROLE) { distributor = _distributor; } /*********************** Compound Strategy ************************************************************************ * Swap all reward tokens to WFX and swap half/half WFX token to both LP token0 & token1, Add liquidity to LP token ***********************************************************************************************************************/ function _compound() private returns (uint256) { _getReinvestReward(); _convertBonusRewardIntoWFX(); uint256 wfxAmount = IERC20Upgradeable(WFX).balanceOf(address(this)); uint256 protocolFee = (wfxAmount * (feeOnReward)) / (BIPS_DIVISOR); uint256 reinvestFee = (wfxAmount * (feeOnCompounder)) / (BIPS_DIVISOR); IERC20Upgradeable(WFX).safeTransfer(feeTreasury, protocolFee); IERC20Upgradeable(WFX).safeTransfer(msg.sender, reinvestFee); uint256 liquidity = _convertWFXToDepositToken(wfxAmount - reinvestFee - protocolFee); return liquidity; } function _convertBonusRewardIntoWFX() private { uint256 rewardLength = bonusRewardTokens.length; if (rewardLength > 0) { uint256 pathLength = 2; address[] memory path = new address[](pathLength); // BAVA-WFX Super farm strategy path[0] = address(BAVA); path[1] = address(WFX); uint256 rewardBal = bavaBonusReward; if (rewardBal > 0) { bavaBonusReward -= rewardBal; _convertExactTokentoToken(path, rewardBal); } } } function _convertWFXToDepositToken(uint256 amount) private returns (uint256) { require(amount > 0, "#<0"); uint256 amountIn = amount / 2; address depositToken = asset(); // swap to token0 uint256 path0Length = 2; address[] memory path0 = new address[](path0Length); path0[0] = address(WFX); path0[1] = IPair(address(depositToken)).token0(); uint256 amountOutToken0 = amountIn; // Check if path0[1] equal to WFX if (path0[0] != path0[path0Length - 1]) { amountOutToken0 = _convertExactTokentoToken(path0, amountIn); } // swap to token1 uint256 path1Length = 2; address[] memory path1 = new address[](path1Length); path1[0] = path0[0]; path1[1] = IPair(address(depositToken)).token1(); uint256 amountOutToken1 = amountIn; if (path1[0] != path1[path1Length - 1]) { amountOutToken1 = _convertExactTokentoToken(path1, amountIn); } // swap to deposit(LP) Token (, , uint256 liquidity) = router.addLiquidity( path0[path0Length - 1], path1[path1Length - 1], amountOutToken0, amountOutToken1, 0, 0, address(this), block.timestamp + 3000 ); return liquidity; } function _convertExactTokentoToken(address[] memory path, uint256 amount) private returns (uint256) { uint256[] memory amountsOutToken = router.getAmountsOut(amount, path); uint256 amountOutToken = amountsOutToken[amountsOutToken.length - 1]; uint256[] memory amountOut = router.swapExactTokensForTokens( amount, amountOutToken, path, address(this), block.timestamp + 1200 ); uint256 swapAmount = amountOut[amountOut.length - 1]; return swapAmount; } function _beforeTokenTransfer(address from, address to, uint256 amount) internal whenNotPaused override { _updateRewards(from); _updateRewards(to); super._beforeTokenTransfer(from, to, amount); } function _authorizeUpgrade(address) internal override onlyRole(OWNER_ROLE) {} /************************************************************** * @dev Initialize smart contract functions - only called once * @param symbol: BRT2LPSYMBOL *************************************************************/ function initialize( address _asset, address _owner, address _governor, string memory name_, string memory symbol_ ) public initializer { __BaseVaultInit( _asset, name_, symbol_, _owner, _governor ); __UUPSUpgradeable_init(); } }
contracts/interfaces/IRouter.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IRouter { function addLiquidity( address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns ( uint256 amountA, uint256 amountB, uint256 liquidity ); function addLiquidityFX( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountFXMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountFX, uint256 liquidity ); function removeLiquidity( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityFX( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountFXMin, address to, uint256 deadline ) external returns (uint256 amountToken, uint256 amountFX); function removeLiquidityWithPermit( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityFXWithPermit( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountFXMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountToken, uint256 amountFX); function removeLiquidityFXSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountFXMin, address to, uint256 deadline ) external returns (uint256 amountFX); function removeLiquidityFXWithPermitSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountFXMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountFX); function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapTokensForExactTokens( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactFXForTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapTokensForExactFX( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactTokensForFX( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapFXForExactTokens( uint256 amountOut, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function swapExactFXForTokensSupportingFeeOnTransferTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable; function swapExactTokensForFXSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function quote( uint256 amountA, uint256 reserveA, uint256 reserveB ) external pure returns (uint256 amountB); function getAmountOut( uint256 amountIn, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountOut); function getAmountIn( uint256 amountOut, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountIn); function getAmountsOut(uint256 amountIn, address[] memory path) external view returns (uint256[] memory amounts); function getAmountsIn(uint256 amountOut, address[] memory path) external view returns (uint256[] memory amounts); }
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @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 * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 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://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.0/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 functionCallWithValue(target, data, 0, "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"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or 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 { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) 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 IERC165Upgradeable { /** * @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); }
@openzeppelin/contracts-upgradeable/utils/math/SignedMathUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.0; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMathUpgradeable { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } }
@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../interfaces/IERC1967Upgradeable.sol"; import "../../interfaces/draft-IERC1822Upgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ */ abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable { function __ERC1967Upgrade_init() internal onlyInitializing { } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { AddressUpgradeable.functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal { // Upgrades from old implementations will perform a rollback test. This test requires the new // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing // this special case will break upgrade paths from old UUPS implementation to new ones. if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) { _setImplementation(newImplementation); } else { try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) { require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID"); } catch { revert("ERC1967Upgrade: new implementation is not UUPS"); } _upgradeToAndCall(newImplementation, data, forceCall); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../../interfaces/draft-IERC1822Upgradeable.sol"; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Check that the execution is not being performed through a delegate call. This allows a function to be * callable on the implementing contract but not through proxies. */ modifier notDelegated() { require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall"); _; } /** * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the * implementation. It is used to validate the implementation's compatibility when performing an upgrade. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier. */ function proxiableUUID() external view virtual override notDelegated returns (bytes32) { return _IMPLEMENTATION_SLOT; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. * * @custom:oz-upgrades-unsafe-allow-reachable delegatecall */ function upgradeTo(address newImplementation) public virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallUUPS(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. * * @custom:oz-upgrades-unsafe-allow-reachable delegatecall */ function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallUUPS(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
contracts/impl/Storage.sol
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.2; pragma abicoder v2; import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import {Types} from "../lib/Types.sol"; import {IRouter} from "../interfaces/IRouter.sol"; import "../interfaces/IMasterChefV2.sol"; /** * @title LS1Storage * @author MarginX * * @dev Storage contract. Contains or inherits from all contract with storage. */ abstract contract Storage is AccessControlUpgradeable, ReentrancyGuardUpgradeable { // ============ Rewards Accounting ============ /// @dev The fee treasury contract address. address public feeTreasury; /// @dev The reward distributor contract address. address public distributor; /// @dev The cumulative rewards earned per staked token. uint256 public cumulativeRewardPerToken; /// @dev The user's rewards info mapping(address => Types.UserInfo) public userInfo; // ============ Staking Strategy setting ============ /// @dev The staking farm contract IMasterChefV2 public stakingContract; /// @dev The fx swap router IRouter public router; /// @dev The staking farm reward token. IERC20Upgradeable public poolRewardToken; /// @dev The staking farm pool's bonus reward token. IERC20Upgradeable[] public bonusRewardTokens; /// @dev The staking farm poolId uint256 public stakingFarmID; /// @dev The minimum reward tokens to reinvest. uint256 public minTokensToReinvest; /// @dev Indicates whether a deposit is restricted. bool public depositsEnabled; /// @dev Indicates whether a restaking to farm is restricted. bool public restakingEnabled; // ============ Fee setting ============ /// @dev The protocol fee for rewards. uint256 internal feeOnReward; /// @dev The compounder fee for rewards. uint256 internal feeOnCompounder; /// @dev The withdrawal fee for rewards. uint256 internal feeOnWithdrawal; /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
contracts/FXSwapStrategyVault.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import {SafeERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol"; import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import {MathUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol"; import {IMasterChefV2} from "./interfaces/IMasterChefV2.sol"; import {IRouter} from "./interfaces/IRouter.sol"; import {IPair} from "./interfaces/IPair.sol"; import {IRewardDistributor} from "./interfaces/IRewardDistributor.sol"; import {Types} from './lib/Types.sol'; import {BaseVault} from "./vaults/BaseVault.sol"; // BavaCompoundVault is the compoundVault of FX-Swap Farm. It will autocompound user LP. // Note that it's ownable and the owner wields tremendous power. contract FXSwapStrategyVault is Initializable, UUPSUpgradeable, BaseVault { using SafeERC20Upgradeable for IERC20Upgradeable; // ============ Constants ============ address internal constant WFX = 0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd; // WFX mainnet: 0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd; WFX testnet: 0x3452e23F9c4cC62c70B7ADAd699B264AF3549C19 address internal constant BAVA = 0xc8B4d3e67238e38B20d38908646fF6F4F48De5EC; // BAVA mainnet: 0xc8B4d3e67238e38B20d38908646fF6F4F48De5EC; BAVA testnet: 0xc7e56EEc629D3728fE41baCa2f6BFc502096f94E uint256 internal constant PRECISION = 1e30; // ============ Events ============ event Claim(address indexed account, uint256 tokenAmount); event EmergencyWithdraw(address indexed owner, uint256 assets, uint256 shares); event EmergencyWithdrawVault(address indexed owner, bool disableDeposits); event DepositsEnabled(bool newValue); event RestakingEnabled(bool newValue); /// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); } /********************************* INITIAL SETUP *********************************/ /** * @dev Init the vault. Support LP from Fx-Swap masterChef. */ function initVault( address _stakingContract, uint256 _stakingFarmID, address _poolRewardToken, IERC20Upgradeable[] memory _bonusRewardTokens, address _router, address _feeTreasury, address _distributor, Types.StrategySettings memory _strategySettings ) external onlyRole(OWNER_ROLE) { require(address(_stakingContract) != address(0), "0 Add"); stakingContract = IMasterChefV2(_stakingContract); stakingFarmID = _stakingFarmID; poolRewardToken = IERC20Upgradeable(_poolRewardToken); bonusRewardTokens = _bonusRewardTokens; router = IRouter(_router); feeTreasury = _feeTreasury; distributor = _distributor; minTokensToReinvest = _strategySettings.minTokensToReinvest; feeOnReward = _strategySettings.feeOnReward; feeOnCompounder = _strategySettings.feeOnCompounder; feeOnWithdrawal = _strategySettings.feeOnWithdrawal; depositsEnabled = true; restakingEnabled = true; } /** * @notice Approve tokens for use in Strategy, Restricted to avoid griefing attacks */ function approveAllowances(uint256 _amount) external onlyRole(OWNER_ROLE) { address depositToken = asset(); if (address(stakingContract) != address(0)) { IERC20Upgradeable(depositToken).approve( address(stakingContract), _amount ); } if (address(router) != address(0)) { IERC20Upgradeable(WFX).approve(address(router), _amount); IERC20Upgradeable(IPair(depositToken).token0()).approve(address(router), _amount); IERC20Upgradeable(IPair(depositToken).token1()).approve(address(router), _amount); IERC20Upgradeable(depositToken).approve(address(router), _amount); poolRewardToken.approve(address(router), _amount); uint256 rewardLength = bonusRewardTokens.length; uint256 i = 0; for (i; i < rewardLength; i++) { bonusRewardTokens[i].approve(address(router), _amount); } } } /****************************************** FARMING CORE FUNCTION ******************************************/ /** * @notice Deposit LP tokens to staking farm. */ function deposit(uint256 _assets, address _receiver) public nonReentrant override returns (uint256) { require(depositsEnabled == true, "Deposit !enabled"); uint256 estimatedTotalReward = checkReward(); if (estimatedTotalReward > minTokensToReinvest) { _compound(); } _claim(msg.sender, _receiver); uint256 shares = super.deposit(_assets, _receiver); if (restakingEnabled == true) { uint256 stakeAmount = IERC20Upgradeable(asset()).balanceOf(address(this)); _depositTokens(stakeAmount); } return shares; } // Withdraw LP tokens from BavaMasterFarmer. argument "_shares" is receipt amount. function redeem(uint256 _shares, address _receiver, address _owner) public nonReentrant override returns (uint256) { uint256 depositTokenAmount = previewRedeem(_shares); uint256 assets; uint256 estimatedTotalReward = checkReward(); if (estimatedTotalReward > minTokensToReinvest) { _compound(); } _claim(msg.sender, msg.sender); if (depositTokenAmount > 0) { _withdrawTokens(depositTokenAmount); assets = super.redeem(_shares, _receiver, _owner); } if (restakingEnabled == true) { uint256 stakeAmount = IERC20Upgradeable(asset()).balanceOf(address(this)); _depositTokens(stakeAmount); } return assets; } // EMERGENCY ONLY. Withdraw without caring about rewards. // This has the same 25% fee as same block withdrawals and ucer receipt record set to 0 to prevent abuse of thisfunction. function emergencyRedeem() external nonReentrant { Types.UserInfo storage user = userInfo[msg.sender]; uint256 userBRTAmount = balanceOf(msg.sender); require(userBRTAmount > 0, "#>0"); _updateRewards(msg.sender); user.claimableReward = 0; // Reordered from Sushi function to prevent risk of reentrancy uint256 assets = _convertToAssets(userBRTAmount, MathUpgradeable.Rounding.Down); assets -= (assets * 2500) / BIPS_DIVISOR; _withdrawTokens(assets); _burn(msg.sender, userBRTAmount); IERC20Upgradeable(asset()).safeTransfer(address(msg.sender), assets); emit EmergencyWithdraw(msg.sender, assets, userBRTAmount); } function compound() external nonReentrant { uint256 estimatedTotalReward = checkReward(); require(estimatedTotalReward >= minTokensToReinvest, "#<MinInvest"); uint256 liquidity = _compound(); if (restakingEnabled == true) { _depositTokens(liquidity); } } // Update reward variables of the given vault to be up-to-date. function claimReward(address receiver) external nonReentrant returns (uint256) { return _claim(msg.sender, receiver); } function updateRewards() external nonReentrant { _updateRewards(address(0)); } /**************************************** Internal FUNCTIONS ****************************************/ // Deposit LP token to 3rd party restaking farm function _depositTokens(uint256 amount) internal { if(amount > 0) { stakingContract.deposit( stakingFarmID, amount ); } } // Withdraw LP token to 3rd party restaking farm function _withdrawTokens(uint256 amount) internal { if(amount > 0) { (uint256 depositAmount, ) = stakingContract.userInfo( stakingFarmID, address(this) ); if (depositAmount > 0) { uint256 pendingRewardAmount = stakingContract.pendingReward(stakingFarmID, address(this)); if (pendingRewardAmount == 0) { stakingContract.emergencyWithdraw( stakingFarmID ); } else if (depositAmount >= amount) { stakingContract.withdraw( stakingFarmID, amount ); } else { stakingContract.withdraw( stakingFarmID, depositAmount ); } } } } // Claim LP restaking reward from 3rd party restaking contract function _getReinvestReward() internal { uint256 pendingRewardAmount = stakingContract.pendingReward( stakingFarmID, address(this) ); if (pendingRewardAmount > 0) { stakingContract.withdraw( stakingFarmID, 0 ); } } // Claim bonus BAVA reward from Baklava function _claim(address account, address receiver) private returns (uint256) { _updateRewards(account); Types.UserInfo storage user = userInfo[account]; uint256 tokenAmount = user.claimableReward; user.claimableReward = 0; if (tokenAmount > 0) { IERC20Upgradeable(rewardToken()).safeTransfer(receiver, tokenAmount); emit Claim(account, tokenAmount); } return tokenAmount; } function _updateRewards(address account) private { uint256 blockReward = IRewardDistributor(distributor).distribute(address(this)); uint256 supply = totalSupply(); uint256 _cumulativeRewardPerToken = cumulativeRewardPerToken; if (supply > 0 && blockReward > 0) { _cumulativeRewardPerToken = _cumulativeRewardPerToken + (blockReward * (PRECISION) / (supply)); cumulativeRewardPerToken = _cumulativeRewardPerToken; } // cumulativeRewardPerToken can only increase // so if cumulativeRewardPerToken is zero, it means there are no rewards yet if (_cumulativeRewardPerToken == 0) { return; } if (account != address(0)) { Types.UserInfo storage user = userInfo[account]; uint256 stakedAmount = balanceOf(account); uint256 accountReward = stakedAmount * (_cumulativeRewardPerToken - (user.previousCumulatedRewardPerToken)) / (PRECISION); uint256 _claimableReward = user.claimableReward + (accountReward); user.claimableReward = _claimableReward; user.previousCumulatedRewardPerToken = _cumulativeRewardPerToken; } } /**************************************** VIEW FUNCTIONS ****************************************/ function rewardToken() public view returns (address) { return IRewardDistributor(distributor).rewardToken(); } // View function to see pending Bavas on frontend. function claimable(address account) public view returns (uint256) { Types.UserInfo memory user = userInfo[account]; uint256 stakedAmount = balanceOf(account); if (stakedAmount == 0) { return user.claimableReward; } uint256 supply = totalSupply(); uint256 pendingRewards = IRewardDistributor(distributor).pendingRewards(address(this)) * (PRECISION); uint256 nextCumulativeRewardPerToken = cumulativeRewardPerToken + (pendingRewards / (supply)); return user.claimableReward + ( stakedAmount * (nextCumulativeRewardPerToken - (user.previousCumulatedRewardPerToken)) / (PRECISION)); } // View function to see pending 3rd party reward. Ignore bonus reward view to reduce code error due to 3rd party contract changes function checkReward() public view returns (uint256) { uint256 pendingRewardAmount = stakingContract.pendingReward( stakingFarmID, address(this) ); uint256 rewardBalance = poolRewardToken.balanceOf(address(this)); return (pendingRewardAmount + rewardBalance); } /**************************************** ONLY OWNER FUNCTIONS ****************************************/ // @notice Rescue any token function, just in case if any user not able to withdraw token from the smart contract. function rescueDeployedFunds( address token, uint256 amount, address _to ) external onlyRole(OWNER_ROLE) { require(_to != address(0), "0Addr"); IERC20Upgradeable(token).safeTransfer(_to, amount); } // @notice Emergency withdraw all LP tokens from staking farm contract function emergencyWithdrawVault(bool disableDeposits) external onlyRole(OWNER_ROLE) { stakingContract.emergencyWithdraw(stakingFarmID); if (depositsEnabled == true && disableDeposits == true) { updateDepositsEnabled(false); updateRestakingEnabled(false); } emit EmergencyWithdrawVault(msg.sender, disableDeposits); } // @notice Enable/disable deposits function updateDepositsEnabled(bool newValue) public onlyRole(OWNER_ROLE) { require(depositsEnabled != newValue); depositsEnabled = newValue; emit DepositsEnabled(newValue); } function updateRestakingEnabled(bool newValue) public onlyRole(OWNER_ROLE) { require(restakingEnabled != newValue); restakingEnabled = newValue; emit RestakingEnabled(newValue); } /**************************************** ONLY AUTHORIZED FUNCTIONS ****************************************/ function updateMinReinvestToken(uint256 _minTokensToReinvest) public onlyRole(GOVERNOR_ROLE) { minTokensToReinvest = _minTokensToReinvest; } function updateFeeBips(uint256 _feeOnReward, uint256 _feeOnCompounder) public onlyRole(GOVERNOR_ROLE) { feeOnReward = _feeOnReward; feeOnCompounder = _feeOnCompounder; } function updateBonusReward(IERC20Upgradeable[] memory _bonusRewardTokens) public onlyRole(GOVERNOR_ROLE) { bonusRewardTokens = _bonusRewardTokens; } function updateFeeTreasury(address _feeTreasury) public onlyRole(GOVERNOR_ROLE) { feeTreasury = _feeTreasury; } function updateDistributor(address _distributor) public onlyRole(GOVERNOR_ROLE) { distributor = _distributor; } /*********************** Compound Strategy ************************************************************************ * Swap all reward tokens to WFX and swap half/half WFX token to both LP token0 & token1, Add liquidity to LP token ***********************************************************************************************************************/ function _compound() private returns (uint256) { _getReinvestReward(); _convertBonusRewardIntoWFX(); uint256 wfxAmount = IERC20Upgradeable(WFX).balanceOf(address(this)); uint256 protocolFee = (wfxAmount * (feeOnReward)) / (BIPS_DIVISOR); uint256 reinvestFee = (wfxAmount * (feeOnCompounder)) / (BIPS_DIVISOR); IERC20Upgradeable(WFX).safeTransfer(feeTreasury, protocolFee); IERC20Upgradeable(WFX).safeTransfer(msg.sender, reinvestFee); uint256 liquidity = _convertWFXToDepositToken(wfxAmount - reinvestFee - protocolFee); return liquidity; } function _convertBonusRewardIntoWFX() private { uint256 rewardLength = bonusRewardTokens.length; if (rewardLength > 0) { // Variable reward Super farm strategy uint256 rewardBal; uint256 pathLength = 2; address[] memory path = new address[](pathLength); for (uint256 i; i < rewardLength; i++) { if (address(bonusRewardTokens[i]) != address(WFX)) { path[0] = address(bonusRewardTokens[i]); path[1] = address(WFX); rewardBal = bonusRewardTokens[i].balanceOf(address(this)); if (rewardBal > 0) { _convertExactTokentoToken(path, rewardBal); } } } } } function _convertWFXToDepositToken(uint256 amount) private returns (uint256) { require(amount > 0, "#<0"); uint256 amountIn = amount / 2; address depositToken = asset(); // swap to token0 uint256 path0Length = 2; address[] memory path0 = new address[](path0Length); path0[0] = address(WFX); path0[1] = IPair(address(depositToken)).token0(); uint256 amountOutToken0 = amountIn; // Check if path0[1] equal to WFX if (path0[0] != path0[path0Length - 1]) { amountOutToken0 = _convertExactTokentoToken(path0, amountIn); } // swap to token1 uint256 path1Length = 2; address[] memory path1 = new address[](path1Length); path1[0] = path0[0]; path1[1] = IPair(address(depositToken)).token1(); uint256 amountOutToken1 = amountIn; if (path1[0] != path1[path1Length - 1]) { amountOutToken1 = _convertExactTokentoToken(path1, amountIn); } // swap to deposit(LP) Token (, , uint256 liquidity) = router.addLiquidity( path0[path0Length - 1], path1[path1Length - 1], amountOutToken0, amountOutToken1, 0, 0, address(this), block.timestamp + 3000 ); return liquidity; } function _convertExactTokentoToken(address[] memory path, uint256 amount) private returns (uint256) { uint256[] memory amountsOutToken = router.getAmountsOut(amount, path); uint256 amountOutToken = amountsOutToken[amountsOutToken.length - 1]; uint256[] memory amountOut = router.swapExactTokensForTokens( amount, amountOutToken, path, address(this), block.timestamp + 1200 ); uint256 swapAmount = amountOut[amountOut.length - 1]; return swapAmount; } /*********************** Openzeppelin inherited functions *********************************/ function _beforeTokenTransfer(address from, address to, uint256 amount) internal whenNotPaused override { _updateRewards(from); _updateRewards(to); super._beforeTokenTransfer(from, to, amount); } function _authorizeUpgrade(address) internal override onlyRole(OWNER_ROLE) {} /************************************************************** * @dev Initialize smart contract functions - only called once * @param symbol: BRT2LPSYMBOL *************************************************************/ function initialize( address _asset, address _owner, address _governor, string memory name_, string memory symbol_ ) public initializer { __BaseVaultInit( _asset, name_, symbol_, _owner, _governor ); __UUPSUpgradeable_init(); } }
contracts/interfaces/IPair.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IPair is IERC20 { function token0() external pure returns (address); function token1() external pure returns (address); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; // function getReserves() external view returns (uint112 reserve0, uint112 reserve1); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function mint(address to) external returns (uint liquidity); function sync() external; }
@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol) // This file was procedurally generated from scripts/generate/templates/StorageSlot.js. pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ```solidity * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._ * _Available since v4.9 for `string`, `bytes`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } struct StringSlot { string value; } struct BytesSlot { bytes value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` with member `value` located at `slot`. */ function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` representation of the string storage pointer `store`. */ function getStringSlot(string storage store) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } /** * @dev Returns an `BytesSlot` with member `value` located at `slot`. */ function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`. */ function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } }
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized != type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _initializing; } }
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/MathUpgradeable.sol"; import "./math/SignedMathUpgradeable.sol"; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = MathUpgradeable.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.abs(value)))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, MathUpgradeable.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } }
@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20MetadataUpgradeable is IERC20Upgradeable { /** * @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); }
@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the 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 `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, 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 `from` to `to` 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 from, address to, uint256 amount) external returns (bool); }
@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) 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 onlyInitializing { __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { 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()); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20Upgradeable.sol"; import "./extensions/IERC20MetadataUpgradeable.sol"; import "../../utils/ContextUpgradeable.sol"; import "../../proxy/utils/Initializable.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.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * The default value of {decimals} is 18. To change this, you should override * this function so it returns a different value. * * 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 ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable { 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}. * * All two of these values are immutable: they can only be set once during * construction. */ function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing { __ERC20_init_unchained(name_, symbol_); } function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing { _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 default value returned by this function, unless * it's 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: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, 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}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, 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}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, 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) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, 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) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * 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: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer(address from, address to, uint256 amount) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by // decrementing then incrementing. _balances[to] += amount; } emit Transfer(from, to, amount); _afterTokenTransfer(from, to, 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; unchecked { // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above. _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; // Overflow not possible: amount <= accountBalance <= totalSupply. _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 Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance(address owner, address spender, uint256 amount) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - 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 {} /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[45] private __gap; }
contracts/interfaces/IMasterChefV2.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IMasterChefV2 { function userInfo(uint pid, address user) external view returns ( uint256 amount, uint256 rewardDebt ); function poolInfo(uint pid) external view returns ( address lpToken, uint allocPoint, uint lastRewardBlock, uint accRewardPerShare ); function rewarder(uint pid) external view returns (address); function pendingReward(uint256 _pid, address _user) external view returns (uint256); function deposit(uint256 pid, uint256 amount) external; function withdraw(uint256 pid, uint256 amount) external; function emergencyWithdraw(uint256 pid) external; }
@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; import "../extensions/IERC20PermitUpgradeable.sol"; import "../../../utils/AddressUpgradeable.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 SafeERC20Upgradeable { using AddressUpgradeable for address; /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20Upgradeable token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20Upgradeable 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(IERC20Upgradeable 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)); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value)); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value)); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. */ function forceApprove(IERC20Upgradeable token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0)); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ function safePermit( IERC20PermitUpgradeable token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @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(IERC20Upgradeable 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"); require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20Upgradeable token, bytes memory data) private returns (bool) { // 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 cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && AddressUpgradeable.isContract(address(token)); } }
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) 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 onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library MathUpgradeable { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @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 == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } }
@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol) pragma solidity ^0.8.0; /** * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified * proxy whose upgrades are fully controlled by the current implementation. */ interface IERC1822ProxiableUpgradeable { /** * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation * address. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. */ function proxiableUUID() external view returns (bytes32); }
contracts/interfaces/IRewardDistributor.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; interface IRewardDistributor { function rewardToken() external view returns (address); function tokensPerInterval() external view returns (uint256); function pendingRewards(address _rewardTracker) external view returns (uint256); function distribute(address _rewardTracker) external returns (uint256); }
contracts/vaults/BaseVault.sol
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.10; import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; import {IERC20MetadataUpgradeable, IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol"; import {ERC4626Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol"; import {MathUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol"; import {Governable} from "../common/Governable.sol"; import {Storage} from "../impl/Storage.sol"; abstract contract BaseVault is Governable, Storage, PausableUpgradeable, ERC4626Upgradeable { using MathUpgradeable for uint256; uint256 internal constant BIPS_DIVISOR = 10000; function __BaseVaultInit(address _asset, string memory _name, string memory _symbol, address _owner, address _governor) internal{ __ERC4626_init(IERC20MetadataUpgradeable(_asset)); __ERC20_init(_name, _symbol); __Pausable_init(); __Governable_init(_owner, _governor); } // ============================= Public functions ================================ // /** * @dev See {openzeppelin-IERC4626-deposit}. */ function deposit(uint256 _assets, address _receiver) public virtual override whenNotPaused returns (uint256) { return super.deposit(_assets, _receiver); } /** * @dev See {openzeppelin-IERC4626-mint}. */ function mint(uint256 _shares, address _receiver) public override whenNotPaused returns (uint256) { revert("disabled"); } /** * @dev See {openzeppelin-IERC4626-withdraw}. */ function withdraw(uint256 _assets, address _receiver, address _owner) public virtual override returns (uint256) { revert("disabled"); } /** * @dev See {openzeppelin-IERC4626-redeem}. */ function redeem(uint256 _shares, address _receiver, address _owner) public virtual override returns (uint256) { return super.redeem(_shares, _receiver, _owner); } /** @dev See {IERC4626-previewRedeem}. */ function previewRedeem(uint256 shares) public view virtual override returns (uint256) { uint256 assets = _convertToAssets(shares, MathUpgradeable.Rounding.Down); assets -= (assets * feeOnWithdrawal) / BIPS_DIVISOR; return assets; } // View function to override ERC-4626 totalAssets(). function totalAssets() public view virtual override returns (uint256) { (uint256 underlying, ) = stakingContract.userInfo(stakingFarmID, address(this)); underlying += IERC20Upgradeable(asset()).balanceOf(address(this)); return underlying; } // ============================= Internal functions ================================ // /** * @dev Internal conversion function (from assets to shares) with support for rounding direction. * * Will revert if assets > 0, totalSupply > 0 and totalAssets = 0. That corresponds to a case where any asset * would represent an infinite amount of shares. */ function _convertToShares(uint256 assets, MathUpgradeable.Rounding rounding) internal view override returns (uint256 shares) { uint256 supply = totalSupply(); return (assets == 0 || supply == 0) ? _initialConvertToShares(assets, rounding) : assets.mulDiv(supply, totalAssets(), rounding); } /** * @dev Internal conversion function (from assets to shares) to apply when the vault is empty. * * NOTE: Make sure to keep this function consistent with {_initialConvertToAssets} when overriding it. */ function _initialConvertToShares( uint256 assets, MathUpgradeable.Rounding /*rounding*/ ) internal view virtual returns (uint256 shares) { return assets; } /** * @dev Internal conversion function (from shares to assets) with support for rounding direction. */ function _convertToAssets(uint256 shares, MathUpgradeable.Rounding rounding) internal view override returns (uint256 assets) { uint256 supply = totalSupply(); return (supply == 0) ? _initialConvertToAssets(shares, rounding) : shares.mulDiv(totalAssets(), supply, rounding); } /** * @dev Internal conversion function (from shares to assets) to apply when the vault is empty. * * NOTE: Make sure to keep this function consistent with {_initialConvertToShares} when overriding it. */ function _initialConvertToAssets( uint256 shares, MathUpgradeable.Rounding /*rounding*/ ) internal view virtual returns (uint256 assets) { return shares; } // ============================= Governable functions ================================ // function pause() public onlyRole(OWNER_ROLE) { _pause(); } function unpause() public onlyRole(OWNER_ROLE) { _unpause(); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol) 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 onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { return _status == _ENTERED; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ```solidity * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ```solidity * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules} * to enforce additional security measures for this role. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(account), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/interfaces/IERC4626Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4626.sol) pragma solidity ^0.8.0; import "../token/ERC20/IERC20Upgradeable.sol"; import "../token/ERC20/extensions/IERC20MetadataUpgradeable.sol"; /** * @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626]. * * _Available since v4.7._ */ interface IERC4626Upgradeable is IERC20Upgradeable, IERC20MetadataUpgradeable { event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares); event Withdraw( address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares ); /** * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing. * * - MUST be an ERC-20 token contract. * - MUST NOT revert. */ function asset() external view returns (address assetTokenAddress); /** * @dev Returns the total amount of the underlying asset that is “managed” by Vault. * * - SHOULD include any compounding that occurs from yield. * - MUST be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT revert. */ function totalAssets() external view returns (uint256 totalManagedAssets); /** * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal * scenario where all the conditions are met. * * - MUST NOT be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT show any variations depending on the caller. * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange. * - MUST NOT revert. * * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and * from. */ function convertToShares(uint256 assets) external view returns (uint256 shares); /** * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal * scenario where all the conditions are met. * * - MUST NOT be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT show any variations depending on the caller. * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange. * - MUST NOT revert. * * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and * from. */ function convertToAssets(uint256 shares) external view returns (uint256 assets); /** * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver, * through a deposit call. * * - MUST return a limited value if receiver is subject to some deposit limit. * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited. * - MUST NOT revert. */ function maxDeposit(address receiver) external view returns (uint256 maxAssets); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given * current on-chain conditions. * * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit * call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called * in the same transaction. * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the * deposit would be accepted, regardless if the user has enough tokens approved, etc. * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by depositing. */ function previewDeposit(uint256 assets) external view returns (uint256 shares); /** * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens. * * - MUST emit the Deposit event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * deposit execution, and are accounted for during deposit. * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not * approving enough underlying tokens to the Vault contract, etc). * * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token. */ function deposit(uint256 assets, address receiver) external returns (uint256 shares); /** * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call. * - MUST return a limited value if receiver is subject to some mint limit. * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted. * - MUST NOT revert. */ function maxMint(address receiver) external view returns (uint256 maxShares); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given * current on-chain conditions. * * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call * in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the * same transaction. * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint * would be accepted, regardless if the user has enough tokens approved, etc. * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by minting. */ function previewMint(uint256 shares) external view returns (uint256 assets); /** * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens. * * - MUST emit the Deposit event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint * execution, and are accounted for during mint. * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not * approving enough underlying tokens to the Vault contract, etc). * * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token. */ function mint(uint256 shares, address receiver) external returns (uint256 assets); /** * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the * Vault, through a withdraw call. * * - MUST return a limited value if owner is subject to some withdrawal limit or timelock. * - MUST NOT revert. */ function maxWithdraw(address owner) external view returns (uint256 maxAssets); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block, * given current on-chain conditions. * * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw * call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if * called * in the same transaction. * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though * the withdrawal would be accepted, regardless if the user has enough shares, etc. * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by depositing. */ function previewWithdraw(uint256 assets) external view returns (uint256 shares); /** * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver. * * - MUST emit the Withdraw event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * withdraw execution, and are accounted for during withdraw. * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner * not having enough shares, etc). * * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed. * Those methods should be performed separately. */ function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares); /** * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault, * through a redeem call. * * - MUST return a limited value if owner is subject to some withdrawal limit or timelock. * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock. * - MUST NOT revert. */ function maxRedeem(address owner) external view returns (uint256 maxShares); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block, * given current on-chain conditions. * * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call * in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the * same transaction. * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the * redemption would be accepted, regardless if the user has enough shares, etc. * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by redeeming. */ function previewRedeem(uint256 shares) external view returns (uint256 assets); /** * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver. * * - MUST emit the Withdraw event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * redeem execution, and are accounted for during redeem. * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner * not having enough shares, etc). * * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed. * Those methods should be performed separately. */ function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets); }
contracts/common/Governable.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.10; import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; abstract contract Governable is AccessControlUpgradeable { bytes32 public constant OWNER_ROLE = bytes32("OWNER_ROLE"); bytes32 public constant GOVERNOR_ROLE = bytes32("GOVERNOR_ROLE"); bytes32 public constant OPERATOR_ROLE = bytes32("OPERATOR_ROLE"); // only contract address function __Governable_init(address _owner, address _governor) internal { __AccessControl_init(); // Assign roles to the sender. _grantRole(OWNER_ROLE, _owner); _grantRole(GOVERNOR_ROLE, _governor); // Set OWNER_ROLE as the admin of all roles. _setRoleAdmin(OWNER_ROLE, OWNER_ROLE); _setRoleAdmin(GOVERNOR_ROLE, OWNER_ROLE); _setRoleAdmin(OPERATOR_ROLE, OWNER_ROLE); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20PermitUpgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol) 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 IERC20PermitUpgradeable { /** * @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); }
@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/ERC4626.sol) pragma solidity ^0.8.0; import "../ERC20Upgradeable.sol"; import "../utils/SafeERC20Upgradeable.sol"; import "../../../interfaces/IERC4626Upgradeable.sol"; import "../../../utils/math/MathUpgradeable.sol"; import "../../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the ERC4626 "Tokenized Vault Standard" as defined in * https://eips.ethereum.org/EIPS/eip-4626[EIP-4626]. * * This extension allows the minting and burning of "shares" (represented using the ERC20 inheritance) in exchange for * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends * the ERC20 standard. Any additional extensions included along it would affect the "shares" token represented by this * contract and not the "assets" token which is an independent contract. * * [CAUTION] * ==== * In empty (or nearly empty) ERC-4626 vaults, deposits are at high risk of being stolen through frontrunning * with a "donation" to the vault that inflates the price of a share. This is variously known as a donation or inflation * attack and is essentially a problem of slippage. Vault deployers can protect against this attack by making an initial * deposit of a non-trivial amount of the asset, such that price manipulation becomes infeasible. Withdrawals may * similarly be affected by slippage. Users can protect against this attack as well as unexpected slippage in general by * verifying the amount received is as expected, using a wrapper that performs these checks such as * https://github.com/fei-protocol/ERC4626#erc4626router-and-base[ERC4626Router]. * * Since v4.9, this implementation uses virtual assets and shares to mitigate that risk. The `_decimalsOffset()` * corresponds to an offset in the decimal representation between the underlying asset's decimals and the vault * decimals. This offset also determines the rate of virtual shares to virtual assets in the vault, which itself * determines the initial exchange rate. While not fully preventing the attack, analysis shows that the default offset * (0) makes it non-profitable, as a result of the value being captured by the virtual shares (out of the attacker's * donation) matching the attacker's expected gains. With a larger offset, the attack becomes orders of magnitude more * expensive than it is profitable. More details about the underlying math can be found * xref:erc4626.adoc#inflation-attack[here]. * * The drawback of this approach is that the virtual shares do capture (a very small) part of the value being accrued * to the vault. Also, if the vault experiences losses, the users try to exit the vault, the virtual shares and assets * will cause the first user to exit to experience reduced losses in detriment to the last users that will experience * bigger losses. Developers willing to revert back to the pre-v4.9 behavior just need to override the * `_convertToShares` and `_convertToAssets` functions. * * To learn more, check out our xref:ROOT:erc4626.adoc[ERC-4626 guide]. * ==== * * _Available since v4.7._ */ abstract contract ERC4626Upgradeable is Initializable, ERC20Upgradeable, IERC4626Upgradeable { using MathUpgradeable for uint256; IERC20Upgradeable private _asset; uint8 private _underlyingDecimals; /** * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC20 or ERC777). */ function __ERC4626_init(IERC20Upgradeable asset_) internal onlyInitializing { __ERC4626_init_unchained(asset_); } function __ERC4626_init_unchained(IERC20Upgradeable asset_) internal onlyInitializing { (bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_); _underlyingDecimals = success ? assetDecimals : 18; _asset = asset_; } /** * @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way. */ function _tryGetAssetDecimals(IERC20Upgradeable asset_) private view returns (bool, uint8) { (bool success, bytes memory encodedDecimals) = address(asset_).staticcall( abi.encodeWithSelector(IERC20MetadataUpgradeable.decimals.selector) ); if (success && encodedDecimals.length >= 32) { uint256 returnedDecimals = abi.decode(encodedDecimals, (uint256)); if (returnedDecimals <= type(uint8).max) { return (true, uint8(returnedDecimals)); } } return (false, 0); } /** * @dev Decimals are computed by adding the decimal offset on top of the underlying asset's decimals. This * "original" value is cached during construction of the vault contract. If this read operation fails (e.g., the * asset has not been created yet), a default of 18 is used to represent the underlying asset's decimals. * * See {IERC20Metadata-decimals}. */ function decimals() public view virtual override(IERC20MetadataUpgradeable, ERC20Upgradeable) returns (uint8) { return _underlyingDecimals + _decimalsOffset(); } /** @dev See {IERC4626-asset}. */ function asset() public view virtual override returns (address) { return address(_asset); } /** @dev See {IERC4626-totalAssets}. */ function totalAssets() public view virtual override returns (uint256) { return _asset.balanceOf(address(this)); } /** @dev See {IERC4626-convertToShares}. */ function convertToShares(uint256 assets) public view virtual override returns (uint256) { return _convertToShares(assets, MathUpgradeable.Rounding.Down); } /** @dev See {IERC4626-convertToAssets}. */ function convertToAssets(uint256 shares) public view virtual override returns (uint256) { return _convertToAssets(shares, MathUpgradeable.Rounding.Down); } /** @dev See {IERC4626-maxDeposit}. */ function maxDeposit(address) public view virtual override returns (uint256) { return type(uint256).max; } /** @dev See {IERC4626-maxMint}. */ function maxMint(address) public view virtual override returns (uint256) { return type(uint256).max; } /** @dev See {IERC4626-maxWithdraw}. */ function maxWithdraw(address owner) public view virtual override returns (uint256) { return _convertToAssets(balanceOf(owner), MathUpgradeable.Rounding.Down); } /** @dev See {IERC4626-maxRedeem}. */ function maxRedeem(address owner) public view virtual override returns (uint256) { return balanceOf(owner); } /** @dev See {IERC4626-previewDeposit}. */ function previewDeposit(uint256 assets) public view virtual override returns (uint256) { return _convertToShares(assets, MathUpgradeable.Rounding.Down); } /** @dev See {IERC4626-previewMint}. */ function previewMint(uint256 shares) public view virtual override returns (uint256) { return _convertToAssets(shares, MathUpgradeable.Rounding.Up); } /** @dev See {IERC4626-previewWithdraw}. */ function previewWithdraw(uint256 assets) public view virtual override returns (uint256) { return _convertToShares(assets, MathUpgradeable.Rounding.Up); } /** @dev See {IERC4626-previewRedeem}. */ function previewRedeem(uint256 shares) public view virtual override returns (uint256) { return _convertToAssets(shares, MathUpgradeable.Rounding.Down); } /** @dev See {IERC4626-deposit}. */ function deposit(uint256 assets, address receiver) public virtual override returns (uint256) { require(assets <= maxDeposit(receiver), "ERC4626: deposit more than max"); uint256 shares = previewDeposit(assets); _deposit(_msgSender(), receiver, assets, shares); return shares; } /** @dev See {IERC4626-mint}. * * As opposed to {deposit}, minting is allowed even if the vault is in a state where the price of a share is zero. * In this case, the shares will be minted without requiring any assets to be deposited. */ function mint(uint256 shares, address receiver) public virtual override returns (uint256) { require(shares <= maxMint(receiver), "ERC4626: mint more than max"); uint256 assets = previewMint(shares); _deposit(_msgSender(), receiver, assets, shares); return assets; } /** @dev See {IERC4626-withdraw}. */ function withdraw(uint256 assets, address receiver, address owner) public virtual override returns (uint256) { require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max"); uint256 shares = previewWithdraw(assets); _withdraw(_msgSender(), receiver, owner, assets, shares); return shares; } /** @dev See {IERC4626-redeem}. */ function redeem(uint256 shares, address receiver, address owner) public virtual override returns (uint256) { require(shares <= maxRedeem(owner), "ERC4626: redeem more than max"); uint256 assets = previewRedeem(shares); _withdraw(_msgSender(), receiver, owner, assets, shares); return assets; } /** * @dev Internal conversion function (from assets to shares) with support for rounding direction. */ function _convertToShares(uint256 assets, MathUpgradeable.Rounding rounding) internal view virtual returns (uint256) { return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding); } /** * @dev Internal conversion function (from shares to assets) with support for rounding direction. */ function _convertToAssets(uint256 shares, MathUpgradeable.Rounding rounding) internal view virtual returns (uint256) { return shares.mulDiv(totalAssets() + 1, totalSupply() + 10 ** _decimalsOffset(), rounding); } /** * @dev Deposit/mint common workflow. */ function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual { // If _asset is ERC777, `transferFrom` can trigger a reentrancy BEFORE the transfer happens through the // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer, // calls the vault, which is assumed not malicious. // // Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the // assets are transferred and before the shares are minted, which is a valid state. // slither-disable-next-line reentrancy-no-eth SafeERC20Upgradeable.safeTransferFrom(_asset, caller, address(this), assets); _mint(receiver, shares); emit Deposit(caller, receiver, assets, shares); } /** * @dev Withdraw/redeem common workflow. */ function _withdraw( address caller, address receiver, address owner, uint256 assets, uint256 shares ) internal virtual { if (caller != owner) { _spendAllowance(owner, caller, shares); } // If _asset is ERC777, `transfer` can trigger a reentrancy AFTER the transfer happens through the // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer, // calls the vault, which is assumed not malicious. // // Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the // shares are burned and after the assets are transferred, which is a valid state. _burn(owner, shares); SafeERC20Upgradeable.safeTransfer(_asset, receiver, assets); emit Withdraw(caller, receiver, owner, assets, shares); } function _decimalsOffset() internal view virtual returns (uint8) { return 0; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
contracts/lib/Types.sol
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.2; pragma abicoder v2; /** * @title LS1Types * @author Baklava Space * * @dev Structs used by the FXSwapStrategyVault contract. */ library Types { /** * @dev The parameters used to representing user reward information. * * @param claimableReward user claimable reward * @param previousCumulatedRewardPerToken user previous cumulated reward per token - used to calculate user reward */ struct UserInfo { uint256 claimableReward; uint256 previousCumulatedRewardPerToken; } /** * @dev The parameters to show vault information. * * @param minTokensToReinvest LP Staking contract * @param feeOnReward staking Farm ID * @param feeOnCompounder Fee for user help to sent compound tx * @param feeOnWithdrawal Fee for protocol */ struct StrategySettings { uint256 minTokensToReinvest; uint256 feeOnReward; uint256 feeOnCompounder; uint256 feeOnWithdrawal; } }
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
@openzeppelin/contracts-upgradeable/interfaces/IERC1967Upgradeable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol) pragma solidity ^0.8.0; /** * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC. * * _Available since v4.8.3._ */ interface IERC1967Upgradeable { /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Emitted when the beacon is changed. */ event BeaconUpgraded(address indexed beacon); }
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the 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 `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, 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 `from` to `to` 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 from, address to, uint256 amount) external returns (bool); }
Compiler Settings
{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers"]}},"optimizer":{"runs":200,"enabled":true},"libraries":{}}
Contract ABI
[{"type":"constructor","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"DEFAULT_ADMIN_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"GOVERNOR_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"OPERATOR_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"OWNER_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"allowance","inputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"address","name":"spender","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"approve","inputs":[{"type":"address","name":"spender","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"approveAllowances","inputs":[{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"asset","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOf","inputs":[{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"bavaBonusReward","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IERC20Upgradeable"}],"name":"bonusRewardTokens","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"checkReward","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"claimReward","inputs":[{"type":"address","name":"receiver","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"claimable","inputs":[{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"compound","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"convertToAssets","inputs":[{"type":"uint256","name":"shares","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"convertToShares","inputs":[{"type":"uint256","name":"assets","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"cumulativeRewardPerToken","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"uint8"}],"name":"decimals","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"decreaseAllowance","inputs":[{"type":"address","name":"spender","internalType":"address"},{"type":"uint256","name":"subtractedValue","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"deposit","inputs":[{"type":"uint256","name":"_assets","internalType":"uint256"},{"type":"address","name":"_receiver","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"depositsEnabled","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"distributor","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"emergencyRedeem","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"emergencyWithdrawVault","inputs":[{"type":"bool","name":"disableDeposits","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"feeTreasury","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRoleAdmin","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"increaseAllowance","inputs":[{"type":"address","name":"spender","internalType":"address"},{"type":"uint256","name":"addedValue","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initVault","inputs":[{"type":"address","name":"_stakingContract","internalType":"address"},{"type":"uint256","name":"_stakingFarmID","internalType":"uint256"},{"type":"address","name":"_poolRewardToken","internalType":"address"},{"type":"address[]","name":"_bonusRewardTokens","internalType":"contract IERC20Upgradeable[]"},{"type":"address","name":"_router","internalType":"address"},{"type":"address","name":"_feeTreasury","internalType":"address"},{"type":"address","name":"_distributor","internalType":"address"},{"type":"tuple","name":"_strategySettings","internalType":"struct Types.StrategySettings","components":[{"type":"uint256"},{"type":"uint256"},{"type":"uint256"},{"type":"uint256"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"address","name":"_asset","internalType":"address"},{"type":"address","name":"_owner","internalType":"address"},{"type":"address","name":"_governor","internalType":"address"},{"type":"string","name":"name_","internalType":"string"},{"type":"string","name":"symbol_","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"maxDeposit","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"maxMint","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"maxRedeem","inputs":[{"type":"address","name":"owner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"maxWithdraw","inputs":[{"type":"address","name":"owner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"minTokensToReinvest","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"mint","inputs":[{"type":"uint256","name":"_shares","internalType":"uint256"},{"type":"address","name":"_receiver","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"name","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"pause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"paused","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IERC20Upgradeable"}],"name":"poolRewardToken","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"previewDeposit","inputs":[{"type":"uint256","name":"assets","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"previewMint","inputs":[{"type":"uint256","name":"shares","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"previewRedeem","inputs":[{"type":"uint256","name":"shares","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"previewWithdraw","inputs":[{"type":"uint256","name":"assets","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"proxiableUUID","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"redeem","inputs":[{"type":"uint256","name":"_shares","internalType":"uint256"},{"type":"address","name":"_receiver","internalType":"address"},{"type":"address","name":"_owner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"rescueDeployedFunds","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"address","name":"_to","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"restakingEnabled","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"rewardToken","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IRouter"}],"name":"router","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IMasterChefV2"}],"name":"stakingContract","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"stakingFarmID","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"symbol","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalAssets","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalSupply","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"transfer","inputs":[{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"transferFrom","inputs":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unpause","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateDepositsEnabled","inputs":[{"type":"bool","name":"newValue","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateDistributor","inputs":[{"type":"address","name":"_distributor","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateFeeBips","inputs":[{"type":"uint256","name":"_feeOnReward","internalType":"uint256"},{"type":"uint256","name":"_feeOnCompounder","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateFeeTreasury","inputs":[{"type":"address","name":"_feeTreasury","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateMinReinvestToken","inputs":[{"type":"uint256","name":"_minTokensToReinvest","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateRestakingEnabled","inputs":[{"type":"bool","name":"newValue","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"updateRewards","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"upgradeTo","inputs":[{"type":"address","name":"newImplementation","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"upgradeToAndCall","inputs":[{"type":"address","name":"newImplementation","internalType":"address"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"claimableReward","internalType":"uint256"},{"type":"uint256","name":"previousCumulatedRewardPerToken","internalType":"uint256"}],"name":"userInfo","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"withdraw","inputs":[{"type":"uint256","name":"_assets","internalType":"uint256"},{"type":"address","name":"_receiver","internalType":"address"},{"type":"address","name":"_owner","internalType":"address"}]},{"type":"event","name":"AdminChanged","inputs":[{"type":"address","name":"previousAdmin","indexed":false},{"type":"address","name":"newAdmin","indexed":false}],"anonymous":false},{"type":"event","name":"Approval","inputs":[{"type":"address","name":"owner","indexed":true},{"type":"address","name":"spender","indexed":true},{"type":"uint256","name":"value","indexed":false}],"anonymous":false},{"type":"event","name":"BeaconUpgraded","inputs":[{"type":"address","name":"beacon","indexed":true}],"anonymous":false},{"type":"event","name":"Claim","inputs":[{"type":"address","name":"account","indexed":true},{"type":"uint256","name":"tokenAmount","indexed":false}],"anonymous":false},{"type":"event","name":"Deposit","inputs":[{"type":"address","name":"sender","indexed":true},{"type":"address","name":"owner","indexed":true},{"type":"uint256","name":"assets","indexed":false},{"type":"uint256","name":"shares","indexed":false}],"anonymous":false},{"type":"event","name":"DepositsEnabled","inputs":[{"type":"bool","name":"newValue","indexed":false}],"anonymous":false},{"type":"event","name":"EmergencyWithdraw","inputs":[{"type":"address","name":"owner","indexed":true},{"type":"uint256","name":"assets","indexed":false},{"type":"uint256","name":"shares","indexed":false}],"anonymous":false},{"type":"event","name":"EmergencyWithdrawVault","inputs":[{"type":"address","name":"owner","indexed":true},{"type":"bool","name":"disableDeposits","indexed":false}],"anonymous":false},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","indexed":false}],"anonymous":false},{"type":"event","name":"Paused","inputs":[{"type":"address","name":"account","indexed":false}],"anonymous":false},{"type":"event","name":"RestakingEnabled","inputs":[{"type":"bool","name":"newValue","indexed":false}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"type":"bytes32","name":"role","indexed":true},{"type":"bytes32","name":"previousAdminRole","indexed":true},{"type":"bytes32","name":"newAdminRole","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"type":"bytes32","name":"role","indexed":true},{"type":"address","name":"account","indexed":true},{"type":"address","name":"sender","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"type":"bytes32","name":"role","indexed":true},{"type":"address","name":"account","indexed":true},{"type":"address","name":"sender","indexed":true}],"anonymous":false},{"type":"event","name":"Transfer","inputs":[{"type":"address","name":"from","indexed":true},{"type":"address","name":"to","indexed":true},{"type":"uint256","name":"value","indexed":false}],"anonymous":false},{"type":"event","name":"Unpaused","inputs":[{"type":"address","name":"account","indexed":false}],"anonymous":false},{"type":"event","name":"Upgraded","inputs":[{"type":"address","name":"implementation","indexed":true}],"anonymous":false},{"type":"event","name":"Withdraw","inputs":[{"type":"address","name":"sender","indexed":true},{"type":"address","name":"receiver","indexed":true},{"type":"address","name":"owner","indexed":true},{"type":"uint256","name":"assets","indexed":false},{"type":"uint256","name":"shares","indexed":false}],"anonymous":false}]
Contract Creation Code
0x60a0604052306080523480156200001557600080fd5b506200002062000026565b620000e7565b600054610100900460ff1615620000935760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff90811614620000e5576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b60805161593c6200011f60003960008181611074015281816110b40152818161149d015281816114dd015261156c015261593c6000f3fe6080604052600436106104315760003560e01c806383b4358911610229578063c63d75b61161012e578063dd62ed3e116100b6578063f5fc50761161007a578063f5fc507614610c7e578063f69e204614610c95578063f70eebf514610caa578063f7c618c114610ccb578063f887ea4014610ce057600080fd5b8063dd62ed3e14610bf8578063e58378bb14610c18578063ee99205c14610c39578063ef8b30f714610af4578063f5b541a614610c5a57600080fd5b8063ce96cb77116100fd578063ce96cb7714610b58578063d279c19114610b78578063d4a0d4c614610b98578063d547741f14610bb8578063d905777e14610bd857600080fd5b8063c63d75b614610746578063c6e6f59214610af4578063ccc5749014610b14578063ce13267214610b3857600080fd5b8063a8e82603116101b1578063b460af9411610180578063b460af9414610a5e578063ba08765214610a7e578063bc30a61814610a9e578063bfe1092814610abe578063c4b24a4614610adf57600080fd5b8063a8e82603146109de578063a9059cbb146109fe578063af386a8514610a1e578063b3d7f6b914610a3e57600080fd5b806394bf804d116101f857806394bf804d1461095457806395d89b4114610974578063a217fddf14610989578063a457c2d71461099e578063a7eadf2b146109be57600080fd5b806383b43589146108ea5780638456cb591461090a5780638954b3e01461091f57806391d148541461093457600080fd5b80633bebe2bc1161033a578063531819de116102c257806360dc23401161028657806360dc2340146108525780636b1ba43b146108735780636e553f651461088a57806370a08231146108aa5780637fc8821d146108ca57600080fd5b8063531819de146107d05780635392fd1c146107e75780635625e6bc14610802578063587800c6146108225780635c975abb1461083957600080fd5b8063402d267d11610309578063402d267d146107465780634cdad506146107685780634e77ace5146107885780634f1ef286146107a857806352d1902d146107bb57600080fd5b80633bebe2bc146106dc5780633e158b0c146106fc5780633f4ba83a14610711578063402914f51461072657600080fd5b806323b872dd116103bd57806331522b681161038c57806331522b681461062957806336568abe146106495780633659cfe61461066957806338d52e0f1461068957806339509351146106bc57600080fd5b806323b872dd14610592578063248a9ca3146105b25780632f2ff15d146105e2578063313ce5671461060257600080fd5b806307a2d13a1161040457806307a2d13a146104d2578063095ea7b3146104f25780630a28a4771461051257806318160ddd146105325780631959a0021461054857600080fd5b806301e1d1141461043657806301ffc9a71461045e57806306fdde031461048e578063077e2e37146104b0575b600080fd5b34801561044257600080fd5b5061044b610d01565b6040519081526020015b60405180910390f35b34801561046a57600080fd5b5061047e610479366004614d82565b610e0e565b6040519015158152602001610455565b34801561049a57600080fd5b506104a3610e43565b6040516104559190614dd0565b3480156104bc57600080fd5b506104d06104cb366004614e23565b610ed6565b005b3480156104de57600080fd5b5061044b6104ed366004614e65565b610f4a565b3480156104fe57600080fd5b5061047e61050d366004614e7e565b610f57565b34801561051e57600080fd5b5061044b61052d366004614e65565b610f6f565b34801561053e57600080fd5b506101d15461044b565b34801561055457600080fd5b5061057d610563366004614eaa565b610161602052600090815260409020805460019091015482565b60408051928352602083019190915201610455565b34801561059e57600080fd5b5061047e6105ad366004614ec7565b610f7c565b3480156105be57600080fd5b5061044b6105cd366004614e65565b600090815260c9602052604090206001015490565b3480156105ee57600080fd5b506104d06105fd366004614f08565b610fa2565b34801561060e57600080fd5b50610617610fcc565b60405160ff9091168152602001610455565b34801561063557600080fd5b506101685461047e90610100900460ff1681565b34801561065557600080fd5b506104d0610664366004614f08565b610fec565b34801561067557600080fd5b506104d0610684366004614eaa565b61106a565b34801561069557600080fd5b50610201546001600160a01b03165b6040516001600160a01b039091168152602001610455565b3480156106c857600080fd5b5061047e6106d7366004614e7e565b611149565b3480156106e857600080fd5b506104d06106f7366004614f46565b61116b565b34801561070857600080fd5b506104d061125a565b34801561071d57600080fd5b506104d0611279565b34801561073257600080fd5b5061044b610741366004614eaa565b611298565b34801561075257600080fd5b5061044b610761366004614eaa565b5060001990565b34801561077457600080fd5b5061044b610783366004614e65565b6113e4565b34801561079457600080fd5b506104d06107a3366004614f46565b61141a565b6104d06107b6366004615002565b611493565b3480156107c757600080fd5b5061044b61155f565b3480156107dc57600080fd5b5061044b6101665481565b3480156107f357600080fd5b506101685461047e9060ff1681565b34801561080e57600080fd5b506104d061081d366004614e65565b611612565b34801561082e57600080fd5b5061044b6101675481565b34801561084557600080fd5b5061019d5460ff1661047e565b34801561085e57600080fd5b5061015e546106a4906001600160a01b031681565b34801561087f57600080fd5b5061044b6102645481565b34801561089657600080fd5b5061044b6108a5366004614f08565b611ad3565b3480156108b657600080fd5b5061044b6108c5366004614eaa565b611c16565b3480156108d657600080fd5b506104d06108e53660046150f0565b611c32565b3480156108f657600080fd5b506104d0610905366004615224565b611d4b565b34801561091657600080fd5b506104d0611e6e565b34801561092b57600080fd5b506104d0611e8d565b34801561094057600080fd5b5061047e61094f366004614f08565b611fa5565b34801561096057600080fd5b5061044b61096f366004614f08565b611fd0565b34801561098057600080fd5b506104a361200d565b34801561099557600080fd5b5061044b600081565b3480156109aa57600080fd5b5061047e6109b9366004614e7e565b61201d565b3480156109ca57600080fd5b506104d06109d9366004614e65565b6120a3565b3480156109ea57600080fd5b506104d06109f9366004614f46565b6120c4565b348015610a0a57600080fd5b5061047e610a19366004614e7e565b612145565b348015610a2a57600080fd5b506106a4610a39366004614e65565b612153565b348015610a4a57600080fd5b5061044b610a59366004614e65565b61217e565b348015610a6a57600080fd5b5061044b610a793660046152c0565b61218b565b348015610a8a57600080fd5b5061044b610a993660046152c0565b6121c1565b348015610aaa57600080fd5b506104d0610ab9366004614eaa565b6122d7565b348015610aca57600080fd5b5061015f546106a4906001600160a01b031681565b348015610aeb57600080fd5b5061044b612315565b348015610b0057600080fd5b5061044b610b0f366004614e65565b612419565b348015610b2057600080fd5b5061044b6c474f5645524e4f525f524f4c4560981b81565b348015610b4457600080fd5b506104d0610b533660046152f7565b612426565b348015610b6457600080fd5b5061044b610b73366004614eaa565b61244e565b348015610b8457600080fd5b5061044b610b93366004614eaa565b612463565b348015610ba457600080fd5b506104d0610bb3366004614eaa565b612489565b348015610bc457600080fd5b506104d0610bd3366004614f08565b6124c7565b348015610be457600080fd5b5061044b610bf3366004614eaa565b6124ec565b348015610c0457600080fd5b5061044b610c13366004615319565b6124f7565b348015610c2457600080fd5b5061044b694f574e45525f524f4c4560b01b81565b348015610c4557600080fd5b50610162546106a4906001600160a01b031681565b348015610c6657600080fd5b5061044b6c4f50455241544f525f524f4c4560981b81565b348015610c8a57600080fd5b5061044b6101605481565b348015610ca157600080fd5b506104d0612523565b348015610cb657600080fd5b50610164546106a4906001600160a01b031681565b348015610cd757600080fd5b506106a46125b0565b348015610cec57600080fd5b50610163546106a4906001600160a01b031681565b61016254610166546040516393f1a40b60e01b8152600481019190915230602482015260009182916001600160a01b03909116906393f1a40b906044016040805180830381865afa158015610d5a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d7e9190615347565b509050610d94610201546001600160a01b031690565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015610dda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dfe919061536b565b610e08908261539a565b92915050565b60006001600160e01b03198216637965db0b60e01b1480610e0857506301ffc9a760e01b6001600160e01b0319831614610e08565b60606101d28054610e53906153ad565b80601f0160208091040260200160405190810160405280929190818152602001828054610e7f906153ad565b8015610ecc5780601f10610ea157610100808354040283529160200191610ecc565b820191906000526020600020905b815481529060010190602001808311610eaf57829003601f168201915b5050505050905090565b694f574e45525f524f4c4560b01b610eed8161261f565b6001600160a01b038216610f305760405162461bcd60e51b81526020600482015260056024820152641820b2323960d91b60448201526064015b60405180910390fd5b610f446001600160a01b0385168385612629565b50505050565b6000610e0882600061268c565b600033610f658185856126c4565b5060019392505050565b6000610e088260016127e9565b600033610f8a85828561281c565b610f95858585612890565b60019150505b9392505050565b600082815260c96020526040902060010154610fbd8161261f565b610fc78383612a48565b505050565b60008061020154610fe79190600160a01b900460ff166153e7565b905090565b6001600160a01b038116331461105c5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610f27565b6110668282612ace565b5050565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036110b25760405162461bcd60e51b8152600401610f2790615400565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166110fb6000805160206158c0833981519152546001600160a01b031690565b6001600160a01b0316146111215760405162461bcd60e51b8152600401610f279061544c565b61112a81612b35565b6040805160008082526020820190925261114691839190612b4c565b50565b600033610f6581858561115c83836124f7565b611166919061539a565b6126c4565b694f574e45525f524f4c4560b01b6111828161261f565b6101625461016654604051632989754760e11b81526001600160a01b0390921691635312ea8e916111b99160040190815260200190565b600060405180830381600087803b1580156111d357600080fd5b505af11580156111e7573d6000803e3d6000fd5b50506101685460ff161515600114915050801561120657506001821515145b1561121f57611215600061141a565b61121f60006120c4565b604051821515815233907f898a2bf2227b490bfee6c32f57ba117104777db13f3381be9e335b7b828750fa9060200160405180910390a25050565b611262612cb7565b61126c6000612d12565b611277600161012c55565b565b694f574e45525f524f4c4560b01b6112908161261f565b611146612e78565b6001600160a01b0381166000908152610161602090815260408083208151808301909252805482526001015491810191909152816112d584611c16565b9050806000036112e757505192915050565b60006112f36101d15490565b61015f546040516318ebd13160e11b81523060048201529192506000916c0c9f2c9cd04674edea40000000916001600160a01b0316906331d7a26290602401602060405180830381865afa15801561134f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611373919061536b565b61137d9190615498565b9050600061138b83836154c5565b61016054611399919061539a565b90506c0c9f2c9cd04674edea400000008560200151826113b991906154e7565b6113c39086615498565b6113cd91906154c5565b85516113d9919061539a565b979650505050505050565b6000806113f283600061268c565b905061271061016b54826114069190615498565b61141091906154c5565b610f9b90826154e7565b694f574e45525f524f4c4560b01b6114318161261f565b6101685482151560ff90911615150361144957600080fd5b610168805460ff19168315159081179091556040519081527f7b014ed3854e7f5cb0218d58b3c6ae7d53a68bb0af2f67bfb029ea42c38a7e85906020015b60405180910390a15050565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036114db5760405162461bcd60e51b8152600401610f2790615400565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166115246000805160206158c0833981519152546001600160a01b031690565b6001600160a01b03161461154a5760405162461bcd60e51b8152600401610f279061544c565b61155382612b35565b61106682826001612b4c565b6000306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146115ff5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152608401610f27565b506000805160206158c083398151915290565b694f574e45525f524f4c4560b01b6116298161261f565b600061163e610201546001600160a01b031690565b610162549091506001600160a01b0316156116cd576101625460405163095ea7b360e01b81526001600160a01b039182166004820152602481018590529082169063095ea7b3906044016020604051808303816000875af11580156116a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116cb91906154fa565b505b610163546001600160a01b031615610fc7576101635460405163095ea7b360e01b81526001600160a01b039091166004820152602481018490527380b5a32e4f032b2a058b4f29ec95eefeeb87adcd9063095ea7b3906044016020604051808303816000875af1158015611745573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061176991906154fa565b50806001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117cc9190615517565b6101635460405163095ea7b360e01b81526001600160a01b0391821660048201526024810186905291169063095ea7b3906044016020604051808303816000875af115801561181f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061184391906154fa565b50806001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611882573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118a69190615517565b6101635460405163095ea7b360e01b81526001600160a01b0391821660048201526024810186905291169063095ea7b3906044016020604051808303816000875af11580156118f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061191d91906154fa565b506101635460405163095ea7b360e01b81526001600160a01b039182166004820152602481018590529082169063095ea7b3906044016020604051808303816000875af1158015611972573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061199691906154fa565b50610164546101635460405163095ea7b360e01b81526001600160a01b0391821660048201526024810186905291169063095ea7b3906044016020604051808303816000875af11580156119ee573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a1291906154fa565b506101655460005b81811015611acc576101658181548110611a3657611a36615534565b6000918252602090912001546101635460405163095ea7b360e01b81526001600160a01b0391821660048201526024810188905291169063095ea7b3906044016020604051808303816000875af1158015611a95573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ab991906154fa565b5080611ac48161554a565b915050611a1a565b5050505050565b6000611add612cb7565b6101685460ff161515600114611b285760405162461bcd60e51b815260206004820152601060248201526f11195c1bdcda5d0808595b98589b195960821b6044820152606401610f27565b6000611b3d610201546001600160a01b031690565b90506000611b49612315565b905061016754811115611b6057611b5e612ecb565b505b611b6a338561300a565b506000611b7786866130a2565b61016854909150610100900460ff161515600103611c07576040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015611bd6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bfa919061536b565b9050611c05816130b6565b505b92505050610e08600161012c55565b6001600160a01b031660009081526101cf602052604090205490565b694f574e45525f524f4c4560b01b611c498161261f565b6001600160a01b038916611c875760405162461bcd60e51b81526020600482015260056024820152640c0810591960da1b6044820152606401610f27565b61016280546001600160a01b03808c166001600160a01b0319928316179092556101668a90556101648054928a16929091169190911790558551611cd390610165906020890190614d08565b505061016380546001600160a01b03199081166001600160a01b039687161790915561015e805482169486169490941790935561015f805490931691909316179055805161016755602081015161016955604081015161016a556060015161016b555050610168805461ffff19166101011790555050565b600054610100900460ff1615808015611d6b5750600054600160ff909116105b80611d855750303b158015611d85575060005460ff166001145b611de85760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610f27565b6000805460ff191660011790558015611e0b576000805461ff0019166101001790555b611e1886848488886131a7565b611e206131cc565b8015611e66576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b694f574e45525f524f4c4560b01b611e858161261f565b6111466131f3565b611e95612cb7565b3360008181526101616020526040812091611eaf90611c16565b905060008111611ee75760405162461bcd60e51b81526020600482015260036024820152620233e360ec1b6044820152606401610f27565b611ef033612d12565b6000808355610201546001600160a01b031690611f0d838261268c565b9050612710611f1e826109c4615498565b611f2891906154c5565b611f3290826154e7565b9050611f3d81613231565b611f4733846134e7565b611f5b6001600160a01b0383163383612629565b604080518281526020810185905233917fbb757047c2b5f3974fe26b7c10f732e7bce710b0952a71082702781e62ae0595910160405180910390a250505050611277600161012c55565b600091825260c9602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6000611fda61362a565b60405162461bcd60e51b8152602060048201526008602482015267191a5cd8589b195960c21b6044820152606401610f27565b60606101d38054610e53906153ad565b6000338161202b82866124f7565b90508381101561208b5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610f27565b61209882868684036126c4565b506001949350505050565b6c474f5645524e4f525f524f4c4560981b6120bd8161261f565b5061016755565b694f574e45525f524f4c4560b01b6120db8161261f565b81151561016860019054906101000a900460ff161515036120fb57600080fd5b61016880548315156101000261ff00199091161790556040517fe8e51070d451440726dc975c3a7ce24ad3e1243eeb07ef11389a7143ca74d48b9061148790841515815260200190565b600033610f65818585612890565b610165818154811061216457600080fd5b6000918252602090912001546001600160a01b0316905081565b6000610e0882600161268c565b60405162461bcd60e51b8152602060048201526008602482015267191a5cd8589b195960c21b6044820152600090606401610f27565b60006121cb612cb7565b60006121d6856113e4565b90506000806121ee610201546001600160a01b031690565b905060006121fa612315565b9050610167548111156122115761220f612ecb565b505b61221b333361300a565b5083156122395761222b84613231565b612236888888613671565b92505b61016854610100900460ff1615156001036122c6576040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612295573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122b9919061536b565b90506122c4816130b6565b505b509092505050610f9b600161012c55565b6c474f5645524e4f525f524f4c4560981b6122f18161261f565b5061015f80546001600160a01b0319166001600160a01b0392909216919091179055565b6101625461016654604051634c4b4f4160e11b8152600481019190915230602482015260009182916001600160a01b03909116906398969e8290604401602060405180830381865afa15801561236f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612393919061536b565b610164546040516370a0823160e01b81523060048201529192506000916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156123e2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612406919061536b565b9050612412818361539a565b9250505090565b6000610e088260006127e9565b6c474f5645524e4f525f524f4c4560981b6124408161261f565b506101699190915561016a55565b6000610e0861245c83611c16565b600061268c565b600061246d612cb7565b612477338361300a565b9050612484600161012c55565b919050565b6c474f5645524e4f525f524f4c4560981b6124a38161261f565b5061015e80546001600160a01b0319166001600160a01b0392909216919091179055565b600082815260c960205260409020600101546124e28161261f565b610fc78383612ace565b6000610e0882611c16565b6001600160a01b0391821660009081526101d06020908152604080832093909416825291909152205490565b61252b612cb7565b6000612535612315565b9050610167548110156125785760405162461bcd60e51b815260206004820152600b60248201526a08cf135a5b925b9d995cdd60aa1b6044820152606401610f27565b6000612582612ecb565b61016854909150610100900460ff1615156001036125a3576125a3816130b6565b5050611277600161012c55565b61015f546040805163f7c618c160e01b815290516000926001600160a01b03169163f7c618c19160048083019260209291908290030181865afa1580156125fb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fe79190615517565b611146813361367e565b6040516001600160a01b038316602482015260448101829052610fc790849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526136d7565b6000806126996101d15490565b905080156126ba576126b56126ac610d01565b859083866137ac565b6126bc565b835b949350505050565b6001600160a01b0383166127265760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610f27565b6001600160a01b0382166127875760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610f27565b6001600160a01b0383811660008181526101d0602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6000806127f66101d15490565b9050831580612803575080155b6126ba576126b581612813610d01565b869190866137ac565b600061282884846124f7565b90506000198114610f4457818110156128835760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610f27565b610f4484848484036126c4565b6001600160a01b0383166128f45760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610f27565b6001600160a01b0382166129565760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610f27565b612961838383613807565b6001600160a01b03831660009081526101cf6020526040902054818110156129da5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610f27565b6001600160a01b0380851660008181526101cf602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90612a3b9086815260200190565b60405180910390a3610f44565b612a528282611fa5565b61106657600082815260c9602090815260408083206001600160a01b03851684529091529020805460ff19166001179055612a8a3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b612ad88282611fa5565b1561106657600082815260c9602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b694f574e45525f524f4c4560b01b6110668161261f565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615612b7f57610fc783613821565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612bd9575060408051601f3d908101601f19168201909252612bd69181019061536b565b60015b612c3c5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610f27565b6000805160206158c08339815191528114612cab5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610f27565b50610fc78383836138bd565b600261012c5403612d0a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610f27565b600261012c55565b61015f546040516363453ae160e01b81523060048201526000916001600160a01b0316906363453ae1906024016020604051808303816000875af1158015612d5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d82919061536b565b90506000612d906101d15490565b610160549091508115801590612da65750600083115b15612de05781612dc36c0c9f2c9cd04674edea4000000085615498565b612dcd91906154c5565b612dd7908261539a565b61016081905590505b80600003612dee5750505050565b6001600160a01b03841615610f44576001600160a01b03841660009081526101616020526040812090612e2086611c16565b905060006c0c9f2c9cd04674edea40000000836001015485612e4291906154e7565b612e4c9084615498565b612e5691906154c5565b90506000818460000154612e6a919061539a565b845550505060010155505050565b612e806138e2565b61019d805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6000612ed561392c565b612edd613a9e565b6040516370a0823160e01b81523060048201526000907380b5a32e4f032b2a058b4f29ec95eefeeb87adcd906370a0823190602401602060405180830381865afa158015612f2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f53919061536b565b905060006127106101695483612f699190615498565b612f7391906154c5565b9050600061271061016a5484612f899190615498565b612f9391906154c5565b61015e54909150612fc3907380b5a32e4f032b2a058b4f29ec95eefeeb87adcd906001600160a01b031684612629565b612fe27380b5a32e4f032b2a058b4f29ec95eefeeb87adcd3383612629565b600061300183612ff284876154e7565b612ffc91906154e7565b613b83565b95945050505050565b600061301583612d12565b6001600160a01b03831660009081526101616020526040812080549181559080156126bc5761305784826130476125b0565b6001600160a01b03169190612629565b846001600160a01b03167f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d48260405161309291815260200190565b60405180910390a2949350505050565b60006130ac61362a565b610f9b8383613fc6565b8015611146576040516370a0823160e01b815230600482015260009073c8b4d3e67238e38b20d38908646ff6f4f48de5ec906370a0823190602401602060405180830381865afa15801561310e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613132919061536b565b6101625461016654604051631c57762b60e31b81526004810191909152602481018590529192506001600160a01b03169063e2bbb15890604401600060405180830381600087803b15801561318657600080fd5b505af115801561319a573d6000803e3d6000fd5b5050505061106681613fe0565b6131b0856140b4565b6131ba84846140e4565b6131c2614115565b611acc8282614144565b600054610100900460ff166112775760405162461bcd60e51b8152600401610f2790615563565b6131fb61362a565b61019d805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612eae3390565b8015611146576040516370a0823160e01b815230600482015260009073c8b4d3e67238e38b20d38908646ff6f4f48de5ec906370a0823190602401602060405180830381865afa158015613289573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ad919061536b565b61016254610166546040516393f1a40b60e01b815260048101919091523060248201529192506000916001600160a01b03909116906393f1a40b906044016040805180830381865afa158015613307573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061332b9190615347565b50905080156134de576101625461016654604051634c4b4f4160e11b815260048101919091523060248201526000916001600160a01b0316906398969e8290604401602060405180830381865afa15801561338a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133ae919061536b565b905080600003613426576101625461016654604051632989754760e11b81526001600160a01b0390921691635312ea8e916133ef9160040190815260200190565b600060405180830381600087803b15801561340957600080fd5b505af115801561341d573d6000803e3d6000fd5b505050506134dc565b83821061346b576101625461016654604051630441a3e760e41b81526001600160a01b039092169163441a3e70916133ef918890600401918252602082015260400190565b6101625461016654604051630441a3e760e41b81526001600160a01b039092169163441a3e70916134a9918690600401918252602082015260400190565b600060405180830381600087803b1580156134c357600080fd5b505af11580156134d7573d6000803e3d6000fd5b505050505b505b610fc782613fe0565b6001600160a01b0382166135475760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610f27565b61355382600083613807565b6001600160a01b03821660009081526101cf6020526040902054818110156135c85760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610f27565b6001600160a01b03831660008181526101cf6020908152604080832086860390556101d180548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b61019d5460ff16156112775760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610f27565b60006126bc8484846141e2565b6136888282611fa5565b6110665761369581614256565b6136a0836020614268565b6040516020016136b19291906155ae565b60408051601f198184030181529082905262461bcd60e51b8252610f2791600401614dd0565b600061372c826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166144049092919063ffffffff16565b905080516000148061374d57508080602001905181019061374d91906154fa565b610fc75760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610f27565b6000806137ba868686614413565b905060018360028111156137d0576137d0615623565b1480156137ed5750600084806137e8576137e86154af565b868809115b15613001576137fd60018261539a565b9695505050505050565b61380f61362a565b61381883612d12565b610fc782612d12565b6001600160a01b0381163b61388e5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610f27565b6000805160206158c083398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6138c6836144fd565b6000825111806138d35750805b15610fc757610f44838361453d565b61019d5460ff166112775760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610f27565b6040516370a0823160e01b815230600482015260009073c8b4d3e67238e38b20d38908646ff6f4f48de5ec906370a0823190602401602060405180830381865afa15801561397e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139a2919061536b565b6101625461016654604051634c4b4f4160e11b815260048101919091523060248201529192506000916001600160a01b03909116906398969e8290604401602060405180830381865afa1580156139fd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a21919061536b565b90508015613a95576101625461016654604051630441a3e760e41b81526004810191909152600060248201526001600160a01b039091169063441a3e7090604401600060405180830381600087803b158015613a7c57600080fd5b505af1158015613a90573d6000803e3d6000fd5b505050505b61106682613fe0565b61016554801561114657604080516002808252606082019092526000908281602001602082028036833701905050905073c8b4d3e67238e38b20d38908646ff6f4f48de5ec81600081518110613af657613af6615534565b60200260200101906001600160a01b031690816001600160a01b0316815250507380b5a32e4f032b2a058b4f29ec95eefeeb87adcd81600181518110613b3e57613b3e615534565b6001600160a01b0390921660209283029190910190910152610264548015610f4457806102646000828254613b7391906154e7565b90915550611acc90508282614562565b6000808211613bba5760405162461bcd60e51b81526020600482015260036024820152620233c360ec1b6044820152606401610f27565b6000613bc76002846154c5565b90506000613bde610201546001600160a01b031690565b60408051600280825260608201835292935060009183906020830190803683370190505090507380b5a32e4f032b2a058b4f29ec95eefeeb87adcd81600081518110613c2c57613c2c615534565b60200260200101906001600160a01b031690816001600160a01b031681525050826001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015613c8a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613cae9190615517565b81600181518110613cc157613cc1615534565b6001600160a01b03909216602092830291909101909101528381613ce66001856154e7565b81518110613cf657613cf6615534565b60200260200101516001600160a01b031682600081518110613d1a57613d1a615534565b60200260200101516001600160a01b031614613d3d57613d3a8286614562565b90505b604080516002808252606082019092526000908281602001602082028036833701905050905083600081518110613d7657613d76615534565b602002602001015181600081518110613d9157613d91615534565b60200260200101906001600160a01b031690816001600160a01b031681525050856001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015613def573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e139190615517565b81600181518110613e2657613e26615534565b6001600160a01b03909216602092830291909101909101528681613e4b6001856154e7565b81518110613e5b57613e5b615534565b60200260200101516001600160a01b031682600081518110613e7f57613e7f615534565b60200260200101516001600160a01b031614613ea257613e9f8289614562565b90505b610163546000906001600160a01b031663e8e3370087613ec360018b6154e7565b81518110613ed357613ed3615534565b602002602001015185600188613ee991906154e7565b81518110613ef957613ef9615534565b602002602001015188866000803042610bb8613f15919061539a565b60405160e08a901b6001600160e01b03191681526001600160a01b039889166004820152968816602488015260448701959095526064860193909352608485019190915260a484015290921660c482015260e4810191909152610104016060604051808303816000875af1158015613f91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613fb59190615639565b9d9c50505050505050505050505050565b600080613fd284612419565b9050610f9b338486846146d6565b6040516370a0823160e01b8152306004820152600090819073c8b4d3e67238e38b20d38908646ff6f4f48de5ec906370a0823190602401602060405180830381865afa158015614034573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614058919061536b565b915082821061408b5761406b83836154e7565b9050806102646000828254614080919061539a565b90915550610fc79050565b61409582846154e7565b90508061026460008282546140aa91906154e7565b9091555050505050565b600054610100900460ff166140db5760405162461bcd60e51b8152600401610f2790615563565b61114681614755565b600054610100900460ff1661410b5760405162461bcd60e51b8152600401610f2790615563565b61106682826147db565b600054610100900460ff1661413c5760405162461bcd60e51b8152600401610f2790615563565b61127761481d565b61414c6131cc565b614163694f574e45525f524f4c4560b01b83612a48565b61417d6c474f5645524e4f525f524f4c4560981b82612a48565b614194694f574e45525f524f4c4560b01b80614851565b6141bb6c474f5645524e4f525f524f4c4560981b694f574e45525f524f4c4560b01b614851565b6110666c4f50455241544f525f524f4c4560981b694f574e45525f524f4c4560b01b614851565b60006141ed826124ec565b84111561423c5760405162461bcd60e51b815260206004820152601d60248201527f455243343632363a2072656465656d206d6f7265207468616e206d61780000006044820152606401610f27565b6000614247856113e4565b90506126bc338585848961489c565b6060610e086001600160a01b03831660145b60606000614277836002615498565b61428290600261539a565b67ffffffffffffffff81111561429a5761429a614f63565b6040519080825280601f01601f1916602001820160405280156142c4576020820181803683370190505b509050600360fc1b816000815181106142df576142df615534565b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061430e5761430e615534565b60200101906001600160f81b031916908160001a9053506000614332846002615498565b61433d90600161539a565b90505b60018111156143b5576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061437157614371615534565b1a60f81b82828151811061438757614387615534565b60200101906001600160f81b031916908160001a90535060049490941c936143ae81615667565b9050614340565b508315610f9b5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610f27565b60606126bc8484600085614949565b600080806000198587098587029250828110838203039150508060000361444d57838281614443576144436154af565b0492505050610f9b565b8084116144945760405162461bcd60e51b81526020600482015260156024820152744d6174683a206d756c446976206f766572666c6f7760581b6044820152606401610f27565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b61450681613821565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060610f9b83836040518060600160405280602781526020016158e060279139614a19565b6101635460405163d06ca61f60e01b815260009182916001600160a01b039091169063d06ca61f9061459a90869088906004016156c2565b600060405180830381865afa1580156145b7573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526145df91908101906156db565b9050600081600183516145f291906154e7565b8151811061460257614602615534565b6020908102919091010151610163549091506000906001600160a01b03166338ed173986848930614635426104b061539a565b6040518663ffffffff1660e01b8152600401614655959493929190615761565b6000604051808303816000875af1158015614674573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261469c91908101906156db565b9050600081600183516146af91906154e7565b815181106146bf576146bf615534565b602002602001015190508094505050505092915050565b610201546146ef906001600160a01b0316853085614a87565b6146f98382614abf565b826001600160a01b0316846001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78484604051614747929190918252602082015260400190565b60405180910390a350505050565b600054610100900460ff1661477c5760405162461bcd60e51b8152600401610f2790615563565b60008061478883614b8e565b915091508161479857601261479a565b805b61020180546001600160a01b039095166001600160a01b031960ff93909316600160a01b02929092166001600160a81b031990951694909417179092555050565b600054610100900460ff166148025760405162461bcd60e51b8152600401610f2790615563565b6101d261480f83826157e3565b506101d3610fc782826157e3565b600054610100900460ff166148445760405162461bcd60e51b8152600401610f2790615563565b61019d805460ff19169055565b600082815260c96020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b826001600160a01b0316856001600160a01b0316146148c0576148c083868361281c565b6148ca83826134e7565b610201546148e2906001600160a01b03168584612629565b826001600160a01b0316846001600160a01b0316866001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db858560405161493a929190918252602082015260400190565b60405180910390a45050505050565b6060824710156149aa5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610f27565b600080866001600160a01b031685876040516149c691906158a3565b60006040518083038185875af1925050503d8060008114614a03576040519150601f19603f3d011682016040523d82523d6000602084013e614a08565b606091505b50915091506113d987838387614c6a565b6060600080856001600160a01b031685604051614a3691906158a3565b600060405180830381855af49150503d8060008114614a71576040519150601f19603f3d011682016040523d82523d6000602084013e614a76565b606091505b50915091506137fd86838387614c6a565b6040516001600160a01b0380851660248301528316604482015260648101829052610f449085906323b872dd60e01b90608401612655565b6001600160a01b038216614b155760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610f27565b614b2160008383613807565b806101d16000828254614b34919061539a565b90915550506001600160a01b03821660008181526101cf60209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290516000918291829182916001600160a01b03871691614bd5916158a3565b600060405180830381855afa9150503d8060008114614c10576040519150601f19603f3d011682016040523d82523d6000602084013e614c15565b606091505b5091509150818015614c2957506020815110155b15614c5d57600081806020019051810190614c44919061536b565b905060ff8111614c5b576001969095509350505050565b505b5060009485945092505050565b60608315614cd9578251600003614cd2576001600160a01b0385163b614cd25760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610f27565b50816126bc565b6126bc8383815115614cee5781518083602001fd5b8060405162461bcd60e51b8152600401610f279190614dd0565b828054828255906000526020600020908101928215614d5d579160200282015b82811115614d5d57825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190614d28565b50614d69929150614d6d565b5090565b5b80821115614d695760008155600101614d6e565b600060208284031215614d9457600080fd5b81356001600160e01b031981168114610f9b57600080fd5b60005b83811015614dc7578181015183820152602001614daf565b50506000910152565b6020815260008251806020840152614def816040850160208701614dac565b601f01601f19169190910160400192915050565b6001600160a01b038116811461114657600080fd5b803561248481614e03565b600080600060608486031215614e3857600080fd5b8335614e4381614e03565b9250602084013591506040840135614e5a81614e03565b809150509250925092565b600060208284031215614e7757600080fd5b5035919050565b60008060408385031215614e9157600080fd5b8235614e9c81614e03565b946020939093013593505050565b600060208284031215614ebc57600080fd5b8135610f9b81614e03565b600080600060608486031215614edc57600080fd5b8335614ee781614e03565b92506020840135614ef781614e03565b929592945050506040919091013590565b60008060408385031215614f1b57600080fd5b823591506020830135614f2d81614e03565b809150509250929050565b801515811461114657600080fd5b600060208284031215614f5857600080fd5b8135610f9b81614f38565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715614fa257614fa2614f63565b604052919050565b600067ffffffffffffffff831115614fc457614fc4614f63565b614fd7601f8401601f1916602001614f79565b9050828152838383011115614feb57600080fd5b828260208301376000602084830101529392505050565b6000806040838503121561501557600080fd5b823561502081614e03565b9150602083013567ffffffffffffffff81111561503c57600080fd5b8301601f8101851361504d57600080fd5b61505c85823560208401614faa565b9150509250929050565b600067ffffffffffffffff82111561508057615080614f63565b5060051b60200190565b60006080828403121561509c57600080fd5b6040516080810181811067ffffffffffffffff821117156150bf576150bf614f63565b8060405250809150823581526020830135602082015260408301356040820152606083013560608201525092915050565b600080600080600080600080610160898b03121561510d57600080fd5b883561511881614e03565b9750602089810135975060408a013561513081614e03565b965060608a013567ffffffffffffffff81111561514c57600080fd5b8a01601f81018c1361515d57600080fd5b803561517061516b82615066565b614f79565b81815260059190911b8201830190838101908e83111561518f57600080fd5b928401925b828410156151b65783356151a781614e03565b82529284019290840190615194565b80995050505050506151ca60808a01614e18565b93506151d860a08a01614e18565b92506151e660c08a01614e18565b91506151f58a60e08b0161508a565b90509295985092959890939650565b600082601f83011261521557600080fd5b610f9b83833560208501614faa565b600080600080600060a0868803121561523c57600080fd5b853561524781614e03565b9450602086013561525781614e03565b9350604086013561526781614e03565b9250606086013567ffffffffffffffff8082111561528457600080fd5b61529089838a01615204565b935060808801359150808211156152a657600080fd5b506152b388828901615204565b9150509295509295909350565b6000806000606084860312156152d557600080fd5b8335925060208401356152e781614e03565b91506040840135614e5a81614e03565b6000806040838503121561530a57600080fd5b50508035926020909101359150565b6000806040838503121561532c57600080fd5b823561533781614e03565b91506020830135614f2d81614e03565b6000806040838503121561535a57600080fd5b505080516020909101519092909150565b60006020828403121561537d57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b80820180821115610e0857610e08615384565b600181811c908216806153c157607f821691505b6020821081036153e157634e487b7160e01b600052602260045260246000fd5b50919050565b60ff8181168382160190811115610e0857610e08615384565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b8082028115828204841417610e0857610e08615384565b634e487b7160e01b600052601260045260246000fd5b6000826154e257634e487b7160e01b600052601260045260246000fd5b500490565b81810381811115610e0857610e08615384565b60006020828403121561550c57600080fd5b8151610f9b81614f38565b60006020828403121561552957600080fd5b8151610f9b81614e03565b634e487b7160e01b600052603260045260246000fd5b60006001820161555c5761555c615384565b5060010190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516155e6816017850160208801614dac565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351615617816028840160208801614dac565b01602801949350505050565b634e487b7160e01b600052602160045260246000fd5b60008060006060848603121561564e57600080fd5b8351925060208401519150604084015190509250925092565b60008161567657615676615384565b506000190190565b600081518084526020808501945080840160005b838110156156b75781516001600160a01b031687529582019590820190600101615692565b509495945050505050565b8281526040602082015260006126bc604083018461567e565b600060208083850312156156ee57600080fd5b825167ffffffffffffffff81111561570557600080fd5b8301601f8101851361571657600080fd5b805161572461516b82615066565b81815260059190911b8201830190838101908783111561574357600080fd5b928401925b828410156113d957835182529284019290840190615748565b85815284602082015260a06040820152600061578060a083018661567e565b6001600160a01b0394909416606083015250608001529392505050565b601f821115610fc757600081815260208120601f850160051c810160208610156157c45750805b601f850160051c820191505b81811015611e66578281556001016157d0565b815167ffffffffffffffff8111156157fd576157fd614f63565b6158118161580b84546153ad565b8461579d565b602080601f831160018114615846576000841561582e5750858301515b600019600386901b1c1916600185901b178555611e66565b600085815260208120601f198616915b8281101561587557888601518255948401946001909101908401615856565b50858210156158935787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b600082516158b5818460208701614dac565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220bf4b189f862a7f435ae2f551f5fe646af5decde7018f9e818e794abaa36af73164736f6c63430008120033
Deployed ByteCode
0x6080604052600436106104315760003560e01c806383b4358911610229578063c63d75b61161012e578063dd62ed3e116100b6578063f5fc50761161007a578063f5fc507614610c7e578063f69e204614610c95578063f70eebf514610caa578063f7c618c114610ccb578063f887ea4014610ce057600080fd5b8063dd62ed3e14610bf8578063e58378bb14610c18578063ee99205c14610c39578063ef8b30f714610af4578063f5b541a614610c5a57600080fd5b8063ce96cb77116100fd578063ce96cb7714610b58578063d279c19114610b78578063d4a0d4c614610b98578063d547741f14610bb8578063d905777e14610bd857600080fd5b8063c63d75b614610746578063c6e6f59214610af4578063ccc5749014610b14578063ce13267214610b3857600080fd5b8063a8e82603116101b1578063b460af9411610180578063b460af9414610a5e578063ba08765214610a7e578063bc30a61814610a9e578063bfe1092814610abe578063c4b24a4614610adf57600080fd5b8063a8e82603146109de578063a9059cbb146109fe578063af386a8514610a1e578063b3d7f6b914610a3e57600080fd5b806394bf804d116101f857806394bf804d1461095457806395d89b4114610974578063a217fddf14610989578063a457c2d71461099e578063a7eadf2b146109be57600080fd5b806383b43589146108ea5780638456cb591461090a5780638954b3e01461091f57806391d148541461093457600080fd5b80633bebe2bc1161033a578063531819de116102c257806360dc23401161028657806360dc2340146108525780636b1ba43b146108735780636e553f651461088a57806370a08231146108aa5780637fc8821d146108ca57600080fd5b8063531819de146107d05780635392fd1c146107e75780635625e6bc14610802578063587800c6146108225780635c975abb1461083957600080fd5b8063402d267d11610309578063402d267d146107465780634cdad506146107685780634e77ace5146107885780634f1ef286146107a857806352d1902d146107bb57600080fd5b80633bebe2bc146106dc5780633e158b0c146106fc5780633f4ba83a14610711578063402914f51461072657600080fd5b806323b872dd116103bd57806331522b681161038c57806331522b681461062957806336568abe146106495780633659cfe61461066957806338d52e0f1461068957806339509351146106bc57600080fd5b806323b872dd14610592578063248a9ca3146105b25780632f2ff15d146105e2578063313ce5671461060257600080fd5b806307a2d13a1161040457806307a2d13a146104d2578063095ea7b3146104f25780630a28a4771461051257806318160ddd146105325780631959a0021461054857600080fd5b806301e1d1141461043657806301ffc9a71461045e57806306fdde031461048e578063077e2e37146104b0575b600080fd5b34801561044257600080fd5b5061044b610d01565b6040519081526020015b60405180910390f35b34801561046a57600080fd5b5061047e610479366004614d82565b610e0e565b6040519015158152602001610455565b34801561049a57600080fd5b506104a3610e43565b6040516104559190614dd0565b3480156104bc57600080fd5b506104d06104cb366004614e23565b610ed6565b005b3480156104de57600080fd5b5061044b6104ed366004614e65565b610f4a565b3480156104fe57600080fd5b5061047e61050d366004614e7e565b610f57565b34801561051e57600080fd5b5061044b61052d366004614e65565b610f6f565b34801561053e57600080fd5b506101d15461044b565b34801561055457600080fd5b5061057d610563366004614eaa565b610161602052600090815260409020805460019091015482565b60408051928352602083019190915201610455565b34801561059e57600080fd5b5061047e6105ad366004614ec7565b610f7c565b3480156105be57600080fd5b5061044b6105cd366004614e65565b600090815260c9602052604090206001015490565b3480156105ee57600080fd5b506104d06105fd366004614f08565b610fa2565b34801561060e57600080fd5b50610617610fcc565b60405160ff9091168152602001610455565b34801561063557600080fd5b506101685461047e90610100900460ff1681565b34801561065557600080fd5b506104d0610664366004614f08565b610fec565b34801561067557600080fd5b506104d0610684366004614eaa565b61106a565b34801561069557600080fd5b50610201546001600160a01b03165b6040516001600160a01b039091168152602001610455565b3480156106c857600080fd5b5061047e6106d7366004614e7e565b611149565b3480156106e857600080fd5b506104d06106f7366004614f46565b61116b565b34801561070857600080fd5b506104d061125a565b34801561071d57600080fd5b506104d0611279565b34801561073257600080fd5b5061044b610741366004614eaa565b611298565b34801561075257600080fd5b5061044b610761366004614eaa565b5060001990565b34801561077457600080fd5b5061044b610783366004614e65565b6113e4565b34801561079457600080fd5b506104d06107a3366004614f46565b61141a565b6104d06107b6366004615002565b611493565b3480156107c757600080fd5b5061044b61155f565b3480156107dc57600080fd5b5061044b6101665481565b3480156107f357600080fd5b506101685461047e9060ff1681565b34801561080e57600080fd5b506104d061081d366004614e65565b611612565b34801561082e57600080fd5b5061044b6101675481565b34801561084557600080fd5b5061019d5460ff1661047e565b34801561085e57600080fd5b5061015e546106a4906001600160a01b031681565b34801561087f57600080fd5b5061044b6102645481565b34801561089657600080fd5b5061044b6108a5366004614f08565b611ad3565b3480156108b657600080fd5b5061044b6108c5366004614eaa565b611c16565b3480156108d657600080fd5b506104d06108e53660046150f0565b611c32565b3480156108f657600080fd5b506104d0610905366004615224565b611d4b565b34801561091657600080fd5b506104d0611e6e565b34801561092b57600080fd5b506104d0611e8d565b34801561094057600080fd5b5061047e61094f366004614f08565b611fa5565b34801561096057600080fd5b5061044b61096f366004614f08565b611fd0565b34801561098057600080fd5b506104a361200d565b34801561099557600080fd5b5061044b600081565b3480156109aa57600080fd5b5061047e6109b9366004614e7e565b61201d565b3480156109ca57600080fd5b506104d06109d9366004614e65565b6120a3565b3480156109ea57600080fd5b506104d06109f9366004614f46565b6120c4565b348015610a0a57600080fd5b5061047e610a19366004614e7e565b612145565b348015610a2a57600080fd5b506106a4610a39366004614e65565b612153565b348015610a4a57600080fd5b5061044b610a59366004614e65565b61217e565b348015610a6a57600080fd5b5061044b610a793660046152c0565b61218b565b348015610a8a57600080fd5b5061044b610a993660046152c0565b6121c1565b348015610aaa57600080fd5b506104d0610ab9366004614eaa565b6122d7565b348015610aca57600080fd5b5061015f546106a4906001600160a01b031681565b348015610aeb57600080fd5b5061044b612315565b348015610b0057600080fd5b5061044b610b0f366004614e65565b612419565b348015610b2057600080fd5b5061044b6c474f5645524e4f525f524f4c4560981b81565b348015610b4457600080fd5b506104d0610b533660046152f7565b612426565b348015610b6457600080fd5b5061044b610b73366004614eaa565b61244e565b348015610b8457600080fd5b5061044b610b93366004614eaa565b612463565b348015610ba457600080fd5b506104d0610bb3366004614eaa565b612489565b348015610bc457600080fd5b506104d0610bd3366004614f08565b6124c7565b348015610be457600080fd5b5061044b610bf3366004614eaa565b6124ec565b348015610c0457600080fd5b5061044b610c13366004615319565b6124f7565b348015610c2457600080fd5b5061044b694f574e45525f524f4c4560b01b81565b348015610c4557600080fd5b50610162546106a4906001600160a01b031681565b348015610c6657600080fd5b5061044b6c4f50455241544f525f524f4c4560981b81565b348015610c8a57600080fd5b5061044b6101605481565b348015610ca157600080fd5b506104d0612523565b348015610cb657600080fd5b50610164546106a4906001600160a01b031681565b348015610cd757600080fd5b506106a46125b0565b348015610cec57600080fd5b50610163546106a4906001600160a01b031681565b61016254610166546040516393f1a40b60e01b8152600481019190915230602482015260009182916001600160a01b03909116906393f1a40b906044016040805180830381865afa158015610d5a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d7e9190615347565b509050610d94610201546001600160a01b031690565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa158015610dda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dfe919061536b565b610e08908261539a565b92915050565b60006001600160e01b03198216637965db0b60e01b1480610e0857506301ffc9a760e01b6001600160e01b0319831614610e08565b60606101d28054610e53906153ad565b80601f0160208091040260200160405190810160405280929190818152602001828054610e7f906153ad565b8015610ecc5780601f10610ea157610100808354040283529160200191610ecc565b820191906000526020600020905b815481529060010190602001808311610eaf57829003601f168201915b5050505050905090565b694f574e45525f524f4c4560b01b610eed8161261f565b6001600160a01b038216610f305760405162461bcd60e51b81526020600482015260056024820152641820b2323960d91b60448201526064015b60405180910390fd5b610f446001600160a01b0385168385612629565b50505050565b6000610e0882600061268c565b600033610f658185856126c4565b5060019392505050565b6000610e088260016127e9565b600033610f8a85828561281c565b610f95858585612890565b60019150505b9392505050565b600082815260c96020526040902060010154610fbd8161261f565b610fc78383612a48565b505050565b60008061020154610fe79190600160a01b900460ff166153e7565b905090565b6001600160a01b038116331461105c5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610f27565b6110668282612ace565b5050565b6001600160a01b037f0000000000000000000000009361a267c441f3c508c2704ce4835a795b09cf201630036110b25760405162461bcd60e51b8152600401610f2790615400565b7f0000000000000000000000009361a267c441f3c508c2704ce4835a795b09cf206001600160a01b03166110fb6000805160206158c0833981519152546001600160a01b031690565b6001600160a01b0316146111215760405162461bcd60e51b8152600401610f279061544c565b61112a81612b35565b6040805160008082526020820190925261114691839190612b4c565b50565b600033610f6581858561115c83836124f7565b611166919061539a565b6126c4565b694f574e45525f524f4c4560b01b6111828161261f565b6101625461016654604051632989754760e11b81526001600160a01b0390921691635312ea8e916111b99160040190815260200190565b600060405180830381600087803b1580156111d357600080fd5b505af11580156111e7573d6000803e3d6000fd5b50506101685460ff161515600114915050801561120657506001821515145b1561121f57611215600061141a565b61121f60006120c4565b604051821515815233907f898a2bf2227b490bfee6c32f57ba117104777db13f3381be9e335b7b828750fa9060200160405180910390a25050565b611262612cb7565b61126c6000612d12565b611277600161012c55565b565b694f574e45525f524f4c4560b01b6112908161261f565b611146612e78565b6001600160a01b0381166000908152610161602090815260408083208151808301909252805482526001015491810191909152816112d584611c16565b9050806000036112e757505192915050565b60006112f36101d15490565b61015f546040516318ebd13160e11b81523060048201529192506000916c0c9f2c9cd04674edea40000000916001600160a01b0316906331d7a26290602401602060405180830381865afa15801561134f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611373919061536b565b61137d9190615498565b9050600061138b83836154c5565b61016054611399919061539a565b90506c0c9f2c9cd04674edea400000008560200151826113b991906154e7565b6113c39086615498565b6113cd91906154c5565b85516113d9919061539a565b979650505050505050565b6000806113f283600061268c565b905061271061016b54826114069190615498565b61141091906154c5565b610f9b90826154e7565b694f574e45525f524f4c4560b01b6114318161261f565b6101685482151560ff90911615150361144957600080fd5b610168805460ff19168315159081179091556040519081527f7b014ed3854e7f5cb0218d58b3c6ae7d53a68bb0af2f67bfb029ea42c38a7e85906020015b60405180910390a15050565b6001600160a01b037f0000000000000000000000009361a267c441f3c508c2704ce4835a795b09cf201630036114db5760405162461bcd60e51b8152600401610f2790615400565b7f0000000000000000000000009361a267c441f3c508c2704ce4835a795b09cf206001600160a01b03166115246000805160206158c0833981519152546001600160a01b031690565b6001600160a01b03161461154a5760405162461bcd60e51b8152600401610f279061544c565b61155382612b35565b61106682826001612b4c565b6000306001600160a01b037f0000000000000000000000009361a267c441f3c508c2704ce4835a795b09cf2016146115ff5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c00000000000000006064820152608401610f27565b506000805160206158c083398151915290565b694f574e45525f524f4c4560b01b6116298161261f565b600061163e610201546001600160a01b031690565b610162549091506001600160a01b0316156116cd576101625460405163095ea7b360e01b81526001600160a01b039182166004820152602481018590529082169063095ea7b3906044016020604051808303816000875af11580156116a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116cb91906154fa565b505b610163546001600160a01b031615610fc7576101635460405163095ea7b360e01b81526001600160a01b039091166004820152602481018490527380b5a32e4f032b2a058b4f29ec95eefeeb87adcd9063095ea7b3906044016020604051808303816000875af1158015611745573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061176991906154fa565b50806001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117cc9190615517565b6101635460405163095ea7b360e01b81526001600160a01b0391821660048201526024810186905291169063095ea7b3906044016020604051808303816000875af115801561181f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061184391906154fa565b50806001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611882573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118a69190615517565b6101635460405163095ea7b360e01b81526001600160a01b0391821660048201526024810186905291169063095ea7b3906044016020604051808303816000875af11580156118f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061191d91906154fa565b506101635460405163095ea7b360e01b81526001600160a01b039182166004820152602481018590529082169063095ea7b3906044016020604051808303816000875af1158015611972573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061199691906154fa565b50610164546101635460405163095ea7b360e01b81526001600160a01b0391821660048201526024810186905291169063095ea7b3906044016020604051808303816000875af11580156119ee573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a1291906154fa565b506101655460005b81811015611acc576101658181548110611a3657611a36615534565b6000918252602090912001546101635460405163095ea7b360e01b81526001600160a01b0391821660048201526024810188905291169063095ea7b3906044016020604051808303816000875af1158015611a95573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ab991906154fa565b5080611ac48161554a565b915050611a1a565b5050505050565b6000611add612cb7565b6101685460ff161515600114611b285760405162461bcd60e51b815260206004820152601060248201526f11195c1bdcda5d0808595b98589b195960821b6044820152606401610f27565b6000611b3d610201546001600160a01b031690565b90506000611b49612315565b905061016754811115611b6057611b5e612ecb565b505b611b6a338561300a565b506000611b7786866130a2565b61016854909150610100900460ff161515600103611c07576040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015611bd6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bfa919061536b565b9050611c05816130b6565b505b92505050610e08600161012c55565b6001600160a01b031660009081526101cf602052604090205490565b694f574e45525f524f4c4560b01b611c498161261f565b6001600160a01b038916611c875760405162461bcd60e51b81526020600482015260056024820152640c0810591960da1b6044820152606401610f27565b61016280546001600160a01b03808c166001600160a01b0319928316179092556101668a90556101648054928a16929091169190911790558551611cd390610165906020890190614d08565b505061016380546001600160a01b03199081166001600160a01b039687161790915561015e805482169486169490941790935561015f805490931691909316179055805161016755602081015161016955604081015161016a556060015161016b555050610168805461ffff19166101011790555050565b600054610100900460ff1615808015611d6b5750600054600160ff909116105b80611d855750303b158015611d85575060005460ff166001145b611de85760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610f27565b6000805460ff191660011790558015611e0b576000805461ff0019166101001790555b611e1886848488886131a7565b611e206131cc565b8015611e66576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b694f574e45525f524f4c4560b01b611e858161261f565b6111466131f3565b611e95612cb7565b3360008181526101616020526040812091611eaf90611c16565b905060008111611ee75760405162461bcd60e51b81526020600482015260036024820152620233e360ec1b6044820152606401610f27565b611ef033612d12565b6000808355610201546001600160a01b031690611f0d838261268c565b9050612710611f1e826109c4615498565b611f2891906154c5565b611f3290826154e7565b9050611f3d81613231565b611f4733846134e7565b611f5b6001600160a01b0383163383612629565b604080518281526020810185905233917fbb757047c2b5f3974fe26b7c10f732e7bce710b0952a71082702781e62ae0595910160405180910390a250505050611277600161012c55565b600091825260c9602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6000611fda61362a565b60405162461bcd60e51b8152602060048201526008602482015267191a5cd8589b195960c21b6044820152606401610f27565b60606101d38054610e53906153ad565b6000338161202b82866124f7565b90508381101561208b5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610f27565b61209882868684036126c4565b506001949350505050565b6c474f5645524e4f525f524f4c4560981b6120bd8161261f565b5061016755565b694f574e45525f524f4c4560b01b6120db8161261f565b81151561016860019054906101000a900460ff161515036120fb57600080fd5b61016880548315156101000261ff00199091161790556040517fe8e51070d451440726dc975c3a7ce24ad3e1243eeb07ef11389a7143ca74d48b9061148790841515815260200190565b600033610f65818585612890565b610165818154811061216457600080fd5b6000918252602090912001546001600160a01b0316905081565b6000610e0882600161268c565b60405162461bcd60e51b8152602060048201526008602482015267191a5cd8589b195960c21b6044820152600090606401610f27565b60006121cb612cb7565b60006121d6856113e4565b90506000806121ee610201546001600160a01b031690565b905060006121fa612315565b9050610167548111156122115761220f612ecb565b505b61221b333361300a565b5083156122395761222b84613231565b612236888888613671565b92505b61016854610100900460ff1615156001036122c6576040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612295573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122b9919061536b565b90506122c4816130b6565b505b509092505050610f9b600161012c55565b6c474f5645524e4f525f524f4c4560981b6122f18161261f565b5061015f80546001600160a01b0319166001600160a01b0392909216919091179055565b6101625461016654604051634c4b4f4160e11b8152600481019190915230602482015260009182916001600160a01b03909116906398969e8290604401602060405180830381865afa15801561236f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612393919061536b565b610164546040516370a0823160e01b81523060048201529192506000916001600160a01b03909116906370a0823190602401602060405180830381865afa1580156123e2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612406919061536b565b9050612412818361539a565b9250505090565b6000610e088260006127e9565b6c474f5645524e4f525f524f4c4560981b6124408161261f565b506101699190915561016a55565b6000610e0861245c83611c16565b600061268c565b600061246d612cb7565b612477338361300a565b9050612484600161012c55565b919050565b6c474f5645524e4f525f524f4c4560981b6124a38161261f565b5061015e80546001600160a01b0319166001600160a01b0392909216919091179055565b600082815260c960205260409020600101546124e28161261f565b610fc78383612ace565b6000610e0882611c16565b6001600160a01b0391821660009081526101d06020908152604080832093909416825291909152205490565b61252b612cb7565b6000612535612315565b9050610167548110156125785760405162461bcd60e51b815260206004820152600b60248201526a08cf135a5b925b9d995cdd60aa1b6044820152606401610f27565b6000612582612ecb565b61016854909150610100900460ff1615156001036125a3576125a3816130b6565b5050611277600161012c55565b61015f546040805163f7c618c160e01b815290516000926001600160a01b03169163f7c618c19160048083019260209291908290030181865afa1580156125fb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fe79190615517565b611146813361367e565b6040516001600160a01b038316602482015260448101829052610fc790849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526136d7565b6000806126996101d15490565b905080156126ba576126b56126ac610d01565b859083866137ac565b6126bc565b835b949350505050565b6001600160a01b0383166127265760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610f27565b6001600160a01b0382166127875760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610f27565b6001600160a01b0383811660008181526101d0602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6000806127f66101d15490565b9050831580612803575080155b6126ba576126b581612813610d01565b869190866137ac565b600061282884846124f7565b90506000198114610f4457818110156128835760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610f27565b610f4484848484036126c4565b6001600160a01b0383166128f45760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610f27565b6001600160a01b0382166129565760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610f27565b612961838383613807565b6001600160a01b03831660009081526101cf6020526040902054818110156129da5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610f27565b6001600160a01b0380851660008181526101cf602052604080822086860390559286168082529083902080548601905591517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90612a3b9086815260200190565b60405180910390a3610f44565b612a528282611fa5565b61106657600082815260c9602090815260408083206001600160a01b03851684529091529020805460ff19166001179055612a8a3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b612ad88282611fa5565b1561106657600082815260c9602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b694f574e45525f524f4c4560b01b6110668161261f565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615612b7f57610fc783613821565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612bd9575060408051601f3d908101601f19168201909252612bd69181019061536b565b60015b612c3c5760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610f27565b6000805160206158c08339815191528114612cab5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610f27565b50610fc78383836138bd565b600261012c5403612d0a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610f27565b600261012c55565b61015f546040516363453ae160e01b81523060048201526000916001600160a01b0316906363453ae1906024016020604051808303816000875af1158015612d5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d82919061536b565b90506000612d906101d15490565b610160549091508115801590612da65750600083115b15612de05781612dc36c0c9f2c9cd04674edea4000000085615498565b612dcd91906154c5565b612dd7908261539a565b61016081905590505b80600003612dee5750505050565b6001600160a01b03841615610f44576001600160a01b03841660009081526101616020526040812090612e2086611c16565b905060006c0c9f2c9cd04674edea40000000836001015485612e4291906154e7565b612e4c9084615498565b612e5691906154c5565b90506000818460000154612e6a919061539a565b845550505060010155505050565b612e806138e2565b61019d805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6000612ed561392c565b612edd613a9e565b6040516370a0823160e01b81523060048201526000907380b5a32e4f032b2a058b4f29ec95eefeeb87adcd906370a0823190602401602060405180830381865afa158015612f2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f53919061536b565b905060006127106101695483612f699190615498565b612f7391906154c5565b9050600061271061016a5484612f899190615498565b612f9391906154c5565b61015e54909150612fc3907380b5a32e4f032b2a058b4f29ec95eefeeb87adcd906001600160a01b031684612629565b612fe27380b5a32e4f032b2a058b4f29ec95eefeeb87adcd3383612629565b600061300183612ff284876154e7565b612ffc91906154e7565b613b83565b95945050505050565b600061301583612d12565b6001600160a01b03831660009081526101616020526040812080549181559080156126bc5761305784826130476125b0565b6001600160a01b03169190612629565b846001600160a01b03167f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d48260405161309291815260200190565b60405180910390a2949350505050565b60006130ac61362a565b610f9b8383613fc6565b8015611146576040516370a0823160e01b815230600482015260009073c8b4d3e67238e38b20d38908646ff6f4f48de5ec906370a0823190602401602060405180830381865afa15801561310e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613132919061536b565b6101625461016654604051631c57762b60e31b81526004810191909152602481018590529192506001600160a01b03169063e2bbb15890604401600060405180830381600087803b15801561318657600080fd5b505af115801561319a573d6000803e3d6000fd5b5050505061106681613fe0565b6131b0856140b4565b6131ba84846140e4565b6131c2614115565b611acc8282614144565b600054610100900460ff166112775760405162461bcd60e51b8152600401610f2790615563565b6131fb61362a565b61019d805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612eae3390565b8015611146576040516370a0823160e01b815230600482015260009073c8b4d3e67238e38b20d38908646ff6f4f48de5ec906370a0823190602401602060405180830381865afa158015613289573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ad919061536b565b61016254610166546040516393f1a40b60e01b815260048101919091523060248201529192506000916001600160a01b03909116906393f1a40b906044016040805180830381865afa158015613307573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061332b9190615347565b50905080156134de576101625461016654604051634c4b4f4160e11b815260048101919091523060248201526000916001600160a01b0316906398969e8290604401602060405180830381865afa15801561338a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133ae919061536b565b905080600003613426576101625461016654604051632989754760e11b81526001600160a01b0390921691635312ea8e916133ef9160040190815260200190565b600060405180830381600087803b15801561340957600080fd5b505af115801561341d573d6000803e3d6000fd5b505050506134dc565b83821061346b576101625461016654604051630441a3e760e41b81526001600160a01b039092169163441a3e70916133ef918890600401918252602082015260400190565b6101625461016654604051630441a3e760e41b81526001600160a01b039092169163441a3e70916134a9918690600401918252602082015260400190565b600060405180830381600087803b1580156134c357600080fd5b505af11580156134d7573d6000803e3d6000fd5b505050505b505b610fc782613fe0565b6001600160a01b0382166135475760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610f27565b61355382600083613807565b6001600160a01b03821660009081526101cf6020526040902054818110156135c85760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610f27565b6001600160a01b03831660008181526101cf6020908152604080832086860390556101d180548790039055518581529192917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3505050565b61019d5460ff16156112775760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610f27565b60006126bc8484846141e2565b6136888282611fa5565b6110665761369581614256565b6136a0836020614268565b6040516020016136b19291906155ae565b60408051601f198184030181529082905262461bcd60e51b8252610f2791600401614dd0565b600061372c826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166144049092919063ffffffff16565b905080516000148061374d57508080602001905181019061374d91906154fa565b610fc75760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610f27565b6000806137ba868686614413565b905060018360028111156137d0576137d0615623565b1480156137ed5750600084806137e8576137e86154af565b868809115b15613001576137fd60018261539a565b9695505050505050565b61380f61362a565b61381883612d12565b610fc782612d12565b6001600160a01b0381163b61388e5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610f27565b6000805160206158c083398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6138c6836144fd565b6000825111806138d35750805b15610fc757610f44838361453d565b61019d5460ff166112775760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610f27565b6040516370a0823160e01b815230600482015260009073c8b4d3e67238e38b20d38908646ff6f4f48de5ec906370a0823190602401602060405180830381865afa15801561397e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139a2919061536b565b6101625461016654604051634c4b4f4160e11b815260048101919091523060248201529192506000916001600160a01b03909116906398969e8290604401602060405180830381865afa1580156139fd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a21919061536b565b90508015613a95576101625461016654604051630441a3e760e41b81526004810191909152600060248201526001600160a01b039091169063441a3e7090604401600060405180830381600087803b158015613a7c57600080fd5b505af1158015613a90573d6000803e3d6000fd5b505050505b61106682613fe0565b61016554801561114657604080516002808252606082019092526000908281602001602082028036833701905050905073c8b4d3e67238e38b20d38908646ff6f4f48de5ec81600081518110613af657613af6615534565b60200260200101906001600160a01b031690816001600160a01b0316815250507380b5a32e4f032b2a058b4f29ec95eefeeb87adcd81600181518110613b3e57613b3e615534565b6001600160a01b0390921660209283029190910190910152610264548015610f4457806102646000828254613b7391906154e7565b90915550611acc90508282614562565b6000808211613bba5760405162461bcd60e51b81526020600482015260036024820152620233c360ec1b6044820152606401610f27565b6000613bc76002846154c5565b90506000613bde610201546001600160a01b031690565b60408051600280825260608201835292935060009183906020830190803683370190505090507380b5a32e4f032b2a058b4f29ec95eefeeb87adcd81600081518110613c2c57613c2c615534565b60200260200101906001600160a01b031690816001600160a01b031681525050826001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015613c8a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613cae9190615517565b81600181518110613cc157613cc1615534565b6001600160a01b03909216602092830291909101909101528381613ce66001856154e7565b81518110613cf657613cf6615534565b60200260200101516001600160a01b031682600081518110613d1a57613d1a615534565b60200260200101516001600160a01b031614613d3d57613d3a8286614562565b90505b604080516002808252606082019092526000908281602001602082028036833701905050905083600081518110613d7657613d76615534565b602002602001015181600081518110613d9157613d91615534565b60200260200101906001600160a01b031690816001600160a01b031681525050856001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015613def573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e139190615517565b81600181518110613e2657613e26615534565b6001600160a01b03909216602092830291909101909101528681613e4b6001856154e7565b81518110613e5b57613e5b615534565b60200260200101516001600160a01b031682600081518110613e7f57613e7f615534565b60200260200101516001600160a01b031614613ea257613e9f8289614562565b90505b610163546000906001600160a01b031663e8e3370087613ec360018b6154e7565b81518110613ed357613ed3615534565b602002602001015185600188613ee991906154e7565b81518110613ef957613ef9615534565b602002602001015188866000803042610bb8613f15919061539a565b60405160e08a901b6001600160e01b03191681526001600160a01b039889166004820152968816602488015260448701959095526064860193909352608485019190915260a484015290921660c482015260e4810191909152610104016060604051808303816000875af1158015613f91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613fb59190615639565b9d9c50505050505050505050505050565b600080613fd284612419565b9050610f9b338486846146d6565b6040516370a0823160e01b8152306004820152600090819073c8b4d3e67238e38b20d38908646ff6f4f48de5ec906370a0823190602401602060405180830381865afa158015614034573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614058919061536b565b915082821061408b5761406b83836154e7565b9050806102646000828254614080919061539a565b90915550610fc79050565b61409582846154e7565b90508061026460008282546140aa91906154e7565b9091555050505050565b600054610100900460ff166140db5760405162461bcd60e51b8152600401610f2790615563565b61114681614755565b600054610100900460ff1661410b5760405162461bcd60e51b8152600401610f2790615563565b61106682826147db565b600054610100900460ff1661413c5760405162461bcd60e51b8152600401610f2790615563565b61127761481d565b61414c6131cc565b614163694f574e45525f524f4c4560b01b83612a48565b61417d6c474f5645524e4f525f524f4c4560981b82612a48565b614194694f574e45525f524f4c4560b01b80614851565b6141bb6c474f5645524e4f525f524f4c4560981b694f574e45525f524f4c4560b01b614851565b6110666c4f50455241544f525f524f4c4560981b694f574e45525f524f4c4560b01b614851565b60006141ed826124ec565b84111561423c5760405162461bcd60e51b815260206004820152601d60248201527f455243343632363a2072656465656d206d6f7265207468616e206d61780000006044820152606401610f27565b6000614247856113e4565b90506126bc338585848961489c565b6060610e086001600160a01b03831660145b60606000614277836002615498565b61428290600261539a565b67ffffffffffffffff81111561429a5761429a614f63565b6040519080825280601f01601f1916602001820160405280156142c4576020820181803683370190505b509050600360fc1b816000815181106142df576142df615534565b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061430e5761430e615534565b60200101906001600160f81b031916908160001a9053506000614332846002615498565b61433d90600161539a565b90505b60018111156143b5576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061437157614371615534565b1a60f81b82828151811061438757614387615534565b60200101906001600160f81b031916908160001a90535060049490941c936143ae81615667565b9050614340565b508315610f9b5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610f27565b60606126bc8484600085614949565b600080806000198587098587029250828110838203039150508060000361444d57838281614443576144436154af565b0492505050610f9b565b8084116144945760405162461bcd60e51b81526020600482015260156024820152744d6174683a206d756c446976206f766572666c6f7760581b6044820152606401610f27565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b61450681613821565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060610f9b83836040518060600160405280602781526020016158e060279139614a19565b6101635460405163d06ca61f60e01b815260009182916001600160a01b039091169063d06ca61f9061459a90869088906004016156c2565b600060405180830381865afa1580156145b7573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526145df91908101906156db565b9050600081600183516145f291906154e7565b8151811061460257614602615534565b6020908102919091010151610163549091506000906001600160a01b03166338ed173986848930614635426104b061539a565b6040518663ffffffff1660e01b8152600401614655959493929190615761565b6000604051808303816000875af1158015614674573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261469c91908101906156db565b9050600081600183516146af91906154e7565b815181106146bf576146bf615534565b602002602001015190508094505050505092915050565b610201546146ef906001600160a01b0316853085614a87565b6146f98382614abf565b826001600160a01b0316846001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78484604051614747929190918252602082015260400190565b60405180910390a350505050565b600054610100900460ff1661477c5760405162461bcd60e51b8152600401610f2790615563565b60008061478883614b8e565b915091508161479857601261479a565b805b61020180546001600160a01b039095166001600160a01b031960ff93909316600160a01b02929092166001600160a81b031990951694909417179092555050565b600054610100900460ff166148025760405162461bcd60e51b8152600401610f2790615563565b6101d261480f83826157e3565b506101d3610fc782826157e3565b600054610100900460ff166148445760405162461bcd60e51b8152600401610f2790615563565b61019d805460ff19169055565b600082815260c96020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b826001600160a01b0316856001600160a01b0316146148c0576148c083868361281c565b6148ca83826134e7565b610201546148e2906001600160a01b03168584612629565b826001600160a01b0316846001600160a01b0316866001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db858560405161493a929190918252602082015260400190565b60405180910390a45050505050565b6060824710156149aa5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610f27565b600080866001600160a01b031685876040516149c691906158a3565b60006040518083038185875af1925050503d8060008114614a03576040519150601f19603f3d011682016040523d82523d6000602084013e614a08565b606091505b50915091506113d987838387614c6a565b6060600080856001600160a01b031685604051614a3691906158a3565b600060405180830381855af49150503d8060008114614a71576040519150601f19603f3d011682016040523d82523d6000602084013e614a76565b606091505b50915091506137fd86838387614c6a565b6040516001600160a01b0380851660248301528316604482015260648101829052610f449085906323b872dd60e01b90608401612655565b6001600160a01b038216614b155760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610f27565b614b2160008383613807565b806101d16000828254614b34919061539a565b90915550506001600160a01b03821660008181526101cf60209081526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290516000918291829182916001600160a01b03871691614bd5916158a3565b600060405180830381855afa9150503d8060008114614c10576040519150601f19603f3d011682016040523d82523d6000602084013e614c15565b606091505b5091509150818015614c2957506020815110155b15614c5d57600081806020019051810190614c44919061536b565b905060ff8111614c5b576001969095509350505050565b505b5060009485945092505050565b60608315614cd9578251600003614cd2576001600160a01b0385163b614cd25760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610f27565b50816126bc565b6126bc8383815115614cee5781518083602001fd5b8060405162461bcd60e51b8152600401610f279190614dd0565b828054828255906000526020600020908101928215614d5d579160200282015b82811115614d5d57825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190614d28565b50614d69929150614d6d565b5090565b5b80821115614d695760008155600101614d6e565b600060208284031215614d9457600080fd5b81356001600160e01b031981168114610f9b57600080fd5b60005b83811015614dc7578181015183820152602001614daf565b50506000910152565b6020815260008251806020840152614def816040850160208701614dac565b601f01601f19169190910160400192915050565b6001600160a01b038116811461114657600080fd5b803561248481614e03565b600080600060608486031215614e3857600080fd5b8335614e4381614e03565b9250602084013591506040840135614e5a81614e03565b809150509250925092565b600060208284031215614e7757600080fd5b5035919050565b60008060408385031215614e9157600080fd5b8235614e9c81614e03565b946020939093013593505050565b600060208284031215614ebc57600080fd5b8135610f9b81614e03565b600080600060608486031215614edc57600080fd5b8335614ee781614e03565b92506020840135614ef781614e03565b929592945050506040919091013590565b60008060408385031215614f1b57600080fd5b823591506020830135614f2d81614e03565b809150509250929050565b801515811461114657600080fd5b600060208284031215614f5857600080fd5b8135610f9b81614f38565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715614fa257614fa2614f63565b604052919050565b600067ffffffffffffffff831115614fc457614fc4614f63565b614fd7601f8401601f1916602001614f79565b9050828152838383011115614feb57600080fd5b828260208301376000602084830101529392505050565b6000806040838503121561501557600080fd5b823561502081614e03565b9150602083013567ffffffffffffffff81111561503c57600080fd5b8301601f8101851361504d57600080fd5b61505c85823560208401614faa565b9150509250929050565b600067ffffffffffffffff82111561508057615080614f63565b5060051b60200190565b60006080828403121561509c57600080fd5b6040516080810181811067ffffffffffffffff821117156150bf576150bf614f63565b8060405250809150823581526020830135602082015260408301356040820152606083013560608201525092915050565b600080600080600080600080610160898b03121561510d57600080fd5b883561511881614e03565b9750602089810135975060408a013561513081614e03565b965060608a013567ffffffffffffffff81111561514c57600080fd5b8a01601f81018c1361515d57600080fd5b803561517061516b82615066565b614f79565b81815260059190911b8201830190838101908e83111561518f57600080fd5b928401925b828410156151b65783356151a781614e03565b82529284019290840190615194565b80995050505050506151ca60808a01614e18565b93506151d860a08a01614e18565b92506151e660c08a01614e18565b91506151f58a60e08b0161508a565b90509295985092959890939650565b600082601f83011261521557600080fd5b610f9b83833560208501614faa565b600080600080600060a0868803121561523c57600080fd5b853561524781614e03565b9450602086013561525781614e03565b9350604086013561526781614e03565b9250606086013567ffffffffffffffff8082111561528457600080fd5b61529089838a01615204565b935060808801359150808211156152a657600080fd5b506152b388828901615204565b9150509295509295909350565b6000806000606084860312156152d557600080fd5b8335925060208401356152e781614e03565b91506040840135614e5a81614e03565b6000806040838503121561530a57600080fd5b50508035926020909101359150565b6000806040838503121561532c57600080fd5b823561533781614e03565b91506020830135614f2d81614e03565b6000806040838503121561535a57600080fd5b505080516020909101519092909150565b60006020828403121561537d57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b80820180821115610e0857610e08615384565b600181811c908216806153c157607f821691505b6020821081036153e157634e487b7160e01b600052602260045260246000fd5b50919050565b60ff8181168382160190811115610e0857610e08615384565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b8082028115828204841417610e0857610e08615384565b634e487b7160e01b600052601260045260246000fd5b6000826154e257634e487b7160e01b600052601260045260246000fd5b500490565b81810381811115610e0857610e08615384565b60006020828403121561550c57600080fd5b8151610f9b81614f38565b60006020828403121561552957600080fd5b8151610f9b81614e03565b634e487b7160e01b600052603260045260246000fd5b60006001820161555c5761555c615384565b5060010190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516155e6816017850160208801614dac565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351615617816028840160208801614dac565b01602801949350505050565b634e487b7160e01b600052602160045260246000fd5b60008060006060848603121561564e57600080fd5b8351925060208401519150604084015190509250925092565b60008161567657615676615384565b506000190190565b600081518084526020808501945080840160005b838110156156b75781516001600160a01b031687529582019590820190600101615692565b509495945050505050565b8281526040602082015260006126bc604083018461567e565b600060208083850312156156ee57600080fd5b825167ffffffffffffffff81111561570557600080fd5b8301601f8101851361571657600080fd5b805161572461516b82615066565b81815260059190911b8201830190838101908783111561574357600080fd5b928401925b828410156113d957835182529284019290840190615748565b85815284602082015260a06040820152600061578060a083018661567e565b6001600160a01b0394909416606083015250608001529392505050565b601f821115610fc757600081815260208120601f850160051c810160208610156157c45750805b601f850160051c820191505b81811015611e66578281556001016157d0565b815167ffffffffffffffff8111156157fd576157fd614f63565b6158118161580b84546153ad565b8461579d565b602080601f831160018114615846576000841561582e5750858301515b600019600386901b1c1916600185901b178555611e66565b600085815260208120601f198616915b8281101561587557888601518255948401946001909101908401615856565b50858210156158935787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b600082516158b5818460208701614dac565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220bf4b189f862a7f435ae2f551f5fe646af5decde7018f9e818e794abaa36af73164736f6c63430008120033