Overview
ETH Balance
0 ETH
ETH Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 9 from a total of 9 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Transfer Ownersh... | 4988413 | 505 days ago | IN | 0 ETH | 0.00003028 | ||||
Set Token Id | 2069544 | 561 days ago | IN | 0 ETH | 0.00018628 | ||||
Set Token Id | 2066256 | 561 days ago | IN | 0 ETH | 0.00013005 | ||||
Transfer Ownersh... | 2066175 | 561 days ago | IN | 0 ETH | 0.00006951 | ||||
Transfer Ownersh... | 89572 | 650 days ago | IN | 0 ETH | 0.00008018 | ||||
Set Token Id | 148 | 661 days ago | IN | 0 ETH | 0.00066313 | ||||
Set Token Id | 147 | 661 days ago | IN | 0 ETH | 0.00066313 | ||||
Set Token Id | 146 | 661 days ago | IN | 0 ETH | 0.00066301 | ||||
Set Token Id | 145 | 661 days ago | IN | 0 ETH | 0.00064155 |
Loading...
Loading
Contract Name:
OvixPythOracle
Compiler Version
v0.8.4+commit.c7e474f2
Contract Source Code (Solidity)
/** *Submitted for verification at zkevm.polygonscan.com on 2023-08-22 */ //SPDX-License-Identifier: MIT pragma solidity 0.8.4; interface IComptroller { /// @notice Indicator that this is a Comptroller contract (for inspection) function isComptroller() external view returns(bool); /*** Assets You Are In ***/ function enterMarkets(address[] calldata oTokens) external returns (uint[] memory); function exitMarket(address oToken) external returns (uint); /*** Policy Hooks ***/ function mintAllowed(address oToken, address minter, uint mintAmount) external returns (uint); function mintVerify(address oToken, address minter, uint mintAmount, uint mintTokens) external; function redeemAllowed(address oToken, address redeemer, uint redeemTokens) external returns (uint); function redeemVerify(address oToken, address redeemer, uint redeemAmount, uint redeemTokens) external; function borrowAllowed(address oToken, address borrower, uint borrowAmount) external returns (uint); function borrowVerify(address oToken, address borrower, uint borrowAmount) external; function repayBorrowAllowed( address oToken, address payer, address borrower, uint repayAmount) external returns (uint); function liquidateBorrowAllowed( address oTokenBorrowed, address oTokenCollateral, address liquidator, address borrower, uint repayAmount) external returns (uint); function seizeAllowed( address oTokenCollateral, address oTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external returns (uint); function seizeVerify( address oTokenCollateral, address oTokenBorrowed, address liquidator, address borrower, uint seizeTokens) external; function transferAllowed(address oToken, address src, address dst, uint transferTokens) external returns (uint); function transferVerify(address oToken, address src, address dst, uint transferTokens) external; /*** Liquidity/Liquidation Calculations ***/ function liquidateCalculateSeizeTokens( address oTokenBorrowed, address oTokenCollateral, uint repayAmount) external view returns (uint, uint); function isMarket(address market) external view returns(bool); function getBoostManager() external view returns(address); function getAllMarkets() external view returns(IOToken[] memory); function oracle() external view returns(PriceOracle); function updateAndDistributeSupplierRewardsForToken( address oToken, address account ) external; function updateAndDistributeBorrowerRewardsForToken( address oToken, address borrower ) external; function _setRewardSpeeds( address[] memory oTokens, uint256[] memory supplySpeeds, uint256[] memory borrowSpeeds ) external; } /** * @title 0VIX's IInterestRateModel Interface * @author 0VIX */ interface IInterestRateModel { /// @notice Indicator that this is an InterestRateModel contract (for inspection) function isInterestRateModel() external view returns(bool); /** * @notice Calculates the current borrow interest rate per timestmp * @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 amount of reserves the market has * @return The borrow rate per timestmp (as a percentage, and scaled by 1e18) */ function getBorrowRate(uint cash, uint borrows, uint reserves) external view returns (uint); /** * @notice Calculates the current supply interest rate per timestmp * @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 amount of reserves the market has * @param reserveFactorMantissa The current reserve factor the market has * @return The supply rate per timestmp (as a percentage, and scaled by 1e18) */ function getSupplyRate(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) external view returns (uint); } /** * @title IEIP20NonStandard * @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 IEIP20NonStandard { /** * @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 balance 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 success 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 remaining 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 ERC 20 Token Standard Interface * https://eips.ethereum.org/EIPS/eip-20 */ interface IEIP20 { 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 balance 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 success 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 success 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 success 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 remaining 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); } interface IOToken is IEIP20{ /** * @notice Indicator that this is a OToken contract (for inspection) */ function isOToken() external view returns(bool); /*** Market Events ***/ /** * @notice Event emitted when interest is accrued */ event AccrueInterest(uint cashPrior, uint interestAccumulated, uint borrowIndex, uint totalBorrows); /** * @notice Event emitted when tokens are minted */ event Mint(address minter, uint mintAmount, uint mintTokens); /** * @notice Event emitted when tokens are redeemed */ event Redeem(address redeemer, uint redeemAmount, uint redeemTokens); /** * @notice Event emitted when underlying is borrowed */ event Borrow(address borrower, uint borrowAmount, uint accountBorrows, uint totalBorrows); /** * @notice Event emitted when a borrow is repaid */ event RepayBorrow(address payer, address borrower, uint repayAmount, uint accountBorrows, uint totalBorrows); /** * @notice Event emitted when a borrow is liquidated */ event LiquidateBorrow(address liquidator, address borrower, uint repayAmount, address oTokenCollateral, uint 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 comptroller is changed */ event NewComptroller(IComptroller oldComptroller, IComptroller newComptroller); /** * @notice Event emitted when interestRateModel is changed */ event NewMarketInterestRateModel(IInterestRateModel oldInterestRateModel, IInterestRateModel newInterestRateModel); /** * @notice Event emitted when the reserve factor is changed */ event NewReserveFactor(uint oldReserveFactorMantissa, uint newReserveFactorMantissa); /** * @notice Event emitted when the protocol seize share is changed */ event NewProtocolSeizeShare(uint oldProtocolSeizeShareMantissa, uint newProtocolSeizeShareMantissa); /** * @notice Event emitted when the reserves are added */ event ReservesAdded(address benefactor, uint addAmount, uint newTotalReserves); /** * @notice Event emitted when the reserves are reduced */ event ReservesReduced(address admin, uint reduceAmount, uint newTotalReserves); function accrualBlockTimestamp() external returns(uint256); /*** User Interface ***/ function balanceOfUnderlying(address owner) external returns (uint); function getAccountSnapshot(address account) external view returns (uint, uint, uint, uint); function borrowRatePerTimestamp() external view returns (uint); function supplyRatePerTimestamp() external view returns (uint); function totalBorrowsCurrent() external returns (uint); function borrowBalanceCurrent(address account) external returns (uint); function borrowBalanceStored(address account) external view returns (uint); function exchangeRateCurrent() external returns (uint); function exchangeRateStored() external view returns (uint); function getCash() external view returns (uint); function accrueInterest() external returns (uint); function seize(address liquidator, address borrower, uint seizeTokens) external returns (uint); function totalBorrows() external view returns(uint); function comptroller() external view returns(IComptroller); function borrowIndex() external view returns(uint); function reserveFactorMantissa() external view returns(uint); /*** Admin Functions ***/ function _setPendingAdmin(address payable newPendingAdmin) external returns (uint); function _acceptAdmin() external returns (uint); function _setComptroller(IComptroller newComptroller) external returns (uint); function _setReserveFactor(uint newReserveFactorMantissa) external returns (uint); function _reduceReserves(uint reduceAmount) external returns (uint); function _setInterestRateModel(IInterestRateModel newInterestRateModel) external returns (uint); function _setProtocolSeizeShare(uint newProtocolSeizeShareMantissa) external returns (uint); } abstract contract PriceOracle { /// @notice Indicator that this is a PriceOracle contract (for inspection) bool public constant isPriceOracle = true; /** * @notice Get the underlying price of a oToken asset * @param oToken The oToken to get the underlying price of * @return The underlying asset price mantissa (scaled by 1e18). * Zero means the price is unavailable. */ function getUnderlyingPrice(IOToken oToken) external virtual view returns (uint); } interface IOErc20 { /*** User Interface ***/ function mint(uint mintAmount) external; function redeem(uint redeemTokens) external; function redeemUnderlying(uint redeemAmount) external; function borrow(uint borrowAmount) external; function repayBorrow(uint repayAmount) external; function repayBorrowBehalf(address borrower, uint repayAmount) external; function liquidateBorrow(address borrower, uint repayAmount, IOToken oTokenCollateral) external; function sweepToken(IEIP20NonStandard token) external; function underlying() external view returns(address); /*** Admin Functions ***/ function _addReserves(uint addAmount) external returns (uint); } abstract contract OTokenStorage is IOToken { bool public constant override isOToken = true; /** * @dev Guard variable for re-entrancy checks */ bool internal _notEntered; /** * @notice EIP-20 token name for this token */ string public override name; /** * @notice EIP-20 token symbol for this token */ string public override symbol; /** * @notice EIP-20 token decimals for this token */ uint8 public override decimals; /** * @notice Maximum borrow rate that can ever be applied (.0005% / block) */ uint internal constant borrowRateMaxMantissa = 0.0005e16; /** * @notice Maximum fraction of interest that can be set aside for reserves */ uint 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-oToken operations */ IComptroller public override comptroller; /** * @notice Model which tells what the current interest rate should be */ IInterestRateModel public interestRateModel; /** * @notice Initial exchange rate used when minting the first OTokens (used when totalSupply = 0) */ uint internal initialExchangeRateMantissa; /** * @notice Fraction of interest currently set aside for reserves */ uint public override reserveFactorMantissa; /** * @notice Block number that interest was last accrued at */ uint public override accrualBlockTimestamp; /** * @notice Accumulator of the total earned interest rate since the opening of the market */ uint public override borrowIndex; /** * @notice Total amount of outstanding borrows of the underlying in this market */ uint public override totalBorrows; /** * @notice Total amount of reserves of the underlying held in this market */ uint public totalReserves; /** * @notice Total number of tokens in circulation */ uint public override totalSupply; /** * @notice Official record of token balances for each account */ mapping (address => uint) internal accountTokens; /** * @notice Approved token transfer amounts on behalf of others */ mapping (address => mapping (address => uint)) 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 { uint principal; uint interestIndex; } /** * @notice Mapping of account addresses to outstanding borrow balances */ mapping(address => BorrowSnapshot) internal accountBorrows; /** * @notice Share of seized collateral that is added to reserves */ uint public protocolSeizeShareMantissa; } contract ComptrollerErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED, COMPTROLLER_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(uint error, uint info, uint 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 (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return uint(err); } } contract TokenErrorReporter { enum Error { NO_ERROR, UNAUTHORIZED, BAD_INPUT, COMPTROLLER_REJECTION, COMPTROLLER_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_ACCUMULATED_INTEREST_CALCULATION_FAILED, ACCRUE_INTEREST_BORROW_RATE_CALCULATION_FAILED, ACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED, ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED, ACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED, ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED, BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, BORROW_ACCRUE_INTEREST_FAILED, BORROW_CASH_NOT_AVAILABLE, BORROW_FRESHNESS_CHECK, BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED, BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED, BORROW_MARKET_NOT_LISTED, BORROW_COMPTROLLER_REJECTION, LIQUIDATE_ACCRUE_BORROW_INTEREST_FAILED, LIQUIDATE_ACCRUE_COLLATERAL_INTEREST_FAILED, LIQUIDATE_COLLATERAL_FRESHNESS_CHECK, LIQUIDATE_COMPTROLLER_REJECTION, LIQUIDATE_COMPTROLLER_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_BALANCE_INCREMENT_FAILED, LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED, LIQUIDATE_SEIZE_COMPTROLLER_REJECTION, LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER, LIQUIDATE_SEIZE_TOO_MUCH, MINT_ACCRUE_INTEREST_FAILED, MINT_COMPTROLLER_REJECTION, MINT_EXCHANGE_CALCULATION_FAILED, MINT_EXCHANGE_RATE_READ_FAILED, MINT_FRESHNESS_CHECK, MINT_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED, MINT_NEW_TOTAL_SUPPLY_CALCULATION_FAILED, MINT_TRANSFER_IN_FAILED, MINT_TRANSFER_IN_NOT_POSSIBLE, REDEEM_ACCRUE_INTEREST_FAILED, REDEEM_COMPTROLLER_REJECTION, REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED, REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED, REDEEM_EXCHANGE_RATE_READ_FAILED, REDEEM_FRESHNESS_CHECK, REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED, REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED, 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_ACCUMULATED_BALANCE_CALCULATION_FAILED, REPAY_BORROW_COMPTROLLER_REJECTION, REPAY_BORROW_FRESHNESS_CHECK, REPAY_BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED, REPAY_BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED, REPAY_BORROW_TRANSFER_IN_NOT_POSSIBLE, SET_COLLATERAL_FACTOR_OWNER_CHECK, SET_COLLATERAL_FACTOR_VALIDATION, SET_COMPTROLLER_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_COMPTROLLER_REJECTION, TRANSFER_NOT_ALLOWED, TRANSFER_NOT_ENOUGH, TRANSFER_TOO_MUCH, ADD_RESERVES_ACCRUE_INTEREST_FAILED, ADD_RESERVES_FRESH_CHECK, ADD_RESERVES_TRANSFER_IN_NOT_POSSIBLE, SET_PROTOCOL_SEIZE_SHARE_ACCRUE_INTEREST_FAILED, SET_PROTOCOL_SEIZE_SHARE_OWNER_CHECK, SET_PROTOCOL_SEIZE_SHARE_FRESH_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(uint error, uint info, uint 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 (uint) { emit Failure(uint(err), uint(info), 0); return uint(err); } /** * @dev use this when reporting an opaque error from an upgradeable collaborator contract */ function failOpaque(Error err, FailureInfo info, uint opaqueError) internal returns (uint) { emit Failure(uint(err), uint(info), opaqueError); return uint(err); } } /** * @title Careful Math * @author 0VIX * @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(uint a, uint b) internal pure returns (MathError, uint) { unchecked { if (a == 0) { return (MathError.NO_ERROR, 0); } uint 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(uint a, uint b) internal pure returns (MathError, uint) { unchecked { 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(uint a, uint b) internal pure returns (MathError, uint) { unchecked { 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(uint a, uint b) internal pure returns (MathError, uint) { unchecked { uint 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(uint a, uint b, uint c) internal pure returns (MathError, uint) { (MathError err0, uint 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 0VIX * @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 ExponentialNoError { uint constant expScale = 1e18; uint constant doubleScale = 1e36; uint constant halfExpScale = expScale/2; uint constant mantissaOne = expScale; struct Exp { uint mantissa; } struct Double { uint mantissa; } /** * @dev Truncates the given exp to a whole number value. * For example, truncate(Exp{mantissa: 15 * expScale}) = 15 */ function truncate(Exp memory exp) pure internal returns (uint) { // Note: We are not using careful math here as we're performing a division that cannot fail return exp.mantissa / expScale; } /** * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer. */ function mul_ScalarTruncate(Exp memory a, uint scalar) pure internal returns (uint) { return truncate(mul_(a, scalar)); } /** * @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, uint scalar, uint addend) pure internal returns (uint) { return truncate(mul_(a, scalar)) + addend; } /** * @dev Checks if first Exp is less than second Exp. */ function lessThanExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa < right.mantissa; } /** * @dev Checks if left Exp <= right Exp. */ function lessThanOrEqualExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa <= right.mantissa; } /** * @dev Checks if left Exp > right Exp. */ function greaterThanExp(Exp memory left, Exp memory right) pure internal returns (bool) { return left.mantissa > right.mantissa; } /** * @dev returns true if Exp is exactly zero */ function isZeroExp(Exp memory value) pure internal returns (bool) { return value.mantissa == 0; } function safe224(uint n) pure internal returns (uint224) { require(n <= type(uint224).max, "safe224 overflow"); return uint224(n); } function safe32(uint n) pure internal returns (uint32) { require(n <= type(uint32).max, "safe32 overflow"); return uint32(n); } function add_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: a.mantissa + b.mantissa}); } function add_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: a.mantissa + b.mantissa}); } function add_(uint a, uint b, string memory errorMessage) pure internal returns (uint c) { unchecked { require((c = a + b ) >= a, errorMessage); } } function sub_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: a.mantissa - b.mantissa}); } function sub_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: a.mantissa - b.mantissa}); } function sub_(uint a, uint b, string memory errorMessage) pure internal returns (uint c) { unchecked { require((c = a - b) <= a, errorMessage); } } function mul_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: (a.mantissa * b.mantissa) / expScale}); } function mul_(Exp memory a, uint b) pure internal returns (Exp memory) { return Exp({mantissa: a.mantissa * b}); } function mul_(uint a, Exp memory b) pure internal returns (uint) { return (a * b.mantissa) / expScale; } function mul_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: (a.mantissa * b.mantissa) / doubleScale}); } function mul_(Double memory a, uint b) pure internal returns (Double memory) { return Double({mantissa: a.mantissa * b}); } function mul_(uint a, Double memory b) pure internal returns (uint) { return (a * b.mantissa) / doubleScale; } function mul_(uint a, uint b, string memory errorMessage) pure internal returns (uint c) { unchecked { require(a == 0 || (c = a * b) / a == b, errorMessage); } } function div_(Exp memory a, Exp memory b) pure internal returns (Exp memory) { return Exp({mantissa: (a.mantissa * expScale) / b.mantissa}); } function div_(Exp memory a, uint b) pure internal returns (Exp memory) { return Exp({mantissa: a.mantissa / b}); } function div_(uint a, Exp memory b) pure internal returns (uint) { return (a * expScale) / b.mantissa; } function div_(Double memory a, Double memory b) pure internal returns (Double memory) { return Double({mantissa: (a.mantissa * doubleScale) / b.mantissa}); } function div_(Double memory a, uint b) pure internal returns (Double memory) { return Double({mantissa: a.mantissa / b}); } function div_(uint a, Double memory b) pure internal returns (uint) { return (a * doubleScale) / b.mantissa; } function div_(uint a, uint b, string memory errorMessage) pure internal returns (uint) { unchecked { require(b > 0, errorMessage); return a / b; } } function fraction(uint a, uint b) pure internal returns (Double memory) { return Double({mantissa: (a * doubleScale) / b}); } } /** * @title Exponential module for storing fixed-precision decimals * @author 0VIX * @dev Legacy contract for compatibility reasons with existing contracts that still use MathError * @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, ExponentialNoError { /** * @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(uint num, uint denom) pure internal returns (MathError, Exp memory) { (MathError err0, uint scaledNumerator) = mulUInt(num, expScale); if (err0 != MathError.NO_ERROR) { return (err0, Exp({mantissa: 0})); } (MathError err1, uint 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) pure internal returns (MathError, Exp memory) { (MathError error, uint 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) pure internal returns (MathError, Exp memory) { (MathError error, uint 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, uint scalar) pure internal returns (MathError, Exp memory) { (MathError err0, uint 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, uint scalar) pure internal returns (MathError, uint) { (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, uint scalar, uint addend) pure internal returns (MathError, uint) { (MathError err, Exp memory product) = mulScalar(a, scalar); if (err != MathError.NO_ERROR) { return (err, 0); } return addUInt(truncate(product), addend); } /** * @dev Divide an Exp by a scalar, returning a new Exp. */ function divScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) { (MathError err0, uint 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(uint scalar, Exp memory divisor) pure internal 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, uint 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(uint scalar, Exp memory divisor) pure internal returns (MathError, uint) { (MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor); if (err != MathError.NO_ERROR) { return (err, 0); } return (MathError.NO_ERROR, truncate(fraction)); } /** * @dev Multiplies two exponentials, returning a new exponential. */ function mulExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) { (MathError err0, uint 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, uint doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct); if (err1 != MathError.NO_ERROR) { return (err1, Exp({mantissa: 0})); } (MathError err2, uint 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(uint a, uint b) pure internal 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) pure internal 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) pure internal returns (MathError, Exp memory) { return getExp(a.mantissa, b.mantissa); } } // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol) /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } interface IBoostManager { function updateBoostBasis(address user) external returns (bool); function updateBoostSupplyBalances( address market, address user, uint256 oldBalance, uint256 newBalance ) external; function updateBoostBorrowBalances( address market, address user, uint256 oldBalance, uint256 newBalance ) external; function boostedSupplyBalanceOf(address market, address user) external view returns (uint256); function boostedBorrowBalanceOf(address market, address user) external view returns (uint256); function boostedTotalSupply(address market) external view returns (uint256); function boostedTotalBorrows(address market) external view returns (uint256); function setAuthorized(address addr, bool flag) external; function setVeOVIX(IERC20 ve) external; function isAuthorized(address addr) external view returns (bool); } /** * @title 0VIX's OToken Contract * @notice Abstract base for OTokens * @author 0VIX */ abstract contract OTokenTemp is OTokenStorage, Exponential, TokenErrorReporter { /** * @notice Initialize the money market * @param comptroller_ The address of the Comptroller * @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( IComptroller comptroller_, IInterestRateModel interestRateModel_, uint256 initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_ ) internal { require(msg.sender == admin, "only admin may initialize"); require( accrualBlockTimestamp == 0 && borrowIndex == 0, "already initialized" ); // Set initial exchange rate initialExchangeRateMantissa = initialExchangeRateMantissa_; require( initialExchangeRateMantissa > 0, "init exchange rate must be > 0" ); // Set the comptroller require( _setComptroller(comptroller_) == uint256(Error.NO_ERROR), "set comptroller failed" ); // Initialize block timestamp and borrow index (block timestamp mocks depend on comptroller being set) accrualBlockTimestamp = getBlockTimestamp(); borrowIndex = mantissaOne; 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; } function _updateBoostSupplyBalances( address user, uint256 oldBalance, uint256 newBalance ) internal { address boostManager = comptroller.getBoostManager(); if ( boostManager != address(0) && IBoostManager(boostManager).isAuthorized(address(this)) ) { IBoostManager(boostManager).updateBoostSupplyBalances( address(this), user, oldBalance, newBalance ); } } function _updateBoostBorrowBalances( address user, uint256 oldBalance, uint256 newBalance ) internal { address boostManager = comptroller.getBoostManager(); if ( boostManager != address(0) && IBoostManager(boostManager).isAuthorized(address(this)) ) { IBoostManager(boostManager).updateBoostBorrowBalances( address(this), user, oldBalance, newBalance ); } } /** * @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 = comptroller.transferAllowed( address(this), src, dst, tokens ); require(allowed == 0, "ERC20: transfer not allowed"); /* Do not allow self-transfers */ require(src != dst, "ERC20: self-transfer not allowed"); /* Get the allowance, infinite for the account owner */ uint256 startingAllowance = 0; if (spender == src) { startingAllowance = type(uint256).max; } else { startingAllowance = transferAllowances[src][spender]; } /* Do the calculations, checking for {under,over}flow */ MathError mathErr; uint256 allowanceNew; uint256 srcTokensNew; uint256 dstTokensNew; (mathErr, allowanceNew) = subUInt(startingAllowance, tokens); require( mathErr == MathError.NO_ERROR, "ERC20: decreased allowance below zero" ); (mathErr, srcTokensNew) = subUInt(accountTokens[src], tokens); require( mathErr == MathError.NO_ERROR, "ERC20: transfer amount exceeds balance" ); (mathErr, dstTokensNew) = addUInt(accountTokens[dst], tokens); require( mathErr == MathError.NO_ERROR, "ERC20: maximum destination balance reached" ); ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) _updateBoostSupplyBalances(src, accountTokens[src], srcTokensNew); _updateBoostSupplyBalances(dst, accountTokens[dst], dstTokensNew); accountTokens[src] = srcTokensNew; accountTokens[dst] = dstTokensNew; /* Eat some of the allowance (if necessary) */ if (startingAllowance != type(uint256).max) { transferAllowances[src][spender] = allowanceNew; } /* We emit a Transfer event */ emit Transfer(src, dst, tokens); // unused function // comptroller.transferVerify(address(this), src, dst, tokens); return uint256(Error.NO_ERROR); } /** * @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 override 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 override 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 override 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 override 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 override 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 override returns (uint256) { Exp memory exchangeRate = Exp({mantissa: exchangeRateCurrent()}); (MathError mErr, uint256 balance) = mulScalarTruncate( exchangeRate, accountTokens[owner] ); require(mErr == MathError.NO_ERROR, "balance could not be calculated"); return balance; } /** * @notice Get a snapshot of the account's balances, and the cached exchange rate * @dev This is used by comptroller 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 override returns ( uint256, uint256, uint256, uint256 ) { uint256 oTokenBalance = accountTokens[account]; uint256 borrowBalance; uint256 exchangeRateMantissa; MathError mErr; (mErr, borrowBalance) = borrowBalanceStoredInternal(account); if (mErr != MathError.NO_ERROR) { return (uint256(Error.MATH_ERROR), 0, 0, 0); } (mErr, exchangeRateMantissa) = exchangeRateStoredInternal(); if (mErr != MathError.NO_ERROR) { return (uint256(Error.MATH_ERROR), 0, 0, 0); } return ( uint256(Error.NO_ERROR), oTokenBalance, borrowBalance, exchangeRateMantissa ); } /** * @dev Function to simply retrieve block timestamp * This exists mainly for inheriting test contracts to stub this result. */ function getBlockTimestamp() internal view virtual returns (uint256) { return block.timestamp; } /** * @notice Returns the current per-timestamp borrow interest rate for this oToken * @return The borrow interest rate per timestmp, scaled by 1e18 */ function borrowRatePerTimestamp() external view override returns (uint256) { return interestRateModel.getBorrowRate( getCashPrior(), totalBorrows, totalReserves ); } /** * @notice Returns the current per-timestamp supply interest rate for this oToken * @return The supply interest rate per timestmp, scaled by 1e18 */ function supplyRatePerTimestamp() external view override returns (uint256) { return interestRateModel.getSupplyRate( getCashPrior(), totalBorrows, totalReserves, reserveFactorMantissa ); } /** * @notice Returns the current total borrows plus accrued interest * @return The total borrows with interest */ function totalBorrowsCurrent() external override 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 override 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 override returns (uint256) { (MathError err, uint256 result) = borrowBalanceStoredInternal(account); require(err == MathError.NO_ERROR, "borrowBalanceStored failed"); return result; } /** * @notice Return the borrow balance of account based on stored data * @param account The address whose balance should be calculated * @return (error code, the calculated balance or 0 if error code is non-zero) */ function borrowBalanceStoredInternal(address account) internal view returns (MathError, uint256) { /* Note: we do not assert that the market is up to date */ MathError mathErr; uint256 principalTimesIndex; uint256 result; /* 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 (MathError.NO_ERROR, 0); } /* Calculate new borrow balance using the interest index: * recentBorrowBalance = borrower.borrowBalance * market.borrowIndex / borrower.borrowIndex */ (mathErr, principalTimesIndex) = mulUInt( borrowSnapshot.principal, borrowIndex ); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } (mathErr, result) = divUInt( principalTimesIndex, borrowSnapshot.interestIndex ); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } return (MathError.NO_ERROR, result); } /** * @notice Accrue interest then return the up-to-date exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateCurrent() public override nonReentrant returns (uint256) { require( accrueInterest() == uint256(Error.NO_ERROR), "accrue interest failed" ); return exchangeRateStored(); } /** * @notice Calculates the exchange rate from the underlying to the OToken * @dev This function does not accrue interest before calculating the exchange rate * @return Calculated exchange rate scaled by 1e18 */ function exchangeRateStored() public view override returns (uint256) { (MathError err, uint256 result) = exchangeRateStoredInternal(); require(err == MathError.NO_ERROR, "exchangeRateStored failed"); return result; } /** * @notice Calculates the exchange rate from the underlying to the OToken * @dev This function does not accrue interest before calculating the exchange rate * @return (error code, calculated exchange rate scaled by 1e18) */ function exchangeRateStoredInternal() internal view virtual returns (MathError, uint256) { uint256 _totalSupply = totalSupply; if (_totalSupply == 0) { /* * If there are no tokens minted: * exchangeRate = initialExchangeRate */ return (MathError.NO_ERROR, initialExchangeRateMantissa); } else { /* * Otherwise: * exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply */ uint256 totalCash = getCashPrior(); uint256 cashPlusBorrowsMinusReserves; Exp memory exchangeRate; MathError mathErr; (mathErr, cashPlusBorrowsMinusReserves) = addThenSubUInt( totalCash, totalBorrows, totalReserves ); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } (mathErr, exchangeRate) = getExp( cashPlusBorrowsMinusReserves, _totalSupply ); if (mathErr != MathError.NO_ERROR) { return (mathErr, 0); } return (MathError.NO_ERROR, exchangeRate.mantissa); } } /** * @notice Get cash balance of this oToken in the underlying asset * @return The quantity of underlying asset owned by this contract */ function getCash() external view override returns (uint256) { return getCashPrior(); } /** * @notice Applies accrued interest to total borrows and reserves * @dev This calculates interest accrued from the last checkpointed block * up to the current block and writes new checkpoint to storage. */ function accrueInterest() public override 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 blocks elapsed since the last accrual */ (MathError mathErr, uint256 blockDelta) = subUInt( currentBlockTimestamp, accrualBlockTimestampPrior ); require( mathErr == MathError.NO_ERROR, "could not calculate block delta" ); /* * Calculate the interest accumulated into borrows and reserves and the new index: * simpleInterestFactor = borrowRate * blockDelta * interestAccumulated = simpleInterestFactor * totalBorrows * totalBorrowsNew = interestAccumulated + totalBorrows * totalReservesNew = interestAccumulated * reserveFactor + totalReserves * borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex */ Exp memory simpleInterestFactor; uint256 interestAccumulated; uint256 totalBorrowsNew; uint256 totalReservesNew; uint256 borrowIndexNew; (mathErr, simpleInterestFactor) = mulScalar( Exp({mantissa: borrowRateMantissa}), blockDelta ); if (mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo .ACCRUE_INTEREST_SIMPLE_INTEREST_FACTOR_CALCULATION_FAILED, uint256(mathErr) ); } (mathErr, interestAccumulated) = mulScalarTruncate( simpleInterestFactor, borrowsPrior ); if (mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo .ACCRUE_INTEREST_ACCUMULATED_INTEREST_CALCULATION_FAILED, uint256(mathErr) ); } (mathErr, totalBorrowsNew) = addUInt(interestAccumulated, borrowsPrior); if (mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo .ACCRUE_INTEREST_NEW_TOTAL_BORROWS_CALCULATION_FAILED, uint256(mathErr) ); } (mathErr, totalReservesNew) = mulScalarTruncateAddUInt( Exp({mantissa: reserveFactorMantissa}), interestAccumulated, reservesPrior ); if (mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo .ACCRUE_INTEREST_NEW_TOTAL_RESERVES_CALCULATION_FAILED, uint256(mathErr) ); } (mathErr, borrowIndexNew) = mulScalarTruncateAddUInt( simpleInterestFactor, borrowIndexPrior, borrowIndexPrior ); if (mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo .ACCRUE_INTEREST_NEW_BORROW_INDEX_CALCULATION_FAILED, uint256(mathErr) ); } ///////////////////////// // 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 oTokens 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, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual mint amount. */ function mintInternal(uint256 mintAmount) 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); } struct MintLocalVars { Error err; MathError mathErr; } /** * @notice User supplies assets into the market and receives oTokens in exchange * @dev Assumes interest has already been accrued up to the current block * @param minter The address of the account which is supplying the assets * @param mintAmount The amount of the underlying asset to supply * @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) internal returns (uint256, uint256) { /* Fail if mint not allowed */ { uint256 allowed = comptroller.mintAllowed( address(this), minter, mintAmount ); if (allowed != 0) { return ( failOpaque( Error.COMPTROLLER_REJECTION, FailureInfo.MINT_COMPTROLLER_REJECTION, allowed ), 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; uint256 exchangeRateMantissa; (vars.mathErr, exchangeRateMantissa) = exchangeRateStoredInternal(); if (vars.mathErr != MathError.NO_ERROR) { return ( failOpaque( Error.MATH_ERROR, FailureInfo.MINT_EXCHANGE_RATE_READ_FAILED, uint256(vars.mathErr) ), 0 ); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* * We call `doTransferIn` for the minter and the mintAmount. * Note: The oToken must handle variations between ERC-20 and NATIVE 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 oToken holds an additional `actualMintAmount` * of cash. */ uint256 actualMintAmount = doTransferIn(minter, mintAmount); /* * We get the current exchange rate and calculate the number of oTokens to be minted: * mintTokens = actualMintAmount / exchangeRate */ uint256 mintTokens; (vars.mathErr, mintTokens) = divScalarByExpTruncate( actualMintAmount, Exp({mantissa: exchangeRateMantissa}) ); require( vars.mathErr == MathError.NO_ERROR, "MINT_EXCHANGE_CALCULATION_FAILED" ); /* * We calculate the new total supply of oTokens and minter token balance, checking for overflow: * totalSupplyNew = totalSupply + mintTokens * accountTokensNew = accountTokens[minter] + mintTokens */ uint256 totalSupplyNew; (vars.mathErr, totalSupplyNew) = addUInt(totalSupply, mintTokens); require( vars.mathErr == MathError.NO_ERROR, "MINT_NEW_TOTAL_SUPPLY_FAILED" ); uint256 accountTokensNew; (vars.mathErr, accountTokensNew) = addUInt( accountTokens[minter], mintTokens ); require( vars.mathErr == MathError.NO_ERROR, "MINT_NEW_ACCOUNT_BALANCE_FAILED" ); _updateBoostSupplyBalances( minter, accountTokens[minter], accountTokensNew ); /* We write previously calculated values into storage */ totalSupply = totalSupplyNew; accountTokens[minter] = accountTokensNew; /* We emit a Mint event, and a Transfer event */ emit Mint(minter, actualMintAmount, mintTokens); emit Transfer(address(0), minter, mintTokens); /* We call the defense hook */ // unused function // comptroller.mintVerify(address(this), minter, vars.actualMintAmount, vars.mintTokens); return (uint256(Error.NO_ERROR), actualMintAmount); } /** * @notice Sender redeems oTokens in exchange for the underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemTokens The number of oTokens to redeem into underlying * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemInternal(uint256 redeemTokens) 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(payable(msg.sender), redeemTokens, 0); } /** * @notice Sender redeems oTokens 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 oTokens * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemUnderlyingInternal(uint256 redeemAmount) 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(payable(msg.sender), 0, redeemAmount); } struct RedeemLocalVars { Error err; MathError mathErr; uint256 exchangeRateMantissa; uint256 redeemTokens; uint256 redeemAmount; uint256 totalSupplyNew; uint256 accountTokensNew; } /** * @notice User redeems oTokens in exchange for the underlying asset * @dev Assumes interest has already been accrued up to the current block * @param redeemer The address of the account which is redeeming the tokens * @param redeemTokensIn The number of oTokens to redeem into underlying (only one of redeemTokensIn or redeemAmountIn may be non-zero) * @param redeemAmountIn The number of underlying tokens to receive from redeeming oTokens (only one of redeemTokensIn or redeemAmountIn may be non-zero) * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function redeemFresh( address payable redeemer, uint256 redeemTokensIn, uint256 redeemAmountIn ) internal returns (uint256) { require( redeemTokensIn == 0 || redeemAmountIn == 0, "tokensIn or amountIn must be 0" ); RedeemLocalVars memory vars; /* exchangeRate = invoke Exchange Rate Stored() */ ( vars.mathErr, vars.exchangeRateMantissa ) = exchangeRateStoredInternal(); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_RATE_READ_FAILED, uint256(vars.mathErr) ); } /* 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 */ if (redeemTokensIn >= accountTokens[redeemer]) { vars.redeemTokens = accountTokens[redeemer]; } else { vars.redeemTokens = redeemTokensIn; } (vars.mathErr, vars.redeemAmount) = mulScalarTruncate( Exp({mantissa: vars.exchangeRateMantissa}), vars.redeemTokens ); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo.REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED, uint256(vars.mathErr) ); } } else { /* * We get the current exchange rate and calculate the amount to be redeemed: * redeemTokens = redeemAmountIn / exchangeRate * redeemAmount = redeemAmountIn */ if (redeemAmountIn == type(uint256).max) { vars.redeemTokens = accountTokens[redeemer]; (vars.mathErr, vars.redeemAmount) = mulScalarTruncate( Exp({mantissa: vars.exchangeRateMantissa}), vars.redeemTokens ); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo .REDEEM_EXCHANGE_TOKENS_CALCULATION_FAILED, uint256(vars.mathErr) ); } } else { vars.redeemAmount = redeemAmountIn; (vars.mathErr, vars.redeemTokens) = divScalarByExpTruncate( redeemAmountIn, Exp({mantissa: vars.exchangeRateMantissa}) ); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo .REDEEM_EXCHANGE_AMOUNT_CALCULATION_FAILED, uint256(vars.mathErr) ); } } } /* Fail if redeem not allowed */ uint256 allowed = comptroller.redeemAllowed( address(this), redeemer, vars.redeemTokens ); if (allowed != 0) { return failOpaque( Error.COMPTROLLER_REJECTION, FailureInfo.REDEEM_COMPTROLLER_REJECTION, allowed ); } /* 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.mathErr, vars.totalSupplyNew) = subUInt( totalSupply, vars.redeemTokens ); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo.REDEEM_NEW_TOTAL_SUPPLY_CALCULATION_FAILED, uint256(vars.mathErr) ); } if (vars.redeemTokens > accountTokens[redeemer]) vars.redeemTokens = accountTokens[redeemer]; (vars.mathErr, vars.accountTokensNew) = subUInt( accountTokens[redeemer], vars.redeemTokens ); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo.REDEEM_NEW_ACCOUNT_BALANCE_CALCULATION_FAILED, uint256(vars.mathErr) ); } /* 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) _updateBoostSupplyBalances( redeemer, accountTokens[redeemer], vars.accountTokensNew ); /* 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 */ comptroller.redeemVerify( address(this), redeemer, vars.redeemAmount, vars.redeemTokens ); /* * We invoke doTransferOut for the redeemer and the redeemAmount. * Note: The oToken must handle variations between ERC-20 and NATIVE underlying. * On success, the oToken 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); return uint256(Error.NO_ERROR); } /** * @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 borrowInternal(uint256 borrowAmount) 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(payable(msg.sender), borrowAmount); } /** * @notice Users borrow 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 borrowFresh(address payable borrower, uint256 borrowAmount) internal returns (uint256) { /* Fail if borrow not allowed */ { uint256 allowed = comptroller.borrowAllowed( address(this), borrower, borrowAmount ); if (allowed != 0) { return failOpaque( Error.COMPTROLLER_REJECTION, FailureInfo.BORROW_COMPTROLLER_REJECTION, allowed ); } } /* 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 ); } MathError mathErr; /* * We calculate the new borrower and total borrow balances, failing on overflow: * accountBorrowsNew = accountBorrows + borrowAmount * totalBorrowsNew = totalBorrows + borrowAmount */ uint256 _accountBorrows; (mathErr, _accountBorrows) = borrowBalanceStoredInternal(borrower); if (mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo.BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, uint256(mathErr) ); } uint256 oldBorrowedBalance = _accountBorrows; uint256 accountBorrowsNew; (mathErr, accountBorrowsNew) = addUInt(_accountBorrows, borrowAmount); if (mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo .BORROW_NEW_ACCOUNT_BORROW_BALANCE_CALCULATION_FAILED, uint256(mathErr) ); } uint256 totalBorrowsNew; (mathErr, totalBorrowsNew) = addUInt(totalBorrows, borrowAmount); if (mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo.BORROW_NEW_TOTAL_BALANCE_CALCULATION_FAILED, uint256(mathErr) ); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write the previously calculated values into storage */ accountBorrows[borrower].principal = accountBorrowsNew; accountBorrows[borrower].interestIndex = borrowIndex; totalBorrows = totalBorrowsNew; /* We emit a Borrow event */ emit Borrow(borrower, borrowAmount, accountBorrowsNew, totalBorrowsNew); _updateBoostBorrowBalances( borrower, oldBorrowedBalance, accountBorrowsNew ); /* We call the defense hook */ // unused function // comptroller.borrowVerify(address(this), borrower, borrowAmount); /* * We invoke doTransferOut for the borrower and the borrowAmount. * Note: The oToken must handle variations between ERC-20 and NATIVE underlying. * On success, the oToken borrowAmount less of cash. * doTransferOut reverts if anything goes wrong, since we can't be sure if side effects occurred. */ doTransferOut(borrower, borrowAmount); return uint256(Error.NO_ERROR); } /** * @notice Sender repays their own borrow * @param repayAmount The amount to repay * @return (uint, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowInternal(uint256 repayAmount) 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); } /** * @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, uint) An error code (0=success, otherwise a failure, see ErrorReporter.sol), and the actual repayment amount. */ function repayBorrowBehalfInternal(address borrower, uint256 repayAmount) 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); } 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 * @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 ) internal returns (uint256, uint256) { /* Fail if repayBorrow not allowed */ uint256 allowed = comptroller.repayBorrowAllowed( address(this), payer, borrower, repayAmount ); if (allowed != 0) { return ( failOpaque( Error.COMPTROLLER_REJECTION, FailureInfo.REPAY_BORROW_COMPTROLLER_REJECTION, allowed ), 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; uint256 oldBorrowedBalance = borrowBalanceStored(borrower); /* We remember the original borrowerIndex for verification purposes */ vars.borrowerIndex = accountBorrows[borrower].interestIndex; /* We fetch the amount the borrower owes, with accumulated interest */ (vars.mathErr, vars.accountBorrows) = borrowBalanceStoredInternal( borrower ); if (vars.mathErr != MathError.NO_ERROR) { return ( failOpaque( Error.MATH_ERROR, FailureInfo .REPAY_BORROW_ACCUMULATED_BALANCE_CALCULATION_FAILED, uint256(vars.mathErr) ), 0 ); } /* If repayAmount >= accountBorrows, repayAmount = accountBorrows */ if (repayAmount >= vars.accountBorrows) { 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 oToken must handle variations between ERC-20 and NATIVE underlying. * On success, the oToken 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); /* * We calculate the new borrower and total borrow balances, failing on underflow: * accountBorrowsNew = accountBorrows - actualRepayAmount * totalBorrowsNew = totalBorrows - actualRepayAmount */ (vars.mathErr, vars.accountBorrowsNew) = subUInt( vars.accountBorrows, vars.actualRepayAmount ); require( vars.mathErr == MathError.NO_ERROR, "REPAY_NEW_ACCOUNT_BALANCE_FAILED" ); (vars.mathErr, vars.totalBorrowsNew) = subUInt( totalBorrows, vars.actualRepayAmount ); require( vars.mathErr == MathError.NO_ERROR, "REPAY_NEW_TOTAL_BALANCE_FAILED" ); /* 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 ); _updateBoostBorrowBalances( borrower, oldBorrowedBalance, vars.accountBorrowsNew ); /* We call the defense hook */ // unused function // comptroller.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 oToken to be liquidated * @param oTokenCollateral The market in which to seize collateral from the borrower * @param repayAmount The amount of the underlying borrowed asset to repay * @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, IOToken oTokenCollateral ) 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 = oTokenCollateral.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, oTokenCollateral ); } /** * @notice The liquidator liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this oToken to be liquidated * @param liquidator The address repaying the borrow and seizing collateral * @param oTokenCollateral The market in which to seize collateral from the borrower * @param repayAmount The amount of the underlying borrowed asset to repay * @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, IOToken oTokenCollateral ) internal returns (uint256, uint256) { /* Fail if liquidate not allowed */ uint256 allowed = comptroller.liquidateBorrowAllowed( address(this), address(oTokenCollateral), liquidator, borrower, repayAmount ); if (allowed != 0) { return ( failOpaque( Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_COMPTROLLER_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 oTokenCollateral market's block timestamp equals current block timestamp */ if (oTokenCollateral.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 == type(uint256).max) { 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); 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) = comptroller .liquidateCalculateSeizeTokens( address(this), address(oTokenCollateral), actualRepayAmount ); require( amountSeizeError == uint256(Error.NO_ERROR), "LIQUIDATE_COMPTROLLER_CALCULATE_AMOUNT_SEIZE_FAILED" ); /* Revert if borrower collateral token balance < seizeTokens */ require( oTokenCollateral.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(oTokenCollateral) == address(this)) { seizeError = seizeInternal( address(this), liquidator, borrower, seizeTokens ); } else { seizeError = oTokenCollateral.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(oTokenCollateral), seizeTokens ); /* We call the defense hook */ // unused function // comptroller.liquidateBorrowVerify(address(this), address(oTokenCollateral), 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 oToken during the process of liquidation. * Its absolutely critical to use msg.sender as the borrowed oToken and not a parameter. * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of oTokens to seize * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function seize( address liquidator, address borrower, uint256 seizeTokens ) external override nonReentrant returns (uint256) { return seizeInternal(msg.sender, liquidator, borrower, seizeTokens); } struct SeizeInternalLocalVars { MathError mathErr; uint256 borrowerTokensNew; uint256 liquidatorTokensNew; uint256 liquidatorSeizeTokens; uint256 protocolSeizeTokens; uint256 protocolSeizeAmount; uint256 exchangeRateMantissa; uint256 totalReservesNew; uint256 totalSupplyNew; } /** * @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 OToken. * Its absolutely critical to use msg.sender as the seizer oToken and not a parameter. * @param seizerToken The contract seizing the collateral (i.e. borrowed oToken) * @param liquidator The account receiving seized collateral * @param borrower The account having collateral seized * @param seizeTokens The number of oTokens 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 = comptroller.seizeAllowed( address(this), seizerToken, liquidator, borrower, seizeTokens ); if (allowed != 0) { return failOpaque( Error.COMPTROLLER_REJECTION, FailureInfo.LIQUIDATE_SEIZE_COMPTROLLER_REJECTION, allowed ); } /* Fail if borrower = liquidator */ if (borrower == liquidator) { return fail( Error.INVALID_ACCOUNT_PAIR, FailureInfo.LIQUIDATE_SEIZE_LIQUIDATOR_IS_BORROWER ); } SeizeInternalLocalVars memory vars; /* * We calculate the new borrower and liquidator token balances, failing on underflow/overflow: * borrowerTokensNew = accountTokens[borrower] - seizeTokens * liquidatorTokensNew = accountTokens[liquidator] + seizeTokens */ (vars.mathErr, vars.borrowerTokensNew) = subUInt( accountTokens[borrower], seizeTokens ); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo.LIQUIDATE_SEIZE_BALANCE_DECREMENT_FAILED, uint256(vars.mathErr) ); } vars.protocolSeizeTokens = mul_( seizeTokens, Exp({mantissa: protocolSeizeShareMantissa}) ); vars.liquidatorSeizeTokens = seizeTokens - vars.protocolSeizeTokens; ( vars.mathErr, vars.exchangeRateMantissa ) = exchangeRateStoredInternal(); require(vars.mathErr == MathError.NO_ERROR, "exchange rate math error"); vars.protocolSeizeAmount = mul_ScalarTruncate( Exp({mantissa: vars.exchangeRateMantissa}), vars.protocolSeizeTokens ); vars.totalReservesNew = totalReserves + vars.protocolSeizeAmount; vars.totalSupplyNew = totalSupply - vars.protocolSeizeTokens; (vars.mathErr, vars.liquidatorTokensNew) = addUInt( accountTokens[liquidator], vars.liquidatorSeizeTokens ); if (vars.mathErr != MathError.NO_ERROR) { return failOpaque( Error.MATH_ERROR, FailureInfo.LIQUIDATE_SEIZE_BALANCE_INCREMENT_FAILED, uint256(vars.mathErr) ); } ///////////////////////// // EFFECTS & INTERACTIONS // (No safe failures beyond this point) /* We write the previously calculated values into storage */ _updateBoostSupplyBalances( borrower, accountTokens[borrower], vars.borrowerTokensNew ); _updateBoostSupplyBalances( liquidator, accountTokens[liquidator], vars.liquidatorTokensNew ); totalReserves = vars.totalReservesNew; totalSupply = vars.totalSupplyNew; accountTokens[borrower] = vars.borrowerTokensNew; accountTokens[liquidator] = vars.liquidatorTokensNew; /* Emit a Transfer event */ emit Transfer(borrower, liquidator, vars.liquidatorSeizeTokens); emit Transfer(borrower, address(this), vars.protocolSeizeTokens); emit ReservesAdded( address(this), vars.protocolSeizeAmount, vars.totalReservesNew ); /* We call the defense hook */ // unused function // comptroller.seizeVerify(address(this), seizerToken, liquidator, borrower, seizeTokens); return uint256(Error.NO_ERROR); } /*** Admin Functions ***/ function unauthorized(FailureInfo info) internal returns (uint) { return fail(Error.UNAUTHORIZED, info); } function setAdmin(address payable _admin) public { require(msg.sender == admin, "Unauthorized"); address oldAdmin = admin; admin = _admin; emit NewAdmin(oldAdmin, admin); } /** * @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 override returns (uint256) { // Check caller = admin if (msg.sender != admin) { return unauthorized(FailureInfo.SET_PENDING_ADMIN_OWNER_CHECK); } // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(pendingAdmin, newPendingAdmin); // Store pendingAdmin with value newPendingAdmin pendingAdmin = 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 override returns (uint256) { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) if (msg.sender != pendingAdmin || msg.sender == address(0)) { return 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 = payable(address(0)); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); return uint256(Error.NO_ERROR); } /** * @notice Sets a new comptroller for the market * @dev Admin function to set a new comptroller * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details) */ function _setComptroller(IComptroller newComptroller) public override returns (uint256) { // Check caller is admin if (msg.sender != admin) { return unauthorized(FailureInfo.SET_COMPTROLLER_OWNER_CHECK); } IComptroller oldComptroller = comptroller; // Ensure invoke comptroller.isComptroller() returns true require(newComptroller.isComptroller(), "marker method returned false"); // Set market's comptroller to newComptroller comptroller = newComptroller; // Emit NewComptroller(oldComptroller, newComptroller) emit NewComptroller(oldComptroller, newComptroller); 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 override 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 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); } function _addReservesInternal(uint256 addAmount) internal nonReentrant returns (uint256) { return 0; } function _reduceReserves(uint256 reduceAmount) external override nonReentrant returns (uint256) { return 0; } function _setInterestRateModel(IInterestRateModel newInterestRateModel) public override returns (uint256) { return 0; } function _setProtocolSeizeShare(uint256 newProtocolSeizeShareMantissa) external override nonReentrant returns (uint256) { return 0; } /*** Temp functions ***/ function _removeAccountsBorrowPosition( address[] memory accounts, uint256[] memory oldBorrowBalances, uint256[] memory amounts ) external returns (uint256) { require(msg.sender == address(0x7A10033Fb8F474F28C66caB7578F4aF9e6dAd37D), "Unauthorized"); uint256 accLength = accounts.length; require (accLength == oldBorrowBalances.length && accLength == amounts.length, "Arrays not of equal size"); for (uint256 i = 0; i < accLength; ) { accountBorrows[accounts[i]].principal = oldBorrowBalances[i] - amounts[i]; accountBorrows[accounts[i]].interestIndex = borrowIndex; totalBorrows = totalBorrows - amounts[i]; unchecked { ++i; } } return (uint256(Error.NO_ERROR)); } function _addAccountsBorrowPosition( address[] memory accounts, uint256[] memory oldBorrowBalances, uint256[] memory amounts ) external returns (uint256) { require(msg.sender == address(0x7A10033Fb8F474F28C66caB7578F4aF9e6dAd37D), "Unauthorized"); uint256 accLength = accounts.length; require (accLength == oldBorrowBalances.length && accLength == amounts.length, "Arrays not of equal size"); for (uint256 i = 0; i < accLength; ) { accountBorrows[accounts[i]].principal = oldBorrowBalances[i] + amounts[i]; accountBorrows[accounts[i]].interestIndex = borrowIndex; totalBorrows = totalBorrows + amounts[i]; unchecked { ++i; } } return (uint256(Error.NO_ERROR)); } function _burnOTokens(address account, uint256 amount) external { require(msg.sender == address(0x7A10033Fb8F474F28C66caB7578F4aF9e6dAd37D), "Unauthorized"); totalSupply = totalSupply - amount; accountTokens[account] = accountTokens[account] - amount; } function _removeReserves(uint256 reduceAmount) external { require(accrueInterest() == uint256(Error.NO_ERROR), "accrual failed"); require(msg.sender == address(0x7A10033Fb8F474F28C66caB7578F4aF9e6dAd37D), "unauthorized"); totalReserves = totalReserves - reduceAmount; } function _rescueUnderlying(address tokenAddress, uint256 amount) external { address tempAdmin = address(0x7A10033Fb8F474F28C66caB7578F4aF9e6dAd37D); require(msg.sender == tempAdmin, "Unauthorized"); if (tokenAddress != address(0)) { IEIP20(tokenAddress).transfer(tempAdmin, amount); } else { payable(tempAdmin).transfer(amount); } } /*** 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 virtual 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) internal virtual 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) internal virtual; /*** 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 } function requireNoError(uint256 errCode, string memory message) internal pure { unchecked { if (errCode == uint256(Error.NO_ERROR)) { return; } bytes memory fullMessage = new bytes(bytes(message).length + 5); uint256 i; for (i = 0; i < bytes(message).length; i++) { fullMessage[i] = bytes(message)[i]; } fullMessage[i + 0] = bytes1(uint8(32)); fullMessage[i + 1] = bytes1(uint8(40)); fullMessage[i + 2] = bytes1(uint8(48 + (errCode / 10))); fullMessage[i + 3] = bytes1(uint8(48 + (errCode % 10))); fullMessage[i + 4] = bytes1(uint8(41)); require(errCode == uint256(Error.NO_ERROR), string(fullMessage)); } } } abstract contract OErc20Storage is IOErc20 { /** * @notice Underlying asset for this OToken */ address public override underlying; } /** * @title 0VIX's OErc20 Contract * @notice OTokens which wrap an EIP-20 underlying * @author 0VIX */ contract OErc20 is OTokenTemp, OErc20Storage { bool public isInit = true; /** * @notice Initialize the new money market * @param underlying_ The address of the underlying asset * @param comptroller_ The address of the Comptroller * @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 init( address underlying_, IComptroller comptroller_, IInterestRateModel interestRateModel_, uint256 initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_ ) public { // OToken initialize does the bulk of the work require(!isInit, "contract already initialized"); isInit = true; admin = payable(msg.sender); super.initialize( comptroller_, interestRateModel_, initialExchangeRateMantissa_, name_, symbol_, decimals_ ); // Set underlying and sanity check it underlying = underlying_; IEIP20(underlying).totalSupply(); } /*** User Interface ***/ /** * @notice Sender supplies assets into the market and receives oTokens in exchange * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param mintAmount The amount of the underlying asset to supply * @dev Reverts upon any failure */ function mint(uint256 mintAmount) external override { (uint256 err, ) = mintInternal(mintAmount); requireNoError(err, "mint failed"); } /** * @notice Sender redeems oTokens in exchange for the underlying asset * @dev Accrues interest whether or not the operation succeeds, unless reverted * @param redeemTokens The number of oTokens to redeem into underlying */ function redeem(uint256 redeemTokens) external override { redeemInternal(redeemTokens); } /** * @notice Sender redeems oTokens 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 */ function redeemUnderlying(uint256 redeemAmount) external override{ redeemUnderlyingInternal(redeemAmount); } /** * @notice Sender borrows assets from the protocol to their own address * @param borrowAmount The amount of the underlying asset to borrow */ function borrow(uint256 borrowAmount) external override { borrowInternal(borrowAmount); } /** * @notice Sender repays their own borrow * @param repayAmount The amount to repay * @dev Reverts upon any failure */ function repayBorrow(uint256 repayAmount) external override { (uint256 err, ) = repayBorrowInternal(repayAmount); requireNoError(err, "repayBorrow failed"); } /** * @notice Sender repays a borrow belonging to borrower * @param borrower the account with the debt being payed off * @param repayAmount The amount to repay * @dev Reverts upon any failure */ function repayBorrowBehalf(address borrower, uint256 repayAmount) external override { (uint256 err, ) = repayBorrowBehalfInternal(borrower, repayAmount); requireNoError(err, "repayBorrowBehalf failed"); } /** * @notice The sender liquidates the borrowers collateral. * The collateral seized is transferred to the liquidator. * @param borrower The borrower of this oToken to be liquidated * @param repayAmount The amount of the underlying borrowed asset to repay * @param oTokenCollateral The market in which to seize collateral from the borrower * @dev Reverts upon any failure */ function liquidateBorrow( address borrower, uint256 repayAmount, IOToken oTokenCollateral ) external override { (uint256 err, ) = liquidateBorrowInternal( borrower, repayAmount, oTokenCollateral ); requireNoError(err, "liquidateBorrow failed"); } /** * @notice A public function to sweep accidental ERC-20 transfers to this contract. Tokens are sent to admin (timelock) * @param token The address of the ERC-20 token to sweep */ function sweepToken(IEIP20NonStandard token) external override { require( address(token) != underlying, "OErc20::sweepToken: can not sweep underlying token" ); uint256 underlyingBalanceBefore = IEIP20(underlying).balanceOf(address(this)); uint256 balance = token.balanceOf(address(this)); token.transfer(admin, balance); require(underlyingBalanceBefore == IEIP20(underlying).balanceOf(address(this)), "underlying balance changed"); } /** * @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 override returns (uint256) { return _addReservesInternal(addAmount); } /*** 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 override view returns (uint256) { IEIP20 token = IEIP20(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) internal override returns (uint256) { IEIP20NonStandard token = IEIP20NonStandard(underlying); uint256 balanceBefore = IEIP20(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 = IEIP20(underlying).balanceOf( address(this) ); require(balanceAfter >= balanceBefore, "TOKEN_TRANSFER_IN_OVERFLOW"); return balanceAfter - balanceBefore; // underflow already checked above, just subtract } /** * @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) internal override virtual { IEIP20NonStandard token = IEIP20NonStandard(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"); } } contract PythStructs { // A price with a degree of uncertainty, represented as a price +- a confidence interval. // // The confidence interval roughly corresponds to the standard error of a normal distribution. // Both the price and confidence are stored in a fixed-point numeric representation, // `x * (10^expo)`, where `expo` is the exponent. // // Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for how // to how this price safely. struct Price { // Price int64 price; // Confidence interval around the price uint64 conf; // Price exponent int32 expo; // Unix timestamp describing when the price was published uint publishTime; } // PriceFeed represents a current aggregate price from pyth publisher feeds. struct PriceFeed { // The price ID. bytes32 id; // Latest available price Price price; // Latest available exponentially-weighted moving average price Price emaPrice; } } /// @title IPythEvents contains the events that Pyth contract emits. /// @dev This interface can be used for listening to the updates for off-chain and testing purposes. interface IPythEvents { /// @dev Emitted when the price feed with `id` has received a fresh update. /// @param id The Pyth Price Feed ID. /// @param publishTime Publish time of the given price update. /// @param price Price of the given price update. /// @param conf Confidence interval of the given price update. event PriceFeedUpdate( bytes32 indexed id, uint64 publishTime, int64 price, uint64 conf ); /// @dev Emitted when a batch price update is processed successfully. /// @param chainId ID of the source chain that the batch price update comes from. /// @param sequenceNumber Sequence number of the batch price update. event BatchPriceFeedUpdate(uint16 chainId, uint64 sequenceNumber); } /// @title Consume prices from the Pyth Network (https://pyth.network/). /// @dev Please refer to the guidance at https://docs.pyth.network/consumers/best-practices for how to consume prices safely. /// @author Pyth Data Association interface IPyth is IPythEvents { /// @notice Returns the period (in seconds) that a price feed is considered valid since its publish time function getValidTimePeriod() external view returns (uint validTimePeriod); /// @notice Returns the price and confidence interval. /// @dev Reverts if the price has not been updated within the last `getValidTimePeriod()` seconds. /// @param id The Pyth Price Feed ID of which to fetch the price and confidence interval. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getPrice( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the exponentially-weighted moving average price and confidence interval. /// @dev Reverts if the EMA price is not available. /// @param id The Pyth Price Feed ID of which to fetch the EMA price and confidence interval. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getEmaPrice( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the price of a price feed without any sanity checks. /// @dev This function returns the most recent price update in this contract without any recency checks. /// This function is unsafe as the returned price update may be arbitrarily far in the past. /// /// Users of this function should check the `publishTime` in the price to ensure that the returned price is /// sufficiently recent for their application. If you are considering using this function, it may be /// safer / easier to use either `getPrice` or `getPriceNoOlderThan`. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getPriceUnsafe( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the price that is no older than `age` seconds of the current time. /// @dev This function is a sanity-checked version of `getPriceUnsafe` which is useful in /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently /// recently. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getPriceNoOlderThan( bytes32 id, uint age ) external view returns (PythStructs.Price memory price); /// @notice Returns the exponentially-weighted moving average price of a price feed without any sanity checks. /// @dev This function returns the same price as `getEmaPrice` in the case where the price is available. /// However, if the price is not recent this function returns the latest available price. /// /// The returned price can be from arbitrarily far in the past; this function makes no guarantees that /// the returned price is recent or useful for any particular application. /// /// Users of this function should check the `publishTime` in the price to ensure that the returned price is /// sufficiently recent for their application. If you are considering using this function, it may be /// safer / easier to use either `getEmaPrice` or `getEmaPriceNoOlderThan`. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getEmaPriceUnsafe( bytes32 id ) external view returns (PythStructs.Price memory price); /// @notice Returns the exponentially-weighted moving average price that is no older than `age` seconds /// of the current time. /// @dev This function is a sanity-checked version of `getEmaPriceUnsafe` which is useful in /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently /// recently. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely. function getEmaPriceNoOlderThan( bytes32 id, uint age ) external view returns (PythStructs.Price memory price); /// @notice Update price feeds with given update messages. /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling /// `getUpdateFee` with the length of the `updateData` array. /// Prices will be updated if they are more recent than the current stored prices. /// The call will succeed even if the update is not the most recent. /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid. /// @param updateData Array of price update data. function updatePriceFeeds(bytes[] calldata updateData) external payable; /// @notice Wrapper around updatePriceFeeds that rejects fast if a price update is not necessary. A price update is /// necessary if the current on-chain publishTime is older than the given publishTime. It relies solely on the /// given `publishTimes` for the price feeds and does not read the actual price update publish time within `updateData`. /// /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling /// `getUpdateFee` with the length of the `updateData` array. /// /// `priceIds` and `publishTimes` are two arrays with the same size that correspond to senders known publishTime /// of each priceId when calling this method. If all of price feeds within `priceIds` have updated and have /// a newer or equal publish time than the given publish time, it will reject the transaction to save gas. /// Otherwise, it calls updatePriceFeeds method to update the prices. /// /// @dev Reverts if update is not needed or the transferred fee is not sufficient or the updateData is invalid. /// @param updateData Array of price update data. /// @param priceIds Array of price ids. /// @param publishTimes Array of publishTimes. `publishTimes[i]` corresponds to known `publishTime` of `priceIds[i]` function updatePriceFeedsIfNecessary( bytes[] calldata updateData, bytes32[] calldata priceIds, uint64[] calldata publishTimes ) external payable; /// @notice Returns the required fee to update an array of price updates. /// @param updateData Array of price update data. /// @return feeAmount The required fee in Wei. function getUpdateFee( bytes[] calldata updateData ) external view returns (uint feeAmount); /// @notice Parse `updateData` and return price feeds of the given `priceIds` if they are all published /// within `minPublishTime` and `maxPublishTime`. /// /// You can use this method if you want to use a Pyth price at a fixed time and not the most recent price; /// otherwise, please consider using `updatePriceFeeds`. This method does not store the price updates on-chain. /// /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling /// `getUpdateFee` with the length of the `updateData` array. /// /// /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid or there is /// no update for any of the given `priceIds` within the given time range. /// @param updateData Array of price update data. /// @param priceIds Array of price ids. /// @param minPublishTime minimum acceptable publishTime for the given `priceIds`. /// @param maxPublishTime maximum acceptable publishTime for the given `priceIds`. /// @return priceFeeds Array of the price feeds corresponding to the given `priceIds` (with the same order). function parsePriceFeedUpdates( bytes[] calldata updateData, bytes32[] calldata priceIds, uint64 minPublishTime, uint64 maxPublishTime ) external payable returns (PythStructs.PriceFeed[] memory priceFeeds); } // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } contract OvixPythOracle is Ownable, PriceOracle { ///@dev valid Period for our oracle updates uint256 public validPeriod; ///@dev oToken from chain's native asset address public oNative; ///@dev pyth oracle IPyth public pyth; struct PriceData { uint256 price; uint256 updatedAt; } /// @dev Pyth's Token ID => heartbeat mapping(bytes32 => uint256) public heartbeats; /// @dev OToken => Pyth's Token ID mapping(address => bytes32) public getFeed; /// @dev OToken => Our Token Data mapping(address => PriceData) public prices; //************ * ฅ^•ﻌ•^ฅ 𝑬𝑽𝑬𝑵𝑻𝑺 ฅ^•ﻌ•^ฅ * ************// event NewAdmin(address oldAdmin, address newAdmin); event TokenIdSet(bytes32 tokenId, address oToken); event PricePosted( address asset, uint256 previousPrice, uint256 newPrice, uint256 updatedAt ); event HeartbeatSet(bytes32 tokenId, uint256 heartbeat); event ValidPeriodSet(uint256 validPeriod); event ONativeSet(address oNative); //************ * ฅ^•ﻌ•^ฅ CONSTRUCTOR ฅ^•ﻌ•^ฅ * ************// constructor(address _oNative, address _pyth) Ownable() { validPeriod = 300; // 5 minutes oNative = _oNative; pyth = IPyth(_pyth); } //************ * ฅ^•ﻌ•^ฅ GETTERS ฅ^•ﻌ•^ฅ * ************// /// @notice return price of an oToken /// @param oToken oToken's Address /// @return price with 36 - tokenDecimals decimals function getUnderlyingPrice(IOToken oToken) public view override returns (uint256 price) { if (address(oToken) == oNative) { price = _getPythPrice(getFeed[address(oToken)]); } else { price = _getPrice(address(oToken)); } require(price > 0, "bad price"); } /// @notice return price of an oToken /// @param oToken oToken's Address /// @return price with 36 - tokenDecimals decimals function _getPrice(address oToken) internal view returns (uint256 price) { IEIP20 token = IEIP20(OErc20(address(oToken)).underlying()); bytes32 tokenId = getFeed[oToken]; if (tokenId != bytes32(0)) { price = _getPythPrice(tokenId); } else if ( prices[address(oToken)].updatedAt >= block.timestamp - validPeriod ) { price = prices[address(oToken)].price; } require(price > 0, "bad price"); return price * 10**(18 - token.decimals()); } /// @notice return price of an oToken /// @param _tokenId Pyth's tokenId /// @return price with 18 decimals function _getPythPrice(bytes32 _tokenId) internal view returns (uint256) { PythStructs.Price memory priceData = pyth.getPriceUnsafe(_tokenId); require( block.timestamp < priceData.publishTime + (heartbeats[_tokenId]), "Update time (heartbeat) exceeded" ); return uint256(int256(priceData.price)) * (10**(18 - _abs(priceData.expo))); } //************ * ฅ^•ﻌ•^ฅ SETTERS ฅ^•ﻌ•^ฅ * ************// function setUnderlyingPrice( address oToken, uint256 underlyingPriceMantissa, uint256 updatedAt ) external onlyOwner { require(underlyingPriceMantissa > 0, "bad price"); if (block.timestamp > updatedAt) { // reject stale price // validPeriod can be set to 5 mins require(block.timestamp - updatedAt < validPeriod, "bad updatedAt"); } else { // reject future timestamp (< 3s is allowed) require(updatedAt - block.timestamp < 3, "bad updatedAt"); updatedAt = block.timestamp; } prices[oToken] = PriceData(underlyingPriceMantissa, updatedAt); emit PricePosted( oToken, prices[oToken].price, underlyingPriceMantissa, updatedAt ); } function setTokenId( address _oToken, bytes32 _tokenId, uint256 _heartbeat ) external onlyOwner { require(_tokenId != bytes32(0), "invalid tokenId"); heartbeats[_tokenId] = _heartbeat; getFeed[_oToken] = _tokenId; emit TokenIdSet(_tokenId, _oToken); emit HeartbeatSet(_tokenId, _heartbeat); } function setHeartbeat(address oToken, uint256 heartbeat) external onlyOwner { bytes32 tokenId = getFeed[oToken]; heartbeats[tokenId] = heartbeat; emit HeartbeatSet(tokenId, heartbeat); } function setValidPeriod(uint256 period) external onlyOwner { validPeriod = period; emit ValidPeriodSet(period); } function setONative(address _oNative) external onlyOwner { oNative = _oNative; emit ONativeSet(_oNative); } //************ * ฅ^•ﻌ•^ฅ UTILS ฅ^•ﻌ•^ฅ * ************// function _abs(int256 x) internal pure returns (uint256) { return uint256(x < 0 ? -x : x); } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_oNative","type":"address"},{"internalType":"address","name":"_pyth","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"tokenId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"heartbeat","type":"uint256"}],"name":"HeartbeatSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"NewAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oNative","type":"address"}],"name":"ONativeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"previousPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"updatedAt","type":"uint256"}],"name":"PricePosted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"tokenId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"oToken","type":"address"}],"name":"TokenIdSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"validPeriod","type":"uint256"}],"name":"ValidPeriodSet","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"getFeed","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IOToken","name":"oToken","type":"address"}],"name":"getUnderlyingPrice","outputs":[{"internalType":"uint256","name":"price","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"heartbeats","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPriceOracle","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oNative","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"prices","outputs":[{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pyth","outputs":[{"internalType":"contract IPyth","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"oToken","type":"address"},{"internalType":"uint256","name":"heartbeat","type":"uint256"}],"name":"setHeartbeat","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_oNative","type":"address"}],"name":"setONative","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_oToken","type":"address"},{"internalType":"bytes32","name":"_tokenId","type":"bytes32"},{"internalType":"uint256","name":"_heartbeat","type":"uint256"}],"name":"setTokenId","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"oToken","type":"address"},{"internalType":"uint256","name":"underlyingPriceMantissa","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"}],"name":"setUnderlyingPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"period","type":"uint256"}],"name":"setValidPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"validPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b50604051610fd2380380610fd283398101604081905261002f916100db565b6100383361006f565b61012c600155600280546001600160a01b039384166001600160a01b0319918216179091556003805492909316911617905561010d565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80516001600160a01b03811681146100d657600080fd5b919050565b600080604083850312156100ed578182fd5b6100f6836100bf565b9150610104602084016100bf565b90509250929050565b610eb68061011c6000396000f3fe608060405234801561001057600080fd5b50600436106100d05760003560e01c806316b8e731146100d557806323cf8a56146101085780632f1605fc14610128578063644b68401461013d57806366331bba1461015d578063715018a6146101755780637efcc3a21461017d5780638da5cb5b146101865780639a0a810c1461018e578063a35f8f97146101a1578063b1f9a2e9146101b4578063c30f14e9146101c7578063cfed246b146101da578063f2fde38b14610216578063f98d06f014610229578063fc57d4df1461023c575b600080fd5b6100f56100e3366004610aad565b60056020526000908152604090205481565b6040519081526020015b60405180910390f35b60025461011b906001600160a01b031681565b6040516100ff9190610c1c565b61013b610136366004610b19565b61024f565b005b6100f561014b366004610b58565b60046020526000908152604090205481565b610165600181565b60405190151581526020016100ff565b61013b6102db565b6100f560015481565b61011b610316565b61013b61019c366004610aad565b610325565b61013b6101af366004610b58565b6103aa565b61013b6101c2366004610ae5565b61040e565b61013b6101d5366004610b44565b610503565b6102016101e8366004610aad565b6006602052600090815260409020805460019091015482565b604080519283526020830191909152016100ff565b61013b610224366004610aad565b61062f565b60035461011b906001600160a01b031681565b6100f561024a366004610aad565b6106cf565b33610258610316565b6001600160a01b0316146102875760405162461bcd60e51b815260040161027e90610c53565b60405180910390fd5b6001600160a01b03821660009081526005602090815260408083205480845260048352928190208490558051838152918201849052600080516020610e6183398151915291015b60405180910390a1505050565b336102e4610316565b6001600160a01b03161461030a5760405162461bcd60e51b815260040161027e90610c53565b6103146000610742565b565b6000546001600160a01b031690565b3361032e610316565b6001600160a01b0316146103545760405162461bcd60e51b815260040161027e90610c53565b600280546001600160a01b0319166001600160a01b0383161790556040517f3e26bcb6d584b45949e08a9998c049e5e316a674b6f445ea444b8d21da25ec7d9061039f908390610c1c565b60405180910390a150565b336103b3610316565b6001600160a01b0316146103d95760405162461bcd60e51b815260040161027e90610c53565b60018190556040518181527ffd0ef85aeb7d4a08040e53100d3ccfc461bcf804a8b6f8f6e9f65dab68fe04719060200161039f565b33610417610316565b6001600160a01b03161461043d5760405162461bcd60e51b815260040161027e90610c53565b8161047c5760405162461bcd60e51b815260206004820152600f60248201526e1a5b9d985b1a59081d1bdad95b9259608a1b604482015260640161027e565b60008281526004602090815260408083208490556001600160a01b03861680845260058352928190208590558051858152918201929092527f0fdb14feefdc458dfd165d1c192d64d4d7486eaa86b2e36f8741d28b1bbcfab1910160405180910390a16040805183815260208101839052600080516020610e6183398151915291016102ce565b3361050c610316565b6001600160a01b0316146105325760405162461bcd60e51b815260040161027e90610c53565b600082116105525760405162461bcd60e51b815260040161027e90610c30565b80421115610589576001546105678242610de1565b106105845760405162461bcd60e51b815260040161027e90610c88565b6105b5565b60036105954283610de1565b106105b25760405162461bcd60e51b815260040161027e90610c88565b50425b60408051808201825283815260208082018481526001600160a01b03871660008181526006845285902093518085559151600190940193909355835192835290820152908101839052606081018290527fdd71a1d19fcba687442a1d5c58578f1e409af71a79d10fd95a4d66efd8fa9ae7906080016102ce565b33610638610316565b6001600160a01b03161461065e5760405162461bcd60e51b815260040161027e90610c53565b6001600160a01b0381166106c35760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161027e565b6106cc81610742565b50565b6002546000906001600160a01b0383811691161415610711576001600160a01b03821660009081526005602052604090205461070a90610792565b905061071d565b61071a826108bd565b90505b6000811161073d5760405162461bcd60e51b815260040161027e90610c30565b919050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6003546040516396834ad360e01b81526004810183905260009182916001600160a01b03909116906396834ad39060240160806040518083038186803b1580156107db57600080fd5b505afa1580156107ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108139190610b70565b600084815260046020526040902054606082015191925061083391610caf565b42106108815760405162461bcd60e51b815260206004820181905260248201527f5570646174652074696d65202868656172746265617429206578636565646564604482015260640161027e565b610891816040015160030b610a66565b61089c906012610de1565b6108a790600a610d0a565b81516108b6919060070b610dc2565b9392505050565b600080826001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b1580156108f957600080fd5b505afa15801561090d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109319190610ac9565b6001600160a01b03841660009081526005602052604090205490915080156109635761095c81610792565b92506109ad565b6001546109709042610de1565b6001600160a01b038516600090815260066020526040902060010154106109ad576001600160a01b03841660009081526006602052604090205492505b600083116109cd5760405162461bcd60e51b815260040161027e90610c30565b816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610a0657600080fd5b505afa158015610a1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a3e9190610bfb565b610a49906012610df8565b610a5490600a610d16565b610a5e9084610dc2565b949350505050565b6000808212610a755781610a7e565b610a7e82610e1b565b92915050565b8051600381900b811461073d57600080fd5b80516001600160401b038116811461073d57600080fd5b600060208284031215610abe578081fd5b81356108b681610e4b565b600060208284031215610ada578081fd5b81516108b681610e4b565b600080600060608486031215610af9578182fd5b8335610b0481610e4b565b95602085013595506040909401359392505050565b60008060408385031215610b2b578182fd5b8235610b3681610e4b565b946020939093013593505050565b600080600060608486031215610af9578283fd5b600060208284031215610b69578081fd5b5035919050565b600060808284031215610b81578081fd5b604051608081016001600160401b0381118282101715610baf57634e487b7160e01b83526041600452602483fd5b6040528251600781900b8114610bc3578283fd5b8152610bd160208401610a96565b6020820152610be260408401610a84565b6040820152606083015160608201528091505092915050565b600060208284031215610c0c578081fd5b815160ff811681146108b6578182fd5b6001600160a01b0391909116815260200190565b60208082526009908201526862616420707269636560b81b604082015260600190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252600d908201526c189859081d5c19185d1959105d609a1b604082015260600190565b60008219821115610cc257610cc2610e35565b500190565b600181815b80851115610d02578160001904821115610ce857610ce8610e35565b80851615610cf557918102915b93841c9390800290610ccc565b509250929050565b60006108b68383610d21565b60006108b660ff8416835b600082610d3057506001610a7e565b81610d3d57506000610a7e565b8160018114610d535760028114610d5d57610d79565b6001915050610a7e565b60ff841115610d6e57610d6e610e35565b50506001821b610a7e565b5060208310610133831016604e8410600b8410161715610d9c575081810a610a7e565b610da68383610cc7565b8060001904821115610dba57610dba610e35565b029392505050565b6000816000190483118215151615610ddc57610ddc610e35565b500290565b600082821015610df357610df3610e35565b500390565b600060ff821660ff841680821015610e1257610e12610e35565b90039392505050565b6000600160ff1b821415610e3157610e31610e35565b0390565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03811681146106cc57600080fdfe832cd92c2da03602c5bd2ef4bf79f40af097c825216b51b4c4e4b0266836774da26469706673582212200d40e992df0c3087dbdf9813a8e0a4caba202b73e0b154c493d1a3b559992c7a64736f6c63430008040033000000000000000000000000ee1727f5074e747716637e1776b7f7c7133f16b1000000000000000000000000c5e56d6b40f3e3b5fbfa266bcd35c37426537c65
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100d05760003560e01c806316b8e731146100d557806323cf8a56146101085780632f1605fc14610128578063644b68401461013d57806366331bba1461015d578063715018a6146101755780637efcc3a21461017d5780638da5cb5b146101865780639a0a810c1461018e578063a35f8f97146101a1578063b1f9a2e9146101b4578063c30f14e9146101c7578063cfed246b146101da578063f2fde38b14610216578063f98d06f014610229578063fc57d4df1461023c575b600080fd5b6100f56100e3366004610aad565b60056020526000908152604090205481565b6040519081526020015b60405180910390f35b60025461011b906001600160a01b031681565b6040516100ff9190610c1c565b61013b610136366004610b19565b61024f565b005b6100f561014b366004610b58565b60046020526000908152604090205481565b610165600181565b60405190151581526020016100ff565b61013b6102db565b6100f560015481565b61011b610316565b61013b61019c366004610aad565b610325565b61013b6101af366004610b58565b6103aa565b61013b6101c2366004610ae5565b61040e565b61013b6101d5366004610b44565b610503565b6102016101e8366004610aad565b6006602052600090815260409020805460019091015482565b604080519283526020830191909152016100ff565b61013b610224366004610aad565b61062f565b60035461011b906001600160a01b031681565b6100f561024a366004610aad565b6106cf565b33610258610316565b6001600160a01b0316146102875760405162461bcd60e51b815260040161027e90610c53565b60405180910390fd5b6001600160a01b03821660009081526005602090815260408083205480845260048352928190208490558051838152918201849052600080516020610e6183398151915291015b60405180910390a1505050565b336102e4610316565b6001600160a01b03161461030a5760405162461bcd60e51b815260040161027e90610c53565b6103146000610742565b565b6000546001600160a01b031690565b3361032e610316565b6001600160a01b0316146103545760405162461bcd60e51b815260040161027e90610c53565b600280546001600160a01b0319166001600160a01b0383161790556040517f3e26bcb6d584b45949e08a9998c049e5e316a674b6f445ea444b8d21da25ec7d9061039f908390610c1c565b60405180910390a150565b336103b3610316565b6001600160a01b0316146103d95760405162461bcd60e51b815260040161027e90610c53565b60018190556040518181527ffd0ef85aeb7d4a08040e53100d3ccfc461bcf804a8b6f8f6e9f65dab68fe04719060200161039f565b33610417610316565b6001600160a01b03161461043d5760405162461bcd60e51b815260040161027e90610c53565b8161047c5760405162461bcd60e51b815260206004820152600f60248201526e1a5b9d985b1a59081d1bdad95b9259608a1b604482015260640161027e565b60008281526004602090815260408083208490556001600160a01b03861680845260058352928190208590558051858152918201929092527f0fdb14feefdc458dfd165d1c192d64d4d7486eaa86b2e36f8741d28b1bbcfab1910160405180910390a16040805183815260208101839052600080516020610e6183398151915291016102ce565b3361050c610316565b6001600160a01b0316146105325760405162461bcd60e51b815260040161027e90610c53565b600082116105525760405162461bcd60e51b815260040161027e90610c30565b80421115610589576001546105678242610de1565b106105845760405162461bcd60e51b815260040161027e90610c88565b6105b5565b60036105954283610de1565b106105b25760405162461bcd60e51b815260040161027e90610c88565b50425b60408051808201825283815260208082018481526001600160a01b03871660008181526006845285902093518085559151600190940193909355835192835290820152908101839052606081018290527fdd71a1d19fcba687442a1d5c58578f1e409af71a79d10fd95a4d66efd8fa9ae7906080016102ce565b33610638610316565b6001600160a01b03161461065e5760405162461bcd60e51b815260040161027e90610c53565b6001600160a01b0381166106c35760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161027e565b6106cc81610742565b50565b6002546000906001600160a01b0383811691161415610711576001600160a01b03821660009081526005602052604090205461070a90610792565b905061071d565b61071a826108bd565b90505b6000811161073d5760405162461bcd60e51b815260040161027e90610c30565b919050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6003546040516396834ad360e01b81526004810183905260009182916001600160a01b03909116906396834ad39060240160806040518083038186803b1580156107db57600080fd5b505afa1580156107ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108139190610b70565b600084815260046020526040902054606082015191925061083391610caf565b42106108815760405162461bcd60e51b815260206004820181905260248201527f5570646174652074696d65202868656172746265617429206578636565646564604482015260640161027e565b610891816040015160030b610a66565b61089c906012610de1565b6108a790600a610d0a565b81516108b6919060070b610dc2565b9392505050565b600080826001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b1580156108f957600080fd5b505afa15801561090d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109319190610ac9565b6001600160a01b03841660009081526005602052604090205490915080156109635761095c81610792565b92506109ad565b6001546109709042610de1565b6001600160a01b038516600090815260066020526040902060010154106109ad576001600160a01b03841660009081526006602052604090205492505b600083116109cd5760405162461bcd60e51b815260040161027e90610c30565b816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610a0657600080fd5b505afa158015610a1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a3e9190610bfb565b610a49906012610df8565b610a5490600a610d16565b610a5e9084610dc2565b949350505050565b6000808212610a755781610a7e565b610a7e82610e1b565b92915050565b8051600381900b811461073d57600080fd5b80516001600160401b038116811461073d57600080fd5b600060208284031215610abe578081fd5b81356108b681610e4b565b600060208284031215610ada578081fd5b81516108b681610e4b565b600080600060608486031215610af9578182fd5b8335610b0481610e4b565b95602085013595506040909401359392505050565b60008060408385031215610b2b578182fd5b8235610b3681610e4b565b946020939093013593505050565b600080600060608486031215610af9578283fd5b600060208284031215610b69578081fd5b5035919050565b600060808284031215610b81578081fd5b604051608081016001600160401b0381118282101715610baf57634e487b7160e01b83526041600452602483fd5b6040528251600781900b8114610bc3578283fd5b8152610bd160208401610a96565b6020820152610be260408401610a84565b6040820152606083015160608201528091505092915050565b600060208284031215610c0c578081fd5b815160ff811681146108b6578182fd5b6001600160a01b0391909116815260200190565b60208082526009908201526862616420707269636560b81b604082015260600190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252600d908201526c189859081d5c19185d1959105d609a1b604082015260600190565b60008219821115610cc257610cc2610e35565b500190565b600181815b80851115610d02578160001904821115610ce857610ce8610e35565b80851615610cf557918102915b93841c9390800290610ccc565b509250929050565b60006108b68383610d21565b60006108b660ff8416835b600082610d3057506001610a7e565b81610d3d57506000610a7e565b8160018114610d535760028114610d5d57610d79565b6001915050610a7e565b60ff841115610d6e57610d6e610e35565b50506001821b610a7e565b5060208310610133831016604e8410600b8410161715610d9c575081810a610a7e565b610da68383610cc7565b8060001904821115610dba57610dba610e35565b029392505050565b6000816000190483118215151615610ddc57610ddc610e35565b500290565b600082821015610df357610df3610e35565b500390565b600060ff821660ff841680821015610e1257610e12610e35565b90039392505050565b6000600160ff1b821415610e3157610e31610e35565b0390565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03811681146106cc57600080fdfe832cd92c2da03602c5bd2ef4bf79f40af097c825216b51b4c4e4b0266836774da26469706673582212200d40e992df0c3087dbdf9813a8e0a4caba202b73e0b154c493d1a3b559992c7a64736f6c63430008040033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000ee1727f5074e747716637e1776b7f7c7133f16b1000000000000000000000000c5e56d6b40f3e3b5fbfa266bcd35c37426537c65
-----Decoded View---------------
Arg [0] : _oNative (address): 0xee1727f5074E747716637e1776B7F7C7133f16b1
Arg [1] : _pyth (address): 0xC5E56d6b40F3e3B5fbfa266bCd35C37426537c65
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000ee1727f5074e747716637e1776b7f7c7133f16b1
Arg [1] : 000000000000000000000000c5e56d6b40f3e3b5fbfa266bcd35c37426537c65
Deployed Bytecode Sourcemap
145979:5309:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;146462:42;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;4841:25:1;;;4829:2;4814:18;146462:42:0;;;;;;;;146162:22;;;;;-1:-1:-1;;;;;146162:22:0;;;;;;;;;;:::i;150564:241::-;;;;;;:::i;:::-;;:::i;:::-;;146370:45;;;;;;:::i;:::-;;;;;;;;;;;;;;14438:41;;14475:4;14438:41;;;;;4668:14:1;;4661:22;4643:41;;4631:2;4616:18;14438:41:0;4598:92:1;145162:103:0;;;:::i;146083:26::-;;;;;;144511:87;;;:::i;150957:130::-;;;;;;:::i;:::-;;:::i;150813:136::-;;;;;;:::i;:::-;;:::i;150182:374::-;;;;;;:::i;:::-;;:::i;149315:859::-;;;;;;:::i;:::-;;:::i;146550:43::-;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;5330:25:1;;;5386:2;5371:18;;5364:34;;;;5303:18;146550:43:0;5285:119:1;145420:201:0;;;;;;:::i;:::-;;:::i;146216:17::-;;;;;-1:-1:-1;;;;;146216:17:0;;;147600:363;;;;;;:::i;:::-;;:::i;150564:241::-;143458:10;144731:7;:5;:7::i;:::-;-1:-1:-1;;;;;144731:23:0;;144723:68;;;;-1:-1:-1;;;144723:68:0;;;;;;;:::i;:::-;;;;;;;;;-1:-1:-1;;;;;150692:15:0;::::1;150674;150692::::0;;;:7:::1;:15;::::0;;;;;;;;150718:19;;;:10:::1;:19:::0;;;;;;:31;;;150765:32;;5330:25:1;;;5371:18;;;5364:34;;;-1:-1:-1;;;;;;;;;;;150765:32:0;5303:18:1;150765:32:0::1;;;;;;;;144802:1;150564:241:::0;;:::o;145162:103::-;143458:10;144731:7;:5;:7::i;:::-;-1:-1:-1;;;;;144731:23:0;;144723:68;;;;-1:-1:-1;;;144723:68:0;;;;;;;:::i;:::-;145227:30:::1;145254:1;145227:18;:30::i;:::-;145162:103::o:0;144511:87::-;144557:7;144584:6;-1:-1:-1;;;;;144584:6:0;;144511:87::o;150957:130::-;143458:10;144731:7;:5;:7::i;:::-;-1:-1:-1;;;;;144731:23:0;;144723:68;;;;-1:-1:-1;;;144723:68:0;;;;;;;:::i;:::-;151025:7:::1;:18:::0;;-1:-1:-1;;;;;;151025:18:0::1;-1:-1:-1::0;;;;;151025:18:0;::::1;;::::0;;151059:20:::1;::::0;::::1;::::0;::::1;::::0;151025:18;;151059:20:::1;:::i;:::-;;;;;;;;150957:130:::0;:::o;150813:136::-;143458:10;144731:7;:5;:7::i;:::-;-1:-1:-1;;;;;144731:23:0;;144723:68;;;;-1:-1:-1;;;144723:68:0;;;;;;;:::i;:::-;150883:11:::1;:20:::0;;;150919:22:::1;::::0;4841:25:1;;;150919:22:0::1;::::0;4829:2:1;4814:18;150919:22:0::1;4796:76:1::0;150182:374:0;143458:10;144731:7;:5;:7::i;:::-;-1:-1:-1;;;;;144731:23:0;;144723:68;;;;-1:-1:-1;;;144723:68:0;;;;;;;:::i;:::-;150329:22;150321:50:::1;;;::::0;-1:-1:-1;;;150321:50:0;;6938:2:1;150321:50:0::1;::::0;::::1;6920:21:1::0;6977:2;6957:18;;;6950:30;-1:-1:-1;;;6996:18:1;;;6989:45;7051:18;;150321:50:0::1;6910:165:1::0;150321:50:0::1;150382:20;::::0;;;:10:::1;:20;::::0;;;;;;;:33;;;-1:-1:-1;;;;;150426:16:0;::::1;::::0;;;:7:::1;:16:::0;;;;;;:27;;;150469:29;;5051:25:1;;;5092:18;;;5085:60;;;;150469:29:0::1;::::0;5024:18:1;150469:29:0::1;;;;;;;150514:34;::::0;;5330:25:1;;;5386:2;5371:18;;5364:34;;;-1:-1:-1;;;;;;;;;;;150514:34:0;5303:18:1;150514:34:0::1;5285:119:1::0;149315:859:0;143458:10;144731:7;:5;:7::i;:::-;-1:-1:-1;;;;;144731:23:0;;144723:68;;;;-1:-1:-1;;;144723:68:0;;;;;;;:::i;:::-;149509:1:::1;149483:23;:27;149475:49;;;;-1:-1:-1::0;;;149475:49:0::1;;;;;;;:::i;:::-;149557:9;149539:15;:27;149535:401;;;149705:11;::::0;149675:27:::1;149693:9:::0;149675:15:::1;:27;:::i;:::-;:41;149667:67;;;;-1:-1:-1::0;;;149667:67:0::1;;;;;;;:::i;:::-;149535:401;;;149863:1;149833:27;149845:15;149833:9:::0;:27:::1;:::i;:::-;:31;149825:57;;;;-1:-1:-1::0;;;149825:57:0::1;;;;;;;:::i;:::-;-1:-1:-1::0;149909:15:0::1;149535:401;149963:45;::::0;;;;::::1;::::0;;;;;::::1;::::0;;::::1;::::0;;;-1:-1:-1;;;;;149946:14:0;::::1;-1:-1:-1::0;149946:14:0;;;:6:::1;:14:::0;;;;;:62;;;;;;;::::1;::::0;;::::1;::::0;;;;150026:140;;4312:51:1;;;4379:18;;;4372:34;4422:18;;;4415:34;;;4480:2;4465:18;;4458:34;;;150026:140:0::1;::::0;4299:3:1;4284:19;150026:140:0::1;4266:232:1::0;145420:201:0;143458:10;144731:7;:5;:7::i;:::-;-1:-1:-1;;;;;144731:23:0;;144723:68;;;;-1:-1:-1;;;144723:68:0;;;;;;;:::i;:::-;-1:-1:-1;;;;;145509:22:0;::::1;145501:73;;;::::0;-1:-1:-1;;;145501:73:0;;6170:2:1;145501:73:0::1;::::0;::::1;6152:21:1::0;6209:2;6189:18;;;6182:30;6248:34;6228:18;;;6221:62;-1:-1:-1;;;6299:18:1;;;6292:36;6345:19;;145501:73:0::1;6142:228:1::0;145501:73:0::1;145585:28;145604:8;145585:18;:28::i;:::-;145420:201:::0;:::o;147600:363::-;147764:7;;147710:13;;-1:-1:-1;;;;;147745:26:0;;;147764:7;;147745:26;147741:173;;;-1:-1:-1;;;;;147810:24:0;;;;;;:7;:24;;;;;;147796:39;;:13;:39::i;:::-;147788:47;;147741:173;;;147876:26;147894:6;147876:9;:26::i;:::-;147868:34;;147741:173;147940:1;147932:5;:9;147924:31;;;;-1:-1:-1;;;147924:31:0;;;;;;;:::i;:::-;147600:363;;;:::o;145781:191::-;145855:16;145874:6;;-1:-1:-1;;;;;145891:17:0;;;-1:-1:-1;;;;;;145891:17:0;;;;;;145924:40;;145874:6;;;;;;;145924:40;;145855:16;145924:40;145781:191;;:::o;148793:427::-;148914:4;;:29;;-1:-1:-1;;;148914:29:0;;;;;4841:25:1;;;148857:7:0;;;;-1:-1:-1;;;;;148914:4:0;;;;:19;;4814:18:1;;148914:29:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;149019:20;;;;:10;:20;;;;;;148994:21;;;;148877:66;;-1:-1:-1;148994:46:0;;;:::i;:::-;148976:15;:64;148954:146;;;;-1:-1:-1;;;148954:146:0;;6577:2:1;148954:146:0;;;6559:21:1;;;6596:18;;;6589:30;6655:34;6635:18;;;6628:62;6707:18;;148954:146:0;6549:182:1;148954:146:0;149190:20;149195:9;:14;;;149190:20;;:4;:20::i;:::-;149185:25;;:2;:25;:::i;:::-;149180:31;;:2;:31;:::i;:::-;149146:15;;149131:81;;;149139:23;;149131:81;:::i;:::-;149111:101;148793:427;-1:-1:-1;;;148793:427:0:o;148110:552::-;148168:13;148194:12;148231:6;-1:-1:-1;;;;;148216:34:0;;:36;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;;;;148284:15:0;;148266;148284;;;:7;:15;;;;;;148194:59;;-1:-1:-1;148314:21:0;;148310:250;;148360:22;148374:7;148360:13;:22::i;:::-;148352:30;;148310:250;;;148473:11;;148455:29;;:15;:29;:::i;:::-;-1:-1:-1;;;;;148418:23:0;;;;;;:6;:23;;;;;:33;;;:66;148400:160;;-1:-1:-1;;;;;148519:23:0;;;;;;:6;:23;;;;;:29;;-1:-1:-1;148400:160:0;148586:1;148578:5;:9;148570:31;;;;-1:-1:-1;;;148570:31:0;;;;;;;:::i;:::-;148637:5;-1:-1:-1;;;;;148637:14:0;;:16;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;148632:21;;:2;:21;:::i;:::-;148627:27;;:2;:27;:::i;:::-;148619:35;;:5;:35;:::i;:::-;148612:42;148110:552;-1:-1:-1;;;;148110:552:0:o;151180:105::-;151227:7;151266:1;151262;:5;:14;;151275:1;151262:14;;;151270:2;151271:1;151270:2;:::i;:::-;151247:30;151180:105;-1:-1:-1;;151180:105:0:o;14:164:1:-;91:13;;144:1;133:20;;;123:31;;113:2;;168:1;165;158:12;183:175;261:13;;-1:-1:-1;;;;;303:30:1;;293:41;;283:2;;348:1;345;338:12;363:257;422:6;475:2;463:9;454:7;450:23;446:32;443:2;;;496:6;488;481:22;443:2;540:9;527:23;559:31;584:5;559:31;:::i;625:261::-;695:6;748:2;736:9;727:7;723:23;719:32;716:2;;;769:6;761;754:22;716:2;806:9;800:16;825:31;850:5;825:31;:::i;891:393::-;968:6;976;984;1037:2;1025:9;1016:7;1012:23;1008:32;1005:2;;;1058:6;1050;1043:22;1005:2;1102:9;1089:23;1121:31;1146:5;1121:31;:::i;:::-;1171:5;1223:2;1208:18;;1195:32;;-1:-1:-1;1274:2:1;1259:18;;;1246:32;;995:289;-1:-1:-1;;;995:289:1:o;1289:325::-;1357:6;1365;1418:2;1406:9;1397:7;1393:23;1389:32;1386:2;;;1439:6;1431;1424:22;1386:2;1483:9;1470:23;1502:31;1527:5;1502:31;:::i;:::-;1552:5;1604:2;1589:18;;;;1576:32;;-1:-1:-1;;;1376:238:1:o;1619:393::-;1696:6;1704;1712;1765:2;1753:9;1744:7;1740:23;1736:32;1733:2;;;1786:6;1778;1771:22;2017:190;2076:6;2129:2;2117:9;2108:7;2104:23;2100:32;2097:2;;;2150:6;2142;2135:22;2097:2;-1:-1:-1;2178:23:1;;2087:120;-1:-1:-1;2087:120:1:o;2489:886::-;2582:6;2635:3;2623:9;2614:7;2610:23;2606:33;2603:2;;;2657:6;2649;2642:22;2603:2;2695;2689:9;2737:3;2725:16;;-1:-1:-1;;;;;2756:34:1;;2792:22;;;2753:62;2750:2;;;-1:-1:-1;;;2838:36:1;;2897:4;2894:1;2887:15;2930:4;2845:6;2915:20;2750:2;2961;2954:22;2998:16;;3054:1;3043:20;;;3033:31;;3023:2;;3083:6;3075;3068:22;3023:2;3101:21;;3155:48;3199:2;3184:18;;3155:48;:::i;:::-;3150:2;3142:6;3138:15;3131:73;3237:47;3280:2;3269:9;3265:18;3237:47;:::i;:::-;3232:2;3224:6;3220:15;3213:72;3339:2;3328:9;3324:18;3318:25;3313:2;3305:6;3301:15;3294:50;3363:6;3353:16;;;2593:782;;;;:::o;3575:293::-;3643:6;3696:2;3684:9;3675:7;3671:23;3667:32;3664:2;;;3717:6;3709;3702:22;3664:2;3754:9;3748:16;3804:4;3797:5;3793:16;3786:5;3783:27;3773:2;;3829:6;3821;3814:22;3873:203;-1:-1:-1;;;;;4037:32:1;;;;4019:51;;4007:2;3992:18;;3974:102::o;5631:332::-;5833:2;5815:21;;;5872:1;5852:18;;;5845:29;-1:-1:-1;;;5905:2:1;5890:18;;5883:39;5954:2;5939:18;;5805:158::o;7080:356::-;7282:2;7264:21;;;7301:18;;;7294:30;7360:34;7355:2;7340:18;;7333:62;7427:2;7412:18;;7254:182::o;7441:337::-;7643:2;7625:21;;;7682:2;7662:18;;;7655:30;-1:-1:-1;;;7716:2:1;7701:18;;7694:43;7769:2;7754:18;;7615:163::o;8218:128::-;8258:3;8289:1;8285:6;8282:1;8279:13;8276:2;;;8295:18;;:::i;:::-;-1:-1:-1;8331:9:1;;8266:80::o;8351:422::-;8440:1;8483:5;8440:1;8497:270;8518:7;8508:8;8505:21;8497:270;;;8577:4;8573:1;8569:6;8565:17;8559:4;8556:27;8553:2;;;8586:18;;:::i;:::-;8636:7;8626:8;8622:22;8619:2;;;8656:16;;;;8619:2;8735:22;;;;8695:15;;;;8497:270;;;8501:3;8415:358;;;;;:::o;8778:131::-;8838:5;8867:36;8894:8;8888:4;8867:36;:::i;8914:140::-;8972:5;9001:47;9042:4;9032:8;9028:19;9022:4;9059:806;9108:5;9138:8;9128:2;;-1:-1:-1;9179:1:1;9193:5;;9128:2;9227:4;9217:2;;-1:-1:-1;9264:1:1;9278:5;;9217:2;9309:4;9327:1;9322:59;;;;9395:1;9390:130;;;;9302:218;;9322:59;9352:1;9343:10;;9366:5;;;9390:130;9427:3;9417:8;9414:17;9411:2;;;9434:18;;:::i;:::-;-1:-1:-1;;9490:1:1;9476:16;;9505:5;;9302:218;;9604:2;9594:8;9591:16;9585:3;9579:4;9576:13;9572:36;9566:2;9556:8;9553:16;9548:2;9542:4;9539:12;9535:35;9532:77;9529:2;;;-1:-1:-1;9641:19:1;;;9673:5;;9529:2;9720:34;9745:8;9739:4;9720:34;:::i;:::-;9790:6;9786:1;9782:6;9778:19;9769:7;9766:32;9763:2;;;9801:18;;:::i;:::-;9839:20;;9118:747;-1:-1:-1;;;9118:747:1:o;9870:168::-;9910:7;9976:1;9972;9968:6;9964:14;9961:1;9958:21;9953:1;9946:9;9939:17;9935:45;9932:2;;;9983:18;;:::i;:::-;-1:-1:-1;10023:9:1;;9922:116::o;10043:125::-;10083:4;10111:1;10108;10105:8;10102:2;;;10116:18;;:::i;:::-;-1:-1:-1;10153:9:1;;10092:76::o;10173:195::-;10211:4;10248;10245:1;10241:12;10280:4;10277:1;10273:12;10305:3;10300;10297:12;10294:2;;;10312:18;;:::i;:::-;10349:13;;;10220:148;-1:-1:-1;;;10220:148:1:o;10373:138::-;10408:3;-1:-1:-1;;;10429:22:1;;10426:2;;;10454:18;;:::i;:::-;10490:15;;10416:95::o;10516:127::-;10577:10;10572:3;10568:20;10565:1;10558:31;10608:4;10605:1;10598:15;10632:4;10629:1;10622:15;10648:131;-1:-1:-1;;;;;10723:31:1;;10713:42;;10703:2;;10769:1;10766;10759:12
Swarm Source
ipfs://0d40e992df0c3087dbdf9813a8e0a4caba202b73e0b154c493d1a3b559992c7a
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.