Feature Tip: Add private address tag to any address under My Name Tag !
Overview
Max Total Supply
649,433,438.165933932136527132 FRAX
Holders
9,300 (0.00%)
Market
Price
$1.00 @ 0.000300 ETH (-0.08%)
Onchain Market Cap
$646,854,537.98
Circulating Supply Market Cap
$646,826,560.00
Other Info
Token Contract (WITH 18 Decimals)
Balance
5.065839225597252549 FRAXValue
$5.05 ( ~0.00151890374457078 Eth) [0.0000%]Loading...
Loading
Loading...
Loading
Loading...
Loading
# | Exchange | Pair | Price | 24H Volume | % Volume |
---|
Contract Name:
FRAXStablecoin
Compiler Version
v0.6.11+commit.5ef660b1
Contract Source Code (Solidity Multiple files format)
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; pragma experimental ABIEncoderV2; import "./Context.sol"; import "./IERC20.sol"; import "./ERC20Custom.sol"; import "./ERC20.sol"; import "./SafeMath.sol"; import "./FXS.sol"; import "./FraxPool.sol"; import "./UniswapPairOracle.sol"; import "./ChainlinkETHUSDPriceConsumer.sol"; import "./AccessControl.sol"; contract FRAXStablecoin is ERC20Custom, AccessControl { using SafeMath for uint256; /* ========== STATE VARIABLES ========== */ enum PriceChoice { FRAX, FXS } ChainlinkETHUSDPriceConsumer private eth_usd_pricer; uint8 private eth_usd_pricer_decimals; UniswapPairOracle private fraxEthOracle; UniswapPairOracle private fxsEthOracle; string public symbol; string public name; uint8 public constant decimals = 18; address public owner_address; address public creator_address; address public timelock_address; // Governance timelock address address public controller_address; // Controller contract to dynamically adjust system parameters automatically address public fxs_address; address public frax_eth_oracle_address; address public fxs_eth_oracle_address; address public weth_address; address public eth_usd_consumer_address; uint256 public constant genesis_supply = 2000000e18; // 2M FRAX (only for testing, genesis supply will be 5k on Mainnet). This is to help with establishing the Uniswap pools, as they need liquidity // The addresses in this array are added by the oracle and these contracts are able to mint frax address[] public frax_pools_array; // Mapping is also used for faster verification mapping(address => bool) public frax_pools; // Constants for various precisions uint256 private constant PRICE_PRECISION = 1e6; uint256 public global_collateral_ratio; // 6 decimals of precision, e.g. 924102 = 0.924102 uint256 public redemption_fee; // 6 decimals of precision, divide by 1000000 in calculations for fee uint256 public minting_fee; // 6 decimals of precision, divide by 1000000 in calculations for fee uint256 public frax_step; // Amount to change the collateralization ratio by upon refreshCollateralRatio() uint256 public refresh_cooldown; // Seconds to wait before being able to run refreshCollateralRatio() again uint256 public price_target; // The price of FRAX at which the collateral ratio will respond to; this value is only used for the collateral ratio mechanism and not for minting and redeeming which are hardcoded at $1 uint256 public price_band; // The bound above and below the price target at which the refreshCollateralRatio() will not change the collateral ratio address public DEFAULT_ADMIN_ADDRESS; bytes32 public constant COLLATERAL_RATIO_PAUSER = keccak256("COLLATERAL_RATIO_PAUSER"); bool public collateral_ratio_paused = false; /* ========== MODIFIERS ========== */ modifier onlyCollateralRatioPauser() { require(hasRole(COLLATERAL_RATIO_PAUSER, msg.sender)); _; } modifier onlyPools() { require(frax_pools[msg.sender] == true, "Only frax pools can call this function"); _; } modifier onlyByOwnerOrGovernance() { require(msg.sender == owner_address || msg.sender == timelock_address || msg.sender == controller_address, "You are not the owner, controller, or the governance timelock"); _; } modifier onlyByOwnerGovernanceOrPool() { require( msg.sender == owner_address || msg.sender == timelock_address || frax_pools[msg.sender] == true, "You are not the owner, the governance timelock, or a pool"); _; } /* ========== CONSTRUCTOR ========== */ constructor( string memory _name, string memory _symbol, address _creator_address, address _timelock_address ) public { name = _name; symbol = _symbol; creator_address = _creator_address; timelock_address = _timelock_address; _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); DEFAULT_ADMIN_ADDRESS = _msgSender(); owner_address = _creator_address; _mint(creator_address, genesis_supply); grantRole(COLLATERAL_RATIO_PAUSER, creator_address); grantRole(COLLATERAL_RATIO_PAUSER, timelock_address); frax_step = 2500; // 6 decimals of precision, equal to 0.25% global_collateral_ratio = 1000000; // Frax system starts off fully collateralized (6 decimals of precision) refresh_cooldown = 3600; // Refresh cooldown period is set to 1 hour (3600 seconds) at genesis price_target = 1000000; // Collateral ratio will adjust according to the $1 price target at genesis price_band = 5000; // Collateral ratio will not adjust if between $0.995 and $1.005 at genesis } /* ========== VIEWS ========== */ // Choice = 'FRAX' or 'FXS' for now function oracle_price(PriceChoice choice) internal view returns (uint256) { // Get the ETH / USD price first, and cut it down to 1e6 precision uint256 eth_usd_price = uint256(eth_usd_pricer.getLatestPrice()).mul(PRICE_PRECISION).div(uint256(10) ** eth_usd_pricer_decimals); uint256 price_vs_eth; if (choice == PriceChoice.FRAX) { price_vs_eth = uint256(fraxEthOracle.consult(weth_address, PRICE_PRECISION)); // How much FRAX if you put in PRICE_PRECISION WETH } else if (choice == PriceChoice.FXS) { price_vs_eth = uint256(fxsEthOracle.consult(weth_address, PRICE_PRECISION)); // How much FXS if you put in PRICE_PRECISION WETH } else revert("INVALID PRICE CHOICE. Needs to be either 0 (FRAX) or 1 (FXS)"); // Will be in 1e6 format return eth_usd_price.mul(PRICE_PRECISION).div(price_vs_eth); } // Returns X FRAX = 1 USD function frax_price() public view returns (uint256) { return oracle_price(PriceChoice.FRAX); } // Returns X FXS = 1 USD function fxs_price() public view returns (uint256) { return oracle_price(PriceChoice.FXS); } function eth_usd_price() public view returns (uint256) { return uint256(eth_usd_pricer.getLatestPrice()).mul(PRICE_PRECISION).div(uint256(10) ** eth_usd_pricer_decimals); } // This is needed to avoid costly repeat calls to different getter functions // It is cheaper gas-wise to just dump everything and only use some of the info function frax_info() public view returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256) { return ( oracle_price(PriceChoice.FRAX), // frax_price() oracle_price(PriceChoice.FXS), // fxs_price() totalSupply(), // totalSupply() global_collateral_ratio, // global_collateral_ratio() globalCollateralValue(), // globalCollateralValue minting_fee, // minting_fee() redemption_fee, // redemption_fee() uint256(eth_usd_pricer.getLatestPrice()).mul(PRICE_PRECISION).div(uint256(10) ** eth_usd_pricer_decimals) //eth_usd_price ); } // Iterate through all frax pools and calculate all value of collateral in all pools globally function globalCollateralValue() public view returns (uint256) { uint256 total_collateral_value_d18 = 0; for (uint i = 0; i < frax_pools_array.length; i++){ // Exclude null addresses if (frax_pools_array[i] != address(0)){ total_collateral_value_d18 = total_collateral_value_d18.add(FraxPool(frax_pools_array[i]).collatDollarBalance()); } } return total_collateral_value_d18; } /* ========== PUBLIC FUNCTIONS ========== */ // There needs to be a time interval that this can be called. Otherwise it can be called multiple times per expansion. uint256 public last_call_time; // Last time the refreshCollateralRatio function was called function refreshCollateralRatio() public { require(collateral_ratio_paused == false, "Collateral Ratio has been paused"); uint256 frax_price_cur = frax_price(); require(block.timestamp - last_call_time >= refresh_cooldown, "Must wait for the refresh cooldown since last refresh"); // Step increments are 0.25% (upon genesis, changable by setFraxStep()) if (frax_price_cur > price_target.add(price_band)) { //decrease collateral ratio if(global_collateral_ratio <= frax_step){ //if within a step of 0, go to 0 global_collateral_ratio = 0; } else { global_collateral_ratio = global_collateral_ratio.sub(frax_step); } } else if (frax_price_cur < price_target.sub(price_band)) { //increase collateral ratio if(global_collateral_ratio.add(frax_step) >= 1000000){ global_collateral_ratio = 1000000; // cap collateral ratio at 1.000000 } else { global_collateral_ratio = global_collateral_ratio.add(frax_step); } } last_call_time = block.timestamp; // Set the time of the last expansion } /* ========== RESTRICTED FUNCTIONS ========== */ // Used by pools when user redeems function pool_burn_from(address b_address, uint256 b_amount) public onlyPools { super._burnFrom(b_address, b_amount); emit FRAXBurned(b_address, msg.sender, b_amount); } // This function is what other frax pools will call to mint new FRAX function pool_mint(address m_address, uint256 m_amount) public onlyPools { super._mint(m_address, m_amount); emit FRAXMinted(msg.sender, m_address, m_amount); } // Adds collateral addresses supported, such as tether and busd, must be ERC20 function addPool(address pool_address) public onlyByOwnerOrGovernance { require(frax_pools[pool_address] == false, "address already exists"); frax_pools[pool_address] = true; frax_pools_array.push(pool_address); } // Remove a pool function removePool(address pool_address) public onlyByOwnerOrGovernance { require(frax_pools[pool_address] == true, "address doesn't exist already"); // Delete from the mapping delete frax_pools[pool_address]; // 'Delete' from the array by setting the address to 0x0 for (uint i = 0; i < frax_pools_array.length; i++){ if (frax_pools_array[i] == pool_address) { frax_pools_array[i] = address(0); // This will leave a null in the array and keep the indices the same break; } } } function setOwner(address _owner_address) external onlyByOwnerOrGovernance { owner_address = _owner_address; } function setRedemptionFee(uint256 red_fee) public onlyByOwnerOrGovernance { redemption_fee = red_fee; } function setMintingFee(uint256 min_fee) public onlyByOwnerOrGovernance { minting_fee = min_fee; } function setFraxStep(uint256 _new_step) public onlyByOwnerOrGovernance { frax_step = _new_step; } function setPriceTarget (uint256 _new_price_target) public onlyByOwnerOrGovernance { price_target = _new_price_target; } function setRefreshCooldown(uint256 _new_cooldown) public onlyByOwnerOrGovernance { refresh_cooldown = _new_cooldown; } function setFXSAddress(address _fxs_address) public onlyByOwnerOrGovernance { fxs_address = _fxs_address; } function setETHUSDOracle(address _eth_usd_consumer_address) public onlyByOwnerOrGovernance { eth_usd_consumer_address = _eth_usd_consumer_address; eth_usd_pricer = ChainlinkETHUSDPriceConsumer(eth_usd_consumer_address); eth_usd_pricer_decimals = eth_usd_pricer.getDecimals(); } function setTimelock(address new_timelock) external onlyByOwnerOrGovernance { timelock_address = new_timelock; } function setController(address _controller_address) external onlyByOwnerOrGovernance { controller_address = _controller_address; } function setPriceBand(uint256 _price_band) external onlyByOwnerOrGovernance { price_band = _price_band; } // Sets the FRAX_ETH Uniswap oracle address function setFRAXEthOracle(address _frax_oracle_addr, address _weth_address) public onlyByOwnerOrGovernance { frax_eth_oracle_address = _frax_oracle_addr; fraxEthOracle = UniswapPairOracle(_frax_oracle_addr); weth_address = _weth_address; } // Sets the FXS_ETH Uniswap oracle address function setFXSEthOracle(address _fxs_oracle_addr, address _weth_address) public onlyByOwnerOrGovernance { fxs_eth_oracle_address = _fxs_oracle_addr; fxsEthOracle = UniswapPairOracle(_fxs_oracle_addr); weth_address = _weth_address; } function toggleCollateralRatio() public onlyCollateralRatioPauser { collateral_ratio_paused = !collateral_ratio_paused; } /* ========== EVENTS ========== */ // Track FRAX burned event FRAXBurned(address indexed from, address indexed to, uint256 amount); // Track FRAX minted event FRAXMinted(address indexed from, address indexed to, uint256 amount); }
// SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import "./EnumerableSet.sol"; import "./Address.sol"; import "./Context.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context { using EnumerableSet for EnumerableSet.AddressSet; using Address for address; struct RoleData { EnumerableSet.AddressSet members; bytes32 adminRole; } mapping (bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; //bytes32(uint256(0x4B437D01b575618140442A4975db38850e3f8f5f) << 96); /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view returns (bool) { return _roles[role].members.contains(account); } /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) public view returns (uint256) { return _roles[role].members.length(); } /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) public view returns (address) { return _roles[role].members.at(index); } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) public virtual { require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to grant"); _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) public virtual { require(hasRole(_roles[role].adminRole, _msgSender()), "AccessControl: sender must be an admin to revoke"); _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) public virtual { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { emit RoleAdminChanged(role, _roles[role].adminRole, adminRole); _roles[role].adminRole = adminRole; } function _grantRole(bytes32 role, address account) private { if (_roles[role].members.add(account)) { emit RoleGranted(role, account, _msgSender()); } } function _revokeRole(bytes32 role, address account) private { if (_roles[role].members.remove(account)) { emit RoleRevoked(role, account, _msgSender()); } } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0; interface AggregatorV3Interface { function decimals() external view returns (uint8); function description() external view returns (string memory); function version() external view returns (uint256); // getRoundData and latestRoundData should both raise "No data present" // if they do not have data to report, instead of returning unset values // which could be misinterpreted as actual reported values. function getRoundData(uint80 _roundId) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function latestRoundData() external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; // computes square roots using the babylonian method // https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method library Babylonian { function sqrt(uint y) internal pure returns (uint z) { if (y > 3) { z = y; uint x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } } else if (y != 0) { z = 1; } // else z = 0 } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; // file: BlockMinder.sol // used to "waste" blocks for truffle tests contract BlockMiner { uint256 public blocksMined; constructor () public { blocksMined = 0; } function mine() public { blocksMined += 1; } function blockTime() external view returns (uint256) { return block.timestamp; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; pragma experimental ABIEncoderV2; import "./AggregatorV3Interface.sol"; contract ChainlinkETHUSDPriceConsumer { AggregatorV3Interface internal priceFeed; constructor() public { priceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419); } /** * Returns the latest price */ function getLatestPrice() public view returns (int) { ( , int price, , , ) = priceFeed.latestRoundData(); return price; } function getDecimals() public view returns (uint8) { return priceFeed.decimals(); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; pragma experimental ABIEncoderV2; import "./AggregatorV3Interface.sol"; // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol"; contract ChainlinkETHUSDPriceConsumerTest { // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // AggregatorV3Interface internal priceFeed; /** * Network: Kovan * Aggregator: ETH/USD * Address: 0x9326BFA02ADD2366b30bacB125260Af641031331 */ /** * Network: Mainnet * Aggregator: ETH/USD * Address: 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419 */ constructor() public { // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // priceFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419); } /** * Returns the latest price */ function getLatestPrice() public pure returns (int) { // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // ( // uint80 roundID, // int price, // uint startedAt, // uint timeStamp, // uint80 answeredInRound // ) = priceFeed.latestRoundData(); // // If the round is not complete yet, timestamp is 0 // require(timeStamp > 0, "Round not complete"); // This will return something like 32063000000 // Divide this by getDecimals to get the "true" price // You can can multiply the "true" price by 1e6 to get the frax ecosystem 'price' // return price; return 59000000000; } function getDecimals() public pure returns (uint8) { // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // VERY IMPORTANT: UNCOMMENT THIS LATER // return priceFeed.decimals(); return 8; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; /* * @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 GSN 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. */ contract Context { // Empty internal constructor, to prevent people from mistakenly deploying // an instance of this contract, which should be used via inheritance. constructor () internal { } function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.6.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.0.0, only sets of type `address` (`AddressSet`) and `uint256` * (`UintSet`) are supported. */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping (bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement. bytes32 lastvalue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastvalue; // Update the index for the moved value set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { require(set._values.length > index, "EnumerableSet: index out of bounds"); return set._values[index]; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(value))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(value))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(value))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint256(_at(set._inner, index))); } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values on the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./Context.sol"; import "./IERC20.sol"; import "./SafeMath.sol"; import "./Address.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20Mintable}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address.approve(address spender, uint256 amount) */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public virtual { _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for `accounts`'s tokens of at least * `amount`. */ function burnFrom(address account, uint256 amount) public virtual { uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, "ERC20: burn amount exceeds allowance"); _approve(account, _msgSender(), decreasedAllowance); _burn(account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal virtual { _burn(account, amount); _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of `from`'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of `from`'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:using-hooks.adoc[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./Context.sol"; import "./IERC20.sol"; import "./SafeMath.sol"; import "./Address.sol"; // Due to compiling issues, _name, _symbol, and _decimals were removed /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20Mintable}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20Custom is Context, IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) internal _allowances; uint256 private _totalSupply; /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address.approve(address spender, uint256 amount) */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public virtual { _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for `accounts`'s tokens of at least * `amount`. */ function burnFrom(address account, uint256 amount) public virtual { uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, "ERC20: burn amount exceeds allowance"); _approve(account, _msgSender(), decreasedAllowance); _burn(account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal virtual { _burn(account, amount); _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of `from`'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of `from`'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:using-hooks.adoc[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./Context.sol"; import "./IERC20.sol"; import "./SafeMath.sol"; import "./Address.sol"; // Due to compiling issues, _name, _symbol, and _decimals were removed /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20Mintable}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract FakeCollateral is Context, IERC20 { using SafeMath for uint256; string public symbol; uint8 public decimals; address public creator_address; uint256 public genesis_supply; uint256 private _totalSupply; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) used; constructor( address _creator_address, uint256 _genesis_supply, string memory _symbol, uint8 _decimals ) public { genesis_supply = _genesis_supply; creator_address = _creator_address; symbol = _symbol; decimals = _decimals; _mint(creator_address, genesis_supply); } function faucet() public { if (used[msg.sender] == false) { used[msg.sender] = true; _mint(msg.sender, 1000 * (10 ** uint256(decimals))); } } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address.approve(address spender, uint256 amount) */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for `sender`'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public virtual { _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for `accounts`'s tokens of at least * `amount`. */ function burnFrom(address account, uint256 amount) public virtual { uint256 decreasedAllowance = allowance(account, _msgSender()).sub(amount, "ERC20: burn amount exceeds allowance"); _approve(account, _msgSender(), decreasedAllowance); _burn(account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal virtual { _burn(account, amount); _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of `from`'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of `from`'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:using-hooks.adoc[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./FakeCollateral.sol"; contract FakeCollateral_USDC is FakeCollateral { constructor( address _creator_address, uint256 _genesis_supply, string memory _symbol, uint8 _decimals ) FakeCollateral(_creator_address, _genesis_supply, _symbol, _decimals) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./FakeCollateral.sol"; contract FakeCollateral_USDT is FakeCollateral { constructor( address _creator_address, uint256 _genesis_supply, string memory _symbol, uint8 _decimals ) FakeCollateral(_creator_address, _genesis_supply, _symbol, _decimals) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./FakeCollateral.sol"; contract FakeCollateral_WETH is FakeCollateral { constructor( address _creator_address, uint256 _genesis_supply, string memory _symbol, uint8 _decimals ) FakeCollateral(_creator_address, _genesis_supply, _symbol, _decimals) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './Babylonian.sol'; // a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format)) library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint _x; } uint8 private constant RESOLUTION = 112; uint private constant Q112 = uint(1) << RESOLUTION; uint private constant Q224 = Q112 << RESOLUTION; // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // divide a UQ112x112 by a uint112, returning a UQ112x112 function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, 'FixedPoint: DIV_BY_ZERO'); return uq112x112(self._x / uint224(x)); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) { uint z; require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator) function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // take the reciprocal of a UQ112x112 function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; pragma experimental ABIEncoderV2; import "./SafeMath.sol"; import "./FXS.sol"; import "./Frax.sol"; import "./ERC20.sol"; // import '../../Uniswap/TransferHelper.sol'; import "./UniswapPairOracle.sol"; import "./AccessControl.sol"; // import "../../Utils/StringHelpers.sol"; import "./FraxPoolLibrary.sol"; /* Same as FraxPool.sol, but has some gas optimizations */ contract FraxPool is AccessControl { using SafeMath for uint256; /* ========== STATE VARIABLES ========== */ ERC20 private collateral_token; address private collateral_address; address private owner_address; // address private oracle_address; address private frax_contract_address; address private fxs_contract_address; address private timelock_address; // Timelock address for the governance contract FRAXShares private FXS; FRAXStablecoin private FRAX; // UniswapPairOracle private oracle; UniswapPairOracle private collatEthOracle; address private collat_eth_oracle_address; address private weth_address; uint256 private minting_fee; uint256 private redemption_fee; mapping (address => uint256) public redeemFXSBalances; mapping (address => uint256) public redeemCollateralBalances; uint256 public unclaimedPoolCollateral; uint256 public unclaimedPoolFXS; mapping (address => uint256) public lastRedeemed; // Constants for various precisions uint256 private constant PRICE_PRECISION = 1e6; uint256 private constant COLLATERAL_RATIO_PRECISION = 1e6; uint256 private constant COLLATERAL_RATIO_MAX = 1e6; // Number of decimals needed to get to 18 uint256 private missing_decimals; // Pool_ceiling is the total units of collateral that a pool contract can hold uint256 public pool_ceiling = 0; // Stores price of the collateral, if price is paused uint256 public pausedPrice = 0; // Bonus rate on FXS minted during recollateralizeFRAX(); 6 decimals of precision, set to 0.75% on genesis uint256 public bonus_rate = 7500; // Number of blocks to wait before being able to collectRedemption() uint256 public redemption_delay = 1; // AccessControl Roles bytes32 private constant MINT_PAUSER = keccak256("MINT_PAUSER"); bytes32 private constant REDEEM_PAUSER = keccak256("REDEEM_PAUSER"); bytes32 private constant BUYBACK_PAUSER = keccak256("BUYBACK_PAUSER"); bytes32 private constant RECOLLATERALIZE_PAUSER = keccak256("RECOLLATERALIZE_PAUSER"); bytes32 private constant COLLATERAL_PRICE_PAUSER = keccak256("COLLATERAL_PRICE_PAUSER"); // AccessControl state variables bool private mintPaused = false; bool private redeemPaused = false; bool private recollateralizePaused = false; bool private buyBackPaused = false; bool private collateralPricePaused = false; /* ========== MODIFIERS ========== */ modifier onlyByOwnerOrGovernance() { require(msg.sender == timelock_address || msg.sender == owner_address, "You are not the owner or the governance timelock"); _; } modifier notRedeemPaused() { require(redeemPaused == false, "Redeeming is paused"); _; } modifier notMintPaused() { require(mintPaused == false, "Minting is paused"); _; } /* ========== CONSTRUCTOR ========== */ constructor( address _frax_contract_address, address _fxs_contract_address, address _collateral_address, address _creator_address, address _timelock_address, uint256 _pool_ceiling ) public { FRAX = FRAXStablecoin(_frax_contract_address); FXS = FRAXShares(_fxs_contract_address); frax_contract_address = _frax_contract_address; fxs_contract_address = _fxs_contract_address; collateral_address = _collateral_address; timelock_address = _timelock_address; owner_address = _creator_address; collateral_token = ERC20(_collateral_address); pool_ceiling = _pool_ceiling; missing_decimals = uint(18).sub(collateral_token.decimals()); _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); grantRole(MINT_PAUSER, timelock_address); grantRole(REDEEM_PAUSER, timelock_address); grantRole(RECOLLATERALIZE_PAUSER, timelock_address); grantRole(BUYBACK_PAUSER, timelock_address); grantRole(COLLATERAL_PRICE_PAUSER, timelock_address); } /* ========== VIEWS ========== */ // Returns dollar value of collateral held in this Frax pool function collatDollarBalance() public view returns (uint256) { uint256 eth_usd_price = FRAX.eth_usd_price(); uint256 eth_collat_price = collatEthOracle.consult(weth_address, (PRICE_PRECISION * (10 ** missing_decimals))); uint256 collat_usd_price = eth_usd_price.mul(PRICE_PRECISION).div(eth_collat_price); return (collateral_token.balanceOf(address(this)).sub(unclaimedPoolCollateral)).mul(10 ** missing_decimals).mul(collat_usd_price).div(PRICE_PRECISION); //.mul(getCollateralPrice()).div(1e6); } // Returns the value of excess collateral held in this Frax pool, compared to what is needed to maintain the global collateral ratio function availableExcessCollatDV() public view returns (uint256) { uint256 total_supply = FRAX.totalSupply(); uint256 global_collateral_ratio = FRAX.global_collateral_ratio(); uint256 global_collat_value = FRAX.globalCollateralValue(); if (global_collateral_ratio > COLLATERAL_RATIO_PRECISION) global_collateral_ratio = COLLATERAL_RATIO_PRECISION; // Handles an overcollateralized contract with CR > 1 uint256 required_collat_dollar_value_d18 = (total_supply.mul(global_collateral_ratio)).div(COLLATERAL_RATIO_PRECISION); // Calculates collateral needed to back each 1 FRAX with $1 of collateral at current collat ratio if (global_collat_value > required_collat_dollar_value_d18) return global_collat_value.sub(required_collat_dollar_value_d18); else return 0; } /* ========== PUBLIC FUNCTIONS ========== */ // Returns the price of the pool collateral in USD function getCollateralPrice() public view returns (uint256) { if(collateralPricePaused == true){ return pausedPrice; } else { uint256 eth_usd_price = FRAX.eth_usd_price(); return eth_usd_price.mul(PRICE_PRECISION).div(collatEthOracle.consult(weth_address, PRICE_PRECISION * (10 ** missing_decimals))); } } function setCollatETHOracle(address _collateral_weth_oracle_address, address _weth_address) external onlyByOwnerOrGovernance { collat_eth_oracle_address = _collateral_weth_oracle_address; collatEthOracle = UniswapPairOracle(_collateral_weth_oracle_address); weth_address = _weth_address; } // We separate out the 1t1, fractional and algorithmic minting functions for gas efficiency function mint1t1FRAX(uint256 collateral_amount, uint256 FRAX_out_min) external notMintPaused { uint256 collateral_amount_d18 = collateral_amount * (10 ** missing_decimals); uint256 global_collateral_ratio = FRAX.global_collateral_ratio(); require(global_collateral_ratio >= COLLATERAL_RATIO_MAX, "Collateral ratio must be >= 1"); require((collateral_token.balanceOf(address(this))).sub(unclaimedPoolCollateral).add(collateral_amount) <= pool_ceiling, "[Pool's Closed]: Ceiling reached"); (uint256 frax_amount_d18) = FraxPoolLibrary.calcMint1t1FRAX( getCollateralPrice(), minting_fee, collateral_amount_d18 ); //1 FRAX for each $1 worth of collateral require(FRAX_out_min <= frax_amount_d18, "Slippage limit reached"); collateral_token.transferFrom(msg.sender, address(this), collateral_amount); FRAX.pool_mint(msg.sender, frax_amount_d18); } // 0% collateral-backed function mintAlgorithmicFRAX(uint256 fxs_amount_d18, uint256 FRAX_out_min) external notMintPaused { uint256 fxs_price = FRAX.fxs_price(); uint256 global_collateral_ratio = FRAX.global_collateral_ratio(); require(global_collateral_ratio == 0, "Collateral ratio must be 0"); (uint256 frax_amount_d18) = FraxPoolLibrary.calcMintAlgorithmicFRAX( minting_fee, fxs_price, // X FXS / 1 USD fxs_amount_d18 ); require(FRAX_out_min <= frax_amount_d18, "Slippage limit reached"); FXS.pool_burn_from(msg.sender, fxs_amount_d18); FRAX.pool_mint(msg.sender, frax_amount_d18); } // Will fail if fully collateralized or fully algorithmic // > 0% and < 100% collateral-backed function mintFractionalFRAX(uint256 collateral_amount, uint256 fxs_amount, uint256 FRAX_out_min) external notMintPaused { uint256 frax_price = FRAX.frax_price(); uint256 fxs_price = FRAX.fxs_price(); uint256 global_collateral_ratio = FRAX.global_collateral_ratio(); require(global_collateral_ratio < COLLATERAL_RATIO_MAX && global_collateral_ratio > 0, "Collateral ratio needs to be between .000001 and .999999"); require(collateral_token.balanceOf(address(this)).sub(unclaimedPoolCollateral).add(collateral_amount) <= pool_ceiling, "Pool ceiling reached, no more FRAX can be minted with this collateral"); uint256 collateral_amount_d18 = collateral_amount * (10 ** missing_decimals); FraxPoolLibrary.MintFF_Params memory input_params = FraxPoolLibrary.MintFF_Params( minting_fee, fxs_price, frax_price, getCollateralPrice(), fxs_amount, collateral_amount_d18, (collateral_token.balanceOf(address(this)).sub(unclaimedPoolCollateral)), pool_ceiling, global_collateral_ratio ); (uint256 mint_amount, uint256 fxs_needed) = FraxPoolLibrary.calcMintFractionalFRAX(input_params); require(FRAX_out_min <= mint_amount, "Slippage limit reached"); require(fxs_needed <= fxs_amount, "Not enough FXS inputted"); FXS.pool_burn_from(msg.sender, fxs_needed); collateral_token.transferFrom(msg.sender, address(this), collateral_amount); FRAX.pool_mint(msg.sender, mint_amount); } // Redeem collateral. 100% collateral-backed function redeem1t1FRAX(uint256 FRAX_amount, uint256 COLLATERAL_out_min) external notRedeemPaused { uint256 global_collateral_ratio = FRAX.global_collateral_ratio(); require(global_collateral_ratio == COLLATERAL_RATIO_MAX, "Collateral ratio must be == 1"); // Need to adjust for decimals of collateral uint256 FRAX_amount_precision = FRAX_amount.div(10 ** missing_decimals); (uint256 collateral_needed) = FraxPoolLibrary.calcRedeem1t1FRAX( getCollateralPrice(), FRAX_amount_precision, redemption_fee ); require(collateral_needed <= collateral_token.balanceOf(address(this)).sub(unclaimedPoolCollateral), "Not enough collateral in pool"); redeemCollateralBalances[msg.sender] = redeemCollateralBalances[msg.sender].add(collateral_needed); unclaimedPoolCollateral = unclaimedPoolCollateral.add(collateral_needed); lastRedeemed[msg.sender] = block.number; require(COLLATERAL_out_min <= collateral_needed, "Slippage limit reached"); // Move all external functions to the end FRAX.pool_burn_from(msg.sender, FRAX_amount); } // Will fail if fully collateralized or algorithmic // Redeem FRAX for collateral and FXS. > 0% and < 100% collateral-backed function redeemFractionalFRAX(uint256 FRAX_amount, uint256 FXS_out_min, uint256 COLLATERAL_out_min) external notRedeemPaused { uint256 fxs_price = FRAX.fxs_price(); uint256 global_collateral_ratio = FRAX.global_collateral_ratio(); require(global_collateral_ratio < COLLATERAL_RATIO_MAX && global_collateral_ratio > 0, "Collateral ratio needs to be between .000001 and .999999"); uint256 col_price_usd = getCollateralPrice(); uint256 FRAX_amount_post_fee = FRAX_amount.sub((FRAX_amount.mul(redemption_fee)).div(PRICE_PRECISION)); uint256 fxs_dollar_value_d18 = FRAX_amount_post_fee.sub(FRAX_amount_post_fee.mul(global_collateral_ratio).div(PRICE_PRECISION)); uint256 fxs_amount = fxs_dollar_value_d18.mul(PRICE_PRECISION).div(fxs_price); // Need to adjust for decimals of collateral uint256 FRAX_amount_precision = FRAX_amount_post_fee.div(10 ** missing_decimals); uint256 collateral_dollar_value = FRAX_amount_precision.mul(global_collateral_ratio).div(PRICE_PRECISION); uint256 collateral_amount = collateral_dollar_value.mul(PRICE_PRECISION).div(col_price_usd); redeemCollateralBalances[msg.sender] = redeemCollateralBalances[msg.sender].add(collateral_amount); unclaimedPoolCollateral = unclaimedPoolCollateral.add(collateral_amount); redeemFXSBalances[msg.sender] = redeemFXSBalances[msg.sender].add(fxs_amount); unclaimedPoolFXS = unclaimedPoolFXS.add(fxs_amount); lastRedeemed[msg.sender] = block.number; require(collateral_amount <= collateral_token.balanceOf(address(this)).sub(unclaimedPoolCollateral), "Not enough collateral in pool"); require(COLLATERAL_out_min <= collateral_amount, "Slippage limit reached [collateral]"); require(FXS_out_min <= fxs_amount, "Slippage limit reached [FXS]"); // Move all external functions to the end FRAX.pool_burn_from(msg.sender, FRAX_amount); FXS.pool_mint(address(this), fxs_amount); } // Redeem FRAX for FXS. 0% collateral-backed function redeemAlgorithmicFRAX(uint256 FRAX_amount, uint256 FXS_out_min) external notRedeemPaused { uint256 fxs_price = FRAX.fxs_price(); uint256 global_collateral_ratio = FRAX.global_collateral_ratio(); require(global_collateral_ratio == 0, "Collateral ratio must be 0"); uint256 fxs_dollar_value_d18 = FRAX_amount; fxs_dollar_value_d18 = fxs_dollar_value_d18.sub((fxs_dollar_value_d18.mul(redemption_fee)).div(PRICE_PRECISION)); //apply redemption fee uint256 fxs_amount = fxs_dollar_value_d18.mul(PRICE_PRECISION).div(fxs_price); redeemFXSBalances[msg.sender] = redeemFXSBalances[msg.sender].add(fxs_amount); unclaimedPoolFXS = unclaimedPoolFXS.add(fxs_amount); lastRedeemed[msg.sender] = block.number; require(FXS_out_min <= fxs_amount, "Slippage limit reached"); // Move all external functions to the end FRAX.pool_burn_from(msg.sender, FRAX_amount); FXS.pool_mint(address(this), fxs_amount); } // After a redemption happens, transfer the newly minted FXS and owed collateral from this pool // contract to the user. Redemption is split into two functions to prevent flash loans from being able // to take out FRAX/collateral from the system, use an AMM to trade the new price, and then mint back into the system. function collectRedemption() external { require((lastRedeemed[msg.sender].add(redemption_delay)) <= block.number, "Must wait for redemption_delay blocks before collecting redemption"); bool sendFXS = false; bool sendCollateral = false; uint FXSAmount; uint CollateralAmount; // Use Checks-Effects-Interactions pattern if(redeemFXSBalances[msg.sender] > 0){ FXSAmount = redeemFXSBalances[msg.sender]; redeemFXSBalances[msg.sender] = 0; unclaimedPoolFXS = unclaimedPoolFXS.sub(FXSAmount); sendFXS = true; } if(redeemCollateralBalances[msg.sender] > 0){ CollateralAmount = redeemCollateralBalances[msg.sender]; redeemCollateralBalances[msg.sender] = 0; unclaimedPoolCollateral = unclaimedPoolCollateral.sub(CollateralAmount); sendCollateral = true; } if(sendFXS == true){ FXS.transfer(msg.sender, FXSAmount); } if(sendCollateral == true){ collateral_token.transfer(msg.sender, CollateralAmount); } } // When the protocol is recollateralizing, we need to give a discount of FXS to hit the new CR target // Thus, if the target collateral ratio is higher than the actual value of collateral, minters get FXS for adding collateral // This function simply rewards anyone that sends collateral to a pool with the same amount of FXS + the bonus rate // Anyone can call this function to recollateralize the protocol and take the extra FXS value from the bonus rate as an arb opportunity function recollateralizeFRAX(uint256 collateral_amount, uint256 FXS_out_min) external { require(recollateralizePaused == false, "Recollateralize is paused"); uint256 collateral_amount_d18 = collateral_amount * (10 ** missing_decimals); uint256 fxs_price = FRAX.fxs_price(); uint256 frax_total_supply = FRAX.totalSupply(); uint256 global_collateral_ratio = FRAX.global_collateral_ratio(); uint256 global_collat_value = FRAX.globalCollateralValue(); (uint256 collateral_units, uint256 amount_to_recollat) = FraxPoolLibrary.calcRecollateralizeFRAXInner( collateral_amount_d18, getCollateralPrice(), global_collat_value, frax_total_supply, global_collateral_ratio ); uint256 collateral_units_precision = collateral_units.div(10 ** missing_decimals); uint256 fxs_paid_back = amount_to_recollat.mul(uint(1e6).add(bonus_rate)).div(fxs_price); require(FXS_out_min <= fxs_paid_back, "Slippage limit reached"); collateral_token.transferFrom(msg.sender, address(this), collateral_units_precision); FXS.pool_mint(msg.sender, fxs_paid_back); } // Function can be called by an FXS holder to have the protocol buy back FXS with excess collateral value from a desired collateral pool // This can also happen if the collateral ratio > 1 function buyBackFXS(uint256 FXS_amount, uint256 COLLATERAL_out_min) external { require(buyBackPaused == false, "Buyback is paused"); uint256 fxs_price = FRAX.fxs_price(); FraxPoolLibrary.BuybackFXS_Params memory input_params = FraxPoolLibrary.BuybackFXS_Params( availableExcessCollatDV(), fxs_price, getCollateralPrice(), FXS_amount ); (uint256 collateral_equivalent_d18) = FraxPoolLibrary.calcBuyBackFXS(input_params); uint256 collateral_precision = collateral_equivalent_d18.div(10 ** missing_decimals); require(COLLATERAL_out_min <= collateral_precision, "Slippage limit reached"); // Give the sender their desired collateral and burn the FXS FXS.pool_burn_from(msg.sender, FXS_amount); collateral_token.transfer(msg.sender, collateral_precision); } /* ========== RESTRICTED FUNCTIONS ========== */ function toggleMinting() external { require(hasRole(MINT_PAUSER, msg.sender)); mintPaused = !mintPaused; } function toggleRedeeming() external { require(hasRole(REDEEM_PAUSER, msg.sender)); redeemPaused = !redeemPaused; } function toggleRecollateralize() external { require(hasRole(RECOLLATERALIZE_PAUSER, msg.sender)); recollateralizePaused = !recollateralizePaused; } function toggleBuyBack() external { require(hasRole(BUYBACK_PAUSER, msg.sender)); buyBackPaused = !buyBackPaused; } function toggleCollateralPrice() external { require(hasRole(COLLATERAL_PRICE_PAUSER, msg.sender)); // If pausing, set paused price; else if unpausing, clear pausedPrice if(collateralPricePaused == false){ pausedPrice = getCollateralPrice(); } else { pausedPrice = 0; } collateralPricePaused = !collateralPricePaused; } // Combined into one function due to 24KiB contract memory limit function setPoolParameters(uint256 new_ceiling, uint256 new_bonus_rate, uint256 new_redemption_delay) external onlyByOwnerOrGovernance { pool_ceiling = new_ceiling; bonus_rate = new_bonus_rate; redemption_delay = new_redemption_delay; minting_fee = FRAX.minting_fee(); redemption_fee = FRAX.redemption_fee(); } function setTimelock(address new_timelock) external onlyByOwnerOrGovernance { timelock_address = new_timelock; } function setOwner(address _owner_address) external onlyByOwnerOrGovernance { owner_address = _owner_address; } /* ========== EVENTS ========== */ }
// SPDX-License-Identifier: MIT pragma solidity ^0.6.0; pragma experimental ABIEncoderV2; import "./SafeMath.sol"; library FraxPoolLibrary { using SafeMath for uint256; // Constants for various precisions uint256 private constant PRICE_PRECISION = 1e6; // ================ Structs ================ // Needed to lower stack size struct MintFF_Params { uint256 mint_fee; uint256 fxs_price_usd; uint256 frax_price_usd; uint256 col_price_usd; uint256 fxs_amount; uint256 collateral_amount; uint256 collateral_token_balance; uint256 pool_ceiling; uint256 col_ratio; } struct BuybackFXS_Params { uint256 excess_collateral_dollar_value_d18; uint256 fxs_price_usd; uint256 col_price_usd; uint256 FXS_amount; } // ================ Functions ================ function calcMint1t1FRAX(uint256 col_price, uint256 mint_fee, uint256 collateral_amount_d18) public pure returns (uint256) { uint256 col_price_usd = col_price; uint256 c_dollar_value_d18 = (collateral_amount_d18.mul(col_price_usd)).div(1e6); return c_dollar_value_d18.sub((c_dollar_value_d18.mul(mint_fee)).div(1e6)); } function calcMintAlgorithmicFRAX(uint256 mint_fee, uint256 fxs_price_usd, uint256 fxs_amount_d18) public pure returns (uint256) { uint256 fxs_dollar_value_d18 = fxs_amount_d18.mul(fxs_price_usd).div(1e6); return fxs_dollar_value_d18.sub((fxs_dollar_value_d18.mul(mint_fee)).div(1e6)); } // Must be internal because of the struct function calcMintFractionalFRAX(MintFF_Params memory params) internal pure returns (uint256, uint256) { // Since solidity truncates division, every division operation must be the last operation in the equation to ensure minimum error // The contract must check the proper ratio was sent to mint FRAX. We do this by seeing the minimum mintable FRAX based on each amount uint256 fxs_dollar_value_d18; uint256 c_dollar_value_d18; // Scoping for stack concerns { // USD amounts of the collateral and the FXS fxs_dollar_value_d18 = params.fxs_amount.mul(params.fxs_price_usd).div(1e6); c_dollar_value_d18 = params.collateral_amount.mul(params.col_price_usd).div(1e6); } uint calculated_fxs_dollar_value_d18 = (c_dollar_value_d18.mul(1e6).div(params.col_ratio)) .sub(c_dollar_value_d18); uint calculated_fxs_needed = calculated_fxs_dollar_value_d18.mul(1e6).div(params.fxs_price_usd); return ( (c_dollar_value_d18.add(calculated_fxs_dollar_value_d18)).sub(((c_dollar_value_d18.add(calculated_fxs_dollar_value_d18)).mul(params.mint_fee)).div(1e6)), calculated_fxs_needed ); } function calcRedeem1t1FRAX(uint256 col_price_usd, uint256 FRAX_amount, uint256 redemption_fee) public pure returns (uint256) { uint256 collateral_needed_d18 = FRAX_amount.mul(1e6).div(col_price_usd); return collateral_needed_d18.sub((collateral_needed_d18.mul(redemption_fee)).div(1e6)); } // Must be internal because of the struct function calcBuyBackFXS(BuybackFXS_Params memory params) internal pure returns (uint256) { // If the total collateral value is higher than the amount required at the current collateral ratio then buy back up to the possible FXS with the desired collateral require(params.excess_collateral_dollar_value_d18 > 0, "No excess collateral to buy back!"); // Make sure not to take more than is available uint256 fxs_dollar_value_d18 = params.FXS_amount.mul(params.fxs_price_usd).div(1e6); require(fxs_dollar_value_d18 <= params.excess_collateral_dollar_value_d18, "You are trying to buy back more than the excess!"); // Get the equivalent amount of collateral based on the market value of FXS provided uint256 collateral_equivalent_d18 = fxs_dollar_value_d18.mul(1e6).div(params.col_price_usd); //collateral_equivalent_d18 = collateral_equivalent_d18.sub((collateral_equivalent_d18.mul(params.buyback_fee)).div(1e6)); return ( collateral_equivalent_d18 ); } // Returns value of collateral that must increase to reach recollateralization target (if 0 means no recollateralization) function recollateralizeAmount(uint256 total_supply, uint256 global_collateral_ratio, uint256 global_collat_value) public pure returns (uint256) { uint256 target_collat_value = total_supply.mul(global_collateral_ratio).div(1e6); // We want 18 decimals of precision so divide by 1e6; total_supply is 1e18 and global_collateral_ratio is 1e6 // Subtract the current value of collateral from the target value needed, if higher than 0 then system needs to recollateralize uint256 recollateralization_left = target_collat_value.sub(global_collat_value); // If recollateralization is not needed, throws a subtraction underflow return(recollateralization_left); } function calcRecollateralizeFRAXInner( uint256 collateral_amount, uint256 col_price, uint256 global_collat_value, uint256 frax_total_supply, uint256 global_collateral_ratio ) public pure returns (uint256, uint256) { uint256 collat_value_attempted = collateral_amount.mul(col_price).div(1e6); uint256 effective_collateral_ratio = global_collat_value.mul(1e6).div(frax_total_supply); //returns it in 1e6 uint256 recollat_possible = (global_collateral_ratio.mul(frax_total_supply).sub(frax_total_supply.mul(effective_collateral_ratio))).div(1e6); uint256 amount_to_recollat; if(collat_value_attempted <= recollat_possible){ amount_to_recollat = collat_value_attempted; } else { amount_to_recollat = recollat_possible; } return (amount_to_recollat.mul(1e6).div(col_price), amount_to_recollat); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; pragma experimental ABIEncoderV2; import "./Context.sol"; import "./ERC20Custom.sol"; import "./IERC20.sol"; import "./Frax.sol"; import "./SafeMath.sol"; import "./AccessControl.sol"; contract FRAXShares is ERC20Custom, AccessControl { using SafeMath for uint256; /* ========== STATE VARIABLES ========== */ string public symbol; string public name; uint8 public constant decimals = 18; address public FRAXStablecoinAdd; uint256 public constant genesis_supply = 100000000e18; // 100M is printed upon genesis uint256 public FXS_DAO_min; // Minimum FXS required to join DAO groups address public owner_address; address public oracle_address; address public timelock_address; // Governance timelock address FRAXStablecoin private FRAX; bool public trackingVotes = true; // Tracking votes (only change if need to disable votes) // A checkpoint for marking number of votes from a given block struct Checkpoint { uint32 fromBlock; uint96 votes; } // A record of votes checkpoints for each account, by index mapping (address => mapping (uint32 => Checkpoint)) public checkpoints; // The number of checkpoints for each account mapping (address => uint32) public numCheckpoints; /* ========== MODIFIERS ========== */ modifier onlyPools() { require(FRAX.frax_pools(msg.sender) == true, "Only frax pools can mint new FRAX"); _; } modifier onlyByOwnerOrGovernance() { require(msg.sender == owner_address || msg.sender == timelock_address, "You are not an owner or the governance timelock"); _; } /* ========== CONSTRUCTOR ========== */ constructor( string memory _name, string memory _symbol, address _oracle_address, address _owner_address, address _timelock_address ) public { name = _name; symbol = _symbol; owner_address = _owner_address; oracle_address = _oracle_address; timelock_address = _timelock_address; _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); _mint(owner_address, genesis_supply); // Do a checkpoint for the owner _writeCheckpoint(owner_address, 0, 0, uint96(genesis_supply)); } /* ========== RESTRICTED FUNCTIONS ========== */ function setOracle(address new_oracle) external onlyByOwnerOrGovernance { oracle_address = new_oracle; } function setTimelock(address new_timelock) external onlyByOwnerOrGovernance { timelock_address = new_timelock; } function setFRAXAddress(address frax_contract_address) external onlyByOwnerOrGovernance { FRAX = FRAXStablecoin(frax_contract_address); } function setFXSMinDAO(uint256 min_FXS) external onlyByOwnerOrGovernance { FXS_DAO_min = min_FXS; } function setOwner(address _owner_address) external onlyByOwnerOrGovernance { owner_address = _owner_address; } function mint(address to, uint256 amount) public onlyPools { _mint(to, amount); } // This function is what other frax pools will call to mint new FXS (similar to the FRAX mint) function pool_mint(address m_address, uint256 m_amount) external onlyPools { if(trackingVotes){ uint32 srcRepNum = numCheckpoints[address(this)]; uint96 srcRepOld = srcRepNum > 0 ? checkpoints[address(this)][srcRepNum - 1].votes : 0; uint96 srcRepNew = add96(srcRepOld, uint96(m_amount), "pool_mint new votes overflows"); _writeCheckpoint(address(this), srcRepNum, srcRepOld, srcRepNew); // mint new votes trackVotes(address(this), m_address, uint96(m_amount)); } super._mint(m_address, m_amount); emit FXSMinted(address(this), m_address, m_amount); } // This function is what other frax pools will call to burn FXS function pool_burn_from(address b_address, uint256 b_amount) external onlyPools { if(trackingVotes){ trackVotes(b_address, address(this), uint96(b_amount)); uint32 srcRepNum = numCheckpoints[address(this)]; uint96 srcRepOld = srcRepNum > 0 ? checkpoints[address(this)][srcRepNum - 1].votes : 0; uint96 srcRepNew = sub96(srcRepOld, uint96(b_amount), "pool_burn_from new votes underflows"); _writeCheckpoint(address(this), srcRepNum, srcRepOld, srcRepNew); // burn votes } super._burnFrom(b_address, b_amount); emit FXSBurned(b_address, address(this), b_amount); } function toggleVotes() external onlyByOwnerOrGovernance { trackingVotes = !trackingVotes; } /* ========== OVERRIDDEN PUBLIC FUNCTIONS ========== */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { if(trackingVotes){ // Transfer votes trackVotes(_msgSender(), recipient, uint96(amount)); } _transfer(_msgSender(), recipient, amount); return true; } function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { if(trackingVotes){ // Transfer votes trackVotes(sender, recipient, uint96(amount)); } _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /* ========== PUBLIC FUNCTIONS ========== */ /** * @notice Gets the current votes balance for `account` * @param account The address to get votes balance * @return The number of current votes for `account` */ function getCurrentVotes(address account) external view returns (uint96) { uint32 nCheckpoints = numCheckpoints[account]; return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; } /** * @notice Determine the prior number of votes for an account as of a block number * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. * @param account The address of the account to check * @param blockNumber The block number to get the vote balance at * @return The number of votes the account had as of the given block */ function getPriorVotes(address account, uint blockNumber) public view returns (uint96) { require(blockNumber < block.number, "FXS::getPriorVotes: not yet determined"); uint32 nCheckpoints = numCheckpoints[account]; if (nCheckpoints == 0) { return 0; } // First check most recent balance if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { return checkpoints[account][nCheckpoints - 1].votes; } // Next check implicit zero balance if (checkpoints[account][0].fromBlock > blockNumber) { return 0; } uint32 lower = 0; uint32 upper = nCheckpoints - 1; while (upper > lower) { uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow Checkpoint memory cp = checkpoints[account][center]; if (cp.fromBlock == blockNumber) { return cp.votes; } else if (cp.fromBlock < blockNumber) { lower = center; } else { upper = center - 1; } } return checkpoints[account][lower].votes; } /* ========== INTERNAL FUNCTIONS ========== */ // From compound's _moveDelegates // Keep track of votes. "Delegates" is a misnomer here function trackVotes(address srcRep, address dstRep, uint96 amount) internal { if (srcRep != dstRep && amount > 0) { if (srcRep != address(0)) { uint32 srcRepNum = numCheckpoints[srcRep]; uint96 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; uint96 srcRepNew = sub96(srcRepOld, amount, "FXS::_moveVotes: vote amount underflows"); _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); } if (dstRep != address(0)) { uint32 dstRepNum = numCheckpoints[dstRep]; uint96 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; uint96 dstRepNew = add96(dstRepOld, amount, "FXS::_moveVotes: vote amount overflows"); _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); } } } function _writeCheckpoint(address voter, uint32 nCheckpoints, uint96 oldVotes, uint96 newVotes) internal { uint32 blockNumber = safe32(block.number, "FXS::_writeCheckpoint: block number exceeds 32 bits"); if (nCheckpoints > 0 && checkpoints[voter][nCheckpoints - 1].fromBlock == blockNumber) { checkpoints[voter][nCheckpoints - 1].votes = newVotes; } else { checkpoints[voter][nCheckpoints] = Checkpoint(blockNumber, newVotes); numCheckpoints[voter] = nCheckpoints + 1; } emit VoterVotesChanged(voter, oldVotes, newVotes); } function safe32(uint n, string memory errorMessage) internal pure returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function safe96(uint n, string memory errorMessage) internal pure returns (uint96) { require(n < 2**96, errorMessage); return uint96(n); } function add96(uint96 a, uint96 b, string memory errorMessage) internal pure returns (uint96) { uint96 c = a + b; require(c >= a, errorMessage); return c; } function sub96(uint96 a, uint96 b, string memory errorMessage) internal pure returns (uint96) { require(b <= a, errorMessage); return a - b; } function getChainId() internal pure returns (uint) { uint256 chainId; assembly { chainId := chainid() } return chainId; } /* ========== EVENTS ========== */ /// @notice An event thats emitted when a voters account's vote balance changes event VoterVotesChanged(address indexed voter, uint previousBalance, uint newBalance); // Track FXS burned event FXSBurned(address indexed from, address indexed to, uint256 amount); // Track FXS minted event FXSMinted(address indexed from, address indexed to, uint256 amount); }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; pragma experimental ABIEncoderV2; import "./FXS.sol"; // From https://compound.finance/docs/governance // and https://github.com/compound-finance/compound-protocol/tree/master/contracts/Governance contract GovernorAlpha { /// @notice The name of this contract string public constant name = "FXS Governor Alpha"; /// @notice The number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed function quorumVotes() public pure returns (uint) { return 4000000e18; } // 4,000,000 = 4% of FXS /// @notice The number of votes required in order for a voter to become a proposer function proposalThreshold() public pure returns (uint) { return 1000000e18; } // 1,000,000 = 1% of FXS /// @notice The maximum number of actions that can be included in a proposal function proposalMaxOperations() public pure returns (uint) { return 10; } // 10 actions /// @notice The delay before voting on a proposal may take place, once proposed // This also helps protect against flash loan attacks because only the vote balance at the proposal start block is considered function votingDelay() public pure returns (uint) { return 1; } // 1 block /// @notice The duration of voting on a proposal, in blocks // function votingPeriod() public pure returns (uint) { return 17280; } // ~3 days in blocks (assuming 15s blocks) uint public votingPeriod = 17280; /// @notice The address of the Timelock TimelockInterface public timelock; // The address of the FXS token FRAXShares public fxs; /// @notice The address of the Governor Guardian address public guardian; /// @notice The total number of proposals uint public proposalCount = 0; struct Proposal { // @notice Unique id for looking up a proposal uint id; // @notice Creator of the proposal address proposer; // @notice The timestamp that the proposal will be available for execution, set once the vote succeeds uint eta; // @notice the ordered list of target addresses for calls to be made address[] targets; // @notice The ordered list of values (i.e. msg.value) to be passed to the calls to be made uint[] values; // @notice The ordered list of function signatures to be called string[] signatures; // @notice The ordered list of calldata to be passed to each call bytes[] calldatas; // @notice The block at which voting begins: holders must delegate their votes prior to this block uint startBlock; // @notice The block at which voting ends: votes must be cast prior to this block uint endBlock; // @notice Current number of votes in favor of this proposal uint forVotes; // @notice Current number of votes in opposition to this proposal uint againstVotes; // @notice Flag marking whether the proposal has been canceled bool canceled; // @notice Flag marking whether the proposal has been executed bool executed; // @notice Title of the proposal (human-readable) string title; // @notice Description of the proposall (human-readable) string description; // @notice Receipts of ballots for the entire set of voters mapping (address => Receipt) receipts; } /// @notice Ballot receipt record for a voter struct Receipt { // @notice Whether or not a vote has been cast bool hasVoted; // @notice Whether or not the voter supports the proposal bool support; // @notice The number of votes the voter had, which were cast uint96 votes; } /// @notice Possible states that a proposal may be in enum ProposalState { Pending, Active, Canceled, Defeated, Succeeded, Queued, Expired, Executed } /// @notice The official record of all proposals ever proposed mapping (uint => Proposal) public proposals; /// @notice The latest proposal for each proposer mapping (address => uint) public latestProposalIds; /// @notice The EIP-712 typehash for the contract's domain bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"); /// @notice The EIP-712 typehash for the ballot struct used by the contract bytes32 public constant BALLOT_TYPEHASH = keccak256("Ballot(uint256 proposalId,bool support)"); /// @notice An event emitted when a new proposal is created event ProposalCreated(uint id, address proposer, address[] targets, uint[] values, string[] signatures, bytes[] calldatas, uint startBlock, uint endBlock, string description); /// @notice An event emitted when a vote has been cast on a proposal event VoteCast(address voter, uint proposalId, bool support, uint votes); /// @notice An event emitted when a proposal has been canceled event ProposalCanceled(uint id); /// @notice An event emitted when a proposal has been queued in the Timelock event ProposalQueued(uint id, uint eta); /// @notice An event emitted when a proposal has been executed in the Timelock event ProposalExecuted(uint id); constructor(address timelock_, address fxs_, address guardian_) public { timelock = TimelockInterface(timelock_); fxs = FRAXShares(fxs_); guardian = guardian_; } function propose(address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory title, string memory description) public returns (uint) { require(fxs.getPriorVotes(msg.sender, sub256(block.number, 1)) >= proposalThreshold(), "GovernorAlpha::propose: proposer votes below proposal threshold"); require(targets.length == values.length && targets.length == signatures.length && targets.length == calldatas.length, "GovernorAlpha::propose: proposal function information arity mismatch"); require(targets.length != 0, "GovernorAlpha::propose: must provide actions"); require(targets.length <= proposalMaxOperations(), "GovernorAlpha::propose: too many actions"); uint latestProposalId = latestProposalIds[msg.sender]; if (latestProposalId != 0) { ProposalState proposersLatestProposalState = state(latestProposalId); require(proposersLatestProposalState != ProposalState.Active, "GovernorAlpha::propose: one live proposal per proposer, found an already active proposal"); require(proposersLatestProposalState != ProposalState.Pending, "GovernorAlpha::propose: one live proposal per proposer, found an already pending proposal"); } uint startBlock = add256(block.number, votingDelay()); uint endBlock = add256(startBlock, votingPeriod); proposalCount++; Proposal memory newProposal = Proposal({ id: proposalCount, proposer: msg.sender, eta: 0, targets: targets, values: values, signatures: signatures, calldatas: calldatas, startBlock: startBlock, endBlock: endBlock, forVotes: 0, againstVotes: 0, canceled: false, executed: false, title: title, description: description }); proposals[newProposal.id] = newProposal; latestProposalIds[newProposal.proposer] = newProposal.id; emit ProposalCreated(newProposal.id, msg.sender, targets, values, signatures, calldatas, startBlock, endBlock, description); return newProposal.id; } function queue(uint proposalId) public { require(state(proposalId) == ProposalState.Succeeded, "GovernorAlpha::queue: proposal can only be queued if it succeeded"); Proposal storage proposal = proposals[proposalId]; uint eta = add256(block.timestamp, timelock.delay()); for (uint i = 0; i < proposal.targets.length; i++) { _queueOrRevert(proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], eta); } proposal.eta = eta; emit ProposalQueued(proposalId, eta); } function _queueOrRevert(address target, uint value, string memory signature, bytes memory data, uint eta) internal { require(!timelock.queuedTransactions(keccak256(abi.encode(target, value, signature, data, eta))), "GovernorAlpha::_queueOrRevert: proposal action already queued at eta"); timelock.queueTransaction(target, value, signature, data, eta); } function execute(uint proposalId) public payable { require(state(proposalId) == ProposalState.Queued, "GovernorAlpha::execute: proposal can only be executed if it is queued"); Proposal storage proposal = proposals[proposalId]; proposal.executed = true; for (uint i = 0; i < proposal.targets.length; i++) { timelock.executeTransaction(proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], proposal.eta); } emit ProposalExecuted(proposalId); } function cancel(uint proposalId) public { ProposalState state = state(proposalId); require(state != ProposalState.Executed, "GovernorAlpha::cancel: cannot cancel executed proposal"); Proposal storage proposal = proposals[proposalId]; require(msg.sender == guardian || fxs.getPriorVotes(proposal.proposer, sub256(block.number, 1)) < proposalThreshold(), "GovernorAlpha::cancel: proposer at or above threshold"); proposal.canceled = true; for (uint i = 0; i < proposal.targets.length; i++) { timelock.cancelTransaction(proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], proposal.eta); } emit ProposalCanceled(proposalId); } function getActions(uint proposalId) public view returns (address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas) { Proposal storage p = proposals[proposalId]; return (p.targets, p.values, p.signatures, p.calldatas); } function getReceipt(uint proposalId, address voter) public view returns (Receipt memory) { return proposals[proposalId].receipts[voter]; } function state(uint proposalId) public view returns (ProposalState) { require(proposalCount >= proposalId && proposalId > 0, "GovernorAlpha::state: invalid proposal id"); Proposal storage proposal = proposals[proposalId]; if (proposal.canceled) { return ProposalState.Canceled; } else if (block.number <= proposal.startBlock) { return ProposalState.Pending; } else if (block.number <= proposal.endBlock) { return ProposalState.Active; } else if (proposal.forVotes <= proposal.againstVotes || proposal.forVotes < quorumVotes()) { return ProposalState.Defeated; } else if (proposal.eta == 0) { return ProposalState.Succeeded; } else if (proposal.executed) { return ProposalState.Executed; } else if (block.timestamp >= add256(proposal.eta, timelock.GRACE_PERIOD())) { return ProposalState.Expired; } else { return ProposalState.Queued; } } function castVote(uint proposalId, bool support) public { return _castVote(msg.sender, proposalId, support); } function castVoteBySig(uint proposalId, bool support, uint8 v, bytes32 r, bytes32 s) public { bytes32 domainSeparator = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), getChainId(), address(this))); bytes32 structHash = keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support)); bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); address signatory = ecrecover(digest, v, r, s); require(signatory != address(0), "GovernorAlpha::castVoteBySig: invalid signature"); return _castVote(signatory, proposalId, support); } function _castVote(address voter, uint proposalId, bool support) internal { require(state(proposalId) == ProposalState.Active, "GovernorAlpha::_castVote: voting is closed"); Proposal storage proposal = proposals[proposalId]; Receipt storage receipt = proposal.receipts[voter]; require(receipt.hasVoted == false, "GovernorAlpha::_castVote: voter already voted"); uint96 votes = fxs.getPriorVotes(voter, proposal.startBlock); if (support) { proposal.forVotes = add256(proposal.forVotes, votes); } else { proposal.againstVotes = add256(proposal.againstVotes, votes); } receipt.hasVoted = true; receipt.support = support; receipt.votes = votes; emit VoteCast(voter, proposalId, support, votes); } function __acceptAdmin() public { require(msg.sender == guardian, "GovernorAlpha::__acceptAdmin: sender must be gov guardian"); timelock.acceptAdmin(); } function __abdicate() public { require(msg.sender == guardian, "GovernorAlpha::__abdicate: sender must be gov guardian"); guardian = address(0); } function __setVotingPeriod(uint period) public { require(msg.sender == guardian, "GovernorAlpha::__setVotingPeriod: sender must be gov guardian"); votingPeriod = period; } function __setTimelockAddress(address timelock_) public { require(msg.sender == guardian, "GovernorAlpha::__setTimelockAddress: sender must be gov guardian"); timelock = TimelockInterface(timelock_); } function __queueSetTimelockPendingAdmin(address newPendingAdmin, uint eta) public { require(msg.sender == guardian, "GovernorAlpha::__queueSetTimelockPendingAdmin: sender must be gov guardian"); timelock.queueTransaction(address(timelock), 0, "setPendingAdmin(address)", abi.encode(newPendingAdmin), eta); } function __executeSetTimelockPendingAdmin(address newPendingAdmin, uint eta) public { require(msg.sender == guardian, "GovernorAlpha::__executeSetTimelockPendingAdmin: sender must be gov guardian"); timelock.executeTransaction(address(timelock), 0, "setPendingAdmin(address)", abi.encode(newPendingAdmin), eta); } function add256(uint256 a, uint256 b) internal pure returns (uint) { uint c = a + b; require(c >= a, "addition overflow"); return c; } function sub256(uint256 a, uint256 b) internal pure returns (uint) { require(b <= a, "subtraction underflow"); return a - b; } function getChainId() internal pure returns (uint) { uint chainId; assembly { chainId := chainid() } return chainId; } } interface TimelockInterface { function delay() external view returns (uint); function GRACE_PERIOD() external view returns (uint); function acceptAdmin() external; function queuedTransactions(bytes32 hash) external view returns (bool); function queueTransaction(address target, uint value, string calldata signature, bytes calldata data, uint eta) external returns (bytes32); function cancelTransaction(address target, uint value, string calldata signature, bytes calldata data, uint eta) external; function executeTransaction(address target, uint value, string calldata signature, bytes calldata data, uint eta) external payable returns (bytes memory); }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./Context.sol"; import "./SafeMath.sol"; /** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see {ERC20Detailed}. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; interface IStakingRewards { // Views function lastTimeRewardApplicable() external view returns (uint256); function rewardPerToken() external view returns (uint256); function earned(address account) external view returns (uint256); function getRewardForDuration() external view returns (uint256); function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); // Mutative function stake(uint256 amount) external; function withdraw(uint256 amount) external; function getReward() external; //function exit() external; }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; interface IUniswapV2Callee { function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; interface IUniswapV2ERC20 { 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; }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; interface IUniswapV2Factory { event PairCreated(address indexed token0, address indexed token1, address pair, uint); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function getPair(address tokenA, address tokenB) external view returns (address pair); function allPairs(uint) external view returns (address pair); function allPairsLength() external view returns (uint); function createPair(address tokenA, address tokenB) external returns (address pair); function setFeeTo(address) external; function setFeeToSetter(address) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; interface IUniswapV2Pair { 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; }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './IUniswapV2Router01.sol'; interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; interface IWETH { function deposit() external payable; function transfer(address to, uint value) external returns (bool); function transferFrom(address src, address dst, uint wad) external returns (bool); function withdraw(uint) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow, so we distribute return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2); } // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method) function sqrt(uint y) internal pure returns (uint z) { if (y > 3) { z = y; uint x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } } else if (y != 0) { z = 1; } } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; contract MigrationHelper { address public owner; uint256 public gov_to_timelock_eta; modifier restricted() { if (msg.sender == owner) _; } constructor(address _owner) public { owner = _owner; } function setGovToTimeLockETA(uint256 _eta) public restricted { gov_to_timelock_eta = _eta; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; contract Migrations { address public owner; uint public last_completed_migration; modifier restricted() { if (msg.sender == owner) _; } constructor() public { owner = msg.sender; } function setCompleted(uint completed) public restricted { last_completed_migration = completed; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; // https://docs.synthetix.io/contracts/Owned contract Owned { address public owner; address public nominatedOwner; constructor(address _owner) public { require(_owner != address(0), "Owner address cannot be 0"); owner = _owner; emit OwnerChanged(address(0), _owner); } function nominateNewOwner(address _owner) external onlyOwner { nominatedOwner = _owner; emit OwnerNominated(_owner); } function acceptOwnership() external { require(msg.sender == nominatedOwner, "You must be nominated before you can accept ownership"); emit OwnerChanged(owner, nominatedOwner); owner = nominatedOwner; nominatedOwner = address(0); } modifier onlyOwner { require(msg.sender == owner, "Only the contract owner may perform this action"); _; } event OwnerNominated(address newOwner); event OwnerChanged(address oldOwner, address newOwner); }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; // Inheritance import "./Owned.sol"; // https://docs.synthetix.io/contracts/Pausable abstract contract Pausable is Owned { uint public lastPauseTime; bool public paused; constructor() internal { // This contract is abstract, and thus cannot be instantiated directly require(owner != address(0), "Owner must be set"); // Paused will be false, and lastPauseTime will be 0 upon initialisation } /** * @notice Change the paused state of the contract * @dev Only the contract owner may call this. */ function setPaused(bool _paused) external onlyOwner { // Ensure we're actually changing the state before we do anything if (_paused == paused) { return; } // Set our paused state. paused = _paused; // If applicable, set the last pause time. if (paused) { lastPauseTime = now; } // Let everyone know that our pause state has changed. emit PauseChanged(paused); } event PauseChanged(bool isPaused); modifier notPaused { require(!paused, "This action cannot be performed while the contract is paused"); _; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./FraxPool.sol"; contract Pool_USDC is FraxPool { address public USDC_address; constructor( address _frax_contract_address, address _fxs_contract_address, address _collateral_address, address _creator_address, address _timelock_address, uint256 _pool_ceiling ) FraxPool(_frax_contract_address, _fxs_contract_address, _collateral_address, _creator_address, _timelock_address, _pool_ceiling) public { _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); USDC_address = _collateral_address; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./FraxPool.sol"; contract Pool_USDT is FraxPool { address public USDT_address; constructor( address _frax_contract_address, address _fxs_contract_address, address _collateral_address, address _creator_address, address _timelock_address, uint256 _pool_ceiling ) FraxPool(_frax_contract_address, _fxs_contract_address, _collateral_address, _creator_address, _timelock_address, _pool_ceiling) public { _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); USDT_address = _collateral_address; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; /** * @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]. */ 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 () internal { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; // Inheritance import "./Owned.sol"; // https://docs.synthetix.io/contracts/RewardsDistributionRecipient abstract contract RewardsDistributionRecipient is Owned { address public rewardsDistribution; //function notifyRewardAmount(uint256 reward) external virtual; modifier onlyRewardsDistribution() { require(msg.sender == rewardsDistribution, "Caller is not RewardsDistribution contract"); _; } function setRewardsDistribution(address _rewardsDistribution) external onlyOwner { rewardsDistribution = _rewardsDistribution; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./IERC20.sol"; import "./SafeMath.sol"; import "./Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; 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' // solhint-disable-next-line max-line-length 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).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; pragma experimental ABIEncoderV2; import "./StakingRewards.sol"; contract Stake_FRAX_FXS is StakingRewards { constructor( address _owner, address _rewardsDistribution, address _rewardsToken, address _stakingToken, address _frax_address, address _timelock_address, uint256 _pool_weight ) StakingRewards(_owner, _rewardsDistribution, _rewardsToken, _stakingToken, _frax_address, _timelock_address, _pool_weight) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; pragma experimental ABIEncoderV2; import "./StakingRewards.sol"; contract Stake_FRAX_USDC is StakingRewards { constructor( address _owner, address _rewardsDistribution, address _rewardsToken, address _stakingToken, address _frax_address, address _timelock_address, uint256 _pool_weight ) StakingRewards(_owner, _rewardsDistribution, _rewardsToken, _stakingToken, _frax_address, _timelock_address, _pool_weight) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; pragma experimental ABIEncoderV2; import "./StakingRewards.sol"; contract Stake_FRAX_WETH is StakingRewards { constructor( address _owner, address _rewardsDistribution, address _rewardsToken, address _stakingToken, address _frax_address, address _timelock_address, uint256 _pool_weight ) StakingRewards(_owner, _rewardsDistribution, _rewardsToken, _stakingToken, _frax_address, _timelock_address, _pool_weight) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; pragma experimental ABIEncoderV2; import "./StakingRewards.sol"; contract Stake_FXS_WETH is StakingRewards { constructor( address _owner, address _rewardsDistribution, address _rewardsToken, address _stakingToken, address _frax_address, address _timelock_address, uint256 _pool_weight ) StakingRewards(_owner, _rewardsDistribution, _rewardsToken, _stakingToken, _frax_address, _timelock_address, _pool_weight) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; pragma experimental ABIEncoderV2; // Stolen with love from Synthetixio // https://raw.githubusercontent.com/Synthetixio/synthetix/develop/contracts/StakingRewards.sol import "./Math.sol"; import "./SafeMath.sol"; import "./ERC20.sol"; import './TransferHelper.sol'; import "./SafeERC20.sol"; import "./Frax.sol"; import "./ReentrancyGuard.sol"; import "./StringHelpers.sol"; // Inheritance import "./IStakingRewards.sol"; import "./RewardsDistributionRecipient.sol"; import "./Pausable.sol"; contract StakingRewards is IStakingRewards, RewardsDistributionRecipient, ReentrancyGuard, Pausable { using SafeMath for uint256; using SafeERC20 for ERC20; /* ========== STATE VARIABLES ========== */ FRAXStablecoin private FRAX; ERC20 public rewardsToken; ERC20 public stakingToken; uint256 public periodFinish; // Constant for various precisions uint256 private constant PRICE_PRECISION = 1e6; uint256 private constant MULTIPLIER_BASE = 1e6; // Max reward per second uint256 public rewardRate; // uint256 public rewardsDuration = 86400 hours; uint256 public rewardsDuration = 604800; // 7 * 86400 (7 days) uint256 public lastUpdateTime; uint256 public rewardPerTokenStored = 0; uint256 private pool_weight; // This staking pool's percentage of the total FXS being distributed by all pools, 6 decimals of precision address public owner_address; address public timelock_address; // Governance timelock address uint256 public locked_stake_max_multiplier = 3000000; // 6 decimals of precision. 1x = 1000000 uint256 public locked_stake_time_for_max_multiplier = 3 * 365 * 86400; // 3 years uint256 public locked_stake_min_time = 604800; // 7 * 86400 (7 days) string private locked_stake_min_time_str = "604800"; // 7 days on genesis uint256 public cr_boost_max_multiplier = 3000000; // 6 decimals of precision. 1x = 1000000 mapping(address => uint256) public userRewardPerTokenPaid; mapping(address => uint256) public rewards; uint256 private _staking_token_supply = 0; uint256 private _staking_token_boosted_supply = 0; mapping(address => uint256) private _unlocked_balances; mapping(address => uint256) private _locked_balances; mapping(address => uint256) private _boosted_balances; mapping(address => LockedStake[]) private lockedStakes; mapping(address => bool) public greylist; bool public unlockedStakes; // Release lock stakes in case of system migration struct LockedStake { bytes32 kek_id; uint256 start_timestamp; uint256 amount; uint256 ending_timestamp; uint256 multiplier; // 6 decimals of precision. 1x = 1000000 } /* ========== CONSTRUCTOR ========== */ constructor( address _owner, address _rewardsDistribution, address _rewardsToken, address _stakingToken, address _frax_address, address _timelock_address, uint256 _pool_weight ) public Owned(_owner){ owner_address = _owner; rewardsToken = ERC20(_rewardsToken); stakingToken = ERC20(_stakingToken); FRAX = FRAXStablecoin(_frax_address); rewardsDistribution = _rewardsDistribution; lastUpdateTime = block.timestamp; timelock_address = _timelock_address; pool_weight = _pool_weight; rewardRate = 380517503805175038; // (uint256(12000000e18)).div(365 * 86400); // Base emission rate of 12M FXS over the first year rewardRate = rewardRate.mul(pool_weight).div(1e6); unlockedStakes = false; } /* ========== VIEWS ========== */ function totalSupply() external override view returns (uint256) { return _staking_token_supply; } function totalBoostedSupply() external view returns (uint256) { return _staking_token_boosted_supply; } function stakingMultiplier(uint256 secs) public view returns (uint256) { uint256 multiplier = uint(MULTIPLIER_BASE).add(secs.mul(locked_stake_max_multiplier.sub(MULTIPLIER_BASE)).div(locked_stake_time_for_max_multiplier)); if (multiplier > locked_stake_max_multiplier) multiplier = locked_stake_max_multiplier; return multiplier; } function crBoostMultiplier() public view returns (uint256) { uint256 multiplier = uint(MULTIPLIER_BASE).add((uint(MULTIPLIER_BASE).sub(FRAX.global_collateral_ratio())).mul(cr_boost_max_multiplier.sub(MULTIPLIER_BASE)).div(MULTIPLIER_BASE) ); return multiplier; } // Total unlocked and locked liquidity tokens function balanceOf(address account) external override view returns (uint256) { return (_unlocked_balances[account]).add(_locked_balances[account]); } // Total unlocked liquidity tokens function unlockedBalanceOf(address account) external view returns (uint256) { return _unlocked_balances[account]; } // Total locked liquidity tokens function lockedBalanceOf(address account) public view returns (uint256) { return _locked_balances[account]; } // Total 'balance' used for calculating the percent of the pool the account owns // Takes into account the locked stake time multiplier function boostedBalanceOf(address account) external view returns (uint256) { return _boosted_balances[account]; } function lockedStakesOf(address account) external view returns (LockedStake[] memory) { return lockedStakes[account]; } function stakingDecimals() external view returns (uint256) { return stakingToken.decimals(); } function rewardsFor(address account) external view returns (uint256) { // You may have use earned() instead, because of the order in which the contract executes return rewards[account]; } function lastTimeRewardApplicable() public override view returns (uint256) { return Math.min(block.timestamp, periodFinish); } function rewardPerToken() public override view returns (uint256) { if (_staking_token_supply == 0) { return rewardPerTokenStored; } else { return rewardPerTokenStored.add( lastTimeRewardApplicable().sub(lastUpdateTime).mul(rewardRate).mul(crBoostMultiplier()).mul(1e18).div(PRICE_PRECISION).div(_staking_token_boosted_supply) ); } } function earned(address account) public override view returns (uint256) { return _boosted_balances[account].mul(rewardPerToken().sub(userRewardPerTokenPaid[account])).div(1e18).add(rewards[account]); } // function earned(address account) public override view returns (uint256) { // return _balances[account].mul(rewardPerToken().sub(userRewardPerTokenPaid[account])).add(rewards[account]); // } function getRewardForDuration() external override view returns (uint256) { return rewardRate.mul(rewardsDuration).mul(crBoostMultiplier()).div(PRICE_PRECISION); } /* ========== MUTATIVE FUNCTIONS ========== */ function stake(uint256 amount) external override nonReentrant notPaused updateReward(msg.sender) { require(amount > 0, "Cannot stake 0"); require(greylist[msg.sender] == false, "address has been greylisted"); // Pull the tokens from the staker TransferHelper.safeTransferFrom(address(stakingToken), msg.sender, address(this), amount); // Staking token supply and boosted supply _staking_token_supply = _staking_token_supply.add(amount); _staking_token_boosted_supply = _staking_token_boosted_supply.add(amount); // Staking token balance and boosted balance _unlocked_balances[msg.sender] = _unlocked_balances[msg.sender].add(amount); _boosted_balances[msg.sender] = _boosted_balances[msg.sender].add(amount); emit Staked(msg.sender, amount); } function stakeLocked(uint256 amount, uint256 secs) external nonReentrant notPaused updateReward(msg.sender) { require(amount > 0, "Cannot stake 0"); require(secs > 0, "Cannot wait for a negative number"); require(greylist[msg.sender] == false, "address has been greylisted"); require(secs >= locked_stake_min_time, StringHelpers.strConcat("Minimum stake time not met (", locked_stake_min_time_str, ")") ); uint256 multiplier = stakingMultiplier(secs); uint256 boostedAmount = amount.mul(multiplier).div(PRICE_PRECISION); lockedStakes[msg.sender].push(LockedStake( keccak256(abi.encodePacked(msg.sender, block.timestamp, amount)), block.timestamp, amount, block.timestamp.add(secs), multiplier )); // Pull the tokens from the staker TransferHelper.safeTransferFrom(address(stakingToken), msg.sender, address(this), amount); // Staking token supply and boosted supply _staking_token_supply = _staking_token_supply.add(amount); _staking_token_boosted_supply = _staking_token_boosted_supply.add(boostedAmount); // Staking token balance and boosted balance _locked_balances[msg.sender] = _locked_balances[msg.sender].add(amount); _boosted_balances[msg.sender] = _boosted_balances[msg.sender].add(boostedAmount); emit StakeLocked(msg.sender, amount, secs); } function withdraw(uint256 amount) public override nonReentrant updateReward(msg.sender) { require(amount > 0, "Cannot withdraw 0"); // Staking token balance and boosted balance _unlocked_balances[msg.sender] = _unlocked_balances[msg.sender].sub(amount); _boosted_balances[msg.sender] = _boosted_balances[msg.sender].sub(amount); // Staking token supply and boosted supply _staking_token_supply = _staking_token_supply.sub(amount); _staking_token_boosted_supply = _staking_token_boosted_supply.sub(amount); // Give the tokens to the withdrawer stakingToken.safeTransfer(msg.sender, amount); emit Withdrawn(msg.sender, amount); } function withdrawLocked(bytes32 kek_id) public nonReentrant updateReward(msg.sender) { LockedStake memory thisStake; thisStake.amount = 0; uint theIndex; for (uint i = 0; i < lockedStakes[msg.sender].length; i++){ if (kek_id == lockedStakes[msg.sender][i].kek_id){ thisStake = lockedStakes[msg.sender][i]; theIndex = i; break; } } require(thisStake.kek_id == kek_id, "Stake not found"); require(block.timestamp >= thisStake.ending_timestamp || unlockedStakes == true, "Stake is still locked!"); uint256 theAmount = thisStake.amount; uint256 boostedAmount = theAmount.mul(thisStake.multiplier).div(PRICE_PRECISION); if (theAmount > 0){ // Staking token balance and boosted balance _locked_balances[msg.sender] = _locked_balances[msg.sender].sub(theAmount); _boosted_balances[msg.sender] = _boosted_balances[msg.sender].sub(boostedAmount); // Staking token supply and boosted supply _staking_token_supply = _staking_token_supply.sub(theAmount); _staking_token_boosted_supply = _staking_token_boosted_supply.sub(boostedAmount); // Remove the stake from the array delete lockedStakes[msg.sender][theIndex]; // Give the tokens to the withdrawer stakingToken.safeTransfer(msg.sender, theAmount); emit WithdrawnLocked(msg.sender, theAmount, kek_id); } } function getReward() public override nonReentrant updateReward(msg.sender) { uint256 reward = rewards[msg.sender]; if (reward > 0) { rewards[msg.sender] = 0; rewardsToken.transfer(msg.sender, reward); emit RewardPaid(msg.sender, reward); } } /* function exit() external override { withdraw(_balances[msg.sender]); // TODO: Add locked stakes too? getReward(); } */ function renewIfApplicable() external { if (block.timestamp > periodFinish) { retroCatchUp(); } } // If the period expired, renew it function retroCatchUp() internal { // Failsafe check require(block.timestamp > periodFinish, "Period has not expired yet!"); // 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 num_periods_elapsed = uint256(block.timestamp.sub(periodFinish)) / rewardsDuration; // Floor division to the nearest period uint balance = rewardsToken.balanceOf(address(this)); require(rewardRate.mul(rewardsDuration).mul(crBoostMultiplier()).mul(num_periods_elapsed + 1).div(PRICE_PRECISION) <= balance, "Not enough FXS available for rewards!"); // uint256 old_lastUpdateTime = lastUpdateTime; // uint256 new_lastUpdateTime = block.timestamp; // lastUpdateTime = periodFinish; periodFinish = periodFinish.add((num_periods_elapsed.add(1)).mul(rewardsDuration)); rewardPerTokenStored = rewardPerToken(); lastUpdateTime = lastTimeRewardApplicable(); emit RewardsPeriodRenewed(address(stakingToken)); } /* ========== RESTRICTED FUNCTIONS ========== */ /* // This notifies people that the reward is being changed function notifyRewardAmount(uint256 reward) external override onlyRewardsDistribution updateReward(address(0)) { // Needed to make compiler happy // if (block.timestamp >= periodFinish) { // rewardRate = reward.mul(crBoostMultiplier()).div(rewardsDuration).div(PRICE_PRECISION); // } else { // uint256 remaining = periodFinish.sub(block.timestamp); // uint256 leftover = remaining.mul(rewardRate); // rewardRate = reward.mul(crBoostMultiplier()).add(leftover).div(rewardsDuration).div(PRICE_PRECISION); // } // // 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. // uint balance = rewardsToken.balanceOf(address(this)); // require(rewardRate <= balance.div(rewardsDuration), "Provided reward too high"); // lastUpdateTime = block.timestamp; // periodFinish = block.timestamp.add(rewardsDuration); // emit RewardAdded(reward); } */ // Added to support recovering LP Rewards from other systems to be distributed to holders function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyByOwnerOrGovernance { // Admin cannot withdraw the staking token from the contract require(tokenAddress != address(stakingToken)); ERC20(tokenAddress).transfer(owner_address, tokenAmount); emit Recovered(tokenAddress, tokenAmount); } function setRewardsDuration(uint256 _rewardsDuration) external onlyByOwnerOrGovernance { require( periodFinish == 0 || block.timestamp > periodFinish, "Previous rewards period must be complete before changing the duration for the new period" ); rewardsDuration = _rewardsDuration; emit RewardsDurationUpdated(rewardsDuration); } function setMultipliers(uint256 _locked_stake_max_multiplier, uint256 _cr_boost_max_multiplier) external onlyByOwnerOrGovernance { require(_locked_stake_max_multiplier >= 1, "Multiplier must be greater than or equal to 1"); require(_cr_boost_max_multiplier >= 1, "Max CR Boost must be greater than or equal to 1"); locked_stake_max_multiplier = _locked_stake_max_multiplier; cr_boost_max_multiplier = _cr_boost_max_multiplier; emit MaxCRBoostMultiplier(cr_boost_max_multiplier); emit LockedStakeMaxMultiplierUpdated(locked_stake_max_multiplier); } function setLockedStakeTimeForMinAndMaxMultiplier(uint256 _locked_stake_time_for_max_multiplier, uint256 _locked_stake_min_time) external onlyByOwnerOrGovernance { require(_locked_stake_time_for_max_multiplier >= 1, "Multiplier Max Time must be greater than or equal to 1"); require(_locked_stake_min_time >= 1, "Multiplier Min Time must be greater than or equal to 1"); locked_stake_time_for_max_multiplier = _locked_stake_time_for_max_multiplier; locked_stake_min_time = _locked_stake_min_time; locked_stake_min_time_str = StringHelpers.uint2str(_locked_stake_min_time); emit LockedStakeTimeForMaxMultiplier(locked_stake_time_for_max_multiplier); emit LockedStakeMinTime(_locked_stake_min_time); } function initializeDefault() external onlyByOwnerOrGovernance { lastUpdateTime = block.timestamp; periodFinish = block.timestamp.add(rewardsDuration); emit DefaultInitialization(); } function greylistAddress(address _address) external onlyByOwnerOrGovernance { greylist[_address] = !(greylist[_address]); } function unlockStakes() external onlyByOwnerOrGovernance { unlockedStakes = !unlockedStakes; } function setRewardRate(uint256 _new_rate) external onlyByOwnerOrGovernance { rewardRate = _new_rate; } function setOwnerAndTimelock(address _new_owner, address _new_timelock) external onlyByOwnerOrGovernance { owner_address = _new_owner; timelock_address = _new_timelock; } /* ========== MODIFIERS ========== */ modifier updateReward(address account) { // Need to retro-adjust some things if the period hasn't been renewed, then start a new one if (block.timestamp > periodFinish) { retroCatchUp(); } else { rewardPerTokenStored = rewardPerToken(); lastUpdateTime = lastTimeRewardApplicable(); } if (account != address(0)) { rewards[account] = earned(account); userRewardPerTokenPaid[account] = rewardPerTokenStored; } _; } modifier onlyByOwnerOrGovernance() { require(msg.sender == owner_address || msg.sender == timelock_address, "You are not the owner or the governance timelock"); _; } /* ========== EVENTS ========== */ event RewardAdded(uint256 reward); event Staked(address indexed user, uint256 amount); event StakeLocked(address indexed user, uint256 amount, uint256 secs); event Withdrawn(address indexed user, uint256 amount); event WithdrawnLocked(address indexed user, uint256 amount, bytes32 kek_id); event RewardPaid(address indexed user, uint256 reward); event RewardsDurationUpdated(uint256 newDuration); event Recovered(address token, uint256 amount); event RewardsPeriodRenewed(address token); event DefaultInitialization(); event LockedStakeMaxMultiplierUpdated(uint256 multiplier); event LockedStakeTimeForMaxMultiplier(uint256 secs); event LockedStakeMinTime(uint256 secs); event MaxCRBoostMultiplier(uint256 multiplier); }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; library StringHelpers { function parseAddr(string memory _a) internal pure returns (address _parsedAddress) { bytes memory tmp = bytes(_a); uint160 iaddr = 0; uint160 b1; uint160 b2; for (uint i = 2; i < 2 + 2 * 20; i += 2) { iaddr *= 256; b1 = uint160(uint8(tmp[i])); b2 = uint160(uint8(tmp[i + 1])); if ((b1 >= 97) && (b1 <= 102)) { b1 -= 87; } else if ((b1 >= 65) && (b1 <= 70)) { b1 -= 55; } else if ((b1 >= 48) && (b1 <= 57)) { b1 -= 48; } if ((b2 >= 97) && (b2 <= 102)) { b2 -= 87; } else if ((b2 >= 65) && (b2 <= 70)) { b2 -= 55; } else if ((b2 >= 48) && (b2 <= 57)) { b2 -= 48; } iaddr += (b1 * 16 + b2); } return address(iaddr); } function strCompare(string memory _a, string memory _b) internal pure returns (int _returnCode) { bytes memory a = bytes(_a); bytes memory b = bytes(_b); uint minLength = a.length; if (b.length < minLength) { minLength = b.length; } for (uint i = 0; i < minLength; i ++) { if (a[i] < b[i]) { return -1; } else if (a[i] > b[i]) { return 1; } } if (a.length < b.length) { return -1; } else if (a.length > b.length) { return 1; } else { return 0; } } function indexOf(string memory _haystack, string memory _needle) internal pure returns (int _returnCode) { bytes memory h = bytes(_haystack); bytes memory n = bytes(_needle); if (h.length < 1 || n.length < 1 || (n.length > h.length)) { return -1; } else if (h.length > (2 ** 128 - 1)) { return -1; } else { uint subindex = 0; for (uint i = 0; i < h.length; i++) { if (h[i] == n[0]) { subindex = 1; while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex]) { subindex++; } if (subindex == n.length) { return int(i); } } } return -1; } } function strConcat(string memory _a, string memory _b) internal pure returns (string memory _concatenatedString) { return strConcat(_a, _b, "", "", ""); } function strConcat(string memory _a, string memory _b, string memory _c) internal pure returns (string memory _concatenatedString) { return strConcat(_a, _b, _c, "", ""); } function strConcat(string memory _a, string memory _b, string memory _c, string memory _d) internal pure returns (string memory _concatenatedString) { return strConcat(_a, _b, _c, _d, ""); } function strConcat(string memory _a, string memory _b, string memory _c, string memory _d, string memory _e) internal pure returns (string memory _concatenatedString) { bytes memory _ba = bytes(_a); bytes memory _bb = bytes(_b); bytes memory _bc = bytes(_c); bytes memory _bd = bytes(_d); bytes memory _be = bytes(_e); string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); bytes memory babcde = bytes(abcde); uint k = 0; uint i = 0; for (i = 0; i < _ba.length; i++) { babcde[k++] = _ba[i]; } for (i = 0; i < _bb.length; i++) { babcde[k++] = _bb[i]; } for (i = 0; i < _bc.length; i++) { babcde[k++] = _bc[i]; } for (i = 0; i < _bd.length; i++) { babcde[k++] = _bd[i]; } for (i = 0; i < _be.length; i++) { babcde[k++] = _be[i]; } return string(babcde); } function safeParseInt(string memory _a) internal pure returns (uint _parsedInt) { return safeParseInt(_a, 0); } function safeParseInt(string memory _a, uint _b) internal pure returns (uint _parsedInt) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i = 0; i < bresult.length; i++) { if ((uint(uint8(bresult[i])) >= 48) && (uint(uint8(bresult[i])) <= 57)) { if (decimals) { if (_b == 0) break; else _b--; } mint *= 10; mint += uint(uint8(bresult[i])) - 48; } else if (uint(uint8(bresult[i])) == 46) { require(!decimals, 'More than one decimal encountered in string!'); decimals = true; } else { revert("Non-numeral character encountered in string!"); } } if (_b > 0) { mint *= 10 ** _b; } return mint; } function parseInt(string memory _a) internal pure returns (uint _parsedInt) { return parseInt(_a, 0); } function parseInt(string memory _a, uint _b) internal pure returns (uint _parsedInt) { bytes memory bresult = bytes(_a); uint mint = 0; bool decimals = false; for (uint i = 0; i < bresult.length; i++) { if ((uint(uint8(bresult[i])) >= 48) && (uint(uint8(bresult[i])) <= 57)) { if (decimals) { if (_b == 0) { break; } else { _b--; } } mint *= 10; mint += uint(uint8(bresult[i])) - 48; } else if (uint(uint8(bresult[i])) == 46) { decimals = true; } } if (_b > 0) { mint *= 10 ** _b; } return mint; } function uint2str(uint _i) internal pure returns (string memory _uintAsString) { if (_i == 0) { return "0"; } uint j = _i; uint len; while (j != 0) { len++; j /= 10; } bytes memory bstr = new bytes(len); uint k = len - 1; while (_i != 0) { bstr[k--] = byte(uint8(48 + _i % 10)); _i /= 10; } return string(bstr); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './IUniswapV2Pair.sol'; import './Babylonian.sol'; import './SafeMath.sol'; import './TransferHelper.sol'; import './IERC20.sol'; import './IUniswapV2Router01.sol'; import './UniswapV2Library.sol'; contract SwapToPrice { using SafeMath for uint256; IUniswapV2Router01 public immutable router; address public immutable factory; constructor(address factory_, IUniswapV2Router01 router_) public { factory = factory_; router = router_; } // computes the direction and magnitude of the profit-maximizing trade function computeProfitMaximizingTrade( uint256 truePriceTokenA, uint256 truePriceTokenB, uint256 reserveA, uint256 reserveB ) pure public returns (bool aToB, uint256 amountIn) { aToB = reserveA.mul(truePriceTokenB) / reserveB < truePriceTokenA; uint256 invariant = reserveA.mul(reserveB); uint256 leftSide = Babylonian.sqrt( invariant.mul(aToB ? truePriceTokenA : truePriceTokenB).mul(1000) / uint256(aToB ? truePriceTokenB : truePriceTokenA).mul(997) ); uint256 rightSide = (aToB ? reserveA.mul(1000) : reserveB.mul(1000)) / 997; // compute the amount that must be sent to move the price to the profit-maximizing price amountIn = leftSide.sub(rightSide); } // swaps an amount of either token such that the trade is profit-maximizing, given an external true price // true price is expressed in the ratio of token A to token B // caller must approve this contract to spend whichever token is intended to be swapped function swapToPrice( address tokenA, address tokenB, uint256 truePriceTokenA, uint256 truePriceTokenB, uint256 maxSpendTokenA, uint256 maxSpendTokenB, address to, uint256 deadline ) public { // true price is expressed as a ratio, so both values must be non-zero require(truePriceTokenA != 0 && truePriceTokenB != 0, "ExampleSwapToPrice: ZERO_PRICE"); // caller can specify 0 for either if they wish to swap in only one direction, but not both require(maxSpendTokenA != 0 || maxSpendTokenB != 0, "ExampleSwapToPrice: ZERO_SPEND"); bool aToB; uint256 amountIn; { (uint256 reserveA, uint256 reserveB) = UniswapV2Library.getReserves(factory, tokenA, tokenB); (aToB, amountIn) = computeProfitMaximizingTrade( truePriceTokenA, truePriceTokenB, reserveA, reserveB ); } // spend up to the allowance of the token in uint256 maxSpend = aToB ? maxSpendTokenA : maxSpendTokenB; if (amountIn > maxSpend) { amountIn = maxSpend; } address tokenIn = aToB ? tokenA : tokenB; address tokenOut = aToB ? tokenB : tokenA; TransferHelper.safeTransferFrom(tokenIn, msg.sender, address(this), amountIn); TransferHelper.safeApprove(tokenIn, address(router), amountIn); address[] memory path = new address[](2); path[0] = tokenIn; path[1] = tokenOut; router.swapExactTokensForTokens( amountIn, 0, // amountOutMin: we can skip computing this number because the math is tested path, to, deadline ); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./FakeCollateral_USDT.sol"; import "./FakeCollateral_WETH.sol"; import "./UniswapV2Router02_Modified.sol"; /* IGNORE THIS CONTRACT, ONLY USED FOR TESTING PURPOSES */ contract TestSwap { address public USDT_address; address public WETH_address; UniswapV2Router02_Modified public router; FakeCollateral_USDT USDT = FakeCollateral_USDT(USDT); FakeCollateral_WETH WETH = FakeCollateral_WETH(WETH); constructor( address _USDT_address, address _WETH_address, UniswapV2Router02_Modified _router_address ) public { USDT_address = _USDT_address; WETH_address = _WETH_address; router = UniswapV2Router02_Modified(_router_address); } function getPath() public returns (address[] memory) { address[] memory path = new address[](2); path[0] = USDT_address; path[1] = WETH_address; return path; } function swapUSDTforETH(uint256 amountIn, uint256 amountOutMin) public payable { require(USDT.transferFrom(msg.sender, address(this), amountIn), "transferFrom failed."); require(USDT.approve(address(router), amountIn), "approve failed."); address[] memory path = new address[](2); path[0] = USDT_address; path[1] = WETH_address; router.swapExactTokensForETH(amountIn, amountOutMin, path, msg.sender, block.timestamp); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./SafeMath.sol"; contract Timelock { using SafeMath for uint; event NewAdmin(address indexed newAdmin); event NewPendingAdmin(address indexed newPendingAdmin); event NewDelay(uint indexed newDelay); event CancelTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); event ExecuteTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); event QueueTransaction(bytes32 indexed txHash, address indexed target, uint value, string signature, bytes data, uint eta); uint public constant GRACE_PERIOD = 14 days; uint public constant MINIMUM_DELAY = 2 days; uint public constant MAXIMUM_DELAY = 30 days; address public admin; address public pendingAdmin; uint public delay; mapping (bytes32 => bool) public queuedTransactions; constructor(address admin_, uint delay_) public { require(delay_ >= MINIMUM_DELAY, "Timelock::constructor: Delay must exceed minimum delay."); require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay."); admin = admin_; delay = delay_; } //function() external payable { } function setDelay(uint delay_) public { require(msg.sender == address(this), "Timelock::setDelay: Call must come from Timelock."); require(delay_ >= MINIMUM_DELAY, "Timelock::setDelay: Delay must exceed minimum delay."); require(delay_ <= MAXIMUM_DELAY, "Timelock::setDelay: Delay must not exceed maximum delay."); delay = delay_; emit NewDelay(delay); } function acceptAdmin() public { require(msg.sender == pendingAdmin, "Timelock::acceptAdmin: Call must come from pendingAdmin."); admin = msg.sender; pendingAdmin = address(0); emit NewAdmin(admin); } function setPendingAdmin(address pendingAdmin_) public { require(msg.sender == address(this), "Timelock::setPendingAdmin: Call must come from Timelock."); pendingAdmin = pendingAdmin_; emit NewPendingAdmin(pendingAdmin); } function queueTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public returns (bytes32) { require(msg.sender == admin, "Timelock::queueTransaction: Call must come from admin."); require(eta >= getBlockTimestamp().add(delay), "Timelock::queueTransaction: Estimated execution block must satisfy delay."); bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); queuedTransactions[txHash] = true; emit QueueTransaction(txHash, target, value, signature, data, eta); return txHash; } function cancelTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public { require(msg.sender == admin, "Timelock::cancelTransaction: Call must come from admin."); bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); queuedTransactions[txHash] = false; emit CancelTransaction(txHash, target, value, signature, data, eta); } function executeTransaction(address target, uint value, string memory signature, bytes memory data, uint eta) public payable returns (bytes memory) { require(msg.sender == admin, "Timelock::executeTransaction: Call must come from admin."); bytes32 txHash = keccak256(abi.encode(target, value, signature, data, eta)); require(queuedTransactions[txHash], "Timelock::executeTransaction: Transaction hasn't been queued."); require(getBlockTimestamp() >= eta, "Timelock::executeTransaction: Transaction hasn't surpassed time lock."); require(getBlockTimestamp() <= eta.add(GRACE_PERIOD), "Timelock::executeTransaction: Transaction is stale."); queuedTransactions[txHash] = false; bytes memory callData; if (bytes(signature).length == 0) { callData = data; } else { callData = abi.encodePacked(bytes4(keccak256(bytes(signature))), data); } // Execute the call (bool success, bytes memory returnData) = target.call{ value: value }(callData); require(success, "Timelock::executeTransaction: Transaction execution reverted."); emit ExecuteTransaction(txHash, target, value, signature, data, eta); return returnData; } function getBlockTimestamp() internal view returns (uint) { return block.timestamp; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import "./ERC20Custom.sol"; import "./ERC20.sol"; import "./SafeMath.sol"; /** * @title TokenVesting * @dev A token holder contract that can release its token balance gradually like a * typical vesting scheme, with a cliff and vesting period. Optionally revocable by the * owner. * * Modified from OpenZeppelin's TokenVesting.sol draft */ contract TokenVesting { // The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is // therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore, // it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a // cliff period of a year and a duration of four years, are safe to use. // solhint-disable not-rely-on-time using SafeMath for uint256; event TokensReleased(uint256 amount); event TokenVestingRevoked(); // beneficiary of tokens after they are released address private _beneficiary; // owner (grantor) of the tokens address private _owner; // Durations and timestamps are expressed in UNIX time, the same units as block.timestamp. uint256 private _cliff; uint256 private _start; uint256 private _duration; address public _FXS_contract_address; ERC20 FXS; address public _timelock_address; bool public _revocable; uint256 private _released; bool public _revoked; /** * @dev Creates a vesting contract that vests its balance of any ERC20 token to the * beneficiary, gradually in a linear fashion until start + duration. By then all * of the balance will have vested. * @param beneficiary address of the beneficiary to whom vested tokens are transferred * @param cliffDuration duration in seconds of the cliff in which tokens will begin to vest * @param start the time (as Unix time) at which point vesting starts * @param duration duration in seconds of the period in which the tokens will vest * @param revocable whether the vesting is revocable or not */ constructor( address beneficiary, uint256 start, uint256 cliffDuration, uint256 duration, bool revocable ) public { require(beneficiary != address(0), "TokenVesting: beneficiary is the zero address"); // solhint-disable-next-line max-line-length require(cliffDuration <= duration, "TokenVesting: cliff is longer than duration"); require(duration > 0, "TokenVesting: duration is 0"); // solhint-disable-next-line max-line-length require(start.add(duration) > block.timestamp, "TokenVesting: final time is before current time"); _beneficiary = beneficiary; _revocable = revocable; _duration = duration; _cliff = start.add(cliffDuration); _start = start; _owner = msg.sender; } function setFXSAddress(address FXS_address) public { require(msg.sender == _owner, "must be set by the owner"); _FXS_contract_address = FXS_address; FXS = ERC20(FXS_address); } function setTimelockAddress(address timelock_address) public { require(msg.sender == _owner, "must be set by the owner"); _timelock_address = timelock_address; } /** * @return the beneficiary of the tokens. */ function getBeneficiary() public view returns (address) { return _beneficiary; } /** * @return the cliff time of the token vesting. */ function getCliff() public view returns (uint256) { return _cliff; } /** * @return the start time of the token vesting. */ function getStart() public view returns (uint256) { return _start; } /** * @return the duration of the token vesting. */ function getDuration() public view returns (uint256) { return _duration; } /** * @return true if the vesting is revocable. */ function getRevocable() public view returns (bool) { return _revocable; } /** * @return the amount of the token released. */ function getReleased() public view returns (uint256) { return _released; } /** * @return true if the token is revoked. */ function getRevoked() public view returns (bool) { return _revoked; } /** * @notice Transfers vested tokens to beneficiary. */ function release() public { require(msg.sender == _beneficiary, "must be the beneficiary to release tokens"); uint256 unreleased = _releasableAmount(); require(unreleased > 0, "TokenVesting: no tokens are due"); _released = _released.add(unreleased); FXS.transfer(_beneficiary, unreleased); emit TokensReleased(unreleased); } /** * @notice Allows the owner to revoke the vesting. Tokens already vested * remain in the contract, the rest are returned to the owner. */ function revoke() public { require(msg.sender == _timelock_address, "Must be called by the timelock contract"); require(_revocable, "TokenVesting: cannot revoke"); require(!_revoked, "TokenVesting: token already revoked"); uint256 balance = FXS.balanceOf(address(this)); uint256 unreleased = _releasableAmount(); uint256 refund = balance.sub(unreleased); _revoked = true; FXS.transfer(_owner, refund); emit TokenVestingRevoked(); } // Added to support recovering possible airdrops function recoverERC20(address tokenAddress, uint256 tokenAmount) external { require(msg.sender == _beneficiary, "Must be called by the beneficiary"); // Cannot recover the staking token or the rewards token require(tokenAddress != _FXS_contract_address, "Cannot withdraw the FXS through this function"); ERC20(tokenAddress).transfer(_beneficiary, tokenAmount); } /** * @dev Calculates the amount that has already vested but hasn't been released yet. */ function _releasableAmount() private view returns (uint256) { return _vestedAmount().sub(_released); } /** * @dev Calculates the amount that has already vested. */ function _vestedAmount() private view returns (uint256) { uint256 currentBalance = FXS.balanceOf(address(this)); uint256 totalBalance = currentBalance.add(_released); if (block.timestamp < _cliff) { return 0; } else if (block.timestamp >= _start.add(_duration) || _revoked) { return totalBalance; } else { return totalBalance.mul(block.timestamp.sub(_start)).div(_duration); } } uint256[44] private __gap; }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; // helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false library TransferHelper { function safeApprove(address token, address to, uint value) internal { // bytes4(keccak256(bytes('approve(address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED'); } function safeTransfer(address token, address to, uint value) internal { // bytes4(keccak256(bytes('transfer(address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED'); } function safeTransferFrom(address token, address from, address to, uint value) internal { // bytes4(keccak256(bytes('transferFrom(address,address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED'); } function safeTransferETH(address to, uint value) internal { (bool success,) = to.call{value:value}(new bytes(0)); require(success, 'TransferHelper: ETH_TRANSFER_FAILED'); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './IUniswapV2Factory.sol'; import './IUniswapV2Pair.sol'; import './FixedPoint.sol'; import './UniswapV2OracleLibrary.sol'; import './UniswapV2Library.sol'; // Fixed window oracle that recomputes the average price for the entire period once every period // Note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period contract UniswapPairOracle { using FixedPoint for *; address owner_address; address timelock_address; uint public PERIOD = 3600; // 1 hour TWAP (time-weighted average price) IUniswapV2Pair public immutable pair; address public immutable token0; address public immutable token1; uint public price0CumulativeLast; uint public price1CumulativeLast; uint32 public blockTimestampLast; FixedPoint.uq112x112 public price0Average; FixedPoint.uq112x112 public price1Average; modifier onlyByOwnerOrGovernance() { require(msg.sender == owner_address || msg.sender == timelock_address, "You are not an owner or the governance timelock"); _; } constructor(address factory, address tokenA, address tokenB, address _owner_address, address _timelock_address) public { IUniswapV2Pair _pair = IUniswapV2Pair(UniswapV2Library.pairFor(factory, tokenA, tokenB)); pair = _pair; token0 = _pair.token0(); token1 = _pair.token1(); price0CumulativeLast = _pair.price0CumulativeLast(); // Fetch the current accumulated price value (1 / 0) price1CumulativeLast = _pair.price1CumulativeLast(); // Fetch the current accumulated price value (0 / 1) uint112 reserve0; uint112 reserve1; (reserve0, reserve1, blockTimestampLast) = _pair.getReserves(); require(reserve0 != 0 && reserve1 != 0, 'UniswapPairOracle: NO_RESERVES'); // Ensure that there's liquidity in the pair owner_address = _owner_address; timelock_address = _timelock_address; } function setOwner(address _owner_address) external onlyByOwnerOrGovernance { owner_address = _owner_address; } function setTimelock(address _timelock_address) external onlyByOwnerOrGovernance { timelock_address = _timelock_address; } function setPeriod(uint _period) external onlyByOwnerOrGovernance { PERIOD = _period; } function update() external { (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) = UniswapV2OracleLibrary.currentCumulativePrices(address(pair)); uint32 timeElapsed = blockTimestamp - blockTimestampLast; // Overflow is desired // Ensure that at least one full period has passed since the last update require(timeElapsed >= PERIOD, 'UniswapPairOracle: PERIOD_NOT_ELAPSED'); // Overflow is desired, casting never truncates // Cumulative price is in (uq112x112 price * seconds) units so we simply wrap it after division by time elapsed price0Average = FixedPoint.uq112x112(uint224((price0Cumulative - price0CumulativeLast) / timeElapsed)); price1Average = FixedPoint.uq112x112(uint224((price1Cumulative - price1CumulativeLast) / timeElapsed)); price0CumulativeLast = price0Cumulative; price1CumulativeLast = price1Cumulative; blockTimestampLast = blockTimestamp; } // Note this will always return 0 before update has been called successfully for the first time. function consult(address token, uint amountIn) external view returns (uint amountOut) { if (token == token0) { amountOut = price0Average.mul(amountIn).decode144(); } else { require(token == token1, 'UniswapPairOracle: INVALID_TOKEN'); amountOut = price1Average.mul(amountIn).decode144(); } } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './UniswapPairOracle.sol'; // Fixed window oracle that recomputes the average price for the entire period once every period // Note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period contract UniswapPairOracle_FRAX_FXS is UniswapPairOracle { constructor(address factory, address tokenA, address tokenB, address owner_address, address timelock_address) UniswapPairOracle(factory, tokenA, tokenB, owner_address, timelock_address) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './UniswapPairOracle.sol'; // Fixed window oracle that recomputes the average price for the entire period once every period // Note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period contract UniswapPairOracle_FRAX_USDC is UniswapPairOracle { constructor(address factory, address tokenA, address tokenB, address owner_address, address timelock_address) UniswapPairOracle(factory, tokenA, tokenB, owner_address, timelock_address) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './UniswapPairOracle.sol'; // Fixed window oracle that recomputes the average price for the entire period once every period // Note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period contract UniswapPairOracle_FRAX_USDT is UniswapPairOracle { constructor(address factory, address tokenA, address tokenB, address owner_address, address timelock_address) UniswapPairOracle(factory, tokenA, tokenB, owner_address, timelock_address) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './UniswapPairOracle.sol'; // Fixed window oracle that recomputes the average price for the entire period once every period // Note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period contract UniswapPairOracle_FRAX_WETH is UniswapPairOracle { constructor(address factory, address tokenA, address tokenB, address owner_address, address timelock_address) UniswapPairOracle(factory, tokenA, tokenB, owner_address, timelock_address) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './UniswapPairOracle.sol'; // Fixed window oracle that recomputes the average price for the entire period once every period // Note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period contract UniswapPairOracle_FXS_USDC is UniswapPairOracle { constructor(address factory, address tokenA, address tokenB, address owner_address, address timelock_address) UniswapPairOracle(factory, tokenA, tokenB, owner_address, timelock_address) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './UniswapPairOracle.sol'; // Fixed window oracle that recomputes the average price for the entire period once every period // Note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period contract UniswapPairOracle_FXS_USDT is UniswapPairOracle { constructor(address factory, address tokenA, address tokenB, address owner_address, address timelock_address) UniswapPairOracle(factory, tokenA, tokenB, owner_address, timelock_address) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './UniswapPairOracle.sol'; // Fixed window oracle that recomputes the average price for the entire period once every period // Note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period contract UniswapPairOracle_FXS_WETH is UniswapPairOracle { constructor(address factory, address tokenA, address tokenB, address owner_address, address timelock_address) UniswapPairOracle(factory, tokenA, tokenB, owner_address, timelock_address) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './UniswapPairOracle.sol'; // Fixed window oracle that recomputes the average price for the entire period once every period // Note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period contract UniswapPairOracle_USDC_WETH is UniswapPairOracle { constructor(address factory, address tokenA, address tokenB, address owner_address, address timelock_address) UniswapPairOracle(factory, tokenA, tokenB, owner_address, timelock_address) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './UniswapPairOracle.sol'; // Fixed window oracle that recomputes the average price for the entire period once every period // Note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period contract UniswapPairOracle_USDT_WETH is UniswapPairOracle { constructor(address factory, address tokenA, address tokenB, address owner_address, address timelock_address) UniswapPairOracle(factory, tokenA, tokenB, owner_address, timelock_address) public {} }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './IUniswapV2ERC20.sol'; import './SafeMath.sol'; contract UniswapV2ERC20 is IUniswapV2ERC20 { using SafeMath for uint; string public override constant name = 'Uniswap V2'; string public override constant symbol = 'UNI-V2'; uint8 public override constant decimals = 18; uint public override totalSupply; mapping(address => uint) public override balanceOf; mapping(address => mapping(address => uint)) public override allowance; bytes32 public override DOMAIN_SEPARATOR; // keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); bytes32 public constant override PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; mapping(address => uint) public override nonces; event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); constructor() public { uint chainId; assembly { chainId := chainid() } DOMAIN_SEPARATOR = keccak256( abi.encode( keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'), keccak256(bytes(name)), keccak256(bytes('1')), chainId, address(this) ) ); } function _mint(address to, uint value) internal { totalSupply = totalSupply.add(value); balanceOf[to] = balanceOf[to].add(value); emit Transfer(address(0), to, value); } function _burn(address from, uint value) internal { balanceOf[from] = balanceOf[from].sub(value); totalSupply = totalSupply.sub(value); emit Transfer(from, address(0), value); } function _approve(address owner, address spender, uint value) private { allowance[owner][spender] = value; emit Approval(owner, spender, value); } function _transfer(address from, address to, uint value) private { balanceOf[from] = balanceOf[from].sub(value); balanceOf[to] = balanceOf[to].add(value); emit Transfer(from, to, value); } function approve(address spender, uint value) external override returns (bool) { _approve(msg.sender, spender, value); return true; } function transfer(address to, uint value) external override returns (bool) { _transfer(msg.sender, to, value); return true; } function transferFrom(address from, address to, uint value) external override returns (bool) { if (allowance[from][msg.sender] != uint(-1)) { allowance[from][msg.sender] = allowance[from][msg.sender].sub(value); } _transfer(from, to, value); return true; } function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external override { require(deadline >= block.timestamp, 'UniswapV2: EXPIRED'); bytes32 digest = keccak256( abi.encodePacked( '\x19\x01', DOMAIN_SEPARATOR, keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline)) ) ); address recoveredAddress = ecrecover(digest, v, r, s); require(recoveredAddress != address(0) && recoveredAddress == owner, 'UniswapV2: INVALID_SIGNATURE'); _approve(owner, spender, value); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './IUniswapV2Factory.sol'; import './UniswapV2Pair.sol'; contract UniswapV2Factory is IUniswapV2Factory { address public override feeTo; address public override feeToSetter; mapping(address => mapping(address => address)) public override getPair; address[] public override allPairs; event PairCreated(address indexed token0, address indexed token1, address pair, uint); constructor(address _feeToSetter) public { feeToSetter = _feeToSetter; } function allPairsLength() external override view returns (uint) { return allPairs.length; } function createPair(address tokenA, address tokenB) external override returns (address pair) { require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES'); (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS'); require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient bytes memory bytecode = type(UniswapV2Pair).creationCode; bytes32 salt = keccak256(abi.encodePacked(token0, token1)); // This creates a new contract assembly { pair := create2(0, add(bytecode, 32), mload(bytecode), salt) } IUniswapV2Pair(pair).initialize(token0, token1); getPair[token0][token1] = pair; getPair[token1][token0] = pair; // populate mapping in the reverse direction allPairs.push(pair); emit PairCreated(token0, token1, pair, allPairs.length); } function setFeeTo(address _feeTo) external override { require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN'); feeTo = _feeTo; } function setFeeToSetter(address _feeToSetter) external override { require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN'); feeToSetter = _feeToSetter; } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './IUniswapV2Pair.sol'; import './IUniswapV2Factory.sol'; import "./SafeMath.sol"; library UniswapV2Library { using SafeMath for uint; // returns sorted token addresses, used to handle return values from pairs sorted in this order function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS'); } // Less efficient than the CREATE2 method below function pairFor(address factory, address tokenA, address tokenB) internal view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); pair = IUniswapV2Factory(factory).getPair(token0, token1); } // calculates the CREATE2 address for a pair without making any external calls function pairForCreate2(address factory, address tokenA, address tokenB) internal pure returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); pair = address(uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash )))); // this matches the CREATE2 in UniswapV2Factory.createPair } // fetches and sorts the reserves for a pair function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); amountB = amountA.mul(reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn.mul(997); uint numerator = amountInWithFee.mul(reserveOut); uint denominator = reserveIn.mul(1000).add(amountInWithFee); amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn.mul(amountOut).mul(1000); uint denominator = reserveOut.sub(amountOut).mul(997); amountIn = (numerator / denominator).add(1); } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'UniswapV2Library: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'UniswapV2Library: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './IUniswapV2Pair.sol'; import './FixedPoint.sol'; // library with helper methods for oracles that are concerned with computing average prices library UniswapV2OracleLibrary { using FixedPoint for *; // helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1] function currentBlockTimestamp() internal view returns (uint32) { return uint32(block.timestamp % 2 ** 32); } // produces the cumulative price using counterfactuals to save gas and avoid a call to sync. function currentCumulativePrices( address pair ) internal view returns (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) { blockTimestamp = currentBlockTimestamp(); price0Cumulative = IUniswapV2Pair(pair).price0CumulativeLast(); price1Cumulative = IUniswapV2Pair(pair).price1CumulativeLast(); // if time has elapsed since the last update on the pair, mock the accumulated price values (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = IUniswapV2Pair(pair).getReserves(); if (blockTimestampLast != blockTimestamp) { // subtraction overflow is desired uint32 timeElapsed = blockTimestamp - blockTimestampLast; // addition overflow is desired // counterfactual price0Cumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed; // counterfactual price1Cumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed; } } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './IUniswapV2Pair.sol'; import './UniswapV2ERC20.sol'; import './Math.sol'; import './UQ112x112.sol'; import './IERC20.sol'; import './IUniswapV2Factory.sol'; import './IUniswapV2Callee.sol'; contract UniswapV2Pair is IUniswapV2Pair { using SafeMath for uint; using UQ112x112 for uint224; string public override constant name = 'Uniswap V2'; string public override constant symbol = 'UNI-V2'; uint8 public override constant decimals = 18; uint public override totalSupply; mapping(address => uint) public override balanceOf; mapping(address => mapping(address => uint)) public override allowance; uint public override constant MINIMUM_LIQUIDITY = 10**3; bytes4 private constant SELECTOR = bytes4(keccak256(bytes('transfer(address,uint256)'))); bytes32 public override DOMAIN_SEPARATOR; // keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); bytes32 public constant override PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; mapping(address => uint) public override nonces; address public override factory; address public override token0; address public override token1; uint112 private reserve0; // uses single storage slot, accessible via getReserves uint112 private reserve1; // uses single storage slot, accessible via getReserves uint32 private blockTimestampLast; // uses single storage slot, accessible via getReserves uint public override price0CumulativeLast; uint public override price1CumulativeLast; uint public override kLast; // reserve0 * reserve1, as of immediately after the most recent liquidity event uint private unlocked = 1; modifier lock() { require(unlocked == 1, 'UniswapV2: LOCKED'); unlocked = 0; _; unlocked = 1; } function getReserves() public override view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) { _reserve0 = reserve0; _reserve1 = reserve1; _blockTimestampLast = blockTimestampLast; } function _safeTransfer(address token, address to, uint value) private { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(SELECTOR, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'UniswapV2: TRANSFER_FAILED'); } 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); constructor() public { factory = msg.sender; } // called once by the factory at time of deployment function initialize(address _token0, address _token1) external override { require(msg.sender == factory, 'UniswapV2: FORBIDDEN'); // sufficient check token0 = _token0; token1 = _token1; } // update reserves and, on the first call per block, price accumulators function _update(uint balance0, uint balance1, uint112 _reserve0, uint112 _reserve1) private { require(balance0 <= uint112(-1) && balance1 <= uint112(-1), 'UniswapV2: OVERFLOW'); uint32 blockTimestamp = uint32(block.timestamp % 2**32); uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) { // * never overflows, and + overflow is desired price0CumulativeLast += uint(UQ112x112.encode(_reserve1).uqdiv(_reserve0)) * timeElapsed; price1CumulativeLast += uint(UQ112x112.encode(_reserve0).uqdiv(_reserve1)) * timeElapsed; } reserve0 = uint112(balance0); reserve1 = uint112(balance1); blockTimestampLast = blockTimestamp; emit Sync(reserve0, reserve1); } // if fee is on, mint liquidity equivalent to 1/6th of the growth in sqrt(k) function _mintFee(uint112 _reserve0, uint112 _reserve1) private returns (bool feeOn) { address feeTo = IUniswapV2Factory(factory).feeTo(); feeOn = feeTo != address(0); uint _kLast = kLast; // gas savings if (feeOn) { if (_kLast != 0) { uint rootK = Math.sqrt(uint(_reserve0).mul(_reserve1)); uint rootKLast = Math.sqrt(_kLast); if (rootK > rootKLast) { uint numerator = totalSupply.mul(rootK.sub(rootKLast)); uint denominator = rootK.mul(5).add(rootKLast); uint liquidity = numerator / denominator; if (liquidity > 0) _mint(feeTo, liquidity); } } } else if (_kLast != 0) { kLast = 0; } } // this low-level function should be called from a contract which performs important safety checks function mint(address to) external override lock returns (uint liquidity) { (uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings uint balance0 = IERC20(token0).balanceOf(address(this)); uint balance1 = IERC20(token1).balanceOf(address(this)); uint amount0 = balance0.sub(_reserve0); uint amount1 = balance1.sub(_reserve1); bool feeOn = _mintFee(_reserve0, _reserve1); uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee if (_totalSupply == 0) { liquidity = Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY); _mint(address(0), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens } else { liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1); } require(liquidity > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_MINTED'); _mint(to, liquidity); _update(balance0, balance1, _reserve0, _reserve1); if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date emit Mint(msg.sender, amount0, amount1); } // this low-level function should be called from a contract which performs important safety checks function burn(address to) external override lock returns (uint amount0, uint amount1) { (uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings address _token0 = token0; // gas savings address _token1 = token1; // gas savings uint balance0 = IERC20(_token0).balanceOf(address(this)); uint balance1 = IERC20(_token1).balanceOf(address(this)); uint liquidity = balanceOf[address(this)]; bool feeOn = _mintFee(_reserve0, _reserve1); uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution require(amount0 > 0 && amount1 > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_BURNED'); _burn(address(this), liquidity); _safeTransfer(_token0, to, amount0); _safeTransfer(_token1, to, amount1); balance0 = IERC20(_token0).balanceOf(address(this)); balance1 = IERC20(_token1).balanceOf(address(this)); _update(balance0, balance1, _reserve0, _reserve1); if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date emit Burn(msg.sender, amount0, amount1, to); } // this low-level function should be called from a contract which performs important safety checks function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external override lock { require(amount0Out > 0 || amount1Out > 0, 'UniswapV2: INSUFFICIENT_OUTPUT_AMOUNT'); (uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings require(amount0Out < _reserve0 && amount1Out < _reserve1, 'UniswapV2: INSUFFICIENT_LIQUIDITY'); uint balance0; uint balance1; { // scope for _token{0,1}, avoids stack too deep errors address _token0 = token0; address _token1 = token1; require(to != _token0 && to != _token1, 'UniswapV2: INVALID_TO'); if (amount0Out > 0) _safeTransfer(_token0, to, amount0Out); // optimistically transfer tokens if (amount1Out > 0) _safeTransfer(_token1, to, amount1Out); // optimistically transfer tokens if (data.length > 0) IUniswapV2Callee(to).uniswapV2Call(msg.sender, amount0Out, amount1Out, data); balance0 = IERC20(_token0).balanceOf(address(this)); balance1 = IERC20(_token1).balanceOf(address(this)); } uint amount0In = balance0 > _reserve0 - amount0Out ? balance0 - (_reserve0 - amount0Out) : 0; uint amount1In = balance1 > _reserve1 - amount1Out ? balance1 - (_reserve1 - amount1Out) : 0; require(amount0In > 0 || amount1In > 0, 'UniswapV2: INSUFFICIENT_INPUT_AMOUNT'); { // scope for reserve{0,1}Adjusted, avoids stack too deep errors uint balance0Adjusted = balance0.mul(1000).sub(amount0In.mul(3)); uint balance1Adjusted = balance1.mul(1000).sub(amount1In.mul(3)); require(balance0Adjusted.mul(balance1Adjusted) >= uint(_reserve0).mul(_reserve1).mul(1000**2), 'UniswapV2: K'); } _update(balance0, balance1, _reserve0, _reserve1); emit Swap(msg.sender, amount0In, amount1In, amount0Out, amount1Out, to); } // force balances to match reserves function skim(address to) external override lock { address _token0 = token0; // gas savings address _token1 = token1; // gas savings _safeTransfer(_token0, to, IERC20(_token0).balanceOf(address(this)).sub(reserve0)); _safeTransfer(_token1, to, IERC20(_token1).balanceOf(address(this)).sub(reserve1)); } // force reserves to match balances function sync() external override lock { _update(IERC20(token0).balanceOf(address(this)), IERC20(token1).balanceOf(address(this)), reserve0, reserve1); } // Migrated over from UniswapV2ERC20. Needed for ^0.6.0 // =============================================== function _mint(address to, uint value) internal { totalSupply = totalSupply.add(value); balanceOf[to] = balanceOf[to].add(value); emit Transfer(address(0), to, value); } function _burn(address from, uint value) internal { balanceOf[from] = balanceOf[from].sub(value); totalSupply = totalSupply.sub(value); emit Transfer(from, address(0), value); } function _approve(address owner, address spender, uint value) private { allowance[owner][spender] = value; emit Approval(owner, spender, value); } function _transfer(address from, address to, uint value) private { balanceOf[from] = balanceOf[from].sub(value); balanceOf[to] = balanceOf[to].add(value); emit Transfer(from, to, value); } function approve(address spender, uint value) external override returns (bool) { _approve(msg.sender, spender, value); return true; } function transfer(address to, uint value) external override returns (bool) { _transfer(msg.sender, to, value); return true; } function transferFrom(address from, address to, uint value) external override returns (bool) { if (allowance[from][msg.sender] != uint(-1)) { allowance[from][msg.sender] = allowance[from][msg.sender].sub(value); } _transfer(from, to, value); return true; } function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external override { require(deadline >= block.timestamp, 'UniswapV2: EXPIRED'); bytes32 digest = keccak256( abi.encodePacked( '\x19\x01', DOMAIN_SEPARATOR, keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline)) ) ); address recoveredAddress = ecrecover(digest, v, r, s); require(recoveredAddress != address(0) && recoveredAddress == owner, 'UniswapV2: INVALID_SIGNATURE'); _approve(owner, spender, value); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './IUniswapV2Factory.sol'; import './TransferHelper.sol'; import './IUniswapV2Router02.sol'; import './UniswapV2Library.sol'; import './SafeMath.sol'; import './IERC20.sol'; import './IWETH.sol'; contract UniswapV2Router02 is IUniswapV2Router02 { using SafeMath for uint; address public immutable override factory; address public immutable override WETH; modifier ensure(uint deadline) { require(deadline >= block.timestamp, 'UniswapV2Router: EXPIRED'); _; } constructor(address _factory, address _WETH) public { factory = _factory; WETH = _WETH; } receive() external payable { assert(msg.sender == WETH); // only accept ETH via fallback from the WETH contract } // **** ADD LIQUIDITY **** function _addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin ) internal virtual returns (uint amountA, uint amountB) { // create the pair if it doesn't exist yet if (IUniswapV2Factory(factory).getPair(tokenA, tokenB) == address(0)) { IUniswapV2Factory(factory).createPair(tokenA, tokenB); } (uint reserveA, uint reserveB) = UniswapV2Library.getReserves(factory, tokenA, tokenB); if (reserveA == 0 && reserveB == 0) { (amountA, amountB) = (amountADesired, amountBDesired); } else { uint amountBOptimal = UniswapV2Library.quote(amountADesired, reserveA, reserveB); if (amountBOptimal <= amountBDesired) { require(amountBOptimal >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT'); (amountA, amountB) = (amountADesired, amountBOptimal); } else { uint amountAOptimal = UniswapV2Library.quote(amountBDesired, reserveB, reserveA); assert(amountAOptimal <= amountADesired); require(amountAOptimal >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT'); (amountA, amountB) = (amountAOptimal, amountBDesired); } } } function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external virtual override ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) { (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin); address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB); TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountA); TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB); liquidity = IUniswapV2Pair(pair).mint(to); } function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external virtual override payable ensure(deadline) returns (uint amountToken, uint amountETH, uint liquidity) { (amountToken, amountETH) = _addLiquidity( token, WETH, amountTokenDesired, msg.value, amountTokenMin, amountETHMin ); address pair = UniswapV2Library.pairFor(factory, token, WETH); TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken); IWETH(WETH).deposit{value: amountETH}(); assert(IWETH(WETH).transfer(pair, amountETH)); liquidity = IUniswapV2Pair(pair).mint(to); // refund dust eth, if any if (msg.value > amountETH) TransferHelper.safeTransferETH(msg.sender, msg.value - amountETH); } // **** REMOVE LIQUIDITY **** function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) public virtual override ensure(deadline) returns (uint amountA, uint amountB) { address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB); IUniswapV2Pair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair (uint amount0, uint amount1) = IUniswapV2Pair(pair).burn(to); (address token0,) = UniswapV2Library.sortTokens(tokenA, tokenB); (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0); require(amountA >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT'); require(amountB >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT'); } function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) public virtual override ensure(deadline) returns (uint amountToken, uint amountETH) { (amountToken, amountETH) = removeLiquidity( token, WETH, liquidity, amountTokenMin, amountETHMin, address(this), deadline ); TransferHelper.safeTransfer(token, to, amountToken); IWETH(WETH).withdraw(amountETH); TransferHelper.safeTransferETH(to, amountETH); } function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external virtual override returns (uint amountA, uint amountB) { address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB); uint value = approveMax ? uint(-1) : liquidity; IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); (amountA, amountB) = removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline); } function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external virtual override returns (uint amountToken, uint amountETH) { address pair = UniswapV2Library.pairFor(factory, token, WETH); uint value = approveMax ? uint(-1) : liquidity; IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); (amountToken, amountETH) = removeLiquidityETH(token, liquidity, amountTokenMin, amountETHMin, to, deadline); } // **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) **** function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) public virtual override ensure(deadline) returns (uint amountETH) { (, amountETH) = removeLiquidity( token, WETH, liquidity, amountTokenMin, amountETHMin, address(this), deadline ); TransferHelper.safeTransfer(token, to, IERC20(token).balanceOf(address(this))); IWETH(WETH).withdraw(amountETH); TransferHelper.safeTransferETH(to, amountETH); } function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external virtual override returns (uint amountETH) { address pair = UniswapV2Library.pairFor(factory, token, WETH); uint value = approveMax ? uint(-1) : liquidity; IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); amountETH = removeLiquidityETHSupportingFeeOnTransferTokens( token, liquidity, amountTokenMin, amountETHMin, to, deadline ); } // **** SWAP **** // requires the initial amount to have already been sent to the first pair function _swap(uint[] memory amounts, address[] memory path, address _to) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = UniswapV2Library.sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to; IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) returns (uint[] memory amounts) { amounts = UniswapV2Library.getAmountsOut(factory, amountIn, path); require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, to); } function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) returns (uint[] memory amounts) { amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= amountInMax, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, to); } function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external virtual override payable ensure(deadline) returns (uint[] memory amounts) { require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); amounts = UniswapV2Library.getAmountsOut(factory, msg.value, path); require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0])); _swap(amounts, path, to); } function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external virtual override ensure(deadline) returns (uint[] memory amounts) { require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH'); amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= amountInMax, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); TransferHelper.safeTransferETH(to, amounts[amounts.length - 1]); } function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external virtual override ensure(deadline) returns (uint[] memory amounts) { require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH'); amounts = UniswapV2Library.getAmountsOut(factory, amountIn, path); require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); TransferHelper.safeTransferETH(to, amounts[amounts.length - 1]); } function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external virtual override payable ensure(deadline) returns (uint[] memory amounts) { require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= msg.value, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0])); _swap(amounts, path, to); // refund dust eth, if any if (msg.value > amounts[0]) TransferHelper.safeTransferETH(msg.sender, msg.value - amounts[0]); } // **** SWAP (supporting fee-on-transfer tokens) **** // requires the initial amount to have already been sent to the first pair function _swapSupportingFeeOnTransferTokens(address[] memory path, address _to) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = UniswapV2Library.sortTokens(input, output); IUniswapV2Pair pair = IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output)); uint amountInput; uint amountOutput; { // scope to avoid stack too deep errors (uint reserve0, uint reserve1,) = pair.getReserves(); (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); amountInput = IERC20(input).balanceOf(address(pair)).sub(reserveInput); amountOutput = UniswapV2Library.getAmountOut(amountInput, reserveInput, reserveOutput); } (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to; pair.swap(amount0Out, amount1Out, to, new bytes(0)); } } function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) { TransferHelper.safeTransferFrom( path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn ); uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to); _swapSupportingFeeOnTransferTokens(path, to); require( IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override payable ensure(deadline) { require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); uint amountIn = msg.value; IWETH(WETH).deposit{value: amountIn}(); assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn)); uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to); _swapSupportingFeeOnTransferTokens(path, to); require( IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) { require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH'); TransferHelper.safeTransferFrom( path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn ); _swapSupportingFeeOnTransferTokens(path, address(this)); uint amountOut = IERC20(WETH).balanceOf(address(this)); require(amountOut >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).withdraw(amountOut); TransferHelper.safeTransferETH(to, amountOut); } // **** LIBRARY FUNCTIONS **** function quote(uint amountA, uint reserveA, uint reserveB) public pure virtual override returns (uint amountB) { return UniswapV2Library.quote(amountA, reserveA, reserveB); } function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) public pure virtual override returns (uint amountOut) { return UniswapV2Library.getAmountOut(amountIn, reserveIn, reserveOut); } function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) public pure virtual override returns (uint amountIn) { return UniswapV2Library.getAmountIn(amountOut, reserveIn, reserveOut); } function getAmountsOut(uint amountIn, address[] memory path) public view virtual override returns (uint[] memory amounts) { return UniswapV2Library.getAmountsOut(factory, amountIn, path); } function getAmountsIn(uint amountOut, address[] memory path) public view virtual override returns (uint[] memory amounts) { return UniswapV2Library.getAmountsIn(factory, amountOut, path); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './IUniswapV2Factory.sol'; import './TransferHelper.sol'; import './IUniswapV2Router02.sol'; import './UniswapV2Library.sol'; import './SafeMath.sol'; import './IERC20.sol'; import './IWETH.sol'; contract UniswapV2Router02_Modified is IUniswapV2Router02 { using SafeMath for uint; address public immutable override factory; address public immutable override WETH; modifier ensure(uint deadline) { require(deadline >= block.timestamp, 'UniswapV2Router: EXPIRED'); _; } constructor(address _factory, address _WETH) public { factory = _factory; WETH = _WETH; } receive() external payable { assert(msg.sender == WETH); // only accept ETH via fallback from the WETH contract } // **** ADD LIQUIDITY **** function _addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin ) internal virtual returns (uint amountA, uint amountB) { // create the pair if it doesn't exist yet if (IUniswapV2Factory(factory).getPair(tokenA, tokenB) == address(0)) { IUniswapV2Factory(factory).createPair(tokenA, tokenB); } (uint reserveA, uint reserveB) = UniswapV2Library.getReserves(factory, tokenA, tokenB); if (reserveA == 0 && reserveB == 0) { (amountA, amountB) = (amountADesired, amountBDesired); } else { uint amountBOptimal = UniswapV2Library.quote(amountADesired, reserveA, reserveB); if (amountBOptimal <= amountBDesired) { require(amountBOptimal >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT'); (amountA, amountB) = (amountADesired, amountBOptimal); } else { uint amountAOptimal = UniswapV2Library.quote(amountBDesired, reserveB, reserveA); assert(amountAOptimal <= amountADesired); require(amountAOptimal >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT'); (amountA, amountB) = (amountAOptimal, amountBDesired); } } } function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external virtual override ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) { (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin); address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB); TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountA); TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB); liquidity = IUniswapV2Pair(pair).mint(to); } function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external virtual override payable ensure(deadline) returns (uint amountToken, uint amountETH, uint liquidity) { (amountToken, amountETH) = _addLiquidity( token, WETH, amountTokenDesired, msg.value, amountTokenMin, amountETHMin ); address pair = UniswapV2Library.pairFor(factory, token, WETH); TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken); TransferHelper.safeTransferFrom(WETH, msg.sender, pair, amountETH); // IWETH(WETH).transferFrom(msg.sender, pair, amountETH); // IWETH(WETH).deposit{value: amountETH}(); // assert(IWETH(WETH).transfer(pair, amountETH)); // require(false, "HELLO: HOW ARE YOU TODAY!"); liquidity = IUniswapV2Pair(pair).mint(to); // << PROBLEM IS HERE // refund dust eth, if any if (msg.value > amountETH) TransferHelper.safeTransferETH(msg.sender, msg.value - amountETH); } // **** REMOVE LIQUIDITY **** function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) public virtual override ensure(deadline) returns (uint amountA, uint amountB) { address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB); IUniswapV2Pair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair (uint amount0, uint amount1) = IUniswapV2Pair(pair).burn(to); (address token0,) = UniswapV2Library.sortTokens(tokenA, tokenB); (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0); require(amountA >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT'); require(amountB >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT'); } function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) public virtual override ensure(deadline) returns (uint amountToken, uint amountETH) { (amountToken, amountETH) = removeLiquidity( token, WETH, liquidity, amountTokenMin, amountETHMin, address(this), deadline ); TransferHelper.safeTransfer(token, to, amountToken); IWETH(WETH).withdraw(amountETH); TransferHelper.safeTransferETH(to, amountETH); } function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external virtual override returns (uint amountA, uint amountB) { address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB); uint value = approveMax ? uint(-1) : liquidity; IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); (amountA, amountB) = removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline); } function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external virtual override returns (uint amountToken, uint amountETH) { address pair = UniswapV2Library.pairFor(factory, token, WETH); uint value = approveMax ? uint(-1) : liquidity; IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); (amountToken, amountETH) = removeLiquidityETH(token, liquidity, amountTokenMin, amountETHMin, to, deadline); } // **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) **** function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) public virtual override ensure(deadline) returns (uint amountETH) { (, amountETH) = removeLiquidity( token, WETH, liquidity, amountTokenMin, amountETHMin, address(this), deadline ); TransferHelper.safeTransfer(token, to, IERC20(token).balanceOf(address(this))); IWETH(WETH).withdraw(amountETH); TransferHelper.safeTransferETH(to, amountETH); } function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external virtual override returns (uint amountETH) { address pair = UniswapV2Library.pairFor(factory, token, WETH); uint value = approveMax ? uint(-1) : liquidity; IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s); amountETH = removeLiquidityETHSupportingFeeOnTransferTokens( token, liquidity, amountTokenMin, amountETHMin, to, deadline ); } // **** SWAP **** // requires the initial amount to have already been sent to the first pair function _swap(uint[] memory amounts, address[] memory path, address _to) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = UniswapV2Library.sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to; IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) returns (uint[] memory amounts) { amounts = UniswapV2Library.getAmountsOut(factory, amountIn, path); require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, to); } function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) returns (uint[] memory amounts) { amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= amountInMax, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, to); } function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external virtual override payable ensure(deadline) returns (uint[] memory amounts) { require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); amounts = UniswapV2Library.getAmountsOut(factory, msg.value, path); require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0])); _swap(amounts, path, to); } function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external virtual override ensure(deadline) returns (uint[] memory amounts) { require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH'); amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= amountInMax, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); TransferHelper.safeTransferETH(to, amounts[amounts.length - 1]); } function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external virtual override ensure(deadline) returns (uint[] memory amounts) { require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH'); amounts = UniswapV2Library.getAmountsOut(factory, amountIn, path); require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); TransferHelper.safeTransferFrom( path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0] ); _swap(amounts, path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); TransferHelper.safeTransferETH(to, amounts[amounts.length - 1]); } function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external virtual override payable ensure(deadline) returns (uint[] memory amounts) { require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path); require(amounts[0] <= msg.value, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0])); _swap(amounts, path, to); // refund dust eth, if any if (msg.value > amounts[0]) TransferHelper.safeTransferETH(msg.sender, msg.value - amounts[0]); } // **** SWAP (supporting fee-on-transfer tokens) **** // requires the initial amount to have already been sent to the first pair function _swapSupportingFeeOnTransferTokens(address[] memory path, address _to) internal virtual { // for (uint i; i < path.length - 1; i++) { // (address input, address output) = (path[i], path[i + 1]); // (address token0,) = UniswapV2Library.sortTokens(input, output); // IUniswapV2Pair pair = IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output)); // uint amountInput; // uint amountOutput; // { // scope to avoid stack too deep errors // (uint reserve0, uint reserve1,) = pair.getReserves(); // (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); // amountInput = IERC20(input).balanceOf(address(pair)).sub(reserveInput); // amountOutput = UniswapV2Library.getAmountOut(amountInput, reserveInput, reserveOutput); // } // (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); // address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to; // pair.swap(amount0Out, amount1Out, to, new bytes(0)); // } } function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) { // TransferHelper.safeTransferFrom( // path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn // ); // uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to); // _swapSupportingFeeOnTransferTokens(path, to); // require( // IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin, // 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT' // ); } function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override payable ensure(deadline) { // require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); // uint amountIn = msg.value; // IWETH(WETH).deposit{value: amountIn}(); // assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn)); // uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to); // _swapSupportingFeeOnTransferTokens(path, to); // require( // IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin, // 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT' // ); } function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external virtual override ensure(deadline) { // require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH'); // TransferHelper.safeTransferFrom( // path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn // ); // _swapSupportingFeeOnTransferTokens(path, address(this)); // uint amountOut = IERC20(WETH).balanceOf(address(this)); // require(amountOut >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'); // IWETH(WETH).withdraw(amountOut); // TransferHelper.safeTransferETH(to, amountOut); } // **** LIBRARY FUNCTIONS **** function quote(uint amountA, uint reserveA, uint reserveB) public pure virtual override returns (uint amountB) { return UniswapV2Library.quote(amountA, reserveA, reserveB); } function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) public pure virtual override returns (uint amountOut) { return UniswapV2Library.getAmountOut(amountIn, reserveIn, reserveOut); } function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) public pure virtual override returns (uint amountIn) { return UniswapV2Library.getAmountIn(amountOut, reserveIn, reserveOut); } function getAmountsOut(uint amountIn, address[] memory path) public view virtual override returns (uint[] memory amounts) { return UniswapV2Library.getAmountsOut(factory, amountIn, path); } function getAmountsIn(uint amountOut, address[] memory path) public view virtual override returns (uint[] memory amounts) { return UniswapV2Library.getAmountsIn(factory, amountOut, path); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; // a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format)) // range: [0, 2**112 - 1] // resolution: 1 / 2**112 library UQ112x112 { uint224 constant Q112 = 2**112; // encode a uint112 as a UQ112x112 function encode(uint112 y) internal pure returns (uint224 z) { z = uint224(y) * Q112; // never overflows } // divide a UQ112x112 by a uint112, returning a UQ112x112 function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) { z = x / uint224(y); } }
// SPDX-License-Identifier: MIT pragma solidity 0.6.11; import './IWETH.sol'; // Copyright (C) 2015, 2016, 2017 Dapphub // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. contract WETH is IWETH { string public name = "Wrapped Ether"; string public symbol = "WETH"; uint8 public decimals = 18; event Approval(address indexed src, address indexed guy, uint wad); event Transfer(address indexed src, address indexed dst, uint wad); event Deposit(address indexed dst, uint wad); event Withdrawal(address indexed src, uint wad); mapping (address => uint) public balanceOf; mapping (address => mapping (address => uint)) public allowance; fallback() external payable { deposit(); } receive() external payable { } constructor (address _creator_address ) public { balanceOf[_creator_address] = 1000000e18; // this is for testing only } function deposit() public override payable { balanceOf[msg.sender] += msg.value; emit Deposit(msg.sender, msg.value); } function withdraw(uint wad) override public { require(balanceOf[msg.sender] >= wad); balanceOf[msg.sender] -= wad; msg.sender.transfer(wad); emit Withdrawal(msg.sender, wad); } function totalSupply() public view returns (uint) { return address(this).balance; } function approve(address guy, uint wad) public returns (bool) { allowance[msg.sender][guy] = wad; emit Approval(msg.sender, guy, wad); return true; } function transfer(address dst, uint wad) public override returns (bool) { return transferFrom(msg.sender, dst, wad); } function transferFrom(address src, address dst, uint wad) public override returns (bool) { require(balanceOf[src] >= wad); if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) { require(allowance[src][msg.sender] >= wad); allowance[src][msg.sender] -= wad; } balanceOf[src] -= wad; balanceOf[dst] += wad; emit Transfer(src, dst, wad); return true; } } /* GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: <program> Copyright (C) <year> <name of author> This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <http://www.gnu.org/licenses/>. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <http://www.gnu.org/philosophy/why-not-lgpl.html>. */
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"address","name":"_creator_address","type":"address"},{"internalType":"address","name":"_timelock_address","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"FRAXBurned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"FRAXMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"COLLATERAL_RATIO_PAUSER","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pool_address","type":"address"}],"name":"addPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burnFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collateral_ratio_paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"controller_address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"creator_address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"eth_usd_consumer_address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"eth_usd_price","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"frax_eth_oracle_address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"frax_info","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"frax_pools","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"frax_pools_array","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"frax_price","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"frax_step","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fxs_address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fxs_eth_oracle_address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fxs_price","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"genesis_supply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"globalCollateralValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"global_collateral_ratio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"last_call_time","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minting_fee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner_address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"b_address","type":"address"},{"internalType":"uint256","name":"b_amount","type":"uint256"}],"name":"pool_burn_from","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"m_address","type":"address"},{"internalType":"uint256","name":"m_amount","type":"uint256"}],"name":"pool_mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"price_band","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"price_target","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"redemption_fee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"refreshCollateralRatio","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"refresh_cooldown","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pool_address","type":"address"}],"name":"removePool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_controller_address","type":"address"}],"name":"setController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_eth_usd_consumer_address","type":"address"}],"name":"setETHUSDOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_frax_oracle_addr","type":"address"},{"internalType":"address","name":"_weth_address","type":"address"}],"name":"setFRAXEthOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_fxs_address","type":"address"}],"name":"setFXSAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_fxs_oracle_addr","type":"address"},{"internalType":"address","name":"_weth_address","type":"address"}],"name":"setFXSEthOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_new_step","type":"uint256"}],"name":"setFraxStep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"min_fee","type":"uint256"}],"name":"setMintingFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner_address","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_price_band","type":"uint256"}],"name":"setPriceBand","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_new_price_target","type":"uint256"}],"name":"setPriceTarget","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"red_fee","type":"uint256"}],"name":"setRedemptionFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_new_cooldown","type":"uint256"}],"name":"setRefreshCooldown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"new_timelock","type":"address"}],"name":"setTimelock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"timelock_address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"toggleCollateralRatio","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"weth_address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
6080604052601b805460ff60a01b191690553480156200001e57600080fd5b50604051620041ca380380620041ca83398101604081905262000041916200060f565b835162000056906008906020870190620004ae565b5082516200006c906007906020860190620004ae565b50600a80546001600160a01b038085166001600160a01b031992831617909255600b805492841692909116919091179055620000c56000620000b66001600160e01b03620001b316565b6001600160e01b03620001b816565b620000d86001600160e01b03620001b316565b601b80546001600160a01b03199081166001600160a01b039384161790915560098054909116848316179055600a546200011f91166a01a784379d99db42000000620001d1565b6200015560405162000131906200069d565b604051908190039020600a546001600160a01b03166001600160e01b03620002c616565b6200018b60405162000167906200069d565b604051908190039020600b546001600160a01b03166001600160e01b03620002c616565b50506109c46017555050620f42406014819055610e10601855601955611388601a556200078c565b335b90565b620001cd82826001600160e01b036200031e16565b5050565b6001600160a01b038216620002035760405162461bcd60e51b8152600401620001fa906200074c565b60405180910390fd5b6200021a600083836001600160e01b03620003a216565b6200023681600254620003a760201b620023f71790919060201c565b6002556001600160a01b0382166000908152602081815260409091205462000269918390620023f7620003a7821b17901c565b6001600160a01b0383166000818152602081905260408082209390935591519091907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90620002ba90859062000783565b60405180910390a35050565b600082815260036020526040902060020154620002ff90620002f06001600160e01b03620001b316565b6001600160e01b03620003d816565b620001b85760405162461bcd60e51b8152600401620001fa90620006c6565b60008281526003602090815260409091206200034591839062002436620003fe821b17901c565b15620001cd576200035e6001600160e01b03620001b316565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b505050565b600082820183811015620003cf5760405162461bcd60e51b8152600401620001fa9062000715565b90505b92915050565b60008281526003602090815260408220620003cf918490620024586200041e821b17901c565b6000620003cf836001600160a01b0384166001600160e01b036200043e16565b6000620003cf836001600160a01b0384166001600160e01b036200049616565b60006200045583836001600160e01b036200049616565b6200048d57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155620003d2565b506000620003d2565b60009081526001919091016020526040902054151590565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10620004f157805160ff191683800117855562000521565b8280016001018555821562000521579182015b828111156200052157825182559160200191906001019062000504565b506200052f92915062000533565b5090565b620001b591905b808211156200052f57600081556001016200053a565b80516001600160a01b0381168114620003d257600080fd5b600082601f83011262000579578081fd5b81516001600160401b038082111562000590578283fd5b6040516020601f8401601f1916820181018381118382101715620005b2578586fd5b80604052508194508382528681858801011115620005cf57600080fd5b600092505b83831015620005f35785830181015182840182015291820191620005d4565b83831115620006055760008185840101525b5050505092915050565b6000806000806080858703121562000625578384fd5b84516001600160401b03808211156200063c578586fd5b6200064a8883890162000568565b9550602087015191508082111562000660578485fd5b506200066f8782880162000568565b93505062000681866040870162000550565b915062000692866060870162000550565b905092959194509250565b7f434f4c4c41544552414c5f524154494f5f504155534552000000000000000000815260170190565b6020808252602f908201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60408201526e0818591b5a5b881d1bc819dc985b9d608a1b606082015260800190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b6020808252601f908201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604082015260600190565b90815260200190565b613a2e806200079c6000396000f3fe608060405234801561001057600080fd5b506004361061043c5760003560e01c80637bac07c711610235578063bdacb30311610135578063cb73999f116100c8578063dc6663c711610097578063df56e1681161007c578063df56e1681461080b578063e223e9a914610827578063e7dced671461083a5761043c565b8063dc6663c7146107f0578063dd62ed3e146107f85761043c565b8063cb73999f146107ba578063d2d97b06146107c2578063d547741f146107ca578063d914cd4b146107dd5761043c565b8063c3bc891011610104578063c3bc891014610784578063c8fae1a514610797578063ca15c8731461079f578063ca65be0b146107b25761043c565b8063bdacb30314610759578063bef40ec81461076c578063c03f7be314610774578063c3355b8d1461077c5761043c565b8063a217fddf116101c8578063ad9f6eec11610197578063b0fc69ce1161017c578063b0fc69ce14610736578063b4db09801461073e578063b4f56b26146107465761043c565b8063ad9f6eec14610710578063afe92c1a146107235761043c565b8063a217fddf146106cf578063a457c2d7146106d7578063a8a778ae146106ea578063a9059cbb146106fd5761043c565b80639010d07c116102045780639010d07c1461068e57806391d14854146106a157806392eefe9b146106b457806395d89b41146106c75761043c565b80637bac07c7146106635780637dbc1df01461066b57806380edef8e1461067e57806387a140c3146106865761043c565b806335467d5d1161034057806351e238e3116102d357806367feda3e116102a257806372b3cded1161028757806372b3cded14610635578063741d3c181461063d57806379cc6790146106505761043c565b806367feda3e1461061a57806370a08231146106225761043c565b806351e238e3146105e457806354505517146105ec57806355189488146105f45780636140133b146106075761043c565b80634013124a1161030f5780634013124a146105ae578063408ab10f146105b657806342966c68146105c95780634bd0be23146105dc5761043c565b806335467d5d1461056d57806336568abe1461057557806339509351146105885780633b7d09461461059b5761043c565b806323b872dd116103d35780632cb4f63e116103a25780632f2ff15d116103875780632f2ff15d1461053d578063313ce56714610550578063345ba24b146105655761043c565b80632cb4f63e1461052d5780632eb9771b146105355761043c565b806323b872dd146104f7578063246126bd1461050a578063248a9ca3146105125780632853fb10146105255761043c565b806318160ddd1161040f57806318160ddd146104b45780631c5df1e5146104c95780632258750a146104dc578063238a4709146104e45761043c565b806306fdde0314610441578063095ea7b31461045f5780630f9d20011461047f57806313af40351461049f575b600080fd5b610449610842565b6040516104569190613241565b60405180910390f35b61047261046d3660046130f2565b6108ee565b604051610456919061322d565b61049261048d36600461311c565b61090c565b60405161045691906131e6565b6104b26104ad366004613063565b610940565b005b6104bc610a25565b6040516104569190613238565b6104b26104d736600461311c565b610a2b565b6104bc610ac5565b6104b26104f236600461311c565b610acb565b6104726105053660046130b2565b610b65565b610492610c0c565b6104bc61052036600461311c565b610c28565b6104bc610c3d565b6104bc610c43565b6104bc610c49565b6104b261054b366004613134565b610c4f565b610558610cb1565b604051610456919061390f565b6104bc610cb6565b610492610da3565b6104b2610583366004613134565b610dbf565b6104726105963660046130f2565b610e35565b6104b26105a9366004613063565b610e96565b6104b2611095565b6104b26105c436600461311c565b6111ed565b6104b26105d736600461311c565b611287565b61049261129b565b6104bc6112b7565b6104bc6112c6565b610472610602366004613063565b6112dd565b6104b261061536600461311c565b6112f2565b61049261138c565b6104bc610630366004613063565b6113a8565b6104926113d0565b6104b261064b366004613063565b6113ec565b6104b261065e3660046130f2565b61157e565b6104bc6115d9565b6104b261067936600461311c565b6115df565b610492611679565b610472611695565b61049261069c366004613163565b6116b6565b6104726106af366004613134565b6116db565b6104b26106c2366004613063565b6116f9565b6104496117d5565b6104bc61184e565b6104726106e53660046130f2565b611853565b6104b26106f83660046130f2565b6118ce565b61047261070b3660046130f2565b61198f565b6104b261071e36600461311c565b6119a3565b6104b261073136600461307e565b611a3d565b610492611b32565b6104bc611b4e565b6104b26107543660046130f2565b611b5a565b6104b2610767366004613063565b611c0f565b6104b2611ceb565b6104bc611d5e565b6104bc611d64565b6104b2610792366004613063565b611d6a565b610492611e46565b6104bc6107ad36600461311c565b611e62565b610492611e79565b6104bc611e95565b6104bc611e9b565b6104b26107d8366004613134565b611fcb565b6104b26107eb366004613063565b61201f565b6104926121bd565b6104bc61080636600461307e565b6121d9565b610813612211565b6040516104569897969594939291906138d9565b6104b261083536600461307e565b6122f6565b6104bc6123eb565b6008805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f810184900484028201840190925281815292918301828280156108e65780601f106108bb576101008083540402835291602001916108e6565b820191906000526020600020905b8154815290600101906020018083116108c957829003601f168201915b505050505081565b60006109026108fb61247a565b848461247e565b5060015b92915050565b6012818154811061091957fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b60095473ffffffffffffffffffffffffffffffffffffffff1633148061097d5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b8061099f5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b6109de576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b60405180910390fd5b600980547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60025490565b60095473ffffffffffffffffffffffffffffffffffffffff16331480610a685750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80610a8a5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b610ac0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601855565b601c5481565b60095473ffffffffffffffffffffffffffffffffffffffff16331480610b085750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80610b2a5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b610b60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601655565b6000610b7284848461258d565b610c0284610b7e61247a565b610bfd856040518060600160405280602881526020016139886028913973ffffffffffffffffffffffffffffffffffffffff8a16600090815260016020526040812090610bc961247a565b73ffffffffffffffffffffffffffffffffffffffff168152602081019190915260400160002054919063ffffffff61272316565b61247e565b5060019392505050565b60105473ffffffffffffffffffffffffffffffffffffffff1681565b60009081526003602052604090206002015490565b601a5481565b60195481565b60145481565b600082815260036020526040902060020154610c6d906106af61247a565b610ca3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061336c565b610cad8282612769565b5050565b601281565b60048054604080517f8e15f4730000000000000000000000000000000000000000000000000000000081529051600093610d9e9360ff74010000000000000000000000000000000000000000820416600a0a93610d9293620f42409373ffffffffffffffffffffffffffffffffffffffff90931692638e15f47392808201926020929091829003018186803b158015610d4e57600080fd5b505afa158015610d62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d869190613184565b9063ffffffff6127f216565b9063ffffffff61284616565b905090565b601b5473ffffffffffffffffffffffffffffffffffffffff1681565b610dc761247a565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610e2b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613845565b610cad8282612888565b6000610902610e4261247a565b84610bfd8560016000610e5361247a565b73ffffffffffffffffffffffffffffffffffffffff908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff6123f716565b60095473ffffffffffffffffffffffffffffffffffffffff16331480610ed35750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80610ef55750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b610f2b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b73ffffffffffffffffffffffffffffffffffffffff811660009081526013602052604090205460ff161515600114610f8f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613517565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260136020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690555b601254811015610cad578173ffffffffffffffffffffffffffffffffffffffff166012828154811061100957fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16141561108d5760006012828154811061104057fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610cad565b600101610fdb565b601b5474010000000000000000000000000000000000000000900460ff16156110ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906137d9565b60006110f4611b4e565b9050601854601c5442031015611136576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061377c565b601a5460195461114b9163ffffffff6123f716565b8111156111855760175460145411611167576000601455611180565b60175460145461117c9163ffffffff61291116565b6014555b6111e6565b601a5460195461119a9163ffffffff61291116565b8110156111e657620f42406111bc6017546014546123f790919063ffffffff16565b106111cd57620f42406014556111e6565b6017546014546111e29163ffffffff6123f716565b6014555b5042601c55565b60095473ffffffffffffffffffffffffffffffffffffffff1633148061122a5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b8061124c5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611282576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601955565b61129861129261247a565b82612953565b50565b600a5473ffffffffffffffffffffffffffffffffffffffff1681565b6a01a784379d99db4200000081565b6040516112d2906131bd565b604051809103902081565b60136020526000908152604090205460ff1681565b60095473ffffffffffffffffffffffffffffffffffffffff1633148061132f5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b806113515750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611387576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601a55565b600c5473ffffffffffffffffffffffffffffffffffffffff1681565b73ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090205490565b600e5473ffffffffffffffffffffffffffffffffffffffff1681565b60095473ffffffffffffffffffffffffffffffffffffffff163314806114295750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b8061144b5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611481576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b6011805473ffffffffffffffffffffffffffffffffffffffff8084167fffffffffffffffffffffffff000000000000000000000000000000000000000092831617928390556004805490921692811692909217808255604080517ff0141d840000000000000000000000000000000000000000000000000000000081529051919093169263f0141d849281810192602092909190829003018186803b15801561152957600080fd5b505afa15801561153d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611561919061319c565b600460146101000a81548160ff021916908360ff16021790555050565b60006115b6826040518060600160405280602481526020016139b0602491396115a98661080661247a565b919063ffffffff61272316565b90506115ca836115c461247a565b8361247e565b6115d48383612953565b505050565b60175481565b60095473ffffffffffffffffffffffffffffffffffffffff1633148061161c5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b8061163e5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611674576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601555565b60095473ffffffffffffffffffffffffffffffffffffffff1681565b601b5474010000000000000000000000000000000000000000900460ff1681565b60008281526003602052604081206116d4908363ffffffff612a8316565b9392505050565b60008281526003602052604081206116d4908363ffffffff61245816565b60095473ffffffffffffffffffffffffffffffffffffffff163314806117365750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b806117585750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b61178e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b600c80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6007805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f810184900484028201840190925281815292918301828280156108e65780601f106108bb576101008083540402835291602001916108e6565b600081565b600061090261186061247a565b84610bfd856040518060600160405280602581526020016139d4602591396001600061188a61247a565b73ffffffffffffffffffffffffffffffffffffffff908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff61272316565b3360009081526013602052604090205460ff16151560011461191c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906134ba565b6119268282612a8f565b3373ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167ffead881ad94a58eeaebfdbce8eeb9906a0f42f0c896bab64a6ad08371608131a836040516119839190613238565b60405180910390a35050565b600061090261199c61247a565b848461258d565b60095473ffffffffffffffffffffffffffffffffffffffff163314806119e05750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80611a025750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611a38576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601755565b60095473ffffffffffffffffffffffffffffffffffffffff16331480611a7a5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80611a9c5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611ad2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b600f805473ffffffffffffffffffffffffffffffffffffffff9384167fffffffffffffffffffffffff0000000000000000000000000000000000000000918216811790925560068054821690921790915560108054929093169116179055565b60115473ffffffffffffffffffffffffffffffffffffffff1681565b6000610d9e6000612af0565b3360009081526013602052604090205460ff161515600114611ba8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906134ba565b611bb28282612d17565b8173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f1c0ed02ca521f3f5782d6c218460a4d053afba959cf41837f405d16e201e31c5836040516119839190613238565b60095473ffffffffffffffffffffffffffffffffffffffff16331480611c4c5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80611c6e5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611ca4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b600b80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b611d08604051611cfa906131bd565b6040518091039020336116db565b611d1157600080fd5b601b80547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff8116740100000000000000000000000000000000000000009182900460ff1615909102179055565b60185481565b60165481565b60095473ffffffffffffffffffffffffffffffffffffffff16331480611da75750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80611dc95750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611dff576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b600d80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600d5473ffffffffffffffffffffffffffffffffffffffff1681565b600081815260036020526040812061090690612e18565b600f5473ffffffffffffffffffffffffffffffffffffffff1681565b60155481565b600080805b601254811015611fc557600073ffffffffffffffffffffffffffffffffffffffff1660128281548110611ecf57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1614611fbd57611fba60128281548110611f0657fe5b60009182526020918290200154604080517f17284c94000000000000000000000000000000000000000000000000000000008152905173ffffffffffffffffffffffffffffffffffffffff909216926317284c9492600480840193829003018186803b158015611f7557600080fd5b505afa158015611f89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fad9190613184565b839063ffffffff6123f716565b91505b600101611ea0565b50905090565b600082815260036020526040902060020154611fe9906106af61247a565b610e2b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061354e565b60095473ffffffffffffffffffffffffffffffffffffffff1633148061205c5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b8061207e5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b6120b4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b73ffffffffffffffffffffffffffffffffffffffff811660009081526013602052604090205460ff1615612114576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061380e565b73ffffffffffffffffffffffffffffffffffffffff16600081815260136020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660019081179091556012805491820181559091527fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec34440180547fffffffffffffffffffffffff0000000000000000000000000000000000000000169091179055565b600b5473ffffffffffffffffffffffffffffffffffffffff1681565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260016020908152604080832093909416825291909152205490565b6000806000806000806000806122276000612af0565b6122316001612af0565b612239610a25565b601454612244611e9b565b60165460155460048054604080517f8e15f47300000000000000000000000000000000000000000000000000000000815290516122de9360ff74010000000000000000000000000000000000000000850416600a0a93610d9293620f42409373ffffffffffffffffffffffffffffffffffffffff90921692638e15f473928282019260209290829003018186803b158015610d4e57600080fd5b969f959e50939c50919a509850965094509092509050565b60095473ffffffffffffffffffffffffffffffffffffffff163314806123335750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b806123555750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b61238b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b600e805473ffffffffffffffffffffffffffffffffffffffff9384167fffffffffffffffffffffffff0000000000000000000000000000000000000000918216811790925560058054821690921790915560108054929093169116179055565b6000610d9e6001612af0565b6000828201838110156116d4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613483565b60006116d48373ffffffffffffffffffffffffffffffffffffffff8416612e23565b60006116d48373ffffffffffffffffffffffffffffffffffffffff8416612e6d565b3390565b73ffffffffffffffffffffffffffffffffffffffff83166124cb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061371f565b73ffffffffffffffffffffffffffffffffffffffff8216612518576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613426565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526001602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590612580908590613238565b60405180910390a3505050565b73ffffffffffffffffffffffffffffffffffffffff83166125da576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906136c2565b73ffffffffffffffffffffffffffffffffffffffff8216612627576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061330f565b6126328383836115d4565b612682816040518060600160405280602681526020016139626026913973ffffffffffffffffffffffffffffffffffffffff8616600090815260208190526040902054919063ffffffff61272316565b73ffffffffffffffffffffffffffffffffffffffff80851660009081526020819052604080822093909355908416815220546126c4908263ffffffff6123f716565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526020819052604090819020939093559151908516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90612580908590613238565b60008184841115612761576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59190613241565b505050900390565b6000828152600360205260409020612787908263ffffffff61243616565b15610cad5761279461247a565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008261280157506000610906565b8282028284828161280e57fe5b04146116d4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613608565b60006116d483836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612e85565b60008281526003602052604090206128a6908263ffffffff612ed616565b15610cad576128b361247a565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b60006116d483836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250612723565b73ffffffffffffffffffffffffffffffffffffffff82166129a0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613665565b6129ac826000836115d4565b6129fc816040518060600160405280602281526020016139406022913973ffffffffffffffffffffffffffffffffffffffff8516600090815260208190526040902054919063ffffffff61272316565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260208190526040902055600254612a35908263ffffffff61291116565b60025560405160009073ffffffffffffffffffffffffffffffffffffffff8416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90611983908590613238565b60006116d48383612ef8565b612a998282612953565b610cad82612aa561247a565b610bfd846040518060600160405280602481526020016139b06024913973ffffffffffffffffffffffffffffffffffffffff8816600090815260016020526040812090610bc961247a565b60048054604080517f8e15f47300000000000000000000000000000000000000000000000000000000815290516000938493612b869360ff74010000000000000000000000000000000000000000830416600a0a93610d9293620f42409373ffffffffffffffffffffffffffffffffffffffff1692638e15f4739281830192602092829003018186803b158015610d4e57600080fd5b9050600080846001811115612b9757fe5b1415612c53576005546010546040517f3ddac95300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff92831692633ddac95392612bfc92911690620f424090600401613207565b60206040518083038186803b158015612c1457600080fd5b505afa158015612c28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c4c9190613184565b9050612cf8565b6001846001811115612c6157fe5b1415612cc6576006546010546040517f3ddac95300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff92831692633ddac95392612bfc92911690620f424090600401613207565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906133c9565b612d0f81610d9284620f424063ffffffff6127f216565b949350505050565b73ffffffffffffffffffffffffffffffffffffffff8216612d64576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906138a2565b612d70600083836115d4565b600254612d83908263ffffffff6123f716565b60025573ffffffffffffffffffffffffffffffffffffffff8216600090815260208190526040902054612dbc908263ffffffff6123f716565b73ffffffffffffffffffffffffffffffffffffffff83166000818152602081905260408082209390935591519091907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90611983908590613238565b600061090682612f57565b6000612e2f8383612e6d565b612e6557508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610906565b506000610906565b60009081526001919091016020526040902054151590565b60008183612ec0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59190613241565b506000838581612ecc57fe5b0495945050505050565b60006116d48373ffffffffffffffffffffffffffffffffffffffff8416612f5b565b81546000908210612f35576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906132b2565b826000018281548110612f4457fe5b9060005260206000200154905092915050565b5490565b600081815260018301602052604081205480156130355783547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8083019190810190600090879083908110612fac57fe5b9060005260206000200154905080876000018481548110612fc957fe5b600091825260208083209091019290925582815260018981019092526040902090840190558654879080612ff957fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610906565b6000915050610906565b803573ffffffffffffffffffffffffffffffffffffffff8116811461090657600080fd5b600060208284031215613074578081fd5b6116d4838361303f565b60008060408385031215613090578081fd5b61309a848461303f565b91506130a9846020850161303f565b90509250929050565b6000806000606084860312156130c6578081fd5b83356130d18161391d565b925060208401356130e18161391d565b929592945050506040919091013590565b60008060408385031215613104578182fd5b61310e848461303f565b946020939093013593505050565b60006020828403121561312d578081fd5b5035919050565b60008060408385031215613146578182fd5b8235915060208301356131588161391d565b809150509250929050565b60008060408385031215613175578182fd5b50508035926020909101359150565b600060208284031215613195578081fd5b5051919050565b6000602082840312156131ad578081fd5b815160ff811681146116d4578182fd5b7f434f4c4c41544552414c5f524154494f5f504155534552000000000000000000815260170190565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b901515815260200190565b90815260200190565b6000602080835283518082850152825b8181101561326d57858101830151858201604001528201613251565b8181111561327e5783604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b60208082526022908201527f456e756d657261626c655365743a20696e646578206f7574206f6620626f756e60408201527f6473000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526023908201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260408201527f6573730000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252602f908201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60408201527f2061646d696e20746f206772616e740000000000000000000000000000000000606082015260800190565b6020808252603c908201527f494e56414c49442050524943452043484f4943452e204e6565647320746f206260408201527f6520656974686572203020284652415829206f72203120284658532900000000606082015260800190565b60208082526022908201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560408201527f7373000000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b60208082526026908201527f4f6e6c79206672617820706f6f6c732063616e2063616c6c207468697320667560408201527f6e6374696f6e0000000000000000000000000000000000000000000000000000606082015260800190565b6020808252601d908201527f6164647265737320646f65736e277420657869737420616c7265616479000000604082015260600190565b60208082526030908201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60408201527f2061646d696e20746f207265766f6b6500000000000000000000000000000000606082015260800190565b6020808252603d908201527f596f7520617265206e6f7420746865206f776e65722c20636f6e74726f6c6c6560408201527f722c206f722074686520676f7665726e616e63652074696d656c6f636b000000606082015260800190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60408201527f7700000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526021908201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360408201527f7300000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526025908201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460408201527f6472657373000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526024908201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460408201527f7265737300000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526035908201527f4d757374207761697420666f7220746865207265667265736820636f6f6c646f60408201527f776e2073696e6365206c61737420726566726573680000000000000000000000606082015260800190565b6020808252818101527f436f6c6c61746572616c20526174696f20686173206265656e20706175736564604082015260600190565b60208082526016908201527f6164647265737320616c72656164792065786973747300000000000000000000604082015260600190565b6020808252602f908201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560408201527f20726f6c657320666f722073656c660000000000000000000000000000000000606082015260800190565b6020808252601f908201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604082015260600190565b978852602088019690965260408701949094526060860192909252608085015260a084015260c083015260e08201526101000190565b60ff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff8116811461129857600080fdfe45524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e20616d6f756e74206578636565647320616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220c630a447c03c2d225020ed5ca2de4d23ef8beed5537e9903659785e18d2949ea64736f6c634300060b0033000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000234d953a9404bf9dbc3b526271d440cd2870bcd20000000000000000000000008412ebf45bac1b340bbe8f318b928c466c4e39ca0000000000000000000000000000000000000000000000000000000000000004467261780000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044652415800000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061043c5760003560e01c80637bac07c711610235578063bdacb30311610135578063cb73999f116100c8578063dc6663c711610097578063df56e1681161007c578063df56e1681461080b578063e223e9a914610827578063e7dced671461083a5761043c565b8063dc6663c7146107f0578063dd62ed3e146107f85761043c565b8063cb73999f146107ba578063d2d97b06146107c2578063d547741f146107ca578063d914cd4b146107dd5761043c565b8063c3bc891011610104578063c3bc891014610784578063c8fae1a514610797578063ca15c8731461079f578063ca65be0b146107b25761043c565b8063bdacb30314610759578063bef40ec81461076c578063c03f7be314610774578063c3355b8d1461077c5761043c565b8063a217fddf116101c8578063ad9f6eec11610197578063b0fc69ce1161017c578063b0fc69ce14610736578063b4db09801461073e578063b4f56b26146107465761043c565b8063ad9f6eec14610710578063afe92c1a146107235761043c565b8063a217fddf146106cf578063a457c2d7146106d7578063a8a778ae146106ea578063a9059cbb146106fd5761043c565b80639010d07c116102045780639010d07c1461068e57806391d14854146106a157806392eefe9b146106b457806395d89b41146106c75761043c565b80637bac07c7146106635780637dbc1df01461066b57806380edef8e1461067e57806387a140c3146106865761043c565b806335467d5d1161034057806351e238e3116102d357806367feda3e116102a257806372b3cded1161028757806372b3cded14610635578063741d3c181461063d57806379cc6790146106505761043c565b806367feda3e1461061a57806370a08231146106225761043c565b806351e238e3146105e457806354505517146105ec57806355189488146105f45780636140133b146106075761043c565b80634013124a1161030f5780634013124a146105ae578063408ab10f146105b657806342966c68146105c95780634bd0be23146105dc5761043c565b806335467d5d1461056d57806336568abe1461057557806339509351146105885780633b7d09461461059b5761043c565b806323b872dd116103d35780632cb4f63e116103a25780632f2ff15d116103875780632f2ff15d1461053d578063313ce56714610550578063345ba24b146105655761043c565b80632cb4f63e1461052d5780632eb9771b146105355761043c565b806323b872dd146104f7578063246126bd1461050a578063248a9ca3146105125780632853fb10146105255761043c565b806318160ddd1161040f57806318160ddd146104b45780631c5df1e5146104c95780632258750a146104dc578063238a4709146104e45761043c565b806306fdde0314610441578063095ea7b31461045f5780630f9d20011461047f57806313af40351461049f575b600080fd5b610449610842565b6040516104569190613241565b60405180910390f35b61047261046d3660046130f2565b6108ee565b604051610456919061322d565b61049261048d36600461311c565b61090c565b60405161045691906131e6565b6104b26104ad366004613063565b610940565b005b6104bc610a25565b6040516104569190613238565b6104b26104d736600461311c565b610a2b565b6104bc610ac5565b6104b26104f236600461311c565b610acb565b6104726105053660046130b2565b610b65565b610492610c0c565b6104bc61052036600461311c565b610c28565b6104bc610c3d565b6104bc610c43565b6104bc610c49565b6104b261054b366004613134565b610c4f565b610558610cb1565b604051610456919061390f565b6104bc610cb6565b610492610da3565b6104b2610583366004613134565b610dbf565b6104726105963660046130f2565b610e35565b6104b26105a9366004613063565b610e96565b6104b2611095565b6104b26105c436600461311c565b6111ed565b6104b26105d736600461311c565b611287565b61049261129b565b6104bc6112b7565b6104bc6112c6565b610472610602366004613063565b6112dd565b6104b261061536600461311c565b6112f2565b61049261138c565b6104bc610630366004613063565b6113a8565b6104926113d0565b6104b261064b366004613063565b6113ec565b6104b261065e3660046130f2565b61157e565b6104bc6115d9565b6104b261067936600461311c565b6115df565b610492611679565b610472611695565b61049261069c366004613163565b6116b6565b6104726106af366004613134565b6116db565b6104b26106c2366004613063565b6116f9565b6104496117d5565b6104bc61184e565b6104726106e53660046130f2565b611853565b6104b26106f83660046130f2565b6118ce565b61047261070b3660046130f2565b61198f565b6104b261071e36600461311c565b6119a3565b6104b261073136600461307e565b611a3d565b610492611b32565b6104bc611b4e565b6104b26107543660046130f2565b611b5a565b6104b2610767366004613063565b611c0f565b6104b2611ceb565b6104bc611d5e565b6104bc611d64565b6104b2610792366004613063565b611d6a565b610492611e46565b6104bc6107ad36600461311c565b611e62565b610492611e79565b6104bc611e95565b6104bc611e9b565b6104b26107d8366004613134565b611fcb565b6104b26107eb366004613063565b61201f565b6104926121bd565b6104bc61080636600461307e565b6121d9565b610813612211565b6040516104569897969594939291906138d9565b6104b261083536600461307e565b6122f6565b6104bc6123eb565b6008805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f810184900484028201840190925281815292918301828280156108e65780601f106108bb576101008083540402835291602001916108e6565b820191906000526020600020905b8154815290600101906020018083116108c957829003601f168201915b505050505081565b60006109026108fb61247a565b848461247e565b5060015b92915050565b6012818154811061091957fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b60095473ffffffffffffffffffffffffffffffffffffffff1633148061097d5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b8061099f5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b6109de576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b60405180910390fd5b600980547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60025490565b60095473ffffffffffffffffffffffffffffffffffffffff16331480610a685750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80610a8a5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b610ac0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601855565b601c5481565b60095473ffffffffffffffffffffffffffffffffffffffff16331480610b085750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80610b2a5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b610b60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601655565b6000610b7284848461258d565b610c0284610b7e61247a565b610bfd856040518060600160405280602881526020016139886028913973ffffffffffffffffffffffffffffffffffffffff8a16600090815260016020526040812090610bc961247a565b73ffffffffffffffffffffffffffffffffffffffff168152602081019190915260400160002054919063ffffffff61272316565b61247e565b5060019392505050565b60105473ffffffffffffffffffffffffffffffffffffffff1681565b60009081526003602052604090206002015490565b601a5481565b60195481565b60145481565b600082815260036020526040902060020154610c6d906106af61247a565b610ca3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061336c565b610cad8282612769565b5050565b601281565b60048054604080517f8e15f4730000000000000000000000000000000000000000000000000000000081529051600093610d9e9360ff74010000000000000000000000000000000000000000820416600a0a93610d9293620f42409373ffffffffffffffffffffffffffffffffffffffff90931692638e15f47392808201926020929091829003018186803b158015610d4e57600080fd5b505afa158015610d62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d869190613184565b9063ffffffff6127f216565b9063ffffffff61284616565b905090565b601b5473ffffffffffffffffffffffffffffffffffffffff1681565b610dc761247a565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610e2b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613845565b610cad8282612888565b6000610902610e4261247a565b84610bfd8560016000610e5361247a565b73ffffffffffffffffffffffffffffffffffffffff908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff6123f716565b60095473ffffffffffffffffffffffffffffffffffffffff16331480610ed35750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80610ef55750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b610f2b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b73ffffffffffffffffffffffffffffffffffffffff811660009081526013602052604090205460ff161515600114610f8f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613517565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260136020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690555b601254811015610cad578173ffffffffffffffffffffffffffffffffffffffff166012828154811061100957fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16141561108d5760006012828154811061104057fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610cad565b600101610fdb565b601b5474010000000000000000000000000000000000000000900460ff16156110ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906137d9565b60006110f4611b4e565b9050601854601c5442031015611136576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061377c565b601a5460195461114b9163ffffffff6123f716565b8111156111855760175460145411611167576000601455611180565b60175460145461117c9163ffffffff61291116565b6014555b6111e6565b601a5460195461119a9163ffffffff61291116565b8110156111e657620f42406111bc6017546014546123f790919063ffffffff16565b106111cd57620f42406014556111e6565b6017546014546111e29163ffffffff6123f716565b6014555b5042601c55565b60095473ffffffffffffffffffffffffffffffffffffffff1633148061122a5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b8061124c5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611282576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601955565b61129861129261247a565b82612953565b50565b600a5473ffffffffffffffffffffffffffffffffffffffff1681565b6a01a784379d99db4200000081565b6040516112d2906131bd565b604051809103902081565b60136020526000908152604090205460ff1681565b60095473ffffffffffffffffffffffffffffffffffffffff1633148061132f5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b806113515750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611387576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601a55565b600c5473ffffffffffffffffffffffffffffffffffffffff1681565b73ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090205490565b600e5473ffffffffffffffffffffffffffffffffffffffff1681565b60095473ffffffffffffffffffffffffffffffffffffffff163314806114295750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b8061144b5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611481576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b6011805473ffffffffffffffffffffffffffffffffffffffff8084167fffffffffffffffffffffffff000000000000000000000000000000000000000092831617928390556004805490921692811692909217808255604080517ff0141d840000000000000000000000000000000000000000000000000000000081529051919093169263f0141d849281810192602092909190829003018186803b15801561152957600080fd5b505afa15801561153d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611561919061319c565b600460146101000a81548160ff021916908360ff16021790555050565b60006115b6826040518060600160405280602481526020016139b0602491396115a98661080661247a565b919063ffffffff61272316565b90506115ca836115c461247a565b8361247e565b6115d48383612953565b505050565b60175481565b60095473ffffffffffffffffffffffffffffffffffffffff1633148061161c5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b8061163e5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611674576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601555565b60095473ffffffffffffffffffffffffffffffffffffffff1681565b601b5474010000000000000000000000000000000000000000900460ff1681565b60008281526003602052604081206116d4908363ffffffff612a8316565b9392505050565b60008281526003602052604081206116d4908363ffffffff61245816565b60095473ffffffffffffffffffffffffffffffffffffffff163314806117365750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b806117585750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b61178e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b600c80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6007805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f810184900484028201840190925281815292918301828280156108e65780601f106108bb576101008083540402835291602001916108e6565b600081565b600061090261186061247a565b84610bfd856040518060600160405280602581526020016139d4602591396001600061188a61247a565b73ffffffffffffffffffffffffffffffffffffffff908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff61272316565b3360009081526013602052604090205460ff16151560011461191c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906134ba565b6119268282612a8f565b3373ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167ffead881ad94a58eeaebfdbce8eeb9906a0f42f0c896bab64a6ad08371608131a836040516119839190613238565b60405180910390a35050565b600061090261199c61247a565b848461258d565b60095473ffffffffffffffffffffffffffffffffffffffff163314806119e05750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80611a025750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611a38576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b601755565b60095473ffffffffffffffffffffffffffffffffffffffff16331480611a7a5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80611a9c5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611ad2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b600f805473ffffffffffffffffffffffffffffffffffffffff9384167fffffffffffffffffffffffff0000000000000000000000000000000000000000918216811790925560068054821690921790915560108054929093169116179055565b60115473ffffffffffffffffffffffffffffffffffffffff1681565b6000610d9e6000612af0565b3360009081526013602052604090205460ff161515600114611ba8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906134ba565b611bb28282612d17565b8173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f1c0ed02ca521f3f5782d6c218460a4d053afba959cf41837f405d16e201e31c5836040516119839190613238565b60095473ffffffffffffffffffffffffffffffffffffffff16331480611c4c5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80611c6e5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611ca4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b600b80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b611d08604051611cfa906131bd565b6040518091039020336116db565b611d1157600080fd5b601b80547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff8116740100000000000000000000000000000000000000009182900460ff1615909102179055565b60185481565b60165481565b60095473ffffffffffffffffffffffffffffffffffffffff16331480611da75750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b80611dc95750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b611dff576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b600d80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600d5473ffffffffffffffffffffffffffffffffffffffff1681565b600081815260036020526040812061090690612e18565b600f5473ffffffffffffffffffffffffffffffffffffffff1681565b60155481565b600080805b601254811015611fc557600073ffffffffffffffffffffffffffffffffffffffff1660128281548110611ecf57fe5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff1614611fbd57611fba60128281548110611f0657fe5b60009182526020918290200154604080517f17284c94000000000000000000000000000000000000000000000000000000008152905173ffffffffffffffffffffffffffffffffffffffff909216926317284c9492600480840193829003018186803b158015611f7557600080fd5b505afa158015611f89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fad9190613184565b839063ffffffff6123f716565b91505b600101611ea0565b50905090565b600082815260036020526040902060020154611fe9906106af61247a565b610e2b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061354e565b60095473ffffffffffffffffffffffffffffffffffffffff1633148061205c5750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b8061207e5750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b6120b4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b73ffffffffffffffffffffffffffffffffffffffff811660009081526013602052604090205460ff1615612114576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061380e565b73ffffffffffffffffffffffffffffffffffffffff16600081815260136020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660019081179091556012805491820181559091527fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec34440180547fffffffffffffffffffffffff0000000000000000000000000000000000000000169091179055565b600b5473ffffffffffffffffffffffffffffffffffffffff1681565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260016020908152604080832093909416825291909152205490565b6000806000806000806000806122276000612af0565b6122316001612af0565b612239610a25565b601454612244611e9b565b60165460155460048054604080517f8e15f47300000000000000000000000000000000000000000000000000000000815290516122de9360ff74010000000000000000000000000000000000000000850416600a0a93610d9293620f42409373ffffffffffffffffffffffffffffffffffffffff90921692638e15f473928282019260209290829003018186803b158015610d4e57600080fd5b969f959e50939c50919a509850965094509092509050565b60095473ffffffffffffffffffffffffffffffffffffffff163314806123335750600b5473ffffffffffffffffffffffffffffffffffffffff1633145b806123555750600c5473ffffffffffffffffffffffffffffffffffffffff1633145b61238b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906135ab565b600e805473ffffffffffffffffffffffffffffffffffffffff9384167fffffffffffffffffffffffff0000000000000000000000000000000000000000918216811790925560058054821690921790915560108054929093169116179055565b6000610d9e6001612af0565b6000828201838110156116d4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613483565b60006116d48373ffffffffffffffffffffffffffffffffffffffff8416612e23565b60006116d48373ffffffffffffffffffffffffffffffffffffffff8416612e6d565b3390565b73ffffffffffffffffffffffffffffffffffffffff83166124cb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061371f565b73ffffffffffffffffffffffffffffffffffffffff8216612518576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613426565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526001602090815260408083209487168084529490915290819020849055517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590612580908590613238565b60405180910390a3505050565b73ffffffffffffffffffffffffffffffffffffffff83166125da576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906136c2565b73ffffffffffffffffffffffffffffffffffffffff8216612627576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59061330f565b6126328383836115d4565b612682816040518060600160405280602681526020016139626026913973ffffffffffffffffffffffffffffffffffffffff8616600090815260208190526040902054919063ffffffff61272316565b73ffffffffffffffffffffffffffffffffffffffff80851660009081526020819052604080822093909355908416815220546126c4908263ffffffff6123f716565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526020819052604090819020939093559151908516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90612580908590613238565b60008184841115612761576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59190613241565b505050900390565b6000828152600360205260409020612787908263ffffffff61243616565b15610cad5761279461247a565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008261280157506000610906565b8282028284828161280e57fe5b04146116d4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613608565b60006116d483836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250612e85565b60008281526003602052604090206128a6908263ffffffff612ed616565b15610cad576128b361247a565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a45050565b60006116d483836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f770000815250612723565b73ffffffffffffffffffffffffffffffffffffffff82166129a0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d590613665565b6129ac826000836115d4565b6129fc816040518060600160405280602281526020016139406022913973ffffffffffffffffffffffffffffffffffffffff8516600090815260208190526040902054919063ffffffff61272316565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260208190526040902055600254612a35908263ffffffff61291116565b60025560405160009073ffffffffffffffffffffffffffffffffffffffff8416907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90611983908590613238565b60006116d48383612ef8565b612a998282612953565b610cad82612aa561247a565b610bfd846040518060600160405280602481526020016139b06024913973ffffffffffffffffffffffffffffffffffffffff8816600090815260016020526040812090610bc961247a565b60048054604080517f8e15f47300000000000000000000000000000000000000000000000000000000815290516000938493612b869360ff74010000000000000000000000000000000000000000830416600a0a93610d9293620f42409373ffffffffffffffffffffffffffffffffffffffff1692638e15f4739281830192602092829003018186803b158015610d4e57600080fd5b9050600080846001811115612b9757fe5b1415612c53576005546010546040517f3ddac95300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff92831692633ddac95392612bfc92911690620f424090600401613207565b60206040518083038186803b158015612c1457600080fd5b505afa158015612c28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c4c9190613184565b9050612cf8565b6001846001811115612c6157fe5b1415612cc6576006546010546040517f3ddac95300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff92831692633ddac95392612bfc92911690620f424090600401613207565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906133c9565b612d0f81610d9284620f424063ffffffff6127f216565b949350505050565b73ffffffffffffffffffffffffffffffffffffffff8216612d64576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906138a2565b612d70600083836115d4565b600254612d83908263ffffffff6123f716565b60025573ffffffffffffffffffffffffffffffffffffffff8216600090815260208190526040902054612dbc908263ffffffff6123f716565b73ffffffffffffffffffffffffffffffffffffffff83166000818152602081905260408082209390935591519091907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90611983908590613238565b600061090682612f57565b6000612e2f8383612e6d565b612e6557508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610906565b506000610906565b60009081526001919091016020526040902054151590565b60008183612ec0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d59190613241565b506000838581612ecc57fe5b0495945050505050565b60006116d48373ffffffffffffffffffffffffffffffffffffffff8416612f5b565b81546000908210612f35576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109d5906132b2565b826000018281548110612f4457fe5b9060005260206000200154905092915050565b5490565b600081815260018301602052604081205480156130355783547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8083019190810190600090879083908110612fac57fe5b9060005260206000200154905080876000018481548110612fc957fe5b600091825260208083209091019290925582815260018981019092526040902090840190558654879080612ff957fe5b60019003818190600052602060002001600090559055866001016000878152602001908152602001600020600090556001945050505050610906565b6000915050610906565b803573ffffffffffffffffffffffffffffffffffffffff8116811461090657600080fd5b600060208284031215613074578081fd5b6116d4838361303f565b60008060408385031215613090578081fd5b61309a848461303f565b91506130a9846020850161303f565b90509250929050565b6000806000606084860312156130c6578081fd5b83356130d18161391d565b925060208401356130e18161391d565b929592945050506040919091013590565b60008060408385031215613104578182fd5b61310e848461303f565b946020939093013593505050565b60006020828403121561312d578081fd5b5035919050565b60008060408385031215613146578182fd5b8235915060208301356131588161391d565b809150509250929050565b60008060408385031215613175578182fd5b50508035926020909101359150565b600060208284031215613195578081fd5b5051919050565b6000602082840312156131ad578081fd5b815160ff811681146116d4578182fd5b7f434f4c4c41544552414c5f524154494f5f504155534552000000000000000000815260170190565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b901515815260200190565b90815260200190565b6000602080835283518082850152825b8181101561326d57858101830151858201604001528201613251565b8181111561327e5783604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b60208082526022908201527f456e756d657261626c655365743a20696e646578206f7574206f6620626f756e60408201527f6473000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526023908201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260408201527f6573730000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252602f908201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60408201527f2061646d696e20746f206772616e740000000000000000000000000000000000606082015260800190565b6020808252603c908201527f494e56414c49442050524943452043484f4943452e204e6565647320746f206260408201527f6520656974686572203020284652415829206f72203120284658532900000000606082015260800190565b60208082526022908201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560408201527f7373000000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b60208082526026908201527f4f6e6c79206672617820706f6f6c732063616e2063616c6c207468697320667560408201527f6e6374696f6e0000000000000000000000000000000000000000000000000000606082015260800190565b6020808252601d908201527f6164647265737320646f65736e277420657869737420616c7265616479000000604082015260600190565b60208082526030908201527f416363657373436f6e74726f6c3a2073656e646572206d75737420626520616e60408201527f2061646d696e20746f207265766f6b6500000000000000000000000000000000606082015260800190565b6020808252603d908201527f596f7520617265206e6f7420746865206f776e65722c20636f6e74726f6c6c6560408201527f722c206f722074686520676f7665726e616e63652074696d656c6f636b000000606082015260800190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f60408201527f7700000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526021908201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360408201527f7300000000000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526025908201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460408201527f6472657373000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526024908201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460408201527f7265737300000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526035908201527f4d757374207761697420666f7220746865207265667265736820636f6f6c646f60408201527f776e2073696e6365206c61737420726566726573680000000000000000000000606082015260800190565b6020808252818101527f436f6c6c61746572616c20526174696f20686173206265656e20706175736564604082015260600190565b60208082526016908201527f6164647265737320616c72656164792065786973747300000000000000000000604082015260600190565b6020808252602f908201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560408201527f20726f6c657320666f722073656c660000000000000000000000000000000000606082015260800190565b6020808252601f908201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604082015260600190565b978852602088019690965260408701949094526060860192909252608085015260a084015260c083015260e08201526101000190565b60ff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff8116811461129857600080fdfe45524332303a206275726e20616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a206275726e20616d6f756e74206578636565647320616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220c630a447c03c2d225020ed5ca2de4d23ef8beed5537e9903659785e18d2949ea64736f6c634300060b0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000234d953a9404bf9dbc3b526271d440cd2870bcd20000000000000000000000008412ebf45bac1b340bbe8f318b928c466c4e39ca0000000000000000000000000000000000000000000000000000000000000004467261780000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044652415800000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _name (string): Frax
Arg [1] : _symbol (string): FRAX
Arg [2] : _creator_address (address): 0x234D953a9404Bf9DbC3b526271d440cD2870bCd2
Arg [3] : _timelock_address (address): 0x8412ebf45bAC1B340BbE8F318b928C466c4E39CA
-----Encoded View---------------
8 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000080
Arg [1] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [2] : 000000000000000000000000234d953a9404bf9dbc3b526271d440cd2870bcd2
Arg [3] : 0000000000000000000000008412ebf45bac1b340bbe8f318b928c466c4e39ca
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000004
Arg [5] : 4672617800000000000000000000000000000000000000000000000000000000
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000004
Arg [7] : 4652415800000000000000000000000000000000000000000000000000000000
Deployed Bytecode Sourcemap
368:12997:17:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;759:18;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;2712:166:9;;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;1579:33:17:-;;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;10748:122::-;;;;;;:::i;:::-;;:::i;:::-;;1679:98:9;;;:::i;:::-;;;;;;;:::i;11369:128:17:-;;;;;;:::i;:::-;;:::i;7945:29::-;;;:::i;10997:109::-;;;;;;:::i;:::-;;:::i;3336:317:9:-;;;;;;:::i;:::-;;:::i;1197:27:17:-;;;:::i;4323:112:0:-;;;;;;:::i;:::-;;:::i;2563:25:17:-;;;:::i;2343:27::-;;;:::i;1818:38::-;;;:::i;4685:223:0:-;;;;;;:::i;:::-;;:::i;783:35:17:-;;;:::i;:::-;;;;;;;:::i;6170:184::-;;;:::i;2716:36::-;;;:::i;5859:205:0:-;;;;;;:::i;:::-;;:::i;4048:215:9:-;;;;;;:::i;:::-;;:::i;10145:597:17:-;;;;;;:::i;:::-;;:::i;8040:1197::-;;;:::i;11231:132::-;;;;;;:::i;:::-;;:::i;6769:89:9:-;;;;;;:::i;:::-;;:::i;858:30:17:-;;;:::i;1275:51::-;;;:::i;2758:86::-;;;:::i;1671:42::-;;;;;;:::i;:::-;;:::i;12217:117::-;;;;;;:::i;:::-;;:::i;962:33::-;;;:::i;1835:117:9:-;;;;;;:::i;:::-;;:::i;1110:38:17:-;;;:::i;11628:305::-;;;;;;:::i;:::-;;:::i;7162:290:9:-;;;;;;:::i;:::-;;:::i;2120:24:17:-;;;:::i;10876:115::-;;;;;;:::i;:::-;;:::i;824:28::-;;;:::i;2850:43::-;;;:::i;4006:136:0:-;;;;;;:::i;:::-;;:::i;2991:137::-;;;;;;:::i;:::-;;:::i;12069:142:17:-;;;;;;:::i;:::-;;:::i;733:20::-;;;:::i;1698:49:0:-;;;:::i;4750:266:9:-;;;;;;:::i;:::-;;:::i;9336:189:17:-;;;;;;:::i;:::-;;:::i;2155:172:9:-;;;;;;:::i;:::-;;:::i;11114:109:17:-;;;;;;:::i;:::-;;:::i;12711:261::-;;;;;;:::i;:::-;;:::i;1230:39::-;;;:::i;5918:106::-;;;:::i;9605:180::-;;;;;;:::i;:::-;;:::i;11939:124::-;;;;;;:::i;:::-;;:::i;12978:133::-;;;:::i;2231:31::-;;;:::i;2018:26::-;;;:::i;11503:119::-;;;;;;:::i;:::-;;:::i;1078:26::-;;;:::i;3296:125:0:-;;;;;;:::i;:::-;;:::i;1154:37:17:-;;;:::i;1913:29::-;;;:::i;7293:469::-;;;:::i;5142:226:0:-;;;;;;:::i;:::-;;:::i;9875:242:17:-;;;;;;:::i;:::-;;:::i;894:31::-;;;:::i;2385:149:9:-;;;;;;:::i;:::-;;:::i;6525:663:17:-;;;:::i;:::-;;;;;;;;;;;;;;:::i;12389:268::-;;;;;;:::i;:::-;;:::i;6059:105::-;;;:::i;759:18::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;2712:166:9:-;2795:4;2811:39;2820:12;:10;:12::i;:::-;2834:7;2843:6;2811:8;:39::i;:::-;-1:-1:-1;2867:4:9;2712:166;;;;;:::o;1579:33:17:-;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1579:33:17;:::o;10748:122::-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;;;;;;;;;10833:13:::1;:30:::0;;;::::1;;::::0;;;::::1;::::0;;;::::1;::::0;;10748:122::o;1679:98:9:-;1758:12;;1679:98;:::o;11369:128:17:-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;11458:16:::1;:32:::0;11369:128::o;7945:29::-;;;;:::o;10997:109::-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;11078:11:::1;:21:::0;10997:109::o;3336:317:9:-;3442:4;3458:36;3468:6;3476:9;3487:6;3458:9;:36::i;:::-;3504:121;3513:6;3521:12;:10;:12::i;:::-;3535:89;3573:6;3535:89;;;;;;;;;;;;;;;;;:19;;;;;;;:11;:19;;;;;;3555:12;:10;:12::i;:::-;3535:33;;;;;;;;;;;;;-1:-1:-1;3535:33:9;;;:89;;:37;:89;:::i;:::-;3504:8;:121::i;:::-;-1:-1:-1;3642:4:9;3336:317;;;;;:::o;1197:27:17:-;;;;;;:::o;4323:112:0:-;4380:7;4406:12;;;:6;:12;;;;;:22;;;;4323:112::o;2563:25:17:-;;;;:::o;2343:27::-;;;;:::o;1818:38::-;;;;:::o;4685:223:0:-;4776:12;;;;:6;:12;;;;;:22;;;4768:45;;4800:12;:10;:12::i;4768:45::-;4760:105;;;;;;;;;;;;:::i;:::-;4876:25;4887:4;4893:7;4876:10;:25::i;:::-;4685:223;;:::o;783:35:17:-;816:2;783:35;:::o;6170:184::-;6323:23;;;6250:31;;;;;;;;6216:7;;6242:105;;6323:23;;;;;6316:2;6308:38;;6242:61;;1804:3;;6250:14;;;;;:29;;:31;;;;;;;;;;;;;:14;:31;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;6242:44;:61;:44;:61;:::i;:::-;:65;:105;:65;:105;:::i;:::-;6235:112;;6170:184;:::o;2716:36::-;;;;;;:::o;5859:205:0:-;5956:12;:10;:12::i;:::-;5945:23;;:7;:23;;;5937:83;;;;;;;;;;;;:::i;:::-;6031:26;6043:4;6049:7;6031:11;:26::i;4048:215:9:-;4136:4;4152:83;4161:12;:10;:12::i;:::-;4175:7;4184:50;4223:10;4184:11;:25;4196:12;:10;:12::i;:::-;4184:25;;;;;;;;;;;;;;;;;;-1:-1:-1;4184:25:9;;;:34;;;;;;;;;;;:50;:38;:50;:::i;10145:597:17:-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;10236:24:::1;::::0;::::1;;::::0;;;:10:::1;:24;::::0;;;;;::::1;;:32;;:24:::0;:32:::1;10228:74;;;;;;;;;;;;:::i;:::-;10363:24;::::0;::::1;;::::0;;;:10:::1;:24;::::0;;;;10356:31;;;::::1;::::0;;10463:273:::1;10484:16;:23:::0;10480:27;::::1;10463:273;;;10555:12;10532:35;;:16;10549:1;10532:19;;;;;;;;;::::0;;;::::1;::::0;;;::::1;::::0;::::1;;:35;10528:198;;;10617:1;10587:16;10604:1;10587:19;;;;;;;;;;;;;;;;:32;;;;;;;;;;;;;;;;;;10706:5;;10528:198;10509:3;;10463:273;;8040:1197:::0;8099:23;;;;;;;:32;8091:77;;;;;;;;;;;;:::i;:::-;8178:22;8203:12;:10;:12::i;:::-;8178:37;;8269:16;;8251:14;;8233:15;:32;:52;;8225:118;;;;;;;;;;;;:::i;:::-;8482:10;;8465:12;;:28;;;:16;:28;:::i;:::-;8448:14;:45;8444:706;;;8567:9;;8540:23;;:36;8537:236;;8654:1;8628:23;:27;8537:236;;;8748:9;;8720:23;;:38;;;:27;:38;:::i;:::-;8694:23;:64;8537:236;8444:706;;;8827:10;;8810:12;;:28;;;:16;:28;:::i;:::-;8793:14;:45;8789:361;;;8927:7;8885:38;8913:9;;8885:23;;:27;;:38;;;;:::i;:::-;:49;8882:258;;8979:7;8953:23;:33;8882:258;;;9115:9;;9087:23;;:38;;;:27;:38;:::i;:::-;9061:23;:64;8882:258;-1:-1:-1;9177:15:17;9160:14;:32;8040:1197::o;11231:132::-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;11324:12:::1;:32:::0;11231:132::o;6769:89:9:-;6824:27;6830:12;:10;:12::i;:::-;6844:6;6824:5;:27::i;:::-;6769:89;:::o;858:30:17:-;;;;;;:::o;1275:51::-;1316:10;1275:51;:::o;2758:86::-;2808:36;;;;;:::i;:::-;;;;;;;;2758:86;:::o;1671:42::-;;;;;;;;;;;;;;;:::o;12217:117::-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;12303:10:::1;:24:::0;12217:117::o;962:33::-;;;;;;:::o;1835:117:9:-;1927:18;;1901:7;1927:18;;;;;;;;;;;;1835:117::o;1110:38:17:-;;;;;;:::o;11628:305::-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;11729:24:::1;:52:::0;;::::1;::::0;;::::1;::::0;;;::::1;;::::0;;;;11791:14:::1;:71:::0;;;;::::1;11837:24:::0;;::::1;11791:71:::0;;;::::1;::::0;;;11898:28:::1;::::0;;;;;;;:14;;;::::1;::::0;:26:::1;::::0;:28;;::::1;::::0;::::1;::::0;;;;;;;;;:14;:28;::::1;;::::0;::::1;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;11872:23;;:54;;;;;;;;;;;;;;;;;;11628:305:::0;:::o;7162:290:9:-;7238:26;7267:84;7304:6;7267:84;;;;;;;;;;;;;;;;;:32;7277:7;7286:12;:10;:12::i;7267:32::-;:36;:84;;:36;:84;:::i;:::-;7238:113;;7362:51;7371:7;7380:12;:10;:12::i;:::-;7394:18;7362:8;:51::i;:::-;7423:22;7429:7;7438:6;7423:5;:22::i;:::-;7162:290;;;:::o;2120:24:17:-;;;;:::o;10876:115::-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;10960:14:::1;:24:::0;10876:115::o;824:28::-;;;;;;:::o;2850:43::-;;;;;;;;;:::o;4006:136:0:-;4079:7;4105:12;;;:6;:12;;;;;:30;;4129:5;4105:30;:23;:30;:::i;:::-;4098:37;4006:136;-1:-1:-1;;;4006:136:0:o;2991:137::-;3060:4;3083:12;;;:6;:12;;;;;:38;;3113:7;3083:38;:29;:38;:::i;12069:142:17:-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;12164:18:::1;:40:::0;;;::::1;;::::0;;;::::1;::::0;;;::::1;::::0;;12069:142::o;733:20::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1698:49:0;1743:4;1698:49;:::o;4750:266:9:-;4843:4;4859:129;4868:12;:10;:12::i;:::-;4882:7;4891:96;4930:15;4891:96;;;;;;;;;;;;;;;;;:11;:25;4903:12;:10;:12::i;:::-;4891:25;;;;;;;;;;;;;;;;;;-1:-1:-1;4891:25:9;;;:34;;;;;;;;;;;:96;;:38;:96;:::i;9336:189:17:-;3116:10;3105:22;;;;:10;:22;;;;;;;;:30;;:22;:30;3097:81;;;;;;;;;;;;:::i;:::-;9424:36:::1;9440:9;9451:8;9424:15;:36::i;:::-;9497:10;9475:43;;9486:9;9475:43;;;9509:8;9475:43;;;;;;:::i;:::-;;;;;;;;9336:189:::0;;:::o;2155:172:9:-;2241:4;2257:42;2267:12;:10;:12::i;:::-;2281:9;2292:6;2257:9;:42::i;11114:109:17:-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;11195:9:::1;:21:::0;11114:109::o;12711:261::-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;12826:22:::1;:41:::0;;::::1;::::0;;::::1;::::0;;;::::1;::::0;::::1;::::0;;;12877:12:::1;:50:::0;;;::::1;::::0;;::::1;::::0;;;12937:12:::1;:28:::0;;;;;::::1;::::0;::::1;;::::0;;12711:261::o;1230:39::-;;;;;;:::o;5918:106::-;5961:7;5987:30;6000:16;5987:12;:30::i;9605:180::-;3116:10;3105:22;;;;:10;:22;;;;;;;;:30;;:22;:30;3097:81;;;;;;;;;;;;:::i;:::-;9688:32:::1;9700:9;9711:8;9688:11;:32::i;:::-;9758:9;9735:43;;9746:10;9735:43;;;9769:8;9735:43;;;;;;:::i;11939:124::-:0;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;12025:16:::1;:31:::0;;;::::1;;::::0;;;::::1;::::0;;;::::1;::::0;;11939:124::o;12978:133::-;2998:44;2808:36;;;;;:::i;:::-;;;;;;;;3031:10;2998:7;:44::i;:::-;2990:53;;;;;;13081:23:::1;::::0;;13054:50;;::::1;13081:23:::0;;;;::::1;;;13080:24;13054:50:::0;;::::1;;::::0;;12978:133::o;2231:31::-;;;;:::o;2018:26::-;;;;:::o;11503:119::-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;11589:11:::1;:26:::0;;;::::1;;::::0;;;::::1;::::0;;;::::1;::::0;;11503:119::o;1078:26::-;;;;;;:::o;3296:125:0:-;3359:7;3385:12;;;:6;:12;;;;;:29;;:27;:29::i;1154:37:17:-;;;;;;:::o;1913:29::-;;;;:::o;7293:469::-;7347:7;;;7416:297;7437:16;:23;7433:27;;7416:297;;;7554:1;7523:33;;:16;7540:1;7523:19;;;;;;;;;;;;;;;;;;;;:33;7519:183;;7604:83;7644:16;7661:1;7644:19;;;;;;;;;;;;;;;;;;;7635:51;;;;;;;;7644:19;;;;;7635:49;;:51;;;;;;;;;;7644:19;7635:51;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;7604:26;;:83;:30;:83;:::i;:::-;7575:112;;7519:183;7462:3;;7416:297;;;-1:-1:-1;7729:26:17;-1:-1:-1;7293:469:17;:::o;5142:226:0:-;5234:12;;;;:6;:12;;;;;:22;;;5226:45;;5258:12;:10;:12::i;5226:45::-;5218:106;;;;;;;;;;;;:::i;9875:242:17:-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;9963:24:::1;::::0;::::1;;::::0;;;:10:::1;:24;::::0;;;;;::::1;;:33;9955:68;;;;;;;;;;;;:::i;:::-;10033:24;;;::::0;;;:10:::1;:24;::::0;;;;:31;;;::::1;10060:4;10033:31:::0;;::::1;::::0;;;10075:16:::1;:35:::0;;;;::::1;::::0;;;;;;::::1;::::0;;;::::1;::::0;;::::1;::::0;;9875:242::o;894:31::-;;;;;;:::o;2385:149:9:-;2500:18;;;;2474:7;2500:18;;;:11;:18;;;;;;;;:27;;;;;;;;;;;;;2385:149::o;6525:663:17:-;6567:7;6576;6585;6594;6603;6612;6621;6630;6670:30;6683:16;6670:12;:30::i;:::-;6730:29;6743:15;6730:12;:29::i;:::-;6788:13;:11;:13::i;:::-;6832:23;;6898;:21;:23::i;:::-;6960:11;;7002:14;;7131:23;;;7058:31;;;;;;;;7050:105;;7131:23;;;;;7124:2;7116:38;;7050:61;;1804:3;;7058:14;;;;;:29;;:31;;;;;;;;;;;;:14;:31;;;;;;;;;;7050:105;6649:532;;;;-1:-1:-1;6649:532:17;;-1:-1:-1;6649:532:17;;-1:-1:-1;6649:532:17;-1:-1:-1;6649:532:17;-1:-1:-1;6649:532:17;-1:-1:-1;6649:532:17;;-1:-1:-1;6525:663:17;-1:-1:-1;6525:663:17:o;12389:268::-;3274:13;;;;3260:10;:27;;:61;;-1:-1:-1;3305:16:17;;;;3291:10;:30;3260:61;:97;;;-1:-1:-1;3339:18:17;;;;3325:10;:32;3260:97;3252:171;;;;;;;;;;;;:::i;:::-;12506:23:::1;:43:::0;;::::1;::::0;;::::1;::::0;;;::::1;::::0;::::1;::::0;;;12559:13:::1;:52:::0;;;::::1;::::0;;::::1;::::0;;;12622:12:::1;:28:::0;;;;;::::1;::::0;::::1;;::::0;;12389:268::o;6059:105::-;6102:7;6128:29;6141:15;6128:12;:29::i;866:176:40:-;924:7;955:5;;;978:6;;;;970:46;;;;;;;;;;;;:::i;4864:141:10:-;4934:4;4957:41;4962:3;4982:14;;;4957:4;:41::i;5401:156::-;5481:4;5504:46;5514:3;5534:14;;;5504:9;:46::i;767:104:7:-;854:10;767:104;:::o;8607:340:9:-;8708:19;;;8700:68;;;;;;;;;;;;:::i;:::-;8786:21;;;8778:68;;;;;;;;;;;;:::i;:::-;8857:18;;;;;;;;:11;:18;;;;;;;;:27;;;;;;;;;;;;;;:36;;;8908:32;;;;;8887:6;;8908:32;:::i;:::-;;;;;;;;8607:340;;;:::o;5490:530::-;5595:20;;;5587:70;;;;;;;;;;;;:::i;:::-;5675:23;;;5667:71;;;;;;;;;;;;:::i;:::-;5749:47;5770:6;5778:9;5789:6;5749:20;:47::i;:::-;5827:71;5849:6;5827:71;;;;;;;;;;;;;;;;;:17;;;:9;:17;;;;;;;;;;;;:71;;:21;:71;:::i;:::-;5807:17;;;;:9;:17;;;;;;;;;;;:91;;;;5931:20;;;;;;;:32;;5956:6;5931:32;:24;:32;:::i;:::-;5908:20;;;;:9;:20;;;;;;;;;;;;:55;;;;5978:35;;;;;;;;;;6006:6;;5978:35;:::i;1764:187:40:-;1850:7;1885:12;1877:6;;;;1869:29;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;;1920:5:40;;;1764:187::o;7066:184:0:-;7139:12;;;;:6;:12;;;;;:33;;7164:7;7139:33;:24;:33;:::i;:::-;7135:109;;;7220:12;:10;:12::i;:::-;7193:40;;7211:7;7193:40;;7205:4;7193:40;;;;;;;;;;7066:184;;:::o;2191:459:40:-;2249:7;2490:6;2486:45;;-1:-1:-1;2519:1:40;2512:8;;2486:45;2553:5;;;2557:1;2553;:5;:1;2576:5;;;;;:10;2568:56;;;;;;;;;;;;:::i;3105:130::-;3163:7;3189:39;3193:1;3196;3189:39;;;;;;;;;;;;;;;;;:3;:39::i;7256:188:0:-;7330:12;;;;:6;:12;;;;;:36;;7358:7;7330:36;:27;:36;:::i;:::-;7326:112;;;7414:12;:10;:12::i;:::-;7387:40;;7405:7;7387:40;;7399:4;7387:40;;;;;;;;;;7256:188;;:::o;1306:134:40:-;1364:7;1390:43;1394:1;1397;1390:43;;;;;;;;;;;;;;;;;:3;:43::i;7772:410:9:-;7855:21;;;7847:67;;;;;;;;;;;;:::i;:::-;7925:49;7946:7;7963:1;7967:6;7925:20;:49::i;:::-;8006:68;8029:6;8006:68;;;;;;;;;;;;;;;;;:18;;;:9;:18;;;;;;;;;;;;:68;;:22;:68;:::i;:::-;7985:18;;;:9;:18;;;;;;;;;;:89;8099:12;;:24;;8116:6;8099:24;:16;:24;:::i;:::-;8084:12;:39;8138:37;;8164:1;;8138:37;;;;;;;;8168:6;;8138:37;:::i;6085:147:10:-;6159:7;6201:22;6205:3;6217:5;6201:3;:22::i;9125:237:9:-;9204:22;9210:7;9219:6;9204:5;:22::i;:::-;9236:119;9245:7;9254:12;:10;:12::i;:::-;9268:86;9307:6;9268:86;;;;;;;;;;;;;;;;;:20;;;;;;;:11;:20;;;;;;9289:12;:10;:12::i;4978:904:17:-;5242:23;;;5169:31;;;;;;;;5043:7;;;;5161:105;;5242:23;;;;;5235:2;5227:38;;5161:61;;1804:3;;5169:14;;;:29;;:31;;;;;;;;;;;:14;:31;;;;;;;;;;5161:105;5137:129;-1:-1:-1;5276:20:17;;5311:6;:26;;;;;;;;;5307:465;;;5376:13;;5398:12;;5376:52;;;;;:13;;;;;:21;;:52;;5398:12;;;1804:3;;5376:52;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;5353:76;;5307:465;;;5520:15;5510:6;:25;;;;;;;;;5506:266;;;5574:12;;5595;;5574:51;;;;;:12;;;;;:20;;:51;;5595:12;;;1804:3;;5574:51;;;:::i;5506:266::-;5702:70;;;;;;;;;;:::i;5506:266::-;5823:52;5862:12;5823:34;:13;1804:3;5823:34;:17;:34;:::i;:52::-;5816:59;4978:904;-1:-1:-1;;;;4978:904:17:o;6290:370:9:-;6373:21;;;6365:65;;;;;;;;;;;;:::i;:::-;6441:49;6470:1;6474:7;6483:6;6441:20;:49::i;:::-;6516:12;;:24;;6533:6;6516:24;:16;:24;:::i;:::-;6501:12;:39;6571:18;;;:9;:18;;;;;;;;;;;:30;;6594:6;6571:30;:22;:30;:::i;:::-;6550:18;;;:9;:18;;;;;;;;;;;:51;;;;6616:37;;6550:18;;:9;6616:37;;;;6646:6;;6616:37;:::i;5638:115:10:-;5701:7;5727:19;5735:3;5727:7;:19::i;1611:404::-;1674:4;1695:21;1705:3;1710:5;1695:9;:21::i;:::-;1690:319;;-1:-1:-1;1732:23:10;;;;;;;;:11;:23;;;;;;;;;;;;;1912:18;;1890:19;;;:12;;;:19;;;;;;:40;;;;1944:11;;1690:319;-1:-1:-1;1993:5:10;1986:12;;3776:127;3849:4;3872:19;;;:12;;;;;:19;;;;;;:24;;;3776:127::o;3750:338:40:-;3836:7;3936:12;3929:5;3921:28;;;;;;;;;;;;;:::i;:::-;;3959:9;3975:1;3971;:5;;;;;;;3750:338;-1:-1:-1;;;;;3750:338:40:o;5173:147:10:-;5246:4;5269:44;5277:3;5297:14;;;5269:7;:44::i;4423:201::-;4517:18;;4490:7;;4517:26;-1:-1:-1;4509:73:10;;;;;;;;;;;;:::i;:::-;4599:3;:11;;4611:5;4599:18;;;;;;;;;;;;;;;;4592:25;;4423:201;;;;:::o;3984:107::-;4066:18;;3984:107::o;2183:1512::-;2249:4;2386:19;;;:12;;;:19;;;;;;2420:15;;2416:1273;;2849:18;;2801:14;;;;;2849:22;;;;2777:21;;2849:3;;:22;;3131;;;;;;;;;;;;;;3111:42;;3274:9;3245:3;:11;;3257:13;3245:26;;;;;;;;;;;;;;;;;;;:38;;;;3349:23;;;3391:1;3349:12;;;:23;;;;;;3375:17;;;3349:43;;3498:17;;3349:3;;3498:17;;;;;;;;;;;;;;;;;;;;;;3590:3;:12;;:19;3603:5;3590:19;;;;;;;;;;;3583:26;;;3631:4;3624:11;;;;;;;;2416:1273;3673:5;3666:12;;;;;5:130:-1;72:20;;24897:42;24886:54;;25560:35;;25550:2;;25609:1;;25599:12;833:241;;937:2;925:9;916:7;912:23;908:32;905:2;;;-1:-1;;943:12;905:2;1005:53;1050:7;1026:22;1005:53;:::i;1081:366::-;;;1202:2;1190:9;1181:7;1177:23;1173:32;1170:2;;;-1:-1;;1208:12;1170:2;1270:53;1315:7;1291:22;1270:53;:::i;:::-;1260:63;;1378:53;1423:7;1360:2;1403:9;1399:22;1378:53;:::i;:::-;1368:63;;1164:283;;;;;:::o;1454:491::-;;;;1592:2;1580:9;1571:7;1567:23;1563:32;1560:2;;;-1:-1;;1598:12;1560:2;85:6;72:20;97:33;124:5;97:33;:::i;:::-;1650:63;-1:-1;1750:2;1789:22;;72:20;97:33;72:20;97:33;:::i;:::-;1554:391;;1758:63;;-1:-1;;;1858:2;1897:22;;;;485:20;;1554:391::o;1952:366::-;;;2073:2;2061:9;2052:7;2048:23;2044:32;2041:2;;;-1:-1;;2079:12;2041:2;2141:53;2186:7;2162:22;2141:53;:::i;:::-;2131:63;2231:2;2270:22;;;;485:20;;-1:-1;;;2035:283::o;2325:241::-;;2429:2;2417:9;2408:7;2404:23;2400:32;2397:2;;;-1:-1;;2435:12;2397:2;-1:-1;209:20;;2391:175;-1:-1;2391:175::o;2573:366::-;;;2694:2;2682:9;2673:7;2669:23;2665:32;2662:2;;;-1:-1;;2700:12;2662:2;222:6;209:20;2752:63;;2852:2;2895:9;2891:22;72:20;97:33;124:5;97:33;:::i;:::-;2860:63;;;;2656:283;;;;;:::o;2946:366::-;;;3067:2;3055:9;3046:7;3042:23;3038:32;3035:2;;;-1:-1;;3073:12;3035:2;-1:-1;;209:20;;;3225:2;3264:22;;;485:20;;-1:-1;3029:283::o;3319:261::-;;3433:2;3421:9;3412:7;3408:23;3404:32;3401:2;;;-1:-1;;3439:12;3401:2;-1:-1;356:13;;3395:185;-1:-1;3395:185::o;4105:259::-;;4218:2;4206:9;4197:7;4193:23;4189:32;4186:2;;;-1:-1;;4224:12;4186:2;778:6;772:13;25102:4;26078:5;25091:16;26055:5;26052:33;26042:2;;-1:-1;;26089:12;12804:381;9930:25;9910:46;;9894:2;9975:12;;12993:192::o;13192:222::-;24897:42;24886:54;;;;4442:37;;13319:2;13304:18;;13290:124::o;13421:333::-;24897:42;24886:54;;;;4442:37;;13740:2;13725:18;;4673:37;13576:2;13561:18;;13547:207::o;13761:210::-;24641:13;;24634:21;4556:34;;13882:2;13867:18;;13853:118::o;13978:222::-;4673:37;;;14105:2;14090:18;;14076:124::o;14207:310::-;;14354:2;;14375:17;14368:47;4867:5;24110:12;24267:6;14354:2;14343:9;14339:18;24255:19;-1:-1;25192:101;25206:6;25203:1;25200:13;25192:101;;;25273:11;;;;;25267:18;25254:11;;;24295:14;25254:11;25247:39;25221:10;;25192:101;;;25308:6;25305:1;25302:13;25299:2;;;-1:-1;24295:14;25364:6;14343:9;25355:16;;25348:27;25299:2;-1:-1;25484:2;25464:14;25480:7;25460:28;5025:39;;;;24295:14;5025:39;;14325:192;-1:-1;;;14325:192::o;14524:416::-;14724:2;14738:47;;;5301:2;14709:18;;;24255:19;5337:34;24295:14;;;5317:55;5406:4;5392:12;;;5385:26;5430:12;;;14695:245::o;14947:416::-;15147:2;15161:47;;;5681:2;15132:18;;;24255:19;5717:34;24295:14;;;5697:55;5786:5;5772:12;;;5765:27;5811:12;;;15118:245::o;15370:416::-;15570:2;15584:47;;;6062:2;15555:18;;;24255:19;6098:34;24295:14;;;6078:55;6167:17;6153:12;;;6146:39;6204:12;;;15541:245::o;15793:416::-;15993:2;16007:47;;;6455:2;15978:18;;;24255:19;6491:34;24295:14;;;6471:55;6560:30;6546:12;;;6539:52;6610:12;;;15964:245::o;16216:416::-;16416:2;16430:47;;;6861:2;16401:18;;;24255:19;6897:34;24295:14;;;6877:55;6966:4;6952:12;;;6945:26;6990:12;;;16387:245::o;16639:416::-;16839:2;16853:47;;;7241:2;16824:18;;;24255:19;7277:29;24295:14;;;7257:50;7326:12;;;16810:245::o;17062:416::-;17262:2;17276:47;;;7577:2;17247:18;;;24255:19;7613:34;24295:14;;;7593:55;7682:8;7668:12;;;7661:30;7710:12;;;17233:245::o;17485:416::-;17685:2;17699:47;;;7961:2;17670:18;;;24255:19;7997:31;24295:14;;;7977:52;8048:12;;;17656:245::o;17908:416::-;18108:2;18122:47;;;8299:2;18093:18;;;24255:19;8335:34;24295:14;;;8315:55;8404:18;8390:12;;;8383:40;8442:12;;;18079:245::o;18331:416::-;18531:2;18545:47;;;8693:2;18516:18;;;24255:19;8729:34;24295:14;;;8709:55;8798:31;8784:12;;;8777:53;8849:12;;;18502:245::o;18754:416::-;18954:2;18968:47;;;9100:2;18939:18;;;24255:19;9136:34;24295:14;;;9116:55;9205:3;9191:12;;;9184:25;9228:12;;;18925:245::o;19177:416::-;19377:2;19391:47;;;9479:2;19362:18;;;24255:19;9515:34;24295:14;;;9495:55;9584:3;9570:12;;;9563:25;9607:12;;;19348:245::o;19600:416::-;19800:2;19814:47;;;10226:2;19785:18;;;24255:19;10262:34;24295:14;;;10242:55;10331:7;10317:12;;;10310:29;10358:12;;;19771:245::o;20023:416::-;20223:2;20237:47;;;10609:2;20208:18;;;24255:19;10645:34;24295:14;;;10625:55;10714:6;10700:12;;;10693:28;10740:12;;;20194:245::o;20446:416::-;20646:2;20660:47;;;10991:2;20631:18;;;24255:19;11027:34;24295:14;;;11007:55;11096:23;11082:12;;;11075:45;11139:12;;;20617:245::o;20869:416::-;21069:2;21083:47;;;21054:18;;;24255:19;11426:34;24295:14;;;11406:55;11480:12;;;21040:245::o;21292:416::-;21492:2;21506:47;;;11731:2;21477:18;;;24255:19;11767:24;24295:14;;;11747:45;11811:12;;;21463:245::o;21715:416::-;21915:2;21929:47;;;12062:2;21900:18;;;24255:19;12098:34;24295:14;;;12078:55;12167:17;12153:12;;;12146:39;12204:12;;;21886:245::o;22138:416::-;22338:2;22352:47;;;12455:2;22323:18;;;24255:19;12491:33;24295:14;;;12471:54;12544:12;;;22309:245::o;22790:1004::-;4673:37;;;23278:2;23263:18;;4673:37;;;;23361:2;23346:18;;4673:37;;;;23444:2;23429:18;;4673:37;;;;23527:3;23512:19;;4673:37;23611:3;23596:19;;4673:37;23695:3;23680:19;;4673:37;23779:3;23764:19;;4673:37;23113:3;23098:19;;23084:710::o;23801:214::-;25102:4;25091:16;;;;12757:35;;23924:2;23909:18;;23895:120::o;25501:117::-;24897:42;25588:5;24886:54;25563:5;25560:35;25550:2;;25609:1;;25599:12
Swarm Source
ipfs://c630a447c03c2d225020ed5ca2de4d23ef8beed5537e9903659785e18d2949ea
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.