Contract Overview
Balance:
0 BTT
My Name Tag:
Not Available
Txn Hash | Method |
Block
|
From
|
To
|
Value | [Txn Fee] | |||
---|---|---|---|---|---|---|---|---|---|
0x2281b8d3eee81ea3ce7c9dffcf2629188f99b881030b589a03404aaa5dd1266e | 0x615e5d61 | 21929589 | 27 days 20 hrs ago | 0x997ebeee6e89de030880cad6d604465549277cc9 | IN | Create: ElkFactoryHelper | 0 BTT | 47,204.649 |
[ Download CSV Export ]
Latest 9 internal transactions
[ Download CSV Export ]
Contract Source Code Verified (Exact Match)
Contract Name:
ElkFactoryHelper
Compiler Version
v0.8.19+commit.7dd6d404
Contract Source Code (Solidity)
/** *Submitted for verification at testnet.bttcscan.com on 2023-05-11 */ // SPDX-License-Identifier: BUSL-1.1 // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> // - Elijah <[email protected]> // - Snake <[email protected]> // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.0/contracts/utils/Address.sol // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [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://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return 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); } } } // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.0/contracts/token/ERC20/extensions/draft-IERC20Permit.sol // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-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 IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); } // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.0/contracts/token/ERC20/IERC20.sol // OpenZeppelin Contracts (last updated v4.6.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); } // File: contracts/interfaces/IStaking.sol // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> pragma solidity >=0.8.0; interface IStaking { /* ========== STATE VARIABLES ========== */ function stakingToken() external returns (IERC20); function totalSupply() external returns (uint256); function balances(address _account) external returns (uint256); /* ========== MUTATIVE FUNCTIONS ========== */ function stake(uint256 _amount) external; function withdraw(uint256 _amount) external; function exit() external; function recoverERC20( address _tokenAddress, address _recipient, uint256 _amount ) external; /* ========== EVENTS ========== */ // Emitted on staking event Staked(address indexed account, uint256 amount); // Emitted on withdrawal (including exit) event Withdrawn(address indexed account, uint256 amount); // Emitted on token recovery event Recovered( address indexed token, address indexed recipient, uint256 amount ); } // File: contracts/interfaces/IStakingFee.sol // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> pragma solidity >=0.8.0; interface IStakingFee is IStaking { /* ========== STATE VARIABLES ========== */ function feesUnit() external returns (uint256); function maxFee() external returns (uint256); function withdrawalFeeSchedule(uint256) external returns (uint256); function withdrawalFeesBps(uint256) external returns (uint256); function depositFeeBps() external returns (uint256); function collectedFees() external returns (uint256); function userLastStakedTime(address _user) external view returns (uint32); /* ========== VIEWS ========== */ function depositFee(uint256 _depositAmount) external view returns (uint256); function withdrawalFee( address _account, uint256 _withdrawalAmount ) external view returns (uint256); /* ========== MUTATIVE FUNCTIONS ========== */ function recoverFees(address _recipient) external; function setFees( uint16 _depositFeeBps, uint16[] memory _withdrawalFeesBps, uint32[] memory _withdrawalFeeSchedule ) external; /* ========== EVENTS ========== */ // Emitted when fees are (re)configured event FeesSet( uint16 _depositFeeBps, uint16[] _withdrawalFeesBps, uint32[] _feeSchedule ); // Emitted when a deposit fee is collected event DepositFeesCollected(address indexed _user, uint256 _amount); // Emitted when a withdrawal fee is collected event WithdrawalFeesCollected(address indexed _user, uint256 _amount); // Emitted when fees are recovered by governance event FeesRecovered(uint256 _amount); } // File: contracts/interfaces/IStakingRewards.sol // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> pragma solidity >=0.8.0; interface IStakingRewards is IStakingFee { /* ========== STATE VARIABLES ========== */ function rewardTokens(uint256) external view returns (IERC20); function rewardTokenAddresses( address _rewardAddress ) external view returns (bool); function periodFinish() external view returns (uint256); function rewardsDuration() external view returns (uint256); function lastUpdateTime() external view returns (uint256); function rewardRates( address _rewardAddress ) external view returns (uint256); function rewardPerTokenStored( address _rewardAddress ) external view returns (uint256); // wallet address => token address => amount function userRewardPerTokenPaid( address _walletAddress, address _tokenAddress ) external view returns (uint256); function rewards( address _walletAddress, address _tokenAddress ) external view returns (uint256); /* ========== VIEWS ========== */ function lastTimeRewardApplicable() external view returns (uint256); function rewardPerToken( address _tokenAddress ) external view returns (uint256); function earned( address _tokenAddress, address _account ) external view returns (uint256); /* ========== MUTATIVE FUNCTIONS ========== */ function getReward(address _tokenAddress, address _recipient) external; function getRewards(address _recipient) external; // Must send reward before calling this! function startEmission( uint256[] memory _rewards, uint256 _duration ) external; function stopEmission(address _refundAddress) external; function recoverLeftoverReward( address _tokenAddress, address _recipient ) external; function addRewardToken(address _tokenAddress) external; function rewardTokenIndex( address _tokenAddress ) external view returns (int8); /* ========== EVENTS ========== */ // Emitted when a reward is paid to an account event RewardPaid( address indexed _token, address indexed _account, uint256 _reward ); // Emitted when a leftover reward is recovered event LeftoverRewardRecovered(address indexed _recipient, uint256 _amount); // Emitted when rewards emission is started event RewardsEmissionStarted(uint256[] _rewards, uint256 _duration); // Emitted when rewards emission ends event RewardsEmissionEnded(); } // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.0/contracts/token/ERC20/utils/SafeERC20.sol // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit 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(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.0/contracts/security/ReentrancyGuard.sol // OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @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 ReentrancyGuard { // 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; constructor() { _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; } } // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.0/contracts/utils/Context.sol // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.8.0/contracts/access/Ownable.sol // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // File: contracts/Staking.sol // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> // - Elijah <[email protected]> // - Snake <[email protected]> pragma solidity >=0.8.0; /** * Base contract implementing simple ERC20 token staking functionality (no staking rewards). */ contract Staking is ReentrancyGuard, Ownable, IStaking { using SafeERC20 for IERC20; /* ========== STATE VARIABLES ========== */ /// @notice Staking token interface IERC20 public immutable stakingToken; /// @notice Total supply of the staking token uint256 public totalSupply; /// @notice Account balances mapping(address => uint256) public balances; /* ========== CONSTRUCTOR ========== */ /// @param _stakingTokenAddress address of the token used for staking (must be ERC20) constructor(address _stakingTokenAddress) { require(_stakingTokenAddress != address(0), "E1"); stakingToken = IERC20(_stakingTokenAddress); } /** * @dev Stake tokens. * Note: the contract must have sufficient allowance for the staking token. * @param _amount amount to stake */ function stake(uint256 _amount) public nonReentrant { uint256 originalAmount = _amount; _amount = _beforeStake(msg.sender, _amount); require(_amount > 0 && originalAmount > 0, "E2"); // Check after the hook totalSupply += _amount; balances[msg.sender] += _amount; stakingToken.safeTransferFrom(msg.sender, address(this), originalAmount); emit Staked(msg.sender, _amount); } /** * @dev Withdraw previously staked tokens. * @param _amount amount to withdraw */ function withdraw(uint256 _amount) public nonReentrant { uint256 originalAmount = _amount; _amount = _beforeWithdraw(msg.sender, _amount); require( _amount > 0 && _amount <= balances[msg.sender] && originalAmount <= balances[msg.sender], "E3" ); // Check after the hook totalSupply -= originalAmount; balances[msg.sender] -= originalAmount; stakingToken.safeTransfer(msg.sender, _amount); emit Withdrawn(msg.sender, _amount); } /** * @dev Exit the farm, i.e., withdraw the entire token balance of the calling account */ function exit() external { _beforeExit(msg.sender); withdraw(balances[msg.sender]); } /* ========== RESTRICTED FUNCTIONS ========== */ /** * @dev Recover ERC20 tokens held in the contract. * Note: privileged governance function to recover tokens mistakenly sent to this contract address. * This function cannot be used to withdraw staking tokens. * @param _tokenAddress address of the token to recover * @param _recipient recovery address * @param _amount amount to withdraw * @ return withdrawn amount (may differ from input amount due to e.g., fees) */ function recoverERC20( address _tokenAddress, address _recipient, uint256 _amount ) external nonReentrant onlyOwner { require( _tokenAddress != address(stakingToken), "E4" ); _beforeRecoverERC20(_tokenAddress, _recipient, _amount); IERC20 token = IERC20(_tokenAddress); token.safeTransfer(_recipient, _amount); emit Recovered(_tokenAddress, _recipient, _amount); } /* ========== HOOKS ========== */ /** * @dev Internal hook called before staking (in the stake() function). * @ param _account staker address * @param _amount amount being staken * @return amount to stake (may be changed by the hook) */ function _beforeStake( address /*_account*/, uint256 _amount ) internal virtual returns (uint256) { return _amount; } /** * @dev Internal hook called before withdrawing (in the withdraw() function). * @ param _account withdrawer address * @param _amount amount being withdrawn * @return amount to withdraw (may be changed by the hook) */ function _beforeWithdraw( address /*_account*/, uint256 _amount ) internal virtual returns (uint256) { return _amount; } /** * @dev Internal hook called before exiting (in the exit() function). * Note: since exit() calls withdraw() internally, the _beforeWithdraw() hook fill fire too. * @param _account address exiting */ function _beforeExit(address _account) internal virtual {} /** * @dev Internal hook called before recovering tokens (in the recoverERC20() function). * @param _tokenAddress address of the token being recovered * @param _recipient recovery address * @param _amount amount being withdrawn */ function _beforeRecoverERC20( address _tokenAddress, address _recipient, uint256 _amount ) internal virtual {} } // File: contracts/StakingFee.sol // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> // - Elijah <[email protected]> // - Snake <[email protected]> pragma solidity >=0.8.0; /** * Contract implementing simple ERC20 token staking functionality and supporting deposit/withdrawal fees (no staking rewards). */ contract StakingFee is Staking, IStakingFee { using SafeERC20 for IERC20; /* ========== STATE VARIABLES ========== */ /// @notice Constant Fee Unit (1e4) uint256 public constant feesUnit = 10000; /// @notice Maximum fee (20%) uint256 public constant maxFee = 2000; /// @notice Schedule of withdrawal fees represented as a sorted array of durations /// @dev example: 10% after 1 hour, 1% after a day, 0% after a week => [3600, 86400] uint256[] public withdrawalFeeSchedule; /// @notice Withdrawal fees described in basis points (fee unit) represented as an array of the same length as withdrawalFeeSchedule /// @dev example: 10% after 1 hour, 1% after a day, 0% after a week => [1000, 100] uint256[] public withdrawalFeesBps; /// @notice Deposit (staking) fee in basis points (fee unit) uint256 public depositFeeBps; /// @notice Counter of collected fees uint256 public collectedFees; /// @notice Last staking time for each user mapping(address => uint32) public userLastStakedTime; /* ========== CONSTRUCTOR ========== */ /** * @param _stakingTokenAddress address of the token used for staking (must be ERC20) * @param _depositFeeBps deposit fee in basis points * @param _withdrawalFeesBps aligned to fee schedule * @param _withdrawalFeeSchedule assumes a sorted array */ constructor( address _stakingTokenAddress, uint16 _depositFeeBps, uint16[] memory _withdrawalFeesBps, uint32[] memory _withdrawalFeeSchedule ) Staking(_stakingTokenAddress) { setFees(_depositFeeBps, _withdrawalFeesBps, _withdrawalFeeSchedule); } /* ========== VIEWS ========== */ /** * @dev Calculate the deposit fee for a given amount. * @param _depositAmount amount to stake * @return fee paid upon deposit */ function depositFee(uint256 _depositAmount) public view returns (uint256) { return depositFeeBps > 0 ? (_depositAmount * depositFeeBps) / feesUnit : 0; } /** * @dev Calculate the withdrawal fee for a given amount. * @param _account user wallet address * @param _withdrawalAmount amount to withdraw * @return fee paid upon withdrawal */ function withdrawalFee( address _account, uint256 _withdrawalAmount ) public view returns (uint256) { uint256 userLastStakedTimestampDiff = block.timestamp - userLastStakedTime[_account]; uint256 withdrawalFeeAmount; for (uint i = 0; i < withdrawalFeeSchedule.length; ++i) { if (userLastStakedTimestampDiff < withdrawalFeeSchedule[i]) { withdrawalFeeAmount = (_withdrawalAmount * withdrawalFeesBps[i]) / feesUnit; break; } } return withdrawalFeeAmount; } /* ========== RESTRICTED FUNCTIONS ========== */ /** * @dev Recover collected fees held in the contract. * Note: privileged function for governance * @param _recipient fee recovery address */ function recoverFees(address _recipient) external onlyOwner nonReentrant { _beforeRecoverFees(_recipient); uint256 previousFees = collectedFees; collectedFees = 0; emit FeesRecovered(previousFees); stakingToken.safeTransfer(_recipient, previousFees); } /** * @dev Configure the fees for this contract. * @param _depositFeeBps deposit fee in basis points * @param _withdrawalFeesBps withdrawal fees in basis points * @param _withdrawalFeeSchedule withdrawal fees schedule */ function setFees( uint16 _depositFeeBps, uint16[] memory _withdrawalFeesBps, uint32[] memory _withdrawalFeeSchedule ) public onlyOwner { _beforeSetFees(); require(_withdrawalFeeSchedule.length == _withdrawalFeesBps.length && _withdrawalFeeSchedule.length <= 10 && _depositFeeBps <= maxFee, "E5"); uint32 lastFeeSchedule = 0; uint256 lastWithdrawalFee = maxFee + 1; for (uint i = 0; i < _withdrawalFeeSchedule.length; ++i) { require(_withdrawalFeeSchedule[i] > lastFeeSchedule, "E7"); require(_withdrawalFeesBps[i] < lastWithdrawalFee, "E8"); lastFeeSchedule = _withdrawalFeeSchedule[i]; lastWithdrawalFee = _withdrawalFeesBps[i]; } withdrawalFeeSchedule = _withdrawalFeeSchedule; withdrawalFeesBps = _withdrawalFeesBps; depositFeeBps = _depositFeeBps; emit FeesSet( _depositFeeBps, _withdrawalFeesBps, _withdrawalFeeSchedule ); } /* ========== HOOKS ========== */ /** * @dev Override _beforeStake() hook to collect the deposit fee and update associated state */ function _beforeStake( address _account, uint256 _amount ) internal virtual override returns (uint256) { uint256 fee = depositFee(_amount); userLastStakedTime[_account] = uint32(block.timestamp); if (fee > 0) { collectedFees += fee; emit DepositFeesCollected(_account, fee); } return super._beforeStake(_account, _amount - fee); } /** * @dev Override _beforeWithdrawl() hook to collect the withdrawal fee and update associated state */ function _beforeWithdraw( address _account, uint256 _amount ) internal virtual override returns (uint256) { uint256 fee = withdrawalFee(_account, _amount); if (fee > 0) { collectedFees += fee; emit WithdrawalFeesCollected(_account, fee); } return super._beforeWithdraw(_account, _amount - fee); } /** * @dev Internal hook called before recovering fees (in the recoverFees() function). * @param _recipient recovery address */ function _beforeRecoverFees(address _recipient) internal virtual {} /** * @dev Internal hook called before setting fees (in the setFees() function). */ function _beforeSetFees() internal virtual {} } // File: contracts/StakingRewards.sol // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> // - Elijah <[email protected]> // - Snake <[email protected]> pragma solidity >=0.8.0; /** * Contract implementing simple ERC20 token staking functionality with staking rewards and deposit/withdrawal fees. */ contract StakingRewards is StakingFee, IStakingRewards { using SafeERC20 for IERC20; /* ========== STATE VARIABLES ========== */ /// @notice List of reward token interfaces IERC20[] public rewardTokens; /// @notice Reward token addresses (maps every reward token address to true, others to false) mapping(address => bool) public rewardTokenAddresses; /// @notice Timestamp when rewards stop emitting uint256 public periodFinish; /// @notice Duration for reward emission uint256 public rewardsDuration; /// @notice Last time the rewards were updated uint256 public lastUpdateTime; /// @notice Reward token rates (maps every reward token to an emission rate, i.e., how many tokens emitted per second) mapping(address => uint256) public rewardRates; /// @notice How many tokens are emitted per staked token mapping(address => uint256) public rewardPerTokenStored; /// @notice How many reward tokens were paid per user (token address => wallet address => amount) mapping(address => mapping(address => uint256)) public userRewardPerTokenPaid; /// @notice Accumulator of reward tokens per user (token address => wallet address => amount) mapping(address => mapping(address => uint256)) public rewards; /* ========== CONSTRUCTOR ========== */ /** * @param _stakingTokenAddress address of the token used for staking (must be ERC20) * @param _rewardTokenAddresses addresses the reward tokens (must be ERC20) * @param _rewardsDuration reward emission duration * @param _depositFeeBps deposit fee in basis points * @param _withdrawalFeesBps aligned to fee schedule * @param _withdrawalFeeSchedule assumes a sorted array */ constructor( address _stakingTokenAddress, address[] memory _rewardTokenAddresses, uint256 _rewardsDuration, uint16 _depositFeeBps, uint16[] memory _withdrawalFeesBps, uint32[] memory _withdrawalFeeSchedule ) StakingFee( _stakingTokenAddress, _depositFeeBps, _withdrawalFeesBps, _withdrawalFeeSchedule ) { require(_rewardTokenAddresses.length > 0, "E9"); // update reward data structures for (uint i = 0; i < _rewardTokenAddresses.length; ++i) { address tokenAddress = _rewardTokenAddresses[i]; _addRewardToken(tokenAddress); } rewardsDuration = _rewardsDuration; } /* ========== VIEWS ========== */ /** * @notice Return the last time rewards are applicable (the lowest of the current timestamp and the rewards expiry timestamp). * @return timestamp */ function lastTimeRewardApplicable() public view returns (uint256) { return block.timestamp < periodFinish ? block.timestamp : periodFinish; } /** * @notice Return the reward per staked token for a given reward token address. * @param _tokenAddress reward token address * @return amount of reward per staked token */ function rewardPerToken( address _tokenAddress ) public view returns (uint256) { if (totalSupply == 0) { return rewardPerTokenStored[_tokenAddress]; } return rewardPerTokenStored[_tokenAddress] + ((lastTimeRewardApplicable() - lastUpdateTime) * rewardRates[_tokenAddress] * 1e18) / totalSupply; } /** * @notice Return the total reward earned by a user for a given reward token address. * @param _tokenAddress reward token address * @param _account user wallet address * @return amount earned */ function earned( address _tokenAddress, address _account ) public view returns (uint256) { return (balances[_account] * (rewardPerToken(_tokenAddress) - userRewardPerTokenPaid[_tokenAddress][_account])) / 1e18 + rewards[_tokenAddress][_account]; } /* ========== MUTATIVE FUNCTIONS ========== */ /** * @dev claim the specified token reward for a staker * @param _tokenAddress the address of the reward token * @param _recipient the address of the staker that should receive the reward * @ return amount of reward received */ function getReward( address _tokenAddress, address _recipient ) public nonReentrant updateRewards(_recipient) { return _getReward(_tokenAddress, _recipient); } /** * @dev claim rewards for all the reward tokens for the staker * @param _recipient address of the recipient to receive the rewards */ function getRewards( address _recipient ) public nonReentrant updateRewards(_recipient) { for (uint i = 0; i < rewardTokens.length; ++i) { _getReward(address(rewardTokens[i]), _recipient); } } /** * @dev Start the emission of rewards to stakers. The owner must send reward tokens to the contract before calling this function. * Note: Can only be called by owner when the contract is not emitting rewards. * @param _rewards array of rewards amounts for each reward token * @param _duration duration in seconds for which rewards will be emitted */ function startEmission( uint256[] memory _rewards, uint256 _duration ) public virtual nonReentrant onlyOwner whenNotEmitting updateRewards(address(0)) { require(_duration > 0, "E10"); require(_rewards.length == rewardTokens.length, "E11"); _beforeStartEmission(_rewards, _duration); rewardsDuration = _duration; for (uint i = 0; i < rewardTokens.length; ++i) { IERC20 token = rewardTokens[i]; address tokenAddress = address(token); rewardRates[tokenAddress] = _rewards[i] / rewardsDuration; // Ensure the provided reward amount is not more than the balance in the contract. // This keeps the reward rate in the right range, preventing overflows due to // very high values of rewardRate in the earned and rewardsPerToken functions; // Reward + leftover must be less than 2^256 / 10^18 to avoid overflow. uint256 balance = rewardTokens[i].balanceOf(address(this)); if (tokenAddress != address(stakingToken)) { require( rewardRates[tokenAddress] <= balance / rewardsDuration, "E3" ); } else { // Handle carefully where rewardsToken is the same as stakingToken (need to subtract total supply) require( rewardRates[tokenAddress] <= (balance - totalSupply) / rewardsDuration, "E3" ); } } lastUpdateTime = block.timestamp; periodFinish = block.timestamp + rewardsDuration; emit RewardsEmissionStarted(_rewards, _duration); } /** * @dev stop the reward emission process and transfer the remaining reward tokens to a specified address * Note: can only be called by owner when the contract is currently emitting rewards * @param _refundAddress the address to receive the remaining reward tokens */ function stopEmission( address _refundAddress ) external nonReentrant onlyOwner whenEmitting { _beforeStopEmission(_refundAddress); uint256 remaining = 0; if (periodFinish > block.timestamp) { remaining = periodFinish - block.timestamp; } periodFinish = block.timestamp; for (uint i = 0; i < rewardTokens.length; ++i) { IERC20 token = rewardTokens[i]; address tokenAddress = address(token); uint256 refund = rewardRates[tokenAddress] * remaining; if (refund > 0) { token.safeTransfer(_refundAddress, refund); } } emit RewardsEmissionEnded(); } /** * @dev recover leftover reward tokens and transfer them to a specified recipient * Note: can only be called by owner when the contract is not emitting rewards * @param _tokenAddress address of the reward token to be recovered * @param _recipient address to receive the recovered reward tokens */ function recoverLeftoverReward( address _tokenAddress, address _recipient ) external onlyOwner whenNotEmitting { require(totalSupply == 0, "E12"); if (rewardTokenAddresses[_tokenAddress]) { _beforeRecoverLeftoverReward(_tokenAddress, _recipient); IERC20 token = IERC20(_tokenAddress); uint256 amount = token.balanceOf(address(this)); if (amount > 0) { token.safeTransfer(_recipient, amount); } emit LeftoverRewardRecovered(_recipient, amount); } } /** * @dev add a reward token to the contract * Note: can only be called by owner when the contract is not emitting rewards * @param _tokenAddress address of the new reward token */ function addRewardToken( address _tokenAddress ) external onlyOwner whenNotEmitting { _addRewardToken(_tokenAddress); } /** * @dev Return the array index of the provided token address (if applicable) * @param _tokenAddress address of the LP token * @return the array index for _tokenAddress or -1 if it is not a reward token */ function rewardTokenIndex( address _tokenAddress ) public view returns (int8) { if (rewardTokenAddresses[_tokenAddress]) { for (uint i = 0; i < rewardTokens.length; ++i) { if (address(rewardTokens[i]) == _tokenAddress) { return int8(int256(i)); } } } return -1; } /* ========== PRIVATE FUNCTIONS ========== */ /** * @dev Get the reward amount of a token for a specific recipient * @param _tokenAddress address of the token * @param _recipient address of the recipient */ function _getReward(address _tokenAddress, address _recipient) private { require(msg.sender == owner() || msg.sender == _recipient, "E14"); require(rewardTokenAddresses[_tokenAddress], "E13"); uint256 reward = rewards[_tokenAddress][_recipient]; if (reward > 0) { rewards[_tokenAddress][_recipient] = 0; IERC20(_tokenAddress).safeTransfer(_recipient, reward); emit RewardPaid(_tokenAddress, _recipient, reward); } } /** * @dev Add a token as a reward token * @param _tokenAddress address of the token to be added as a reward token */ function _addRewardToken(address _tokenAddress) private { require(rewardTokens.length <= 15, "E15"); require(_tokenAddress != address(0), "E1"); if (!rewardTokenAddresses[_tokenAddress]) { rewardTokens.push(IERC20(_tokenAddress)); rewardTokenAddresses[_tokenAddress] = true; } } /* ========== HOOKS ========== */ /** * @dev Override _beforeStake() hook to ensure staking is only possible when rewards are emitting and update the rewards */ function _beforeStake( address _account, uint256 _amount ) internal virtual override whenEmitting updateRewards(_account) returns (uint256) { return super._beforeStake(_account, _amount); } /** * @dev Override _beforeExit() hook to claim all rewards for the account exiting */ function _beforeExit(address _account) internal virtual override { getRewards(_account); // getRewards calls updateRewards so we don't need to call it explicitly again here super._beforeExit(_account); } /** * @dev Override _beforeRecoverERC20() hook to prevent recovery of a reward token */ function _beforeRecoverERC20( address _tokenAddress, address _recipient, uint256 _amount ) internal virtual override { require(!rewardTokenAddresses[_tokenAddress], "E16"); super._beforeRecoverERC20(_tokenAddress, _recipient, _amount); } /** * @dev Override _beforeSetFees() hook to prevent settings fees when rewards are emitting */ function _beforeSetFees() internal virtual override whenNotEmitting { super._beforeSetFees(); } /** * @dev Internal hook called before starting the emission process (in the startEmission() function). * @param _rewards array of rewards per token. * @param _duration emission duration. */ function _beforeStartEmission( uint256[] memory _rewards, uint256 _duration ) internal virtual {} /** * @dev Internal hook called before stopping the emission process (in the stopEmission() function). * @param _refundAddress address to refund the remaining reward to */ function _beforeStopEmission(address _refundAddress) internal virtual {} /** * @dev Internal hook called before recovering leftover rewards (in the recoverLeftoverRewards() function). * @param _tokenAddress address of the token to recover * @param _recipient address to recover the leftover rewards to */ function _beforeRecoverLeftoverReward( address _tokenAddress, address _recipient ) internal virtual {} /* ========== MODIFIERS ========== */ /** * @dev Modifier to update rewards of a given account. * @param _account account to update rewards for */ modifier updateRewards(address _account) { for (uint i = 0; i < rewardTokens.length; ++i) { address tokenAddress = address(rewardTokens[i]); rewardPerTokenStored[tokenAddress] = rewardPerToken(tokenAddress); if (_account != address(0)) { rewards[tokenAddress][_account] = earned(tokenAddress, _account); userRewardPerTokenPaid[tokenAddress][_account] = rewardPerTokenStored[tokenAddress]; } } lastUpdateTime = lastTimeRewardApplicable(); _; } /** * @dev Modifier to check if rewards are emitting. */ modifier whenEmitting() { require(block.timestamp <= periodFinish, "E18"); _; } /** * @dev Modifier to check if rewards are not emitting. */ modifier whenNotEmitting() { require(block.timestamp > periodFinish, "E17"); _; } } // File: contracts/interfaces/IElkPair.sol // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> pragma solidity >=0.5.0; interface IElkPair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address _owner) external view returns (uint); function allowance( address _owner, address _spender ) external view returns (uint); function approve(address _spender, uint _value) external returns (bool); function transfer(address _to, uint _value) external returns (bool); function transferFrom( address _from, address _to, uint _value ) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address _owner) external view returns (uint); function permit( address _owner, address _spender, uint _value, uint _deadline, uint8 _v, bytes32 _r, bytes32 _s ) external; event Mint(address indexed sender, uint amount0, uint amount1); event Burn( address indexed sender, uint amount0, uint amount1, address indexed to ); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns ( uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast ); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address _to) external returns (uint liquidity); function burn(address _to) external returns (uint amount0, uint amount1); function swap( uint _amount0Out, uint _amount1Out, address _to, bytes calldata _data ) external; function skim(address _to) external; function sync() external; function initialize(address, address) external; } // File: contracts/interfaces/IElkDexOracle.sol // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> pragma solidity >=0.8.0; interface IElkDexOracle { struct Observation { uint timestamp; uint price0Cumulative; uint price1Cumulative; } function weth() external view returns (address); function factory() external view returns (address); function windowSize() external view returns (uint); function granularity() external view returns (uint8); function periodSize() external view returns (uint); function pairObservations( address _pair ) external view returns (Observation[] memory); function observationIndexOf(uint _timestamp) external view returns (uint); function update(address _tokenA, address _tokenB) external; function updateWeth(address _token) external; function consult( address _tokenIn, uint _amountIn, address _tokenOut ) external view returns (uint); function consultWeth( address _tokenIn, uint _amountIn ) external view returns (uint); } // File: contracts/interfaces/IFarmingRewards.sol // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> pragma solidity >=0.8.0; interface IFarmingRewards is IStakingRewards { /// @notice Represents a snapshot of an LP position at a given timestamp struct Position { uint112 amount0; uint112 amount1; uint32 blockTimestamp; } /* ========== STATE VARIABLES ========== */ function oracle() external returns (IElkDexOracle); function lpToken() external returns (IElkPair); function coverageTokenAddress() external returns (address); function coverageAmount() external returns (uint256); function coverageVestingDuration() external returns (uint256); function coverageRate() external returns (uint256); function coveragePerTokenStored() external returns (uint256); function userCoveragePerTokenPaid( address _tokenPaid ) external returns (uint256); function coverage(address _token) external returns (uint256); function lastStakedPosition( address _user ) external returns (uint112 amount0, uint112 amount1, uint32 blockTimeStamp); /* ========== VIEWS ========== */ function coveragePerToken() external view returns (uint256); function coverageEarned(address _account) external view returns (uint256); /* ========== MUTATIVE FUNCTIONS ========== */ function getCoverage(address _recipient) external; function startEmission( uint256[] memory _rewards, uint256 _coverage, uint256 _duration ) external; function recoverLeftoverCoverage(address _recipient) external; /* ========== EVENTS ========== */ // Emitted when the coverage is paid to an account event CoveragePaid(address indexed account, uint256 coverage); // Emitted when the leftover coverage is recovered event LeftoverCoverageRecovered(address indexed recipient, uint256 amount); } // File: contracts/FarmingRewards.sol // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> // - Elijah <[email protected]> // - Snake <[email protected]> pragma solidity >=0.8.0; /** * Contract implementing simple ERC20 token staking functionality with staking rewards, impermanent loss coverage, and deposit/withdrawal fees. */ contract FarmingRewards is StakingRewards, IFarmingRewards { using SafeERC20 for IERC20; /* ========== STATE VARIABLES ========== */ /// @notice Interface to the ElkDex pricing oracle on this blockchain IElkDexOracle public immutable oracle; /// @notice Interface to the LP token that is staked in this farm IElkPair public immutable lpToken; /// @notice Address of the coverage token address public coverageTokenAddress; /// @notice Total amount of coverage available (worst case max amount) uint256 public coverageAmount; /// @notice Time until a farmed position is fully covered against impermanent loss (100%) uint256 public coverageVestingDuration; /// @notice Rate of coverage vesting uint256 public coverageRate; /// @notice Coverage amount per token staked in the farm uint256 public coveragePerTokenStored; /// @notice How much coverage was paid per user (wallet address => amount) mapping(address => uint256) public userCoveragePerTokenPaid; /// @notice Accumulator of coverage tokens per user (wallet address => amount) mapping(address => uint256) public coverage; /// @notice Last farming position for a given user (wallet address => position) mapping(address => Position) public lastStakedPosition; /* ========== CONSTRUCTOR ========== */ /** * @param _oracleAddress address of the price oracle * @param _lpTokenAddress address of the staking LP token (must be an ElkDex LP) * @param _coverageTokenAddress address of the token that the coverage is paid in * @param _coverageAmount total amount of coverage * @param _coverageVestingDuration time it takes to vest 100% of the coverage (min. 1 day) * @param _rewardTokenAddresses addresses the reward tokens (must be ERC20) * @param _rewardsDuration reward emission duration * @param _depositFeeBps deposit fee in basis points * @param _withdrawalFeesBps aligned to fee schedule * @param _withdrawalFeeSchedule assumes a sorted array */ constructor( address _oracleAddress, address _lpTokenAddress, address _coverageTokenAddress, uint256 _coverageAmount, uint32 _coverageVestingDuration, address[] memory _rewardTokenAddresses, uint256 _rewardsDuration, uint16 _depositFeeBps, uint16[] memory _withdrawalFeesBps, uint32[] memory _withdrawalFeeSchedule ) StakingRewards( _lpTokenAddress, _rewardTokenAddresses, _rewardsDuration, _depositFeeBps, _withdrawalFeesBps, _withdrawalFeeSchedule ) { oracle = IElkDexOracle(_oracleAddress); lpToken = IElkPair(_lpTokenAddress); if (_coverageTokenAddress != address(0)) { require( lpToken.token0() == _coverageTokenAddress || lpToken.token1() == _coverageTokenAddress, "E19" ); require( _coverageVestingDuration >= 24 * 3600 && _coverageVestingDuration <= rewardsDuration, "E21" ); } require( lpToken.factory() == oracle.factory(), "E20" ); coverageTokenAddress = _coverageTokenAddress; coverageAmount = _coverageAmount; coverageVestingDuration = _coverageVestingDuration; } // Optimized version below /*function coveragePerToken() public view returns (uint256) { if (totalSupply == 0) { return coveragePerTokenStored; } return // does this work for non 18 dec tokens? rate = _coverage / rewardsDuration, here rate is converted back to 18 dec coveragePerTokenStored + ((lastTimeRewardApplicable() - lastUpdateTime) * coverageRate * 1e18) / totalSupply; }*/ /** * @dev Return the coverage per staked token (in coverage token amounts) * @return amount of coverage per staked token */ function coveragePerToken() public view returns (uint256) { return totalSupply == 0 ? coveragePerTokenStored : coveragePerTokenStored + (((lastTimeRewardApplicable() - lastUpdateTime) * coverageRate * 1e18) / totalSupply); } // Code below optimizes this version of the function /*function coverageEarned(address _account) public view returns(uint256) { if (coverageTokenAddress == address(0)) { return 0; } uint256 hodlValue = lpValueWeth(lastStakedPosition[_account]); if (hodlValue == 0) { // prevent division by zero below // equivalent check would be lastStakedPosition[_account].blockTimestamp > 0 return coverage[_account]; } uint256 outValue = lpValueWeth(position(balances[_account])); uint256 cappedCoverage = (balances[_account] * (coveragePerToken() - userCoveragePerTokenPaid[_account])) / 1e18; uint256 vested = vestedCoverage( hodlValue, outValue, lastStakedPosition[_account].blockTimestamp ); if (vested > cappedCoverage) { vested = cappedCoverage; } // amount * (hodl value - out value) / hodl value = amount * (1 - (out value / hodl value)) return (vested - (vested * outValue) / hodlValue) + coverage[_account]; }*/ /** * @dev Return the total coverage earned by a user. * @param _account user wallet address * @return coverage amount earned */ function coverageEarned(address _account) public view returns(uint256) { if (coverageTokenAddress == address(0)) { return 0; } Position memory lastStake = lastStakedPosition[_account]; uint256 hodlValue = lpValueWeth(lastStake); if (hodlValue == 0) { return coverage[_account]; } uint256 outValue = lpValueWeth(position(balances[_account])); uint256 balance = balances[_account]; uint256 cappedCoverage = (balance * (coveragePerToken() - userCoveragePerTokenPaid[_account])) / 1e18; uint256 vested = vestedCoverage(hodlValue, outValue, lastStake.blockTimestamp); return (vested > cappedCoverage ? cappedCoverage : vested) - (vested * outValue) / hodlValue + coverage[_account]; } /* ========== MUTATIVE FUNCTIONS ========== */ // Optimized version of this below /* function getCoverage( address _recipient ) public nonReentrant updateCoverage(_recipient) { require( msg.sender == owner() || msg.sender == _recipient, "E14" ); require(coverageTokenAddress != address(0), "E23"); uint256 cov = coverage[_recipient]; if (cov > 0) { coverage[_recipient] = 0; IERC20(coverageTokenAddress).safeTransfer(_recipient, cov); emit CoveragePaid(_recipient, cov); } } */ /** * @dev claim the coverage for a staker * @param _recipient the address of the staker that should receive the coverage * @ return the amount of reward received */ function getCoverage(address _recipient) public nonReentrant updateCoverage(_recipient) { require(msg.sender == owner() || msg.sender == _recipient, "E14"); require(coverageTokenAddress != address(0), "E23"); uint256 cov = coverage[_recipient]; if (cov == 0) return; coverage[_recipient] = 0; IERC20(coverageTokenAddress).safeTransfer(_recipient, cov); emit CoveragePaid(_recipient, cov); } /** * @dev Set the coverage parameters if none were set in the constructor. Gives the option for farm owners to change coverage tokens. * Note: Can't change coverage token if coverage is already accumulated * @param _tokenAddress address of token to be used for coverage emissions * @param _coverageAmount total amount of coverage token to emit * @param _coverageVestingDuration vesting period in seconds that users need to have staked to claim coverage */ function setCoverage(address _tokenAddress, uint256 _coverageAmount, uint32 _coverageVestingDuration) external onlyOwner whenNotEmitting { require(coveragePerTokenStored == 0, "E24"); require( (lpToken.token0() == _tokenAddress || lpToken.token1() == _tokenAddress) && (_coverageVestingDuration >= 24 * 3600) && (_coverageVestingDuration <= rewardsDuration), "E19" ); coverageTokenAddress = _tokenAddress; coverageAmount = _coverageAmount; coverageVestingDuration = _coverageVestingDuration; } // Override startEmission() so it calls the expanded function that includes the coverage amount /** * @dev Start the emission of rewards to stakers with no coverage. The owner must send reward tokens to the contract before calling this function. * Note: Can only be called by owner when the contract is not emitting rewards. * @param _rewards array of rewards amounts for each reward token * @param _duration duration in seconds for which rewards will be emitted */ function startEmission( uint256[] memory _rewards, uint256 _duration ) public override(StakingRewards, IStakingRewards) onlyOwner { return startEmission(_rewards, 0, _duration); } /** * @dev Start the emission of rewards to stakers. The owner must send reward and coverage tokens to the contract before calling this function. * Note: Can only be called by owner when the contract is not emitting rewards. * @param _rewards array of rewards amounts for each reward token * @param _coverage total amount of coverage provided to users (worst case max) * @param _duration duration in seconds for which rewards will be emitted (and coverage will be active) */ function startEmission( uint256[] memory _rewards, uint256 _coverage, uint256 _duration ) public onlyOwner updateCoverage(address(0)) { super.startEmission(_rewards, _duration); require( coverageVestingDuration <= rewardsDuration, "E22" ); // must check again coverageRate = _coverage / rewardsDuration; // rewardsDuration, not coverageVestingDuration which can be shorter! if (coverageTokenAddress != address(0) && _coverage > 0) { // Ensure the provided coverage amount is not more than the balance in the contract uint256 balance = IERC20(coverageTokenAddress).balanceOf( address(this) ); int8 tokenIndex = rewardTokenIndex(coverageTokenAddress); if (tokenIndex >= 0) { balance -= _rewards[uint256(int256(tokenIndex))]; } require( coverageRate <= balance / rewardsDuration, "E3" ); } } /** * @dev recover leftover coverage tokens and transfer them to a specified recipient * Note: can only be called by owner when the contract is not emitting rewards * @param _recipient address to receive the recovered coverage tokens */ function recoverLeftoverCoverage(address _recipient) public onlyOwner whenNotEmitting { require(totalSupply == 0 && coverageTokenAddress != address(0), "E12/E23"); _beforeRecoverLeftoverCoverage(_recipient); IERC20 token = IERC20(coverageTokenAddress); uint256 amount = token.balanceOf(address(this)); if (amount > 0) { token.safeTransfer(_recipient, amount); emit LeftoverCoverageRecovered(_recipient, amount); } } /* ========== PRIVATE FUNCTIONS ========== */ /** * @dev Return the LP position for a given amount of LP token. * @param _amount the amount of LP token * @return the corresponding LP position (amount0, amount1, timestamp) */ function position(uint256 _amount) private view returns (Position memory) { (uint112 reserve0, uint112 reserve1, uint32 timestamp) = lpToken.getReserves(); uint256 totalAmount = lpToken.totalSupply(); return Position(uint112((_amount * reserve0) / totalAmount), uint112((_amount * reserve1) / totalAmount), timestamp); } /** * @dev Return the value in WETH of the given LP position. * @param _position LP position * @return the value in WETH */ function lpValueWeth( Position memory _position ) private view returns (uint256) { return oracle.consultWeth(lpToken.token0(), _position.amount0) + oracle.consultWeth(lpToken.token1(), _position.amount1); } /** * @dev Return the vested coverage in coverage token amount for the given HODL and OUT values since the provided timestamp. * @param _hodlValue the value (in WETH) if the tokens making up the LP were kept unpaired * @param _outValue the value (in WETH) of the LP token position * @param _lastTimestamp the start timestamp (when the LP token position was created) * @return vested coverage in coverage token amount */ function vestedCoverage( uint256 _hodlValue, uint256 _outValue, uint32 _lastTimestamp ) private view returns (uint256) { uint256 timeElapsed = block.timestamp - _lastTimestamp; uint256 wethCov = _hodlValue > _outValue ? _hodlValue - _outValue : 0; uint256 tokenCoverage = wethCov == 0 ? 0 : oracle.consult(oracle.weth(), wethCov, coverageTokenAddress); if (timeElapsed >= coverageVestingDuration) { return tokenCoverage; } return (tokenCoverage * timeElapsed) / coverageVestingDuration; } /* ========== HOOKS ========== */ /** * @dev Override _beforeStake() hook to ensure staking updates the coverage */ function _beforeStake( address _account, uint256 _amount ) internal virtual override updateCoverage(_account) returns (uint256) { return super._beforeStake(_account, _amount); } /** * @dev Override _beforeWithdraw() hook to ensure withdrawing updates the coverage */ function _beforeWithdraw( address _account, uint256 _amount ) internal virtual override updateCoverage(_account) returns (uint256) { return super._beforeWithdraw(_account, _amount); } /** * @dev Override _beforeExit() hook to claim all coverage for the account exiting */ function _beforeExit(address _account) internal virtual override { if (coverageTokenAddress != address(0)) { getCoverage(_account); } super._beforeExit(_account); } /** * @dev Override _beforeRecoverERC20() hook to prevent recovery of a coverage token */ function _beforeRecoverERC20( address _tokenAddress, address _recipient, uint256 _amount ) internal virtual override { require( _tokenAddress != coverageTokenAddress, "E16" ); super._beforeRecoverERC20(_tokenAddress, _recipient, _amount); } // New hooks /** * @dev Internal hook called before recovering leftover coverage (in the recoverLeftoverCoverage() function). * @param _recipient address to recover the leftover coverage to */ function _beforeRecoverLeftoverCoverage( address _recipient ) internal virtual {} /* ========== MODIFIERS ========== */ /** * @dev Modifier to update the coverage of a given account. * @param _account account to update coverage for */ modifier updateCoverage(address _account) { if (coverageTokenAddress != address(0)) { coveragePerTokenStored = coveragePerToken(); lastUpdateTime = lastTimeRewardApplicable(); // it seems fine to redo this here oracle.update(lpToken.token0(), oracle.weth()); // update oracle for first token oracle.update(lpToken.token1(), oracle.weth()); // ditto for the second token if (_account != address(0)) { coverage[_account] = coverageEarned(_account); userCoveragePerTokenPaid[_account] = coveragePerTokenStored; lastStakedPosition[_account] = position(balances[_account]); // don't forget to reset the last position info } } _; } } // File: contracts/ElkFactoryHelper.sol // // Copyright (c) 2023 ElkLabs // License terms: https://github.com/elkfinance/faas/blob/main/LICENSE // // Authors: // - Seth <[email protected]> // - Baal <[email protected]> // - Elijah <[email protected]> // - Snake <[email protected]> pragma solidity >=0.8.0; /** * @title contains a helper function that creates new FarmingRewards contracts in the ElkFarmFactory * @notice this is a separate contract so that the FarmFactory contract is not too large */ library ElkFactoryHelper { /** * @notice creates a new FarmingRewards contract and transfers ownership to the provided farm manager * @param _abi the abi of the FarmingRewards contract * @param _salt the salt used to create the contract * @param _farmManager the address of the farm manager */ function createFarmContract( bytes memory _abi, bytes32 _salt, address _farmManager ) external returns (address addr) { bytes memory bytecode = abi.encodePacked( type(FarmingRewards).creationCode, _abi ); assembly { addr := create2(0, add(bytecode, 0x20), mload(bytecode), _salt) if iszero(extcodesize(addr)) { revert(0, 0) } } FarmingRewards(addr).transferOwnership(_farmManager); } }
Contract Creation Code
615e5d61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe7300000000000000000000000000000000000000003014608060405260043610620000375760003560e01c8063c82e8b95146200003c575b600080fd5b8180156200004957600080fd5b50620000616200005b366004620001e0565b6200008a565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b600080604051806020016200009f9062000179565b601f1982820381018352601f909101166040819052620000c591908790602001620002e9565b6040516020818303038152906040529050838151602083016000f59150813b620000ee57600080fd5b6040517ff2fde38b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff848116600483015283169063f2fde38b90602401600060405180830381600087803b1580156200015857600080fd5b505af11580156200016d573d6000803e3d6000fd5b50505050509392505050565b615b1d806200030b83390190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b803573ffffffffffffffffffffffffffffffffffffffff81168114620001db57600080fd5b919050565b600080600060608486031215620001f657600080fd5b833567ffffffffffffffff808211156200020f57600080fd5b818601915086601f8301126200022457600080fd5b81358181111562000239576200023962000187565b604051601f8201601f19908116603f0116810190838211818310171562000264576200026462000187565b816040528281528960208487010111156200027e57600080fd5b82602086016020830137600060208483010152809750505050505060208401359150620002ae60408501620001b6565b90509250925092565b6000815160005b81811015620002da5760208185018101518683015201620002be565b50600093019283525090919050565b600062000302620002fb8386620002b7565b84620002b7565b94935050505056fe60e06040523480156200001157600080fd5b5060405162005b1d38038062005b1d833981016040819052620000349162000b00565b600160005588858585858585838383836200004f336200043b565b6001600160a01b038116620000905760405162461bcd60e51b8152602060048201526002602482015261453160f01b60448201526064015b60405180910390fd5b6001600160a01b0316608052620000a98383836200048d565b505050506000855111620000e55760405162461bcd60e51b8152602060048201526002602482015261453960f01b604482015260640162000087565b60005b85518110156200013857600086828151811062000109576200010962000c05565b602002602001015190506200012481620006a060201b60201c565b50620001308162000c31565b9050620000e8565b505050600c919091555050506001600160a01b03808b1660a05289811660c052881615620002e857876001600160a01b031660c0516001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015620001ab573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001d1919062000c4d565b6001600160a01b031614806200025e5750876001600160a01b031660c0516001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200022d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000253919062000c4d565b6001600160a01b0316145b620002925760405162461bcd60e51b815260206004820152600360248201526245313960e81b604482015260640162000087565b620151808663ffffffff1610158015620002b45750600c548663ffffffff1611155b620002e85760405162461bcd60e51b815260206004820152600360248201526245323160e81b604482015260640162000087565b60a0516001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000329573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200034f919062000c4d565b6001600160a01b031660c0516001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000399573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003bf919062000c4d565b6001600160a01b031614620003fd5760405162461bcd60e51b815260206004820152600360248201526204532360ec1b604482015260640162000087565b5050601280546001600160a01b0319166001600160a01b039790971696909617909555505060139190915563ffffffff166014555062000d26915050565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b62000497620007a0565b620004a1620007fe565b81518151148015620004b55750600a815111155b8015620004c857506107d08361ffff1611155b620004fb5760405162461bcd60e51b8152602060048201526002602482015261453560f01b604482015260640162000087565b6000806200050d6107d0600162000c72565b905060005b835181101562000626578263ffffffff1684828151811062000538576200053862000c05565b602002602001015163ffffffff16116200057a5760405162461bcd60e51b8152602060048201526002602482015261453760f01b604482015260640162000087565b8185828151811062000590576200059062000c05565b602002602001015161ffff1610620005d05760405162461bcd60e51b815260206004820152600260248201526108a760f31b604482015260640162000087565b838181518110620005e557620005e562000c05565b6020026020010151925084818151811062000604576200060462000c05565b602002602001015161ffff169150806200061e9062000c31565b905062000512565b5082516200063c90600490602086019062000847565b508351620006529060059060208701906200089f565b5061ffff85166006556040517fab4c36b25b04e6f8ac9915203aba1048c17841782324a583e98128b8c1c964f390620006919087908790879062000c8e565b60405180910390a15050505050565b600954600f1015620006db5760405162461bcd60e51b815260206004820152600360248201526245313560e81b604482015260640162000087565b6001600160a01b038116620007185760405162461bcd60e51b8152602060048201526002602482015261453160f01b604482015260640162000087565b6001600160a01b0381166000908152600a602052604090205460ff166200079d576009805460018082019092557f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0180546001600160a01b0319166001600160a01b0384169081179091556000908152600a60205260409020805460ff191690911790555b50565b6001546001600160a01b03163314620007fc5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640162000087565b565b600b544211620008375760405162461bcd60e51b815260206004820152600360248201526245313760e81b604482015260640162000087565b620007fc6001600160e01b038116565b8280548282559060005260206000209081019282156200088d579160200282015b828111156200088d578251829063ffffffff1690559160200191906001019062000868565b506200089b929150620008e3565b5090565b8280548282559060005260206000209081019282156200088d579160200282015b828111156200088d578251829061ffff16905591602001919060010190620008c0565b5b808211156200089b5760008155600101620008e4565b80516001600160a01b03811681146200091257600080fd5b919050565b805163ffffffff811681146200091257600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156200096d576200096d6200092c565b604052919050565b60006001600160401b038211156200099157620009916200092c565b5060051b60200190565b600082601f830112620009ad57600080fd5b81516020620009c6620009c08362000975565b62000942565b82815260059290921b84018101918181019086841115620009e657600080fd5b8286015b8481101562000a0c57620009fe81620008fa565b8352918301918301620009ea565b509695505050505050565b805161ffff811681146200091257600080fd5b600082601f83011262000a3c57600080fd5b8151602062000a4f620009c08362000975565b82815260059290921b8401810191818101908684111562000a6f57600080fd5b8286015b8481101562000a0c5762000a878162000a17565b835291830191830162000a73565b600082601f83011262000aa757600080fd5b8151602062000aba620009c08362000975565b82815260059290921b8401810191818101908684111562000ada57600080fd5b8286015b8481101562000a0c5762000af28162000917565b835291830191830162000ade565b6000806000806000806000806000806101408b8d03121562000b2157600080fd5b62000b2c8b620008fa565b995062000b3c60208c01620008fa565b985062000b4c60408c01620008fa565b975060608b0151965062000b6360808c0162000917565b60a08c01519096506001600160401b038082111562000b8157600080fd5b62000b8f8e838f016200099b565b965060c08d0151955062000ba660e08e0162000a17565b94506101008d015191508082111562000bbe57600080fd5b62000bcc8e838f0162000a2a565b93506101208d015191508082111562000be457600080fd5b5062000bf38d828e0162000a95565b9150509295989b9194979a5092959850565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820162000c465762000c4662000c1b565b5060010190565b60006020828403121562000c6057600080fd5b62000c6b82620008fa565b9392505050565b8082018082111562000c885762000c8862000c1b565b92915050565b60006060820161ffff80871684526020606081860152828751808552608087019150828901945060005b8181101562000cd857855185168352948301949183019160010162000cb8565b5050858103604087015286518082529082019350915080860160005b8381101562000d1857815163ffffffff168552938201939082019060010162000cf4565b509298975050505050505050565b60805160a05160c051614cb662000e676000396000818161052b015281816115de0152818161167a015281816119cb01528181611b5e01528181611f80015281816121130152818161290101528181612a2d01528181612b5301528181612bdd0152818161319a0152818161332d015281816137c8015261395b0152600081816106510152818161199c01528181611a4d01528181611b2f01528181611be001528181611f5101528181612002015281816120e401528181612195015281816128d2015281816129fe01528181612d1601528181612d450152818161316b0152818161321c015281816132fe015281816133af015281816137990152818161384a0152818161392c01526139dd0152600081816105df01528181610a3901528181610ce80152818161180f0152818161190b0152613ead0152614cb66000f3fe608060405234801561001057600080fd5b50600436106103785760003560e01c80637aaeaf7f116101d3578063ab87982711610104578063ebe2b12b116100a2578063f2d176391161007c578063f2d176391461084f578063f2fde38b14610862578063f9cb1d0414610875578063f9ea07781461087e57600080fd5b8063ebe2b12b146107c3578063ef2849b3146107cc578063f12297771461083c57600080fd5b8063ca423031116100de578063ca4230311461076a578063e13d87221461077d578063e70b9e2714610790578063e9fad8ee146107bb57600080fd5b8063ab87982714610745578063ad3bc5461461074e578063c8f33c911461076157600080fd5b80638da5cb5b116101715780639ce43f901161014b5780639ce43f90146106c45780639e3582c8146106e4578063a694fc3a146106f7578063a7309d7d1461070a57600080fd5b80638da5cb5b146106a15780639003adfe146106b257806399d531e1146106bb57600080fd5b80637dc0d1d0116101ad5780637dc0d1d01461064c57806380faa57d146106735780638194c1781461067b57806387e7ed3a1461068e57600080fd5b80637aaeaf7f1461061d5780637bb7bed1146106305780637beb3d9f1461064357600080fd5b8063423c485a116102ad5780636b0916951161024b578063715018a611610225578063715018a6146105d257806372f702f3146105da578063757767d71461060157806379ee54f71461060a57600080fd5b80636b091695146105815780636da9c58e146105945780637035ab98146105a757600080fd5b806354feec3e1161028757806354feec3e146105135780635fcbd2851461052657806367c0d00f1461056557806369d1bdea1461056e57600080fd5b8063423c485a146104d8578063486e63b1146104eb578063502cd30f146104f357600080fd5b806327e235e31161031a57806333024430116102f45780633302443014610469578063386a9525146104895780633d3b260314610492578063415be3b5146104b257600080fd5b806327e235e3146104235780632e1a7d4d146104435780632e9f06021461045657600080fd5b806318160ddd1161035657806318160ddd146103c15780631c03e6cc146103ca5780631db7efd8146103dd578063211dc32d1461041057600080fd5b806301f59d161461037d57806304a79e48146103995780631171bda9146103ac575b600080fd5b6103866107d081565b6040519081526020015b60405180910390f35b6103866103a7366004614601565b610891565b6103bf6103ba36600461461e565b610a27565b005b61038660025481565b6103bf6103d8366004614601565b610b3a565b6104006103eb366004614601565b600a6020526000908152604090205460ff1681565b6040519015158152602001610390565b61038661041e36600461465f565b610b85565b610386610431366004614601565b60036020526000908152604090205481565b6103bf610451366004614698565b610c1f565b6103bf610464366004614787565b610d50565b610386610477366004614601565b60186020526000908152604090205481565b610386600c5481565b6103866104a0366004614601565b600e6020526000908152604090205481565b6104c56104c0366004614601565b610d68565b60405160009190910b8152602001610390565b6103866104e6366004614698565b610dee565b610386610e1b565b610386610501366004614601565b60176020526000908152604090205481565b610386610521366004614698565b610e81565b61054d7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610390565b61038660135481565b6103bf61057c366004614854565b610ea2565b6103bf61058f36600461465f565b6110e2565b6103bf6105a2366004614601565b6111d8565b6103866105b536600461465f565b601060209081526000928352604080842090915290825290205481565b6103bf6112fd565b61054d7f000000000000000000000000000000000000000000000000000000000000000081565b61038660145481565b6103bf610618366004614601565b611311565b61038661062b366004614926565b61144c565b61054d61063e366004614698565b611502565b61038661271081565b61054d7f000000000000000000000000000000000000000000000000000000000000000081565b61038661152c565b6103bf610689366004614952565b611543565b6103bf61069c366004614601565b6117b6565b6001546001600160a01b031661054d565b61038660075481565b61038660155481565b6103866106d2366004614601565b600f6020526000908152604090205481565b6103866106f2366004614698565b611841565b6103bf610705366004614698565b611851565b610730610718366004614601565b60086020526000908152604090205463ffffffff1681565b60405163ffffffff9091168152602001610390565b61038660065481565b6103bf61075c366004614994565b611965565b610386600d5481565b6103bf610778366004614601565b611f1b565b60125461054d906001600160a01b031681565b61038661079e36600461465f565b601160209081526000928352604080842090915290825290205481565b6103bf612481565b610386600b5481565b6108106107da366004614601565b6019602052600090815260409020546001600160701b0380821691600160701b810490911690600160e01b900463ffffffff1683565b604080516001600160701b03948516815293909216602084015263ffffffff1690820152606001610390565b61038661084a366004614601565b6124a3565b6103bf61085d36600461465f565b612545565b6103bf610870366004614601565b6126c7565b61038660165481565b6103bf61088c366004614601565b612754565b6012546000906001600160a01b03166108ac57506000919050565b6001600160a01b0382166000908152601960209081526040808320815160608101835290546001600160701b038082168352600160701b82041693820193909352600160e01b90920463ffffffff169082015290610909826128ce565b905080600003610931575050506001600160a01b031660009081526018602052604090205490565b6001600160a01b03841660009081526003602052604081205461095c9061095790612b2f565b6128ce565b6001600160a01b038616600090815260036020908152604080832054601790925282205492935091670de0b6b3a764000090610996610e1b565b6109a091906149f8565b6109aa9084614a0b565b6109b49190614a22565b905060006109c785858860400151612cdb565b6001600160a01b038916600090815260186020526040902054909150856109ee8684614a0b565b6109f89190614a22565b838311610a055782610a07565b835b610a1191906149f8565b610a1b9190614a44565b98975050505050505050565b610a2f612e7f565b610a37612ed8565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b031603610abd5760405162461bcd60e51b815260206004820152600260248201527f453400000000000000000000000000000000000000000000000000000000000060448201526064015b60405180910390fd5b610ac8838383612f32565b82610add6001600160a01b0382168484612f81565b826001600160a01b0316846001600160a01b03167ffff3b3844276f57024e0b42afec1a37f75db36511e43819a4f2a63ab7862b64884604051610b2291815260200190565b60405180910390a350610b356001600055565b505050565b610b42612ed8565b600b544211610b795760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ab4565b610b8281612ffd565b50565b6001600160a01b038083166000818152601160209081526040808320948616808452948252808320549383526010825280832094835293905291822054670de0b6b3a764000090610bd5866124a3565b610bdf91906149f8565b6001600160a01b038516600090815260036020526040902054610c029190614a0b565b610c0c9190614a22565b610c169190614a44565b90505b92915050565b610c27612e7f565b80610c32338261313a565b9150600082118015610c535750336000908152600360205260409020548211155b8015610c6e5750336000908152600360205260409020548111155b610c9f5760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ab4565b8060026000828254610cb191906149f8565b90915550503360009081526003602052604081208054839290610cd59084906149f8565b90915550610d0f90506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163384612f81565b60405182815233907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5906020015b60405180910390a250610b826001600055565b610d58612ed8565b610d6482600083611965565b5050565b6001600160a01b0381166000908152600a602052604081205460ff1615610de55760005b600954811015610de357826001600160a01b031660098281548110610db357610db3614a57565b6000918252602090912001546001600160a01b031603610dd35792915050565b610ddc81614a6d565b9050610d8c565b505b50600019919050565b60008060065411610e00576000610c19565b61271060065483610e119190614a0b565b610c199190614a22565b6000600254600014610e7a57600254601554600d54610e3861152c565b610e4291906149f8565b610e4c9190614a0b565b610e5e90670de0b6b3a7640000614a0b565b610e689190614a22565b601654610e759190614a44565b905090565b5060165490565b60048181548110610e9157600080fd5b600091825260209091200154905081565b610eaa612ed8565b610eb2613563565b81518151148015610ec55750600a815111155b8015610ed757506107d08361ffff1611155b610f235760405162461bcd60e51b815260206004820152600260248201527f45350000000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b600080610f336107d06001614a44565b905060005b835181101561106e578263ffffffff16848281518110610f5a57610f5a614a57565b602002602001015163ffffffff1611610fb55760405162461bcd60e51b815260206004820152600260248201527f45370000000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b81858281518110610fc857610fc8614a57565b602002602001015161ffff16106110215760405162461bcd60e51b815260206004820152600260248201527f45380000000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b83818151811061103357611033614a57565b6020026020010151925084818151811061104f5761104f614a57565b602002602001015161ffff1691508061106790614a6d565b9050610f38565b508251611082906004906020860190614543565b508351611096906005906020870190614596565b5061ffff85166006556040517fab4c36b25b04e6f8ac9915203aba1048c17841782324a583e98128b8c1c964f3906110d390879087908790614a86565b60405180910390a15050505050565b6110ea612e7f565b8060005b6009548110156111b75760006009828154811061110d5761110d614a57565b6000918252602090912001546001600160a01b0316905061112d816124a3565b6001600160a01b038083166000908152600f60205260409020919091558316156111a65761115b8184610b85565b6001600160a01b03808316600081815260116020908152604080832094891680845294825280832095909555918152600f825283812054601083528482209382529290915291909120555b506111b081614a6d565b90506110ee565b506111c061152c565b600d556111cd838361359a565b50610d646001600055565b6111e0612e7f565b6111e8612ed8565b600b544211156112205760405162461bcd60e51b815260206004820152600360248201526208a62760eb1b6044820152606401610ab4565b600042600b54111561123d5742600b5461123a91906149f8565b90505b42600b5560005b6009548110156112c85760006009828154811061126357611263614a57565b60009182526020808320909101546001600160a01b0316808352600e9091526040822054909250829190611298908690614a0b565b905080156112b4576112b46001600160a01b0384168783612f81565b505050806112c190614a6d565b9050611244565b506040517f9bad5e1e43bc35e89725967a54f4bc384078248a1ea5c315be3b260a68cbb17a90600090a150610b826001600055565b611305612ed8565b61130f6000613709565b565b611319612e7f565b8060005b6009548110156113e65760006009828154811061133c5761133c614a57565b6000918252602090912001546001600160a01b0316905061135c816124a3565b6001600160a01b038083166000908152600f60205260409020919091558316156113d55761138a8184610b85565b6001600160a01b03808316600081815260116020908152604080832094891680845294825280832095909555918152600f825283812054601083528482209382529290915291909120555b506113df81614a6d565b905061131d565b506113ef61152c565b600d5560005b600954811015611440576114306009828154811061141557611415614a57565b6000918252602090912001546001600160a01b03168461359a565b61143981614a6d565b90506113f5565b5050610b826001600055565b6001600160a01b03821660009081526008602052604081205481906114779063ffffffff16426149f8565b90506000805b6004548110156114f9576004818154811061149a5761149a614a57565b90600052602060002001548310156114e957612710600582815481106114c2576114c2614a57565b9060005260206000200154866114d89190614a0b565b6114e29190614a22565b91506114f9565b6114f281614a6d565b905061147d565b50949350505050565b6009818154811061151257600080fd5b6000918252602090912001546001600160a01b0316905081565b6000600b54421061153e5750600b5490565b504290565b61154b612ed8565b600b5442116115825760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ab4565b601654156115d25760405162461bcd60e51b815260206004820152600360248201527f45323400000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b826001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa15801561163a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061165e9190614b1a565b6001600160a01b031614806117055750826001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156116d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116fa9190614b1a565b6001600160a01b0316145b801561171a5750620151808163ffffffff1610155b801561172e5750600c548163ffffffff1611155b61177a5760405162461bcd60e51b815260206004820152600360248201527f45313900000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b6012805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b03949094169390931790925560135563ffffffff16601455565b6117be612ed8565b6117c6612e7f565b6007805460009091556040518181527f6857c770f3cb43e9c19050a37dd914ec876241c1f4b487d26a1d4f5d3054f49b9060200160405180910390a16118366001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168383612f81565b50610b826001600055565b60058181548110610e9157600080fd5b611859612e7f565b806118643382613768565b91506000821180156118765750600081115b6118c25760405162461bcd60e51b815260206004820152600260248201527f45320000000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b81600260008282546118d49190614a44565b909155505033600090815260036020526040812080548492906118f8908490614a44565b9091555061193390506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333084613b89565b60405182815233907f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d90602001610d3d565b61196d612ed8565b6012546000906001600160a01b031615611d8257611989610e1b565b60165561199461152c565b600d819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a4b9190614b1a565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611aa9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611acd9190614b1a565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015611b1557600080fd5b505af1158015611b29573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611bba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bde9190614b1a565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c3c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c609190614b1a565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015611ca857600080fd5b505af1158015611cbc573d6000803e3d6000fd5b505050506001600160a01b03811615611d8257611cd881610891565b6001600160a01b0382166000908152601860209081526040808320939093556016546017825283832055600390522054611d1190612b2f565b6001600160a01b0382166000908152601960209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b611d8c8483613bda565b600c546014541115611de05760405162461bcd60e51b815260206004820152600360248201527f45323200000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b600c54611ded9084614a22565b6015556012546001600160a01b031615801590611e0a5750600083115b15611f15576012546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015611e58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7c9190614b37565b601254909150600090611e97906001600160a01b0316610d68565b905060008160000b12611ecf57858160000b81518110611eb957611eb9614a57565b602002602001015182611ecc91906149f8565b91505b600c54611edc9083614a22565b6015541115611f125760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ab4565b50505b50505050565b611f23612e7f565b60125481906001600160a01b03161561233757611f3e610e1b565b601655611f4961152c565b600d819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611fdc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120009190614b1a565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa15801561205e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120829190614b1a565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b1580156120ca57600080fd5b505af11580156120de573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561216f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121939190614b1a565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122159190614b1a565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b15801561225d57600080fd5b505af1158015612271573d6000803e3d6000fd5b505050506001600160a01b038116156123375761228d81610891565b6001600160a01b03821660009081526018602090815260408083209390935560165460178252838320556003905220546122c690612b2f565b6001600160a01b0382166000908152601960209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b6001546001600160a01b03163314806123585750336001600160a01b038316145b61238a5760405162461bcd60e51b8152602060048201526003602482015262114c4d60ea1b6044820152606401610ab4565b6012546001600160a01b03166123e25760405162461bcd60e51b815260206004820152600360248201527f45323300000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b6001600160a01b038216600090815260186020526040812054908190036124095750611836565b6001600160a01b0380841660009081526018602052604081205560125461243291168483612f81565b826001600160a01b03167fef4696bdcf47e292773442e4169d670e1b2d0d3f5ceff2a5c1e236c10109ee808260405161246d91815260200190565b60405180910390a25050610b826001600055565b61248a33614017565b3360009081526003602052604090205461130f90610c1f565b60006002546000036124cb57506001600160a01b03166000908152600f602052604090205490565b6002546001600160a01b0383166000908152600e6020526040902054600d546124f261152c565b6124fc91906149f8565b6125069190614a0b565b61251890670de0b6b3a7640000614a0b565b6125229190614a22565b6001600160a01b0383166000908152600f6020526040902054610c199190614a44565b61254d612ed8565b600b5442116125845760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ab4565b600254156125d45760405162461bcd60e51b815260206004820152600360248201527f45313200000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b6001600160a01b0382166000908152600a602052604090205460ff1615610d64576040516370a0823160e01b815230600482015282906000906001600160a01b038316906370a0823190602401602060405180830381865afa15801561263e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126629190614b37565b9050801561267e5761267e6001600160a01b0383168483612f81565b826001600160a01b03167fcaa95c7b01f93ffe197f5e7316a1a2f387c5bfff8cb445095f2110ff5c1b2995826040516126b991815260200190565b60405180910390a250505050565b6126cf612ed8565b6001600160a01b03811661274b5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610ab4565b610b8281613709565b61275c612ed8565b600b5442116127935760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ab4565b6002541580156127ad57506012546001600160a01b031615155b6127f95760405162461bcd60e51b815260206004820152600760248201527f4531322f453233000000000000000000000000000000000000000000000000006044820152606401610ab4565b6012546040516370a0823160e01b81523060048201526001600160a01b039091169060009082906370a0823190602401602060405180830381865afa158015612846573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061286a9190614b37565b90508015610b35576128866001600160a01b0383168483612f81565b826001600160a01b03167fcf018d466bd581a77eafe1429d5f079ea9a4a7363785b0561c51c9a8f2925c3c826040516128c191815260200190565b60405180910390a2505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316631421f7307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561295d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129819190614b1a565b60208501516040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526001600160701b03166024820152604401602060405180830381865afa1580156129d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129fc9190614b37565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316631421f7307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612aad9190614b1a565b855160405160e084901b6001600160e01b03191681526001600160a01b0390921660048301526001600160701b03166024820152604401602060405180830381865afa158015612b01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b259190614b37565b610c199190614a44565b604080516060810182526000808252602082018190529181019190915260008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015612baf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bd39190614b67565b92509250925060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c39573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c5d9190614b37565b9050604051806060016040528082866001600160701b031689612c809190614a0b565b612c8a9190614a22565b6001600160701b0316815260200182856001600160701b031689612cae9190614a0b565b612cb89190614a22565b6001600160701b031681526020018363ffffffff16815250945050505050919050565b600080612cee63ffffffff8416426149f8565b90506000848611612d00576000612d0a565b612d0a85876149f8565b905060008115612e43577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638c86f1e47f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015612da1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dc59190614b1a565b60125460405160e084901b6001600160e01b03191681526001600160a01b0392831660048201526024810187905291166044820152606401602060405180830381865afa158015612e1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e3e9190614b37565b612e46565b60005b90506014548310612e5b579250612e78915050565b601454612e688483614a0b565b612e729190614a22565b93505050505b9392505050565b600260005403612ed15760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610ab4565b6002600055565b6001546001600160a01b0316331461130f5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610ab4565b6012546001600160a01b0390811690841603612f765760405162461bcd60e51b815260206004820152600360248201526222989b60e91b6044820152606401610ab4565b610b3583838361403a565b6040516001600160a01b038316602482015260448101829052610b359084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614089565b600954600f10156130505760405162461bcd60e51b815260206004820152600360248201527f45313500000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b6001600160a01b0381166130a65760405162461bcd60e51b815260206004820152600260248201527f45310000000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b6001600160a01b0381166000908152600a602052604090205460ff16610b82576009805460018181019092557f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af0180546001600160a01b03841673ffffffffffffffffffffffffffffffffffffffff1990911681179091556000908152600a60205260409020805460ff1916909117905550565b60125460009083906001600160a01b03161561355157613158610e1b565b60165561316361152c565b600d819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156131f6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061321a9190614b1a565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613278573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061329c9190614b1a565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b1580156132e457600080fd5b505af11580156132f8573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015613389573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133ad9190614b1a565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa15801561340b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061342f9190614b1a565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b15801561347757600080fd5b505af115801561348b573d6000803e3d6000fd5b505050506001600160a01b03811615613551576134a781610891565b6001600160a01b03821660009081526018602090815260408083209390935560165460178252838320556003905220546134e090612b2f565b6001600160a01b0382166000908152601960209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b61355b848461416e565b949350505050565b600b54421161130f5760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ab4565b6001546001600160a01b03163314806135bb5750336001600160a01b038216145b6135ed5760405162461bcd60e51b8152602060048201526003602482015262114c4d60ea1b6044820152606401610ab4565b6001600160a01b0382166000908152600a602052604090205460ff166136555760405162461bcd60e51b815260206004820152600360248201527f45313300000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b6001600160a01b038083166000908152601160209081526040808320938516835292905220548015610b35576001600160a01b0380841660008181526011602090815260408083209487168352939052918220919091556136b7908383612f81565b816001600160a01b0316836001600160a01b03167f540798df468d7b23d11f156fdb954cb19ad414d150722a7b6d55ba369dea792e836040516136fc91815260200190565b60405180910390a3505050565b600180546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60125460009083906001600160a01b031615613b7f57613786610e1b565b60165561379161152c565b600d819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015613824573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138489190614b1a565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156138a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138ca9190614b1a565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b15801561391257600080fd5b505af1158015613926573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156139b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139db9190614b1a565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613a39573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a5d9190614b1a565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015613aa557600080fd5b505af1158015613ab9573d6000803e3d6000fd5b505050506001600160a01b03811615613b7f57613ad581610891565b6001600160a01b0382166000908152601860209081526040808320939093556016546017825283832055600390522054613b0e90612b2f565b6001600160a01b0382166000908152601960209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b61355b84846141ed565b6040516001600160a01b0380851660248301528316604482015260648101829052611f159085907f23b872dd0000000000000000000000000000000000000000000000000000000090608401612fc6565b613be2612e7f565b613bea612ed8565b600b544211613c215760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ab4565b6000805b600954811015613cee57600060098281548110613c4457613c44614a57565b6000918252602090912001546001600160a01b03169050613c64816124a3565b6001600160a01b038083166000908152600f6020526040902091909155831615613cdd57613c928184610b85565b6001600160a01b03808316600081815260116020908152604080832094891680845294825280832095909555918152600f825283812054601083528482209382529290915291909120555b50613ce781614a6d565b9050613c25565b50613cf761152c565b600d5581613d475760405162461bcd60e51b815260206004820152600360248201527f45313000000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b600954835114613d995760405162461bcd60e51b815260206004820152600360248201527f45313100000000000000000000000000000000000000000000000000000000006044820152606401610ab4565b600c82905560005b600954811015613fbc57600060098281548110613dc057613dc0614a57565b600091825260209091200154600c5486516001600160a01b0390921692508291879085908110613df257613df2614a57565b6020026020010151613e049190614a22565b6001600160a01b0382166000908152600e60205260408120919091556009805485908110613e3457613e34614a57565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015613e85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ea99190614b37565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b031614613f4257600c54613ef19082614a22565b6001600160a01b0383166000908152600e60205260409020541115613f3d5760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ab4565b613fa8565b600c54600254613f5290836149f8565b613f5c9190614a22565b6001600160a01b0383166000908152600e60205260409020541115613fa85760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ab4565b50505080613fb590614a6d565b9050613da1565b5042600d819055600c54613fcf91614a44565b600b556040517faab1f55dce0d0e628e283ce1061d0afccffcf61f9c14391c899b5952492ce821906140049085908590614ba3565b60405180910390a150610d646001600055565b6012546001600160a01b0316156140315761403181611f1b565b610b828161430a565b6001600160a01b0383166000908152600a602052604090205460ff1615610b355760405162461bcd60e51b815260206004820152600360248201526222989b60e91b6044820152606401610ab4565b60006140de826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166143139092919063ffffffff16565b805190915015610b3557808060200190518101906140fc9190614beb565b610b355760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610ab4565b60008061417b848461144c565b905080156141da5780600760008282546141959190614a44565b90915550506040518181526001600160a01b038516907fd0b34aaed5c558a8df736a5aaf9a49b539c4e86fb3ee5a1ac76e0bec23cbdd03906020015b60405180910390a25b61355b846141e883866149f8565b919050565b6000600b544211156142275760405162461bcd60e51b815260206004820152600360248201526208a62760eb1b6044820152606401610ab4565b8260005b6009548110156142f45760006009828154811061424a5761424a614a57565b6000918252602090912001546001600160a01b0316905061426a816124a3565b6001600160a01b038083166000908152600f60205260409020919091558316156142e3576142988184610b85565b6001600160a01b03808316600081815260116020908152604080832094891680845294825280832095909555918152600f825283812054601083528482209382529290915291909120555b506142ed81614a6d565b905061422b565b506142fd61152c565b600d5561355b8484614322565b610b8281611311565b606061355b84846000856143b3565b60008061432e83610dee565b6001600160a01b0385166000908152600860205260409020805463ffffffff19164263ffffffff16179055905080156141da5780600760008282546143739190614a44565b90915550506040518181526001600160a01b038516907f34f2a7363b1ef64b0b62a223c88cf3f54a68686acfcb9531d7deb46004f37c46906020016141d1565b60608247101561442b5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610ab4565b600080866001600160a01b031685876040516144479190614c31565b60006040518083038185875af1925050503d8060008114614484576040519150601f19603f3d011682016040523d82523d6000602084013e614489565b606091505b509150915061449a878383876144a5565b979650505050505050565b6060831561451457825160000361450d576001600160a01b0385163b61450d5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610ab4565b508161355b565b61355b83838151156145295781518083602001fd5b8060405162461bcd60e51b8152600401610ab49190614c4d565b828054828255906000526020600020908101928215614586579160200282015b82811115614586578251829063ffffffff16905591602001919060010190614563565b506145929291506145d7565b5090565b828054828255906000526020600020908101928215614586579160200282015b82811115614586578251829061ffff169055916020019190600101906145b6565b5b8082111561459257600081556001016145d8565b6001600160a01b0381168114610b8257600080fd5b60006020828403121561461357600080fd5b8135612e78816145ec565b60008060006060848603121561463357600080fd5b833561463e816145ec565b9250602084013561464e816145ec565b929592945050506040919091013590565b6000806040838503121561467257600080fd5b823561467d816145ec565b9150602083013561468d816145ec565b809150509250929050565b6000602082840312156146aa57600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156146f0576146f06146b1565b604052919050565b600067ffffffffffffffff821115614712576147126146b1565b5060051b60200190565b600082601f83011261472d57600080fd5b8135602061474261473d836146f8565b6146c7565b82815260059290921b8401810191818101908684111561476157600080fd5b8286015b8481101561477c5780358352918301918301614765565b509695505050505050565b6000806040838503121561479a57600080fd5b823567ffffffffffffffff8111156147b157600080fd5b6147bd8582860161471c565b95602094909401359450505050565b803561ffff811681146141e857600080fd5b63ffffffff81168114610b8257600080fd5b600082601f83011261480157600080fd5b8135602061481161473d836146f8565b82815260059290921b8401810191818101908684111561483057600080fd5b8286015b8481101561477c578035614847816147de565b8352918301918301614834565b60008060006060848603121561486957600080fd5b614872846147cc565b925060208085013567ffffffffffffffff8082111561489057600080fd5b818701915087601f8301126148a457600080fd5b81356148b261473d826146f8565b81815260059190911b8301840190848101908a8311156148d157600080fd5b938501935b828510156148f6576148e7856147cc565b825293850193908501906148d6565b96505050604087013592508083111561490e57600080fd5b505061491c868287016147f0565b9150509250925092565b6000806040838503121561493957600080fd5b8235614944816145ec565b946020939093013593505050565b60008060006060848603121561496757600080fd5b8335614972816145ec565b9250602084013591506040840135614989816147de565b809150509250925092565b6000806000606084860312156149a957600080fd5b833567ffffffffffffffff8111156149c057600080fd5b6149cc8682870161471c565b9660208601359650604090950135949350505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610c1957610c196149e2565b8082028115828204841417610c1957610c196149e2565b600082614a3f57634e487b7160e01b600052601260045260246000fd5b500490565b80820180821115610c1957610c196149e2565b634e487b7160e01b600052603260045260246000fd5b600060018201614a7f57614a7f6149e2565b5060010190565b60006060820161ffff80871684526020606081860152828751808552608087019150828901945060005b81811015614ace578551851683529483019491830191600101614ab0565b5050858103604087015286518082529082019350915080860160005b83811015614b0c57815163ffffffff1685529382019390820190600101614aea565b509298975050505050505050565b600060208284031215614b2c57600080fd5b8151612e78816145ec565b600060208284031215614b4957600080fd5b5051919050565b80516001600160701b03811681146141e857600080fd5b600080600060608486031215614b7c57600080fd5b614b8584614b50565b9250614b9360208501614b50565b91506040840151614989816147de565b604080825283519082018190526000906020906060840190828701845b82811015614bdc57815184529284019290840190600101614bc0565b50505092019290925292915050565b600060208284031215614bfd57600080fd5b81518015158114612e7857600080fd5b60005b83811015614c28578181015183820152602001614c10565b50506000910152565b60008251614c43818460208701614c0d565b9190910192915050565b6020815260008251806020840152614c6c816040850160208701614c0d565b601f01601f1916919091016040019291505056fea2646970667358221220e51364630106c4df9447bbbbe828e21d0e937dcf945eae675da683f7f5b52c8d64736f6c63430008130033a264697066735822122068006590f32ecb3b6321de7a1ad30e15e0382e574596ab29a9387f730ba7d17864736f6c63430008130033
Deployed ByteCode Sourcemap
84537:888:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;84871:551;;;;;;;;;;-1:-1:-1;84871:551:0;;;;;:::i;:::-;;:::i;:::-;;;1666:42:1;1654:55;;;1636:74;;1624:2;1609:18;84871:551:0;;;;;;;;85007:12;85032:21;85087:33;;;;;;;;:::i;:::-;-1:-1:-1;;85087:33:0;;;;;;;;;;;;;;;;85056:94;;85087:33;85135:4;;85087:33;85056:94;;:::i;:::-;;;;;;;;;;;;;85032:118;;85244:5;85233:8;85227:15;85220:4;85210:8;85206:19;85203:1;85195:55;85187:63;;85286:4;85274:17;85264:75;;85322:1;85319;85312:12;85264:75;85362:52;;;;;:38;1654:55:1;;;85362:52:0;;;1636:74:1;85362:38:0;;;;;1609:18:1;;85362:52:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;85021:401;84871:551;;;;;:::o;-1:-1:-1:-;;;;;;;;:::o;14:184:1:-;66:77;63:1;56:88;163:4;160:1;153:15;187:4;184:1;177:15;203:196;271:20;;331:42;320:54;;310:65;;300:93;;389:1;386;379:12;300:93;203:196;;;:::o;404:1073::-;490:6;498;506;559:2;547:9;538:7;534:23;530:32;527:52;;;575:1;572;565:12;527:52;615:9;602:23;644:18;685:2;677:6;674:14;671:34;;;701:1;698;691:12;671:34;739:6;728:9;724:22;714:32;;784:7;777:4;773:2;769:13;765:27;755:55;;806:1;803;796:12;755:55;842:2;829:16;864:2;860;857:10;854:36;;;870:18;;:::i;:::-;945:2;939:9;913:2;999:13;;-1:-1:-1;;995:22:1;;;1019:2;991:31;987:40;975:53;;;1043:18;;;1063:22;;;1040:46;1037:72;;;1089:18;;:::i;:::-;1129:10;1125:2;1118:22;1164:2;1156:6;1149:18;1206:7;1199:4;1194:2;1190;1186:11;1182:22;1179:35;1176:55;;;1227:1;1224;1217:12;1176:55;1287:2;1280:4;1276:2;1272:13;1265:4;1257:6;1253:17;1240:50;1334:1;1327:4;1322:2;1314:6;1310:15;1306:26;1299:37;1355:6;1345:16;;;;;;;1408:4;1397:9;1393:20;1380:34;1370:44;;1433:38;1467:2;1456:9;1452:18;1433:38;:::i;:::-;1423:48;;404:1073;;;;;:::o;1721:322::-;1762:3;1800:5;1794:12;1824:1;1834:128;1848:6;1845:1;1842:13;1834:128;;;1945:4;1930:13;;;1926:24;;1920:31;1907:11;;;1900:52;1863:12;1834:128;;;-1:-1:-1;2017:1:1;1981:16;;2006:13;;;-1:-1:-1;1981:16:1;;1721:322;-1:-1:-1;1721:322:1:o;2048:261::-;2223:3;2248:55;2273:29;2298:3;2290:6;2273:29;:::i;:::-;2265:6;2248:55;:::i;:::-;2241:62;2048:261;-1:-1:-1;;;;2048:261:1:o
Swarm Source
ipfs://68006590f32ecb3b6321de7a1ad30e15e0382e574596ab29a9387f730ba7d178
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|