ETH Price: $2,001.18 (-1.09%)

Transaction Decoder

Block:
10804230 at Sep-05-2020 10:48:17 PM +UTC
Transaction Fee:
0.0219142 ETH $43.85
Gas Used:
199,220 Gas / 110 Gwei

Account State Difference:

  Address   Before After State Difference Code
823.963436179894590834 Eth823.985350379894590834 Eth0.0219142
0x9F72a8Aa...7350D9b51
1.488646459828001994 Eth
Nonce: 334
1.466732259828001994 Eth
Nonce: 335
0.0219142

Execution Trace

PYLONCOMPPool.CALL( )
  • Comp.transfer( dst=0x9F72a8AaCc2a38fd26B98E43Ab213647350D9b51, rawAmount=30828204562941418127 ) => ( True )
  • PYLONDelegator.CALL( )
  • PYLONDelegator.transfer( dst=0x9F72a8AaCc2a38fd26B98E43Ab213647350D9b51, amount=1650992134321877408 )
    • PYLONDelegate.transfer( to=0x9F72a8AaCc2a38fd26B98E43Ab213647350D9b51, value=1650992134321877408 )
      File 1 of 4: PYLONCOMPPool
      /*
         ____            __   __        __   _
        / __/__ __ ___  / /_ / /  ___  / /_ (_)__ __
       _\ \ / // // _ \/ __// _ \/ -_)/ __// / \ \ /
      /___/ \_, //_//_/\__//_//_/\__/ \__//_/ /_\_\
           /___/
      
      * Synthetix: PYLONRewards.sol
      *
      * Docs: https://docs.synthetix.io/
      *
      *
      * MIT License
      * ===========
      *
      * Copyright (c) 2020 Synthetix
      *
      * Permission is hereby granted, free of charge, to any person obtaining a copy
      * of this software and associated documentation files (the "Software"), to deal
      * in the Software without restriction, including without limitation the rights
      * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      * copies of the Software, and to permit persons to whom the Software is
      * furnished to do so, subject to the following conditions:
      *
      * The above copyright notice and this permission notice shall be included in all
      * copies or substantial portions of the Software.
      *
      * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      */
      
      // File: @openzeppelin/contracts/math/Math.sol
      
      pragma solidity ^0.5.0;
      
      /**
       * @dev Standard math utilities missing in the Solidity language.
       */
      library Math {
          /**
           * @dev Returns the largest of two numbers.
           */
          function max(uint256 a, uint256 b) internal pure returns (uint256) {
              return a >= b ? a : b;
          }
      
          /**
           * @dev Returns the smallest of two numbers.
           */
          function min(uint256 a, uint256 b) internal pure returns (uint256) {
              return a < b ? a : b;
          }
      
          /**
           * @dev Returns the average of two numbers. The result is rounded towards
           * zero.
           */
          function average(uint256 a, uint256 b) internal pure returns (uint256) {
              // (a + b) / 2 can overflow, so we distribute
              return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
          }
      }
      
      // File: @openzeppelin/contracts/math/SafeMath.sol
      
      pragma solidity ^0.5.0;
      
      /**
       * @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;
          }
      }
      
      // File: @openzeppelin/contracts/GSN/Context.sol
      
      pragma solidity ^0.5.0;
      
      /*
       * @dev Provides information about the current execution context, including the
       * sender of the transaction and its data. While these are generally available
       * via msg.sender and msg.data, they should not be accessed in such a direct
       * manner, since when dealing with 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 { }
          // solhint-disable-previous-line no-empty-blocks
      
          function _msgSender() internal view returns (address payable) {
              return msg.sender;
          }
      
          function _msgData() internal view returns (bytes memory) {
              this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
              return msg.data;
          }
      }
      
      // File: @openzeppelin/contracts/ownership/Ownable.sol
      
      pragma solidity ^0.5.0;
      
      /**
       * @dev Contract module which provides a basic access control mechanism, where
       * there is an account (an owner) that can be granted exclusive access to
       * specific functions.
       *
       * This module is used through inheritance. It will make available the modifier
       * `onlyOwner`, which can be applied to your functions to restrict their use to
       * the owner.
       */
      contract Ownable is Context {
          address private _owner;
      
          event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
      
          /**
           * @dev Initializes the contract setting the deployer as the initial owner.
           */
          constructor () internal {
              _owner = _msgSender();
              emit OwnershipTransferred(address(0), _owner);
          }
      
          /**
           * @dev Returns the address of the current owner.
           */
          function owner() public view returns (address) {
              return _owner;
          }
      
          /**
           * @dev Throws if called by any account other than the owner.
           */
          modifier onlyOwner() {
              require(isOwner(), "Ownable: caller is not the owner");
              _;
          }
      
          /**
           * @dev Returns true if the caller is the current owner.
           */
          function isOwner() public view returns (bool) {
              return _msgSender() == _owner;
          }
      
          /**
           * @dev Leaves the contract without owner. It will not be possible to call
           * `onlyOwner` functions anymore. Can only be called by the current owner.
           *
           * NOTE: Renouncing ownership will leave the contract without an owner,
           * thereby removing any functionality that is only available to the owner.
           */
          function renounceOwnership() public onlyOwner {
              emit OwnershipTransferred(_owner, address(0));
              _owner = address(0);
          }
      
          /**
           * @dev Transfers ownership of the contract to a new account (`newOwner`).
           * Can only be called by the current owner.
           */
          function transferOwnership(address newOwner) public onlyOwner {
              _transferOwnership(newOwner);
          }
      
          /**
           * @dev Transfers ownership of the contract to a new account (`newOwner`).
           */
          function _transferOwnership(address newOwner) internal {
              require(newOwner != address(0), "Ownable: new owner is the zero address");
              emit OwnershipTransferred(_owner, newOwner);
              _owner = newOwner;
          }
      }
      
      // File: @openzeppelin/contracts/token/ERC20/IERC20.sol
      
      pragma solidity ^0.5.0;
      
      /**
       * @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);
      }
      
      // File: @openzeppelin/contracts/utils/Address.sol
      
      pragma solidity ^0.5.5;
      
      /**
       * @dev Collection of functions related to the address type
       */
      library Address {
          /**
           * @dev Returns true if `account` is a contract.
           *
           * This test is non-exhaustive, and there may be false-negatives: during the
           * execution of a contract's constructor, its address will be reported as
           * not containing 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.
           */
          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.
      
              // According to EIP-1052, 0x0 is the value returned for not-yet created accounts
              // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
              // for accounts without code, i.e. `keccak256('')`
              bytes32 codehash;
              bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
              // solhint-disable-next-line no-inline-assembly
              assembly { codehash := extcodehash(account) }
              return (codehash != 0x0 && codehash != accountHash);
          }
      
          /**
           * @dev Converts an `address` into `address payable`. Note that this is
           * simply a type cast: the actual underlying value is not changed.
           *
           * _Available since v2.4.0._
           */
          function toPayable(address account) internal pure returns (address payable) {
              return address(uint160(account));
          }
      
          /**
           * @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].
           *
           * _Available since v2.4.0._
           */
          function sendValue(address payable recipient, uint256 amount) internal {
              require(address(this).balance >= amount, "Address: insufficient balance");
      
              // solhint-disable-next-line avoid-call-value
              (bool success, ) = recipient.call.value(amount)("");
              require(success, "Address: unable to send value, recipient may have reverted");
          }
      }
      
      // File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol
      
      pragma solidity ^0.5.0;
      
      
      
      
      /**
       * @title SafeERC20
       * @dev Wrappers around ERC20 operations that throw on failure (when the token
       * contract returns false). Tokens that return no value (and instead revert or
       * throw on failure) are also supported, non-reverting calls are assumed to be
       * successful.
       * To use this library you can add a `using SafeERC20 for ERC20;` 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));
          }
      
          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.
      
              // A Solidity high level call has three parts:
              //  1. The target address is checked to verify it contains contract code
              //  2. The call itself is made, and success asserted
              //  3. The return value is decoded, which in turn checks the size of the returned data.
              // solhint-disable-next-line max-line-length
              require(address(token).isContract(), "SafeERC20: call to non-contract");
      
              // solhint-disable-next-line avoid-low-level-calls
              (bool success, bytes memory returndata) = address(token).call(data);
              require(success, "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");
              }
          }
      }
      
      // File: contracts/IRewardDistributionRecipient.sol
      
      pragma solidity ^0.5.0;
      
      
      
      contract IRewardDistributionRecipient is Ownable {
          address public rewardDistribution;
      
          function notifyRewardAmount(uint256 reward) external;
      
          modifier onlyRewardDistribution() {
              require(_msgSender() == rewardDistribution, "Caller is not reward distribution");
              _;
          }
      
          function setRewardDistribution(address _rewardDistribution)
              external
              onlyOwner
          {
              rewardDistribution = _rewardDistribution;
          }
      }
      
      // File: contracts/CurveRewards.sol
      
      pragma solidity ^0.5.0;
      
      
      interface PYLON {
          function pylonsScalingFactor() external returns (uint256);
      }
      
      
      
      contract LPTokenWrapper {
          using SafeMath for uint256;
          using SafeERC20 for IERC20;
      
          IERC20 public comp = IERC20(0xc00e94Cb662C3520282E6f5717214004A7f26888);
      
          uint256 private _totalSupply;
          mapping(address => uint256) private _balances;
      
          function totalSupply() public view returns (uint256) {
              return _totalSupply;
          }
      
          function balanceOf(address account) public view returns (uint256) {
              return _balances[account];
          }
      
          function stake(uint256 amount) public {
              _totalSupply = _totalSupply.add(amount);
              _balances[msg.sender] = _balances[msg.sender].add(amount);
              comp.safeTransferFrom(msg.sender, address(this), amount);
          }
      
          function withdraw(uint256 amount) public {
              _totalSupply = _totalSupply.sub(amount);
              _balances[msg.sender] = _balances[msg.sender].sub(amount);
              comp.safeTransfer(msg.sender, amount);
          }
      }
      
      contract PYLONCOMPPool is LPTokenWrapper, IRewardDistributionRecipient {
          IERC20 public pylon = IERC20(0xD7B7d3C0bdA57723Fb54ab95Fd8F9EA033AF37f2);
          uint256 public constant DURATION = 864000; // 10 days
      
          uint256 public starttime = 1598918400; // 2020-09-01 00:00:00 (UTC UTC +00:00)
          uint256 public periodFinish = 0;
          uint256 public rewardRate = 0;
          uint256 public lastUpdateTime;
          uint256 public rewardPerTokenStored;
          mapping(address => uint256) public userRewardPerTokenPaid;
          mapping(address => uint256) public rewards;
      
          event RewardAdded(uint256 reward);
          event Staked(address indexed user, uint256 amount);
          event Withdrawn(address indexed user, uint256 amount);
          event RewardPaid(address indexed user, uint256 reward);
      
          modifier checkStart() {
              require(block.timestamp >= starttime,"not start");
              _;
          }
      
          modifier updateReward(address account) {
              rewardPerTokenStored = rewardPerToken();
              lastUpdateTime = lastTimeRewardApplicable();
              if (account != address(0)) {
                  rewards[account] = earned(account);
                  userRewardPerTokenPaid[account] = rewardPerTokenStored;
              }
              _;
          }
      
          function lastTimeRewardApplicable() public view returns (uint256) {
              return Math.min(block.timestamp, periodFinish);
          }
      
          function rewardPerToken() public view returns (uint256) {
              if (totalSupply() == 0) {
                  return rewardPerTokenStored;
              }
              return
                  rewardPerTokenStored.add(
                      lastTimeRewardApplicable()
                          .sub(lastUpdateTime)
                          .mul(rewardRate)
                          .mul(1e18)
                          .div(totalSupply())
                  );
          }
      
          function earned(address account) public view returns (uint256) {
              return
                  balanceOf(account)
                      .mul(rewardPerToken().sub(userRewardPerTokenPaid[account]))
                      .div(1e18)
                      .add(rewards[account]);
          }
      
          // stake visibility is public as overriding LPTokenWrapper's stake() function
          function stake(uint256 amount) public updateReward(msg.sender) checkStart {
              require(amount > 0, "Cannot stake 0");
              super.stake(amount);
              emit Staked(msg.sender, amount);
          }
      
          function withdraw(uint256 amount) public updateReward(msg.sender) checkStart {
              require(amount > 0, "Cannot withdraw 0");
              super.withdraw(amount);
              emit Withdrawn(msg.sender, amount);
          }
      
          function exit() external {
              withdraw(balanceOf(msg.sender));
              getReward();
          }
      
          function getReward() public updateReward(msg.sender) checkStart {
              uint256 reward = earned(msg.sender);
              if (reward > 0) {
                  rewards[msg.sender] = 0;
                  uint256 scalingFactor = PYLON(address(pylon)).pylonsScalingFactor();
                  uint256 trueReward = reward.mul(scalingFactor).div(10**18);
                  pylon.safeTransfer(msg.sender, trueReward);
                  emit RewardPaid(msg.sender, trueReward);
              }
          }
      
          function notifyRewardAmount(uint256 reward)
              external
              onlyRewardDistribution
              updateReward(address(0))
          {
              if (block.timestamp > starttime) {
                if (block.timestamp >= periodFinish) {
                    rewardRate = reward.div(DURATION);
                } else {
                    uint256 remaining = periodFinish.sub(block.timestamp);
                    uint256 leftover = remaining.mul(rewardRate);
                    rewardRate = reward.add(leftover).div(DURATION);
                }
                lastUpdateTime = block.timestamp;
                periodFinish = block.timestamp.add(DURATION);
                emit RewardAdded(reward);
              } else {
                rewardRate = reward.div(DURATION);
                lastUpdateTime = starttime;
                periodFinish = starttime.add(DURATION);
                emit RewardAdded(reward);
              }
          }
      }

      File 2 of 4: Comp
      pragma solidity ^0.5.16;
      pragma experimental ABIEncoderV2;
      
      contract Comp {
          /// @notice EIP-20 token name for this token
          string public constant name = "Compound";
      
          /// @notice EIP-20 token symbol for this token
          string public constant symbol = "COMP";
      
          /// @notice EIP-20 token decimals for this token
          uint8 public constant decimals = 18;
      
          /// @notice Total number of tokens in circulation
          uint public constant totalSupply = 10000000e18; // 10 million Comp
      
          /// @notice Allowance amounts on behalf of others
          mapping (address => mapping (address => uint96)) internal allowances;
      
          /// @notice Official record of token balances for each account
          mapping (address => uint96) internal balances;
      
          /// @notice A record of each accounts delegate
          mapping (address => address) public delegates;
      
          /// @notice A checkpoint for marking number of votes from a given block
          struct Checkpoint {
              uint32 fromBlock;
              uint96 votes;
          }
      
          /// @notice A record of votes checkpoints for each account, by index
          mapping (address => mapping (uint32 => Checkpoint)) public checkpoints;
      
          /// @notice The number of checkpoints for each account
          mapping (address => uint32) public numCheckpoints;
      
          /// @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 delegation struct used by the contract
          bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
      
          /// @notice A record of states for signing / validating signatures
          mapping (address => uint) public nonces;
      
          /// @notice An event thats emitted when an account changes its delegate
          event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
      
          /// @notice An event thats emitted when a delegate account's vote balance changes
          event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);
      
          /// @notice The standard EIP-20 transfer event
          event Transfer(address indexed from, address indexed to, uint256 amount);
      
          /// @notice The standard EIP-20 approval event
          event Approval(address indexed owner, address indexed spender, uint256 amount);
      
          /**
           * @notice Construct a new Comp token
           * @param account The initial account to grant all the tokens
           */
          constructor(address account) public {
              balances[account] = uint96(totalSupply);
              emit Transfer(address(0), account, totalSupply);
          }
      
          /**
           * @notice Get the number of tokens `spender` is approved to spend on behalf of `account`
           * @param account The address of the account holding the funds
           * @param spender The address of the account spending the funds
           * @return The number of tokens approved
           */
          function allowance(address account, address spender) external view returns (uint) {
              return allowances[account][spender];
          }
      
          /**
           * @notice Approve `spender` to transfer up to `amount` from `src`
           * @dev This will overwrite the approval amount for `spender`
           *  and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
           * @param spender The address of the account which may transfer tokens
           * @param rawAmount The number of tokens that are approved (2^256-1 means infinite)
           * @return Whether or not the approval succeeded
           */
          function approve(address spender, uint rawAmount) external returns (bool) {
              uint96 amount;
              if (rawAmount == uint(-1)) {
                  amount = uint96(-1);
              } else {
                  amount = safe96(rawAmount, "Comp::approve: amount exceeds 96 bits");
              }
      
              allowances[msg.sender][spender] = amount;
      
              emit Approval(msg.sender, spender, amount);
              return true;
          }
      
          /**
           * @notice Get the number of tokens held by the `account`
           * @param account The address of the account to get the balance of
           * @return The number of tokens held
           */
          function balanceOf(address account) external view returns (uint) {
              return balances[account];
          }
      
          /**
           * @notice Transfer `amount` tokens from `msg.sender` to `dst`
           * @param dst The address of the destination account
           * @param rawAmount The number of tokens to transfer
           * @return Whether or not the transfer succeeded
           */
          function transfer(address dst, uint rawAmount) external returns (bool) {
              uint96 amount = safe96(rawAmount, "Comp::transfer: amount exceeds 96 bits");
              _transferTokens(msg.sender, dst, amount);
              return true;
          }
      
          /**
           * @notice Transfer `amount` tokens from `src` to `dst`
           * @param src The address of the source account
           * @param dst The address of the destination account
           * @param rawAmount The number of tokens to transfer
           * @return Whether or not the transfer succeeded
           */
          function transferFrom(address src, address dst, uint rawAmount) external returns (bool) {
              address spender = msg.sender;
              uint96 spenderAllowance = allowances[src][spender];
              uint96 amount = safe96(rawAmount, "Comp::approve: amount exceeds 96 bits");
      
              if (spender != src && spenderAllowance != uint96(-1)) {
                  uint96 newAllowance = sub96(spenderAllowance, amount, "Comp::transferFrom: transfer amount exceeds spender allowance");
                  allowances[src][spender] = newAllowance;
      
                  emit Approval(src, spender, newAllowance);
              }
      
              _transferTokens(src, dst, amount);
              return true;
          }
      
          /**
           * @notice Delegate votes from `msg.sender` to `delegatee`
           * @param delegatee The address to delegate votes to
           */
          function delegate(address delegatee) public {
              return _delegate(msg.sender, delegatee);
          }
      
          /**
           * @notice Delegates votes from signatory to `delegatee`
           * @param delegatee The address to delegate votes to
           * @param nonce The contract state required to match the signature
           * @param expiry The time at which to expire the signature
           * @param v The recovery byte of the signature
           * @param r Half of the ECDSA signature pair
           * @param s Half of the ECDSA signature pair
           */
          function delegateBySig(address delegatee, uint nonce, uint expiry, 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(DELEGATION_TYPEHASH, delegatee, nonce, expiry));
              bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
              address signatory = ecrecover(digest, v, r, s);
              require(signatory != address(0), "Comp::delegateBySig: invalid signature");
              require(nonce == nonces[signatory]++, "Comp::delegateBySig: invalid nonce");
              require(now <= expiry, "Comp::delegateBySig: signature expired");
              return _delegate(signatory, delegatee);
          }
      
          /**
           * @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, "Comp::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;
          }
      
          function _delegate(address delegator, address delegatee) internal {
              address currentDelegate = delegates[delegator];
              uint96 delegatorBalance = balances[delegator];
              delegates[delegator] = delegatee;
      
              emit DelegateChanged(delegator, currentDelegate, delegatee);
      
              _moveDelegates(currentDelegate, delegatee, delegatorBalance);
          }
      
          function _transferTokens(address src, address dst, uint96 amount) internal {
              require(src != address(0), "Comp::_transferTokens: cannot transfer from the zero address");
              require(dst != address(0), "Comp::_transferTokens: cannot transfer to the zero address");
      
              balances[src] = sub96(balances[src], amount, "Comp::_transferTokens: transfer amount exceeds balance");
              balances[dst] = add96(balances[dst], amount, "Comp::_transferTokens: transfer amount overflows");
              emit Transfer(src, dst, amount);
      
              _moveDelegates(delegates[src], delegates[dst], amount);
          }
      
          function _moveDelegates(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, "Comp::_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, "Comp::_moveVotes: vote amount overflows");
                      _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
                  }
              }
          }
      
          function _writeCheckpoint(address delegatee, uint32 nCheckpoints, uint96 oldVotes, uint96 newVotes) internal {
            uint32 blockNumber = safe32(block.number, "Comp::_writeCheckpoint: block number exceeds 32 bits");
      
            if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
                checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
            } else {
                checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
                numCheckpoints[delegatee] = nCheckpoints + 1;
            }
      
            emit DelegateVotesChanged(delegatee, 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;
          }
      }
      

      File 3 of 4: PYLONDelegator
      {"PYLON.sol":{"content":"pragma solidity 0.5.17;\r\n\r\nimport \"./PYLONTokenInterface.sol\";\r\nimport \"./PYLONGovernance.sol\";\r\n\r\ncontract PYLONToken is PYLONGovernanceToken {\r\n    // Modifiers\r\n    modifier onlyGov() {\r\n        require(msg.sender == gov);\r\n        _;\r\n    }\r\n\r\n    modifier onlyRebaser() {\r\n        require(msg.sender == rebaser);\r\n        _;\r\n    }\r\n\r\n    modifier onlyMinter() {\r\n        require(msg.sender == rebaser || msg.sender == incentivizer || msg.sender == gov, \"not minter\");\r\n        _;\r\n    }\r\n\r\n    modifier validRecipient(address to) {\r\n        require(to != address(0x0));\r\n        require(to != address(this));\r\n        _;\r\n    }\r\n\r\n    function initialize(\r\n        string memory name_,\r\n        string memory symbol_,\r\n        uint8 decimals_\r\n    )\r\n        public\r\n    {\r\n        require(pylonsScalingFactor == 0, \"already initialized\");\r\n        name = name_;\r\n        symbol = symbol_;\r\n        decimals = decimals_;\r\n    }\r\n\r\n\r\n    /**\r\n    * @notice Computes the current max scaling factor\r\n    */\r\n    function maxScalingFactor()\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        return _maxScalingFactor();\r\n    }\r\n\r\n    function _maxScalingFactor()\r\n        internal\r\n        view\r\n        returns (uint256)\r\n    {\r\n        // scaling factor can only go up to 2**256-1 = initSupply * pylonsScalingFactor\r\n        // this is used to check if pylonsScalingFactor will be too high to compute balances when rebasing.\r\n        return uint256(-1) / initSupply;\r\n    }\r\n\r\n    /**\r\n    * @notice Mints new tokens, increasing totalSupply, initSupply, and a users balance.\r\n    * @dev Limited to onlyMinter modifier\r\n    */\r\n    function mint(address to, uint256 amount)\r\n        external\r\n        onlyMinter\r\n        returns (bool)\r\n    {\r\n        _mint(to, amount);\r\n        return true;\r\n    }\r\n\r\n    function _mint(address to, uint256 amount)\r\n        internal\r\n    {\r\n      // increase totalSupply\r\n      totalSupply = totalSupply.add(amount);\r\n\r\n      // get underlying value\r\n      uint256 pylonValue = amount.mul(internalDecimals).div(pylonsScalingFactor);\r\n\r\n      // increase initSupply\r\n      initSupply = initSupply.add(pylonValue);\r\n\r\n      // make sure the mint didnt push maxScalingFactor too low\r\n      require(pylonsScalingFactor \u003c= _maxScalingFactor(), \"max scaling factor too low\");\r\n\r\n      // add balance\r\n      _pylonBalances[to] = _pylonBalances[to].add(pylonValue);\r\n\r\n      // add delegates to the minter\r\n      _moveDelegates(address(0), _delegates[to], pylonValue);\r\n      emit Mint(to, amount);\r\n    }\r\n\r\n    /* - ERC20 functionality - */\r\n\r\n    /**\r\n    * @dev Transfer tokens to a specified address.\r\n    * @param to The address to transfer to.\r\n    * @param value The amount to be transferred.\r\n    * @return True on success, false otherwise.\r\n    */\r\n    function transfer(address to, uint256 value)\r\n        external\r\n        validRecipient(to)\r\n        returns (bool)\r\n    {\r\n        // underlying balance is stored in pylons, so divide by current scaling factor\r\n\r\n        // note, this means as scaling factor grows, dust will be untransferrable.\r\n        // minimum transfer value == pylonsScalingFactor / 1e24;\r\n\r\n        // get amount in underlying\r\n        uint256 pylonValue = value.mul(internalDecimals).div(pylonsScalingFactor);\r\n\r\n        // sub from balance of sender\r\n        _pylonBalances[msg.sender] = _pylonBalances[msg.sender].sub(pylonValue);\r\n\r\n        // add to balance of receiver\r\n        _pylonBalances[to] = _pylonBalances[to].add(pylonValue);\r\n        emit Transfer(msg.sender, to, value);\r\n\r\n        _moveDelegates(_delegates[msg.sender], _delegates[to], pylonValue);\r\n        return true;\r\n    }\r\n\r\n    /**\r\n    * @dev Transfer tokens from one address to another.\r\n    * @param from The address you want to send tokens from.\r\n    * @param to The address you want to transfer to.\r\n    * @param value The amount of tokens to be transferred.\r\n    */\r\n    function transferFrom(address from, address to, uint256 value)\r\n        external\r\n        validRecipient(to)\r\n        returns (bool)\r\n    {\r\n        // decrease allowance\r\n        _allowedFragments[from][msg.sender] = _allowedFragments[from][msg.sender].sub(value);\r\n\r\n        // get value in pylons\r\n        uint256 pylonValue = value.mul(internalDecimals).div(pylonsScalingFactor);\r\n\r\n        // sub from from\r\n        _pylonBalances[from] = _pylonBalances[from].sub(pylonValue);\r\n        _pylonBalances[to] = _pylonBalances[to].add(pylonValue);\r\n        emit Transfer(from, to, value);\r\n\r\n        _moveDelegates(_delegates[from], _delegates[to], pylonValue);\r\n        return true;\r\n    }\r\n\r\n    /**\r\n    * @param who The address to query.\r\n    * @return The balance of the specified address.\r\n    */\r\n    function balanceOf(address who)\r\n      external\r\n      view\r\n      returns (uint256)\r\n    {\r\n      return _pylonBalances[who].mul(pylonsScalingFactor).div(internalDecimals);\r\n    }\r\n\r\n    /** @notice Currently returns the internal storage amount\r\n    * @param who The address to query.\r\n    * @return The underlying balance of the specified address.\r\n    */\r\n    function balanceOfUnderlying(address who)\r\n      external\r\n      view\r\n      returns (uint256)\r\n    {\r\n      return _pylonBalances[who];\r\n    }\r\n\r\n    /**\r\n     * @dev Function to check the amount of tokens that an owner has allowed to a spender.\r\n     * @param owner_ The address which owns the funds.\r\n     * @param spender The address which will spend the funds.\r\n     * @return The number of tokens still available for the spender.\r\n     */\r\n    function allowance(address owner_, address spender)\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        return _allowedFragments[owner_][spender];\r\n    }\r\n\r\n    /**\r\n     * @dev Approve the passed address to spend the specified amount of tokens on behalf of\r\n     * msg.sender. This method is included for ERC20 compatibility.\r\n     * increaseAllowance and decreaseAllowance should be used instead.\r\n     * Changing an allowance with this method brings the risk that someone may transfer both\r\n     * the old and the new allowance - if they are both greater than zero - if a transfer\r\n     * transaction is mined before the later approve() call is mined.\r\n     *\r\n     * @param spender The address which will spend the funds.\r\n     * @param value The amount of tokens to be spent.\r\n     */\r\n    function approve(address spender, uint256 value)\r\n        external\r\n        returns (bool)\r\n    {\r\n        _allowedFragments[msg.sender][spender] = value;\r\n        emit Approval(msg.sender, spender, value);\r\n        return true;\r\n    }\r\n\r\n    /**\r\n     * @dev Increase the amount of tokens that an owner has allowed to a spender.\r\n     * This method should be used instead of approve() to avoid the double approval vulnerability\r\n     * described above.\r\n     * @param spender The address which will spend the funds.\r\n     * @param addedValue The amount of tokens to increase the allowance by.\r\n     */\r\n    function increaseAllowance(address spender, uint256 addedValue)\r\n        external\r\n        returns (bool)\r\n    {\r\n        _allowedFragments[msg.sender][spender] =\r\n            _allowedFragments[msg.sender][spender].add(addedValue);\r\n        emit Approval(msg.sender, spender, _allowedFragments[msg.sender][spender]);\r\n        return true;\r\n    }\r\n\r\n    /**\r\n     * @dev Decrease the amount of tokens that an owner has allowed to a spender.\r\n     *\r\n     * @param spender The address which will spend the funds.\r\n     * @param subtractedValue The amount of tokens to decrease the allowance by.\r\n     */\r\n    function decreaseAllowance(address spender, uint256 subtractedValue)\r\n        external\r\n        returns (bool)\r\n    {\r\n        uint256 oldValue = _allowedFragments[msg.sender][spender];\r\n        if (subtractedValue \u003e= oldValue) {\r\n            _allowedFragments[msg.sender][spender] = 0;\r\n        } else {\r\n            _allowedFragments[msg.sender][spender] = oldValue.sub(subtractedValue);\r\n        }\r\n        emit Approval(msg.sender, spender, _allowedFragments[msg.sender][spender]);\r\n        return true;\r\n    }\r\n\r\n    /* - Governance Functions - */\r\n\r\n    /** @notice sets the rebaser\r\n     * @param rebaser_ The address of the rebaser contract to use for authentication.\r\n     */\r\n    function _setRebaser(address rebaser_)\r\n        external\r\n        onlyGov\r\n    {\r\n        address oldRebaser = rebaser;\r\n        rebaser = rebaser_;\r\n        emit NewRebaser(oldRebaser, rebaser_);\r\n    }\r\n\r\n    /** @notice sets the incentivizer\r\n     * @param incentivizer_ The address of the rebaser contract to use for authentication.\r\n     */\r\n    function _setIncentivizer(address incentivizer_)\r\n        external\r\n        onlyGov\r\n    {\r\n        address oldIncentivizer = incentivizer;\r\n        incentivizer = incentivizer_;\r\n        emit NewIncentivizer(oldIncentivizer, incentivizer_);\r\n    }\r\n\r\n    /** @notice sets the pendingGov\r\n     * @param pendingGov_ The address of the rebaser contract to use for authentication.\r\n     */\r\n    function _setPendingGov(address pendingGov_)\r\n        external\r\n        onlyGov\r\n    {\r\n        address oldPendingGov = pendingGov;\r\n        pendingGov = pendingGov_;\r\n        emit NewPendingGov(oldPendingGov, pendingGov_);\r\n    }\r\n\r\n    /** @notice lets msg.sender accept governance\r\n     *\r\n     */\r\n    function _acceptGov()\r\n        external\r\n    {\r\n        require(msg.sender == pendingGov, \"!pending\");\r\n        address oldGov = gov;\r\n        gov = pendingGov;\r\n        pendingGov = address(0);\r\n        emit NewGov(oldGov, gov);\r\n    }\r\n\r\n    /* - Extras - */\r\n\r\n    /**\r\n    * @notice Initiates a new rebase operation, provided the minimum time period has elapsed.\r\n    *\r\n    * @dev The supply adjustment equals (totalSupply * DeviationFromTargetRate) / rebaseLag\r\n    *      Where DeviationFromTargetRate is (MarketOracleRate - targetRate) / targetRate\r\n    *      and targetRate is CpiOracleRate / baseCpi\r\n    */\r\n    function rebase(\r\n        uint256 epoch,\r\n        uint256 indexDelta,\r\n        bool positive\r\n    )\r\n        external\r\n        onlyRebaser\r\n        returns (uint256)\r\n    {\r\n        if (indexDelta == 0) {\r\n          emit Rebase(epoch, pylonsScalingFactor, pylonsScalingFactor);\r\n          return totalSupply;\r\n        }\r\n\r\n        uint256 prevPYLONsScalingFactor = pylonsScalingFactor;\r\n\r\n        if (!positive) {\r\n           pylonsScalingFactor = pylonsScalingFactor.mul(BASE.sub(indexDelta)).div(BASE);\r\n        } else {\r\n            uint256 newScalingFactor = pylonsScalingFactor.mul(BASE.add(indexDelta)).div(BASE);\r\n            if (newScalingFactor \u003c _maxScalingFactor()) {\r\n                pylonsScalingFactor = newScalingFactor;\r\n            } else {\r\n              pylonsScalingFactor = _maxScalingFactor();\r\n            }\r\n        }\r\n\r\n        totalSupply = initSupply.mul(pylonsScalingFactor);\r\n        emit Rebase(epoch, prevPYLONsScalingFactor, pylonsScalingFactor);\r\n        return totalSupply;\r\n    }\r\n}\r\n\r\ncontract PYLON is PYLONToken {\r\n    /**\r\n     * @notice Initialize the new money market\r\n     * @param name_ ERC-20 name of this token\r\n     * @param symbol_ ERC-20 symbol of this token\r\n     * @param decimals_ ERC-20 decimal precision of this token\r\n     */\r\n    function initialize(\r\n        string memory name_,\r\n        string memory symbol_,\r\n        uint8 decimals_,\r\n        address initial_owner,\r\n        uint256 initSupply_\r\n    )\r\n        public\r\n    {\r\n        require(initSupply_ \u003e 0, \"0 init supply\");\r\n\r\n        super.initialize(name_, symbol_, decimals_);\r\n\r\n        initSupply = initSupply_.mul(10**24/ (BASE));\r\n        totalSupply = initSupply_;\r\n        pylonsScalingFactor = BASE;\r\n        _pylonBalances[initial_owner] = initSupply_.mul(10**24 / (BASE));\r\n\r\n        // owner renounces ownership after deployment as they need to set\r\n        // rebaser and incentivizer\r\n        // gov = gov_;\r\n    }\r\n}\r\n"},"PYLONDelegate.sol":{"content":"pragma solidity 0.5.17;\r\n\r\nimport \"./PYLON.sol\";\r\n\r\ncontract PYLONDelegationStorage {\r\n    /**\r\n     * @notice Implementation address for this contract\r\n     */\r\n    address public implementation;\r\n}\r\n\r\ncontract PYLONDelegatorInterface is PYLONDelegationStorage {\r\n    /**\r\n     * @notice Emitted when implementation is changed\r\n     */\r\n    event NewImplementation(address oldImplementation, address newImplementation);\r\n\r\n    /**\r\n     * @notice Called by the gov to update the implementation of the delegator\r\n     * @param implementation_ The address of the new implementation for delegation\r\n     * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation\r\n     * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation\r\n     */\r\n    function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData) public;\r\n}\r\n\r\ncontract PYLONDelegateInterface is PYLONDelegationStorage {\r\n    /**\r\n     * @notice Called by the delegator on a delegate to initialize it for duty\r\n     * @dev Should revert if any issues arise which make it unfit for delegation\r\n     * @param data The encoded bytes data for any initialization\r\n     */\r\n    function _becomeImplementation(bytes memory data) public;\r\n\r\n    /**\r\n     * @notice Called by the delegator on a delegate to forfeit its responsibility\r\n     */\r\n    function _resignImplementation() public;\r\n}\r\n\r\n\r\ncontract PYLONDelegate is PYLON, PYLONDelegateInterface {\r\n    /**\r\n     * @notice Construct an empty delegate\r\n     */\r\n    constructor() public {}\r\n\r\n    /**\r\n     * @notice Called by the delegator on a delegate to initialize it for duty\r\n     * @param data The encoded bytes data for any initialization\r\n     */\r\n    function _becomeImplementation(bytes memory data) public {\r\n        // Shh -- currently unused\r\n        data;\r\n\r\n        // Shh -- we don\u0027t ever want this hook to be marked pure\r\n        if (false) {\r\n            implementation = address(0);\r\n        }\r\n\r\n        require(msg.sender == gov, \"only the gov may call _becomeImplementation\");\r\n    }\r\n\r\n    /**\r\n     * @notice Called by the delegator on a delegate to forfeit its responsibility\r\n     */\r\n    function _resignImplementation() public {\r\n        // Shh -- we don\u0027t ever want this hook to be marked pure\r\n        if (false) {\r\n            implementation = address(0);\r\n        }\r\n\r\n        require(msg.sender == gov, \"only the gov may call _resignImplementation\");\r\n    }\r\n}\r\n"},"PYLONDelegator.sol":{"content":"pragma solidity 0.5.17;\r\n\r\n/* import \"./PYLONTokenInterface.sol\"; */\r\nimport \"./PYLONDelegate.sol\";\r\n\r\ncontract PYLONDelegator is PYLONTokenInterface, PYLONDelegatorInterface {\r\n    /**\r\n     * @notice Construct a new PYLON\r\n     * @param name_ ERC-20 name of this token\r\n     * @param symbol_ ERC-20 symbol of this token\r\n     * @param decimals_ ERC-20 decimal precision of this token\r\n     * @param initSupply_ Initial token amount\r\n     * @param implementation_ The address of the implementation the contract delegates to\r\n     * @param becomeImplementationData The encoded args for becomeImplementation\r\n     */\r\n    constructor(\r\n        string memory name_,\r\n        string memory symbol_,\r\n        uint8 decimals_,\r\n        uint256 initSupply_,\r\n        address implementation_,\r\n        bytes memory becomeImplementationData\r\n    )\r\n        public\r\n    {\r\n\r\n\r\n        // Creator of the contract is gov during initialization\r\n        gov = msg.sender;\r\n\r\n        // First delegate gets to initialize the delegator (i.e. storage contract)\r\n        delegateTo(\r\n            implementation_,\r\n            abi.encodeWithSignature(\r\n                \"initialize(string,string,uint8,address,uint256)\",\r\n                name_,\r\n                symbol_,\r\n                decimals_,\r\n                msg.sender,\r\n                initSupply_\r\n            )\r\n        );\r\n\r\n        // New implementations always get set via the settor (post-initialize)\r\n        _setImplementation(implementation_, false, becomeImplementationData);\r\n\r\n    }\r\n\r\n    /**\r\n     * @notice Called by the gov to update the implementation of the delegator\r\n     * @param implementation_ The address of the new implementation for delegation\r\n     * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation\r\n     * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation\r\n     */\r\n    function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData) public {\r\n        require(msg.sender == gov, \"PYLONDelegator::_setImplementation: Caller must be gov\");\r\n\r\n        if (allowResign) {\r\n            delegateToImplementation(abi.encodeWithSignature(\"_resignImplementation()\"));\r\n        }\r\n\r\n        address oldImplementation = implementation;\r\n        implementation = implementation_;\r\n\r\n        delegateToImplementation(abi.encodeWithSignature(\"_becomeImplementation(bytes)\", becomeImplementationData));\r\n\r\n        emit NewImplementation(oldImplementation, implementation);\r\n    }\r\n\r\n    /**\r\n     * @notice Sender supplies assets into the market and receives cTokens in exchange\r\n     * @dev Accrues interest whether or not the operation succeeds, unless reverted\r\n     * @param mintAmount The amount of the underlying asset to supply\r\n     * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\r\n     */\r\n    function mint(address to, uint256 mintAmount)\r\n        external\r\n        returns (bool)\r\n    {\r\n        to; mintAmount; // Shh\r\n        delegateAndReturn();\r\n    }\r\n\r\n    /**\r\n     * @notice Transfer `amount` tokens from `msg.sender` to `dst`\r\n     * @param dst The address of the destination account\r\n     * @param amount The number of tokens to transfer\r\n     * @return Whether or not the transfer succeeded\r\n     */\r\n    function transfer(address dst, uint256 amount)\r\n        external\r\n        returns (bool)\r\n    {\r\n        dst; amount; // Shh\r\n        delegateAndReturn();\r\n    }\r\n\r\n    /**\r\n     * @notice Transfer `amount` tokens from `src` to `dst`\r\n     * @param src The address of the source account\r\n     * @param dst The address of the destination account\r\n     * @param amount The number of tokens to transfer\r\n     * @return Whether or not the transfer succeeded\r\n     */\r\n    function transferFrom(\r\n        address src,\r\n        address dst,\r\n        uint256 amount\r\n    )\r\n        external\r\n        returns (bool)\r\n    {\r\n        src; dst; amount; // Shh\r\n        delegateAndReturn();\r\n    }\r\n\r\n    /**\r\n     * @notice Approve `spender` to transfer up to `amount` from `src`\r\n     * @dev This will overwrite the approval amount for `spender`\r\n     *  and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)\r\n     * @param spender The address of the account which may transfer tokens\r\n     * @param amount The number of tokens that are approved (-1 means infinite)\r\n     * @return Whether or not the approval succeeded\r\n     */\r\n    function approve(\r\n        address spender,\r\n        uint256 amount\r\n    )\r\n        external\r\n        returns (bool)\r\n    {\r\n        spender; amount; // Shh\r\n        delegateAndReturn();\r\n    }\r\n\r\n    /**\r\n     * @dev Increase the amount of tokens that an owner has allowed to a spender.\r\n     * This method should be used instead of approve() to avoid the double approval vulnerability\r\n     * described above.\r\n     * @param spender The address which will spend the funds.\r\n     * @param addedValue The amount of tokens to increase the allowance by.\r\n     */\r\n    function increaseAllowance(\r\n        address spender,\r\n        uint256 addedValue\r\n    )\r\n        external\r\n        returns (bool)\r\n    {\r\n        spender; addedValue; // Shh\r\n        delegateAndReturn();\r\n    }\r\n\r\n    function maxScalingFactor()\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        delegateToViewAndReturn();\r\n    }\r\n\r\n    function rebase(\r\n        uint256 epoch,\r\n        uint256 indexDelta,\r\n        bool positive\r\n    )\r\n        external\r\n        returns (uint256)\r\n    {\r\n        epoch; indexDelta; positive;\r\n        delegateAndReturn();\r\n    }\r\n\r\n    /**\r\n     * @dev Decrease the amount of tokens that an owner has allowed to a spender.\r\n     *\r\n     * @param spender The address which will spend the funds.\r\n     * @param subtractedValue The amount of tokens to decrease the allowance by.\r\n     */\r\n    function decreaseAllowance(\r\n        address spender,\r\n        uint256 subtractedValue\r\n    )\r\n        external\r\n        returns (bool)\r\n    {\r\n        spender; subtractedValue; // Shh\r\n        delegateAndReturn();\r\n    }\r\n\r\n    /**\r\n     * @notice Get the current allowance from `owner` for `spender`\r\n     * @param owner The address of the account which owns the tokens to be spent\r\n     * @param spender The address of the account which may transfer tokens\r\n     * @return The number of tokens allowed to be spent (-1 means infinite)\r\n     */\r\n    function allowance(\r\n        address owner,\r\n        address spender\r\n    )\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        owner; spender; // Shh\r\n        delegateToViewAndReturn();\r\n    }\r\n\r\n    /**\r\n     * @notice Get the current allowance from `owner` for `spender`\r\n     * @param delegator The address of the account which has designated a delegate\r\n     * @return Address of delegatee\r\n     */\r\n    function delegates(\r\n        address delegator\r\n    )\r\n        external\r\n        view\r\n        returns (address)\r\n    {\r\n        delegator; // Shh\r\n        delegateToViewAndReturn();\r\n    }\r\n\r\n    /**\r\n     * @notice Get the token balance of the `owner`\r\n     * @param owner The address of the account to query\r\n     * @return The number of tokens owned by `owner`\r\n     */\r\n    function balanceOf(address owner)\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        owner; // Shh\r\n        delegateToViewAndReturn();\r\n    }\r\n\r\n    /**\r\n     * @notice Currently unused. For future compatability\r\n     * @param owner The address of the account to query\r\n     * @return The number of underlying tokens owned by `owner`\r\n     */\r\n    function balanceOfUnderlying(address owner)\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        owner; // Shh\r\n        delegateToViewAndReturn();\r\n    }\r\n\r\n    /*** Gov Functions ***/\r\n\r\n    /**\r\n      * @notice Begins transfer of gov rights. The newPendingGov must call `_acceptGov` to finalize the transfer.\r\n      * @dev Gov function to begin change of gov. The newPendingGov must call `_acceptGov` to finalize the transfer.\r\n      * @param newPendingGov New pending gov.\r\n      */\r\n    function _setPendingGov(address newPendingGov)\r\n        external\r\n    {\r\n        newPendingGov; // Shh\r\n        delegateAndReturn();\r\n    }\r\n\r\n    function _setRebaser(address rebaser_)\r\n        external\r\n    {\r\n        rebaser_; // Shh\r\n        delegateAndReturn();\r\n    }\r\n\r\n    function _setIncentivizer(address incentivizer_)\r\n        external\r\n    {\r\n        incentivizer_; // Shh\r\n        delegateAndReturn();\r\n    }\r\n\r\n    /**\r\n      * @notice Accepts transfer of gov rights. msg.sender must be pendingGov\r\n      * @dev Gov function for pending gov to accept role and update gov\r\n      * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)\r\n      */\r\n    function _acceptGov()\r\n        external\r\n    {\r\n        delegateAndReturn();\r\n    }\r\n\r\n\r\n    function getPriorVotes(address account, uint blockNumber)\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        account; blockNumber;\r\n        delegateToViewAndReturn();\r\n    }\r\n\r\n    function delegateBySig(\r\n        address delegatee,\r\n        uint nonce,\r\n        uint expiry,\r\n        uint8 v,\r\n        bytes32 r,\r\n        bytes32 s\r\n    )\r\n        external\r\n    {\r\n        delegatee; nonce; expiry; v; r; s;\r\n        delegateAndReturn();\r\n    }\r\n\r\n    function delegate(address delegatee)\r\n        external\r\n    {\r\n        delegatee;\r\n        delegateAndReturn();\r\n    }\r\n\r\n    function getCurrentVotes(address account)\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        account;\r\n        delegateToViewAndReturn();\r\n    }\r\n\r\n    /**\r\n     * @notice Internal method to delegate execution to another contract\r\n     * @dev It returns to the external caller whatever the implementation returns or forwards reverts\r\n     * @param callee The contract to delegatecall\r\n     * @param data The raw data to delegatecall\r\n     * @return The returned bytes from the delegatecall\r\n     */\r\n    function delegateTo(address callee, bytes memory data) internal returns (bytes memory) {\r\n        (bool success, bytes memory returnData) = callee.delegatecall(data);\r\n        assembly {\r\n            if eq(success, 0) {\r\n                revert(add(returnData, 0x20), returndatasize)\r\n            }\r\n        }\r\n        return returnData;\r\n    }\r\n\r\n    /**\r\n     * @notice Delegates execution to the implementation contract\r\n     * @dev It returns to the external caller whatever the implementation returns or forwards reverts\r\n     * @param data The raw data to delegatecall\r\n     * @return The returned bytes from the delegatecall\r\n     */\r\n    function delegateToImplementation(bytes memory data) public returns (bytes memory) {\r\n        return delegateTo(implementation, data);\r\n    }\r\n\r\n    /**\r\n     * @notice Delegates execution to an implementation contract\r\n     * @dev It returns to the external caller whatever the implementation returns or forwards reverts\r\n     *  There are an additional 2 prefix uints from the wrapper returndata, which we ignore since we make an extra hop.\r\n     * @param data The raw data to delegatecall\r\n     * @return The returned bytes from the delegatecall\r\n     */\r\n    function delegateToViewImplementation(bytes memory data) public view returns (bytes memory) {\r\n        (bool success, bytes memory returnData) = address(this).staticcall(abi.encodeWithSignature(\"delegateToImplementation(bytes)\", data));\r\n        assembly {\r\n            if eq(success, 0) {\r\n                revert(add(returnData, 0x20), returndatasize)\r\n            }\r\n        }\r\n        return abi.decode(returnData, (bytes));\r\n    }\r\n\r\n    function delegateToViewAndReturn() private view returns (bytes memory) {\r\n        (bool success, ) = address(this).staticcall(abi.encodeWithSignature(\"delegateToImplementation(bytes)\", msg.data));\r\n\r\n        assembly {\r\n            let free_mem_ptr := mload(0x40)\r\n            returndatacopy(free_mem_ptr, 0, returndatasize)\r\n\r\n            switch success\r\n            case 0 { revert(free_mem_ptr, returndatasize) }\r\n            default { return(add(free_mem_ptr, 0x40), returndatasize) }\r\n        }\r\n    }\r\n\r\n    function delegateAndReturn() private returns (bytes memory) {\r\n        (bool success, ) = implementation.delegatecall(msg.data);\r\n\r\n        assembly {\r\n            let free_mem_ptr := mload(0x40)\r\n            returndatacopy(free_mem_ptr, 0, returndatasize)\r\n\r\n            switch success\r\n            case 0 { revert(free_mem_ptr, returndatasize) }\r\n            default { return(free_mem_ptr, returndatasize) }\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @notice Delegates execution to an implementation contract\r\n     * @dev It returns to the external caller whatever the implementation returns or forwards reverts\r\n     */\r\n    function () external payable {\r\n        require(msg.value == 0,\"PYLONDelegator:fallback: cannot send value to fallback\");\r\n\r\n        // delegate all other functions to current implementation\r\n        delegateAndReturn();\r\n    }\r\n}\r\n"},"PYLONGovernance.sol":{"content":"pragma solidity 0.5.17;\r\npragma experimental ABIEncoderV2;\r\n\r\nimport \"./PYLONGovernanceStorage.sol\";\r\nimport \"./PYLONTokenInterface.sol\";\r\n\r\ncontract PYLONGovernanceToken is PYLONTokenInterface {\r\n\r\n      /// @notice An event thats emitted when an account changes its delegate\r\n    event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\r\n\r\n    /// @notice An event thats emitted when a delegate account\u0027s vote balance changes\r\n    event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);\r\n\r\n    /**\r\n     * @notice Delegate votes from `msg.sender` to `delegatee`\r\n     * @param delegator The address to get delegatee for\r\n     */\r\n    function delegates(address delegator)\r\n        external\r\n        view\r\n        returns (address)\r\n    {\r\n        return _delegates[delegator];\r\n    }\r\n\r\n   /**\r\n    * @notice Delegate votes from `msg.sender` to `delegatee`\r\n    * @param delegatee The address to delegate votes to\r\n    */\r\n    function delegate(address delegatee) external {\r\n        return _delegate(msg.sender, delegatee);\r\n    }\r\n\r\n    /**\r\n     * @notice Delegates votes from signatory to `delegatee`\r\n     * @param delegatee The address to delegate votes to\r\n     * @param nonce The contract state required to match the signature\r\n     * @param expiry The time at which to expire the signature\r\n     * @param v The recovery byte of the signature\r\n     * @param r Half of the ECDSA signature pair\r\n     * @param s Half of the ECDSA signature pair\r\n     */\r\n    function delegateBySig(\r\n        address delegatee,\r\n        uint nonce,\r\n        uint expiry,\r\n        uint8 v,\r\n        bytes32 r,\r\n        bytes32 s\r\n    )\r\n        external\r\n    {\r\n        bytes32 domainSeparator = keccak256(\r\n            abi.encode(\r\n                DOMAIN_TYPEHASH,\r\n                keccak256(bytes(name)),\r\n                getChainId(),\r\n                address(this)\r\n            )\r\n        );\r\n\r\n        bytes32 structHash = keccak256(\r\n            abi.encode(\r\n                DELEGATION_TYPEHASH,\r\n                delegatee,\r\n                nonce,\r\n                expiry\r\n            )\r\n        );\r\n\r\n        bytes32 digest = keccak256(\r\n            abi.encodePacked(\r\n                \"\\x19\\x01\",\r\n                domainSeparator,\r\n                structHash\r\n            )\r\n        );\r\n\r\n        address signatory = ecrecover(digest, v, r, s);\r\n        require(signatory != address(0), \"PYLON::delegateBySig: invalid signature\");\r\n        require(nonce == nonces[signatory]++, \"PYLON::delegateBySig: invalid nonce\");\r\n        require(now \u003c= expiry, \"PYLON::delegateBySig: signature expired\");\r\n        return _delegate(signatory, delegatee);\r\n    }\r\n\r\n    /**\r\n     * @notice Gets the current votes balance for `account`\r\n     * @param account The address to get votes balance\r\n     * @return The number of current votes for `account`\r\n     */\r\n    function getCurrentVotes(address account)\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        uint32 nCheckpoints = numCheckpoints[account];\r\n        return nCheckpoints \u003e 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;\r\n    }\r\n\r\n    /**\r\n     * @notice Determine the prior number of votes for an account as of a block number\r\n     * @dev Block number must be a finalized block or else this function will revert to prevent misinformation.\r\n     * @param account The address of the account to check\r\n     * @param blockNumber The block number to get the vote balance at\r\n     * @return The number of votes the account had as of the given block\r\n     */\r\n    function getPriorVotes(address account, uint blockNumber)\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        require(blockNumber \u003c block.number, \"PYLON::getPriorVotes: not yet determined\");\r\n\r\n        uint32 nCheckpoints = numCheckpoints[account];\r\n        if (nCheckpoints == 0) {\r\n            return 0;\r\n        }\r\n\r\n        // First check most recent balance\r\n        if (checkpoints[account][nCheckpoints - 1].fromBlock \u003c= blockNumber) {\r\n            return checkpoints[account][nCheckpoints - 1].votes;\r\n        }\r\n\r\n        // Next check implicit zero balance\r\n        if (checkpoints[account][0].fromBlock \u003e blockNumber) {\r\n            return 0;\r\n        }\r\n\r\n        uint32 lower = 0;\r\n        uint32 upper = nCheckpoints - 1;\r\n        while (upper \u003e lower) {\r\n            uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow\r\n            Checkpoint memory cp = checkpoints[account][center];\r\n            if (cp.fromBlock == blockNumber) {\r\n                return cp.votes;\r\n            } else if (cp.fromBlock \u003c blockNumber) {\r\n                lower = center;\r\n            } else {\r\n                upper = center - 1;\r\n            }\r\n        }\r\n        return checkpoints[account][lower].votes;\r\n    }\r\n\r\n    function _delegate(address delegator, address delegatee)\r\n        internal\r\n    {\r\n        address currentDelegate = _delegates[delegator];\r\n        uint256 delegatorBalance = _pylonBalances[delegator]; // balance of underlying PYLONs (not scaled);\r\n        _delegates[delegator] = delegatee;\r\n\r\n        emit DelegateChanged(delegator, currentDelegate, delegatee);\r\n\r\n        _moveDelegates(currentDelegate, delegatee, delegatorBalance);\r\n    }\r\n\r\n    function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {\r\n        if (srcRep != dstRep \u0026\u0026 amount \u003e 0) {\r\n            if (srcRep != address(0)) {\r\n                // decrease old representative\r\n                uint32 srcRepNum = numCheckpoints[srcRep];\r\n                uint256 srcRepOld = srcRepNum \u003e 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;\r\n                uint256 srcRepNew = srcRepOld.sub(amount);\r\n                _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);\r\n            }\r\n\r\n            if (dstRep != address(0)) {\r\n                // increase new representative\r\n                uint32 dstRepNum = numCheckpoints[dstRep];\r\n                uint256 dstRepOld = dstRepNum \u003e 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;\r\n                uint256 dstRepNew = dstRepOld.add(amount);\r\n                _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);\r\n            }\r\n        }\r\n    }\r\n\r\n    function _writeCheckpoint(\r\n        address delegatee,\r\n        uint32 nCheckpoints,\r\n        uint256 oldVotes,\r\n        uint256 newVotes\r\n    )\r\n        internal\r\n    {\r\n        uint32 blockNumber = safe32(block.number, \"PYLON::_writeCheckpoint: block number exceeds 32 bits\");\r\n\r\n        if (nCheckpoints \u003e 0 \u0026\u0026 checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {\r\n            checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;\r\n        } else {\r\n            checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);\r\n            numCheckpoints[delegatee] = nCheckpoints + 1;\r\n        }\r\n\r\n        emit DelegateVotesChanged(delegatee, oldVotes, newVotes);\r\n    }\r\n\r\n    function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {\r\n        require(n \u003c 2**32, errorMessage);\r\n        return uint32(n);\r\n    }\r\n\r\n    function getChainId() internal pure returns (uint) {\r\n        uint256 chainId;\r\n        assembly { chainId := chainid() }\r\n        return chainId;\r\n    }\r\n}\r\n"},"PYLONGovernanceStorage.sol":{"content":"pragma solidity 0.5.17;\r\npragma experimental ABIEncoderV2;\r\n\r\ncontract PYLONGovernanceStorage {\r\n    /// @notice A record of each accounts delegate\r\n    mapping (address =\u003e address) internal _delegates;\r\n\r\n    /// @notice A checkpoint for marking number of votes from a given block\r\n    struct Checkpoint {\r\n        uint32 fromBlock;\r\n        uint256 votes;\r\n    }\r\n\r\n    /// @notice A record of votes checkpoints for each account, by index\r\n    mapping (address =\u003e mapping (uint32 =\u003e Checkpoint)) public checkpoints;\r\n\r\n    /// @notice The number of checkpoints for each account\r\n    mapping (address =\u003e uint32) public numCheckpoints;\r\n\r\n    /// @notice The EIP-712 typehash for the contract\u0027s domain\r\n    bytes32 public constant DOMAIN_TYPEHASH = keccak256(\"EIP712Domain(string name,uint256 chainId,address verifyingContract)\");\r\n\r\n    /// @notice The EIP-712 typehash for the delegation struct used by the contract\r\n    bytes32 public constant DELEGATION_TYPEHASH = keccak256(\"Delegation(address delegatee,uint256 nonce,uint256 expiry)\");\r\n\r\n    /// @notice A record of states for signing / validating signatures\r\n    mapping (address =\u003e uint) public nonces;\r\n}\r\n"},"PYLONTokenInterface.sol":{"content":"pragma solidity 0.5.17;\r\n\r\nimport \"./PYLONTokenStorage.sol\";\r\nimport \"./PYLONGovernanceStorage.sol\";\r\n\r\ncontract PYLONTokenInterface is PYLONTokenStorage, PYLONGovernanceStorage {\r\n\r\n    /// @notice An event thats emitted when an account changes its delegate\r\n    event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\r\n\r\n    /// @notice An event thats emitted when a delegate account\u0027s vote balance changes\r\n    event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);\r\n\r\n    /**\r\n     * @notice Event emitted when tokens are rebased\r\n     */\r\n    event Rebase(uint256 epoch, uint256 prevPYLONsScalingFactor, uint256 newPYLONsScalingFactor);\r\n\r\n    /*** Gov Events ***/\r\n\r\n    /**\r\n     * @notice Event emitted when pendingGov is changed\r\n     */\r\n    event NewPendingGov(address oldPendingGov, address newPendingGov);\r\n\r\n    /**\r\n     * @notice Event emitted when gov is changed\r\n     */\r\n    event NewGov(address oldGov, address newGov);\r\n\r\n    /**\r\n     * @notice Sets the rebaser contract\r\n     */\r\n    event NewRebaser(address oldRebaser, address newRebaser);\r\n\r\n    /**\r\n     * @notice Sets the incentivizer contract\r\n     */\r\n    event NewIncentivizer(address oldIncentivizer, address newIncentivizer);\r\n\r\n    /* - ERC20 Events - */\r\n\r\n    /**\r\n     * @notice EIP20 Transfer event\r\n     */\r\n    event Transfer(address indexed from, address indexed to, uint amount);\r\n\r\n    /**\r\n     * @notice EIP20 Approval event\r\n     */\r\n    event Approval(address indexed owner, address indexed spender, uint amount);\r\n\r\n    /* - Extra Events - */\r\n    /**\r\n     * @notice Tokens minted event\r\n     */\r\n    event Mint(address to, uint256 amount);\r\n\r\n    // Public functions\r\n    function transfer(address to, uint256 value) external returns(bool);\r\n    function transferFrom(address from, address to, uint256 value) external returns(bool);\r\n    function balanceOf(address who) external view returns(uint256);\r\n    function balanceOfUnderlying(address who) external view returns(uint256);\r\n    function allowance(address owner_, address spender) external view returns(uint256);\r\n    function approve(address spender, uint256 value) external returns (bool);\r\n    function increaseAllowance(address spender, uint256 addedValue) external returns (bool);\r\n    function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);\r\n    function maxScalingFactor() external view returns (uint256);\r\n\r\n    /* - Governance Functions - */\r\n    function getPriorVotes(address account, uint blockNumber) external view returns (uint256);\r\n    function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) external;\r\n    function delegate(address delegatee) external;\r\n    function delegates(address delegator) external view returns (address);\r\n    function getCurrentVotes(address account) external view returns (uint256);\r\n\r\n    /* - Permissioned/Governance functions - */\r\n    function mint(address to, uint256 amount) external returns (bool);\r\n    function rebase(uint256 epoch, uint256 indexDelta, bool positive) external returns (uint256);\r\n    function _setRebaser(address rebaser_) external;\r\n    function _setIncentivizer(address incentivizer_) external;\r\n    function _setPendingGov(address pendingGov_) external;\r\n    function _acceptGov() external;\r\n}\r\n"},"PYLONTokenStorage.sol":{"content":"pragma solidity 0.5.17;\r\n\r\nimport \"./SafeMath.sol\";\r\n\r\n// Storage for a PYLON token\r\ncontract PYLONTokenStorage {\r\n\r\n    using SafeMath for uint256;\r\n\r\n    /**\r\n     * @dev Guard variable for re-entrancy checks. Not currently used\r\n     */\r\n    bool internal _notEntered;\r\n\r\n    /**\r\n     * @notice EIP-20 token name for this token\r\n     */\r\n    string public name;\r\n\r\n    /**\r\n     * @notice EIP-20 token symbol for this token\r\n     */\r\n    string public symbol;\r\n\r\n    /**\r\n     * @notice EIP-20 token decimals for this token\r\n     */\r\n    uint8 public decimals;\r\n\r\n    /**\r\n     * @notice Governor for this contract\r\n     */\r\n    address public gov;\r\n\r\n    /**\r\n     * @notice Pending governance for this contract\r\n     */\r\n    address public pendingGov;\r\n\r\n    /**\r\n     * @notice Approved rebaser for this contract\r\n     */\r\n    address public rebaser;\r\n\r\n    /**\r\n     * @notice Reserve address of PYLON protocol\r\n     */\r\n    address public incentivizer;\r\n\r\n    /**\r\n     * @notice Total supply of PYLONs\r\n     */\r\n    uint256 public totalSupply;\r\n\r\n    /**\r\n     * @notice Internal decimals used to handle scaling factor\r\n     */\r\n    uint256 public constant internalDecimals = 10**24;\r\n\r\n    /**\r\n     * @notice Used for percentage maths\r\n     */\r\n    uint256 public constant BASE = 10**18;\r\n\r\n    /**\r\n     * @notice Scaling factor that adjusts everyone\u0027s balances\r\n     */\r\n    uint256 public pylonsScalingFactor;\r\n\r\n    mapping (address =\u003e uint256) internal _pylonBalances;\r\n\r\n    mapping (address =\u003e mapping (address =\u003e uint256)) internal _allowedFragments;\r\n\r\n    uint256 public initSupply;\r\n\r\n}\r\n"},"SafeMath.sol":{"content":"// SPDX-License-Identifier: MIT\r\n\r\npragma solidity ^0.5.17;\r\n\r\n/**\r\n * @dev Wrappers over Solidity\u0027s arithmetic operations with added overflow\r\n * checks.\r\n *\r\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\r\n * in bugs, because programmers usually assume that an overflow raises an\r\n * error, which is the standard behavior in high level programming languages.\r\n * `SafeMath` restores this intuition by reverting the transaction when an\r\n * operation overflows.\r\n *\r\n * Using this library instead of the unchecked operations eliminates an entire\r\n * class of bugs, so it\u0027s recommended to use it always.\r\n */\r\nlibrary SafeMath {\r\n    /**\r\n     * @dev Returns the addition of two unsigned integers, reverting on\r\n     * overflow.\r\n     *\r\n     * Counterpart to Solidity\u0027s `+` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - Addition cannot overflow.\r\n     */\r\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        uint256 c = a + b;\r\n        require(c \u003e= a, \"SafeMath: addition overflow\");\r\n\r\n        return c;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the subtraction of two unsigned integers, reverting on\r\n     * overflow (when the result is negative).\r\n     *\r\n     * Counterpart to Solidity\u0027s `-` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - Subtraction cannot overflow.\r\n     */\r\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        return sub(a, b, \"SafeMath: subtraction overflow\");\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\r\n     * overflow (when the result is negative).\r\n     *\r\n     * Counterpart to Solidity\u0027s `-` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - Subtraction cannot overflow.\r\n     */\r\n    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n        require(b \u003c= a, errorMessage);\r\n        uint256 c = a - b;\r\n\r\n        return c;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the multiplication of two unsigned integers, reverting on\r\n     * overflow.\r\n     *\r\n     * Counterpart to Solidity\u0027s `*` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - Multiplication cannot overflow.\r\n     */\r\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        // Gas optimization: this is cheaper than requiring \u0027a\u0027 not being zero, but the\r\n        // benefit is lost if \u0027b\u0027 is also tested.\r\n        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\r\n        if (a == 0) {\r\n            return 0;\r\n        }\r\n\r\n        uint256 c = a * b;\r\n        require(c / a == b, \"SafeMath: multiplication overflow\");\r\n\r\n        return c;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the integer division of two unsigned integers. Reverts on\r\n     * division by zero. The result is rounded towards zero.\r\n     *\r\n     * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\r\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n     * uses an invalid opcode to revert (consuming all remaining gas).\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - The divisor cannot be zero.\r\n     */\r\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        return div(a, b, \"SafeMath: division by zero\");\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\r\n     * division by zero. The result is rounded towards zero.\r\n     *\r\n     * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\r\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n     * uses an invalid opcode to revert (consuming all remaining gas).\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - The divisor cannot be zero.\r\n     */\r\n    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n        require(b \u003e 0, errorMessage);\r\n        uint256 c = a / b;\r\n        // assert(a == b * c + a % b); // There is no case in which this doesn\u0027t hold\r\n\r\n        return c;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n     * Reverts when dividing by zero.\r\n     *\r\n     * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\r\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n     * invalid opcode to revert (consuming all remaining gas).\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - The divisor cannot be zero.\r\n     */\r\n    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        return mod(a, b, \"SafeMath: modulo by zero\");\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n     * Reverts with custom message when dividing by zero.\r\n     *\r\n     * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\r\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n     * invalid opcode to revert (consuming all remaining gas).\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - The divisor cannot be zero.\r\n     */\r\n    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n        require(b != 0, errorMessage);\r\n        return a % b;\r\n    }\r\n}\r\n"}}

      File 4 of 4: PYLONDelegate
      {"PYLON.sol":{"content":"pragma solidity 0.5.17;\r\n\r\nimport \"./PYLONTokenInterface.sol\";\r\nimport \"./PYLONGovernance.sol\";\r\n\r\ncontract PYLONToken is PYLONGovernanceToken {\r\n    // Modifiers\r\n    modifier onlyGov() {\r\n        require(msg.sender == gov);\r\n        _;\r\n    }\r\n\r\n    modifier onlyRebaser() {\r\n        require(msg.sender == rebaser);\r\n        _;\r\n    }\r\n\r\n    modifier onlyMinter() {\r\n        require(msg.sender == rebaser || msg.sender == incentivizer || msg.sender == gov, \"not minter\");\r\n        _;\r\n    }\r\n\r\n    modifier validRecipient(address to) {\r\n        require(to != address(0x0));\r\n        require(to != address(this));\r\n        _;\r\n    }\r\n\r\n    function initialize(\r\n        string memory name_,\r\n        string memory symbol_,\r\n        uint8 decimals_\r\n    )\r\n        public\r\n    {\r\n        require(pylonsScalingFactor == 0, \"already initialized\");\r\n        name = name_;\r\n        symbol = symbol_;\r\n        decimals = decimals_;\r\n    }\r\n\r\n\r\n    /**\r\n    * @notice Computes the current max scaling factor\r\n    */\r\n    function maxScalingFactor()\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        return _maxScalingFactor();\r\n    }\r\n\r\n    function _maxScalingFactor()\r\n        internal\r\n        view\r\n        returns (uint256)\r\n    {\r\n        // scaling factor can only go up to 2**256-1 = initSupply * pylonsScalingFactor\r\n        // this is used to check if pylonsScalingFactor will be too high to compute balances when rebasing.\r\n        return uint256(-1) / initSupply;\r\n    }\r\n\r\n    /**\r\n    * @notice Mints new tokens, increasing totalSupply, initSupply, and a users balance.\r\n    * @dev Limited to onlyMinter modifier\r\n    */\r\n    function mint(address to, uint256 amount)\r\n        external\r\n        onlyMinter\r\n        returns (bool)\r\n    {\r\n        _mint(to, amount);\r\n        return true;\r\n    }\r\n\r\n    function _mint(address to, uint256 amount)\r\n        internal\r\n    {\r\n      // increase totalSupply\r\n      totalSupply = totalSupply.add(amount);\r\n\r\n      // get underlying value\r\n      uint256 pylonValue = amount.mul(internalDecimals).div(pylonsScalingFactor);\r\n\r\n      // increase initSupply\r\n      initSupply = initSupply.add(pylonValue);\r\n\r\n      // make sure the mint didnt push maxScalingFactor too low\r\n      require(pylonsScalingFactor \u003c= _maxScalingFactor(), \"max scaling factor too low\");\r\n\r\n      // add balance\r\n      _pylonBalances[to] = _pylonBalances[to].add(pylonValue);\r\n\r\n      // add delegates to the minter\r\n      _moveDelegates(address(0), _delegates[to], pylonValue);\r\n      emit Mint(to, amount);\r\n    }\r\n\r\n    /* - ERC20 functionality - */\r\n\r\n    /**\r\n    * @dev Transfer tokens to a specified address.\r\n    * @param to The address to transfer to.\r\n    * @param value The amount to be transferred.\r\n    * @return True on success, false otherwise.\r\n    */\r\n    function transfer(address to, uint256 value)\r\n        external\r\n        validRecipient(to)\r\n        returns (bool)\r\n    {\r\n        // underlying balance is stored in pylons, so divide by current scaling factor\r\n\r\n        // note, this means as scaling factor grows, dust will be untransferrable.\r\n        // minimum transfer value == pylonsScalingFactor / 1e24;\r\n\r\n        // get amount in underlying\r\n        uint256 pylonValue = value.mul(internalDecimals).div(pylonsScalingFactor);\r\n\r\n        // sub from balance of sender\r\n        _pylonBalances[msg.sender] = _pylonBalances[msg.sender].sub(pylonValue);\r\n\r\n        // add to balance of receiver\r\n        _pylonBalances[to] = _pylonBalances[to].add(pylonValue);\r\n        emit Transfer(msg.sender, to, value);\r\n\r\n        _moveDelegates(_delegates[msg.sender], _delegates[to], pylonValue);\r\n        return true;\r\n    }\r\n\r\n    /**\r\n    * @dev Transfer tokens from one address to another.\r\n    * @param from The address you want to send tokens from.\r\n    * @param to The address you want to transfer to.\r\n    * @param value The amount of tokens to be transferred.\r\n    */\r\n    function transferFrom(address from, address to, uint256 value)\r\n        external\r\n        validRecipient(to)\r\n        returns (bool)\r\n    {\r\n        // decrease allowance\r\n        _allowedFragments[from][msg.sender] = _allowedFragments[from][msg.sender].sub(value);\r\n\r\n        // get value in pylons\r\n        uint256 pylonValue = value.mul(internalDecimals).div(pylonsScalingFactor);\r\n\r\n        // sub from from\r\n        _pylonBalances[from] = _pylonBalances[from].sub(pylonValue);\r\n        _pylonBalances[to] = _pylonBalances[to].add(pylonValue);\r\n        emit Transfer(from, to, value);\r\n\r\n        _moveDelegates(_delegates[from], _delegates[to], pylonValue);\r\n        return true;\r\n    }\r\n\r\n    /**\r\n    * @param who The address to query.\r\n    * @return The balance of the specified address.\r\n    */\r\n    function balanceOf(address who)\r\n      external\r\n      view\r\n      returns (uint256)\r\n    {\r\n      return _pylonBalances[who].mul(pylonsScalingFactor).div(internalDecimals);\r\n    }\r\n\r\n    /** @notice Currently returns the internal storage amount\r\n    * @param who The address to query.\r\n    * @return The underlying balance of the specified address.\r\n    */\r\n    function balanceOfUnderlying(address who)\r\n      external\r\n      view\r\n      returns (uint256)\r\n    {\r\n      return _pylonBalances[who];\r\n    }\r\n\r\n    /**\r\n     * @dev Function to check the amount of tokens that an owner has allowed to a spender.\r\n     * @param owner_ The address which owns the funds.\r\n     * @param spender The address which will spend the funds.\r\n     * @return The number of tokens still available for the spender.\r\n     */\r\n    function allowance(address owner_, address spender)\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        return _allowedFragments[owner_][spender];\r\n    }\r\n\r\n    /**\r\n     * @dev Approve the passed address to spend the specified amount of tokens on behalf of\r\n     * msg.sender. This method is included for ERC20 compatibility.\r\n     * increaseAllowance and decreaseAllowance should be used instead.\r\n     * Changing an allowance with this method brings the risk that someone may transfer both\r\n     * the old and the new allowance - if they are both greater than zero - if a transfer\r\n     * transaction is mined before the later approve() call is mined.\r\n     *\r\n     * @param spender The address which will spend the funds.\r\n     * @param value The amount of tokens to be spent.\r\n     */\r\n    function approve(address spender, uint256 value)\r\n        external\r\n        returns (bool)\r\n    {\r\n        _allowedFragments[msg.sender][spender] = value;\r\n        emit Approval(msg.sender, spender, value);\r\n        return true;\r\n    }\r\n\r\n    /**\r\n     * @dev Increase the amount of tokens that an owner has allowed to a spender.\r\n     * This method should be used instead of approve() to avoid the double approval vulnerability\r\n     * described above.\r\n     * @param spender The address which will spend the funds.\r\n     * @param addedValue The amount of tokens to increase the allowance by.\r\n     */\r\n    function increaseAllowance(address spender, uint256 addedValue)\r\n        external\r\n        returns (bool)\r\n    {\r\n        _allowedFragments[msg.sender][spender] =\r\n            _allowedFragments[msg.sender][spender].add(addedValue);\r\n        emit Approval(msg.sender, spender, _allowedFragments[msg.sender][spender]);\r\n        return true;\r\n    }\r\n\r\n    /**\r\n     * @dev Decrease the amount of tokens that an owner has allowed to a spender.\r\n     *\r\n     * @param spender The address which will spend the funds.\r\n     * @param subtractedValue The amount of tokens to decrease the allowance by.\r\n     */\r\n    function decreaseAllowance(address spender, uint256 subtractedValue)\r\n        external\r\n        returns (bool)\r\n    {\r\n        uint256 oldValue = _allowedFragments[msg.sender][spender];\r\n        if (subtractedValue \u003e= oldValue) {\r\n            _allowedFragments[msg.sender][spender] = 0;\r\n        } else {\r\n            _allowedFragments[msg.sender][spender] = oldValue.sub(subtractedValue);\r\n        }\r\n        emit Approval(msg.sender, spender, _allowedFragments[msg.sender][spender]);\r\n        return true;\r\n    }\r\n\r\n    /* - Governance Functions - */\r\n\r\n    /** @notice sets the rebaser\r\n     * @param rebaser_ The address of the rebaser contract to use for authentication.\r\n     */\r\n    function _setRebaser(address rebaser_)\r\n        external\r\n        onlyGov\r\n    {\r\n        address oldRebaser = rebaser;\r\n        rebaser = rebaser_;\r\n        emit NewRebaser(oldRebaser, rebaser_);\r\n    }\r\n\r\n    /** @notice sets the incentivizer\r\n     * @param incentivizer_ The address of the rebaser contract to use for authentication.\r\n     */\r\n    function _setIncentivizer(address incentivizer_)\r\n        external\r\n        onlyGov\r\n    {\r\n        address oldIncentivizer = incentivizer;\r\n        incentivizer = incentivizer_;\r\n        emit NewIncentivizer(oldIncentivizer, incentivizer_);\r\n    }\r\n\r\n    /** @notice sets the pendingGov\r\n     * @param pendingGov_ The address of the rebaser contract to use for authentication.\r\n     */\r\n    function _setPendingGov(address pendingGov_)\r\n        external\r\n        onlyGov\r\n    {\r\n        address oldPendingGov = pendingGov;\r\n        pendingGov = pendingGov_;\r\n        emit NewPendingGov(oldPendingGov, pendingGov_);\r\n    }\r\n\r\n    /** @notice lets msg.sender accept governance\r\n     *\r\n     */\r\n    function _acceptGov()\r\n        external\r\n    {\r\n        require(msg.sender == pendingGov, \"!pending\");\r\n        address oldGov = gov;\r\n        gov = pendingGov;\r\n        pendingGov = address(0);\r\n        emit NewGov(oldGov, gov);\r\n    }\r\n\r\n    /* - Extras - */\r\n\r\n    /**\r\n    * @notice Initiates a new rebase operation, provided the minimum time period has elapsed.\r\n    *\r\n    * @dev The supply adjustment equals (totalSupply * DeviationFromTargetRate) / rebaseLag\r\n    *      Where DeviationFromTargetRate is (MarketOracleRate - targetRate) / targetRate\r\n    *      and targetRate is CpiOracleRate / baseCpi\r\n    */\r\n    function rebase(\r\n        uint256 epoch,\r\n        uint256 indexDelta,\r\n        bool positive\r\n    )\r\n        external\r\n        onlyRebaser\r\n        returns (uint256)\r\n    {\r\n        if (indexDelta == 0) {\r\n          emit Rebase(epoch, pylonsScalingFactor, pylonsScalingFactor);\r\n          return totalSupply;\r\n        }\r\n\r\n        uint256 prevPYLONsScalingFactor = pylonsScalingFactor;\r\n\r\n        if (!positive) {\r\n           pylonsScalingFactor = pylonsScalingFactor.mul(BASE.sub(indexDelta)).div(BASE);\r\n        } else {\r\n            uint256 newScalingFactor = pylonsScalingFactor.mul(BASE.add(indexDelta)).div(BASE);\r\n            if (newScalingFactor \u003c _maxScalingFactor()) {\r\n                pylonsScalingFactor = newScalingFactor;\r\n            } else {\r\n              pylonsScalingFactor = _maxScalingFactor();\r\n            }\r\n        }\r\n\r\n        totalSupply = initSupply.mul(pylonsScalingFactor);\r\n        emit Rebase(epoch, prevPYLONsScalingFactor, pylonsScalingFactor);\r\n        return totalSupply;\r\n    }\r\n}\r\n\r\ncontract PYLON is PYLONToken {\r\n    /**\r\n     * @notice Initialize the new money market\r\n     * @param name_ ERC-20 name of this token\r\n     * @param symbol_ ERC-20 symbol of this token\r\n     * @param decimals_ ERC-20 decimal precision of this token\r\n     */\r\n    function initialize(\r\n        string memory name_,\r\n        string memory symbol_,\r\n        uint8 decimals_,\r\n        address initial_owner,\r\n        uint256 initSupply_\r\n    )\r\n        public\r\n    {\r\n        require(initSupply_ \u003e 0, \"0 init supply\");\r\n\r\n        super.initialize(name_, symbol_, decimals_);\r\n\r\n        initSupply = initSupply_.mul(10**24/ (BASE));\r\n        totalSupply = initSupply_;\r\n        pylonsScalingFactor = BASE;\r\n        _pylonBalances[initial_owner] = initSupply_.mul(10**24 / (BASE));\r\n\r\n        // owner renounces ownership after deployment as they need to set\r\n        // rebaser and incentivizer\r\n        // gov = gov_;\r\n    }\r\n}\r\n"},"PYLONDelegate.sol":{"content":"pragma solidity 0.5.17;\r\n\r\nimport \"./PYLON.sol\";\r\n\r\ncontract PYLONDelegationStorage {\r\n    /**\r\n     * @notice Implementation address for this contract\r\n     */\r\n    address public implementation;\r\n}\r\n\r\ncontract PYLONDelegatorInterface is PYLONDelegationStorage {\r\n    /**\r\n     * @notice Emitted when implementation is changed\r\n     */\r\n    event NewImplementation(address oldImplementation, address newImplementation);\r\n\r\n    /**\r\n     * @notice Called by the gov to update the implementation of the delegator\r\n     * @param implementation_ The address of the new implementation for delegation\r\n     * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation\r\n     * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation\r\n     */\r\n    function _setImplementation(address implementation_, bool allowResign, bytes memory becomeImplementationData) public;\r\n}\r\n\r\ncontract PYLONDelegateInterface is PYLONDelegationStorage {\r\n    /**\r\n     * @notice Called by the delegator on a delegate to initialize it for duty\r\n     * @dev Should revert if any issues arise which make it unfit for delegation\r\n     * @param data The encoded bytes data for any initialization\r\n     */\r\n    function _becomeImplementation(bytes memory data) public;\r\n\r\n    /**\r\n     * @notice Called by the delegator on a delegate to forfeit its responsibility\r\n     */\r\n    function _resignImplementation() public;\r\n}\r\n\r\n\r\ncontract PYLONDelegate is PYLON, PYLONDelegateInterface {\r\n    /**\r\n     * @notice Construct an empty delegate\r\n     */\r\n    constructor() public {}\r\n\r\n    /**\r\n     * @notice Called by the delegator on a delegate to initialize it for duty\r\n     * @param data The encoded bytes data for any initialization\r\n     */\r\n    function _becomeImplementation(bytes memory data) public {\r\n        // Shh -- currently unused\r\n        data;\r\n\r\n        // Shh -- we don\u0027t ever want this hook to be marked pure\r\n        if (false) {\r\n            implementation = address(0);\r\n        }\r\n\r\n        require(msg.sender == gov, \"only the gov may call _becomeImplementation\");\r\n    }\r\n\r\n    /**\r\n     * @notice Called by the delegator on a delegate to forfeit its responsibility\r\n     */\r\n    function _resignImplementation() public {\r\n        // Shh -- we don\u0027t ever want this hook to be marked pure\r\n        if (false) {\r\n            implementation = address(0);\r\n        }\r\n\r\n        require(msg.sender == gov, \"only the gov may call _resignImplementation\");\r\n    }\r\n}\r\n"},"PYLONGovernance.sol":{"content":"pragma solidity 0.5.17;\r\npragma experimental ABIEncoderV2;\r\n\r\nimport \"./PYLONGovernanceStorage.sol\";\r\nimport \"./PYLONTokenInterface.sol\";\r\n\r\ncontract PYLONGovernanceToken is PYLONTokenInterface {\r\n\r\n      /// @notice An event thats emitted when an account changes its delegate\r\n    event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\r\n\r\n    /// @notice An event thats emitted when a delegate account\u0027s vote balance changes\r\n    event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);\r\n\r\n    /**\r\n     * @notice Delegate votes from `msg.sender` to `delegatee`\r\n     * @param delegator The address to get delegatee for\r\n     */\r\n    function delegates(address delegator)\r\n        external\r\n        view\r\n        returns (address)\r\n    {\r\n        return _delegates[delegator];\r\n    }\r\n\r\n   /**\r\n    * @notice Delegate votes from `msg.sender` to `delegatee`\r\n    * @param delegatee The address to delegate votes to\r\n    */\r\n    function delegate(address delegatee) external {\r\n        return _delegate(msg.sender, delegatee);\r\n    }\r\n\r\n    /**\r\n     * @notice Delegates votes from signatory to `delegatee`\r\n     * @param delegatee The address to delegate votes to\r\n     * @param nonce The contract state required to match the signature\r\n     * @param expiry The time at which to expire the signature\r\n     * @param v The recovery byte of the signature\r\n     * @param r Half of the ECDSA signature pair\r\n     * @param s Half of the ECDSA signature pair\r\n     */\r\n    function delegateBySig(\r\n        address delegatee,\r\n        uint nonce,\r\n        uint expiry,\r\n        uint8 v,\r\n        bytes32 r,\r\n        bytes32 s\r\n    )\r\n        external\r\n    {\r\n        bytes32 domainSeparator = keccak256(\r\n            abi.encode(\r\n                DOMAIN_TYPEHASH,\r\n                keccak256(bytes(name)),\r\n                getChainId(),\r\n                address(this)\r\n            )\r\n        );\r\n\r\n        bytes32 structHash = keccak256(\r\n            abi.encode(\r\n                DELEGATION_TYPEHASH,\r\n                delegatee,\r\n                nonce,\r\n                expiry\r\n            )\r\n        );\r\n\r\n        bytes32 digest = keccak256(\r\n            abi.encodePacked(\r\n                \"\\x19\\x01\",\r\n                domainSeparator,\r\n                structHash\r\n            )\r\n        );\r\n\r\n        address signatory = ecrecover(digest, v, r, s);\r\n        require(signatory != address(0), \"PYLON::delegateBySig: invalid signature\");\r\n        require(nonce == nonces[signatory]++, \"PYLON::delegateBySig: invalid nonce\");\r\n        require(now \u003c= expiry, \"PYLON::delegateBySig: signature expired\");\r\n        return _delegate(signatory, delegatee);\r\n    }\r\n\r\n    /**\r\n     * @notice Gets the current votes balance for `account`\r\n     * @param account The address to get votes balance\r\n     * @return The number of current votes for `account`\r\n     */\r\n    function getCurrentVotes(address account)\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        uint32 nCheckpoints = numCheckpoints[account];\r\n        return nCheckpoints \u003e 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;\r\n    }\r\n\r\n    /**\r\n     * @notice Determine the prior number of votes for an account as of a block number\r\n     * @dev Block number must be a finalized block or else this function will revert to prevent misinformation.\r\n     * @param account The address of the account to check\r\n     * @param blockNumber The block number to get the vote balance at\r\n     * @return The number of votes the account had as of the given block\r\n     */\r\n    function getPriorVotes(address account, uint blockNumber)\r\n        external\r\n        view\r\n        returns (uint256)\r\n    {\r\n        require(blockNumber \u003c block.number, \"PYLON::getPriorVotes: not yet determined\");\r\n\r\n        uint32 nCheckpoints = numCheckpoints[account];\r\n        if (nCheckpoints == 0) {\r\n            return 0;\r\n        }\r\n\r\n        // First check most recent balance\r\n        if (checkpoints[account][nCheckpoints - 1].fromBlock \u003c= blockNumber) {\r\n            return checkpoints[account][nCheckpoints - 1].votes;\r\n        }\r\n\r\n        // Next check implicit zero balance\r\n        if (checkpoints[account][0].fromBlock \u003e blockNumber) {\r\n            return 0;\r\n        }\r\n\r\n        uint32 lower = 0;\r\n        uint32 upper = nCheckpoints - 1;\r\n        while (upper \u003e lower) {\r\n            uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow\r\n            Checkpoint memory cp = checkpoints[account][center];\r\n            if (cp.fromBlock == blockNumber) {\r\n                return cp.votes;\r\n            } else if (cp.fromBlock \u003c blockNumber) {\r\n                lower = center;\r\n            } else {\r\n                upper = center - 1;\r\n            }\r\n        }\r\n        return checkpoints[account][lower].votes;\r\n    }\r\n\r\n    function _delegate(address delegator, address delegatee)\r\n        internal\r\n    {\r\n        address currentDelegate = _delegates[delegator];\r\n        uint256 delegatorBalance = _pylonBalances[delegator]; // balance of underlying PYLONs (not scaled);\r\n        _delegates[delegator] = delegatee;\r\n\r\n        emit DelegateChanged(delegator, currentDelegate, delegatee);\r\n\r\n        _moveDelegates(currentDelegate, delegatee, delegatorBalance);\r\n    }\r\n\r\n    function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal {\r\n        if (srcRep != dstRep \u0026\u0026 amount \u003e 0) {\r\n            if (srcRep != address(0)) {\r\n                // decrease old representative\r\n                uint32 srcRepNum = numCheckpoints[srcRep];\r\n                uint256 srcRepOld = srcRepNum \u003e 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;\r\n                uint256 srcRepNew = srcRepOld.sub(amount);\r\n                _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);\r\n            }\r\n\r\n            if (dstRep != address(0)) {\r\n                // increase new representative\r\n                uint32 dstRepNum = numCheckpoints[dstRep];\r\n                uint256 dstRepOld = dstRepNum \u003e 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;\r\n                uint256 dstRepNew = dstRepOld.add(amount);\r\n                _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);\r\n            }\r\n        }\r\n    }\r\n\r\n    function _writeCheckpoint(\r\n        address delegatee,\r\n        uint32 nCheckpoints,\r\n        uint256 oldVotes,\r\n        uint256 newVotes\r\n    )\r\n        internal\r\n    {\r\n        uint32 blockNumber = safe32(block.number, \"PYLON::_writeCheckpoint: block number exceeds 32 bits\");\r\n\r\n        if (nCheckpoints \u003e 0 \u0026\u0026 checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {\r\n            checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;\r\n        } else {\r\n            checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);\r\n            numCheckpoints[delegatee] = nCheckpoints + 1;\r\n        }\r\n\r\n        emit DelegateVotesChanged(delegatee, oldVotes, newVotes);\r\n    }\r\n\r\n    function safe32(uint n, string memory errorMessage) internal pure returns (uint32) {\r\n        require(n \u003c 2**32, errorMessage);\r\n        return uint32(n);\r\n    }\r\n\r\n    function getChainId() internal pure returns (uint) {\r\n        uint256 chainId;\r\n        assembly { chainId := chainid() }\r\n        return chainId;\r\n    }\r\n}\r\n"},"PYLONGovernanceStorage.sol":{"content":"pragma solidity 0.5.17;\r\npragma experimental ABIEncoderV2;\r\n\r\ncontract PYLONGovernanceStorage {\r\n    /// @notice A record of each accounts delegate\r\n    mapping (address =\u003e address) internal _delegates;\r\n\r\n    /// @notice A checkpoint for marking number of votes from a given block\r\n    struct Checkpoint {\r\n        uint32 fromBlock;\r\n        uint256 votes;\r\n    }\r\n\r\n    /// @notice A record of votes checkpoints for each account, by index\r\n    mapping (address =\u003e mapping (uint32 =\u003e Checkpoint)) public checkpoints;\r\n\r\n    /// @notice The number of checkpoints for each account\r\n    mapping (address =\u003e uint32) public numCheckpoints;\r\n\r\n    /// @notice The EIP-712 typehash for the contract\u0027s domain\r\n    bytes32 public constant DOMAIN_TYPEHASH = keccak256(\"EIP712Domain(string name,uint256 chainId,address verifyingContract)\");\r\n\r\n    /// @notice The EIP-712 typehash for the delegation struct used by the contract\r\n    bytes32 public constant DELEGATION_TYPEHASH = keccak256(\"Delegation(address delegatee,uint256 nonce,uint256 expiry)\");\r\n\r\n    /// @notice A record of states for signing / validating signatures\r\n    mapping (address =\u003e uint) public nonces;\r\n}\r\n"},"PYLONTokenInterface.sol":{"content":"pragma solidity 0.5.17;\r\n\r\nimport \"./PYLONTokenStorage.sol\";\r\nimport \"./PYLONGovernanceStorage.sol\";\r\n\r\ncontract PYLONTokenInterface is PYLONTokenStorage, PYLONGovernanceStorage {\r\n\r\n    /// @notice An event thats emitted when an account changes its delegate\r\n    event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\r\n\r\n    /// @notice An event thats emitted when a delegate account\u0027s vote balance changes\r\n    event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance);\r\n\r\n    /**\r\n     * @notice Event emitted when tokens are rebased\r\n     */\r\n    event Rebase(uint256 epoch, uint256 prevPYLONsScalingFactor, uint256 newPYLONsScalingFactor);\r\n\r\n    /*** Gov Events ***/\r\n\r\n    /**\r\n     * @notice Event emitted when pendingGov is changed\r\n     */\r\n    event NewPendingGov(address oldPendingGov, address newPendingGov);\r\n\r\n    /**\r\n     * @notice Event emitted when gov is changed\r\n     */\r\n    event NewGov(address oldGov, address newGov);\r\n\r\n    /**\r\n     * @notice Sets the rebaser contract\r\n     */\r\n    event NewRebaser(address oldRebaser, address newRebaser);\r\n\r\n    /**\r\n     * @notice Sets the incentivizer contract\r\n     */\r\n    event NewIncentivizer(address oldIncentivizer, address newIncentivizer);\r\n\r\n    /* - ERC20 Events - */\r\n\r\n    /**\r\n     * @notice EIP20 Transfer event\r\n     */\r\n    event Transfer(address indexed from, address indexed to, uint amount);\r\n\r\n    /**\r\n     * @notice EIP20 Approval event\r\n     */\r\n    event Approval(address indexed owner, address indexed spender, uint amount);\r\n\r\n    /* - Extra Events - */\r\n    /**\r\n     * @notice Tokens minted event\r\n     */\r\n    event Mint(address to, uint256 amount);\r\n\r\n    // Public functions\r\n    function transfer(address to, uint256 value) external returns(bool);\r\n    function transferFrom(address from, address to, uint256 value) external returns(bool);\r\n    function balanceOf(address who) external view returns(uint256);\r\n    function balanceOfUnderlying(address who) external view returns(uint256);\r\n    function allowance(address owner_, address spender) external view returns(uint256);\r\n    function approve(address spender, uint256 value) external returns (bool);\r\n    function increaseAllowance(address spender, uint256 addedValue) external returns (bool);\r\n    function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);\r\n    function maxScalingFactor() external view returns (uint256);\r\n\r\n    /* - Governance Functions - */\r\n    function getPriorVotes(address account, uint blockNumber) external view returns (uint256);\r\n    function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) external;\r\n    function delegate(address delegatee) external;\r\n    function delegates(address delegator) external view returns (address);\r\n    function getCurrentVotes(address account) external view returns (uint256);\r\n\r\n    /* - Permissioned/Governance functions - */\r\n    function mint(address to, uint256 amount) external returns (bool);\r\n    function rebase(uint256 epoch, uint256 indexDelta, bool positive) external returns (uint256);\r\n    function _setRebaser(address rebaser_) external;\r\n    function _setIncentivizer(address incentivizer_) external;\r\n    function _setPendingGov(address pendingGov_) external;\r\n    function _acceptGov() external;\r\n}\r\n"},"PYLONTokenStorage.sol":{"content":"pragma solidity 0.5.17;\r\n\r\nimport \"./SafeMath.sol\";\r\n\r\n// Storage for a PYLON token\r\ncontract PYLONTokenStorage {\r\n\r\n    using SafeMath for uint256;\r\n\r\n    /**\r\n     * @dev Guard variable for re-entrancy checks. Not currently used\r\n     */\r\n    bool internal _notEntered;\r\n\r\n    /**\r\n     * @notice EIP-20 token name for this token\r\n     */\r\n    string public name;\r\n\r\n    /**\r\n     * @notice EIP-20 token symbol for this token\r\n     */\r\n    string public symbol;\r\n\r\n    /**\r\n     * @notice EIP-20 token decimals for this token\r\n     */\r\n    uint8 public decimals;\r\n\r\n    /**\r\n     * @notice Governor for this contract\r\n     */\r\n    address public gov;\r\n\r\n    /**\r\n     * @notice Pending governance for this contract\r\n     */\r\n    address public pendingGov;\r\n\r\n    /**\r\n     * @notice Approved rebaser for this contract\r\n     */\r\n    address public rebaser;\r\n\r\n    /**\r\n     * @notice Reserve address of PYLON protocol\r\n     */\r\n    address public incentivizer;\r\n\r\n    /**\r\n     * @notice Total supply of PYLONs\r\n     */\r\n    uint256 public totalSupply;\r\n\r\n    /**\r\n     * @notice Internal decimals used to handle scaling factor\r\n     */\r\n    uint256 public constant internalDecimals = 10**24;\r\n\r\n    /**\r\n     * @notice Used for percentage maths\r\n     */\r\n    uint256 public constant BASE = 10**18;\r\n\r\n    /**\r\n     * @notice Scaling factor that adjusts everyone\u0027s balances\r\n     */\r\n    uint256 public pylonsScalingFactor;\r\n\r\n    mapping (address =\u003e uint256) internal _pylonBalances;\r\n\r\n    mapping (address =\u003e mapping (address =\u003e uint256)) internal _allowedFragments;\r\n\r\n    uint256 public initSupply;\r\n\r\n}\r\n"},"SafeMath.sol":{"content":"// SPDX-License-Identifier: MIT\r\n\r\npragma solidity ^0.5.17;\r\n\r\n/**\r\n * @dev Wrappers over Solidity\u0027s arithmetic operations with added overflow\r\n * checks.\r\n *\r\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\r\n * in bugs, because programmers usually assume that an overflow raises an\r\n * error, which is the standard behavior in high level programming languages.\r\n * `SafeMath` restores this intuition by reverting the transaction when an\r\n * operation overflows.\r\n *\r\n * Using this library instead of the unchecked operations eliminates an entire\r\n * class of bugs, so it\u0027s recommended to use it always.\r\n */\r\nlibrary SafeMath {\r\n    /**\r\n     * @dev Returns the addition of two unsigned integers, reverting on\r\n     * overflow.\r\n     *\r\n     * Counterpart to Solidity\u0027s `+` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - Addition cannot overflow.\r\n     */\r\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        uint256 c = a + b;\r\n        require(c \u003e= a, \"SafeMath: addition overflow\");\r\n\r\n        return c;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the subtraction of two unsigned integers, reverting on\r\n     * overflow (when the result is negative).\r\n     *\r\n     * Counterpart to Solidity\u0027s `-` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - Subtraction cannot overflow.\r\n     */\r\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        return sub(a, b, \"SafeMath: subtraction overflow\");\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\r\n     * overflow (when the result is negative).\r\n     *\r\n     * Counterpart to Solidity\u0027s `-` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - Subtraction cannot overflow.\r\n     */\r\n    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n        require(b \u003c= a, errorMessage);\r\n        uint256 c = a - b;\r\n\r\n        return c;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the multiplication of two unsigned integers, reverting on\r\n     * overflow.\r\n     *\r\n     * Counterpart to Solidity\u0027s `*` operator.\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - Multiplication cannot overflow.\r\n     */\r\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        // Gas optimization: this is cheaper than requiring \u0027a\u0027 not being zero, but the\r\n        // benefit is lost if \u0027b\u0027 is also tested.\r\n        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\r\n        if (a == 0) {\r\n            return 0;\r\n        }\r\n\r\n        uint256 c = a * b;\r\n        require(c / a == b, \"SafeMath: multiplication overflow\");\r\n\r\n        return c;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the integer division of two unsigned integers. Reverts on\r\n     * division by zero. The result is rounded towards zero.\r\n     *\r\n     * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\r\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n     * uses an invalid opcode to revert (consuming all remaining gas).\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - The divisor cannot be zero.\r\n     */\r\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        return div(a, b, \"SafeMath: division by zero\");\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\r\n     * division by zero. The result is rounded towards zero.\r\n     *\r\n     * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\r\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n     * uses an invalid opcode to revert (consuming all remaining gas).\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - The divisor cannot be zero.\r\n     */\r\n    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n        require(b \u003e 0, errorMessage);\r\n        uint256 c = a / b;\r\n        // assert(a == b * c + a % b); // There is no case in which this doesn\u0027t hold\r\n\r\n        return c;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n     * Reverts when dividing by zero.\r\n     *\r\n     * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\r\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n     * invalid opcode to revert (consuming all remaining gas).\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - The divisor cannot be zero.\r\n     */\r\n    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\r\n        return mod(a, b, \"SafeMath: modulo by zero\");\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n     * Reverts with custom message when dividing by zero.\r\n     *\r\n     * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\r\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n     * invalid opcode to revert (consuming all remaining gas).\r\n     *\r\n     * Requirements:\r\n     *\r\n     * - The divisor cannot be zero.\r\n     */\r\n    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\r\n        require(b != 0, errorMessage);\r\n        return a % b;\r\n    }\r\n}\r\n"}}