Contract
0xFDF50FEa3527FaD31Fa840B748FD3694aE8a47cc
1
Contract Overview
Balance:
0 AVAX
AVAX Value:
$0.00
My Name Tag:
Not Available, login to update
Txn Hash | Method |
Block
|
From
|
To
|
Value | [Txn Fee] | |||
---|---|---|---|---|---|---|---|---|---|
0xf3413b9c6899becd607b1bbfe8d041f999d6b973d586c24a5d1f42d57aca64e8 | Get Account Limi... | 14518059 | 6 days 15 hrs ago | 0x721d2a396d506e065e55527b6b14212f92c8a54e | IN | 0xfdf50fea3527fad31fa840b748fd3694ae8a47cc | 0 AVAX | 0.003347230427 | |
0x44573e9ef6e3d2e73580c61ed0dfd12c70e0c6f16035a0a3d54a65c19a283655 | Get Account Limi... | 11008657 | 89 days 11 hrs ago | 0x2e601885896103318269ca45431b943a6c8ae39a | IN | 0xfdf50fea3527fad31fa840b748fd3694ae8a47cc | 0 AVAX | 0.020445007315 | |
0x4fb78fd9ffe37a1d5d4e7671d9fa3845fa167f7df962af9a8d2820d57fe43383 | 0x60806040 | 5695702 | 213 days 2 hrs ago | 0x5d3e4c0fe11e0ae4c32f0ff74b4544c49538ac61 | IN | Create: JoeLens | 0 AVAX | 0.581781375 |
[ Download CSV Export ]
Contract Name:
JoeLens
Compiler Version
v0.5.16+commit.9c3226ce
Contract Source Code (Solidity)
/** *Submitted for verification at snowtrace.io on 2021-11-06 */ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.5.16; contract JoetrollerErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED, JOETROLLER_MISMATCH, INSUFFICIENT_SHORTFALL, INSUFFICIENT_LIQUIDITY, INVALID_CLOSE_FACTOR, INVALID_COLLATERAL_FACTOR, INVALID_LIQUIDATION_INCENTIVE, MARKET_NOT_ENTERED, // no longer possible MARKET_NOT_LISTED, MARKET_ALREADY_LISTED, MATH_ERROR, NONZERO_BORROW_BALANCE, PRICE_ERROR, REJECTION, SNAPSHOT_ERROR, TOO_MANY_ASSETS, TOO_MUCH_REPAY } enum FailureInfo { ACCEPT_ADMIN_PENDING_ADMIN_CHECK, ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK, EXIT_MARKET_BALANCE_OWED, EXIT_MARKET_REJECTION, SET_CLOSE_FACTOR_OWNER_CHECK, SET_CLOSE_FACTOR_VALIDATION, SET_COLLATERAL_FACTOR_OWNER_CHECK, SET_COLLATERAL_FACTOR_NO_EXISTS, SET_COLLATERAL_FACTOR_VALIDATION, SET_COLLATERAL_FACTOR_WITHOUT_PRICE, SET_IMPLEMENTATION_OWNER_CHECK, SET_LIQUIDATION_INCENTIVE_OWNER_CHECK, SET_LIQUIDATION_INCENTIVE_VALIDATION, SET_MAX_ASSETS_OWNER_CHECK, SET_PENDING_ADMIN_OWNER_CHECK, SET_PENDING_IMPLEMENTATION_OWNER_CHECK, SET_PRICE_ORACLE_OWNER_CHECK, SUPPORT_MARKET_EXISTS, SUPPORT_MARKET_OWNER_CHECK, SET_PAUSE_GUARDIAN_OWNER_CHECK } /** * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary * contract-specific code that enables us to report opaque error codes from upgradeable contracts. **/ event Failure(uint256 error, uint256 info, uint256 detail); /** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */ function fail(Error err, FailureInfo info) internal returns (uint256) { emit Failure(uint256(err), uint256(info), 0); return uint256(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque( Error err, FailureInfo info, uint256 opaqueError ) internal returns (uint256) { emit Failure(uint256(err), uint256(info), opaqueError); return uint256(err); } } contract TokenErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED, BAD_INPUT, JOETROLLER_REJECTION, JOETROLLER_CALCULATION_ERROR, INTEREST_RATE_MODEL_ERROR, INVALID_ACCOUNT_PAIR, INVALID_CLOSE_AMOUNT_REQUESTED, INVALID_COLLATERAL_FACTOR, MATH_ERROR, MARKET_NOT_FRESH, MARKET_NOT_LISTED, TOKEN_INSUFFICIENT_ALLOWANCE, TOKEN_INSUFFICIENT_BALANCE, TOKEN_INSUFFICIENT_CASH, TOKEN_TRANSFER_IN_FAILED, TOKEN_TRANSFER_OUT_FAILED } /* * Note: FailureInfo (but not Error) is kept in alphabetical order * This is because FailureInfo grows significantly faster, and * the order of Error has some meaning, while the order of FailureInfo * is entirely arbitrary. */ enum FailureInfo { ACCEPT_ADMIN_PENDING_ADMIN_CHECK, ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED, BORROW_ACCRUE_INTEREST_FAILED, BORROW_CASH_NOT_AVAILABLE, BORROW_FRESHNESS_CHECK, BORROW_MARKET_NOT_LISTED, BORROW_JOETROLLER_REJECTION, LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED, LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED, LIQUIDATE_COLLATERAL_FRESHNESS_CHECK, LIQUIDATE_JOETROLLER_REJECTION, LIQUIDATE_JOETROLLER_CALCULATE_AMOUNT_SEIZE_FAILED, LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX, LIQUIDATE_CLOSE_AMOUNT_IS_ZERO, LIQUIDATE_FRESHNESS_CHECK, LIQUIDATE_LIQUIDATOR_IS_BORROWER, LIQUIDATE_REPAY_BORROW_FRESH_FAILED, LIQUIDATE_SEIZE_JOETROLLER_REJECTION, LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER, LIQUIDATE_SEIZE_TOO_MUCH, MINT_ACCRUE_INTEREST_FAILED, MINT_JOETROLLER_REJECTION, MINT_FRESHNESS_CHECK, MINT_TRANSFER_IN_FAILED, MINT_TRANSFER_IN_NOT_POSSIBLE, REDEEM_ACCRUE_INTEREST_FAILED, REDEEM_JOETROLLER_REJECTION, REDEEM_FRESHNESS_CHECK, REDEEM_TRANSFER_OUT_NOT_POSSIBLE, REDUCE_RESERVES_ACCRUE_INTEREST_FAILED, REDUCE_RESERVES_ADMIN_CHECK, REDUCE_RESERVES_CASH_NOT_AVAILABLE, REDUCE_RESERVES_FRESH_CHECK, REDUCE_RESERVES_VALIDATION, REPAY_BEHALF_ACCRUE_INTEREST_FAILED, REPAY_BORROW_ACCRUE_INTEREST_FAILED, REPAY_BORROW_JOETROLLER_REJECTION, REPAY_BORROW_FRESHNESS_CHECK, REPAY_BORROW_TRANSFER_IN_NOT_POSSIBLE, SET_COLLATERAL_FACTOR_OWNER_CHECK, SET_COLLATERAL_FACTOR_VALIDATION, SET_JOETROLLER_OWNER_CHECK, SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED, SET_INTEREST_RATE_MODEL_FRESH_CHECK, SET_INTEREST_RATE_MODEL_OWNER_CHECK, SET_MAX_ASSETS_OWNER_CHECK, SET_ORACLE_MARKET_NOT_LISTED, SET_PENDING_ADMIN_OWNER_CHECK, SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED, SET_RESERVE_FACTOR_ADMIN_CHECK, SET_RESERVE_FACTOR_FRESH_CHECK, SET_RESERVE_FACTOR_BOUNDS_CHECK, TRANSFER_JOETROLLER_REJECTION, TRANSFER_NOT_ALLOWED, ADD_RESERVES_ACCRUE_INTEREST_FAILED, ADD_RESERVES_FRESH_CHECK, ADD_RESERVES_TRANSFER_IN_NOT_POSSIBLE } /** * @dev `error` corresponds to enum Error; `info` corresponds to enum FailureInfo, and `detail` is an arbitrary * contract-specific code that enables us to report opaque error codes from upgradeable contracts. **/ event Failure(uint256 error, uint256 info, uint256 detail); /** * @dev use this when reporting a known error from the money market or a non-upgradeable collaborator */ function fail(Error err, FailureInfo info) internal returns (uint256) { emit Failure(uint256(err), uint256(info), 0); return uint256(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque( Error err, FailureInfo info, uint256 opaqueError ) internal returns (uint256) { emit Failure(uint256(err), uint256(info), opaqueError); return uint256(err); } } /** * @title ERC 20 Token Standard Interface * https://eips.ethereum.org/EIPS/eip-20 */ interface EIP20Interface { function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); /** * @notice Get the total number of tokens in circulation * @return The supply of tokens */ function totalSupply() external view returns (uint256); /** * @notice Gets the balance of the specified address * @param owner The address from which the balance will be retrieved * @return The balance */ function balanceOf(address owner) external view returns (uint256 balance); /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint256 amount) external returns (bool success); /** * @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 amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferFrom( address src, address dst, uint256 amount ) external returns (bool success); /** * @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 amount The number of tokens that are approved (-1 means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool success); /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent (-1 means infinite) */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); } /** * @title Compound's InterestRateModel Interface * @author Compound */ contract InterestRateModel { /// @notice Indicator that this is an InterestRateModel contract (for inspection) bool public constant isInterestRateModel = true; /** * @notice Calculates the current borrow interest rate per sec * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amnount of reserves the market has * @return The borrow rate per sec (as a percentage, and scaled by 1e18) */ function getBorrowRate( uint256 cash, uint256 borrows, uint256 reserves ) external view returns (uint256); /** * @notice Calculates the current supply interest rate per sec * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amnount of reserves the market has * @param reserveFactorMantissa The current reserve factor the market has * @return The supply rate per sec (as a percentage, and scaled by 1e18) */ function getSupplyRate( uint256 cash, uint256 borrows, uint256 reserves, uint256 reserveFactorMantissa ) external view returns (uint256); } interface ERC3156FlashBorrowerInterface { /** * @dev Receive a flash loan. * @param initiator The initiator of the loan. * @param token The loan currency. * @param amount The amount of tokens lent. * @param fee The additional amount of tokens to repay. * @param data Arbitrary data structure, intended to contain user-defined parameters. * @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan" */ function onFlashLoan( address initiator, address token, uint256 amount, uint256 fee, bytes calldata data ) external returns (bytes32); } /** * @title Careful Math * @author Compound * @notice Derived from OpenZeppelin's SafeMath library * https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol */ contract CarefulMath { /** * @dev Possible error codes that we can return */ enum MathError { NO_ERROR, DIVISION_BY_ZERO, INTEGER_OVERFLOW, INTEGER_UNDERFLOW } /** * @dev Multiplies two numbers, returns an error on overflow. */ function mulUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) { if (a == 0) { return (MathError.NO_ERROR, 0); } uint256 c = a * b; if (c / a != b) { return (MathError.INTEGER_OVERFLOW, 0); } else { return (MathError.NO_ERROR, c); } } /** * @dev Integer division of two numbers, truncating the quotient. */ function divUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) { if (b == 0) { return (MathError.DIVISION_BY_ZERO, 0); } return (MathError.NO_ERROR, a / b); } /** * @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend). */ function subUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) { if (b <= a) { return (MathError.NO_ERROR, a - b); } else { return (MathError.INTEGER_UNDERFLOW, 0); } } /** * @dev Adds two numbers, returns an error on overflow. */ function addUInt(uint256 a, uint256 b) internal pure returns (MathError, uint256) { uint256 c = a + b; if (c >= a) { return (MathError.NO_ERROR, c); } else { return (MathError.INTEGER_OVERFLOW, 0); } } /** * @dev add a and b and then subtract c */ function addThenSubUInt( uint256 a, uint256 b, uint256 c ) internal pure returns (MathError, uint256) { (MathError err0, uint256 sum) = addUInt(a, b); if (err0 != MathError.NO_ERROR) { return (err0, 0); } return subUInt(sum, c); } } /** * @title Exponential module for storing fixed-precision decimals * @author Compound * @notice Exp is a struct which stores decimals with a fixed precision of 18 decimal places. * Thus, if we wanted to store the 5.1, mantissa would store 5.1e18. That is: * `Exp({mantissa: 5100000000000000000})`. */ contract Exponential is CarefulMath { uint256 constant expScale = 1e18; uint256 constant doubleScale = 1e36; uint256 constant halfExpScale = expScale / 2; uint256 constant mantissaOne = expScale; struct Exp { uint256 mantissa; } struct Double { uint256 mantissa; } /** * @dev Creates an exponential from numerator and denominator values. * Note: Returns an error if (`num` * 10e18) > MAX_INT, * or if `denom` is zero. */ function getExp(uint256 num, uint256 denom) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 scaledNumerator) = mulUInt(num, expScale); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } (MathError err1, uint256 rational) = divUInt(scaledNumerator, denom); if (err1 != MathError.NO_ERROR) { return (err1, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: rational})); } /** * @dev Adds two exponentials, returning a new exponential. */ function addExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) { (MathError error, uint256 result) = addUInt(a.mantissa, b.mantissa); return (error, Exp({mantissa: result})); } /** * @dev Subtracts two exponentials, returning a new exponential. */ function subExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) { (MathError error, uint256 result) = subUInt(a.mantissa, b.mantissa); return (error, Exp({mantissa: result})); } /** * @dev Multiply an Exp by a scalar, returning a new Exp. */ function mulScalar(Exp memory a, uint256 scalar) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 scaledMantissa) = mulUInt(a.mantissa, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: scaledMantissa})); } /** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */ function mulScalarTruncate(Exp memory a, uint256 scalar) internal pure returns (MathError, uint256) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(product)); } /** * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer. */ function mulScalarTruncateAddUInt( Exp memory a, uint256 scalar, uint256 addend ) internal pure returns (MathError, uint256) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return addUInt(truncate(product), addend); } /** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */ function mul_ScalarTruncate(Exp memory a, uint256 scalar) internal pure returns (uint256) { Exp memory product = mul_(a, scalar); return truncate(product); } /** * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer. */ function mul_ScalarTruncateAddUInt( Exp memory a, uint256 scalar, uint256 addend ) internal pure returns (uint256) { Exp memory product = mul_(a, scalar); return add_(truncate(product), addend); } /** * @dev Divide an Exp by a scalar, returning a new Exp. */ function divScalar(Exp memory a, uint256 scalar) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 descaledMantissa) = divUInt(a.mantissa, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return (MathError.NO_ERROR, Exp({mantissa: descaledMantissa})); } /** * @dev Divide a scalar by an Exp, returning a new Exp. */ function divScalarByExp(uint256 scalar, Exp memory divisor) internal pure returns (MathError, Exp memory) { /* We are doing this as: getExp(mulUInt(expScale, scalar), divisor.mantissa) How it works: Exp = a / b; Scalar = s; `s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale` */ (MathError err0, uint256 numerator) = mulUInt(expScale, scalar); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } return getExp(numerator, divisor.mantissa); } /** * @dev Divide a scalar by an Exp, then truncate to return an unsigned integer. */ function divScalarByExpTruncate(uint256 scalar, Exp memory divisor) internal pure returns (MathError, uint256) { (MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(fraction)); } /** * @dev Divide a scalar by an Exp, returning a new Exp. */ function div_ScalarByExp(uint256 scalar, Exp memory divisor) internal pure returns (Exp memory) { /* We are doing this as: getExp(mulUInt(expScale, scalar), divisor.mantissa) How it works: Exp = a / b; Scalar = s; `s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale` */ uint256 numerator = mul_(expScale, scalar); return Exp({mantissa: div_(numerator, divisor)}); } /** * @dev Divide a scalar by an Exp, then truncate to return an unsigned integer. */ function div_ScalarByExpTruncate(uint256 scalar, Exp memory divisor) internal pure returns (uint256) { Exp memory fraction = div_ScalarByExp(scalar, divisor); return truncate(fraction); } /** * @dev Multiplies two exponentials, returning a new exponential. */ function mulExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) { (MathError err0, uint256 doubleScaledProduct) = mulUInt(a.mantissa, b.mantissa); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } // We add half the scale before dividing so that we get rounding instead of truncation. // See "Listing 6" and text above it at https://accu.org/index.php/journals/1717 // Without this change, a result like 6.6...e-19 will be truncated to 0 instead of being rounded to 1e-18. (MathError err1, uint256 doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct); if (err1 != MathError.NO_ERROR) { return (err1, Exp({mantissa: 0})); } (MathError err2, uint256 product) = divUInt(doubleScaledProductWithHalfScale, expScale); // The only error `div` can return is MathError.DIVISION_BY_ZERO but we control `expScale` and it is not zero. assert(err2 == MathError.NO_ERROR); return (MathError.NO_ERROR, Exp({mantissa: product})); } /** * @dev Multiplies two exponentials given their mantissas, returning a new exponential. */ function mulExp(uint256 a, uint256 b) internal pure returns (MathError, Exp memory) { return mulExp(Exp({mantissa: a}), Exp({mantissa: b})); } /** * @dev Multiplies three exponentials, returning a new exponential. */ function mulExp3( Exp memory a, Exp memory b, Exp memory c ) internal pure returns (MathError, Exp memory) { (MathError err, Exp memory ab) = mulExp(a, b); if (err != MathError.NO_ERROR) { return (err, ab); } return mulExp(ab, c); } /** * @dev Divides two exponentials, returning a new exponential. * (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b, * which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa) */ function divExp(Exp memory a, Exp memory b) internal pure returns (MathError, Exp memory) { return getExp(a.mantissa, b.mantissa); } /** * @dev Truncates the given exp to a whole number value. * For example, truncate(Exp{mantissa: 15 * expScale}) = 15 */ function truncate(Exp memory exp) internal pure returns (uint256) { // Note: We are not using careful math here as we're performing a division that cannot fail return exp.mantissa / expScale; } /** * @dev Checks if first Exp is less than second Exp. */ function lessThanExp(Exp memory left, Exp memory right) internal pure returns (bool) { return left.mantissa < right.mantissa; } /** * @dev Checks if left Exp <= right Exp. */ function lessThanOrEqualExp(Exp memory left, Exp memory right) internal pure returns (bool) { return left.mantissa <= right.mantissa; } /** * @dev returns true if Exp is exactly zero */ function isZeroExp(Exp memory value) internal pure returns (bool) { return value.mantissa == 0; } function safe224(uint256 n, string memory errorMessage) internal pure returns (uint224) { require(n < 2**224, errorMessage); return uint224(n); } function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function add_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({mantissa: add_(a.mantissa, b.mantissa)}); } function add_(uint256 a, uint256 b) internal pure returns (uint256) { return add_(a, b, "addition overflow"); } function add_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, errorMessage); return c; } function sub_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({mantissa: sub_(a.mantissa, b.mantissa)}); } function sub_(uint256 a, uint256 b) internal pure returns (uint256) { return sub_(a, b, "subtraction underflow"); } function sub_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } function mul_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b.mantissa) / expScale}); } function mul_(Exp memory a, uint256 b) internal pure returns (Exp memory) { return Exp({mantissa: mul_(a.mantissa, b)}); } function mul_(uint256 a, Exp memory b) internal pure returns (uint256) { return mul_(a, b.mantissa) / expScale; } function mul_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b.mantissa) / doubleScale}); } function mul_(Double memory a, uint256 b) internal pure returns (Double memory) { return Double({mantissa: mul_(a.mantissa, b)}); } function mul_(uint256 a, Double memory b) internal pure returns (uint256) { return mul_(a, b.mantissa) / doubleScale; } function mul_(uint256 a, uint256 b) internal pure returns (uint256) { return mul_(a, b, "multiplication overflow"); } function mul_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { if (a == 0 || b == 0) { return 0; } uint256 c = a * b; require(c / a == b, errorMessage); return c; } function div_(Exp memory a, Exp memory b) internal pure returns (Exp memory) { return Exp({mantissa: div_(mul_(a.mantissa, expScale), b.mantissa)}); } function div_(Exp memory a, uint256 b) internal pure returns (Exp memory) { return Exp({mantissa: div_(a.mantissa, b)}); } function div_(uint256 a, Exp memory b) internal pure returns (uint256) { return div_(mul_(a, expScale), b.mantissa); } function div_(Double memory a, Double memory b) internal pure returns (Double memory) { return Double({mantissa: div_(mul_(a.mantissa, doubleScale), b.mantissa)}); } function div_(Double memory a, uint256 b) internal pure returns (Double memory) { return Double({mantissa: div_(a.mantissa, b)}); } function div_(uint256 a, Double memory b) internal pure returns (uint256) { return div_(mul_(a, doubleScale), b.mantissa); } function div_(uint256 a, uint256 b) internal pure returns (uint256) { return div_(a, b, "divide by zero"); } function div_( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } function fraction(uint256 a, uint256 b) internal pure returns (Double memory) { return Double({mantissa: div_(mul_(a, doubleScale), b)}); } // implementation from https://github.com/Uniswap/uniswap-lib/commit/99f3f28770640ba1bb1ff460ac7c5292fb8291a0 // original implementation: https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMath64x64.sol#L687 function sqrt(uint256 x) internal pure returns (uint256) { if (x == 0) return 0; uint256 xx = x; uint256 r = 1; if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; } if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; } if (xx >= 0x100000000) { xx >>= 32; r <<= 16; } if (xx >= 0x10000) { xx >>= 16; r <<= 8; } if (xx >= 0x100) { xx >>= 8; r <<= 4; } if (xx >= 0x10) { xx >>= 4; r <<= 2; } if (xx >= 0x8) { r <<= 1; } r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; // Seven iterations should be enough uint256 r1 = x / r; return (r < r1 ? r : r1); } } contract PriceOracle { /** * @notice Get the underlying price of a jToken asset * @param jToken The jToken to get the underlying price of * @return The underlying asset price mantissa (scaled by 1e18). * Zero means the price is unavailable. */ function getUnderlyingPrice(JToken jToken) external view returns (uint256); } contract UnitrollerAdminStorage { /** * @notice Administrator for this contract */ address public admin; /** * @notice Pending administrator for this contract */ address public pendingAdmin; /** * @notice Active brains of Unitroller */ address public implementation; /** * @notice Pending brains of Unitroller */ address public pendingImplementation; } contract JoetrollerV1Storage is UnitrollerAdminStorage { /** * @notice Oracle which gives the price of any given asset */ PriceOracle public oracle; /** * @notice Multiplier used to calculate the maximum repayAmount when liquidating a borrow */ uint256 public closeFactorMantissa; /** * @notice Multiplier representing the discount on collateral that a liquidator receives */ uint256 public liquidationIncentiveMantissa; /** * @notice Per-account mapping of "assets you are in" */ mapping(address => JToken[]) public accountAssets; enum Version { VANILLA, COLLATERALCAP, WRAPPEDNATIVE } struct Market { /// @notice Whether or not this market is listed bool isListed; /** * @notice Multiplier representing the most one can borrow against their collateral in this market. * For instance, 0.9 to allow borrowing 90% of collateral value. * Must be between 0 and 1, and stored as a mantissa. */ uint256 collateralFactorMantissa; /// @notice Per-market mapping of "accounts in this asset" mapping(address => bool) accountMembership; /// @notice JToken version Version version; } /** * @notice Official mapping of jTokens -> Market metadata * @dev Used e.g. to determine if a market is supported */ mapping(address => Market) public markets; /** * @notice The Pause Guardian can pause certain actions as a safety mechanism. * Actions which allow users to remove their own assets cannot be paused. * Liquidation / seizing / transfer can only be paused globally, not by market. */ address public pauseGuardian; bool public _mintGuardianPaused; bool public _borrowGuardianPaused; bool public transferGuardianPaused; bool public seizeGuardianPaused; mapping(address => bool) public mintGuardianPaused; mapping(address => bool) public borrowGuardianPaused; /// @notice A list of all markets JToken[] public allMarkets; // @notice The borrowCapGuardian can set borrowCaps to any number for any market. Lowering the borrow cap could disable borrowing on the given market. address public borrowCapGuardian; // @notice Borrow caps enforced by borrowAllowed for each jToken address. Defaults to zero which corresponds to unlimited borrowing. mapping(address => uint256) public borrowCaps; // @notice The supplyCapGuardian can set supplyCaps to any number for any market. Lowering the supply cap could disable supplying to the given market. address public supplyCapGuardian; // @notice Supply caps enforced by mintAllowed for each jToken address. Defaults to zero which corresponds to unlimited supplying. mapping(address => uint256) public supplyCaps; // @notice creditLimits allowed specific protocols to borrow and repay without collateral. mapping(address => uint256) public creditLimits; // @notice flashloanGuardianPaused can pause flash loan as a safety mechanism. mapping(address => bool) public flashloanGuardianPaused; // @notice rewardDistributor The module that handles reward distribution. address payable public rewardDistributor; } contract JoetrollerInterface { /// @notice Indicator that this is a Joetroller contract (for inspection) bool public constant isJoetroller = true; /*** Assets You Are In ***/ function enterMarkets(address[] calldata jTokens) external returns (uint256[] memory); function exitMarket(address jToken) external returns (uint256); /*** Policy Hooks ***/ function mintAllowed( address jToken, address minter, uint256 mintAmount ) external returns (uint256); function mintVerify( address jToken, address minter, uint256 mintAmount, uint256 mintTokens ) external; function redeemAllowed( address jToken, address redeemer, uint256 redeemTokens ) external returns (uint256); function redeemVerify( address jToken, address redeemer, uint256 redeemAmount, uint256 redeemTokens ) external; function borrowAllowed( address jToken, address borrower, uint256 borrowAmount ) external returns (uint256); function borrowVerify( address jToken, address borrower, uint256 borrowAmount ) external; function repayBorrowAllowed( address jToken, address payer, address borrower, uint256 repayAmount ) external returns (uint256); function repayBorrowVerify( address jToken, address payer, address borrower, uint256 repayAmount, uint256 borrowerIndex ) external; function liquidateBorrowAllowed( address jTokenBorrowed, address jTokenCollateral, address liquidator, address borrower, uint256 repayAmount ) external returns (uint256); function liquidateBorrowVerify( address jTokenBorrowed, address jTokenCollateral, address liquidator, address borrower, uint256 repayAmount, uint256 seizeTokens ) external; function seizeAllowed( address jTokenCollateral, address jTokenBorrowed, address liquidator, address borrower, uint256 seizeTokens ) external returns (uint256); function seizeVerify( address jTokenCollateral, address jTokenBorrowed, address liquidator, address borrower, uint256 seizeTokens ) external; function transferAllowed( address jToken, address src, address dst, uint256 transferTokens ) external returns (uint256); function transferVerify( address jToken, address src, address dst, uint256 transferTokens ) external; /*** Liquidity/Liquidation Calculations ***/ function liquidateCalculateSeizeTokens( address jTokenBorrowed, address jTokenCollateral, uint256 repayAmount ) external view returns (uint256, uint256); } interface JoetrollerInterfaceExtension { function checkMembership(address account, JToken jToken) external view returns (bool); function updateJTokenVersion(address jToken, JoetrollerV1Storage.Version version) external; function flashloanAllowed( address jToken, address receiver, uint256 amount, bytes calldata params ) external view returns (bool); } contract JTokenStorage { /** * @dev Guard variable for re-entrancy checks */ bool internal _notEntered; /** * @notice EIP-20 token name for this token */ string public name; /** * @notice EIP-20 token symbol for this token */ string public symbol; /** * @notice EIP-20 token decimals for this token */ uint8 public decimals; /** * @notice Maximum borrow rate that can ever be applied (.0005% / sec) */ uint256 internal constant borrowRateMaxMantissa = 0.0005e16; /** * @notice Maximum fraction of interest that can be set aside for reserves */ uint256 internal constant reserveFactorMaxMantissa = 1e18; /** * @notice Administrator for this contract */ address payable public admin; /** * @notice Pending administrator for this contract */ address payable public pendingAdmin; /** * @notice Contract which oversees inter-jToken operations */ JoetrollerInterface public joetroller; /** * @notice Model which tells what the current interest rate should be */ InterestRateModel public interestRateModel; /** * @notice Initial exchange rate used when minting the first JTokens (used when totalSupply = 0) */ uint256 internal initialExchangeRateMantissa; /** * @notice Fraction of interest currently set aside for reserves */ uint256 public reserveFactorMantissa; /** * @notice Block timestamp that interest was last accrued at */ uint256 public accrualBlockTimestamp; /** * @notice Accumulator of the total earned interest rate since the opening of the market */ uint256 public borrowIndex; /** * @notice Total amount of outstanding borrows of the underlying in this market */ uint256 public totalBorrows; /** * @notice Total amount of reserves of the underlying held in this market */ uint256 public totalReserves; /** * @notice Total number of tokens in circulation */ uint256 public totalSupply; /** * @notice Official record of token balances for each account */ mapping(address => uint256) internal accountTokens; /** * @notice Approved token transfer amounts on behalf of others */ mapping(address => mapping(address => uint256)) internal transferAllowances; /** * @notice Container for borrow balance information * @member principal Total balance (with accrued interest), after applying the most recent balance-changing action * @member interestIndex Global borrowIndex as of the most recent balance-changing action */ struct BorrowSnapshot { uint256 principal; uint256 interestIndex; } /** * @notice Mapping of account addresses to outstanding borrow balances */ mapping(address => BorrowSnapshot) internal accountBorrows; } contract JErc20Storage { /** * @notice Underlying asset for this JToken */ address public underlying; /** * @notice Implementation address for this contract */ address public implementation; } contract JSupplyCapStorage { /** * @notice Internal cash counter for this JToken. Should equal underlying.balanceOf(address(this)) for CERC20. */ uint256 public internalCash; } contract JCollateralCapStorage { /** * @notice Total number of tokens used as collateral in circulation. */ uint256 public totalCollateralTokens; /** * @notice Record of token balances which could be treated as collateral for each account. * If collateral cap is not set, the value should be equal to accountTokens. */ mapping(address => uint256) public accountCollateralTokens; /** * @notice Check if accountCollateralTokens have been initialized. */ mapping(address => bool) public isCollateralTokenInit; /** * @notice Collateral cap for this JToken, zero for no cap. */ uint256 public collateralCap; } /*** Interface ***/ contract JTokenInterface is JTokenStorage { /** * @notice Indicator that this is a JToken contract (for inspection) */ bool public constant isJToken = true; /*** Market Events ***/ /** * @notice Event emitted when interest is accrued */ event AccrueInterest(uint256 cashPrior, uint256 interestAccumulated, uint256 borrowIndex, uint256 totalBorrows); /** * @notice Event emitted when tokens are minted */ event Mint(address minter, uint256 mintAmount, uint256 mintTokens); /** * @notice Event emitted when tokens are redeemed */ event Redeem(address redeemer, uint256 redeemAmount, uint256 redeemTokens); /** * @notice Event emitted when underlying is borrowed */ event Borrow(address borrower, uint256 borrowAmount, uint256 accountBorrows, uint256 totalBorrows); /** * @notice Event emitted when a borrow is repaid */ event RepayBorrow( address payer, address borrower, uint256 repayAmount, uint256 accountBorrows, uint256 totalBorrows ); /** * @notice Event emitted when a borrow is liquidated */ event LiquidateBorrow( address liquidator, address borrower, uint256 repayAmount, address jTokenCollateral, uint256 seizeTokens ); /*** Admin Events ***/ /** * @notice Event emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Event emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); /** * @notice Event emitted when joetroller is changed */ event NewJoetroller(JoetrollerInterface oldJoetroller, JoetrollerInterface newJoetroller); /** * @notice Event emitted when interestRateModel is changed */ event NewMarketInterestRateModel(InterestRateModel oldInterestRateModel, InterestRateModel newInterestRateModel); /** * @notice Event emitted when the reserve factor is changed */ event NewReserveFactor(uint256 oldReserveFactorMantissa, uint256 newReserveFactorMantissa); /** * @notice Event emitted when the reserves are added */ event ReservesAdded(address benefactor, uint256 addAmount, uint256 newTotalReserves); /** * @notice Event emitted when the reserves are reduced */ event ReservesReduced(address admin, uint256 reduceAmount, uint256 newTotalReserves); /** * @notice EIP20 Transfer event */ event Transfer(address indexed from, address indexed to, uint256 amount); /** * @notice EIP20 Approval event */ event Approval(address indexed owner, address indexed spender, uint256 amount); /** * @notice Failure event */ event Failure(uint256 error, uint256 info, uint256 detail); /*** User Interface ***/ function transfer(address dst, uint256 amount) external returns (bool); function transferFrom( address src, address dst, uint256 amount ) external returns (bool); function approve(address spender, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function balanceOf(address owner) external view returns (uint256); function balanceOfUnderlying(address owner) external returns (uint256); function getAccountSnapshot(address account) external view returns ( uint256, uint256, uint256, uint256 ); function borrowRatePerSecond() external view returns (uint256); function supplyRatePerSecond() external view returns (uint256); function totalBorrowsCurrent() external returns (uint256); function borrowBalanceCurrent(address account) external returns (uint256); function borrowBalanceStored(address account) public view returns (uint256); function exchangeRateCurrent() public returns (uint256); function exchangeRateStored() public view returns (uint256); function getCash() external view returns (uint256); function accrueInterest() public returns (uint256); function seize( address liquidator, address borrower, uint256 seizeTokens ) external returns (uint256); /*** Admin Functions ***/ function _setPendingAdmin(address payable newPendingAdmin) external returns (uint256); function _acceptAdmin() external returns (uint256); function _setJoetroller(JoetrollerInterface newJoetroller) public returns (uint256); function _setReserveFactor(uint256 newReserveFactorMantissa) external returns (uint256); function _reduceReserves(uint256 reduceAmount) external returns (uint256); function _setInterestRateModel(InterestRateModel newInterestRateModel) public returns (uint256); } contract JErc20Interface is JErc20Storage { /*** User Interface ***/ function mint(uint256 mintAmount) external returns (uint256); function redeem(uint256 redeemTokens) external returns (uint256); function redeemUnderlying(uint256 redeemAmount) external returns (uint256); function borrow(uint256 borrowAmount) external returns (uint256); function repayBorrow(uint256 repayAmount) external returns (uint256); function repayBorrowBehalf(address borrower, uint256 repayAmount) external returns (uint256); function liquidateBorrow( address borrower, uint256 repayAmount, JTokenInterface jTokenCollateral ) external returns (uint256); function _addReserves(uint256 addAmount) external returns (uint256); } contract JWrappedNativeInterface is JErc20Interface { /** * @notice Flash loan fee ratio */ uint256 public constant flashFeeBips = 8; /*** Market Events ***/ /** * @notice Event emitted when a flashloan occured */ event Flashloan(address indexed receiver, uint256 amount, uint256 totalFee, uint256 reservesFee); /*** User Interface ***/ function mintNative() external payable returns (uint256); function redeemNative(uint256 redeemTokens) external returns (uint256); function redeemUnderlyingNative(uint256 redeemAmount) external returns (uint256); function borrowNative(uint256 borrowAmount) external returns (uint256); function repayBorrowNative() external payable returns (uint256); function repayBorrowBehalfNative(address borrower) external payable returns (uint256); function liquidateBorrowNative(address borrower, JTokenInterface jTokenCollateral) external payable returns (uint256); function flashLoan( ERC3156FlashBorrowerInterface receiver, address initiator, uint256 amount, bytes calldata data ) external returns (bool); function _addReservesNative() external payable returns (uint256); } contract JCapableErc20Interface is JErc20Interface, JSupplyCapStorage { /** * @notice Flash loan fee ratio */ uint256 public constant flashFeeBips = 8; /*** Market Events ***/ /** * @notice Event emitted when a flashloan occured */ event Flashloan(address indexed receiver, uint256 amount, uint256 totalFee, uint256 reservesFee); /*** User Interface ***/ function gulp() external; } contract JCollateralCapErc20Interface is JCapableErc20Interface, JCollateralCapStorage { /*** Admin Events ***/ /** * @notice Event emitted when collateral cap is set */ event NewCollateralCap(address token, uint256 newCap); /** * @notice Event emitted when user collateral is changed */ event UserCollateralChanged(address account, uint256 newCollateralTokens); /*** User Interface ***/ function registerCollateral(address account) external returns (uint256); function unregisterCollateral(address account) external; function flashLoan( ERC3156FlashBorrowerInterface receiver, address initiator, uint256 amount, bytes calldata data ) external returns (bool); /*** Admin Functions ***/ function _setCollateralCap(uint256 newCollateralCap) external; } contract JDelegatorInterface { /** * @notice Emitted when implementation is changed */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Called by the admin to update the implementation of the delegator * @param implementation_ The address of the new implementation for delegation * @param allowResign Flag to indicate whether to call _resignImplementation on the old implementation * @param becomeImplementationData The encoded bytes data to be passed to _becomeImplementation */ function _setImplementation( address implementation_, bool allowResign, bytes memory becomeImplementationData ) public; } contract JDelegateInterface { /** * @notice Called by the delegator on a delegate to initialize it for duty * @dev Should revert if any issues arise which make it unfit for delegation * @param data The encoded bytes data for any initialization */ function _becomeImplementation(bytes memory data) public; /** * @notice Called by the delegator on a delegate to forfeit its responsibility */ function _resignImplementation() public; } /*** External interface ***/ /** * @title Flash loan receiver interface */ interface IFlashloanReceiver { function executeOperation( address sender, address underlying, uint256 amount, uint256 fee, bytes calldata params ) external; } /** * @title EIP20NonStandardInterface * @dev Version of ERC20 with no return values for `transfer` and `transferFrom` * See https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca */ interface EIP20NonStandardInterface { /** * @notice Get the total number of tokens in circulation * @return The supply of tokens */ function totalSupply() external view returns (uint256); /** * @notice Gets the balance of the specified address * @param owner The address from which the balance will be retrieved * @return The balance */ function balanceOf(address owner) external view returns (uint256 balance); /// /// !!!!!!!!!!!!!! /// !!! NOTICE !!! `transfer` does not return a value, in violation of the ERC-20 specification /// !!!!!!!!!!!!!! /// /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer */ function transfer(address dst, uint256 amount) external; /// /// !!!!!!!!!!!!!! /// !!! NOTICE !!! `transferFrom` does not return a value, in violation of the ERC-20 specification /// !!!!!!!!!!!!!! /// /** * @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 amount The number of tokens to transfer */ function transferFrom( address src, address dst, uint256 amount ) external; /** * @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 amount The number of tokens that are approved * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool success); /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent */ function allowance(address owner, address spender) external view returns (uint256 remaining); event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); } /** * @title Compound's JToken Contract * @notice Abstract base for JTokens * @author Compound */ contract JToken is JTokenInterface, Exponential, TokenErrorReporter { /** * @notice Initialize the money market * @param joetroller_ The address of the Joetroller * @param interestRateModel_ The address of the interest rate model * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18 * @param name_ EIP-20 name of this token * @param symbol_ EIP-20 symbol of this token * @param decimals_ EIP-20 decimal precision of this token */ function initialize( JoetrollerInterface joetroller_, InterestRateModel interestRateModel_, uint256 initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_ ) public { require(msg.sender == admin, "only admin may initialize the market"); require(accrualBlockTimestamp == 0 && borrowIndex == 0, "market may only be initialized once"); // Set initial exchange rate initialExchangeRateMantissa = initialExchangeRateMantissa_; require(initialExchangeRateMantissa > 0, "initial exchange rate must be greater than zero."); // Set the joetroller uint256 err = _setJoetroller(joetroller_); require(err == uint256(Error.NO_ERROR), "setting joetroller failed"); // Initialize block timestamp and borrow index (block timestamp mocks depend on joetroller being set) accrualBlockTimestamp = getBlockTimestamp(); borrowIndex = mantissaOne; // Set the interest rate model (depends on block timestamp / borrow index) err = _setInterestRateModelFresh(interestRateModel_); require(err == uint256(Error.NO_ERROR), "setting interest rate model failed"); name = name_; symbol = symbol_; decimals = decimals_; // The counter starts true to prevent changing it from zero to non-zero (i.e. smaller cost/refund) _notEntered = true; } /** * @notice Transfer `amount` tokens from `msg.sender` to `dst` * @param dst The address of the destination account * @param amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transfer(address dst, uint256 amount) external nonReentrant returns (bool) { return transferTokens(msg.sender, msg.sender, dst, amount) == uint256(Error.NO_ERROR); } /** * @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 amount The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferFrom( address src, address dst, uint256 amount ) external nonReentrant returns (bool) { return transferTokens(msg.sender, src, dst, amount) == uint256(Error.NO_ERROR); } /** * @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 amount The number of tokens that are approved (-1 means infinite) * @return Whether or not the approval succeeded */ function approve(address spender, uint256 amount) external returns (bool) { address src = msg.sender; transferAllowances[src][spender] = amount; emit Approval(src, spender, amount); return true; } /** * @notice Get the current allowance from `owner` for `spender` * @param owner The address of the account which owns the tokens to be spent * @param spender The address of the account which may transfer tokens * @return The number of tokens allowed to be spent (-1 means infinite) */ function allowance(address owner, address spender) external view returns (uint256) { return transferAllowances[owner][spender]; } /** * @notice Get the token balance of the `owner` * @param owner The address of the account to query * @return The number of tokens owned by `owner` */ function balanceOf(address owner) external view returns (uint256) { return accountTokens[owner]; } /** * @notice Get the underlying balance of the `owner` * @dev This also accrues interest in a transaction * @param owner The address of the account to query * @return The amount of underlying owned by `owner` */ function balanceOfUnderlying(address owner) external returns (uint256) { Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()}); return mul_ScalarTruncate(exchangeRate, accountTokens[owner]); } /** * @notice Get a snapshot of the account's balances, and the cached exchange rate * @dev This is used by joetroller to more efficiently perform liquidity checks. * @param account Address of the account to snapshot * @return (possible error, token balance, borrow balance, exchange rate mantissa) */ function getAccountSnapshot(address account) external view returns ( uint256, uint256, uint256, uint256 ) { uint256 jTokenBalance = getJTokenBalanceInternal(account); uint256 borrowBalance = borrowBalanceStoredInternal(account); uint256 exchangeRateMantissa = exchangeRateStoredInternal(); return (uint256(Error.NO_ERROR), jTokenBalance, borrowBalance, exchangeRateMantissa); } /** * @dev Function to simply retrieve block timestamp * This exists mainly for inheriting test contracts to stub this result. */ function getBlockTimestamp() internal view returns (uint256) { return block.timestamp; } /** * @notice Returns the current per-sec borrow interest rate for this jToken * @return The borrow interest rate per sec, scaled by 1e18 */ function borrowRatePerSecond() external view returns (uint256) { return interestRateModel.getBorrowRate(getCashPrior(), totalBorrows, totalReserves); } /** * @notice Returns the current per-sec supply interest rate for this jToken * @return The supply interest rate per sec, scaled by 1e18 */ function supplyRatePerSecond() external view returns (uint256) { return interestRateModel.getSupplyRate(getCashPrior(), totalBorrows, totalReserves, reserveFactorMantissa); } /** * @notice Returns the estimated per-sec borrow interest rate for this jToken after some change * @return The borrow interest rate per sec, scaled by 1e18 */ function estimateBorrowRatePerSecondAfterChange(uint256 change, bool repay) external view returns (uint256) { uint256 cashPriorNew; uint256 totalBorrowsNew; if (repay) { cashPriorNew = add_(getCashPrior(), change); totalBorrowsNew = sub_(totalBorrows, change); } else { cashPriorNew = sub_(getCashPrior(), change); totalBorrowsNew = add_(totalBorrows, change); } return interestRateModel.getBorrowRate(cashPriorNew, totalBorrowsNew, totalReserves); } /** * @notice Returns the estimated per-sec supply interest rate for this jToken after some change * @return The supply interest rate per sec, scaled by 1e18 */ function estimateSupplyRatePerSecondAfterChange(uint256 change, bool repay) external view returns (uint256) { uint256 cashPriorNew; uint256 totalBorrowsNew; if (repay) { cashPriorNew = add_(getCashPrior(), change); totalBorrowsNew = sub_(totalBorrows, change); } else { cashPriorNew = sub_(getCashPrior(), change); totalBorrowsNew = add_(totalBorrows, change); } return interestRateModel.getSupplyRate(cashPriorNew, totalBorrowsNew, totalReserves, reserveFactorMantissa); } /** * @notice Returns the current total borrows plus accrued interest * @return The total borrows with interest */ function totalBorrowsCurrent() external nonReentrant returns (uint256) { require(accrueInterest() == uint256(Error.NO_ERROR), "accrue interest failed"); return totalBorrows; } /** * @notice Accrue interest to updated borrowIndex and then calculate account's borrow balance using the updated borrowIndex * @param account The address whose balance should be calculated after updating borrowIndex * @return The calculated balance */ function borrowBalanceCurrent(address account) external nonReentrant returns (uint256) { require(accrueInterest() == uint256(Error.NO_ERROR), "accrue interest failed"); return borrowBalanceStored(account); } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return The calculated balance */ function borrowBalanceStored(address account) public view returns (uint256) { return borrowBalanceStoredInternal(account); } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return the calculated balance or 0 if error code is non-zero */ function borrowBalanceStoredInternal(address account) internal view returns (uint256) { /* Get borrowBalance and borrowIndex */ BorrowSnapshot storage borrowSnapshot = accountBorrows[account]; /* If borrowBalance = 0 then borrowIndex is likely also 0. * Rather than failing the calculation with a division by 0, we immediately return 0 in this case. */ if (borrowSnapshot.principal == 0) { return 0; } /* Calculate new borrow balance using the interest index: * recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex */ uint256 principalTimesIndex = mul_(borrowSnapshot.principal, borrowIndex); uint256 result = div_(principalTimesIndex, borrowSnapshot.interestIndex); return result; } /** * @notice Accrue interest then return the up-to-date exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateCurrent() public nonReentrant returns (uint256) { require(accrueInterest() == uint256(Error.NO_ERROR), "accrue interest failed"); return exchangeRateStored(); } /** * @notice Calculates the exchange rate from the underlying to the JToken * @dev This function does not accrue interest before calculating the exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateStored() public view returns (uint256) { return exchangeRateStoredInternal(); } /** * @notice Calculates the exchange rate from the underlying to the JToken * @dev This function does not accrue interest before calculating the exchange rate * @return calculated exchange rate scaled by 1e18 */ function exchangeRateStoredInternal() internal view returns (uint256) { uint256 _totalSupply = totalSupply; if (_totalSupply == 0) { /* * If there are no tokens minted: * exchangeRate = initialExchangeRate */ return initialExchangeRateMantissa; } else { /* * Otherwise: * exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply */ uint256 totalCash = getCashPrior(); uint256 cashPlusBorrowsMinusReserves = sub_(add_(totalCash, totalBorrows), totalReserves); uint256 exchangeRate = div_(cashPlusBorrowsMinusReserves, Exp({mantissa: _totalSupply})); return exchangeRate; } } /** * @notice Get cash balance of this jToken in the underlying asset * @return The quantity of underlying asset owned by this contract */ function getCash() external view returns (uint256) { return getCashPrior(); } /** * @notice Applies accrued interest to total borrows and reserves * @dev This calculates interest accrued from the last checkpointed timestamp * up to the current timestamp and writes new checkpoint to storage. */ function accrueInterest() public returns (uint256) { /* Remember the initial block timestamp */ uint256 currentBlockTimestamp = getBlockTimestamp(); uint256 accrualBlockTimestampPrior = accrualBlockTimestamp; /* Short-circuit accumulating 0 interest */ if (accrualBlockTimestampPrior == currentBlockTimestamp) { return uint256(Error.NO_ERROR); } /* Read the previous values out of storage */ uint256 cashPrior = getCashPrior(); uint256 borrowsPrior = totalBorrows; uint256 reservesPrior = totalReserves; uint256 borrowIndexPrior = borrowIndex; /* Calculate the current borrow interest rate */ uint256 borrowRateMantissa = interestRateModel.getBorrowRate(cashPrior, borrowsPrior, reservesPrior); require(borrowRateMantissa <= borrowRateMaxMantissa, "borrow rate is absurdly high"); /* Calculate the number of seconds elapsed since the last accrual */ uint256 timestampDelta = sub_(currentBlockTimestamp, accrualBlockTimestampPrior); /* * Calculate the interest accumulated into borrows and reserves and the new index: * simpleInterestFactor = borrowRate * timestampDelta * interestAccumulated = simpleInterestFactor * totalBorrows * totalBorrowsNew = interestAccumulated + totalBorrows * totalReservesNew = interestAccumulated * reserveFactor + totalReserves * borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex */ Exp memory simpleInterestFactor = mul_(Exp({mantissa: borrowRateMantissa}), timestampDelta); uint256 interestAccumulated = mul_ScalarTruncate(simpleInterestFactor, borrowsPrior); uint256 totalBorrowsNew = add_(interestAccumulated, borrowsPrior); uint256 totalReservesNew = mul_ScalarTruncateAddUInt( Exp({mantissa: reserveFactorMantissa}), interestAccumulated, reservesPrior ); uint256 borrowIndexNew = mul_ScalarTruncateAddUInt(simpleInterestFactor, borrowIndexPrior, borrowIndexPrior); ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write the previously calculated values into storage */ accrualBlockTimestamp = currentBlockTimestamp; borrowIndex = borrowIndexNew; totalBorrows = totalBorrowsNew; totalReserves = totalReservesNew; /* We emit an AccrueInterest event */ emit AccrueInterest(cashPrior, interestAccumulated, borrowIndexNew, totalBorrowsNew); return uint256(Error.NO_ERROR); } /** * @notice Sender supplies assets into the market and receives jTokens in exchange * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param mintAmount The amount of the underlying asset to supply * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount. */ function mintInternal(uint256 mintAmount, bool isNative) internal nonReentrant returns (uint256, uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.MINT_ACCRUE_INTEREST_FAILED), 0); } // mintFresh emits the actual Mint event if successful and logs on errors, so we don't need to return mintFresh(msg.sender, mintAmount, isNative); } /** * @notice Sender redeems jTokens in exchange for the underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemTokens The number of jTokens to redeem into underlying * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemInternal(uint256 redeemTokens, bool isNative) internal nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED); } // redeemFresh emits redeem-specific logs on errors, so we don't need to return redeemFresh(msg.sender, redeemTokens, 0, isNative); } /** * @notice Sender redeems jTokens in exchange for a specified amount of underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemAmount The amount of underlying to receive from redeeming jTokens * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemUnderlyingInternal(uint256 redeemAmount, bool isNative) internal nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted redeem failed return fail(Error(error), FailureInfo.REDEEM_ACCRUE_INTEREST_FAILED); } // redeemFresh emits redeem-specific logs on errors, so we don't need to return redeemFresh(msg.sender, 0, redeemAmount, isNative); } /** * @notice Sender borrows assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrowInternal(uint256 borrowAmount, bool isNative) internal nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return fail(Error(error), FailureInfo.BORROW_ACCRUE_INTEREST_FAILED); } // borrowFresh emits borrow-specific logs on errors, so we don't need to return borrowFresh(msg.sender, borrowAmount, isNative); } struct BorrowLocalVars { MathError mathErr; uint256 accountBorrows; uint256 accountBorrowsNew; uint256 totalBorrowsNew; } /** * @notice Users borrow assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrowFresh( address payable borrower, uint256 borrowAmount, bool isNative ) internal returns (uint256) { /* Fail if borrow not allowed */ uint256 allowed = joetroller.borrowAllowed(address(this), borrower, borrowAmount); if (allowed != 0) { return failOpaque(Error.JOETROLLER_REJECTION, FailureInfo.BORROW_JOETROLLER_REJECTION, allowed); } /* * Return if borrowAmount is zero. * Put behind `borrowAllowed` for accuring potential JOE rewards. */ if (borrowAmount == 0) { accountBorrows[borrower].interestIndex = borrowIndex; return uint256(Error.NO_ERROR); } /* Verify market's block timestamp equals current block timestamp */ if (accrualBlockTimestamp != getBlockTimestamp()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.BORROW_FRESHNESS_CHECK); } /* Fail gracefully if protocol has insufficient underlying cash */ if (getCashPrior() < borrowAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.BORROW_CASH_NOT_AVAILABLE); } BorrowLocalVars memory vars; /* * We calculate the new borrower and total borrow balances, failing on overflow: * accountBorrowsNew = accountBorrows + borrowAmount * totalBorrowsNew = totalBorrows + borrowAmount */ vars.accountBorrows = borrowBalanceStoredInternal(borrower); vars.accountBorrowsNew = add_(vars.accountBorrows, borrowAmount); vars.totalBorrowsNew = add_(totalBorrows, borrowAmount); ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We invoke doTransferOut for the borrower and the borrowAmount. * Note: The jToken must handle variations between ERC-20 and ETH underlying. * On success, the jToken borrowAmount less of cash. * doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. */ doTransferOut(borrower, borrowAmount, isNative); /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = vars.accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = vars.totalBorrowsNew; /* We emit a Borrow event */ emit Borrow(borrower, borrowAmount, vars.accountBorrowsNew, vars.totalBorrowsNew); /* We call the defense hook */ // unused function // joetroller.borrowVerify(address(this), borrower, borrowAmount); return uint256(Error.NO_ERROR); } /** * @notice Sender repays their own borrow * @param repayAmount The amount to repay * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowInternal(uint256 repayAmount, bool isNative) internal nonReentrant returns (uint256, uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.REPAY_BORROW_ACCRUE_INTEREST_FAILED), 0); } // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to return repayBorrowFresh(msg.sender, msg.sender, repayAmount, isNative); } /** * @notice Sender repays a borrow belonging to borrower * @param borrower the account with the debt being payed off * @param repayAmount The amount to repay * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowBehalfInternal( address borrower, uint256 repayAmount, bool isNative ) internal nonReentrant returns (uint256, uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted borrow failed return (fail(Error(error), FailureInfo.REPAY_BEHALF_ACCRUE_INTEREST_FAILED), 0); } // repayBorrowFresh emits repay-borrow-specific logs on errors, so we don't need to return repayBorrowFresh(msg.sender, borrower, repayAmount, isNative); } struct RepayBorrowLocalVars { Error err; MathError mathErr; uint256 repayAmount; uint256 borrowerIndex; uint256 accountBorrows; uint256 accountBorrowsNew; uint256 totalBorrowsNew; uint256 actualRepayAmount; } /** * @notice Borrows are repaid by another user (possibly the borrower). * @param payer the account paying off the borrow * @param borrower the account with the debt being payed off * @param repayAmount the amount of undelrying tokens being returned * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowFresh( address payer, address borrower, uint256 repayAmount, bool isNative ) internal returns (uint256, uint256) { /* Fail if repayBorrow not allowed */ uint256 allowed = joetroller.repayBorrowAllowed(address(this), payer, borrower, repayAmount); if (allowed != 0) { return (failOpaque(Error.JOETROLLER_REJECTION, FailureInfo.REPAY_BORROW_JOETROLLER_REJECTION, allowed), 0); } /* * Return if repayAmount is zero. * Put behind `repayBorrowAllowed` for accuring potential JOE rewards. */ if (repayAmount == 0) { accountBorrows[borrower].interestIndex = borrowIndex; return (uint256(Error.NO_ERROR), 0); } /* Verify market's block timestamp equals current block timestamp */ if (accrualBlockTimestamp != getBlockTimestamp()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.REPAY_BORROW_FRESHNESS_CHECK), 0); } RepayBorrowLocalVars memory vars; /* We remember the original borrowerIndex for verification purposes */ vars.borrowerIndex = accountBorrows[borrower].interestIndex; /* We fetch the amount the borrower owes, with accumulated interest */ vars.accountBorrows = borrowBalanceStoredInternal(borrower); /* If repayAmount == -1, repayAmount = accountBorrows */ if (repayAmount == uint256(-1)) { vars.repayAmount = vars.accountBorrows; } else { vars.repayAmount = repayAmount; } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call doTransferIn for the payer and the repayAmount * Note: The jToken must handle variations between ERC-20 and ETH underlying. * On success, the jToken holds an additional repayAmount of cash. * doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred. * it returns the amount actually transferred, in case of a fee. */ vars.actualRepayAmount = doTransferIn(payer, vars.repayAmount, isNative); /* * We calculate the new borrower and total borrow balances, failing on underflow: * accountBorrowsNew = accountBorrows - actualRepayAmount * totalBorrowsNew = totalBorrows - actualRepayAmount */ vars.accountBorrowsNew = sub_(vars.accountBorrows, vars.actualRepayAmount); vars.totalBorrowsNew = sub_(totalBorrows, vars.actualRepayAmount); /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = vars.accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = vars.totalBorrowsNew; /* We emit a RepayBorrow event */ emit RepayBorrow(payer, borrower, vars.actualRepayAmount, vars.accountBorrowsNew, vars.totalBorrowsNew); /* We call the defense hook */ // unused function // joetroller.repayBorrowVerify(address(this), payer, borrower, vars.actualRepayAmount, vars.borrowerIndex); return (uint256(Error.NO_ERROR), vars.actualRepayAmount); } /** * @notice The sender liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this jToken to be liquidated * @param repayAmount The amount of the underlying borrowed asset to repay * @param jTokenCollateral The market in which to seize collateral from the borrower * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function liquidateBorrowInternal( address borrower, uint256 repayAmount, JTokenInterface jTokenCollateral, bool isNative ) internal nonReentrant returns (uint256, uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED), 0); } error = jTokenCollateral.accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but we still want to log the fact that an attempted liquidation failed return (fail(Error(error), FailureInfo.LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED), 0); } // liquidateBorrowFresh emits borrow-specific logs on errors, so we don't need to return liquidateBorrowFresh(msg.sender, borrower, repayAmount, jTokenCollateral, isNative); } /** * @notice The liquidator liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this jToken to be liquidated * @param liquidator The address repaying the borrow and seizing collateral * @param jTokenCollateral The market in which to seize collateral from the borrower * @param repayAmount The amount of the underlying borrowed asset to repay * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function liquidateBorrowFresh( address liquidator, address borrower, uint256 repayAmount, JTokenInterface jTokenCollateral, bool isNative ) internal returns (uint256, uint256) { /* Fail if liquidate not allowed */ uint256 allowed = joetroller.liquidateBorrowAllowed( address(this), address(jTokenCollateral), liquidator, borrower, repayAmount ); if (allowed != 0) { return (failOpaque(Error.JOETROLLER_REJECTION, FailureInfo.LIQUIDATE_JOETROLLER_REJECTION, allowed), 0); } /* Verify market's block timestamp equals current block timestamp */ if (accrualBlockTimestamp != getBlockTimestamp()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_FRESHNESS_CHECK), 0); } /* Verify jTokenCollateral market's block timestamp equals current block timestamp */ if (jTokenCollateral.accrualBlockTimestamp() != getBlockTimestamp()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.LIQUIDATE_COLLATERAL_FRESHNESS_CHECK), 0); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { return (fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_LIQUIDATOR_IS_BORROWER), 0); } /* Fail if repayAmount = 0 */ if (repayAmount == 0) { return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_ZERO), 0); } /* Fail if repayAmount = -1 */ if (repayAmount == uint256(-1)) { return (fail(Error.INVALID_CLOSE_AMOUNT_REQUESTED, FailureInfo.LIQUIDATE_CLOSE_AMOUNT_IS_UINT_MAX), 0); } /* Fail if repayBorrow fails */ (uint256 repayBorrowError, uint256 actualRepayAmount) = repayBorrowFresh( liquidator, borrower, repayAmount, isNative ); if (repayBorrowError != uint256(Error.NO_ERROR)) { return (fail(Error(repayBorrowError), FailureInfo.LIQUIDATE_REPAY_BORROW_FRESH_FAILED), 0); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We calculate the number of collateral tokens that will be seized */ (uint256 amountSeizeError, uint256 seizeTokens) = joetroller.liquidateCalculateSeizeTokens( address(this), address(jTokenCollateral), actualRepayAmount ); require(amountSeizeError == uint256(Error.NO_ERROR), "LIQUIDATE_JOETROLLER_CALCULATE_AMOUNT_SEIZE_FAILED"); /* Revert if borrower collateral token balance < seizeTokens */ require(jTokenCollateral.balanceOf(borrower) >= seizeTokens, "LIQUIDATE_SEIZE_TOO_MUCH"); // If this is also the collateral, run seizeInternal to avoid re-entrancy, otherwise make an external call uint256 seizeError; if (address(jTokenCollateral) == address(this)) { seizeError = seizeInternal(address(this), liquidator, borrower, seizeTokens); } else { seizeError = jTokenCollateral.seize(liquidator, borrower, seizeTokens); } /* Revert if seize tokens fails (since we cannot be sure of side effects) */ require(seizeError == uint256(Error.NO_ERROR), "token seizure failed"); /* We emit a LiquidateBorrow event */ emit LiquidateBorrow(liquidator, borrower, actualRepayAmount, address(jTokenCollateral), seizeTokens); /* We call the defense hook */ // unused function // joetroller.liquidateBorrowVerify(address(this), address(jTokenCollateral), liquidator, borrower, actualRepayAmount, seizeTokens); return (uint256(Error.NO_ERROR), actualRepayAmount); } /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Will fail unless called by another jToken during the process of liquidation. * Its absolutely critical to use msg.sender as the borrowed jToken and not a parameter. * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of jTokens to seize * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function seize( address liquidator, address borrower, uint256 seizeTokens ) external nonReentrant returns (uint256) { return seizeInternal(msg.sender, liquidator, borrower, seizeTokens); } /*** Admin Functions ***/ /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address payable newPendingAdmin) external returns (uint256) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint256(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() external returns (uint256) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint256(Error.NO_ERROR); } /** * @notice Sets a new joetroller for the market * @dev Admin function to set a new joetroller * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setJoetroller(JoetrollerInterface newJoetroller) public returns (uint256) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_JOETROLLER_OWNER_CHECK); } JoetrollerInterface oldJoetroller = joetroller; // Ensure invoke joetroller.isJoetroller() returns true require(newJoetroller.isJoetroller(), "marker method returned false"); // Set market's joetroller to newJoetroller joetroller = newJoetroller; // Emit NewJoetroller(oldJoetroller, newJoetroller) emit NewJoetroller(oldJoetroller, newJoetroller); return uint256(Error.NO_ERROR); } /** * @notice accrues interest and sets a new reserve factor for the protocol using _setReserveFactorFresh * @dev Admin function to accrue interest and set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactor(uint256 newReserveFactorMantissa) external nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reserve factor change failed. return fail(Error(error), FailureInfo.SET_RESERVE_FACTOR_ACCRUE_INTEREST_FAILED); } // _setReserveFactorFresh emits reserve-factor-specific logs on errors, so we don't need to. return _setReserveFactorFresh(newReserveFactorMantissa); } /** * @notice Sets a new reserve factor for the protocol (*requires fresh interest accrual) * @dev Admin function to set a new reserve factor * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setReserveFactorFresh(uint256 newReserveFactorMantissa) internal returns (uint256) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_RESERVE_FACTOR_ADMIN_CHECK); } // Verify market's block timestamp equals current block timestamp if (accrualBlockTimestamp != getBlockTimestamp()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_RESERVE_FACTOR_FRESH_CHECK); } // Check newReserveFactor ≤ maxReserveFactor if (newReserveFactorMantissa > reserveFactorMaxMantissa) { return fail(Error.BAD_INPUT, FailureInfo.SET_RESERVE_FACTOR_BOUNDS_CHECK); } uint256 oldReserveFactorMantissa = reserveFactorMantissa; reserveFactorMantissa = newReserveFactorMantissa; emit NewReserveFactor(oldReserveFactorMantissa, newReserveFactorMantissa); return uint256(Error.NO_ERROR); } /** * @notice Accrues interest and reduces reserves by transferring from msg.sender * @param addAmount Amount of addition to reserves * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _addReservesInternal(uint256 addAmount, bool isNative) internal nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed. return fail(Error(error), FailureInfo.ADD_RESERVES_ACCRUE_INTEREST_FAILED); } // _addReservesFresh emits reserve-addition-specific logs on errors, so we don't need to. (error, ) = _addReservesFresh(addAmount, isNative); return error; } /** * @notice Add reserves by transferring from caller * @dev Requires fresh interest accrual * @param addAmount Amount of addition to reserves * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure (see ErrorReporter.sol for details)) and the actual amount added, net token fees */ function _addReservesFresh(uint256 addAmount, bool isNative) internal returns (uint256, uint256) { // totalReserves + actualAddAmount uint256 totalReservesNew; uint256 actualAddAmount; // We fail gracefully unless market's block timestamp equals current block timestamp if (accrualBlockTimestamp != getBlockTimestamp()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.ADD_RESERVES_FRESH_CHECK), actualAddAmount); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call doTransferIn for the caller and the addAmount * Note: The jToken must handle variations between ERC-20 and ETH underlying. * On success, the jToken holds an additional addAmount of cash. * doTransferIn reverts if anything goes wrong, since we can't be sure if side effects occurred. * it returns the amount actually transferred, in case of a fee. */ actualAddAmount = doTransferIn(msg.sender, addAmount, isNative); totalReservesNew = add_(totalReserves, actualAddAmount); // Store reserves[n+1] = reserves[n] + actualAddAmount totalReserves = totalReservesNew; /* Emit NewReserves(admin, actualAddAmount, reserves[n+1]) */ emit ReservesAdded(msg.sender, actualAddAmount, totalReservesNew); /* Return (NO_ERROR, actualAddAmount) */ return (uint256(Error.NO_ERROR), actualAddAmount); } /** * @notice Accrues interest and reduces reserves by transferring to admin * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReserves(uint256 reduceAmount) external nonReentrant returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed. return fail(Error(error), FailureInfo.REDUCE_RESERVES_ACCRUE_INTEREST_FAILED); } // _reduceReservesFresh emits reserve-reduction-specific logs on errors, so we don't need to. return _reduceReservesFresh(reduceAmount); } /** * @notice Reduces reserves by transferring to admin * @dev Requires fresh interest accrual * @param reduceAmount Amount of reduction to reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _reduceReservesFresh(uint256 reduceAmount) internal returns (uint256) { // totalReserves - reduceAmount uint256 totalReservesNew; // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.REDUCE_RESERVES_ADMIN_CHECK); } // We fail gracefully unless market's block timestamp equals current block timestamp if (accrualBlockTimestamp != getBlockTimestamp()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDUCE_RESERVES_FRESH_CHECK); } // Fail gracefully if protocol has insufficient underlying cash if (getCashPrior() < reduceAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDUCE_RESERVES_CASH_NOT_AVAILABLE); } // Check reduceAmount ≤ reserves[n] (totalReserves) if (reduceAmount > totalReserves) { return fail(Error.BAD_INPUT, FailureInfo.REDUCE_RESERVES_VALIDATION); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) totalReservesNew = sub_(totalReserves, reduceAmount); // Store reserves[n+1] = reserves[n] - reduceAmount totalReserves = totalReservesNew; // doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. // Restrict reducing reserves in native token. Implementations except `JWrappedNative` won't use parameter `isNative`. doTransferOut(admin, reduceAmount, true); emit ReservesReduced(admin, reduceAmount, totalReservesNew); return uint256(Error.NO_ERROR); } /** * @notice accrues interest and updates the interest rate model using _setInterestRateModelFresh * @dev Admin function to accrue interest and update the interest rate model * @param newInterestRateModel the new interest rate model to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setInterestRateModel(InterestRateModel newInterestRateModel) public returns (uint256) { uint256 error = accrueInterest(); if (error != uint256(Error.NO_ERROR)) { // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted change of interest rate model failed return fail(Error(error), FailureInfo.SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED); } // _setInterestRateModelFresh emits interest-rate-model-update-specific logs on errors, so we don't need to. return _setInterestRateModelFresh(newInterestRateModel); } /** * @notice updates the interest rate model (*requires fresh interest accrual) * @dev Admin function to update the interest rate model * @param newInterestRateModel the new interest rate model to use * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setInterestRateModelFresh(InterestRateModel newInterestRateModel) internal returns (uint256) { // Used to store old model for use in the event that is emitted on success InterestRateModel oldInterestRateModel; // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_INTEREST_RATE_MODEL_OWNER_CHECK); } // We fail gracefully unless market's block timestamp equals current block timestamp if (accrualBlockTimestamp != getBlockTimestamp()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_INTEREST_RATE_MODEL_FRESH_CHECK); } // Track the market's current interest rate model oldInterestRateModel = interestRateModel; // Ensure invoke newInterestRateModel.isInterestRateModel() returns true require(newInterestRateModel.isInterestRateModel(), "marker method returned false"); // Set the interest rate model to newInterestRateModel interestRateModel = newInterestRateModel; // Emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel) emit NewMarketInterestRateModel(oldInterestRateModel, newInterestRateModel); return uint256(Error.NO_ERROR); } /*** Safe Token ***/ /** * @notice Gets balance of this contract in terms of the underlying * @dev This excludes the value of the current message, if any * @return The quantity of underlying owned by this contract */ function getCashPrior() internal view returns (uint256); /** * @dev Performs a transfer in, reverting upon failure. Returns the amount actually transferred to the protocol, in case of a fee. * This may revert due to insufficient balance or insufficient allowance. */ function doTransferIn( address from, uint256 amount, bool isNative ) internal returns (uint256); /** * @dev Performs a transfer out, ideally returning an explanatory error code upon failure tather than reverting. * If caller has not called checked protocol's balance, may revert due to insufficient cash held in the contract. * If caller has checked protocol's balance, and verified it is >= amount, this should not revert in normal conditions. */ function doTransferOut( address payable to, uint256 amount, bool isNative ) internal; /** * @notice Transfer `tokens` tokens from `src` to `dst` by `spender` * @dev Called by both `transfer` and `transferFrom` internally */ function transferTokens( address spender, address src, address dst, uint256 tokens ) internal returns (uint256); /** * @notice Get the account's jToken balances */ function getJTokenBalanceInternal(address account) internal view returns (uint256); /** * @notice User supplies assets into the market and receives jTokens in exchange * @dev Assumes interest has already been accrued up to the current timestamp */ function mintFresh( address minter, uint256 mintAmount, bool isNative ) internal returns (uint256, uint256); /** * @notice User redeems jTokens in exchange for the underlying asset * @dev Assumes interest has already been accrued up to the current timestamp */ function redeemFresh( address payable redeemer, uint256 redeemTokensIn, uint256 redeemAmountIn, bool isNative ) internal returns (uint256); /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another JToken. * Its absolutely critical to use msg.sender as the seizer jToken and not a parameter. */ function seizeInternal( address seizerToken, address liquidator, address borrower, uint256 seizeTokens ) internal returns (uint256); /*** Reentrancy Guard ***/ /** * @dev Prevents a contract from calling itself, directly or indirectly. */ modifier nonReentrant() { require(_notEntered, "re-entered"); _notEntered = false; _; _notEntered = true; // get a gas-refund post-Istanbul } } pragma experimental ABIEncoderV2; /** * @title Compound's JErc20 Contract * @notice JTokens which wrap an EIP-20 underlying * @author Compound */ contract JErc20 is JToken, JErc20Interface { /** * @notice Initialize the new money market * @param underlying_ The address of the underlying asset * @param joetroller_ The address of the Joetroller * @param interestRateModel_ The address of the interest rate model * @param initialExchangeRateMantissa_ The initial exchange rate, scaled by 1e18 * @param name_ ERC-20 name of this token * @param symbol_ ERC-20 symbol of this token * @param decimals_ ERC-20 decimal precision of this token */ function initialize( address underlying_, JoetrollerInterface joetroller_, InterestRateModel interestRateModel_, uint256 initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_ ) public { // JToken initialize does the bulk of the work super.initialize(joetroller_, interestRateModel_, initialExchangeRateMantissa_, name_, symbol_, decimals_); // Set underlying and sanity check it underlying = underlying_; EIP20Interface(underlying).totalSupply(); } /*** User Interface ***/ /** * @notice Sender supplies assets into the market and receives jTokens in exchange * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param mintAmount The amount of the underlying asset to supply * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function mint(uint256 mintAmount) external returns (uint256) { (uint256 err, ) = mintInternal(mintAmount, false); return err; } /** * @notice Sender redeems jTokens in exchange for the underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemTokens The number of jTokens to redeem into underlying * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeem(uint256 redeemTokens) external returns (uint256) { return redeemInternal(redeemTokens, false); } /** * @notice Sender redeems jTokens in exchange for a specified amount of underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemAmount The amount of underlying to redeem * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemUnderlying(uint256 redeemAmount) external returns (uint256) { return redeemUnderlyingInternal(redeemAmount, false); } /** * @notice Sender borrows assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function borrow(uint256 borrowAmount) external returns (uint256) { return borrowInternal(borrowAmount, false); } /** * @notice Sender repays their own borrow * @param repayAmount The amount to repay * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function repayBorrow(uint256 repayAmount) external returns (uint256) { (uint256 err, ) = repayBorrowInternal(repayAmount, false); return err; } /** * @notice Sender repays a borrow belonging to borrower * @param borrower the account with the debt being payed off * @param repayAmount The amount to repay * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function repayBorrowBehalf(address borrower, uint256 repayAmount) external returns (uint256) { (uint256 err, ) = repayBorrowBehalfInternal(borrower, repayAmount, false); return err; } /** * @notice The sender liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this jToken to be liquidated * @param repayAmount The amount of the underlying borrowed asset to repay * @param jTokenCollateral The market in which to seize collateral from the borrower * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function liquidateBorrow( address borrower, uint256 repayAmount, JTokenInterface jTokenCollateral ) external returns (uint256) { (uint256 err, ) = liquidateBorrowInternal(borrower, repayAmount, jTokenCollateral, false); return err; } /** * @notice The sender adds to reserves. * @param addAmount The amount fo underlying token to add as reserves * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _addReserves(uint256 addAmount) external returns (uint256) { return _addReservesInternal(addAmount, false); } /*** Safe Token ***/ /** * @notice Gets balance of this contract in terms of the underlying * @dev This excludes the value of the current message, if any * @return The quantity of underlying tokens owned by this contract */ function getCashPrior() internal view returns (uint256) { EIP20Interface token = EIP20Interface(underlying); return token.balanceOf(address(this)); } /** * @dev Similar to EIP20 transfer, except it handles a False result from `transferFrom` and reverts in that case. * This will revert due to insufficient balance or insufficient allowance. * This function returns the actual amount received, * which may be less than `amount` if there is a fee attached to the transfer. * * Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value. * See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca */ function doTransferIn( address from, uint256 amount, bool isNative ) internal returns (uint256) { isNative; // unused EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying); uint256 balanceBefore = EIP20Interface(underlying).balanceOf(address(this)); token.transferFrom(from, address(this), amount); bool success; assembly { switch returndatasize() case 0 { // This is a non-standard ERC-20 success := not(0) // set success to true } case 32 { // This is a compliant ERC-20 returndatacopy(0, 0, 32) success := mload(0) // Set `success = returndata` of external call } default { // This is an excessively non-compliant ERC-20, revert. revert(0, 0) } } require(success, "TOKEN_TRANSFER_IN_FAILED"); // Calculate the amount that was *actually* transferred uint256 balanceAfter = EIP20Interface(underlying).balanceOf(address(this)); return sub_(balanceAfter, balanceBefore); } /** * @dev Similar to EIP20 transfer, except it handles a False success from `transfer` and returns an explanatory * error code rather than reverting. If caller has not called checked protocol's balance, this may revert due to * insufficient cash held in this contract. If caller has checked protocol's balance prior to this call, and verified * it is >= amount, this should not revert in normal conditions. * * Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value. * See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca */ function doTransferOut( address payable to, uint256 amount, bool isNative ) internal { isNative; // unused EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying); token.transfer(to, amount); bool success; assembly { switch returndatasize() case 0 { // This is a non-standard ERC-20 success := not(0) // set success to true } case 32 { // This is a complaint ERC-20 returndatacopy(0, 0, 32) success := mload(0) // Set `success = returndata` of external call } default { // This is an excessively non-compliant ERC-20, revert. revert(0, 0) } } require(success, "TOKEN_TRANSFER_OUT_FAILED"); } /** * @notice Transfer `tokens` tokens from `src` to `dst` by `spender` * @dev Called by both `transfer` and `transferFrom` internally * @param spender The address of the account performing the transfer * @param src The address of the source account * @param dst The address of the destination account * @param tokens The number of tokens to transfer * @return Whether or not the transfer succeeded */ function transferTokens( address spender, address src, address dst, uint256 tokens ) internal returns (uint256) { /* Fail if transfer not allowed */ uint256 allowed = joetroller.transferAllowed(address(this), src, dst, tokens); if (allowed != 0) { return failOpaque(Error.JOETROLLER_REJECTION, FailureInfo.TRANSFER_JOETROLLER_REJECTION, allowed); } /* Do not allow self-transfers */ if (src == dst) { return fail(Error.BAD_INPUT, FailureInfo.TRANSFER_NOT_ALLOWED); } /* Get the allowance, infinite for the account owner */ uint256 startingAllowance = 0; if (spender == src) { startingAllowance = uint256(-1); } else { startingAllowance = transferAllowances[src][spender]; } /* Do the calculations, checking for {under,over}flow */ accountTokens[src] = sub_(accountTokens[src], tokens); accountTokens[dst] = add_(accountTokens[dst], tokens); /* Eat some of the allowance (if necessary) */ if (startingAllowance != uint256(-1)) { transferAllowances[src][spender] = sub_(startingAllowance, tokens); } /* We emit a Transfer event */ emit Transfer(src, dst, tokens); // unused function // joetroller.transferVerify(address(this), src, dst, tokens); return uint256(Error.NO_ERROR); } /** * @notice Get the account's jToken balances * @param account The address of the account */ function getJTokenBalanceInternal(address account) internal view returns (uint256) { return accountTokens[account]; } struct MintLocalVars { uint256 exchangeRateMantissa; uint256 mintTokens; uint256 actualMintAmount; } /** * @notice User supplies assets into the market and receives jTokens in exchange * @dev Assumes interest has already been accrued up to the current timestamp * @param minter The address of the account which is supplying the assets * @param mintAmount The amount of the underlying asset to supply * @param isNative The amount is in native or not * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount. */ function mintFresh( address minter, uint256 mintAmount, bool isNative ) internal returns (uint256, uint256) { /* Fail if mint not allowed */ uint256 allowed = joetroller.mintAllowed(address(this), minter, mintAmount); if (allowed != 0) { return (failOpaque(Error.JOETROLLER_REJECTION, FailureInfo.MINT_JOETROLLER_REJECTION, allowed), 0); } /* * Return if mintAmount is zero. * Put behind `mintAllowed` for accuring potential JOE rewards. */ if (mintAmount == 0) { return (uint256(Error.NO_ERROR), 0); } /* Verify market's block timestamp equals current block timestamp */ if (accrualBlockTimestamp != getBlockTimestamp()) { return (fail(Error.MARKET_NOT_FRESH, FailureInfo.MINT_FRESHNESS_CHECK), 0); } MintLocalVars memory vars; vars.exchangeRateMantissa = exchangeRateStoredInternal(); ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call `doTransferIn` for the minter and the mintAmount. * Note: The jToken must handle variations between ERC-20 and ETH underlying. * `doTransferIn` reverts if anything goes wrong, since we can't be sure if * side-effects occurred. The function returns the amount actually transferred, * in case of a fee. On success, the jToken holds an additional `actualMintAmount` * of cash. */ vars.actualMintAmount = doTransferIn(minter, mintAmount, isNative); /* * We get the current exchange rate and calculate the number of jTokens to be minted: * mintTokens = actualMintAmount / exchangeRate */ vars.mintTokens = div_ScalarByExpTruncate(vars.actualMintAmount, Exp({mantissa: vars.exchangeRateMantissa})); /* * We calculate the new total supply of jTokens and minter token balance, checking for overflow: * totalSupply = totalSupply + mintTokens * accountTokens[minter] = accountTokens[minter] + mintTokens */ totalSupply = add_(totalSupply, vars.mintTokens); accountTokens[minter] = add_(accountTokens[minter], vars.mintTokens); /* We emit a Mint event, and a Transfer event */ emit Mint(minter, vars.actualMintAmount, vars.mintTokens); emit Transfer(address(this), minter, vars.mintTokens); /* We call the defense hook */ // unused function // joetroller.mintVerify(address(this), minter, vars.actualMintAmount, vars.mintTokens); return (uint256(Error.NO_ERROR), vars.actualMintAmount); } struct RedeemLocalVars { uint256 exchangeRateMantissa; uint256 redeemTokens; uint256 redeemAmount; uint256 totalSupplyNew; uint256 accountTokensNew; } /** * @notice User redeems jTokens in exchange for the underlying asset * @dev Assumes interest has already been accrued up to the current timestamp. Only one of redeemTokensIn or redeemAmountIn may be non-zero and it would do nothing if both are zero. * @param redeemer The address of the account which is redeeming the tokens * @param redeemTokensIn The number of jTokens to redeem into underlying * @param redeemAmountIn The number of underlying tokens to receive from redeeming jTokens * @param isNative The amount is in native or not * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemFresh( address payable redeemer, uint256 redeemTokensIn, uint256 redeemAmountIn, bool isNative ) internal returns (uint256) { require(redeemTokensIn == 0 || redeemAmountIn == 0, "one of redeemTokensIn or redeemAmountIn must be zero"); RedeemLocalVars memory vars; /* exchangeRate = invoke Exchange Rate Stored() */ vars.exchangeRateMantissa = exchangeRateStoredInternal(); /* If redeemTokensIn > 0: */ if (redeemTokensIn > 0) { /* * We calculate the exchange rate and the amount of underlying to be redeemed: * redeemTokens = redeemTokensIn * redeemAmount = redeemTokensIn x exchangeRateCurrent */ vars.redeemTokens = redeemTokensIn; vars.redeemAmount = mul_ScalarTruncate(Exp({mantissa: vars.exchangeRateMantissa}), redeemTokensIn); } else { /* * We get the current exchange rate and calculate the amount to be redeemed: * redeemTokens = redeemAmountIn / exchangeRate * redeemAmount = redeemAmountIn */ vars.redeemTokens = div_ScalarByExpTruncate(redeemAmountIn, Exp({mantissa: vars.exchangeRateMantissa})); vars.redeemAmount = redeemAmountIn; } /* Fail if redeem not allowed */ uint256 allowed = joetroller.redeemAllowed(address(this), redeemer, vars.redeemTokens); if (allowed != 0) { return failOpaque(Error.JOETROLLER_REJECTION, FailureInfo.REDEEM_JOETROLLER_REJECTION, allowed); } /* * Return if redeemTokensIn and redeemAmountIn are zero. * Put behind `redeemAllowed` for accuring potential JOE rewards. */ if (redeemTokensIn == 0 && redeemAmountIn == 0) { return uint256(Error.NO_ERROR); } /* Verify market's block timestamp equals current block timestamp */ if (accrualBlockTimestamp != getBlockTimestamp()) { return fail(Error.MARKET_NOT_FRESH, FailureInfo.REDEEM_FRESHNESS_CHECK); } /* * We calculate the new total supply and redeemer balance, checking for underflow: * totalSupplyNew = totalSupply - redeemTokens * accountTokensNew = accountTokens[redeemer] - redeemTokens */ vars.totalSupplyNew = sub_(totalSupply, vars.redeemTokens); vars.accountTokensNew = sub_(accountTokens[redeemer], vars.redeemTokens); /* Fail gracefully if protocol has insufficient cash */ if (getCashPrior() < vars.redeemAmount) { return fail(Error.TOKEN_INSUFFICIENT_CASH, FailureInfo.REDEEM_TRANSFER_OUT_NOT_POSSIBLE); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We invoke doTransferOut for the redeemer and the redeemAmount. * Note: The jToken must handle variations between ERC-20 and ETH underlying. * On success, the jToken has redeemAmount less of cash. * doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. */ doTransferOut(redeemer, vars.redeemAmount, isNative); /* We write previously calculated values into storage */ totalSupply = vars.totalSupplyNew; accountTokens[redeemer] = vars.accountTokensNew; /* We emit a Transfer event, and a Redeem event */ emit Transfer(redeemer, address(this), vars.redeemTokens); emit Redeem(redeemer, vars.redeemAmount, vars.redeemTokens); /* We call the defense hook */ joetroller.redeemVerify(address(this), redeemer, vars.redeemAmount, vars.redeemTokens); return uint256(Error.NO_ERROR); } /** * @notice Transfers collateral tokens (this market) to the liquidator. * @dev Called only during an in-kind liquidation, or by liquidateBorrow during the liquidation of another JToken. * Its absolutely critical to use msg.sender as the seizer jToken and not a parameter. * @param seizerToken The contract seizing the collateral (i.e. borrowed jToken) * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of jTokens to seize * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function seizeInternal( address seizerToken, address liquidator, address borrower, uint256 seizeTokens ) internal returns (uint256) { /* Fail if seize not allowed */ uint256 allowed = joetroller.seizeAllowed(address(this), seizerToken, liquidator, borrower, seizeTokens); if (allowed != 0) { return failOpaque(Error.JOETROLLER_REJECTION, FailureInfo.LIQUIDATE_SEIZE_JOETROLLER_REJECTION, allowed); } /* * Return if seizeTokens is zero. * Put behind `seizeAllowed` for accuring potential JOE rewards. */ if (seizeTokens == 0) { return uint256(Error.NO_ERROR); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { return fail(Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER); } /* * We calculate the new borrower and liquidator token balances, failing on underflow/overflow: * borrowerTokensNew = accountTokens[borrower] - seizeTokens * liquidatorTokensNew = accountTokens[liquidator] + seizeTokens */ accountTokens[borrower] = sub_(accountTokens[borrower], seizeTokens); accountTokens[liquidator] = add_(accountTokens[liquidator], seizeTokens); /* Emit a Transfer event */ emit Transfer(borrower, liquidator, seizeTokens); /* We call the defense hook */ // unused function // joetroller.seizeVerify(address(this), seizerToken, liquidator, borrower, seizeTokens); return uint256(Error.NO_ERROR); } } contract RewardDistributorStorage { /** * @notice Administrator for this contract */ address public admin; /** * @notice Active brains of Unitroller */ Joetroller public joetroller; struct RewardMarketState { /// @notice The market's last updated joeBorrowIndex or joeSupplyIndex uint224 index; /// @notice The timestamp number the index was last updated at uint32 timestamp; } /// @notice The portion of reward rate that each market currently receives mapping(uint8 => mapping(address => uint256)) public rewardSpeeds; /// @notice The JOE/AVAX market supply state for each market mapping(uint8 => mapping(address => RewardMarketState)) public rewardSupplyState; /// @notice The JOE/AVAX market borrow state for each market mapping(uint8 => mapping(address => RewardMarketState)) public rewardBorrowState; /// @notice The JOE/AVAX borrow index for each market for each supplier as of the last time they accrued reward mapping(uint8 => mapping(address => mapping(address => uint256))) public rewardSupplierIndex; /// @notice The JOE/AVAX borrow index for each market for each borrower as of the last time they accrued reward mapping(uint8 => mapping(address => mapping(address => uint256))) public rewardBorrowerIndex; /// @notice The JOE/AVAX accrued but not yet transferred to each user mapping(uint8 => mapping(address => uint256)) public rewardAccrued; /// @notice The initial reward index for a market uint224 public constant rewardInitialIndex = 1e36; /// @notice JOE token contract address address public joeAddress; } contract RewardDistributor is RewardDistributorStorage, Exponential { /// @notice Emitted when a new reward speed is calculated for a market event RewardSpeedUpdated(uint8 rewardType, JToken indexed jToken, uint256 newSpeed); /// @notice Emitted when JOE/AVAX is distributed to a supplier event DistributedSupplierReward( uint8 rewardType, JToken indexed jToken, address indexed supplier, uint256 rewardDelta, uint256 rewardSupplyIndex ); /// @notice Emitted when JOE/AVAX is distributed to a borrower event DistributedBorrowerReward( uint8 rewardType, JToken indexed jToken, address indexed borrower, uint256 rewardDelta, uint256 rewardBorrowIndex ); /// @notice Emitted when JOE is granted by admin event RewardGranted(uint8 rewardType, address recipient, uint256 amount); bool private initialized; constructor() public { admin = msg.sender; } function initialize() public { require(!initialized, "RewardDistributor already initialized"); joetroller = Joetroller(msg.sender); initialized = true; } /** * @notice Checks caller is admin, or this contract is becoming the new implementation */ function adminOrInitializing() internal view returns (bool) { return msg.sender == admin || msg.sender == address(joetroller); } /** * @notice Set JOE/AVAX speed for a single market * @param rewardType 0 = QI, 1 = AVAX * @param jToken The market whose reward speed to update * @param rewardSpeed New reward speed for market */ function _setRewardSpeed( uint8 rewardType, JToken jToken, uint256 rewardSpeed ) public { require(rewardType <= 1, "rewardType is invalid"); require(adminOrInitializing(), "only admin can set reward speed"); setRewardSpeedInternal(rewardType, jToken, rewardSpeed); } /** * @notice Set JOE/AVAX speed for a single market * @param rewardType 0: JOE, 1: AVAX * @param jToken The market whose speed to update * @param newSpeed New JOE or AVAX speed for market */ function setRewardSpeedInternal( uint8 rewardType, JToken jToken, uint256 newSpeed ) internal { uint256 currentRewardSpeed = rewardSpeeds[rewardType][address(jToken)]; if (currentRewardSpeed != 0) { // note that JOE speed could be set to 0 to halt liquidity rewards for a market Exp memory borrowIndex = Exp({mantissa: jToken.borrowIndex()}); updateRewardSupplyIndex(rewardType, address(jToken)); updateRewardBorrowIndex(rewardType, address(jToken), borrowIndex); } else if (newSpeed != 0) { // Add the JOE market require(joetroller.isMarketListed(address(jToken)), "reward market is not listed"); if ( rewardSupplyState[rewardType][address(jToken)].index == 0 && rewardSupplyState[rewardType][address(jToken)].timestamp == 0 ) { rewardSupplyState[rewardType][address(jToken)] = RewardMarketState({ index: rewardInitialIndex, timestamp: safe32(getBlockTimestamp(), "block timestamp exceeds 32 bits") }); } if ( rewardBorrowState[rewardType][address(jToken)].index == 0 && rewardBorrowState[rewardType][address(jToken)].timestamp == 0 ) { rewardBorrowState[rewardType][address(jToken)] = RewardMarketState({ index: rewardInitialIndex, timestamp: safe32(getBlockTimestamp(), "block timestamp exceeds 32 bits") }); } } if (currentRewardSpeed != newSpeed) { rewardSpeeds[rewardType][address(jToken)] = newSpeed; emit RewardSpeedUpdated(rewardType, jToken, newSpeed); } } /** * @notice Accrue JOE/AVAX to the market by updating the supply index * @param rewardType 0: JOE, 1: AVAX * @param jToken The market whose supply index to update */ function updateRewardSupplyIndex(uint8 rewardType, address jToken) internal { require(rewardType <= 1, "rewardType is invalid"); RewardMarketState storage supplyState = rewardSupplyState[rewardType][jToken]; uint256 supplySpeed = rewardSpeeds[rewardType][jToken]; uint256 blockTimestamp = getBlockTimestamp(); uint256 deltaTimestamps = sub_(blockTimestamp, uint256(supplyState.timestamp)); if (deltaTimestamps > 0 && supplySpeed > 0) { uint256 supplyTokens = JToken(jToken).totalSupply(); uint256 rewardAccrued = mul_(deltaTimestamps, supplySpeed); Double memory ratio = supplyTokens > 0 ? fraction(rewardAccrued, supplyTokens) : Double({mantissa: 0}); Double memory index = add_(Double({mantissa: supplyState.index}), ratio); rewardSupplyState[rewardType][jToken] = RewardMarketState({ index: safe224(index.mantissa, "new index exceeds 224 bits"), timestamp: safe32(blockTimestamp, "block timestamp exceeds 32 bits") }); } else if (deltaTimestamps > 0) { supplyState.timestamp = safe32(blockTimestamp, "block timestamp exceeds 32 bits"); } } /** * @notice Accrue JOE/AVAX to the market by updating the borrow index * @param rewardType 0: JOE, 1: AVAX * @param jToken The market whose borrow index to update */ function updateRewardBorrowIndex( uint8 rewardType, address jToken, Exp memory marketBorrowIndex ) internal { require(rewardType <= 1, "rewardType is invalid"); RewardMarketState storage borrowState = rewardBorrowState[rewardType][jToken]; uint256 borrowSpeed = rewardSpeeds[rewardType][jToken]; uint256 blockTimestamp = getBlockTimestamp(); uint256 deltaTimestamps = sub_(blockTimestamp, uint256(borrowState.timestamp)); if (deltaTimestamps > 0 && borrowSpeed > 0) { uint256 borrowAmount = div_(JToken(jToken).totalBorrows(), marketBorrowIndex); uint256 rewardAccrued = mul_(deltaTimestamps, borrowSpeed); Double memory ratio = borrowAmount > 0 ? fraction(rewardAccrued, borrowAmount) : Double({mantissa: 0}); Double memory index = add_(Double({mantissa: borrowState.index}), ratio); rewardBorrowState[rewardType][jToken] = RewardMarketState({ index: safe224(index.mantissa, "new index exceeds 224 bits"), timestamp: safe32(blockTimestamp, "block timestamp exceeds 32 bits") }); } else if (deltaTimestamps > 0) { borrowState.timestamp = safe32(blockTimestamp, "block timestamp exceeds 32 bits"); } } /** * @notice Calculate JOE/AVAX accrued by a supplier and possibly transfer it to them * @param rewardType 0: JOE, 1: AVAX * @param jToken The market in which the supplier is interacting * @param supplier The address of the supplier to distribute JOE/AVAX to */ function distributeSupplierReward( uint8 rewardType, address jToken, address supplier ) internal { require(rewardType <= 1, "rewardType is invalid"); RewardMarketState storage supplyState = rewardSupplyState[rewardType][jToken]; Double memory supplyIndex = Double({mantissa: supplyState.index}); Double memory supplierIndex = Double({mantissa: rewardSupplierIndex[rewardType][jToken][supplier]}); rewardSupplierIndex[rewardType][jToken][supplier] = supplyIndex.mantissa; if (supplierIndex.mantissa == 0 && supplyIndex.mantissa > 0) { supplierIndex.mantissa = rewardInitialIndex; } Double memory deltaIndex = sub_(supplyIndex, supplierIndex); uint256 supplierTokens = JToken(jToken).balanceOf(supplier); uint256 supplierDelta = mul_(supplierTokens, deltaIndex); uint256 supplierAccrued = add_(rewardAccrued[rewardType][supplier], supplierDelta); rewardAccrued[rewardType][supplier] = supplierAccrued; emit DistributedSupplierReward(rewardType, JToken(jToken), supplier, supplierDelta, supplyIndex.mantissa); } /** * @notice Calculate JOE/AVAX accrued by a borrower and possibly transfer it to them * @dev Borrowers will not begin to accrue until after the first interaction with the protocol. * @param rewardType 0: JOE, 1: AVAX * @param jToken The market in which the borrower is interacting * @param borrower The address of the borrower to distribute JOE/AVAX to */ function distributeBorrowerReward( uint8 rewardType, address jToken, address borrower, Exp memory marketBorrowIndex ) internal { require(rewardType <= 1, "rewardType is invalid"); RewardMarketState storage borrowState = rewardBorrowState[rewardType][jToken]; Double memory borrowIndex = Double({mantissa: borrowState.index}); Double memory borrowerIndex = Double({mantissa: rewardBorrowerIndex[rewardType][jToken][borrower]}); rewardBorrowerIndex[rewardType][jToken][borrower] = borrowIndex.mantissa; if (borrowerIndex.mantissa > 0) { Double memory deltaIndex = sub_(borrowIndex, borrowerIndex); uint256 borrowerAmount = div_(JToken(jToken).borrowBalanceStored(borrower), marketBorrowIndex); uint256 borrowerDelta = mul_(borrowerAmount, deltaIndex); uint256 borrowerAccrued = add_(rewardAccrued[rewardType][borrower], borrowerDelta); rewardAccrued[rewardType][borrower] = borrowerAccrued; emit DistributedBorrowerReward(rewardType, JToken(jToken), borrower, borrowerDelta, borrowIndex.mantissa); } } /** * @notice Refactored function to calc and rewards accounts supplier rewards * @param jToken The market to verify the mint against * @param supplier The supplier to be rewarded */ function updateAndDistributeSupplierRewardsForToken(address jToken, address supplier) external { require(adminOrInitializing(), "only admin can update and distribute supplier rewards"); for (uint8 rewardType = 0; rewardType <= 1; rewardType++) { updateRewardSupplyIndex(rewardType, jToken); distributeSupplierReward(rewardType, jToken, supplier); } } /** * @notice Refactored function to calc and rewards accounts supplier rewards * @param jToken The market to verify the mint against * @param borrower Borrower to be rewarded */ function updateAndDistributeBorrowerRewardsForToken( address jToken, address borrower, Exp calldata marketBorrowIndex ) external { require(adminOrInitializing(), "only admin can update and distribute borrower rewards"); for (uint8 rewardType = 0; rewardType <= 1; rewardType++) { updateRewardBorrowIndex(rewardType, jToken, marketBorrowIndex); distributeBorrowerReward(rewardType, jToken, borrower, marketBorrowIndex); } } /*** User functions ***/ /** * @notice Claim all the JOE/AVAX accrued by holder in all markets * @param holder The address to claim JOE/AVAX for */ function claimReward(uint8 rewardType, address payable holder) public { return claimReward(rewardType, holder, joetroller.getAllMarkets()); } /** * @notice Claim all the JOE/AVAX accrued by holder in the specified markets * @param holder The address to claim JOE/AVAX for * @param jTokens The list of markets to claim JOE/AVAX in */ function claimReward( uint8 rewardType, address payable holder, JToken[] memory jTokens ) public { address payable[] memory holders = new address payable[](1); holders[0] = holder; claimReward(rewardType, holders, jTokens, true, true); } /** * @notice Claim all JOE/AVAX accrued by the holders * @param rewardType 0 = JOE, 1 = AVAX * @param holders The addresses to claim JOE/AVAX for * @param jTokens The list of markets to claim JOE/AVAX in * @param borrowers Whether or not to claim JOE/AVAX earned by borrowing * @param suppliers Whether or not to claim JOE/AVAX earned by supplying */ function claimReward( uint8 rewardType, address payable[] memory holders, JToken[] memory jTokens, bool borrowers, bool suppliers ) public payable { require(rewardType <= 1, "rewardType is invalid"); for (uint256 i = 0; i < jTokens.length; i++) { JToken jToken = jTokens[i]; require(joetroller.isMarketListed(address(jToken)), "market must be listed"); if (borrowers == true) { Exp memory borrowIndex = Exp({mantissa: jToken.borrowIndex()}); updateRewardBorrowIndex(rewardType, address(jToken), borrowIndex); for (uint256 j = 0; j < holders.length; j++) { distributeBorrowerReward(rewardType, address(jToken), holders[j], borrowIndex); rewardAccrued[rewardType][holders[j]] = grantRewardInternal( rewardType, holders[j], rewardAccrued[rewardType][holders[j]] ); } } if (suppliers == true) { updateRewardSupplyIndex(rewardType, address(jToken)); for (uint256 j = 0; j < holders.length; j++) { distributeSupplierReward(rewardType, address(jToken), holders[j]); rewardAccrued[rewardType][holders[j]] = grantRewardInternal( rewardType, holders[j], rewardAccrued[rewardType][holders[j]] ); } } } } /** * @notice Transfer JOE/AVAX to the user * @dev Note: If there is not enough JOE/AVAX, we do not perform the transfer all. * @param user The address of the user to transfer JOE/AVAX to * @param amount The amount of JOE/AVAX to (possibly) transfer * @return The amount of JOE/AVAX which was NOT transferred to the user */ function grantRewardInternal( uint256 rewardType, address payable user, uint256 amount ) internal returns (uint256) { if (rewardType == 0) { EIP20Interface joe = EIP20Interface(joeAddress); uint256 joeRemaining = joe.balanceOf(address(this)); if (amount > 0 && amount <= joeRemaining) { joe.transfer(user, amount); return 0; } } else if (rewardType == 1) { uint256 avaxRemaining = address(this).balance; if (amount > 0 && amount <= avaxRemaining) { user.transfer(amount); return 0; } } return amount; } /*** Joe Distribution Admin ***/ /** * @notice Transfer JOE to the recipient * @dev Note: If there is not enough JOE, we do not perform the transfer all. * @param recipient The address of the recipient to transfer JOE to * @param amount The amount of JOE to (possibly) transfer */ function _grantReward( uint8 rewardType, address payable recipient, uint256 amount ) public { require(adminOrInitializing(), "only admin can grant joe"); uint256 amountLeft = grantRewardInternal(rewardType, recipient, amount); require(amountLeft == 0, "insufficient joe for grant"); emit RewardGranted(rewardType, recipient, amount); } /** * @notice Set the JOE token address */ function setJoeAddress(address newJoeAddress) public { require(msg.sender == admin, "only admin can set JOE"); joeAddress = newJoeAddress; } /** * @notice Set the Joetroller address */ function setJoetroller(address _joetroller) public { require(msg.sender == admin, "only admin can set Joetroller"); joetroller = Joetroller(_joetroller); } /** * @notice Set the admin */ function setAdmin(address _newAdmin) public { require(msg.sender == admin, "only admin can set admin"); admin = _newAdmin; } /** * @notice payable function needed to receive AVAX */ function() external payable {} function getBlockTimestamp() public view returns (uint256) { return block.timestamp; } } /** * @title JoetrollerCore * @dev Storage for the joetroller is at this address, while execution is delegated to the `implementation`. * JTokens should reference this contract as their joetroller. */ contract Unitroller is UnitrollerAdminStorage, JoetrollerErrorReporter { /** * @notice Emitted when pendingImplementation is changed */ event NewPendingImplementation(address oldPendingImplementation, address newPendingImplementation); /** * @notice Emitted when pendingImplementation is accepted, which means joetroller implementation is updated */ event NewImplementation(address oldImplementation, address newImplementation); /** * @notice Emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); constructor() public { // Set admin to caller admin = msg.sender; } /*** Admin Functions ***/ function _setPendingImplementation(address newPendingImplementation) public returns (uint256) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_IMPLEMENTATION_OWNER_CHECK); } address oldPendingImplementation = pendingImplementation; pendingImplementation = newPendingImplementation; emit NewPendingImplementation(oldPendingImplementation, pendingImplementation); return uint256(Error.NO_ERROR); } /** * @notice Accepts new implementation of joetroller. msg.sender must be pendingImplementation * @dev Admin function for new implementation to accept it's role as implementation * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptImplementation() public returns (uint256) { // Check caller is pendingImplementation and pendingImplementation ≠ address(0) if (msg.sender != pendingImplementation || pendingImplementation == address(0)) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_PENDING_IMPLEMENTATION_ADDRESS_CHECK); } // Save current values for inclusion in log address oldImplementation = implementation; address oldPendingImplementation = pendingImplementation; implementation = pendingImplementation; pendingImplementation = address(0); emit NewImplementation(oldImplementation, implementation); emit NewPendingImplementation(oldPendingImplementation, pendingImplementation); return uint256(Error.NO_ERROR); } /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPendingAdmin(address newPendingAdmin) public returns (uint256) { // Check caller = admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); return uint256(Error.NO_ERROR); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _acceptAdmin() public returns (uint256) { // Check caller is pendingAdmin if (msg.sender != pendingAdmin) { return fail(Error.UNAUTHORIZED, FailureInfo.ACCEPT_ADMIN_PENDING_ADMIN_CHECK); } // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint256(Error.NO_ERROR); } /** * @dev Delegates execution to an implementation contract. * It returns to the external caller whatever the implementation returns * or forwards reverts. */ function() external payable { // delegate all other functions to current implementation (bool success, ) = implementation.delegatecall(msg.data); assembly { let free_mem_ptr := mload(0x40) returndatacopy(free_mem_ptr, 0, returndatasize) switch success case 0 { revert(free_mem_ptr, returndatasize) } default { return(free_mem_ptr, returndatasize) } } } } /** * @title Compound's Joetroller Contract * @author Compound (modified by Cream) */ contract Joetroller is JoetrollerV1Storage, JoetrollerInterface, JoetrollerErrorReporter, Exponential { /// @notice Emitted when an admin supports a market event MarketListed(JToken jToken); /// @notice Emitted when an admin delists a market event MarketDelisted(JToken jToken); /// @notice Emitted when an account enters a market event MarketEntered(JToken jToken, address account); /// @notice Emitted when an account exits a market event MarketExited(JToken jToken, address account); /// @notice Emitted when close factor is changed by admin event NewCloseFactor(uint256 oldCloseFactorMantissa, uint256 newCloseFactorMantissa); /// @notice Emitted when a collateral factor is changed by admin event NewCollateralFactor(JToken jToken, uint256 oldCollateralFactorMantissa, uint256 newCollateralFactorMantissa); /// @notice Emitted when liquidation incentive is changed by admin event NewLiquidationIncentive(uint256 oldLiquidationIncentiveMantissa, uint256 newLiquidationIncentiveMantissa); /// @notice Emitted when price oracle is changed event NewPriceOracle(PriceOracle oldPriceOracle, PriceOracle newPriceOracle); /// @notice Emitted when pause guardian is changed event NewPauseGuardian(address oldPauseGuardian, address newPauseGuardian); /// @notice Emitted when an action is paused globally event ActionPaused(string action, bool pauseState); /// @notice Emitted when an action is paused on a market event ActionPaused(JToken jToken, string action, bool pauseState); /// @notice Emitted when borrow cap for a jToken is changed event NewBorrowCap(JToken indexed jToken, uint256 newBorrowCap); /// @notice Emitted when borrow cap guardian is changed event NewBorrowCapGuardian(address oldBorrowCapGuardian, address newBorrowCapGuardian); /// @notice Emitted when supply cap for a jToken is changed event NewSupplyCap(JToken indexed jToken, uint256 newSupplyCap); /// @notice Emitted when supply cap guardian is changed event NewSupplyCapGuardian(address oldSupplyCapGuardian, address newSupplyCapGuardian); /// @notice Emitted when protocol's credit limit has changed event CreditLimitChanged(address protocol, uint256 creditLimit); /// @notice Emitted when jToken version is changed event NewJTokenVersion(JToken jToken, Version oldVersion, Version newVersion); // No collateralFactorMantissa may exceed this value uint256 internal constant collateralFactorMaxMantissa = 0.9e18; // 0.9 constructor() public { admin = msg.sender; } /** * @notice Return all of the markets * @dev The automatic getter may be used to access an individual market. * @return The list of market addresses */ function getAllMarkets() public view returns (JToken[] memory) { return allMarkets; } function getBlockTimestamp() public view returns (uint256) { return block.timestamp; } /*** Assets You Are In ***/ /** * @notice Returns the assets an account has entered * @param account The address of the account to pull assets for * @return A dynamic list with the assets the account has entered */ function getAssetsIn(address account) external view returns (JToken[] memory) { JToken[] memory assetsIn = accountAssets[account]; return assetsIn; } /** * @notice Returns whether the given account is entered in the given asset * @param account The address of the account to check * @param jToken The jToken to check * @return True if the account is in the asset, otherwise false. */ function checkMembership(address account, JToken jToken) external view returns (bool) { return markets[address(jToken)].accountMembership[account]; } /** * @notice Add assets to be included in account liquidity calculation * @param jTokens The list of addresses of the jToken markets to be enabled * @return Success indicator for whether each corresponding market was entered */ function enterMarkets(address[] memory jTokens) public returns (uint256[] memory) { uint256 len = jTokens.length; uint256[] memory results = new uint256[](len); for (uint256 i = 0; i < len; i++) { JToken jToken = JToken(jTokens[i]); results[i] = uint256(addToMarketInternal(jToken, msg.sender)); } return results; } /** * @notice Add the market to the borrower's "assets in" for liquidity calculations * @param jToken The market to enter * @param borrower The address of the account to modify * @return Success indicator for whether the market was entered */ function addToMarketInternal(JToken jToken, address borrower) internal returns (Error) { Market storage marketToJoin = markets[address(jToken)]; if (!marketToJoin.isListed) { // market is not listed, cannot join return Error.MARKET_NOT_LISTED; } if (marketToJoin.version == Version.COLLATERALCAP) { // register collateral for the borrower if the token is CollateralCap version. JCollateralCapErc20Interface(address(jToken)).registerCollateral(borrower); } if (marketToJoin.accountMembership[borrower] == true) { // already joined return Error.NO_ERROR; } // survived the gauntlet, add to list // NOTE: we store these somewhat redundantly as a significant optimization // this avoids having to iterate through the list for the most common use cases // that is, only when we need to perform liquidity checks // and not whenever we want to check if an account is in a particular market marketToJoin.accountMembership[borrower] = true; accountAssets[borrower].push(jToken); emit MarketEntered(jToken, borrower); return Error.NO_ERROR; } /** * @notice Removes asset from sender's account liquidity calculation * @dev Sender must not have an outstanding borrow balance in the asset, * or be providing necessary collateral for an outstanding borrow. * @param jTokenAddress The address of the asset to be removed * @return Whether or not the account successfully exited the market */ function exitMarket(address jTokenAddress) external returns (uint256) { JToken jToken = JToken(jTokenAddress); /* Get sender tokensHeld and amountOwed underlying from the jToken */ (uint256 oErr, uint256 tokensHeld, uint256 amountOwed, ) = jToken.getAccountSnapshot(msg.sender); require(oErr == 0, "exitMarket: getAccountSnapshot failed"); // semi-opaque error code /* Fail if the sender has a borrow balance */ if (amountOwed != 0) { return fail(Error.NONZERO_BORROW_BALANCE, FailureInfo.EXIT_MARKET_BALANCE_OWED); } /* Fail if the sender is not permitted to redeem all of their tokens */ uint256 allowed = redeemAllowedInternal(jTokenAddress, msg.sender, tokensHeld); if (allowed != 0) { return failOpaque(Error.REJECTION, FailureInfo.EXIT_MARKET_REJECTION, allowed); } Market storage marketToExit = markets[jTokenAddress]; if (marketToExit.version == Version.COLLATERALCAP) { JCollateralCapErc20Interface(jTokenAddress).unregisterCollateral(msg.sender); } /* Return true if the sender is not already ‘in’ the market */ if (!marketToExit.accountMembership[msg.sender]) { return uint256(Error.NO_ERROR); } /* Set jToken account membership to false */ delete marketToExit.accountMembership[msg.sender]; /* Delete jToken from the account’s list of assets */ // load into memory for faster iteration JToken[] memory userAssetList = accountAssets[msg.sender]; uint256 len = userAssetList.length; uint256 assetIndex = len; for (uint256 i = 0; i < len; i++) { if (userAssetList[i] == jToken) { assetIndex = i; break; } } // We *must* have found the asset in the list or our redundant data structure is broken assert(assetIndex < len); // copy last item in list to location of item to be removed, reduce length by 1 JToken[] storage storedList = accountAssets[msg.sender]; if (assetIndex != storedList.length - 1) { storedList[assetIndex] = storedList[storedList.length - 1]; } storedList.length--; emit MarketExited(jToken, msg.sender); return uint256(Error.NO_ERROR); } /** * @notice Return whether a specific market is listed or not * @param jTokenAddress The address of the asset to be checked * @return Whether or not the market is listed */ function isMarketListed(address jTokenAddress) public view returns (bool) { return markets[jTokenAddress].isListed; } /*** Policy Hooks ***/ /** * @notice Checks if the account should be allowed to mint tokens in the given market * @param jToken The market to verify the mint against * @param minter The account which would get the minted tokens * @param mintAmount The amount of underlying being supplied to the market in exchange for tokens * @return 0 if the mint is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function mintAllowed( address jToken, address minter, uint256 mintAmount ) external returns (uint256) { // Pausing is a very serious situation - we revert to sound the alarms require(!mintGuardianPaused[jToken], "mint is paused"); require(!isCreditAccount(minter), "credit account cannot mint"); if (!isMarketListed(jToken)) { return uint256(Error.MARKET_NOT_LISTED); } uint256 supplyCap = supplyCaps[jToken]; // Supply cap of 0 corresponds to unlimited supplying if (supplyCap != 0) { uint256 totalCash = JToken(jToken).getCash(); uint256 totalBorrows = JToken(jToken).totalBorrows(); uint256 totalReserves = JToken(jToken).totalReserves(); // totalSupplies = totalCash + totalBorrows - totalReserves (MathError mathErr, uint256 totalSupplies) = addThenSubUInt(totalCash, totalBorrows, totalReserves); require(mathErr == MathError.NO_ERROR, "totalSupplies failed"); uint256 nextTotalSupplies = add_(totalSupplies, mintAmount); require(nextTotalSupplies < supplyCap, "market supply cap reached"); } // Keep the flywheel moving RewardDistributor(rewardDistributor).updateAndDistributeSupplierRewardsForToken(jToken, minter); return uint256(Error.NO_ERROR); } /** * @notice Validates mint and reverts on rejection. May emit logs. * @param jToken Asset being minted * @param minter The address minting the tokens * @param actualMintAmount The amount of the underlying asset being minted * @param mintTokens The number of tokens being minted */ function mintVerify( address jToken, address minter, uint256 actualMintAmount, uint256 mintTokens ) external { // Shh - currently unused jToken; minter; actualMintAmount; mintTokens; // Shh - we don't ever want this hook to be marked pure if (false) { closeFactorMantissa = closeFactorMantissa; } } /** * @notice Checks if the account should be allowed to redeem tokens in the given market * @param jToken The market to verify the redeem against * @param redeemer The account which would redeem the tokens * @param redeemTokens The number of jTokens to exchange for the underlying asset in the market * @return 0 if the redeem is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function redeemAllowed( address jToken, address redeemer, uint256 redeemTokens ) external returns (uint256) { uint256 allowed = redeemAllowedInternal(jToken, redeemer, redeemTokens); if (allowed != uint256(Error.NO_ERROR)) { return allowed; } // Keep the flywheel going RewardDistributor(rewardDistributor).updateAndDistributeSupplierRewardsForToken(jToken, redeemer); return uint256(Error.NO_ERROR); } function redeemAllowedInternal( address jToken, address redeemer, uint256 redeemTokens ) internal view returns (uint256) { if (!isMarketListed(jToken)) { return uint256(Error.MARKET_NOT_LISTED); } /* If the redeemer is not 'in' the market, then we can bypass the liquidity check */ if (!markets[jToken].accountMembership[redeemer]) { return uint256(Error.NO_ERROR); } /* Otherwise, perform a hypothetical liquidity check to guard against shortfall */ (Error err, , uint256 shortfall) = getHypotheticalAccountLiquidityInternal( redeemer, JToken(jToken), redeemTokens, 0 ); if (err != Error.NO_ERROR) { return uint256(err); } if (shortfall > 0) { return uint256(Error.INSUFFICIENT_LIQUIDITY); } return uint256(Error.NO_ERROR); } /** * @notice Validates redeem and reverts on rejection. May emit logs. * @param jToken Asset being redeemed * @param redeemer The address redeeming the tokens * @param redeemAmount The amount of the underlying asset being redeemed * @param redeemTokens The number of tokens being redeemed */ function redeemVerify( address jToken, address redeemer, uint256 redeemAmount, uint256 redeemTokens ) external { // Shh - currently unused jToken; redeemer; // Require tokens is zero or amount is also zero if (redeemTokens == 0 && redeemAmount > 0) { revert("redeemTokens zero"); } } /** * @notice Checks if the account should be allowed to borrow the underlying asset of the given market * @param jToken The market to verify the borrow against * @param borrower The account which would borrow the asset * @param borrowAmount The amount of underlying the account would borrow * @return 0 if the borrow is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function borrowAllowed( address jToken, address borrower, uint256 borrowAmount ) external returns (uint256) { // Pausing is a very serious situation - we revert to sound the alarms require(!borrowGuardianPaused[jToken], "borrow is paused"); if (!isMarketListed(jToken)) { return uint256(Error.MARKET_NOT_LISTED); } if (!markets[jToken].accountMembership[borrower]) { // only jTokens may call borrowAllowed if borrower not in market require(msg.sender == jToken, "sender must be jToken"); // attempt to add borrower to the market Error err = addToMarketInternal(JToken(jToken), borrower); if (err != Error.NO_ERROR) { return uint256(err); } // it should be impossible to break the important invariant assert(markets[jToken].accountMembership[borrower]); } if (oracle.getUnderlyingPrice(JToken(jToken)) == 0) { return uint256(Error.PRICE_ERROR); } uint256 borrowCap = borrowCaps[jToken]; // Borrow cap of 0 corresponds to unlimited borrowing if (borrowCap != 0) { uint256 totalBorrows = JToken(jToken).totalBorrows(); uint256 nextTotalBorrows = add_(totalBorrows, borrowAmount); require(nextTotalBorrows < borrowCap, "market borrow cap reached"); } (Error err, , uint256 shortfall) = getHypotheticalAccountLiquidityInternal( borrower, JToken(jToken), 0, borrowAmount ); if (err != Error.NO_ERROR) { return uint256(err); } if (shortfall > 0) { return uint256(Error.INSUFFICIENT_LIQUIDITY); } // Keep the flywheel going Exp memory borrowIndex = Exp({mantissa: JToken(jToken).borrowIndex()}); RewardDistributor(rewardDistributor).updateAndDistributeBorrowerRewardsForToken(jToken, borrower, borrowIndex); return uint256(Error.NO_ERROR); } /** * @notice Validates borrow and reverts on rejection. May emit logs. * @param jToken Asset whose underlying is being borrowed * @param borrower The address borrowing the underlying * @param borrowAmount The amount of the underlying asset requested to borrow */ function borrowVerify( address jToken, address borrower, uint256 borrowAmount ) external { // Shh - currently unused jToken; borrower; borrowAmount; // Shh - we don't ever want this hook to be marked pure if (false) { closeFactorMantissa = closeFactorMantissa; } } /** * @notice Checks if the account should be allowed to repay a borrow in the given market * @param jToken The market to verify the repay against * @param payer The account which would repay the asset * @param borrower The account which borrowed the asset * @param repayAmount The amount of the underlying asset the account would repay * @return 0 if the repay is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function repayBorrowAllowed( address jToken, address payer, address borrower, uint256 repayAmount ) external returns (uint256) { // Shh - currently unused payer; borrower; repayAmount; if (!isMarketListed(jToken)) { return uint256(Error.MARKET_NOT_LISTED); } // Keep the flywheel going Exp memory borrowIndex = Exp({mantissa: JToken(jToken).borrowIndex()}); RewardDistributor(rewardDistributor).updateAndDistributeBorrowerRewardsForToken(jToken, borrower, borrowIndex); return uint256(Error.NO_ERROR); } /** * @notice Validates repayBorrow and reverts on rejection. May emit logs. * @param jToken Asset being repaid * @param payer The address repaying the borrow * @param borrower The address of the borrower * @param actualRepayAmount The amount of underlying being repaid */ function repayBorrowVerify( address jToken, address payer, address borrower, uint256 actualRepayAmount, uint256 borrowerIndex ) external { // Shh - currently unused jToken; payer; borrower; actualRepayAmount; borrowerIndex; // Shh - we don't ever want this hook to be marked pure if (false) { closeFactorMantissa = closeFactorMantissa; } } /** * @notice Checks if the liquidation should be allowed to occur * @param jTokenBorrowed Asset which was borrowed by the borrower * @param jTokenCollateral Asset which was used as collateral and will be seized * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param repayAmount The amount of underlying being repaid */ function liquidateBorrowAllowed( address jTokenBorrowed, address jTokenCollateral, address liquidator, address borrower, uint256 repayAmount ) external returns (uint256) { require(!isCreditAccount(borrower), "cannot liquidate credit account"); // Shh - currently unused liquidator; if (!isMarketListed(jTokenBorrowed) || !isMarketListed(jTokenCollateral)) { return uint256(Error.MARKET_NOT_LISTED); } /* The borrower must have shortfall in order to be liquidatable */ (Error err, , uint256 shortfall) = getAccountLiquidityInternal(borrower); if (err != Error.NO_ERROR) { return uint256(err); } if (shortfall == 0) { return uint256(Error.INSUFFICIENT_SHORTFALL); } /* The liquidator may not repay more than what is allowed by the closeFactor */ uint256 borrowBalance = JToken(jTokenBorrowed).borrowBalanceStored(borrower); uint256 maxClose = mul_ScalarTruncate(Exp({mantissa: closeFactorMantissa}), borrowBalance); if (repayAmount > maxClose) { return uint256(Error.TOO_MUCH_REPAY); } return uint256(Error.NO_ERROR); } /** * @notice Validates liquidateBorrow and reverts on rejection. May emit logs. * @param jTokenBorrowed Asset which was borrowed by the borrower * @param jTokenCollateral Asset which was used as collateral and will be seized * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param actualRepayAmount The amount of underlying being repaid */ function liquidateBorrowVerify( address jTokenBorrowed, address jTokenCollateral, address liquidator, address borrower, uint256 actualRepayAmount, uint256 seizeTokens ) external { // Shh - currently unused jTokenBorrowed; jTokenCollateral; liquidator; borrower; actualRepayAmount; seizeTokens; // Shh - we don't ever want this hook to be marked pure if (false) { closeFactorMantissa = closeFactorMantissa; } } /** * @notice Checks if the seizing of assets should be allowed to occur * @param jTokenCollateral Asset which was used as collateral and will be seized * @param jTokenBorrowed Asset which was borrowed by the borrower * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param seizeTokens The number of collateral tokens to seize */ function seizeAllowed( address jTokenCollateral, address jTokenBorrowed, address liquidator, address borrower, uint256 seizeTokens ) external returns (uint256) { // Pausing is a very serious situation - we revert to sound the alarms require(!seizeGuardianPaused, "seize is paused"); require(!isCreditAccount(borrower), "cannot sieze from credit account"); // Shh - currently unused liquidator; seizeTokens; if (!isMarketListed(jTokenCollateral) || !isMarketListed(jTokenBorrowed)) { return uint256(Error.MARKET_NOT_LISTED); } if (JToken(jTokenCollateral).joetroller() != JToken(jTokenBorrowed).joetroller()) { return uint256(Error.JOETROLLER_MISMATCH); } // Keep the flywheel moving RewardDistributor(rewardDistributor).updateAndDistributeSupplierRewardsForToken(jTokenCollateral, borrower); RewardDistributor(rewardDistributor).updateAndDistributeSupplierRewardsForToken(jTokenCollateral, liquidator); return uint256(Error.NO_ERROR); } /** * @notice Validates seize and reverts on rejection. May emit logs. * @param jTokenCollateral Asset which was used as collateral and will be seized * @param jTokenBorrowed Asset which was borrowed by the borrower * @param liquidator The address repaying the borrow and seizing the collateral * @param borrower The address of the borrower * @param seizeTokens The number of collateral tokens to seize */ function seizeVerify( address jTokenCollateral, address jTokenBorrowed, address liquidator, address borrower, uint256 seizeTokens ) external { // Shh - currently unused jTokenCollateral; jTokenBorrowed; liquidator; borrower; seizeTokens; // Shh - we don't ever want this hook to be marked pure if (false) { closeFactorMantissa = closeFactorMantissa; } } /** * @notice Checks if the account should be allowed to transfer tokens in the given market * @param jToken The market to verify the transfer against * @param src The account which sources the tokens * @param dst The account which receives the tokens * @param transferTokens The number of jTokens to transfer * @return 0 if the transfer is allowed, otherwise a semi-opaque error code (See ErrorReporter.sol) */ function transferAllowed( address jToken, address src, address dst, uint256 transferTokens ) external returns (uint256) { // Pausing is a very serious situation - we revert to sound the alarms require(!transferGuardianPaused, "transfer is paused"); require(!isCreditAccount(dst), "cannot transfer to a credit account"); // Shh - currently unused dst; // Currently the only consideration is whether or not // the src is allowed to redeem this many tokens uint256 allowed = redeemAllowedInternal(jToken, src, transferTokens); if (allowed != uint256(Error.NO_ERROR)) { return allowed; } // Keep the flywheel moving RewardDistributor(rewardDistributor).updateAndDistributeSupplierRewardsForToken(jToken, src); RewardDistributor(rewardDistributor).updateAndDistributeSupplierRewardsForToken(jToken, dst); return uint256(Error.NO_ERROR); } /** * @notice Validates transfer and reverts on rejection. May emit logs. * @param jToken Asset being transferred * @param src The account which sources the tokens * @param dst The account which receives the tokens * @param transferTokens The number of jTokens to transfer */ function transferVerify( address jToken, address src, address dst, uint256 transferTokens ) external { // Shh - currently unused jToken; src; dst; transferTokens; // Shh - we don't ever want this hook to be marked pure if (false) { closeFactorMantissa = closeFactorMantissa; } } /** * @notice Checks if the account should be allowed to transfer tokens in the given market * @param jToken The market to verify the transfer against * @param receiver The account which receives the tokens * @param amount The amount of the tokens * @param params The other parameters */ function flashloanAllowed( address jToken, address receiver, uint256 amount, bytes calldata params ) external view returns (bool) { return !flashloanGuardianPaused[jToken]; } /** * @notice Update JToken's version. * @param jToken Version of the asset being updated * @param newVersion The new version */ function updateJTokenVersion(address jToken, Version newVersion) external { require(msg.sender == jToken, "only jToken could update its version"); // This function will be called when a new JToken implementation becomes active. // If a new JToken is newly created, this market is not listed yet. The version of // this market will be taken care of when calling `_supportMarket`. if (isMarketListed(jToken)) { Version oldVersion = markets[jToken].version; markets[jToken].version = newVersion; emit NewJTokenVersion(JToken(jToken), oldVersion, newVersion); } } /** * @notice Check if the account is a credit account * @param account The account needs to be checked * @return The account is a credit account or not */ function isCreditAccount(address account) public view returns (bool) { return creditLimits[account] > 0; } /*** Liquidity/Liquidation Calculations ***/ /** * @dev Local vars for avoiding stack-depth limits in calculating account liquidity. * Note that `jTokenBalance` is the number of jTokens the account owns in the market, * whereas `borrowBalance` is the amount of underlying that the account has borrowed. */ struct AccountLiquidityLocalVars { uint256 sumCollateral; uint256 sumBorrowPlusEffects; uint256 jTokenBalance; uint256 borrowBalance; uint256 exchangeRateMantissa; uint256 oraclePriceMantissa; Exp collateralFactor; Exp exchangeRate; Exp oraclePrice; Exp tokensToDenom; } /** * @notice Determine the current account liquidity wrt collateral requirements * @return (possible error code (semi-opaque), account liquidity in excess of collateral requirements, * account shortfall below collateral requirements) */ function getAccountLiquidity(address account) public view returns ( uint256, uint256, uint256 ) { (Error err, uint256 liquidity, uint256 shortfall) = getHypotheticalAccountLiquidityInternal( account, JToken(0), 0, 0 ); return (uint256(err), liquidity, shortfall); } /** * @notice Determine the current account liquidity wrt collateral requirements * @return (possible error code, account liquidity in excess of collateral requirements, * account shortfall below collateral requirements) */ function getAccountLiquidityInternal(address account) internal view returns ( Error, uint256, uint256 ) { return getHypotheticalAccountLiquidityInternal(account, JToken(0), 0, 0); } /** * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed * @param jTokenModify The market to hypothetically redeem/borrow in * @param account The account to determine liquidity for * @param redeemTokens The number of tokens to hypothetically redeem * @param borrowAmount The amount of underlying to hypothetically borrow * @return (possible error code (semi-opaque), hypothetical account liquidity in excess of collateral requirements, * hypothetical account shortfall below collateral requirements) */ function getHypotheticalAccountLiquidity( address account, address jTokenModify, uint256 redeemTokens, uint256 borrowAmount ) public view returns ( uint256, uint256, uint256 ) { (Error err, uint256 liquidity, uint256 shortfall) = getHypotheticalAccountLiquidityInternal( account, JToken(jTokenModify), redeemTokens, borrowAmount ); return (uint256(err), liquidity, shortfall); } /** * @notice Determine what the account liquidity would be if the given amounts were redeemed/borrowed * @param jTokenModify The market to hypothetically redeem/borrow in * @param account The account to determine liquidity for * @param redeemTokens The number of tokens to hypothetically redeem * @param borrowAmount The amount of underlying to hypothetically borrow * @dev Note that we calculate the exchangeRateStored for each collateral jToken using stored data, * without calculating accumulated interest. * @return (possible error code, hypothetical account liquidity in excess of collateral requirements, * hypothetical account shortfall below collateral requirements) */ function getHypotheticalAccountLiquidityInternal( address account, JToken jTokenModify, uint256 redeemTokens, uint256 borrowAmount ) internal view returns ( Error, uint256, uint256 ) { // If credit limit is set to MAX, no need to check account liquidity. if (creditLimits[account] == uint256(-1)) { return (Error.NO_ERROR, uint256(-1), 0); } AccountLiquidityLocalVars memory vars; // Holds all our calculation results uint256 oErr; // For each asset the account is in JToken[] memory assets = accountAssets[account]; for (uint256 i = 0; i < assets.length; i++) { JToken asset = assets[i]; // Read the balances and exchange rate from the jToken (oErr, vars.jTokenBalance, vars.borrowBalance, vars.exchangeRateMantissa) = asset.getAccountSnapshot( account ); if (oErr != 0) { // semi-opaque error code, we assume NO_ERROR == 0 is invariant between upgrades return (Error.SNAPSHOT_ERROR, 0, 0); } // Unlike compound protocol, getUnderlyingPrice is relatively expensive because we use ChainLink as our primary price feed. // If user has no supply / borrow balance on this asset, and user is not redeeming / borrowing this asset, skip it. if (vars.jTokenBalance == 0 && vars.borrowBalance == 0 && asset != jTokenModify) { continue; } vars.collateralFactor = Exp({mantissa: markets[address(asset)].collateralFactorMantissa}); vars.exchangeRate = Exp({mantissa: vars.exchangeRateMantissa}); // Get the normalized price of the asset vars.oraclePriceMantissa = oracle.getUnderlyingPrice(asset); if (vars.oraclePriceMantissa == 0) { return (Error.PRICE_ERROR, 0, 0); } vars.oraclePrice = Exp({mantissa: vars.oraclePriceMantissa}); // Pre-compute a conversion factor from tokens -> ether (normalized price value) vars.tokensToDenom = mul_(mul_(vars.collateralFactor, vars.exchangeRate), vars.oraclePrice); // sumCollateral += tokensToDenom * jTokenBalance vars.sumCollateral = mul_ScalarTruncateAddUInt(vars.tokensToDenom, vars.jTokenBalance, vars.sumCollateral); // sumBorrowPlusEffects += oraclePrice * borrowBalance vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt( vars.oraclePrice, vars.borrowBalance, vars.sumBorrowPlusEffects ); // Calculate effects of interacting with jTokenModify if (asset == jTokenModify) { // redeem effect // sumBorrowPlusEffects += tokensToDenom * redeemTokens vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt( vars.tokensToDenom, redeemTokens, vars.sumBorrowPlusEffects ); // borrow effect // sumBorrowPlusEffects += oraclePrice * borrowAmount vars.sumBorrowPlusEffects = mul_ScalarTruncateAddUInt( vars.oraclePrice, borrowAmount, vars.sumBorrowPlusEffects ); } } // If credit limit is set, no need to consider collateral. if (creditLimits[account] > 0) { vars.sumCollateral = creditLimits[account]; } // These are safe, as the underflow condition is checked first if (vars.sumCollateral > vars.sumBorrowPlusEffects) { return (Error.NO_ERROR, vars.sumCollateral - vars.sumBorrowPlusEffects, 0); } else { return (Error.NO_ERROR, 0, vars.sumBorrowPlusEffects - vars.sumCollateral); } } /** * @notice Calculate number of tokens of collateral asset to seize given an underlying amount * @dev Used in liquidation (called in jToken.liquidateBorrowFresh) * @param jTokenBorrowed The address of the borrowed jToken * @param jTokenCollateral The address of the collateral jToken * @param actualRepayAmount The amount of jTokenBorrowed underlying to convert into jTokenCollateral tokens * @return (errorCode, number of jTokenCollateral tokens to be seized in a liquidation) */ function liquidateCalculateSeizeTokens( address jTokenBorrowed, address jTokenCollateral, uint256 actualRepayAmount ) external view returns (uint256, uint256) { /* Read oracle prices for borrowed and collateral markets */ uint256 priceBorrowedMantissa = oracle.getUnderlyingPrice(JToken(jTokenBorrowed)); uint256 priceCollateralMantissa = oracle.getUnderlyingPrice(JToken(jTokenCollateral)); if (priceBorrowedMantissa == 0 || priceCollateralMantissa == 0) { return (uint256(Error.PRICE_ERROR), 0); } /* * Get the exchange rate and calculate the number of collateral tokens to seize: * seizeAmount = actualRepayAmount * liquidationIncentive * priceBorrowed / priceCollateral * seizeTokens = seizeAmount / exchangeRate * = actualRepayAmount * (liquidationIncentive * priceBorrowed) / (priceCollateral * exchangeRate) */ uint256 exchangeRateMantissa = JToken(jTokenCollateral).exchangeRateStored(); // Note: reverts on error Exp memory numerator = mul_( Exp({mantissa: liquidationIncentiveMantissa}), Exp({mantissa: priceBorrowedMantissa}) ); Exp memory denominator = mul_(Exp({mantissa: priceCollateralMantissa}), Exp({mantissa: exchangeRateMantissa})); Exp memory ratio = div_(numerator, denominator); uint256 seizeTokens = mul_ScalarTruncate(ratio, actualRepayAmount); return (uint256(Error.NO_ERROR), seizeTokens); } /*** Admin Functions ***/ function _setRewardDistributor(address payable newRewardDistributor) public returns (uint256) { if (msg.sender != admin) { return uint256(Error.UNAUTHORIZED); } (bool success, ) = newRewardDistributor.call.value(0)(abi.encodeWithSignature("initialize()", 0)); if (!success) { return uint256(Error.REJECTION); } address oldRewardDistributor = rewardDistributor; rewardDistributor = newRewardDistributor; return uint256(Error.NO_ERROR); } /** * @notice Sets a new price oracle for the joetroller * @dev Admin function to set a new price oracle * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setPriceOracle(PriceOracle newOracle) public returns (uint256) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PRICE_ORACLE_OWNER_CHECK); } // Track the old oracle for the joetroller PriceOracle oldOracle = oracle; // Set joetroller's oracle to newOracle oracle = newOracle; // Emit NewPriceOracle(oldOracle, newOracle) emit NewPriceOracle(oldOracle, newOracle); return uint256(Error.NO_ERROR); } /** * @notice Sets the closeFactor used when liquidating borrows * @dev Admin function to set closeFactor * @param newCloseFactorMantissa New close factor, scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setCloseFactor(uint256 newCloseFactorMantissa) external returns (uint256) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_CLOSE_FACTOR_OWNER_CHECK); } uint256 oldCloseFactorMantissa = closeFactorMantissa; closeFactorMantissa = newCloseFactorMantissa; emit NewCloseFactor(oldCloseFactorMantissa, closeFactorMantissa); return uint256(Error.NO_ERROR); } /** * @notice Sets the collateralFactor for a market * @dev Admin function to set per-market collateralFactor * @param jToken The market to set the factor on * @param newCollateralFactorMantissa The new collateral factor, scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setCollateralFactor(JToken jToken, uint256 newCollateralFactorMantissa) external returns (uint256) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_COLLATERAL_FACTOR_OWNER_CHECK); } // Verify market is listed Market storage market = markets[address(jToken)]; if (!market.isListed) { return fail(Error.MARKET_NOT_LISTED, FailureInfo.SET_COLLATERAL_FACTOR_NO_EXISTS); } Exp memory newCollateralFactorExp = Exp({mantissa: newCollateralFactorMantissa}); // Check collateral factor <= 0.9 Exp memory highLimit = Exp({mantissa: collateralFactorMaxMantissa}); if (lessThanExp(highLimit, newCollateralFactorExp)) { return fail(Error.INVALID_COLLATERAL_FACTOR, FailureInfo.SET_COLLATERAL_FACTOR_VALIDATION); } // If collateral factor != 0, fail if price == 0 if (newCollateralFactorMantissa != 0 && oracle.getUnderlyingPrice(jToken) == 0) { return fail(Error.PRICE_ERROR, FailureInfo.SET_COLLATERAL_FACTOR_WITHOUT_PRICE); } // Set market's collateral factor to new collateral factor, remember old value uint256 oldCollateralFactorMantissa = market.collateralFactorMantissa; market.collateralFactorMantissa = newCollateralFactorMantissa; // Emit event with asset, old collateral factor, and new collateral factor emit NewCollateralFactor(jToken, oldCollateralFactorMantissa, newCollateralFactorMantissa); return uint256(Error.NO_ERROR); } /** * @notice Sets liquidationIncentive * @dev Admin function to set liquidationIncentive * @param newLiquidationIncentiveMantissa New liquidationIncentive scaled by 1e18 * @return uint 0=success, otherwise a failure. (See ErrorReporter for details) */ function _setLiquidationIncentive(uint256 newLiquidationIncentiveMantissa) external returns (uint256) { // Check caller is admin if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_LIQUIDATION_INCENTIVE_OWNER_CHECK); } // Save current value for use in log uint256 oldLiquidationIncentiveMantissa = liquidationIncentiveMantissa; // Set liquidation incentive to new incentive liquidationIncentiveMantissa = newLiquidationIncentiveMantissa; // Emit event with old incentive, new incentive emit NewLiquidationIncentive(oldLiquidationIncentiveMantissa, newLiquidationIncentiveMantissa); return uint256(Error.NO_ERROR); } /** * @notice Add the market to the markets mapping and set it as listed * @dev Admin function to set isListed and add support for the market * @param jToken The address of the market (token) to list * @param version The version of the market (token) * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _supportMarket(JToken jToken, Version version) external returns (uint256) { require(msg.sender == admin, "only admin may support market"); require(!isMarketListed(address(jToken)), "market already listed"); jToken.isJToken(); // Sanity check to make sure its really a JToken markets[address(jToken)] = Market({isListed: true, collateralFactorMantissa: 0, version: version}); _addMarketInternal(address(jToken)); emit MarketListed(jToken); return uint256(Error.NO_ERROR); } /** * @notice Remove the market from the markets mapping * @param jToken The address of the market (token) to delist */ function _delistMarket(JToken jToken) external { require(msg.sender == admin, "only admin may delist market"); require(isMarketListed(address(jToken)), "market not listed"); require(jToken.totalSupply() == 0, "market not empty"); jToken.isJToken(); // Sanity check to make sure its really a JToken delete markets[address(jToken)]; for (uint256 i = 0; i < allMarkets.length; i++) { if (allMarkets[i] == jToken) { allMarkets[i] = allMarkets[allMarkets.length - 1]; delete allMarkets[allMarkets.length - 1]; allMarkets.length--; break; } } emit MarketDelisted(jToken); } function _addMarketInternal(address jToken) internal { for (uint256 i = 0; i < allMarkets.length; i++) { require(allMarkets[i] != JToken(jToken), "market already added"); } allMarkets.push(JToken(jToken)); } /** * @notice Admin function to change the Supply Cap Guardian * @param newSupplyCapGuardian The address of the new Supply Cap Guardian */ function _setSupplyCapGuardian(address newSupplyCapGuardian) external { require(msg.sender == admin, "only admin can set supply cap guardian"); // Save current value for inclusion in log address oldSupplyCapGuardian = supplyCapGuardian; // Store supplyCapGuardian with value newSupplyCapGuardian supplyCapGuardian = newSupplyCapGuardian; // Emit NewSupplyCapGuardian(OldSupplyCapGuardian, NewSupplyCapGuardian) emit NewSupplyCapGuardian(oldSupplyCapGuardian, newSupplyCapGuardian); } /** * @notice Set the given supply caps for the given jToken markets. Supplying that brings total supplys to or above supply cap will revert. * @dev Admin or supplyCapGuardian function to set the supply caps. A supply cap of 0 corresponds to unlimited supplying. If the total borrows * already exceeded the cap, it will prevent anyone to borrow. * @param jTokens The addresses of the markets (tokens) to change the supply caps for * @param newSupplyCaps The new supply cap values in underlying to be set. A value of 0 corresponds to unlimited supplying. */ function _setMarketSupplyCaps(JToken[] calldata jTokens, uint256[] calldata newSupplyCaps) external { require( msg.sender == admin || msg.sender == supplyCapGuardian, "only admin or supply cap guardian can set supply caps" ); uint256 numMarkets = jTokens.length; uint256 numSupplyCaps = newSupplyCaps.length; require(numMarkets != 0 && numMarkets == numSupplyCaps, "invalid input"); for (uint256 i = 0; i < numMarkets; i++) { supplyCaps[address(jTokens[i])] = newSupplyCaps[i]; emit NewSupplyCap(jTokens[i], newSupplyCaps[i]); } } /** * @notice Set the given borrow caps for the given jToken markets. Borrowing that brings total borrows to or above borrow cap will revert. * @dev Admin or borrowCapGuardian function to set the borrow caps. A borrow cap of 0 corresponds to unlimited borrowing. If the total supplies * already exceeded the cap, it will prevent anyone to mint. * @param jTokens The addresses of the markets (tokens) to change the borrow caps for * @param newBorrowCaps The new borrow cap values in underlying to be set. A value of 0 corresponds to unlimited borrowing. */ function _setMarketBorrowCaps(JToken[] calldata jTokens, uint256[] calldata newBorrowCaps) external { require( msg.sender == admin || msg.sender == borrowCapGuardian, "only admin or borrow cap guardian can set borrow caps" ); uint256 numMarkets = jTokens.length; uint256 numBorrowCaps = newBorrowCaps.length; require(numMarkets != 0 && numMarkets == numBorrowCaps, "invalid input"); for (uint256 i = 0; i < numMarkets; i++) { borrowCaps[address(jTokens[i])] = newBorrowCaps[i]; emit NewBorrowCap(jTokens[i], newBorrowCaps[i]); } } /** * @notice Admin function to change the Borrow Cap Guardian * @param newBorrowCapGuardian The address of the new Borrow Cap Guardian */ function _setBorrowCapGuardian(address newBorrowCapGuardian) external { require(msg.sender == admin, "only admin can set borrow cap guardian"); // Save current value for inclusion in log address oldBorrowCapGuardian = borrowCapGuardian; // Store borrowCapGuardian with value newBorrowCapGuardian borrowCapGuardian = newBorrowCapGuardian; // Emit NewBorrowCapGuardian(OldBorrowCapGuardian, NewBorrowCapGuardian) emit NewBorrowCapGuardian(oldBorrowCapGuardian, newBorrowCapGuardian); } /** * @notice Admin function to change the Pause Guardian * @param newPauseGuardian The address of the new Pause Guardian * @return uint 0=success, otherwise a failure. (See enum Error for details) */ function _setPauseGuardian(address newPauseGuardian) public returns (uint256) { if (msg.sender != admin) { return fail(Error.UNAUTHORIZED, FailureInfo.SET_PAUSE_GUARDIAN_OWNER_CHECK); } // Save current value for inclusion in log address oldPauseGuardian = pauseGuardian; // Store pauseGuardian with value newPauseGuardian pauseGuardian = newPauseGuardian; // Emit NewPauseGuardian(OldPauseGuardian, NewPauseGuardian) emit NewPauseGuardian(oldPauseGuardian, pauseGuardian); return uint256(Error.NO_ERROR); } function _setMintPaused(JToken jToken, bool state) public returns (bool) { require(isMarketListed(address(jToken)), "cannot pause a market that is not listed"); require(msg.sender == pauseGuardian || msg.sender == admin, "only pause guardian and admin can pause"); require(msg.sender == admin || state == true, "only admin can unpause"); mintGuardianPaused[address(jToken)] = state; emit ActionPaused(jToken, "Mint", state); return state; } function _setBorrowPaused(JToken jToken, bool state) public returns (bool) { require(isMarketListed(address(jToken)), "cannot pause a market that is not listed"); require(msg.sender == pauseGuardian || msg.sender == admin, "only pause guardian and admin can pause"); require(msg.sender == admin || state == true, "only admin can unpause"); borrowGuardianPaused[address(jToken)] = state; emit ActionPaused(jToken, "Borrow", state); return state; } function _setFlashloanPaused(JToken jToken, bool state) public returns (bool) { require(isMarketListed(address(jToken)), "cannot pause a market that is not listed"); require(msg.sender == pauseGuardian || msg.sender == admin, "only pause guardian and admin can pause"); require(msg.sender == admin || state == true, "only admin can unpause"); flashloanGuardianPaused[address(jToken)] = state; emit ActionPaused(jToken, "Flashloan", state); return state; } function _setTransferPaused(bool state) public returns (bool) { require(msg.sender == pauseGuardian || msg.sender == admin, "only pause guardian and admin can pause"); require(msg.sender == admin || state == true, "only admin can unpause"); transferGuardianPaused = state; emit ActionPaused("Transfer", state); return state; } function _setSeizePaused(bool state) public returns (bool) { require(msg.sender == pauseGuardian || msg.sender == admin, "only pause guardian and admin can pause"); require(msg.sender == admin || state == true, "only admin can unpause"); seizeGuardianPaused = state; emit ActionPaused("Seize", state); return state; } function _become(Unitroller unitroller) public { require(msg.sender == unitroller.admin(), "only unitroller admin can change brains"); require(unitroller._acceptImplementation() == 0, "change not authorized"); } /** * @notice Sets whitelisted protocol's credit limit * @param protocol The address of the protocol * @param creditLimit The credit limit */ function _setCreditLimit(address protocol, uint256 creditLimit) public { require(msg.sender == admin, "only admin can set protocol credit limit"); creditLimits[protocol] = creditLimit; emit CreditLimitChanged(protocol, creditLimit); } /** * @notice Checks caller is admin, or this contract is becoming the new implementation */ function adminOrInitializing() internal view returns (bool) { return msg.sender == admin || msg.sender == implementation; } /*** Reward distribution functions ***/ /** * @notice Claim all the JOE/AVAX accrued by holder in all markets * @param holder The address to claim JOE/AVAX for */ function claimReward(uint8 rewardType, address payable holder) public { RewardDistributor(rewardDistributor).claimReward(rewardType, holder); } /** * @notice Claim all the JOE/AVAX accrued by holder in the specified markets * @param holder The address to claim JOE/AVAX for * @param jTokens The list of markets to claim JOE/AVAX in */ function claimReward( uint8 rewardType, address payable holder, JToken[] memory jTokens ) public { RewardDistributor(rewardDistributor).claimReward(rewardType, holder, jTokens); } /** * @notice Claim all JOE/AVAX accrued by the holders * @param rewardType 0 = JOE, 1 = AVAX * @param holders The addresses to claim JOE/AVAX for * @param jTokens The list of markets to claim JOE/AVAX in * @param borrowers Whether or not to claim JOE/AVAX earned by borrowing * @param suppliers Whether or not to claim JOE/AVAX earned by supplying */ function claimReward( uint8 rewardType, address payable[] memory holders, JToken[] memory jTokens, bool borrowers, bool suppliers ) public payable { RewardDistributor(rewardDistributor).claimReward(rewardType, holders, jTokens, borrowers, suppliers); } } interface JJLPInterface { function claimJoe(address) external returns (uint256); } interface JJTokenInterface { function claimJoe(address) external returns (uint256); } /** * @notice This is a version of JoeLens that contains write transactions. * @dev Call these functions as dry-run transactions for the frontend. */ contract JoeLens is Exponential { string public nativeSymbol; constructor(string memory _nativeSymbol) public { nativeSymbol = _nativeSymbol; } /*** Market info functions ***/ struct JTokenMetadata { address jToken; uint256 exchangeRateCurrent; uint256 supplyRatePerSecond; uint256 borrowRatePerSecond; uint256 reserveFactorMantissa; uint256 totalBorrows; uint256 totalReserves; uint256 totalSupply; uint256 totalCash; uint256 totalCollateralTokens; bool isListed; uint256 collateralFactorMantissa; address underlyingAssetAddress; uint256 jTokenDecimals; uint256 underlyingDecimals; JoetrollerV1Storage.Version version; uint256 collateralCap; uint256 underlyingPrice; bool supplyPaused; bool borrowPaused; uint256 supplyCap; uint256 borrowCap; } function jTokenMetadataAll(JToken[] calldata jTokens) external returns (JTokenMetadata[] memory) { uint256 jTokenCount = jTokens.length; require(jTokenCount > 0, "invalid input"); JTokenMetadata[] memory res = new JTokenMetadata[](jTokenCount); Joetroller joetroller = Joetroller(address(jTokens[0].joetroller())); PriceOracle priceOracle = joetroller.oracle(); for (uint256 i = 0; i < jTokenCount; i++) { require(address(joetroller) == address(jTokens[i].joetroller()), "mismatch joetroller"); res[i] = jTokenMetadataInternal(jTokens[i], joetroller, priceOracle); } return res; } function jTokenMetadata(JToken jToken) public returns (JTokenMetadata memory) { Joetroller joetroller = Joetroller(address(jToken.joetroller())); PriceOracle priceOracle = joetroller.oracle(); return jTokenMetadataInternal(jToken, joetroller, priceOracle); } function jTokenMetadataInternal( JToken jToken, Joetroller joetroller, PriceOracle priceOracle ) internal returns (JTokenMetadata memory) { uint256 exchangeRateCurrent = jToken.exchangeRateCurrent(); (bool isListed, uint256 collateralFactorMantissa, JoetrollerV1Storage.Version version) = joetroller.markets( address(jToken) ); address underlyingAssetAddress; uint256 underlyingDecimals; uint256 collateralCap; uint256 totalCollateralTokens; if (compareStrings(jToken.symbol(), nativeSymbol)) { underlyingAssetAddress = address(0); underlyingDecimals = 18; } else { JErc20 jErc20 = JErc20(address(jToken)); underlyingAssetAddress = jErc20.underlying(); underlyingDecimals = EIP20Interface(jErc20.underlying()).decimals(); } if (version == JoetrollerV1Storage.Version.COLLATERALCAP) { collateralCap = JCollateralCapErc20Interface(address(jToken)).collateralCap(); totalCollateralTokens = JCollateralCapErc20Interface(address(jToken)).totalCollateralTokens(); } return JTokenMetadata({ jToken: address(jToken), exchangeRateCurrent: exchangeRateCurrent, supplyRatePerSecond: jToken.supplyRatePerSecond(), borrowRatePerSecond: jToken.borrowRatePerSecond(), reserveFactorMantissa: jToken.reserveFactorMantissa(), totalBorrows: jToken.totalBorrows(), totalReserves: jToken.totalReserves(), totalSupply: jToken.totalSupply(), totalCash: jToken.getCash(), totalCollateralTokens: totalCollateralTokens, isListed: isListed, collateralFactorMantissa: collateralFactorMantissa, underlyingAssetAddress: underlyingAssetAddress, jTokenDecimals: jToken.decimals(), underlyingDecimals: underlyingDecimals, version: version, collateralCap: collateralCap, underlyingPrice: priceOracle.getUnderlyingPrice(jToken), supplyPaused: joetroller.mintGuardianPaused(address(jToken)), borrowPaused: joetroller.borrowGuardianPaused(address(jToken)), supplyCap: joetroller.supplyCaps(address(jToken)), borrowCap: joetroller.borrowCaps(address(jToken)) }); } /*** Account JToken info functions ***/ struct JTokenBalances { address jToken; uint256 jTokenBalance; // Same as collateral balance - the number of jTokens held uint256 balanceOfUnderlyingCurrent; // Balance of underlying asset supplied by. Accrue interest is not called. uint256 supplyValueUSD; uint256 collateralValueUSD; // This is supplyValueUSD multiplied by collateral factor uint256 borrowBalanceCurrent; // Borrow balance without accruing interest uint256 borrowValueUSD; uint256 underlyingTokenBalance; // Underlying balance current held in user's wallet uint256 underlyingTokenAllowance; bool collateralEnabled; } function jTokenBalancesAll(JToken[] memory jTokens, address account) public returns (JTokenBalances[] memory) { uint256 jTokenCount = jTokens.length; JTokenBalances[] memory res = new JTokenBalances[](jTokenCount); for (uint256 i = 0; i < jTokenCount; i++) { res[i] = jTokenBalances(jTokens[i], account); } return res; } function jTokenBalances(JToken jToken, address account) public returns (JTokenBalances memory) { JTokenBalances memory vars; Joetroller joetroller = Joetroller(address(jToken.joetroller())); vars.jToken = address(jToken); vars.collateralEnabled = joetroller.checkMembership(account, jToken); if (compareStrings(jToken.symbol(), nativeSymbol)) { vars.underlyingTokenBalance = account.balance; vars.underlyingTokenAllowance = account.balance; } else { JErc20 jErc20 = JErc20(address(jToken)); EIP20Interface underlying = EIP20Interface(jErc20.underlying()); vars.underlyingTokenBalance = underlying.balanceOf(account); vars.underlyingTokenAllowance = underlying.allowance(account, address(jToken)); } // (, vars.jTokenBalance, , ) = jToken.getAccountSnapshot(account); vars.jTokenBalance = jToken.balanceOf(account); vars.borrowBalanceCurrent = jToken.borrowBalanceCurrent(account); vars.balanceOfUnderlyingCurrent = jToken.balanceOfUnderlying(account); PriceOracle priceOracle = joetroller.oracle(); uint256 underlyingPrice = priceOracle.getUnderlyingPrice(jToken); (, uint256 collateralFactorMantissa, ) = joetroller.markets(address(jToken)); Exp memory supplyValueInUnderlying = Exp({mantissa: vars.balanceOfUnderlyingCurrent}); vars.supplyValueUSD = mul_ScalarTruncate(supplyValueInUnderlying, underlyingPrice); Exp memory collateralFactor = Exp({mantissa: collateralFactorMantissa}); vars.collateralValueUSD = mul_ScalarTruncate(collateralFactor, vars.supplyValueUSD); Exp memory borrowBalance = Exp({mantissa: vars.borrowBalanceCurrent}); vars.borrowValueUSD = mul_ScalarTruncate(borrowBalance, underlyingPrice); return vars; } struct AccountLimits { JToken[] markets; uint256 liquidity; uint256 shortfall; uint256 totalCollateralValueUSD; uint256 totalBorrowValueUSD; uint256 healthFactor; } function getAccountLimits(Joetroller joetroller, address account) public returns (AccountLimits memory) { AccountLimits memory vars; uint256 errorCode; (errorCode, vars.liquidity, vars.shortfall) = joetroller.getAccountLiquidity(account); require(errorCode == 0, "Can't get account liquidity"); vars.markets = joetroller.getAssetsIn(account); JTokenBalances[] memory jTokenBalancesList = jTokenBalancesAll(vars.markets, account); for (uint256 i = 0; i < jTokenBalancesList.length; i++) { vars.totalCollateralValueUSD = add_(vars.totalCollateralValueUSD, jTokenBalancesList[i].collateralValueUSD); vars.totalBorrowValueUSD = add_(vars.totalBorrowValueUSD, jTokenBalancesList[i].borrowValueUSD); } Exp memory totalBorrows = Exp({mantissa: vars.totalBorrowValueUSD}); vars.healthFactor = vars.totalCollateralValueUSD == 0 ? 0 : vars.totalBorrowValueUSD > 0 ? div_(vars.totalCollateralValueUSD, totalBorrows) : 100; return vars; } function getClaimableRewards( uint8 rewardType, address joetroller, address joe, address payable account ) external returns (uint256) { require(rewardType <= 1, "rewardType is invalid"); if (rewardType == 0) { uint256 balanceBefore = EIP20Interface(joe).balanceOf(account); Joetroller(joetroller).claimReward(0, account); uint256 balanceAfter = EIP20Interface(joe).balanceOf(account); return sub_(balanceAfter, balanceBefore); } else if (rewardType == 1) { uint256 balanceBefore = account.balance; Joetroller(joetroller).claimReward(1, account); uint256 balanceAfter = account.balance; return sub_(balanceAfter, balanceBefore); } } function compareStrings(string memory a, string memory b) internal pure returns (bool) { return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b)))); } }
[{"inputs":[{"internalType":"string","name":"_nativeSymbol","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"constant":false,"inputs":[{"internalType":"contract Joetroller","name":"joetroller","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"getAccountLimits","outputs":[{"components":[{"internalType":"contract JToken[]","name":"markets","type":"address[]"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"shortfall","type":"uint256"},{"internalType":"uint256","name":"totalCollateralValueUSD","type":"uint256"},{"internalType":"uint256","name":"totalBorrowValueUSD","type":"uint256"},{"internalType":"uint256","name":"healthFactor","type":"uint256"}],"internalType":"struct JoeLens.AccountLimits","name":"","type":"tuple"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint8","name":"rewardType","type":"uint8"},{"internalType":"address","name":"joetroller","type":"address"},{"internalType":"address","name":"joe","type":"address"},{"internalType":"address payable","name":"account","type":"address"}],"name":"getClaimableRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract JToken","name":"jToken","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"jTokenBalances","outputs":[{"components":[{"internalType":"address","name":"jToken","type":"address"},{"internalType":"uint256","name":"jTokenBalance","type":"uint256"},{"internalType":"uint256","name":"balanceOfUnderlyingCurrent","type":"uint256"},{"internalType":"uint256","name":"supplyValueUSD","type":"uint256"},{"internalType":"uint256","name":"collateralValueUSD","type":"uint256"},{"internalType":"uint256","name":"borrowBalanceCurrent","type":"uint256"},{"internalType":"uint256","name":"borrowValueUSD","type":"uint256"},{"internalType":"uint256","name":"underlyingTokenBalance","type":"uint256"},{"internalType":"uint256","name":"underlyingTokenAllowance","type":"uint256"},{"internalType":"bool","name":"collateralEnabled","type":"bool"}],"internalType":"struct JoeLens.JTokenBalances","name":"","type":"tuple"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract JToken[]","name":"jTokens","type":"address[]"},{"internalType":"address","name":"account","type":"address"}],"name":"jTokenBalancesAll","outputs":[{"components":[{"internalType":"address","name":"jToken","type":"address"},{"internalType":"uint256","name":"jTokenBalance","type":"uint256"},{"internalType":"uint256","name":"balanceOfUnderlyingCurrent","type":"uint256"},{"internalType":"uint256","name":"supplyValueUSD","type":"uint256"},{"internalType":"uint256","name":"collateralValueUSD","type":"uint256"},{"internalType":"uint256","name":"borrowBalanceCurrent","type":"uint256"},{"internalType":"uint256","name":"borrowValueUSD","type":"uint256"},{"internalType":"uint256","name":"underlyingTokenBalance","type":"uint256"},{"internalType":"uint256","name":"underlyingTokenAllowance","type":"uint256"},{"internalType":"bool","name":"collateralEnabled","type":"bool"}],"internalType":"struct JoeLens.JTokenBalances[]","name":"","type":"tuple[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract JToken","name":"jToken","type":"address"}],"name":"jTokenMetadata","outputs":[{"components":[{"internalType":"address","name":"jToken","type":"address"},{"internalType":"uint256","name":"exchangeRateCurrent","type":"uint256"},{"internalType":"uint256","name":"supplyRatePerSecond","type":"uint256"},{"internalType":"uint256","name":"borrowRatePerSecond","type":"uint256"},{"internalType":"uint256","name":"reserveFactorMantissa","type":"uint256"},{"internalType":"uint256","name":"totalBorrows","type":"uint256"},{"internalType":"uint256","name":"totalReserves","type":"uint256"},{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"internalType":"uint256","name":"totalCash","type":"uint256"},{"internalType":"uint256","name":"totalCollateralTokens","type":"uint256"},{"internalType":"bool","name":"isListed","type":"bool"},{"internalType":"uint256","name":"collateralFactorMantissa","type":"uint256"},{"internalType":"address","name":"underlyingAssetAddress","type":"address"},{"internalType":"uint256","name":"jTokenDecimals","type":"uint256"},{"internalType":"uint256","name":"underlyingDecimals","type":"uint256"},{"internalType":"enum JoetrollerV1Storage.Version","name":"version","type":"uint8"},{"internalType":"uint256","name":"collateralCap","type":"uint256"},{"internalType":"uint256","name":"underlyingPrice","type":"uint256"},{"internalType":"bool","name":"supplyPaused","type":"bool"},{"internalType":"bool","name":"borrowPaused","type":"bool"},{"internalType":"uint256","name":"supplyCap","type":"uint256"},{"internalType":"uint256","name":"borrowCap","type":"uint256"}],"internalType":"struct JoeLens.JTokenMetadata","name":"","type":"tuple"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract JToken[]","name":"jTokens","type":"address[]"}],"name":"jTokenMetadataAll","outputs":[{"components":[{"internalType":"address","name":"jToken","type":"address"},{"internalType":"uint256","name":"exchangeRateCurrent","type":"uint256"},{"internalType":"uint256","name":"supplyRatePerSecond","type":"uint256"},{"internalType":"uint256","name":"borrowRatePerSecond","type":"uint256"},{"internalType":"uint256","name":"reserveFactorMantissa","type":"uint256"},{"internalType":"uint256","name":"totalBorrows","type":"uint256"},{"internalType":"uint256","name":"totalReserves","type":"uint256"},{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"internalType":"uint256","name":"totalCash","type":"uint256"},{"internalType":"uint256","name":"totalCollateralTokens","type":"uint256"},{"internalType":"bool","name":"isListed","type":"bool"},{"internalType":"uint256","name":"collateralFactorMantissa","type":"uint256"},{"internalType":"address","name":"underlyingAssetAddress","type":"address"},{"internalType":"uint256","name":"jTokenDecimals","type":"uint256"},{"internalType":"uint256","name":"underlyingDecimals","type":"uint256"},{"internalType":"enum JoetrollerV1Storage.Version","name":"version","type":"uint8"},{"internalType":"uint256","name":"collateralCap","type":"uint256"},{"internalType":"uint256","name":"underlyingPrice","type":"uint256"},{"internalType":"bool","name":"supplyPaused","type":"bool"},{"internalType":"bool","name":"borrowPaused","type":"bool"},{"internalType":"uint256","name":"supplyCap","type":"uint256"},{"internalType":"uint256","name":"borrowCap","type":"uint256"}],"internalType":"struct JoeLens.JTokenMetadata[]","name":"","type":"tuple[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"nativeSymbol","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"}]
Contract Creation Code
60806040523480156200001157600080fd5b5060405162002f6938038062002f69833981016040819052620000349162000152565b80516200004990600090602084019062000051565b505062000214565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200009457805160ff1916838001178555620000c4565b82800160010185558215620000c4579182015b82811115620000c4578251825591602001919060010190620000a7565b50620000d2929150620000d6565b5090565b620000f391905b80821115620000d25760008155600101620000dd565b90565b600082601f8301126200010857600080fd5b81516200011f6200011982620001b9565b62000192565b915080825260208301602083018583830111156200013c57600080fd5b62000149838284620001e1565b50505092915050565b6000602082840312156200016557600080fd5b81516001600160401b038111156200017c57600080fd5b6200018a84828501620000f6565b949350505050565b6040518181016001600160401b0381118282101715620001b157600080fd5b604052919050565b60006001600160401b03821115620001d057600080fd5b506020601f91909101601f19160190565b60005b83811015620001fe578181015183820152602001620001e4565b838111156200020e576000848401525b50505050565b612d4580620002246000396000f3fe608060405234801561001057600080fd5b506004361061007c5760003560e01c80637dd8f6d91161005b5780637dd8f6d9146100ea5780637fedad551461010a578063886131111461011f578063d9ca3c9c1461013f5761007c565b8062673b0c1461008157806354781336146100aa57806357553afb146100ca575b600080fd5b61009461008f3660046122a4565b61015f565b6040516100a19190612ad0565b60405180910390f35b6100bd6100b836600461246f565b6101f8565b6040516100a19190612b8e565b6100dd6100d836600461237e565b610436565b6040516100a19190612b70565b6100fd6100f836600461237e565b610b8b565b6040516100a19190612b5f565b610112610da1565b6040516100a19190612b0e565b61013261012d36600461222d565b610e2f565b6040516100a19190612ae1565b61015261014d366004612360565b6110bb565b6040516100a19190612b7f565b60606000835190506060816040519080825280602002602001820160405280156101a357816020015b610190611eb4565b8152602001906001900390816101885790505b50905060005b828110156101ed576101ce8682815181106101c057fe5b602002602001015186610436565b8282815181106101da57fe5b60209081029190910101526001016101a9565b509150505b92915050565b600060018560ff1611156102275760405162461bcd60e51b815260040161021e90612b2f565b60405180910390fd5b60ff85166103a6576040516370a0823160e01b81526000906001600160a01b038516906370a082319061025e908690600401612a8c565b60206040518083038186803b15801561027657600080fd5b505afa15801561028a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506102ae91908101906123f0565b604051630952c56360e01b81529091506001600160a01b03861690630952c563906102e0906000908790600401612b00565b600060405180830381600087803b1580156102fa57600080fd5b505af115801561030e573d6000803e3d6000fd5b50506040516370a0823160e01b8152600092506001600160a01b03871691506370a0823190610341908790600401612a8c565b60206040518083038186803b15801561035957600080fd5b505afa15801561036d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061039191908101906123f0565b905061039d81836111c2565b9250505061042e565b8460ff166001141561042e57604051630952c56360e01b81526001600160a01b03808416319190861690630952c563906103e7906001908790600401612b00565b600060405180830381600087803b15801561040157600080fd5b505af1158015610415573d6000803e3d6000fd5b505050506001600160a01b0383163161039d81836111c2565b949350505050565b61043e611eb4565b610446611eb4565b6000846001600160a01b0316636330533c6040518163ffffffff1660e01b815260040160206040518083038186803b15801561048157600080fd5b505afa158015610495573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506104b9919081019061239d565b6001600160a01b03808716845260405163929fe9a160e01b815291925082169063929fe9a1906104ef9087908990600401612ab5565b60206040518083038186803b15801561050757600080fd5b505afa15801561051b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061053f91908101906122f5565b82610120019015159081151581525050610657856001600160a01b03166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561058b57600080fd5b505afa15801561059f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526105c791908101906123bb565b6000805460408051602060026001851615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561064d5780601f106106225761010080835404028352916020019161064d565b820191906000526020600020905b81548152906001019060200180831161063057829003601f168201915b5050505050611203565b15610679576001600160a01b038416803160e0840152316101008301526107fc565b60008590506000816001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b1580156106b957600080fd5b505afa1580156106cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506106f1919081019061220f565b6040516370a0823160e01b81529091506001600160a01b038216906370a0823190610720908990600401612a7e565b60206040518083038186803b15801561073857600080fd5b505afa15801561074c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061077091908101906123f0565b60e0850152604051636eb1769f60e11b81526001600160a01b0382169063dd62ed3e906107a39089908b90600401612a9a565b60206040518083038186803b1580156107bb57600080fd5b505afa1580156107cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506107f391908101906123f0565b61010085015250505b6040516370a0823160e01b81526001600160a01b038616906370a0823190610828908790600401612a7e565b60206040518083038186803b15801561084057600080fd5b505afa158015610854573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061087891908101906123f0565b60208301526040516305eff7ef60e21b81526001600160a01b038616906317bfdfbc906108a9908790600401612a7e565b602060405180830381600087803b1580156108c357600080fd5b505af11580156108d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506108fb91908101906123f0565b60a0830152604051633af9e66960e01b81526001600160a01b03861690633af9e6699061092c908790600401612a7e565b602060405180830381600087803b15801561094657600080fd5b505af115801561095a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061097e91908101906123f0565b8260400181815250506000816001600160a01b0316637dc0d1d06040518163ffffffff1660e01b815260040160206040518083038186803b1580156109c257600080fd5b505afa1580156109d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506109fa919081019061239d565b90506000816001600160a01b031663fc57d4df886040518263ffffffff1660e01b8152600401610a2a9190612af2565b60206040518083038186803b158015610a4257600080fd5b505afa158015610a56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610a7a91908101906123f0565b90506000836001600160a01b0316638e8f294b896040518263ffffffff1660e01b8152600401610aaa9190612a7e565b60606040518083038186803b158015610ac257600080fd5b505afa158015610ad6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610afa9190810190612313565b50915050610b06611f12565b5060408051602081018252908601518152610b21818461125c565b6060870152610b2e611f12565b6040518060200160405280848152509050610b4d81886060015161125c565b6080880152610b5a611f12565b50604080516020810190915260a08801518152610b77818661125c565b60c089015250959998505050505050505050565b610b93611f25565b610b9b611f25565b604051635ec88c7960e01b81526000906001600160a01b03861690635ec88c7990610bca908790600401612a7e565b60606040518083038186803b158015610be257600080fd5b505afa158015610bf6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610c1a919081019061240e565b6040850152602084015290508015610c445760405162461bcd60e51b815260040161021e90612b3f565b604051632aff3bff60e21b81526001600160a01b0386169063abfceffc90610c70908790600401612a7e565b60006040518083038186803b158015610c8857600080fd5b505afa158015610c9c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610cc4919081019061226f565b808352606090610cd4908661015f565b905060005b8151811015610d4257610d078460600151838381518110610cf657fe5b60200260200101516080015161127b565b846060018181525050610d358460800151838381518110610d2457fe5b602002602001015160c0015161127b565b6080850152600101610cd9565b50610d4b611f12565b50604080516020810190915260808401518152606084015115610d8e576000846080015111610d7b576064610d89565b610d898460600151826112b1565b610d91565b60005b60a0850152509195945050505050565b6000805460408051602060026001851615610100026000190190941693909304601f81018490048402820184019092528181529291830182828015610e275780601f10610dfc57610100808354040283529160200191610e27565b820191906000526020600020905b815481529060010190602001808311610e0a57829003601f168201915b505050505081565b60608180610e4f5760405162461bcd60e51b815260040161021e90612b4f565b606081604051908082528060200260200182016040528015610e8b57816020015b610e78611f5b565b815260200190600190039081610e705790505b509050600085856000818110610e9d57fe5b9050602002016020610eb29190810190612360565b6001600160a01b0316636330533c6040518163ffffffff1660e01b815260040160206040518083038186803b158015610eea57600080fd5b505afa158015610efe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610f22919081019061239d565b90506000816001600160a01b0316637dc0d1d06040518163ffffffff1660e01b815260040160206040518083038186803b158015610f5f57600080fd5b505afa158015610f73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610f97919081019061239d565b905060005b848110156110af57878782818110610fb057fe5b9050602002016020610fc59190810190612360565b6001600160a01b0316636330533c6040518163ffffffff1660e01b815260040160206040518083038186803b158015610ffd57600080fd5b505afa158015611011573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611035919081019061239d565b6001600160a01b0316836001600160a01b0316146110655760405162461bcd60e51b815260040161021e90612b1f565b61109088888381811061107457fe5b90506020020160206110899190810190612360565b84846112cf565b84828151811061109c57fe5b6020908102919091010152600101610f9c565b50919695505050505050565b6110c3611f5b565b6000826001600160a01b0316636330533c6040518163ffffffff1660e01b815260040160206040518083038186803b1580156110fe57600080fd5b505afa158015611112573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611136919081019061239d565b90506000816001600160a01b0316637dc0d1d06040518163ffffffff1660e01b815260040160206040518083038186803b15801561117357600080fd5b505afa158015611187573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506111ab919081019061239d565b90506111b88483836112cf565b925050505b919050565b60006111fc8383604051806040016040528060158152602001747375627472616374696f6e20756e646572666c6f7760581b815250611d2e565b9392505050565b6000816040516020016112169190612a72565b604051602081830303815290604052805190602001208360405160200161123d9190612a72565b6040516020818303038152906040528051906020012014905092915050565b6000611266611f12565b6112708484611d5a565b905061042e81611d84565b60006111fc8383604051806040016040528060118152602001706164646974696f6e206f766572666c6f7760781b815250611d93565b60006111fc6112c884670de0b6b3a7640000611dc3565b8351611e05565b6112d7611f5b565b6000846001600160a01b031663bd6d894d6040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561131457600080fd5b505af1158015611328573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061134c91908101906123f0565b90506000806000866001600160a01b0316638e8f294b896040518263ffffffff1660e01b815260040161137f9190612a7e565b60606040518083038186803b15801561139757600080fd5b505afa1580156113ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506113cf9190810190612313565b9250925092506000806000806114178c6001600160a01b03166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801561058b57600080fd5b15611429576000935060129250611589565b60008c9050806001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b15801561146757600080fd5b505afa15801561147b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061149f919081019061220f565b9450806001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b1580156114da57600080fd5b505afa1580156114ee573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611512919081019061220f565b6001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561154a57600080fd5b505afa15801561155e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506115829190810190612451565b60ff169350505b600185600281111561159757fe5b1415611684578b6001600160a01b031663d2bb18e96040518163ffffffff1660e01b815260040160206040518083038186803b1580156115d657600080fd5b505afa1580156115ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061160e91908101906123f0565b91508b6001600160a01b03166319a4dd3c6040518163ffffffff1660e01b815260040160206040518083038186803b15801561164957600080fd5b505afa15801561165d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061168191908101906123f0565b90505b604051806102c001604052808d6001600160a01b031681526020018981526020018d6001600160a01b031663b1d389746040518163ffffffff1660e01b815260040160206040518083038186803b1580156116de57600080fd5b505afa1580156116f2573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061171691908101906123f0565b81526020018d6001600160a01b031663526097506040518163ffffffff1660e01b815260040160206040518083038186803b15801561175457600080fd5b505afa158015611768573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061178c91908101906123f0565b81526020018d6001600160a01b031663173b99046040518163ffffffff1660e01b815260040160206040518083038186803b1580156117ca57600080fd5b505afa1580156117de573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061180291908101906123f0565b81526020018d6001600160a01b03166347bd37186040518163ffffffff1660e01b815260040160206040518083038186803b15801561184057600080fd5b505afa158015611854573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061187891908101906123f0565b81526020018d6001600160a01b0316638f840ddd6040518163ffffffff1660e01b815260040160206040518083038186803b1580156118b657600080fd5b505afa1580156118ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506118ee91908101906123f0565b81526020018d6001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561192c57600080fd5b505afa158015611940573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061196491908101906123f0565b81526020018d6001600160a01b0316633b1d21a26040518163ffffffff1660e01b815260040160206040518083038186803b1580156119a257600080fd5b505afa1580156119b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506119da91908101906123f0565b81526020018281526020018815158152602001878152602001856001600160a01b031681526020018d6001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015611a3b57600080fd5b505afa158015611a4f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611a739190810190612451565b60ff168152602001848152602001866002811115611a8d57fe5b81526020018381526020018b6001600160a01b031663fc57d4df8f6040518263ffffffff1660e01b8152600401611ac49190612af2565b60206040518083038186803b158015611adc57600080fd5b505afa158015611af0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611b1491908101906123f0565b81526020018c6001600160a01b031663731f0c2b8f6040518263ffffffff1660e01b8152600401611b459190612a7e565b60206040518083038186803b158015611b5d57600080fd5b505afa158015611b71573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611b9591908101906122f5565b151581526020018c6001600160a01b0316636d154ea58f6040518263ffffffff1660e01b8152600401611bc89190612a7e565b60206040518083038186803b158015611be057600080fd5b505afa158015611bf4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611c1891908101906122f5565b151581526020018c6001600160a01b03166302c3bcbb8f6040518263ffffffff1660e01b8152600401611c4b9190612a7e565b60206040518083038186803b158015611c6357600080fd5b505afa158015611c77573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611c9b91908101906123f0565b81526020018c6001600160a01b0316634a5844328f6040518263ffffffff1660e01b8152600401611ccc9190612a7e565b60206040518083038186803b158015611ce457600080fd5b505afa158015611cf8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250611d1c91908101906123f0565b90529c9b505050505050505050505050565b60008184841115611d525760405162461bcd60e51b815260040161021e9190612b0e565b505050900390565b611d62611f12565b6040518060200160405280611d7b856000015185611dc3565b90529392505050565b51670de0b6b3a7640000900490565b60008383018285821015611dba5760405162461bcd60e51b815260040161021e9190612b0e565b50949350505050565b60006111fc83836040518060400160405280601781526020017f6d756c7469706c69636174696f6e206f766572666c6f77000000000000000000815250611e38565b60006111fc83836040518060400160405280600e81526020016d646976696465206279207a65726f60901b815250611e80565b6000831580611e45575082155b15611e52575060006111fc565b83830283858281611e5f57fe5b04148390611dba5760405162461bcd60e51b815260040161021e9190612b0e565b60008183611ea15760405162461bcd60e51b815260040161021e9190612b0e565b50828481611eab57fe5b04949350505050565b60405180610140016040528060006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000151581525090565b6040518060200160405280600081525090565b6040518060c001604052806060815260200160008152602001600081526020016000815260200160008152602001600081525090565b604051806102c0016040528060006001600160a01b031681526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000151581526020016000815260200160006001600160a01b03168152602001600081526020016000815260200160006002811115611ff157fe5b8152602001600081526020016000815260200160001515815260200160001515815260200160008152602001600081525090565b80356101f281612cbd565b80516101f281612cbd565b60008083601f84011261204d57600080fd5b50813567ffffffffffffffff81111561206557600080fd5b60208301915083602082028301111561207d57600080fd5b9250929050565b600082601f83011261209557600080fd5b81356120a86120a382612bc3565b612b9c565b915081818352602084019350602081019050838560208402820111156120cd57600080fd5b60005b838110156120f957816120e3888261217e565b84525060209283019291909101906001016120d0565b5050505092915050565b600082601f83011261211457600080fd5b81516121226120a382612bc3565b9150818183526020840193506020810190508385602084028201111561214757600080fd5b60005b838110156120f9578161215d8882612189565b845250602092830192919091019060010161214a565b80516101f281612cd1565b80356101f281612cda565b80516101f281612cda565b80516101f281612ce3565b600082601f8301126121b057600080fd5b81516121be6120a382612be4565b915080825260208301602083018583830111156121da57600080fd5b6121e5838284612c7a565b50505092915050565b80516101f281612cf0565b80356101f281612cf9565b80516101f281612cf9565b60006020828403121561222157600080fd5b600061042e8484612030565b6000806020838503121561224057600080fd5b823567ffffffffffffffff81111561225757600080fd5b6122638582860161203b565b92509250509250929050565b60006020828403121561228157600080fd5b815167ffffffffffffffff81111561229857600080fd5b61042e84828501612103565b600080604083850312156122b757600080fd5b823567ffffffffffffffff8111156122ce57600080fd5b6122da85828601612084565b92505060206122eb85828601612025565b9150509250929050565b60006020828403121561230757600080fd5b600061042e8484612173565b60008060006060848603121561232857600080fd5b60006123348686612173565b9350506020612345868287016121ee565b925050604061235686828701612194565b9150509250925092565b60006020828403121561237257600080fd5b600061042e848461217e565b6000806040838503121561239157600080fd5b60006122da858561217e565b6000602082840312156123af57600080fd5b600061042e8484612189565b6000602082840312156123cd57600080fd5b815167ffffffffffffffff8111156123e457600080fd5b61042e8482850161219f565b60006020828403121561240257600080fd5b600061042e84846121ee565b60008060006060848603121561242357600080fd5b600061242f86866121ee565b9350506020612440868287016121ee565b9250506040612356868287016121ee565b60006020828403121561246357600080fd5b600061042e8484612204565b6000806000806080858703121561248557600080fd5b600061249187876121f9565b94505060206124a287828801612025565b93505060406124b387828801612025565b92505060606124c487828801612025565b91505092959194509250565b60006124dc8383612624565b505060200190565b60006124f083836127e9565b50506101400190565b600061250583836128b0565b50506102c00190565b61251781612c59565b82525050565b61251781612c1f565b600061253182612c12565b61253b8185612c16565b935061254683612c0c565b8060005b8381101561257457815161255e88826124d0565b975061256983612c0c565b92505060010161254a565b509495945050505050565b600061258a82612c12565b6125948185612c16565b935061259f83612c0c565b8060005b838110156125745781516125b788826124e4565b97506125c283612c0c565b9250506001016125a3565b60006125d882612c12565b6125e28185612c16565b93506125ed83612c0c565b8060005b8381101561257457815161260588826124f9565b975061261083612c0c565b9250506001016125f1565b61251781612c2a565b61251781612c2f565b61251781612c64565b61251781612c6f565b600061264a82612c12565b6126548185612c16565b9350612664818560208601612c7a565b61266d81612ca6565b9093019392505050565b600061268282612c12565b61268c81856111bd565b935061269c818560208601612c7a565b9290920192915050565b60006126b3601383612c16565b7236b4b9b6b0ba31b4103537b2ba3937b63632b960691b815260200192915050565b60006126e2601583612c16565b741c995dd85c99151e5c19481a5cc81a5b9d985b1a59605a1b815260200192915050565b6000612713601b83612c16565b7f43616e277420676574206163636f756e74206c69717569646974790000000000815260200192915050565b600061274c600d83612c16565b6c1a5b9d985b1a59081a5b9c1d5d609a1b815260200192915050565b805160c0808452600091908401906127808282612526565b91505060208301516127956020860182612a69565b5060408301516127a86040860182612a69565b5060608301516127bb6060860182612a69565b5060808301516127ce6080860182612a69565b5060a08301516127e160a0860182612a69565b509392505050565b80516101408301906127fb848261251d565b50602082015161280e6020850182612a69565b5060408201516128216040850182612a69565b5060608201516128346060850182612a69565b5060808201516128476080850182612a69565b5060a082015161285a60a0850182612a69565b5060c082015161286d60c0850182612a69565b5060e082015161288060e0850182612a69565b50610100820151612895610100850182612a69565b506101208201516128aa61012085018261261b565b50505050565b80516102c08301906128c2848261251d565b5060208201516128d56020850182612a69565b5060408201516128e86040850182612a69565b5060608201516128fb6060850182612a69565b50608082015161290e6080850182612a69565b5060a082015161292160a0850182612a69565b5060c082015161293460c0850182612a69565b5060e082015161294760e0850182612a69565b5061010082015161295c610100850182612a69565b50610120820151612971610120850182612a69565b5061014082015161298661014085018261261b565b5061016082015161299b610160850182612a69565b506101808201516129b061018085018261251d565b506101a08201516129c56101a0850182612a69565b506101c08201516129da6101c0850182612a69565b506101e08201516129ef6101e085018261262d565b50610200820151612a04610200850182612a69565b50610220820151612a19610220850182612a69565b50610240820151612a2e61024085018261261b565b50610260820151612a4361026085018261261b565b50610280820151612a58610280850182612a69565b506102a08201516128aa6102a08501825b61251781612c50565b60006111fc8284612677565b602081016101f2828461251d565b602081016101f2828461250e565b60408101612aa8828561251d565b6111fc602083018461251d565b60408101612ac3828561251d565b6111fc6020830184612624565b602080825281016111fc818461257f565b602080825281016111fc81846125cd565b602081016101f28284612624565b60408101612aa88285612636565b602080825281016111fc818461263f565b602080825281016101f2816126a6565b602080825281016101f2816126d5565b602080825281016101f281612706565b602080825281016101f28161273f565b602080825281016111fc8184612768565b61014081016101f282846127e9565b6102c081016101f282846128b0565b602081016101f28284612a69565b60405181810167ffffffffffffffff81118282101715612bbb57600080fd5b604052919050565b600067ffffffffffffffff821115612bda57600080fd5b5060209081020190565b600067ffffffffffffffff821115612bfb57600080fd5b506020601f91909101601f19160190565b60200190565b5190565b90815260200190565b60006101f282612c44565b151590565b60006101f282612c1f565b806111bd81612cb0565b6001600160a01b031690565b90565b60ff1690565b60006101f282612c2f565b60006101f282612c3a565b60006101f282612c53565b60005b83811015612c95578181015183820152602001612c7d565b838111156128aa5750506000910152565b601f01601f191690565b60038110612cba57fe5b50565b612cc681612c1f565b8114612cba57600080fd5b612cc681612c2a565b612cc681612c2f565b60038110612cba57600080fd5b612cc681612c50565b612cc681612c5356fea365627a7a72315820b0c5901c60d5b093fda775abd125e6a934f17b0ab1c5821794874ad977816a166c6578706572696d656e74616cf564736f6c63430005100040000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000056a41564158000000000000000000000000000000000000000000000000000000
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000056a41564158000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _nativeSymbol (string): jAVAX
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000020
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000005
Arg [2] : 6a41564158000000000000000000000000000000000000000000000000000000
Deployed ByteCode Sourcemap
211124:9977:0:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;211124:9977:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;216439:383;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;220090:817;;;;;;;;;:::i;:::-;;;;;;;;216830:1921;;;;;;;;;:::i;:::-;;;;;;;;218990:1092;;;;;;;;;:::i;:::-;;;;;;;;211163:26;;;:::i;:::-;;;;;;;;212118:683;;;;;;;;;:::i;:::-;;;;;;;;212809:290;;;;;;;;;:::i;:::-;;;;;;;;216439:383;216524:23;216560:19;216582:7;:14;216560:36;;216607:27;216658:11;216637:33;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;-1:-1:-1;216607:63:0;-1:-1:-1;216686:9:0;216681:113;216705:11;216701:1;:15;216681:113;;;216747:35;216762:7;216770:1;216762:10;;;;;;;;;;;;;;216774:7;216747:14;:35::i;:::-;216738:3;216742:1;216738:6;;;;;;;;;;;;;;;;;:44;216718:3;;216681:113;;;-1:-1:-1;216811:3:0;-1:-1:-1;;216439:383:0;;;;;:::o;220090:817::-;220256:7;220298:1;220284:10;:15;;;;220276:49;;;;-1:-1:-1;;;220276:49:0;;;;;;;;;;;;;;;;;220340:15;;;220336:564;;220396:38;;-1:-1:-1;;;220396:38:0;;220372:21;;-1:-1:-1;;;;;220396:29:0;;;;;:38;;220426:7;;220396:38;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;220396:38:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;220396:38:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;220396:38:0;;;;;;;;;220449:46;;-1:-1:-1;;;220449:46:0;;220372:62;;-1:-1:-1;;;;;;220449:34:0;;;;;:46;;220484:1;;220487:7;;220449:46;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;220449:46:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;-1:-1;;220533:38:0;;-1:-1:-1;;;220533:38:0;;220510:20;;-1:-1:-1;;;;;;220533:29:0;;;-1:-1:-1;220533:29:0;;:38;;220563:7;;220533:38;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;220533:38:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;220533:38:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;220533:38:0;;;;;;;;;220510:61;;220593:33;220598:12;220612:13;220593:4;:33::i;:::-;220586:40;;;;;;220336:564;220648:10;:15;;220662:1;220648:15;220644:256;;;220734:46;;-1:-1:-1;;;220734:46:0;;-1:-1:-1;;;;;220704:15:0;;;;;220734:34;;;;;;:46;;220769:1;;220704:7;;220734:46;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;220734:46:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;-1:-1;;;;;;;;;220818:15:0;;;220855:33;220818:15;220874:13;220855:4;:33::i;220644:256::-;220090:817;;;;;;:::o;216830:1921::-;216902:21;;:::i;:::-;216936:26;;:::i;:::-;216973:21;217016:6;-1:-1:-1;;;;;217016:17:0;;:19;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;217016:19:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;217016:19:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;217016:19:0;;;;;;;;;-1:-1:-1;;;;;217050:29:0;;;;;217115:43;;-1:-1:-1;;;217115:43:0;;216973:64;;-1:-1:-1;217115:26:0;;;;;:43;;217142:7;;217072:6;;217115:43;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;217115:43:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;217115:43:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;217115:43:0;;;;;;;;;217090:4;:22;;:68;;;;;;;;;;;217175:45;217190:6;-1:-1:-1;;;;;217190:13:0;;:15;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;217190:15:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;217190:15:0;;;;;;39:16:-1;36:1;17:17;2:54;101:4;217190:15:0;80::-1;;;-1:-1;;76:31;65:43;;120:4;113:20;217190:15:0;;;;;;;;;217207:12;217175:45;;;;;;;;;;;;;-1:-1:-1;;217175:45:0;;;;;;;;;;;;;;;;;;;;;;;;;;;217207:12;217175:45;;217207:12;217175:45;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:14;:45::i;:::-;217171:502;;;-1:-1:-1;;;;;217267:15:0;;;;217237:27;;;:45;217329:15;217297:29;;;:47;217171:502;;;217377:13;217408:6;217377:39;;217431:25;217474:6;-1:-1:-1;;;;;217474:17:0;;:19;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;217474:19:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;217474:19:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;217474:19:0;;;;;;;;;217539:29;;-1:-1:-1;;;217539:29:0;;217431:63;;-1:-1:-1;;;;;;217539:20:0;;;;;:29;;217560:7;;217539:29;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;217539:29:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;217539:29:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;217539:29:0;;;;;;;;;217509:27;;;:59;217615:46;;-1:-1:-1;;;217615:46:0;;-1:-1:-1;;;;;217615:20:0;;;;;:46;;217636:7;;217653:6;;217615:46;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;217615:46:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;217615:46:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;217615:46:0;;;;;;;;;217583:29;;;:78;-1:-1:-1;;217171:502:0;217783:25;;-1:-1:-1;;;217783:25:0;;-1:-1:-1;;;;;217783:16:0;;;;;:25;;217800:7;;217783:25;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;217783:25:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;217783:25:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;217783:25:0;;;;;;;;;217762:18;;;:46;217847:36;;-1:-1:-1;;;217847:36:0;;-1:-1:-1;;;;;217847:27:0;;;;;:36;;217875:7;;217847:36;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;217847:36:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;217847:36:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;217847:36:0;;;;;;;;;217819:25;;;:64;217930:35;;-1:-1:-1;;;217930:35:0;;-1:-1:-1;;;;;217930:26:0;;;;;:35;;217957:7;;217930:35;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;217930:35:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;217930:35:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;217930:35:0;;;;;;;;;217896:4;:31;;:69;;;;;217976:23;218002:10;-1:-1:-1;;;;;218002:17:0;;:19;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;218002:19:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;218002:19:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;218002:19:0;;;;;;;;;217976:45;;218032:23;218058:11;-1:-1:-1;;;;;218058:30:0;;218089:6;218058:38;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;218058:38:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;218058:38:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;218058:38:0;;;;;;;;;218032:64;;218112:32;218150:10;-1:-1:-1;;;;;218150:18:0;;218177:6;218150:35;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;218150:35:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;218150:35:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;218150:35:0;;;;;;;;;218109:76;;;;218198:34;;:::i;:::-;-1:-1:-1;218235:48:0;;;;;;;;218250:31;;;;218235:48;;218316:60;218235:48;218360:15;218316:18;:60::i;:::-;218294:19;;;:82;218389:27;;:::i;:::-;218419:41;;;;;;;;218434:24;218419:41;;;218389:71;;218497:57;218516:16;218534:4;:19;;;218497:18;:57::i;:::-;218471:23;;;:83;218567:24;;:::i;:::-;-1:-1:-1;218594:42:0;;;;;;;;;218609:25;;;;218594:42;;218669:50;218594:42;218703:15;218669:18;:50::i;:::-;218647:19;;;:72;-1:-1:-1;218647:19:0;;216830:1921;-1:-1:-1;;;;;;;;;216830:1921:0:o;218990:1092::-;219072:20;;:::i;:::-;219105:25;;:::i;:::-;219217:39;;-1:-1:-1;;;219217:39:0;;219141:17;;-1:-1:-1;;;;;219217:30:0;;;;;:39;;219248:7;;219217:39;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;219217:39:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;219217:39:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;219217:39:0;;;;;;;;;219199:14;;;219171:85;219183:14;;;219171:85;;-1:-1:-1;219275:14:0;;219267:54;;;;-1:-1:-1;;;219267:54:0;;;;;;;;;219349:31;;-1:-1:-1;;;219349:31:0;;-1:-1:-1;;;;;219349:22:0;;;;;:31;;219372:7;;219349:31;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;219349:31:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;219349:31:0;;;;;;39:16:-1;36:1;17:17;2:54;101:4;219349:31:0;80:15:-1;;;-1:-1;;76:31;65:43;;120:4;113:20;219349:31:0;;;;;;;;;219334:46;;;219391:42;;219436:40;;219468:7;219436:17;:40::i;:::-;219391:85;-1:-1:-1;219492:9:0;219487:300;219511:18;:25;219507:1;:29;219487:300;;;219589:76;219594:4;:28;;;219624:18;219643:1;219624:21;;;;;;;;;;;;;;:40;;;219589:4;:76::i;:::-;219558:4;:28;;:107;;;;;219707:68;219712:4;:24;;;219738:18;219757:1;219738:21;;;;;;;;;;;;;;:36;;;219707:4;:68::i;:::-;219680:24;;;:95;219538:3;;219487:300;;;;219799:23;;:::i;:::-;-1:-1:-1;219825:41:0;;;;;;;;;219840:24;;;;219825:41;;219899:28;;;;:33;:151;;219966:1;219939:4;:24;;;:28;:111;;220047:3;219939:111;;;219983:48;219988:4;:28;;;220018:12;219983:4;:48::i;:::-;219899:151;;;219935:1;219899:151;219879:17;;;:171;-1:-1:-1;219879:17:0;;218990:1092;-1:-1:-1;;;;;218990:1092:0:o;211163:26::-;;;;;;;;;;;;;;;-1:-1:-1;;211163:26:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;212118:683::-;212190:23;212248:7;212281:15;212273:41;;;;-1:-1:-1;;;212273:41:0;;;;;;;;;212325:27;212376:11;212355:33;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;212325:63;;212399:21;212442:7;;212450:1;212442:10;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;212442:21:0;;:23;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;212442:23:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;212442:23:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;212442:23:0;;;;;;;;;212399:68;;212478:23;212504:10;-1:-1:-1;;;;;212504:17:0;;:19;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;212504:19:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;212504:19:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;212504:19:0;;;;;;;;;212478:45;-1:-1:-1;212539:9:0;212534:239;212558:11;212554:1;:15;212534:239;;;212630:7;;212638:1;212630:10;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;212630:21:0;;:23;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;212630:23:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;212630:23:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;212630:23:0;;;;;;;;;-1:-1:-1;;;;;212599:55:0;212607:10;-1:-1:-1;;;;;212599:55:0;;212591:87;;;;-1:-1:-1;;;212591:87:0;;;;;;;;;212702:59;212725:7;;212733:1;212725:10;;;;;;;;;;;;;;;;;;;;;;212737;212749:11;212702:22;:59::i;:::-;212693:3;212697:1;212693:6;;;;;;;;;;;;;;;;;:68;212571:3;;212534:239;;;-1:-1:-1;212790:3:0;;212118:683;-1:-1:-1;;;;;;212118:683:0:o;212809:290::-;212864:21;;:::i;:::-;212898;212941:6;-1:-1:-1;;;;;212941:17:0;;:19;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;212941:19:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;212941:19:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;212941:19:0;;;;;;;;;212898:64;;212973:23;212999:10;-1:-1:-1;;;;;212999:17:0;;:19;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;212999:19:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;212999:19:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;212999:19:0;;;;;;;;;212973:45;;213036:55;213059:6;213067:10;213079:11;213036:22;:55::i;:::-;213029:62;;;;212809:290;;;;:::o;25213:129::-;25272:7;25299:35;25304:1;25307;25299:35;;;;;;;;;;;;;-1:-1:-1;;;25299:35:0;;;:4;:35::i;:::-;25292:42;25213:129;-1:-1:-1;;;25213:129:0:o;220915:183::-;220996:4;221085:1;221067:21;;;;;;;;;;;;49:4:-1;39:7;30;26:21;22:32;13:7;6:49;221067:21:0;;;221057:32;;;;;;221049:1;221031:21;;;;;;;;;;;;49:4:-1;39:7;30;26:21;22:32;13:7;6:49;221031:21:0;;;221021:32;;;;;;:68;221013:77;;220915:183;;;;:::o;17420:180::-;17501:7;17521:18;;:::i;:::-;17542:15;17547:1;17550:6;17542:4;:15::i;:::-;17521:36;;17575:17;17584:7;17575:8;:17::i;24523:125::-;24582:7;24609:31;24614:1;24617;24609:31;;;;;;;;;;;;;-1:-1:-1;;;24609:31:0;;;:4;:31::i;27240:132::-;27302:7;27329:35;27334:17;27339:1;14277:4;27334;:17::i;:::-;27353:10;;27329:4;:35::i;213107:2590::-;213254:21;;:::i;:::-;213288:27;213318:6;-1:-1:-1;;;;;213318:26:0;;:28;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;213318:28:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;213318:28:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;213318:28:0;;;;;;;;;213288:58;;213358:13;213373:32;213407:35;213446:10;-1:-1:-1;;;;;213446:18:0;;213487:6;213446:59;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;213446:59:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;213446:59:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;213446:59:0;;;;;;;;;213357:148;;;;;;213516:30;213557:26;213594:21;213626:29;213672:45;213687:6;-1:-1:-1;;;;;213687:13:0;;:15;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;213672:45:0;213668:364;;;213767:1;213734:35;;213805:2;213784:23;;213668:364;;;213840:13;213871:6;213840:39;;213919:6;-1:-1:-1;;;;;213919:17:0;;:19;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;213919:19:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;213919:19:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;213919:19:0;;;;;;;;;213894:44;;213989:6;-1:-1:-1;;;;;213989:17:0;;:19;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;213989:19:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;213989:19:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;213989:19:0;;;;;;;;;-1:-1:-1;;;;;213974:44:0;;:46;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;213974:46:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;213974:46:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;213974:46:0;;;;;;;;;213953:67;;;;213668:364;;214059:41;214048:7;:52;;;;;;;;;214044:270;;;214170:6;-1:-1:-1;;;;;214133:59:0;;:61;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;214133:61:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;214133:61:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;214133:61:0;;;;;;;;;214117:77;;214270:6;-1:-1:-1;;;;;214233:67:0;;:69;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;214233:69:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;214233:69:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;214233:69:0;;;;;;;;;214209:93;;214044:270;214346:1343;;;;;;;;214396:6;-1:-1:-1;;;;;214346:1343:0;;;;;214443:19;214346:1343;;;;214502:6;-1:-1:-1;;;;;214502:26:0;;:28;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;214502:28:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;214502:28:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;214502:28:0;;;;;;;;;214346:1343;;;;214570:6;-1:-1:-1;;;;;214570:26:0;;:28;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;214570:28:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;214570:28:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;214570:28:0;;;;;;;;;214346:1343;;;;214640:6;-1:-1:-1;;;;;214640:28:0;;:30;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;214640:30:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;214640:30:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;214640:30:0;;;;;;;;;214346:1343;;;;214703:6;-1:-1:-1;;;;;214703:19:0;;:21;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;214703:21:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;214703:21:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;214703:21:0;;;;;;;;;214346:1343;;;;214758:6;-1:-1:-1;;;;;214758:20:0;;:22;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;214758:22:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;214758:22:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;214758:22:0;;;;;;;;;214346:1343;;;;214812:6;-1:-1:-1;;;;;214812:18:0;;:20;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;214812:20:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;214812:20:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;214812:20:0;;;;;;;;;214346:1343;;;;214862:6;-1:-1:-1;;;;;214862:14:0;;:16;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;214862:16:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;214862:16:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;214862:16:0;;;;;;;;;214346:1343;;;;214920:21;214346:1343;;;;214970:8;214346:1343;;;;;;215023:24;214346:1343;;;;215090:22;-1:-1:-1;;;;;214346:1343:0;;;;;215147:6;-1:-1:-1;;;;;215147:15:0;;:17;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;215147:17:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;215147:17:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;215147:17:0;;;;;;;;;214346:1343;;;;;;215203:18;214346:1343;;;;215249:7;214346:1343;;;;;;;;;;;;215290:13;214346:1343;;;;215339:11;-1:-1:-1;;;;;215339:30:0;;215370:6;215339:38;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;215339:38:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;215339:38:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;215339:38:0;;;;;;;;;214346:1343;;;;215410:10;-1:-1:-1;;;;;215410:29:0;;215448:6;215410:46;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;215410:46:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;215410:46:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;215410:46:0;;;;;;;;;214346:1343;;;;;;215489:10;-1:-1:-1;;;;;215489:31:0;;215529:6;215489:48;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;215489:48:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;215489:48:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;215489:48:0;;;;;;;;;214346:1343;;;;;;215567:10;-1:-1:-1;;;;;215567:21:0;;215597:6;215567:38;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;215567:38:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;215567:38:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;215567:38:0;;;;;;;;;214346:1343;;;;215635:10;-1:-1:-1;;;;;215635:21:0;;215665:6;215635:38;;;;;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;215635:38:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;215635:38:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;215635:38:0;;;;;;;;;214346:1343;;214326:1363;213107:2590;-1:-1:-1;;;;;;;;;;;;213107:2590:0:o;25350:201::-;25471:7;25507:12;25499:6;;;;25491:29;;;;-1:-1:-1;;;25491:29:0;;;;;;;;;;-1:-1:-1;;;25538:5:0;;;25350:201::o;25726:136::-;25788:10;;:::i;:::-;25818:36;;;;;;;;25833:19;25838:1;:10;;;25850:1;25833:4;:19::i;:::-;25818:36;;25811:43;25726:136;-1:-1:-1;;;25726:136:0:o;22995:216::-;23180:12;14277:4;23180:23;;;22995:216::o;24656:225::-;24777:7;24809:5;;;24841:12;24833:6;;;;24825:29;;;;-1:-1:-1;;;24825:29:0;;;;;;;;;;-1:-1:-1;24872:1:0;24656:225;-1:-1:-1;;;;24656:225:0:o;26481:131::-;26540:7;26567:37;26572:1;26575;26567:37;;;;;;;;;;;;;;;;;:4;:37::i;27866:122::-;27925:7;27952:28;27957:1;27960;27952:28;;;;;;;;;;;;;-1:-1:-1;;;27952:28:0;;;:4;:28::i;26620:296::-;26741:7;26765:6;;;:16;;-1:-1:-1;26775:6:0;;26765:16;26761:57;;;-1:-1:-1;26805:1:0;26798:8;;26761:57;26840:5;;;26844:1;26840;:5;:1;26864:5;;;;;:10;26876:12;26856:33;;;;;-1:-1:-1;;;26856:33:0;;;;;;;;;27996:200;28117:7;28152:12;28145:5;28137:28;;;;-1:-1:-1;;;28137:28:0;;;;;;;;;;;28187:1;28183;:5;;;;;;;27996:200;-1:-1:-1;;;;27996:200:0:o;211124:9977::-;;;;;;;;;;-1:-1:-1;;;;;211124:9977:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;-1:-1:-1;;;;;211124:9977:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;211124:9977:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;5:130:-1:-;72:20;;97:33;72:20;97:33;;142:134;220:13;;238:33;220:13;238:33;;462:367;;;607:3;600:4;592:6;588:17;584:27;574:2;;625:1;622;615:12;574:2;-1:-1;645:20;;685:18;674:30;;671:2;;;717:1;714;707:12;671:2;751:4;743:6;739:17;727:29;;802:3;794:4;786:6;782:17;772:8;768:32;765:41;762:2;;;819:1;816;809:12;762:2;567:262;;;;;;863:752;;995:3;988:4;980:6;976:17;972:27;962:2;;1013:1;1010;1003:12;962:2;1050:6;1037:20;1072:95;1087:79;1159:6;1087:79;;;1072:95;;;1063:104;;1184:5;1209:6;1202:5;1195:21;1239:4;1231:6;1227:17;1217:27;;1261:4;1256:3;1252:14;1245:21;;1314:6;1361:3;1353:4;1345:6;1341:17;1336:3;1332:27;1329:36;1326:2;;;1378:1;1375;1368:12;1326:2;1403:1;1388:221;1413:6;1410:1;1407:13;1388:221;;;1471:3;1493:52;1541:3;1529:10;1493:52;;;1481:65;;-1:-1;1569:4;1560:14;;;;1588;;;;;1435:1;1428:9;1388:221;;;1392:14;955:660;;;;;;;;1649:767;;1792:3;1785:4;1777:6;1773:17;1769:27;1759:2;;1810:1;1807;1800:12;1759:2;1840:6;1834:13;1862:95;1877:79;1949:6;1877:79;;1862:95;1853:104;;1974:5;1999:6;1992:5;1985:21;2029:4;2021:6;2017:17;2007:27;;2051:4;2046:3;2042:14;2035:21;;2104:6;2151:3;2143:4;2135:6;2131:17;2126:3;2122:27;2119:36;2116:2;;;2168:1;2165;2158:12;2116:2;2193:1;2178:232;2203:6;2200:1;2197:13;2178:232;;;2261:3;2283:63;2342:3;2330:10;2283:63;;;2271:76;;-1:-1;2370:4;2361:14;;;;2389;;;;;2225:1;2218:9;2178:232;;2424:128;2499:13;;2517:30;2499:13;2517:30;;2559:160;2641:20;;2666:48;2641:20;2666:48;;2726:164;2819:13;;2837:48;2819:13;2837:48;;3452:158;3542:13;;3560:45;3542:13;3560:45;;3618:436;;3727:3;3720:4;3712:6;3708:17;3704:27;3694:2;;3745:1;3742;3735:12;3694:2;3775:6;3769:13;3797:61;3812:45;3850:6;3812:45;;3797:61;3788:70;;3878:6;3871:5;3864:21;3914:4;3906:6;3902:17;3947:4;3940:5;3936:16;3982:3;3973:6;3968:3;3964:16;3961:25;3958:2;;;3999:1;3996;3989:12;3958:2;4009:39;4041:6;4036:3;4031;4009:39;;;3687:367;;;;;;;;4062:134;4140:13;;4158:33;4140:13;4158:33;;4203:126;4268:20;;4293:31;4268:20;4293:31;;4336:130;4412:13;;4430:31;4412:13;4430:31;;4473:263;;4588:2;4576:9;4567:7;4563:23;4559:32;4556:2;;;4604:1;4601;4594:12;4556:2;4639:1;4656:64;4712:7;4692:9;4656:64;;4743:427;;;4897:2;4885:9;4876:7;4872:23;4868:32;4865:2;;;4913:1;4910;4903:12;4865:2;4948:31;;4999:18;4988:30;;4985:2;;;5031:1;5028;5021:12;4985:2;5059:95;5146:7;5137:6;5126:9;5122:22;5059:95;;;5049:105;;;;4927:233;4859:311;;;;;;5177:422;;5332:2;5320:9;5311:7;5307:23;5303:32;5300:2;;;5348:1;5345;5338:12;5300:2;5383:24;;5427:18;5416:30;;5413:2;;;5459:1;5456;5449:12;5413:2;5479:104;5575:7;5566:6;5555:9;5551:22;5479:104;;5606:532;;;5767:2;5755:9;5746:7;5742:23;5738:32;5735:2;;;5783:1;5780;5773:12;5735:2;5818:31;;5869:18;5858:30;;5855:2;;;5901:1;5898;5891:12;5855:2;5921:93;6006:7;5997:6;5986:9;5982:22;5921:93;;;5911:103;;5797:223;6051:2;6069:53;6114:7;6105:6;6094:9;6090:22;6069:53;;;6059:63;;6030:98;5729:409;;;;;;6145:257;;6257:2;6245:9;6236:7;6232:23;6228:32;6225:2;;;6273:1;6270;6263:12;6225:2;6308:1;6325:61;6378:7;6358:9;6325:61;;6409:553;;;;6567:2;6555:9;6546:7;6542:23;6538:32;6535:2;;;6583:1;6580;6573:12;6535:2;6618:1;6635:61;6688:7;6668:9;6635:61;;;6625:71;;6597:105;6733:2;6751:64;6807:7;6798:6;6787:9;6783:22;6751:64;;;6741:74;;6712:109;6852:2;6870:76;6938:7;6929:6;6918:9;6914:22;6870:76;;;6860:86;;6831:121;6529:433;;;;;;6969:271;;7088:2;7076:9;7067:7;7063:23;7059:32;7056:2;;;7104:1;7101;7094:12;7056:2;7139:1;7156:68;7216:7;7196:9;7156:68;;7247:396;;;7383:2;7371:9;7362:7;7358:23;7354:32;7351:2;;;7399:1;7396;7389:12;7351:2;7434:1;7451:68;7511:7;7491:9;7451:68;;7650:319;;7793:2;7781:9;7772:7;7768:23;7764:32;7761:2;;;7809:1;7806;7799:12;7761:2;7844:1;7861:92;7945:7;7925:9;7861:92;;8699:354;;8820:2;8808:9;8799:7;8795:23;8791:32;8788:2;;;8836:1;8833;8826:12;8788:2;8871:24;;8915:18;8904:30;;8901:2;;;8947:1;8944;8937:12;8901:2;8967:70;9029:7;9020:6;9009:9;9005:22;8967:70;;9060:263;;9175:2;9163:9;9154:7;9150:23;9146:32;9143:2;;;9191:1;9188;9181:12;9143:2;9226:1;9243:64;9299:7;9279:9;9243:64;;9330:535;;;;9479:2;9467:9;9458:7;9454:23;9450:32;9447:2;;;9495:1;9492;9485:12;9447:2;9530:1;9547:64;9603:7;9583:9;9547:64;;;9537:74;;9509:108;9648:2;9666:64;9722:7;9713:6;9702:9;9698:22;9666:64;;;9656:74;;9627:109;9767:2;9785:64;9841:7;9832:6;9821:9;9817:22;9785:64;;9872:259;;9985:2;9973:9;9964:7;9960:23;9956:32;9953:2;;;10001:1;9998;9991:12;9953:2;10036:1;10053:62;10107:7;10087:9;10053:62;;10138:629;;;;;10299:3;10287:9;10278:7;10274:23;10270:33;10267:2;;;10316:1;10313;10306:12;10267:2;10351:1;10368:51;10411:7;10391:9;10368:51;;;10358:61;;10330:95;10456:2;10474:53;10519:7;10510:6;10499:9;10495:22;10474:53;;;10464:63;;10435:98;10564:2;10582:53;10627:7;10618:6;10607:9;10603:22;10582:53;;;10572:63;;10543:98;10672:2;10690:61;10743:7;10734:6;10723:9;10719:22;10690:61;;;10680:71;;10651:106;10261:506;;;;;;;;10775:203;;10877:61;10934:3;10926:6;10877:61;;;-1:-1;;10967:4;10958:14;;10870:108;10987:295;;11132:108;11236:3;11228:6;11132:108;;;-1:-1;;11269:6;11260:16;;11125:157;11291:295;;11436:108;11540:3;11532:6;11436:108;;;-1:-1;;11573:6;11564:16;;11429:157;11594:142;11685:45;11724:5;11685:45;;;11680:3;11673:58;11667:69;;;11743:137;11842:32;11868:5;11842:32;;12156:729;;12302:65;12361:5;12302:65;;;12380:76;12449:6;12444:3;12380:76;;;12373:83;;12477:67;12538:5;12477:67;;;12564:7;12592:1;12577:286;12602:6;12599:1;12596:13;12577:286;;;12669:6;12663:13;12690:78;12764:3;12749:13;12690:78;;;12683:85;;12785:71;12849:6;12785:71;;;12775:81;-1:-1;;12624:1;12617:9;12577:286;;;-1:-1;12876:3;;12281:604;-1:-1;;;;;12281:604;12968:922;;13171:83;13248:5;13171:83;;;13267:115;13375:6;13370:3;13267:115;;;13260:122;;13403:85;13482:5;13403:85;;;13508:7;13536:1;13521:347;13546:6;13543:1;13540:13;13521:347;;;13613:6;13607:13;13634:121;13751:3;13736:13;13634:121;;;13627:128;;13772:89;13854:6;13772:89;;;13762:99;-1:-1;;13568:1;13561:9;13521:347;;13973:922;;14176:83;14253:5;14176:83;;;14272:115;14380:6;14375:3;14272:115;;;14265:122;;14408:85;14487:5;14408:85;;;14513:7;14541:1;14526:347;14551:6;14548:1;14545:13;14526:347;;;14618:6;14612:13;14639:121;14756:3;14741:13;14639:121;;;14632:128;;14777:89;14859:6;14777:89;;;14767:99;-1:-1;;14573:1;14566:9;14526:347;;14903:94;14970:21;14985:5;14970:21;;15004:146;15092:52;15138:5;15092:52;;15320:136;15403:47;15444:5;15403:47;;15463:138;15552:43;15589:5;15552:43;;15753:347;;15865:39;15898:5;15865:39;;;15916:71;15980:6;15975:3;15916:71;;;15909:78;;15992:52;16037:6;16032:3;16025:4;16018:5;16014:16;15992:52;;;16065:29;16087:6;16065:29;;;16056:39;;;;15845:255;-1:-1;;;15845:255;16107:360;;16237:39;16270:5;16237:39;;;16288:89;16370:6;16365:3;16288:89;;;16281:96;;16382:52;16427:6;16422:3;16415:4;16408:5;16404:16;16382:52;;;16446:16;;;;;16217:250;-1:-1;;16217:250;16821:319;;16981:67;17045:2;17040:3;16981:67;;;-1:-1;;;17061:42;;17131:2;17122:12;;16967:173;-1:-1;;16967:173;17149:321;;17309:67;17373:2;17368:3;17309:67;;;-1:-1;;;17389:44;;17461:2;17452:12;;17295:175;-1:-1;;17295:175;17479:327;;17639:67;17703:2;17698:3;17639:67;;;17739:29;17719:50;;17797:2;17788:12;;17625:181;-1:-1;;17625:181;17815:313;;17975:67;18039:2;18034:3;17975:67;;;-1:-1;;;18055:36;;18119:2;18110:12;;17961:167;-1:-1;;17961:167;18203:1297;18437:23;;18368:4;18473:38;;;18203:1297;;18359:14;;;;18526:114;18359:14;18437:23;18526:114;;;18518:122;;18388:264;18730:4;18723:5;18719:16;18713:23;18742:63;18799:4;18794:3;18790:14;18776:12;18742:63;;;18662:149;18889:4;18882:5;18878:16;18872:23;18901:63;18958:4;18953:3;18949:14;18935:12;18901:63;;;18821:149;19062:4;19055:5;19051:16;19045:23;19074:63;19131:4;19126:3;19122:14;19108:12;19074:63;;;18980:163;19231:4;19224:5;19220:16;19214:23;19243:63;19300:4;19295:3;19291:14;19277:12;19243:63;;;19153:159;19393:4;19386:5;19382:16;19376:23;19405:63;19462:4;19457:3;19453:14;19439:12;19405:63;;;-1:-1;19491:4;18341:1159;-1:-1;;;18341:1159;19576:1862;19805:23;;19735:6;19726:16;;;19834:63;19730:3;19805:23;19834:63;;;19757:146;19985:4;19978:5;19974:16;19968:23;19997:63;20054:4;20049:3;20045:14;20031:12;19997:63;;;19913:153;20161:4;20154:5;20150:16;20144:23;20173:63;20230:4;20225:3;20221:14;20207:12;20173:63;;;20076:166;20325:4;20318:5;20314:16;20308:23;20337:63;20394:4;20389:3;20385:14;20371:12;20337:63;;;20252:154;20493:4;20486:5;20482:16;20476:23;20505:63;20562:4;20557:3;20553:14;20539:12;20505:63;;;20416:158;20663:4;20656:5;20652:16;20646:23;20675:63;20732:4;20727:3;20723:14;20709:12;20675:63;;;20584:160;20827:4;20820:5;20816:16;20810:23;20839:63;20896:4;20891:3;20887:14;20873:12;20839:63;;;20754:154;20999:4;20992:5;20988:16;20982:23;21011:63;21068:4;21063:3;21059:14;21045:12;21011:63;;;20918:162;21173:6;21166:5;21162:18;21156:25;21187:65;21244:6;21239:3;21235:16;21221:12;21187:65;;;21090:168;21344:6;21337:5;21333:18;21327:25;21358:59;21409:6;21404:3;21400:16;21386:12;21358:59;;;21268:155;19708:1730;;;;23438:3847;23667:23;;23597:6;23588:16;;;23696:63;23592:3;23667:23;23696:63;;;23619:146;23853:4;23846:5;23842:16;23836:23;23865:63;23922:4;23917:3;23913:14;23899:12;23865:63;;;23775:159;24022:4;24015:5;24011:16;24005:23;24034:63;24091:4;24086:3;24082:14;24068:12;24034:63;;;23944:159;24191:4;24184:5;24180:16;24174:23;24203:63;24260:4;24255:3;24251:14;24237:12;24203:63;;;24113:159;24362:4;24355:5;24351:16;24345:23;24374:63;24431:4;24426:3;24422:14;24408:12;24374:63;;;24282:161;24524:4;24517:5;24513:16;24507:23;24536:63;24593:4;24588:3;24584:14;24570:12;24536:63;;;24453:152;24687:4;24680:5;24676:16;24670:23;24699:63;24756:4;24751:3;24747:14;24733:12;24699:63;;;24615:153;24848:4;24841:5;24837:16;24831:23;24860:63;24917:4;24912:3;24908:14;24894:12;24860:63;;;24778:151;25007:6;25000:5;24996:18;24990:25;25021:65;25078:6;25073:3;25069:16;25055:12;25021:65;;;24939:153;25182:6;25175:5;25171:18;25165:25;25196:65;25253:6;25248:3;25244:16;25230:12;25196:65;;;25102:165;25344:6;25337:5;25333:18;25327:25;25358:59;25409:6;25404:3;25400:16;25386:12;25358:59;;;25277:146;25516:6;25509:5;25505:18;25499:25;25530:65;25587:6;25582:3;25578:16;25564:12;25530:65;;;25433:168;25692:6;25685:5;25681:18;25675:25;25706:65;25763:6;25758:3;25754:16;25740:12;25706:65;;;25611:166;25860:6;25853:5;25849:18;25843:25;25874:65;25931:6;25926:3;25922:16;25908:12;25874:65;;;25787:158;26032:6;26025:5;26021:18;26015:25;26046:65;26103:6;26098:3;26094:16;26080:12;26046:65;;;25955:162;26193:6;26186:5;26182:18;26176:25;26207:75;26274:6;26269:3;26265:16;26251:12;26207:75;;;26127:161;26370:6;26363:5;26359:18;26353:25;26384:65;26441:6;26436:3;26432:16;26418:12;26384:65;;;26298:157;26539:6;26532:5;26528:18;26522:25;26553:65;26610:6;26605:3;26601:16;26587:12;26553:65;;;26465:159;26705:6;26698:5;26694:18;26688:25;26719:59;26770:6;26765:3;26761:16;26747:12;26719:59;;;26634:150;26865:6;26858:5;26854:18;26848:25;26879:59;26930:6;26925:3;26921:16;26907:12;26879:59;;;26794:150;27022:6;27015:5;27011:18;27005:25;27036:65;27093:6;27088:3;27084:16;27070:12;27036:65;;;26954:153;27185:6;27178:5;27174:18;27168:25;27199:65;27256:6;27251:3;27247:16;27233:12;31201:103;31274:24;31292:5;31274:24;;31431:266;;31577:95;31668:3;31659:6;31577:95;;31704:213;31822:2;31807:18;;31836:71;31811:9;31880:6;31836:71;;31924:229;32050:2;32035:18;;32064:79;32039:9;32116:6;32064:79;;32160:324;32306:2;32291:18;;32320:71;32295:9;32364:6;32320:71;;;32402:72;32470:2;32459:9;32455:18;32446:6;32402:72;;32491:354;32652:2;32637:18;;32666:71;32641:9;32710:6;32666:71;;;32748:87;32831:2;32820:9;32816:18;32807:6;32748:87;;32852:477;33078:2;33092:47;;;33063:18;;33153:166;33063:18;33305:6;33153:166;;33336:477;33562:2;33576:47;;;33547:18;;33637:166;33547:18;33789:6;33637:166;;33820:243;33953:2;33938:18;;33967:86;33942:9;34026:6;33967:86;;34070:368;34238:2;34223:18;;34252:77;34227:9;34302:6;34252:77;;34820:293;34954:2;34968:47;;;34939:18;;35029:74;34939:18;35089:6;35029:74;;35428:407;35619:2;35633:47;;;35604:18;;35694:131;35604:18;35694:131;;35842:407;36033:2;36047:47;;;36018:18;;36108:131;36018:18;36108:131;;36256:407;36447:2;36461:47;;;36432:18;;36522:131;36432:18;36522:131;;36670:407;36861:2;36875:47;;;36846:18;;36936:131;36846:18;36936:131;;37084:389;37266:2;37280:47;;;37251:18;;37341:122;37251:18;37449:6;37341:122;;37480:346;37664:3;37649:19;;37679:137;37653:9;37789:6;37679:137;;37833:346;38017:3;38002:19;;38032:137;38006:9;38142:6;38032:137;;38186:213;38304:2;38289:18;;38318:71;38293:9;38362:6;38318:71;;38406:256;38468:2;38462:9;38494:17;;;38569:18;38554:34;;38590:22;;;38551:62;38548:2;;;38626:1;38623;38616:12;38548:2;38642;38635:22;38446:216;;-1:-1;38446:216;38669:319;;38843:18;38835:6;38832:30;38829:2;;;38875:1;38872;38865:12;38829:2;-1:-1;38910:4;38898:17;;;38963:15;;38766:222;38995:318;;39135:18;39127:6;39124:30;39121:2;;;39167:1;39164;39157:12;39121:2;-1:-1;39298:4;39234;39211:17;;;;-1:-1;;39207:33;39288:15;;39058:255;39320:162;39455:4;39446:14;;39403:79;39863:148;39977:12;;39948:63;41033:168;41141:19;;;41190:4;41181:14;;41134:67;41967:91;;42029:24;42047:5;42029:24;;42171:85;42237:13;42230:21;;42213:43;42263:106;;42340:24;42358:5;42340:24;;42738:130;42812:5;42818:45;42812:5;42818:45;;42875:121;-1:-1;;;;;42937:54;;42920:76;43003:72;43065:5;43048:27;43082:81;43153:4;43142:16;;43125:38;43170:129;;43257:37;43288:5;43257:37;;43594:130;;43683:36;43713:5;43683:36;;43731:112;;43816:22;43832:5;43816:22;;44213:268;44278:1;44285:101;44299:6;44296:1;44293:13;44285:101;;;44366:11;;;44360:18;44347:11;;;44340:39;44321:2;44314:10;44285:101;;;44401:6;44398:1;44395:13;44392:2;;;-1:-1;;44466:1;44448:16;;44441:27;44262:219;44489:97;44577:2;44557:14;-1:-1;;44553:28;;44537:49;44594:103;44675:1;44668:5;44665:12;44655:2;;44681:9;44655:2;44649:48;;44704:117;44773:24;44791:5;44773:24;;;44766:5;44763:35;44753:2;;44812:1;44809;44802:12;44968:111;45034:21;45049:5;45034:21;;45086:147;45170:39;45203:5;45170:39;;45748:106;45829:1;45822:5;45819:12;45809:2;;45845:1;45842;45835:12;45861:117;45930:24;45948:5;45930:24;;45985:113;46052:22;46068:5;46052:22;
Swarm Source
bzzr://b0c5901c60d5b093fda775abd125e6a934f17b0ab1c5821794874ad977816a16
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.